_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q7800
VersionCollection.getPreviousVersion
train
public function getPreviousVersion($from) { $lastTimestamp = 0; foreach (array_keys($this->versions) as $timestamp) { if ($timestamp == $from) { return $lastTimestamp; } $lastTimestamp = $timestamp; } return 0; }
php
{ "resource": "" }
q7801
TranslationToFile.getAllLanguagesFromTable
train
protected function getAllLanguagesFromTable(): void { foreach($this->translations as $entry){ if(!in_array($entry->language, $this->languages)){ array_push($this->languages, $entry->language); } } $this->compareLanguages(); }
php
{ "resource": "" }
q7802
TranslationToFile.generateGroupFiles
train
protected function generateGroupFiles(): void { foreach($this->languages as $language){ foreach($this->translation_groups as $group){ $file = $this->language_folder . $language . "\\" . $group->name . ".php"; if(!file_exists($file)){ $new_file = fopen($file, "a"); fclose($new_file); $this->info("Created translation group - $group->name - for language $language."); } } } }
php
{ "resource": "" }
q7803
TranslationToFile.addTranslationsToArray
train
private function addTranslationsToArray($array = []): array { foreach($array as $language => $groups){ foreach($groups as $groupname => $entries){ $group_model = TranslationGroup::where('name', $groupname)->first(); $first_level_translations = Translation::where([ ['parent', '=', NULL], ['translation_group', '=', $group_model->id], ['language', '=', $language] ])->get(); foreach($first_level_translations as $translation){ $array[$language][$groupname][$translation->key] = $this->getValue($language, $translation, $group_model); } } } return $array; }
php
{ "resource": "" }
q7804
TranslationToFile.addTranslationGroupsToArray
train
private function addTranslationGroupsToArray($array = []): array { foreach(array_keys($array) as $language){ foreach($this->translation_groups as $group){ $array[$language][$group->name] = []; } } return $array; }
php
{ "resource": "" }
q7805
Canvas.setFormat
train
public function setFormat($name) { if (!$this->hasFactory($name)) { throw new \InvalidArgumentException(sprintf( 'Invalid Canvas Factory "%s"', $name )); } $this->activeFactoryName = $name; $this->activeCanvas = $this->getFactory($name)->getCanvas(); return $this; }
php
{ "resource": "" }
q7806
Canvas.setFactory
train
public function setFactory(array $factories) { foreach ($factories as $name => $factory) { $this->addFactory($name, $factory); } return $this; }
php
{ "resource": "" }
q7807
Canvas.removeFactory
train
public function removeFactory($name) { if ($this->hasFactory($name)) { unset($this->factories[$name]); return true; } return false; }
php
{ "resource": "" }
q7808
Canvas.show
train
public function show() { try { header(sprintf('Content-Type: %s', $this->getMimeType(), true)); $this->save(null); } catch (\Exception $ex) { header(sprintf('Content-Type: text/html'), true); /* rethrow it */ throw $ex; } }
php
{ "resource": "" }
q7809
Update.buildAttribute
train
public function buildAttribute($property) { $attribute = ''; if (isset($this->$property)) { $attribute .= ' ' . $property . '="'; if (is_bool($this->$property)) { $attribute .= ($this->$property) ? 'true' : 'false'; } else { $attribute .= SolrRequest::escapeXml($this->$property); } $attribute .= '"'; } return $attribute; }
php
{ "resource": "" }
q7810
PropertyAbstract.setPropertyDefaultValue
train
public function setPropertyDefaultValue($property) { if (isset($property->default)) { // Use the defined default. return true; } elseif (isset($property->enum) && count($property->enum) == 1) { // Set default to single enum. $property->default = reset($property->enum); return true; } return false; }
php
{ "resource": "" }
q7811
PropertyAbstract.prepareFactory
train
protected function prepareFactory() { if (empty($this->componentFactory) && isset($this->configuration)) { $this->componentFactory = new ComponentFactory($this->configuration); } }
php
{ "resource": "" }
q7812
PropertyAbstract.getValidator
train
public function getValidator() { if (!isset($this->validator) && isset($this->configuration)) { // Initialize JSON validator. $resolver = $this->configuration->getResolver(); if ($resolver && ($retriever = $resolver->getUriRetriever())) { $check_mode = JsonSchema\Validator::CHECK_MODE_NORMAL; $this->validator = new JsonSchema\Validator($check_mode, $retriever); } } return $this->validator; }
php
{ "resource": "" }
q7813
PropertyAbstract.isEmpty
train
public function isEmpty($property_name = null) { $value = $this->get($property_name); return Inspector::isEmpty($value); }
php
{ "resource": "" }
q7814
Timer.endIf
train
public function endIf(bool $condition, ?callable $callback = null): void { if ((bool) $condition) { $this->end($callback); } }
php
{ "resource": "" }
q7815
Timer.endUnless
train
public function endUnless(bool $condition, ?callable $callback = null): void { $this->endIf(! $condition, $callback); }
php
{ "resource": "" }
q7816
IniRead.&
train
protected function & iniReadFilterEnvironmentSections (array & $rawIniData, $environment) { $iniData = []; foreach ($rawIniData as $keyOrSectionName => $valueOrSectionValues) { if (is_array($valueOrSectionValues)) { if (strpos($keyOrSectionName, '>') !== FALSE) { list($envNamesStrLocal, $keyOrSectionName) = explode('>', str_replace(' ', '', $keyOrSectionName)); if (!in_array($environment, explode(',', $envNamesStrLocal))) continue; } $sectionValues = []; foreach ($valueOrSectionValues as $key => $value) $sectionValues[$keyOrSectionName.'.'.$key] = $value; $iniData = array_merge($iniData, $sectionValues); } else { $iniData[$keyOrSectionName] = $valueOrSectionValues; } } return $iniData; }
php
{ "resource": "" }
q7817
IniRead.iniReadExpandLevelsAndReType
train
protected function iniReadExpandLevelsAndReType (array & $iniData) { //$this->objectTypes[''] = [0, & $this->data]; $oldIniScannerMode = $this->_iniScannerMode === 1; foreach ($iniData as $rawKey => $rawValue) { $current = & $this->data; // prepare keys to build levels and configure stdClass/array types $rawKeys = []; $lastRawKey = $rawKey; $lastDotPos = strrpos($rawKey, '.'); if ($lastDotPos !== FALSE) { $rawKeys = explode('.', substr($rawKey, 0, $lastDotPos)); $lastRawKey = substr($rawKey, $lastDotPos + 1); } // prepare levels structure and configure stdClass or array type change where necessary $levelKey = ''; $prevLevelKey = ''; foreach ($rawKeys as $key) { $prevLevelKey = $levelKey; $levelKey .= ($levelKey ? '.' : '') . $key; if (!isset($current[$key])) { $current[$key] = []; $this->objectTypes[$levelKey] = [1, & $current[$key]]; // object type switch -> object by default if (is_numeric($key) && isset($this->objectTypes[$prevLevelKey])) { $this->objectTypes[$prevLevelKey][0] = 0; // object type switch -> set array if it was object } } $current = & $current[$key]; } // set up value into levels structure and configure type into array if necessary if ($oldIniScannerMode) { $typedValue = $this->getTypedValue($rawValue); } else { $typedValue = $rawValue; } if (isset($current[$lastRawKey])) { $current[$lastRawKey][] = $typedValue; $this->objectTypes[$levelKey ? $levelKey : $lastRawKey][0] = 0; // object type switch -> set array } else { if (!is_array($current)) { $current = [$current]; $this->objectTypes[$levelKey] = [0, & $current]; // object type switch -> set array } $current[$lastRawKey] = $typedValue; if (is_numeric($lastRawKey)) $this->objectTypes[$levelKey][0] = 0; // object type switch -> set array } } }
php
{ "resource": "" }
q7818
IniRead.getTypedValue
train
protected function getTypedValue ($rawValue) { if (gettype($rawValue) == "array") { foreach ($rawValue as $key => $value) { $rawValue[$key] = $this->getTypedValue($value); } return $rawValue; // array } else if (mb_strlen($rawValue) > 0) { if (is_numeric($rawValue)) { return $this->getTypedValueFloatOrInt($rawValue); } else { return $this->getTypedSpecialValueOrString($rawValue); } } else { return $this->getTypedSpecialValueOrString($rawValue); } }
php
{ "resource": "" }
q7819
IniRead.getTypedValueFloatOrInt
train
protected function getTypedValueFloatOrInt ($rawValue) { if (strpos($rawValue, '.') !== FALSE || strpos($rawValue, 'e') !== FALSE || strpos($rawValue, 'E') !== FALSE) { return floatval($rawValue); // float } else { // int or string if integer is too high (more then PHP max/min: 2147483647/-2147483647) $intVal = intval($rawValue); return (string) $intVal === $rawValue ? $intVal : $rawValue; } }
php
{ "resource": "" }
q7820
IniRead.getTypedSpecialValueOrString
train
protected function getTypedSpecialValueOrString ($rawValue) { $lowerRawValue = strtolower($rawValue); if (isset(static::$specialValues[$lowerRawValue])) { return static::$specialValues[$lowerRawValue]; // bool or null } else { return trim($rawValue); // string } }
php
{ "resource": "" }
q7821
Starting.GetStarted
train
public static function GetStarted () { if (static::$started === NULL) { $req = self::$req ?: self::$req = & \MvcCore\Application::GetInstance()->GetRequest(); if (!$req->IsCli()) { $alreadyStarted = session_status() === PHP_SESSION_ACTIVE && session_id() !== ''; if ($alreadyStarted) { // if already started but `static::$started` property is `NULL`: static::$sessionStartTime = time(); static::$sessionMaxTime = static::$sessionStartTime; static::setUpMeta(); static::setUpData(); } static::$started = $alreadyStarted; } } return static::$started; }
php
{ "resource": "" }
q7822
Box.scale
train
public function scale($ratio) { $this->getDimension() ->setWidth( round($ratio * $this->getDimension()->getWidth()) )->setHeight( round($ratio * $this->getDimension()->getHeight()) ); return $this; }
php
{ "resource": "" }
q7823
Dispatching.Init
train
public function Init () { if ($this->dispatchState > 0) return; self::$allControllers[spl_object_hash($this)] = & $this; if ($this->parentController === NULL && !$this->request->IsCli()) { if ($this->autoStartSession) $this->application->SessionStart(); $responseContentType = $this->ajax ? 'text/javascript' : 'text/html'; $this->response->SetHeader('Content-Type', $responseContentType); } if ($this->autoInitProperties) $this->processAutoInitProperties(); foreach ($this->childControllers as $controller) { $controller->Init(); if ($controller->dispatchState == 5) break; } if ($this->dispatchState === 0) $this->dispatchState = 1; }
php
{ "resource": "" }
q7824
Dispatching.processAutoInitProperties
train
protected function processAutoInitProperties () { $type = new \ReflectionClass($this); /** @var $props \ReflectionProperty[] */ $props = $type->getProperties( \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE ); $toolsClass = $this->application->GetToolClass(); foreach ($props as $prop) { $docComment = $prop->getDocComment(); if (mb_strpos($docComment, '@autoinit') === FALSE) continue; $propName = $prop->getName(); $methodName = 'create' . ucfirst($propName); $hasMethod = $type->hasMethod($methodName); if (!$hasMethod) { $methodName = '_'.$methodName; $hasMethod = $type->hasMethod($methodName); } if ($hasMethod) { $method = $type->getMethod($methodName); if (!$method->isPublic()) $method->setAccessible(TRUE); $instance = $method->invoke($this); $implementsController = $instance instanceof \MvcCore\IController; } else { $pos = mb_strpos($docComment, '@var '); if ($pos === FALSE) continue; $docComment = str_replace(["\r","\n","\t", "*/"], " ", mb_substr($docComment, $pos + 5)); $pos = mb_strpos($docComment, ' '); if ($pos === FALSE) continue; $className = trim(mb_substr($docComment, 0, $pos)); if (!@class_exists($className)) { $className = $prop->getDeclaringClass()->getNamespaceName() . '\\' . $className; if (!@class_exists($className)) continue; } $implementsController = $toolsClass::CheckClassInterface( $className, 'MvcCore\IController', FALSE, FALSE ); if ($implementsController) { $instance = $className::CreateInstance(); } else { $instance = new $className(); } } if ($implementsController) $this->AddChildController($instance, $propName); if (!$prop->isPublic()) $prop->setAccessible(TRUE); $prop->setValue($this, $instance); } }
php
{ "resource": "" }
q7825
Dispatching.AssetAction
train
public function AssetAction () { $ext = ''; $path = $this->GetParam('path', 'a-zA-Z0-9_\-\/\.'); $path = '/' . ltrim(str_replace('..', '', $path), '/'); if ( strpos($path, static::$staticPath) !== 0 && strpos($path, static::$tmpPath) !== 0 ) { throw new \ErrorException("[".get_class($this)."] File path: '$path' is not allowed.", 500); } $path = $this->request->GetAppRoot() . $path; if (!file_exists($path)) { throw new \ErrorException("[".get_class($this)."] File not found: '$path'.", 404); } $lastDotPos = strrpos($path, '.'); if ($lastDotPos !== FALSE) { $ext = substr($path, $lastDotPos + 1); } if (isset(self::$_assetsMimeTypes[$ext])) { header('Content-Type: ' . self::$_assetsMimeTypes[$ext]); } header_remove('X-Powered-By'); header('Vary: Accept-Encoding'); $assetMTime = @filemtime($path); if ($assetMTime) header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', $assetMTime)); readfile($path); exit; }
php
{ "resource": "" }
q7826
Theme.bootstrapApplication
train
protected function bootstrapApplication( $config ) { if ( ! isset( $config['providers'] ) ) { $config['providers'] = []; } $config['providers'] = array_merge( $config['providers'], $this->service_providers ); Application::bootstrap( $config ); }
php
{ "resource": "" }
q7827
Theme.bootstrap
train
public function bootstrap( $config = [] ) { if ( $this->isBootstrapped() ) { throw new ConfigurationException( static::class . ' already bootstrapped.' ); } $this->bootstrapped = true; $this->bootstrapApplication( $config ); }
php
{ "resource": "" }
q7828
Environment.EnvironmentDetectByIps
train
public static function EnvironmentDetectByIps () { if (static::$environment === NULL) { $request = & \MvcCore\Application::GetInstance()->GetRequest(); $serverAddress = $request->GetServerIp(); $remoteAddress = $request->GetClientIp(); if ($serverAddress == $remoteAddress) { static::$environment = static::ENVIRONMENT_DEVELOPMENT; } else { static::$environment = static::ENVIRONMENT_PRODUCTION; } } return static::$environment; }
php
{ "resource": "" }
q7829
Environment.EnvironmentDetectBySystemConfig
train
public static function EnvironmentDetectBySystemConfig (array $environmentsSectionData = []) { $environment = NULL; $app = self::$app ?: self::$app = & \MvcCore\Application::GetInstance(); $request = $app->GetRequest(); $clientIp = NULL; $serverHostName = NULL; $serverGlobals = NULL; foreach ((array) $environmentsSectionData as $environmentName => $environmentSection) { $sectionData = static::envDetectParseSysConfigEnvSectionData($environmentSection); $detected = static::envDetectBySystemConfigEnvSection( $sectionData, $request, $clientIp, $serverHostName, $serverGlobals ); if ($detected) { $environment = $environmentName; break; } } if ($environment && !static::$environment) { static::SetEnvironment($environment); } else if (!static::$environment) { static::SetEnvironment('production'); } return static::$environment; }
php
{ "resource": "" }
q7830
Environment.envDetectParseSysConfigEnvSectionData
train
protected static function envDetectParseSysConfigEnvSectionData ($environmentSection) { $data = (object) [ 'clientIps' => (object) [ 'check' => FALSE, 'values' => [], 'regExeps' => [] ], 'serverHostNames' => (object) [ 'check' => FALSE, 'values' => [], 'regExeps' => [] ], 'serverVariables' => (object) [ 'check' => FALSE, 'existence' => [], 'values' => [], 'regExeps' => [] ] ]; if (is_string($environmentSection) && strlen($environmentSection) > 0) { // if there is only string provided, value is probably only // about the most and simple way - to describe client IPS: static::envDetectParseSysConfigClientIps($data, $environmentSection); } else if (is_array($environmentSection) || $environmentSection instanceof \stdClass) { foreach ((array) $environmentSection as $key => $value) { if (is_numeric($key) || $key == 'clients') { // if key is only numeric key provided, value is probably // only one regular expression to match client IP or // the strings list with the most and simple way - to describe client IPS: // of if key has `clients` value, there could be list of clients IPs // or list of clients IPs regular expressions static::envDetectParseSysConfigClientIps($data, $value); } else if ($key == 'servers') { // if key is `servers`, there could be string with single regular // expression to match hostname or string with comma separated hostnames // or list with hostnames and hostname regular expressions static::envDetectParseSysConfigServerNames($data, $value); } else if ($key == 'variables') { // if key is `variables`, there could be string with `$_SERVER` variable // names to check if they exists or key => value object with variable // name and value, which could be also regular expression to match static::envDetectParseSysConfigVariables($data, $value); } } } return $data; }
php
{ "resource": "" }
q7831
Environment.envDetectParseSysConfigClientIps
train
protected static function envDetectParseSysConfigClientIps (& $data, $rawClientIps) { $data->clientIps->check = TRUE; if (is_string($rawClientIps)) { if (substr($rawClientIps, 0, 1) == '/') { $data->clientIps->regExeps[] = $rawClientIps; } else { $data->clientIps->values = array_merge( $data->clientIps->values, explode(',', str_replace(' ', '', $rawClientIps)) ); } } else if (is_array($rawClientIps) || $rawClientIps instanceof \stdClass) { foreach ((array) $rawClientIps as $rawClientIpsItem) { if (substr($rawClientIpsItem, 0, 1) == '/') { $data->clientIps->regExeps[] = $rawClientIpsItem; } else { $data->clientIps->values = array_merge( $data->clientIps->values, explode(',', str_replace(' ', '', $rawClientIpsItem)) ); } } } }
php
{ "resource": "" }
q7832
Environment.envDetectParseSysConfigServerNames
train
protected static function envDetectParseSysConfigServerNames (& $data, $rawHostNames) { $data->serverHostNames->check = TRUE; if (is_string($rawHostNames)) { if (substr($rawHostNames, 0, 1) == '/') { $data->serverHostNames->regExeps[] = $rawHostNames; } else { $data->serverHostNames->values = array_merge( $data->serverHostNames->values, explode(',', str_replace(' ', '', $rawHostNames)) ); } } else if (is_array($rawHostNames) || $rawHostNames instanceof \stdClass) { foreach ((array) $rawHostNames as $rawHostNamesItem) { if (substr($rawHostNamesItem, 0, 1) == '/') { $data->serverHostNames->regExeps[] = $rawHostNamesItem; } else { $data->serverHostNames->values = array_merge( $data->serverHostNames->values, explode(',', str_replace(' ', '', $rawHostNamesItem)) ); } } } }
php
{ "resource": "" }
q7833
Environment.envDetectParseSysConfigVariables
train
protected static function envDetectParseSysConfigVariables (& $data, $rawServerVariable) { $data->serverVariables->check = TRUE; if (is_string($rawServerVariable)) { $data->serverVariables->existence[] = $rawServerVariable; } else if (is_array($rawServerVariable) || $rawServerVariable instanceof \stdClass) { foreach ((array) $rawServerVariable as $key => $value) { if (is_numeric($key)) { $data->serverVariables->existence[] = $value; } else if (substr($value, 0, 1) == '/') { $data->serverVariables->regExeps[$key] = $value; } else { $data->serverVariables->values[$key] = $value; } } } }
php
{ "resource": "" }
q7834
Helpers.EncodeJson
train
public static function EncodeJson (& $data) { $flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | (defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0) | (defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0) | (defined('JSON_PRESERVE_ZERO_FRACTION') ? JSON_PRESERVE_ZERO_FRACTION : 0); $json = json_encode($data, $flags); if ($errorCode = json_last_error()) { $selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__; throw new \RuntimeException("[".$selfClass."] ".json_last_error_msg(), $errorCode); } if (PHP_VERSION_ID < 70100) { $json = strtr($json, [ "\xe2\x80\xa8" => '\u2028', "\xe2\x80\xa9" => '\u2029', ]); } return $json; }
php
{ "resource": "" }
q7835
Helpers.GetSystemTmpDir
train
public static function GetSystemTmpDir () { if (self::$tmpDir === NULL) { $tmpDir = sys_get_temp_dir(); if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { // Windows: $sysRoot = getenv('SystemRoot'); // do not store anything directly in C:\Windows, use C\windows\Temp instead if (!$tmpDir || $tmpDir === $sysRoot) { $tmpDir = !empty($_SERVER['TEMP']) ? $_SERVER['TEMP'] : (!empty($_SERVER['TMP']) ? $_SERVER['TMP'] : (!empty($_SERVER['WINDIR']) ? $_SERVER['WINDIR'] . '/Temp' : $sysRoot . '/Temp' ) ); } $tmpDir = str_replace('\\', '/', $tmpDir); } else if (!$tmpDir) { // Other systems $tmpDir = !empty($_SERVER['TMPDIR']) ? $_SERVER['TMPDIR'] : (!empty($_SERVER['TMP']) ? $_SERVER['TMP'] : (!empty(ini_get('sys_temp_dir')) ? ini_get('sys_temp_dir') : '/tmp' ) ); } self::$tmpDir = $tmpDir; } return self::$tmpDir; }
php
{ "resource": "" }
q7836
UrlBuilding.urlAbsPartAndSplit
train
protected function urlAbsPartAndSplit (\MvcCore\IRequest & $request, $resultUrl, & $domainParams, $splitUrl) { $domainParamsFlag = $this->flags[1]; $basePathInReverse = FALSE; if ($domainParamsFlag >= static::FLAG_HOST_BASEPATH) { $basePathInReverse = TRUE; $domainParamsFlag -= static::FLAG_HOST_BASEPATH; } if ($this->flags[0]) { // route is defined as absolute with possible `%domain%` and other params // process possible replacements in reverse result - `%host%`, `%domain%`, `%tld%` and `%sld%` $this->urlReplaceDomainReverseParams($request, $resultUrl, $domainParams, $domainParamsFlag); // try to find URL position after domain part and after base path part if ($basePathInReverse) { return $this->urlAbsPartAndSplitByReverseBasePath($request, $resultUrl, $domainParams, $splitUrl); } else { return $this->urlAbsPartAndSplitByRequestedBasePath($request, $resultUrl, $splitUrl); } } else { // route is not defined as absolute, there could be only flag // in domain params array to complete absolute URL by developer // and there could be also `basePath` param defined. return $this->urlAbsPartAndSplitByGlobalSwitchOrBasePath( $request, $resultUrl, $domainParams, $domainParamsFlag, $splitUrl ); } }
php
{ "resource": "" }
q7837
UrlBuilding.urlAbsPartAndSplitByReverseBasePath
train
protected function urlAbsPartAndSplitByReverseBasePath (\MvcCore\IRequest & $request, $resultUrl, & $domainParams, $splitUrl) { $doubleSlashPos = mb_strpos($resultUrl, '//'); $doubleSlashPos = $doubleSlashPos === FALSE ? 0 : $doubleSlashPos + 2; $router = & $this->router; $basePathPlaceHolderPos = mb_strpos($resultUrl, static::PLACEHOLDER_BASEPATH, $doubleSlashPos); if ($basePathPlaceHolderPos === FALSE) { return $this->urlAbsPartAndSplitByRequestedBasePath( $request, $resultUrl, $splitUrl ); } $pathPart = mb_substr($resultUrl, $basePathPlaceHolderPos + mb_strlen(static::PLACEHOLDER_BASEPATH)); $pathPart = str_replace('//', '/', $pathPart); $basePart = mb_substr($resultUrl, 0, $basePathPlaceHolderPos); $basePathParamName = $router::URL_PARAM_BASEPATH; $basePart .= isset($domainParams[$basePathParamName]) ? $domainParams[$basePathParamName] : $request->GetBasePath(); if ($this->flags[0] === static::FLAG_SCHEME_ANY) $basePart = $request->GetScheme() . $basePart; if ($splitUrl) return [$basePart, $pathPart]; return [$basePart . $pathPart]; }
php
{ "resource": "" }
q7838
UrlBuilding.urlAbsPartAndSplitByRequestedBasePath
train
protected function urlAbsPartAndSplitByRequestedBasePath (\MvcCore\IRequest & $request, $resultUrl, $splitUrl) { $doubleSlashPos = mb_strpos($resultUrl, '//'); $doubleSlashPos = $doubleSlashPos === FALSE ? 0 : $doubleSlashPos + 2; if (!$splitUrl) { $resultSchemePart = mb_substr($resultUrl, 0, $doubleSlashPos); $resultAfterScheme = mb_substr($resultUrl, $doubleSlashPos); $resultAfterScheme = str_replace('//', '/', $resultAfterScheme); if ($this->flags[0] === static::FLAG_SCHEME_ANY) { $resultUrl = $request->GetScheme() . '//' . $resultAfterScheme; } else { $resultUrl = $resultSchemePart . $resultAfterScheme; } return [$resultUrl]; } else { $nextSlashPos = mb_strpos($resultUrl, '/', $doubleSlashPos); if ($nextSlashPos === FALSE) { $queryStringPos = mb_strpos($resultUrl, '?', $doubleSlashPos); $baseUrlPartEndPos = $queryStringPos === FALSE ? mb_strlen($resultUrl) : $queryStringPos; } else { $baseUrlPartEndPos = $nextSlashPos; } $requestedBasePath = $request->GetBasePath(); $basePathLength = mb_strlen($requestedBasePath); if ($basePathLength > 0) { $basePathPos = mb_strpos($resultUrl, $requestedBasePath, $baseUrlPartEndPos); if ($basePathPos === $baseUrlPartEndPos) $baseUrlPartEndPos += $basePathLength; } $basePart = mb_substr($resultUrl, 0, $baseUrlPartEndPos); if ($this->flags[0] === static::FLAG_SCHEME_ANY) $basePart = $request->GetScheme() . $basePart; $pathAndQueryPart = str_replace('//', '/', mb_substr($resultUrl, $baseUrlPartEndPos)); return [$basePart, $pathAndQueryPart]; } }
php
{ "resource": "" }
q7839
Avatar.removeUserMetaKey
train
public function removeUserMetaKey( $user_meta_key ) { $filter = function( $meta_key ) use ( $user_meta_key ) { return $meta_key !== $user_meta_key; }; $this->avatar_user_meta_keys = array_filter( $this->avatar_user_meta_keys, $filter ); }
php
{ "resource": "" }
q7840
Avatar.idOrEmailToId
train
protected function idOrEmailToId( $id_or_email ) { if ( is_a( $id_or_email, WP_Comment::class ) ) { return intval( $id_or_email->user_id ); } if ( ! is_numeric( $id_or_email ) ) { $user = get_user_by( 'email', $id_or_email ); if ( $user ) { return intval( $user->ID ); } } return strval( $id_or_email ); }
php
{ "resource": "" }
q7841
Avatar.getAttachmentFallbackChain
train
protected function getAttachmentFallbackChain( $user_id ) { $chain = []; foreach ( $this->avatar_user_meta_keys as $user_meta_key ) { $attachment_id = get_user_meta( $user_id, $user_meta_key, true ); if ( is_numeric( $attachment_id ) ) { $chain[] = intval( $attachment_id ); } } if ( $this->default_avatar_id !== 0 ) { $chain[] = $this->default_avatar_id; } return $chain; }
php
{ "resource": "" }
q7842
Avatar.getAvatarUrl
train
protected function getAvatarUrl( $id, $size ) { $attachments_fallback_chain = $this->getAttachmentFallbackChain( $id ); foreach ( $attachments_fallback_chain as $attachment_id ) { $image = wp_get_attachment_image_src( $attachment_id, $size ); if ( ! empty( $image ) ) { return $image[0]; } } return null; }
php
{ "resource": "" }
q7843
Avatar.filterAvatar
train
public function filterAvatar( $url, $id_or_email, $args ) { if ( ! empty( $args['force_default'] ) ) { return $url; } if ( $this->default_avatar_id === 0 && empty( $this->avatar_user_meta_keys ) ) { return $url; } $id = $this->idOrEmailToId( $id_or_email ); if ( is_numeric( $id ) ) { $filtered_url = $this->getAvatarUrl( (int) $id, $this->getSize( $args ) ); if ( $filtered_url !== null ) { $url = $filtered_url; } } return $url; }
php
{ "resource": "" }
q7844
Server.collection
train
public function collection(string $collection, ?string $format = null) : string { list($collection, $extension) = preg_split('/\.(css|js)/', $collection, 2, PREG_SPLIT_DELIM_CAPTURE); $group = $extension == 'css' ? 'stylesheets' : 'javascripts'; return $this->serve($collection, $group, $format); }
php
{ "resource": "" }
q7845
Server.stylesheets
train
public function stylesheets(string $collection, ?string $format = null) : string { return $this->serve($collection, 'stylesheets', $format); }
php
{ "resource": "" }
q7846
Server.javascripts
train
public function javascripts(string $collection, ?string $format = null) : string { return $this->serve($collection, 'javascripts', $format); }
php
{ "resource": "" }
q7847
Server.serve
train
public function serve(string $collection, string $group, ?string $format = null) : string { if ( ! isset($this->app['basset'][$collection])) { return '<!-- Basset could not find collection: '.$collection.' -->'; } // Get the collection instance from the array of collections. This instance will be used // throughout the building process to fetch assets and compare against the stored // manfiest of fingerprints. $collection = $this->app['basset'][$collection]; if ($this->runningInProduction() and $this->app['basset.manifest']->has($collection)) { if ($this->app['basset.manifest']->get($collection)->hasProductionFingerprint($group)) { return $this->serveProductionCollection($collection, $group, $format); } } return $this->serveDevelopmentCollection($collection, $group, $format); }
php
{ "resource": "" }
q7848
Server.serveProductionCollection
train
protected function serveProductionCollection(Collection $collection, string $group, ?string $format) : string { $entry = $this->getCollectionEntry($collection); $fingerprint = $entry->getProductionFingerprint($group); $production = $this->{'create'.studly_case($group).'Element'}($this->prefixBuildPath($fingerprint), $format); return $this->formatResponse($this->serveRawAssets($collection, $group, $format), $production); }
php
{ "resource": "" }
q7849
Server.serveDevelopmentCollection
train
protected function serveDevelopmentCollection(Collection $collection, string $group, ?string $format) : string { $identifier = $collection->getIdentifier(); // Before we fetch the collections manifest entry we'll try to build the collection // again if there is anything outstanding. This doesn't have a huge impact on // page loads time like trying to dynamically serve each asset. $this->tryDevelopmentBuild($collection, $group); $entry = $this->getCollectionEntry($collection); $responses = array(); foreach ($collection->getAssetsWithRaw($group) as $asset) { if ( ! $asset->isRaw() and $path = $entry->getDevelopmentAsset($asset)) { $path = $this->prefixBuildPath($identifier.'/'.$path); } else { $path = $asset->getRelativePath(); } $responses[] = $this->{'create'.studly_case($group).'Element'}($path, $format); } return $this->formatResponse($responses); }
php
{ "resource": "" }
q7850
Server.serveRawAssets
train
protected function serveRawAssets(Collection $collection, string $group, ?string $format) : array { $responses = array(); foreach ($collection->getAssetsOnlyRaw($group) as $asset) { $path = $asset->getRelativePath(); $responses[] = $this->{'create'.studly_case($group).'Element'}($path, $format); } return $responses; }
php
{ "resource": "" }
q7851
Server.formatResponse
train
protected function formatResponse() : string { $responses = array(); foreach (func_get_args() as $response) { $responses = array_merge($responses, (array) $response); } return array_to_newlines($responses); }
php
{ "resource": "" }
q7852
Server.tryDevelopmentBuild
train
protected function tryDevelopmentBuild(Collection $collection, string $group) : void { try { $this->app['basset.builder']->buildAsDevelopment($collection, $group); } catch (BuildNotRequiredException $e) {} $this->app['basset.builder.cleaner']->clean($collection->getIdentifier()); }
php
{ "resource": "" }
q7853
Server.prefixBuildPath
train
protected function prefixBuildPath(string $path) : string { if ($buildPath = $this->app['config']->get('basset.build_path')) { $path = "{$buildPath}/{$path}"; } return $path; }
php
{ "resource": "" }
q7854
Server.createStylesheetsElement
train
protected function createStylesheetsElement(string $path, ?string $format) : string { return sprintf($format ?: '<link rel="stylesheet" type="text/css" href="%s" />', $this->buildAssetUrl($path)); }
php
{ "resource": "" }
q7855
Server.createJavascriptsElement
train
protected function createJavascriptsElement(string $path, ?string $format) : string { return sprintf($format ?: '<script src="%s"></script>', $this->buildAssetUrl($path)); }
php
{ "resource": "" }
q7856
Server.buildAssetUrl
train
public function buildAssetUrl(string $path) : string { return starts_with($path, '//') ? $path : $this->app['url']->asset($path); }
php
{ "resource": "" }
q7857
AbstractEnum.all
train
final public static function all() : array { static $all = null; if ($all === null) { foreach ((new \ReflectionClass(get_called_class()))->getConstants() as $constant) { $all[] = new static($constant); } } return $all; }
php
{ "resource": "" }
q7858
Rendering.&
train
public function & Render ($typePath = '', $relativePath = '') { /** @var $this \MvcCore\View */ if (!$typePath) $typePath = static::$scriptsDir; $result = ''; $relativePath = $this->_correctRelativePath( $typePath, $relativePath ); $viewScriptFullPath = static::GetViewScriptFullPath($typePath, $relativePath); if (!file_exists($viewScriptFullPath)) { $selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__; throw new \InvalidArgumentException('['.$selfClass."] Template not found in path: `$viewScriptFullPath`."); } $renderedFullPaths = & $this->__protected['renderedFullPaths']; $renderedFullPaths[] = $viewScriptFullPath; ob_start(); include($viewScriptFullPath); $result = ob_get_clean(); \array_pop($renderedFullPaths); // unset last return $result; }
php
{ "resource": "" }
q7859
AssetFinder.find
train
public function find($name) { $name = $this->config->get("basset.aliases.assets.{$name}", $name); // Spin through an array of methods ordered by the priority of how an asset should be found. // Once we find a non-null path we'll return that path breaking from the loop. foreach (array('RemotelyHosted', 'PackageAsset', 'WorkingDirectory', 'PublicPath', 'AbsolutePath') as $method) { if ($path = $this->{'find'.$method}($name)) { return $path; } } throw new AssetNotFoundException; }
php
{ "resource": "" }
q7860
AssetFinder.findPackageAsset
train
public function findPackageAsset($name) { if (str_contains($name, '::')) { list($namespace, $name) = explode('::', $name); if ( ! isset($this->hints[$namespace])) { return; } $path = $this->prefixPublicPath('packages/'.$this->hints[$namespace].'/'.$name); if ($this->files->exists($path)) { return $path; } } }
php
{ "resource": "" }
q7861
AssetFinder.findWorkingDirectory
train
public function findWorkingDirectory($name) { $path = $this->getWorkingDirectory().'/'.$name; if ($this->withinWorkingDirectory() and $this->files->exists($path)) { return $path; } }
php
{ "resource": "" }
q7862
AssetFinder.findPublicPath
train
public function findPublicPath($name) { $path = $this->prefixPublicPath($name); if ($this->files->exists($path)) { return $path; } }
php
{ "resource": "" }
q7863
AssetFinder.setWorkingDirectory
train
public function setWorkingDirectory($path) { $path = $this->prefixDirectoryStack($path); if ($this->files->exists($path)) { return $this->directoryStack[] = $path; } throw new DirectoryNotFoundException("Directory [{$path}] could not be found."); }
php
{ "resource": "" }
q7864
AssetFinder.prefixDirectoryStack
train
public function prefixDirectoryStack($path) { if ($this->withinWorkingDirectory()) { return rtrim($this->getWorkingDirectory().'/'.ltrim($path, '/'), '/'); } return $this->prefixPublicPath($path); }
php
{ "resource": "" }
q7865
FileSystemAssertTrait.assertDirectoryNotEmpty
train
public static function assertDirectoryNotEmpty($filename, string $message = '') { self::assertThatConstraint($filename, $message, 'assertDirectoryNotEmpty', new LogicalNot(new DirectoryEmptyConstraint())); }
php
{ "resource": "" }
q7866
FileSystemAssertTrait.assertFileIsNotLink
train
public static function assertFileIsNotLink($filename, string $message = '') { self::assertThatConstraint($filename, $message, 'assertFileIsNotLink', new LogicalNot(new FileIsLinkConstraint())); }
php
{ "resource": "" }
q7867
Instancing.constructVarAdvConf
train
protected function constructVarAdvConf (& $advCfg) { $methodParam = static::CONFIG_METHOD; if (isset($advCfg[$methodParam])) $this->method = strtoupper((string) $advCfg[$methodParam]); $redirectParam = static::CONFIG_REDIRECT; if (isset($advCfg[$redirectParam])) $this->redirect = (string) $advCfg[$redirectParam]; $absoluteParam = static::CONFIG_ABSOLUTE; if (isset($advCfg[$absoluteParam])) $this->absolute = (bool) $advCfg[$absoluteParam]; }
php
{ "resource": "" }
q7868
Converters.convertToType
train
protected static function convertToType ($rawValue, $typeStr) { $conversionResult = FALSE; $typeStr = trim($typeStr, '\\'); if ($typeStr == 'DateTime') { $dateTimeFormat = 'Y-m-d H:i:s'; if (is_numeric($rawValue)) { $rawValueStr = str_replace(['+','-','.'], '', strval($rawValue)); $secData = mb_substr($rawValueStr, 0, 10); $dateTimeStr = date($dateTimeFormat, intval($secData)); if (strlen($rawValueStr) > 10) $dateTimeStr .= '.' . mb_substr($rawValueStr, 10); } else { $dateTimeStr = strval($rawValue); if (strpos($dateTimeStr, '-') === FALSE) { $dateTimeFormat = substr($dateTimeFormat, 6); } else if (strpos($dateTimeStr, ':') === FALSE) { $dateTimeFormat = substr($dateTimeFormat, 0, 5); } if (strpos($dateTimeStr, '.') !== FALSE) $dateTimeFormat .= '.u'; } $dateTime = date_create_from_format($dateTimeFormat, $dateTimeStr); if ($dateTime !== FALSE) { $rawValue = $dateTime; $conversionResult = TRUE; } } else { if (settype($rawValue, $typeStr)) $conversionResult = TRUE; } return [$conversionResult, $rawValue]; }
php
{ "resource": "" }
q7869
Converters.getKeyConversionMethods
train
protected static function getKeyConversionMethods ($keysConversionFlags = \MvcCore\IModel::KEYS_CONVERSION_CASE_SENSITIVE) { $flagsAndConversionMethods = [ $keysConversionFlags & \MvcCore\IModel::KEYS_CONVERSION_UNDERSCORES_TO_PASCALCASE => 'keyConversionUnderscoresToPascalcase', $keysConversionFlags & \MvcCore\IModel::KEYS_CONVERSION_UNDERSCORES_TO_CAMELCASE => 'keyConversionUnderscoresToCamelcase', $keysConversionFlags & \MvcCore\IModel::KEYS_CONVERSION_PASCALCASE_TO_UNDERSCORES => 'keyConversionPascalcaseToUnderscores', $keysConversionFlags & \MvcCore\IModel::KEYS_CONVERSION_PASCALCASE_TO_CAMELCASE => 'keyConversionPascalcaseToCamelcase', $keysConversionFlags & \MvcCore\IModel::KEYS_CONVERSION_CAMELCASE_TO_UNDERSCORES => 'keyConversionCamelcaseToUnderscores', $keysConversionFlags & \MvcCore\IModel::KEYS_CONVERSION_CAMELCASE_TO_PASCALCASE => 'keyConversionCamelcaseToPascalcase', /*$keysConversionFlags & \MvcCore\IModel::KEYS_CONVERSION_CASE_SENSITIVE => NULL,*/ $keysConversionFlags & \MvcCore\IModel::KEYS_CONVERSION_CASE_INSENSITIVE => 'keyConversionCaseInsensitive', ]; unset($flagsAndConversionMethods[0]); return $flagsAndConversionMethods; }
php
{ "resource": "" }
q7870
Converters.keyConversionCaseInsensitive
train
protected static function keyConversionCaseInsensitive ($key, & $toolsClass, & $csKeysMap) { $keyPos = stripos($csKeysMap, ','.$key.','); if ($keyPos === FALSE) return $key; return substr($csKeysMap, $keyPos + 1, strlen($key)); }
php
{ "resource": "" }
q7871
Jpeg.isJpegFile
train
public static function isJpegFile($filename) { try { $image = new ImageFile($filename); if (strtolower($image->getMime()) !== @image_type_to_mime_type(IMAGETYPE_JPEG)) { return false; } return true; } catch (\RuntimeException $ex) { return false; } }
php
{ "resource": "" }
q7872
SystemSetting.getPortableType
train
public function getPortableType() { $type = false; switch ($this->getFieldXType()) { case 'modx-combo-template': $type = 'template'; break; case 'modx-combo-source': $type = 'media-source'; break; default: if (isset($this->portable_settings[$this->getFieldKey()])) { $type = $this->portable_settings[$this->getFieldKey()]; } } return $type; }
php
{ "resource": "" }
q7873
SystemSetting.setCoreAccessPoliciesVersion
train
public function setCoreAccessPoliciesVersion($value) { $this->setFieldName('access_policies_version'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7874
SystemSetting.setCoreAllowManagerLoginForgotPassword
train
public function setCoreAllowManagerLoginForgotPassword($value) { $this->setFieldName('allow_manager_login_forgot_password'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7875
SystemSetting.setCoreAllowMultipleEmails
train
public function setCoreAllowMultipleEmails($value) { $this->setFieldName('allow_multiple_emails'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7876
SystemSetting.setCoreAllowTagsInPost
train
public function setCoreAllowTagsInPost($value) { $this->setFieldName('allow_tags_in_post'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7877
SystemSetting.setCoreAnonymousSessions
train
public function setCoreAnonymousSessions($value) { $this->setFieldName('anonymous_sessions'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7878
SystemSetting.setCoreArchiveWith
train
public function setCoreArchiveWith($value) { $this->setFieldName('archive_with'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7879
SystemSetting.setCoreAutoCheckPkgUpdates
train
public function setCoreAutoCheckPkgUpdates($value) { $this->setFieldName('auto_check_pkg_updates'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7880
SystemSetting.setCoreAutoCheckPkgUpdatesCacheExpire
train
public function setCoreAutoCheckPkgUpdatesCacheExpire($value) { $this->setFieldName('auto_check_pkg_updates_cache_expire'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7881
SystemSetting.setCoreAutoIsfolder
train
public function setCoreAutoIsfolder($value) { $this->setFieldName('auto_isfolder'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7882
SystemSetting.setCoreAutoMenuindex
train
public function setCoreAutoMenuindex($value) { $this->setFieldName('auto_menuindex'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7883
SystemSetting.setCoreAutomaticAlias
train
public function setCoreAutomaticAlias($value) { $this->setFieldName('automatic_alias'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7884
SystemSetting.setCoreBaseHelpUrl
train
public function setCoreBaseHelpUrl($value) { $this->setFieldName('base_help_url'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7885
SystemSetting.setCoreCacheAliasMap
train
public function setCoreCacheAliasMap($value) { $this->setFieldName('cache_alias_map'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7886
SystemSetting.setCoreCacheContextSettings
train
public function setCoreCacheContextSettings($value) { $this->setFieldName('cache_context_settings'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7887
SystemSetting.setCoreCacheDb
train
public function setCoreCacheDb($value) { $this->setFieldName('cache_db'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7888
SystemSetting.setCoreCacheDbSession
train
public function setCoreCacheDbSession($value) { $this->setFieldName('cache_db_session'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7889
SystemSetting.setCoreCacheDefault
train
public function setCoreCacheDefault($value) { $this->setFieldName('cache_default'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7890
SystemSetting.setCoreCacheDisabled
train
public function setCoreCacheDisabled($value) { $this->setFieldName('cache_disabled'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7891
SystemSetting.setCoreCacheFormat
train
public function setCoreCacheFormat($value) { $this->setFieldName('cache_format'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7892
SystemSetting.setCoreCacheHandler
train
public function setCoreCacheHandler($value) { $this->setFieldName('cache_handler'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7893
SystemSetting.setCoreCacheLangJs
train
public function setCoreCacheLangJs($value) { $this->setFieldName('cache_lang_js'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7894
SystemSetting.setCoreCacheLexiconTopics
train
public function setCoreCacheLexiconTopics($value) { $this->setFieldName('cache_lexicon_topics'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7895
SystemSetting.setCoreCacheNoncoreLexiconTopics
train
public function setCoreCacheNoncoreLexiconTopics($value) { $this->setFieldName('cache_noncore_lexicon_topics'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7896
SystemSetting.setCoreCacheResource
train
public function setCoreCacheResource($value) { $this->setFieldName('cache_resource'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7897
SystemSetting.setCoreCacheSystemSettings
train
public function setCoreCacheSystemSettings($value) { $this->setFieldName('cache_system_settings'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7898
SystemSetting.setCoreClearCacheRefreshTrees
train
public function setCoreClearCacheRefreshTrees($value) { $this->setFieldName('clear_cache_refresh_trees'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }
q7899
SystemSetting.setCoreCompressCss
train
public function setCoreCompressCss($value) { $this->setFieldName('compress_css'); $this->loadObject(true); $this->setFieldValue($value); return $this; }
php
{ "resource": "" }