id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
28,700
php-deal/framework
src/Contract/Fetcher/Parent/AbstractFetcher.php
AbstractFetcher.filterContractAnnotation
protected function filterContractAnnotation(array $annotations): array { $contractAnnotations = []; foreach ($annotations as $annotation) { $annotationClass = \get_class($annotation); if (\in_array($annotationClass, $this->expectedAnnotationTypes, true)) { $contractAnnotations[] = $annotation; } } return $contractAnnotations; }
php
protected function filterContractAnnotation(array $annotations): array { $contractAnnotations = []; foreach ($annotations as $annotation) { $annotationClass = \get_class($annotation); if (\in_array($annotationClass, $this->expectedAnnotationTypes, true)) { $contractAnnotations[] = $annotation; } } return $contractAnnotations; }
[ "protected", "function", "filterContractAnnotation", "(", "array", "$", "annotations", ")", ":", "array", "{", "$", "contractAnnotations", "=", "[", "]", ";", "foreach", "(", "$", "annotations", "as", "$", "annotation", ")", "{", "$", "annotationClass", "=", "\\", "get_class", "(", "$", "annotation", ")", ";", "if", "(", "\\", "in_array", "(", "$", "annotationClass", ",", "$", "this", "->", "expectedAnnotationTypes", ",", "true", ")", ")", "{", "$", "contractAnnotations", "[", "]", "=", "$", "annotation", ";", "}", "}", "return", "$", "contractAnnotations", ";", "}" ]
Performs filtering of annotations by the requested class name @param array $annotations @return array
[ "Performs", "filtering", "of", "annotations", "by", "the", "requested", "class", "name" ]
31ff0b8fe6c76e4df8cc60b4a0da68a0177b7d43
https://github.com/php-deal/framework/blob/31ff0b8fe6c76e4df8cc60b4a0da68a0177b7d43/src/Contract/Fetcher/Parent/AbstractFetcher.php#L45-L58
28,701
smartboxgroup/integration-framework-bundle
Core/Processors/ControlFlow/ThrowException.php
ThrowException.doProcess
protected function doProcess(Exchange $exchange, SerializableArray $processingContext) { if (empty($this->exceptionClass)) { throw new \RuntimeException('Exception class not found'); } /** @var ExchangeAwareInterface $exception */ $exception = new $this->exceptionClass($this->exceptionMessage); throw $exception; }
php
protected function doProcess(Exchange $exchange, SerializableArray $processingContext) { if (empty($this->exceptionClass)) { throw new \RuntimeException('Exception class not found'); } /** @var ExchangeAwareInterface $exception */ $exception = new $this->exceptionClass($this->exceptionMessage); throw $exception; }
[ "protected", "function", "doProcess", "(", "Exchange", "$", "exchange", ",", "SerializableArray", "$", "processingContext", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "exceptionClass", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Exception class not found'", ")", ";", "}", "/** @var ExchangeAwareInterface $exception */", "$", "exception", "=", "new", "$", "this", "->", "exceptionClass", "(", "$", "this", "->", "exceptionMessage", ")", ";", "throw", "$", "exception", ";", "}" ]
The ThrowException will create an exception of the type specified in Ref. @param Exchange $exchange @return bool @throws ExchangeAwareInterface
[ "The", "ThrowException", "will", "create", "an", "exception", "of", "the", "type", "specified", "in", "Ref", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Core/Processors/ControlFlow/ThrowException.php#L82-L92
28,702
cedx/coveralls.php
lib/Configuration.php
Configuration.fromYaml
static function fromYaml(string $document): self { if (!mb_strlen($document)) throw new \InvalidArgumentException('The specified YAML document is empty.'); try { $yaml = Yaml::parse($document); if (!is_array($yaml)) throw new \InvalidArgumentException('The specified YAML document is invalid.'); return new static($yaml); } catch (ParseException $e) { throw new \InvalidArgumentException('The specified YAML document is invalid.', 0, $e); } }
php
static function fromYaml(string $document): self { if (!mb_strlen($document)) throw new \InvalidArgumentException('The specified YAML document is empty.'); try { $yaml = Yaml::parse($document); if (!is_array($yaml)) throw new \InvalidArgumentException('The specified YAML document is invalid.'); return new static($yaml); } catch (ParseException $e) { throw new \InvalidArgumentException('The specified YAML document is invalid.', 0, $e); } }
[ "static", "function", "fromYaml", "(", "string", "$", "document", ")", ":", "self", "{", "if", "(", "!", "mb_strlen", "(", "$", "document", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'The specified YAML document is empty.'", ")", ";", "try", "{", "$", "yaml", "=", "Yaml", "::", "parse", "(", "$", "document", ")", ";", "if", "(", "!", "is_array", "(", "$", "yaml", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'The specified YAML document is invalid.'", ")", ";", "return", "new", "static", "(", "$", "yaml", ")", ";", "}", "catch", "(", "ParseException", "$", "e", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The specified YAML document is invalid.'", ",", "0", ",", "$", "e", ")", ";", "}", "}" ]
Creates a new configuration from the specified YAML document. @param string $document A YAML document providing configuration parameters. @return static The instance corresponding to the specified YAML document. @throws \InvalidArgumentException The specified document is invalid.
[ "Creates", "a", "new", "configuration", "from", "the", "specified", "YAML", "document", "." ]
c196de0f92e06d5143ba90ebab18c8e384316cc0
https://github.com/cedx/coveralls.php/blob/c196de0f92e06d5143ba90ebab18c8e384316cc0/lib/Configuration.php#L89-L101
28,703
cedx/coveralls.php
lib/Configuration.php
Configuration.loadDefaults
static function loadDefaults(string $coverallsFile = '.coveralls.yml'): self { $defaults = static::fromEnvironment(); try { $defaults->merge(static::fromYaml((string) @file_get_contents($coverallsFile))); return $defaults; } catch (\Throwable $e) { return $defaults; } }
php
static function loadDefaults(string $coverallsFile = '.coveralls.yml'): self { $defaults = static::fromEnvironment(); try { $defaults->merge(static::fromYaml((string) @file_get_contents($coverallsFile))); return $defaults; } catch (\Throwable $e) { return $defaults; } }
[ "static", "function", "loadDefaults", "(", "string", "$", "coverallsFile", "=", "'.coveralls.yml'", ")", ":", "self", "{", "$", "defaults", "=", "static", "::", "fromEnvironment", "(", ")", ";", "try", "{", "$", "defaults", "->", "merge", "(", "static", "::", "fromYaml", "(", "(", "string", ")", "@", "file_get_contents", "(", "$", "coverallsFile", ")", ")", ")", ";", "return", "$", "defaults", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "return", "$", "defaults", ";", "}", "}" ]
Loads the default configuration. The default values are read from the environment variables and an optional `.coveralls.yml` file. @param string $coverallsFile The path to the `.coveralls.yml` file. Defaults to the file found in the current directory. @return Configuration The default configuration.
[ "Loads", "the", "default", "configuration", ".", "The", "default", "values", "are", "read", "from", "the", "environment", "variables", "and", "an", "optional", ".", "coveralls", ".", "yml", "file", "." ]
c196de0f92e06d5143ba90ebab18c8e384316cc0
https://github.com/cedx/coveralls.php/blob/c196de0f92e06d5143ba90ebab18c8e384316cc0/lib/Configuration.php#L109-L120
28,704
cedx/coveralls.php
lib/Configuration.php
Configuration.merge
function merge(self $config): void { foreach ($config as $key => $value) $this[$key] = $value; }
php
function merge(self $config): void { foreach ($config as $key => $value) $this[$key] = $value; }
[ "function", "merge", "(", "self", "$", "config", ")", ":", "void", "{", "foreach", "(", "$", "config", "as", "$", "key", "=>", "$", "value", ")", "$", "this", "[", "$", "key", "]", "=", "$", "value", ";", "}" ]
Adds all entries of the specified configuration to this one. @param self $config The configuration to be merged.
[ "Adds", "all", "entries", "of", "the", "specified", "configuration", "to", "this", "one", "." ]
c196de0f92e06d5143ba90ebab18c8e384316cc0
https://github.com/cedx/coveralls.php/blob/c196de0f92e06d5143ba90ebab18c8e384316cc0/lib/Configuration.php#L158-L160
28,705
netgen/site-bundle
bundle/Menu/Factory/LocationFactory.php
LocationFactory.getExtension
protected function getExtension(Location $location): ExtensionInterface { foreach ($this->extensions as $extension) { if ($extension->matches($location)) { return $extension; } } return $this->fallbackExtension; }
php
protected function getExtension(Location $location): ExtensionInterface { foreach ($this->extensions as $extension) { if ($extension->matches($location)) { return $extension; } } return $this->fallbackExtension; }
[ "protected", "function", "getExtension", "(", "Location", "$", "location", ")", ":", "ExtensionInterface", "{", "foreach", "(", "$", "this", "->", "extensions", "as", "$", "extension", ")", "{", "if", "(", "$", "extension", "->", "matches", "(", "$", "location", ")", ")", "{", "return", "$", "extension", ";", "}", "}", "return", "$", "this", "->", "fallbackExtension", ";", "}" ]
Returns the first extension that matches the provided location. If none match, fallback extension is returned.
[ "Returns", "the", "first", "extension", "that", "matches", "the", "provided", "location", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Menu/Factory/LocationFactory.php#L73-L82
28,706
netgen/site-bundle
bundle/DependencyInjection/Compiler/ContentDownloadUrlGeneratorPass.php
ContentDownloadUrlGeneratorPass.process
public function process(ContainerBuilder $container): void { if ($container->has('ezpublish.fieldType.ease.download_url_generator')) { $container ->findDefinition('ezpublish.fieldType.ezbinarybase.download_url_generator') ->setClass(ContentDownloadUrlGenerator::class); } }
php
public function process(ContainerBuilder $container): void { if ($container->has('ezpublish.fieldType.ease.download_url_generator')) { $container ->findDefinition('ezpublish.fieldType.ezbinarybase.download_url_generator') ->setClass(ContentDownloadUrlGenerator::class); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", ":", "void", "{", "if", "(", "$", "container", "->", "has", "(", "'ezpublish.fieldType.ease.download_url_generator'", ")", ")", "{", "$", "container", "->", "findDefinition", "(", "'ezpublish.fieldType.ezbinarybase.download_url_generator'", ")", "->", "setClass", "(", "ContentDownloadUrlGenerator", "::", "class", ")", ";", "}", "}" ]
Override content download URL generator to generate download links to files with Netgen Site download route.
[ "Override", "content", "download", "URL", "generator", "to", "generate", "download", "links", "to", "files", "with", "Netgen", "Site", "download", "route", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/DependencyInjection/Compiler/ContentDownloadUrlGeneratorPass.php#L17-L24
28,707
cedx/coveralls.php
lib/SourceFile.php
SourceFile.fromJson
static function fromJson(object $map): self { return new static( isset($map->name) && is_string($map->name) ? $map->name : '', isset($map->source_digest) && is_string($map->source_digest) ? $map->source_digest : '', isset($map->source) && is_string($map->source) ? $map->source : '', isset($map->coverage) && is_array($map->coverage) ? $map->coverage : [] ); }
php
static function fromJson(object $map): self { return new static( isset($map->name) && is_string($map->name) ? $map->name : '', isset($map->source_digest) && is_string($map->source_digest) ? $map->source_digest : '', isset($map->source) && is_string($map->source) ? $map->source : '', isset($map->coverage) && is_array($map->coverage) ? $map->coverage : [] ); }
[ "static", "function", "fromJson", "(", "object", "$", "map", ")", ":", "self", "{", "return", "new", "static", "(", "isset", "(", "$", "map", "->", "name", ")", "&&", "is_string", "(", "$", "map", "->", "name", ")", "?", "$", "map", "->", "name", ":", "''", ",", "isset", "(", "$", "map", "->", "source_digest", ")", "&&", "is_string", "(", "$", "map", "->", "source_digest", ")", "?", "$", "map", "->", "source_digest", ":", "''", ",", "isset", "(", "$", "map", "->", "source", ")", "&&", "is_string", "(", "$", "map", "->", "source", ")", "?", "$", "map", "->", "source", ":", "''", ",", "isset", "(", "$", "map", "->", "coverage", ")", "&&", "is_array", "(", "$", "map", "->", "coverage", ")", "?", "$", "map", "->", "coverage", ":", "[", "]", ")", ";", "}" ]
Creates a new source file from the specified JSON map. @param object $map A JSON map representing a source file. @return static The instance corresponding to the specified JSON map.
[ "Creates", "a", "new", "source", "file", "from", "the", "specified", "JSON", "map", "." ]
c196de0f92e06d5143ba90ebab18c8e384316cc0
https://github.com/cedx/coveralls.php/blob/c196de0f92e06d5143ba90ebab18c8e384316cc0/lib/SourceFile.php#L38-L45
28,708
adminarchitect/options
src/Terranet/Options/Drivers/DatabaseOptionsDriver.php
DatabaseOptionsDriver.fetchAll
public function fetchAll(string $group = null) { if (static::$options === null) { static::$options = $this ->createModel() ->when($group, function ($query, $group) { return $query->where('group', $group); }) ->orderBy('group', 'asc') ->orderBy('key', 'asc') ->get(); } return static::$options; }
php
public function fetchAll(string $group = null) { if (static::$options === null) { static::$options = $this ->createModel() ->when($group, function ($query, $group) { return $query->where('group', $group); }) ->orderBy('group', 'asc') ->orderBy('key', 'asc') ->get(); } return static::$options; }
[ "public", "function", "fetchAll", "(", "string", "$", "group", "=", "null", ")", "{", "if", "(", "static", "::", "$", "options", "===", "null", ")", "{", "static", "::", "$", "options", "=", "$", "this", "->", "createModel", "(", ")", "->", "when", "(", "$", "group", ",", "function", "(", "$", "query", ",", "$", "group", ")", "{", "return", "$", "query", "->", "where", "(", "'group'", ",", "$", "group", ")", ";", "}", ")", "->", "orderBy", "(", "'group'", ",", "'asc'", ")", "->", "orderBy", "(", "'key'", ",", "'asc'", ")", "->", "get", "(", ")", ";", "}", "return", "static", "::", "$", "options", ";", "}" ]
Fetch all options @param null|string $group @return mixed
[ "Fetch", "all", "options" ]
b3b43dc3bfc34710143c8e34a79603e925f07fd2
https://github.com/adminarchitect/options/blob/b3b43dc3bfc34710143c8e34a79603e925f07fd2/src/Terranet/Options/Drivers/DatabaseOptionsDriver.php#L40-L54
28,709
adminarchitect/options
src/Terranet/Options/Drivers/DatabaseOptionsDriver.php
DatabaseOptionsDriver.find
public function find($name, $default = null) { foreach ($this->fetchAll() as $option) { if ($option->key == $name) { return $option->value; } } return $default; }
php
public function find($name, $default = null) { foreach ($this->fetchAll() as $option) { if ($option->key == $name) { return $option->value; } } return $default; }
[ "public", "function", "find", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "foreach", "(", "$", "this", "->", "fetchAll", "(", ")", "as", "$", "option", ")", "{", "if", "(", "$", "option", "->", "key", "==", "$", "name", ")", "{", "return", "$", "option", "->", "value", ";", "}", "}", "return", "$", "default", ";", "}" ]
Find an option by name @param $name @param $default @return mixed
[ "Find", "an", "option", "by", "name" ]
b3b43dc3bfc34710143c8e34a79603e925f07fd2
https://github.com/adminarchitect/options/blob/b3b43dc3bfc34710143c8e34a79603e925f07fd2/src/Terranet/Options/Drivers/DatabaseOptionsDriver.php#L63-L72
28,710
smartboxgroup/integration-framework-bundle
Tools/Mapper/Mapper.php
Mapper.dateFromFormat
public function dateFromFormat($format, $date) { if (!empty($format) && !empty($date)) { return \DateTime::createFromFormat($format, $date); } }
php
public function dateFromFormat($format, $date) { if (!empty($format) && !empty($date)) { return \DateTime::createFromFormat($format, $date); } }
[ "public", "function", "dateFromFormat", "(", "$", "format", ",", "$", "date", ")", "{", "if", "(", "!", "empty", "(", "$", "format", ")", "&&", "!", "empty", "(", "$", "date", ")", ")", "{", "return", "\\", "DateTime", "::", "createFromFormat", "(", "$", "format", ",", "$", "date", ")", ";", "}", "}" ]
Convert a formatted string to a date. The portions of the generated time not provided in format, will be set to corresponding values from the Unix epoch. Ex: dateFromFormat('d/m/Y', '23/03/2018'). @param string $format @param string $date @return bool|\DateTime
[ "Convert", "a", "formatted", "string", "to", "a", "date", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Tools/Mapper/Mapper.php#L230-L235
28,711
smartboxgroup/integration-framework-bundle
Tools/Mapper/Mapper.php
Mapper.flattenArrayByKey
public function flattenArrayByKey(array $data, $key) { $array = []; foreach ($data as $value) { if (is_array($value) && isset($value[$key])) { $array[] = $value[$key]; } } return $array; }
php
public function flattenArrayByKey(array $data, $key) { $array = []; foreach ($data as $value) { if (is_array($value) && isset($value[$key])) { $array[] = $value[$key]; } } return $array; }
[ "public", "function", "flattenArrayByKey", "(", "array", "$", "data", ",", "$", "key", ")", "{", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "&&", "isset", "(", "$", "value", "[", "$", "key", "]", ")", ")", "{", "$", "array", "[", "]", "=", "$", "value", "[", "$", "key", "]", ";", "}", "}", "return", "$", "array", ";", "}" ]
Flatten an array by key. @param array $data The array to flatten @param string $key The common key @return array
[ "Flatten", "an", "array", "by", "key", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Tools/Mapper/Mapper.php#L322-L332
28,712
smartboxgroup/integration-framework-bundle
Tools/Mapper/Mapper.php
Mapper.serializeWithGroup
public function serializeWithGroup($data, $format, $group) { $serializer = $this->evaluator->getSerializer(); return $serializer->serialize($data, $format, SerializationContext::create()->setGroups([$group])); }
php
public function serializeWithGroup($data, $format, $group) { $serializer = $this->evaluator->getSerializer(); return $serializer->serialize($data, $format, SerializationContext::create()->setGroups([$group])); }
[ "public", "function", "serializeWithGroup", "(", "$", "data", ",", "$", "format", ",", "$", "group", ")", "{", "$", "serializer", "=", "$", "this", "->", "evaluator", "->", "getSerializer", "(", ")", ";", "return", "$", "serializer", "->", "serialize", "(", "$", "data", ",", "$", "format", ",", "SerializationContext", "::", "create", "(", ")", "->", "setGroups", "(", "[", "$", "group", "]", ")", ")", ";", "}" ]
Serialize the given datas into the expected format with a group. @param $data @param $format @param $group @return string
[ "Serialize", "the", "given", "datas", "into", "the", "expected", "format", "with", "a", "group", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Tools/Mapper/Mapper.php#L369-L374
28,713
smartboxgroup/integration-framework-bundle
Tools/Mapper/Mapper.php
Mapper.wordWrap
public function wordWrap($string, $length, $section) { $wrapped = wordwrap($string, $length, '\mapperDelimiter', true); $lines = explode('\mapperDelimiter', $wrapped); --$section; $result = ''; if (isset($lines[$section])) { $result = $lines[$section]; } return $result; }
php
public function wordWrap($string, $length, $section) { $wrapped = wordwrap($string, $length, '\mapperDelimiter', true); $lines = explode('\mapperDelimiter', $wrapped); --$section; $result = ''; if (isset($lines[$section])) { $result = $lines[$section]; } return $result; }
[ "public", "function", "wordWrap", "(", "$", "string", ",", "$", "length", ",", "$", "section", ")", "{", "$", "wrapped", "=", "wordwrap", "(", "$", "string", ",", "$", "length", ",", "'\\mapperDelimiter'", ",", "true", ")", ";", "$", "lines", "=", "explode", "(", "'\\mapperDelimiter'", ",", "$", "wrapped", ")", ";", "--", "$", "section", ";", "$", "result", "=", "''", ";", "if", "(", "isset", "(", "$", "lines", "[", "$", "section", "]", ")", ")", "{", "$", "result", "=", "$", "lines", "[", "$", "section", "]", ";", "}", "return", "$", "result", ";", "}" ]
Return the n-th section of the given string splitted by piece of the given length. @param string $string @param int $length @param int $section @return string
[ "Return", "the", "n", "-", "th", "section", "of", "the", "given", "string", "splitted", "by", "piece", "of", "the", "given", "length", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Tools/Mapper/Mapper.php#L385-L397
28,714
IconoCoders/otp-simple-sdk
Source/SimpleBase.php
SimpleBase.merchantByCurrency
public function merchantByCurrency($config = array(), $currency = '') { if (!is_array($config)) { $this->errorMessage[] = 'config is not array!'; return false; } elseif (count($config) == 0) { $this->errorMessage[] = 'Empty config array!'; return false; } $config['CURRENCY'] = str_replace(' ', '', $currency); $variables = array('MERCHANT', 'SECRET_KEY'); foreach ($variables as $var) { if (isset($config[$currency . '_' . $var])) { $config[$var] = str_replace(' ', '', $config[$currency . '_' . $var]); } elseif (!isset($config[$currency . '_' . $var])) { $config[$var] = 'MISSING_' . $var; $this->errorMessage[] = 'Missing ' . $var; } } if ($this->debug) { foreach ($config as $configKey => $configValue) { if (strpos($configKey, 'SECRET_KEY') !== true) { $this->debugMessage[] = $configKey . '=' . $configValue; } } } return $config; }
php
public function merchantByCurrency($config = array(), $currency = '') { if (!is_array($config)) { $this->errorMessage[] = 'config is not array!'; return false; } elseif (count($config) == 0) { $this->errorMessage[] = 'Empty config array!'; return false; } $config['CURRENCY'] = str_replace(' ', '', $currency); $variables = array('MERCHANT', 'SECRET_KEY'); foreach ($variables as $var) { if (isset($config[$currency . '_' . $var])) { $config[$var] = str_replace(' ', '', $config[$currency . '_' . $var]); } elseif (!isset($config[$currency . '_' . $var])) { $config[$var] = 'MISSING_' . $var; $this->errorMessage[] = 'Missing ' . $var; } } if ($this->debug) { foreach ($config as $configKey => $configValue) { if (strpos($configKey, 'SECRET_KEY') !== true) { $this->debugMessage[] = $configKey . '=' . $configValue; } } } return $config; }
[ "public", "function", "merchantByCurrency", "(", "$", "config", "=", "array", "(", ")", ",", "$", "currency", "=", "''", ")", "{", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "$", "this", "->", "errorMessage", "[", "]", "=", "'config is not array!'", ";", "return", "false", ";", "}", "elseif", "(", "count", "(", "$", "config", ")", "==", "0", ")", "{", "$", "this", "->", "errorMessage", "[", "]", "=", "'Empty config array!'", ";", "return", "false", ";", "}", "$", "config", "[", "'CURRENCY'", "]", "=", "str_replace", "(", "' '", ",", "''", ",", "$", "currency", ")", ";", "$", "variables", "=", "array", "(", "'MERCHANT'", ",", "'SECRET_KEY'", ")", ";", "foreach", "(", "$", "variables", "as", "$", "var", ")", "{", "if", "(", "isset", "(", "$", "config", "[", "$", "currency", ".", "'_'", ".", "$", "var", "]", ")", ")", "{", "$", "config", "[", "$", "var", "]", "=", "str_replace", "(", "' '", ",", "''", ",", "$", "config", "[", "$", "currency", ".", "'_'", ".", "$", "var", "]", ")", ";", "}", "elseif", "(", "!", "isset", "(", "$", "config", "[", "$", "currency", ".", "'_'", ".", "$", "var", "]", ")", ")", "{", "$", "config", "[", "$", "var", "]", "=", "'MISSING_'", ".", "$", "var", ";", "$", "this", "->", "errorMessage", "[", "]", "=", "'Missing '", ".", "$", "var", ";", "}", "}", "if", "(", "$", "this", "->", "debug", ")", "{", "foreach", "(", "$", "config", "as", "$", "configKey", "=>", "$", "configValue", ")", "{", "if", "(", "strpos", "(", "$", "configKey", ",", "'SECRET_KEY'", ")", "!==", "true", ")", "{", "$", "this", "->", "debugMessage", "[", "]", "=", "$", "configKey", ".", "'='", ".", "$", "configValue", ";", "}", "}", "}", "return", "$", "config", ";", "}" ]
Initialize MERCHANT, SECRET_KEY and CURRENCY @param string $config Config array @param string $currency Currency @return array $this->config Initialized config array
[ "Initialize", "MERCHANT", "SECRET_KEY", "and", "CURRENCY" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleBase.php#L107-L137
28,715
IconoCoders/otp-simple-sdk
Source/SimpleBase.php
SimpleBase.processConfig
public function processConfig($config = array()) { foreach (array_keys($config) as $setting) { if (array_key_exists($setting, $this->settings)) { $prop = $this->settings[$setting]; $this->$prop = $config[$setting]; } } }
php
public function processConfig($config = array()) { foreach (array_keys($config) as $setting) { if (array_key_exists($setting, $this->settings)) { $prop = $this->settings[$setting]; $this->$prop = $config[$setting]; } } }
[ "public", "function", "processConfig", "(", "$", "config", "=", "array", "(", ")", ")", "{", "foreach", "(", "array_keys", "(", "$", "config", ")", "as", "$", "setting", ")", "{", "if", "(", "array_key_exists", "(", "$", "setting", ",", "$", "this", "->", "settings", ")", ")", "{", "$", "prop", "=", "$", "this", "->", "settings", "[", "$", "setting", "]", ";", "$", "this", "->", "$", "prop", "=", "$", "config", "[", "$", "setting", "]", ";", "}", "}", "}" ]
Set config options @param array $config Array with config options @return void
[ "Set", "config", "options" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleBase.php#L175-L183
28,716
IconoCoders/otp-simple-sdk
Source/SimpleBase.php
SimpleBase.hmac
protected function hmac($key = '', $data = '') { if ($data == '') { $this->errorMessage[] = 'DATA FOR HMAC: MISSING!'; return false; } if ($key == '') { $this->errorMessage[] = 'KEY FOR HMAC: MISSING!'; return false; } return hash_hmac('md5', $data, trim($key)); }
php
protected function hmac($key = '', $data = '') { if ($data == '') { $this->errorMessage[] = 'DATA FOR HMAC: MISSING!'; return false; } if ($key == '') { $this->errorMessage[] = 'KEY FOR HMAC: MISSING!'; return false; } return hash_hmac('md5', $data, trim($key)); }
[ "protected", "function", "hmac", "(", "$", "key", "=", "''", ",", "$", "data", "=", "''", ")", "{", "if", "(", "$", "data", "==", "''", ")", "{", "$", "this", "->", "errorMessage", "[", "]", "=", "'DATA FOR HMAC: MISSING!'", ";", "return", "false", ";", "}", "if", "(", "$", "key", "==", "''", ")", "{", "$", "this", "->", "errorMessage", "[", "]", "=", "'KEY FOR HMAC: MISSING!'", ";", "return", "false", ";", "}", "return", "hash_hmac", "(", "'md5'", ",", "$", "data", ",", "trim", "(", "$", "key", ")", ")", ";", "}" ]
HMAC HASH creation @param string $key Secret key for encryption @param string $data String to encode @return string HMAC hash
[ "HMAC", "HASH", "creation" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleBase.php#L194-L205
28,717
IconoCoders/otp-simple-sdk
Source/SimpleBase.php
SimpleBase.flatArray
public function flatArray($array = array(), $skip = array()) { if (count($array) == 0) { $this->errorMessage[] = 'FLAT_ARRAY: array for flatArray is empty'; return array(); } $return = array(); foreach ($array as $name => $item) { if (!in_array($name, $skip)) { if (is_array($item)) { foreach ($item as $subItem) { $return[] = $subItem; } } elseif (!is_array($item)) { $return[] = $item; } } } return $return; }
php
public function flatArray($array = array(), $skip = array()) { if (count($array) == 0) { $this->errorMessage[] = 'FLAT_ARRAY: array for flatArray is empty'; return array(); } $return = array(); foreach ($array as $name => $item) { if (!in_array($name, $skip)) { if (is_array($item)) { foreach ($item as $subItem) { $return[] = $subItem; } } elseif (!is_array($item)) { $return[] = $item; } } } return $return; }
[ "public", "function", "flatArray", "(", "$", "array", "=", "array", "(", ")", ",", "$", "skip", "=", "array", "(", ")", ")", "{", "if", "(", "count", "(", "$", "array", ")", "==", "0", ")", "{", "$", "this", "->", "errorMessage", "[", "]", "=", "'FLAT_ARRAY: array for flatArray is empty'", ";", "return", "array", "(", ")", ";", "}", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "name", "=>", "$", "item", ")", "{", "if", "(", "!", "in_array", "(", "$", "name", ",", "$", "skip", ")", ")", "{", "if", "(", "is_array", "(", "$", "item", ")", ")", "{", "foreach", "(", "$", "item", "as", "$", "subItem", ")", "{", "$", "return", "[", "]", "=", "$", "subItem", ";", "}", "}", "elseif", "(", "!", "is_array", "(", "$", "item", ")", ")", "{", "$", "return", "[", "]", "=", "$", "item", ";", "}", "}", "}", "return", "$", "return", ";", "}" ]
Creates a 1-dimension array from a 2-dimension one @param array $array Array to be processed @param array $skip Array of keys to be skipped when creating the new array @return array $return Flat array
[ "Creates", "a", "1", "-", "dimension", "array", "from", "a", "2", "-", "dimension", "one" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleBase.php#L253-L272
28,718
IconoCoders/otp-simple-sdk
Source/SimpleBase.php
SimpleBase.getErrorMessage
public function getErrorMessage() { $message = $this->getDebugMessage(); $message .= '<font color="red">ERROR START</font><br>'; foreach ($this->errorMessage as $items) { $message .= "-----------------------------------------------------------------------------------<br>"; if (is_array($items) || is_object($items)) { $message .= "<pre>"; $message .= $items; $message .= "</pre>"; } elseif (!is_array($items) && !is_object($items)) { $message .= $items . '<br/>'; } $message .= "-----------------------------------------------------------------------------------<br>"; } $message .= '<font color="red">ERROR END</font><br>'; iconv(mb_detect_encoding($message, mb_detect_order(), true), "UTF-8", $message); return $message; }
php
public function getErrorMessage() { $message = $this->getDebugMessage(); $message .= '<font color="red">ERROR START</font><br>'; foreach ($this->errorMessage as $items) { $message .= "-----------------------------------------------------------------------------------<br>"; if (is_array($items) || is_object($items)) { $message .= "<pre>"; $message .= $items; $message .= "</pre>"; } elseif (!is_array($items) && !is_object($items)) { $message .= $items . '<br/>'; } $message .= "-----------------------------------------------------------------------------------<br>"; } $message .= '<font color="red">ERROR END</font><br>'; iconv(mb_detect_encoding($message, mb_detect_order(), true), "UTF-8", $message); return $message; }
[ "public", "function", "getErrorMessage", "(", ")", "{", "$", "message", "=", "$", "this", "->", "getDebugMessage", "(", ")", ";", "$", "message", ".=", "'<font color=\"red\">ERROR START</font><br>'", ";", "foreach", "(", "$", "this", "->", "errorMessage", "as", "$", "items", ")", "{", "$", "message", ".=", "\"-----------------------------------------------------------------------------------<br>\"", ";", "if", "(", "is_array", "(", "$", "items", ")", "||", "is_object", "(", "$", "items", ")", ")", "{", "$", "message", ".=", "\"<pre>\"", ";", "$", "message", ".=", "$", "items", ";", "$", "message", ".=", "\"</pre>\"", ";", "}", "elseif", "(", "!", "is_array", "(", "$", "items", ")", "&&", "!", "is_object", "(", "$", "items", ")", ")", "{", "$", "message", ".=", "$", "items", ".", "'<br/>'", ";", "}", "$", "message", ".=", "\"-----------------------------------------------------------------------------------<br>\"", ";", "}", "$", "message", ".=", "'<font color=\"red\">ERROR END</font><br>'", ";", "iconv", "(", "mb_detect_encoding", "(", "$", "message", ",", "mb_detect_order", "(", ")", ",", "true", ")", ",", "\"UTF-8\"", ",", "$", "message", ")", ";", "return", "$", "message", ";", "}" ]
Prints all of error message @return void
[ "Prints", "all", "of", "error", "message" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleBase.php#L431-L449
28,719
IconoCoders/otp-simple-sdk
Source/SimpleBase.php
SimpleBase.getDebugMessage
public function getDebugMessage() { $message = '<font color="red">DEBUG START</font><br>'; foreach ($this->debugMessage as $items) { if (is_array($items) || is_object($items)) { $message .= "<pre>"; $message .= print_r($items, true) . '<br/>'; $message .= "</pre>"; } elseif (!is_array($items) && !is_object($items)) { if (strpos($items, 'form action=') !== false) { $message .= highlight_string($items, true) . '<br/>'; } else { $message .= $items . '<br/>'; } } } if ($this->commMethod == 'liveupdate') { $message .= "-----------------------------------------------------------------------------------<br>"; $message .= 'HASH FIELDS ' . print_r($this->hashFields, true); $message .= "-----------------------------------------------------------------------------------<br>"; $message .= 'HASH DATA ' . print_r($this->hashData, true); $message .= "-----------------------------------------------------------------------------------<br>"; $message .= highlight_string(@$this->luForm, true) . '<br/>'; $message .= "-----------------------------------------------------------------------------------<br>"; $message .= 'HASH CHECK ' . "<a href='http://hash.online-convert.com/md5-generator'>ONLINE HASH CONVERTER</a><br>"; } $message .= "-----------------------------------------------------------------------------------<br>"; $message .= '<font color="red">DEBUG END</font><br>'; iconv(mb_detect_encoding($message, mb_detect_order(), true), "UTF-8", $message); return $message; }
php
public function getDebugMessage() { $message = '<font color="red">DEBUG START</font><br>'; foreach ($this->debugMessage as $items) { if (is_array($items) || is_object($items)) { $message .= "<pre>"; $message .= print_r($items, true) . '<br/>'; $message .= "</pre>"; } elseif (!is_array($items) && !is_object($items)) { if (strpos($items, 'form action=') !== false) { $message .= highlight_string($items, true) . '<br/>'; } else { $message .= $items . '<br/>'; } } } if ($this->commMethod == 'liveupdate') { $message .= "-----------------------------------------------------------------------------------<br>"; $message .= 'HASH FIELDS ' . print_r($this->hashFields, true); $message .= "-----------------------------------------------------------------------------------<br>"; $message .= 'HASH DATA ' . print_r($this->hashData, true); $message .= "-----------------------------------------------------------------------------------<br>"; $message .= highlight_string(@$this->luForm, true) . '<br/>'; $message .= "-----------------------------------------------------------------------------------<br>"; $message .= 'HASH CHECK ' . "<a href='http://hash.online-convert.com/md5-generator'>ONLINE HASH CONVERTER</a><br>"; } $message .= "-----------------------------------------------------------------------------------<br>"; $message .= '<font color="red">DEBUG END</font><br>'; iconv(mb_detect_encoding($message, mb_detect_order(), true), "UTF-8", $message); return $message; }
[ "public", "function", "getDebugMessage", "(", ")", "{", "$", "message", "=", "'<font color=\"red\">DEBUG START</font><br>'", ";", "foreach", "(", "$", "this", "->", "debugMessage", "as", "$", "items", ")", "{", "if", "(", "is_array", "(", "$", "items", ")", "||", "is_object", "(", "$", "items", ")", ")", "{", "$", "message", ".=", "\"<pre>\"", ";", "$", "message", ".=", "print_r", "(", "$", "items", ",", "true", ")", ".", "'<br/>'", ";", "$", "message", ".=", "\"</pre>\"", ";", "}", "elseif", "(", "!", "is_array", "(", "$", "items", ")", "&&", "!", "is_object", "(", "$", "items", ")", ")", "{", "if", "(", "strpos", "(", "$", "items", ",", "'form action='", ")", "!==", "false", ")", "{", "$", "message", ".=", "highlight_string", "(", "$", "items", ",", "true", ")", ".", "'<br/>'", ";", "}", "else", "{", "$", "message", ".=", "$", "items", ".", "'<br/>'", ";", "}", "}", "}", "if", "(", "$", "this", "->", "commMethod", "==", "'liveupdate'", ")", "{", "$", "message", ".=", "\"-----------------------------------------------------------------------------------<br>\"", ";", "$", "message", ".=", "'HASH FIELDS '", ".", "print_r", "(", "$", "this", "->", "hashFields", ",", "true", ")", ";", "$", "message", ".=", "\"-----------------------------------------------------------------------------------<br>\"", ";", "$", "message", ".=", "'HASH DATA '", ".", "print_r", "(", "$", "this", "->", "hashData", ",", "true", ")", ";", "$", "message", ".=", "\"-----------------------------------------------------------------------------------<br>\"", ";", "$", "message", ".=", "highlight_string", "(", "@", "$", "this", "->", "luForm", ",", "true", ")", ".", "'<br/>'", ";", "$", "message", ".=", "\"-----------------------------------------------------------------------------------<br>\"", ";", "$", "message", ".=", "'HASH CHECK '", ".", "\"<a href='http://hash.online-convert.com/md5-generator'>ONLINE HASH CONVERTER</a><br>\"", ";", "}", "$", "message", ".=", "\"-----------------------------------------------------------------------------------<br>\"", ";", "$", "message", ".=", "'<font color=\"red\">DEBUG END</font><br>'", ";", "iconv", "(", "mb_detect_encoding", "(", "$", "message", ",", "mb_detect_order", "(", ")", ",", "true", ")", ",", "\"UTF-8\"", ",", "$", "message", ")", ";", "return", "$", "message", ";", "}" ]
Prints all of debug elements @return void
[ "Prints", "all", "of", "debug", "elements" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleBase.php#L457-L491
28,720
netgen/site-bundle
bundle/EventListener/User/PostPasswordResetEventListener.php
PostPasswordResetEventListener.onPasswordReset
public function onPasswordReset(PostPasswordResetEvent $event): void { $user = $event->getUser(); $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.forgot_password.password_changed.subject', $this->configResolver->getParameter('template.user.mail.forgot_password_password_changed', 'ngsite'), [ 'user' => $user, ] ); $this->ezUserAccountKeyRepository->removeByUserId($user->id); }
php
public function onPasswordReset(PostPasswordResetEvent $event): void { $user = $event->getUser(); $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.forgot_password.password_changed.subject', $this->configResolver->getParameter('template.user.mail.forgot_password_password_changed', 'ngsite'), [ 'user' => $user, ] ); $this->ezUserAccountKeyRepository->removeByUserId($user->id); }
[ "public", "function", "onPasswordReset", "(", "PostPasswordResetEvent", "$", "event", ")", ":", "void", "{", "$", "user", "=", "$", "event", "->", "getUser", "(", ")", ";", "$", "this", "->", "mailHelper", "->", "sendMail", "(", "[", "$", "user", "->", "email", "=>", "$", "this", "->", "getUserName", "(", "$", "user", ")", "]", ",", "'ngsite.user.forgot_password.password_changed.subject'", ",", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'template.user.mail.forgot_password_password_changed'", ",", "'ngsite'", ")", ",", "[", "'user'", "=>", "$", "user", ",", "]", ")", ";", "$", "this", "->", "ezUserAccountKeyRepository", "->", "removeByUserId", "(", "$", "user", "->", "id", ")", ";", "}" ]
Listens to the event triggered after the password has been reset. Event contains the information about the user who has changed the password.
[ "Listens", "to", "the", "event", "triggered", "after", "the", "password", "has", "been", "reset", ".", "Event", "contains", "the", "information", "about", "the", "user", "who", "has", "changed", "the", "password", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/EventListener/User/PostPasswordResetEventListener.php#L30-L45
28,721
smartboxgroup/integration-framework-bundle
Components/DB/NoSQL/Drivers/MongoDB/MongoDBDriver.php
MongoDBDriver.configure
public function configure(array $configuration) { // allows to use the default options when a null value is passed if (array_key_exists('options', $configuration) && $configuration['options'] === null) { unset($configuration['options']); } $optionsResolver = new OptionsResolver(); $optionsResolver ->setDefined(['host', 'database', 'options', 'driver_options']) ->setDefaults([ 'options' => ['connect' => false], 'driver_options' => ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']], ]) ->setRequired(['host', 'database']) ->setAllowedTypes('host', 'string') ->setAllowedTypes('database', 'string') ->setAllowedTypes('options', 'array') ->setAllowedTypes('driver_options', 'array') ; try { $this->configuration = $optionsResolver->resolve($configuration); } catch (\Exception $e) { throw new NoSQLDriverException('Wrong configuration: '.$e->getMessage(), $e->getCode(), $e); } }
php
public function configure(array $configuration) { // allows to use the default options when a null value is passed if (array_key_exists('options', $configuration) && $configuration['options'] === null) { unset($configuration['options']); } $optionsResolver = new OptionsResolver(); $optionsResolver ->setDefined(['host', 'database', 'options', 'driver_options']) ->setDefaults([ 'options' => ['connect' => false], 'driver_options' => ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']], ]) ->setRequired(['host', 'database']) ->setAllowedTypes('host', 'string') ->setAllowedTypes('database', 'string') ->setAllowedTypes('options', 'array') ->setAllowedTypes('driver_options', 'array') ; try { $this->configuration = $optionsResolver->resolve($configuration); } catch (\Exception $e) { throw new NoSQLDriverException('Wrong configuration: '.$e->getMessage(), $e->getCode(), $e); } }
[ "public", "function", "configure", "(", "array", "$", "configuration", ")", "{", "// allows to use the default options when a null value is passed", "if", "(", "array_key_exists", "(", "'options'", ",", "$", "configuration", ")", "&&", "$", "configuration", "[", "'options'", "]", "===", "null", ")", "{", "unset", "(", "$", "configuration", "[", "'options'", "]", ")", ";", "}", "$", "optionsResolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "optionsResolver", "->", "setDefined", "(", "[", "'host'", ",", "'database'", ",", "'options'", ",", "'driver_options'", "]", ")", "->", "setDefaults", "(", "[", "'options'", "=>", "[", "'connect'", "=>", "false", "]", ",", "'driver_options'", "=>", "[", "'typeMap'", "=>", "[", "'root'", "=>", "'array'", ",", "'document'", "=>", "'array'", ",", "'array'", "=>", "'array'", "]", "]", ",", "]", ")", "->", "setRequired", "(", "[", "'host'", ",", "'database'", "]", ")", "->", "setAllowedTypes", "(", "'host'", ",", "'string'", ")", "->", "setAllowedTypes", "(", "'database'", ",", "'string'", ")", "->", "setAllowedTypes", "(", "'options'", ",", "'array'", ")", "->", "setAllowedTypes", "(", "'driver_options'", ",", "'array'", ")", ";", "try", "{", "$", "this", "->", "configuration", "=", "$", "optionsResolver", "->", "resolve", "(", "$", "configuration", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "NoSQLDriverException", "(", "'Wrong configuration: '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Define and apply the expected configuration for the driver. @param array $configuration @throws \Smartbox\Integration\FrameworkBundle\Components\DB\NoSQL\Exceptions\NoSQLDriverException
[ "Define", "and", "apply", "the", "expected", "configuration", "for", "the", "driver", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/DB/NoSQL/Drivers/MongoDB/MongoDBDriver.php#L46-L72
28,722
smartboxgroup/integration-framework-bundle
Components/DB/NoSQL/Drivers/MongoDB/MongoDBDriver.php
MongoDBDriver.connect
public function connect() { if (!isset($this->configuration['host']) || !isset($this->configuration['database'])) { throw new NoSQLDriverException('Can not connect to MongoDB because configuration for this driver was not provided.'); } try { $this->connection = new \MongoDB\Client( $this->configuration['host'], $this->configuration['options'], $this->configuration['driver_options'] ); } catch (\Exception $e) { throw new NoSQLDriverException('Can not connect to storage because of: '.$e->getMessage(), $e->getCode(), $e); } $this->db = $this->connection->selectDatabase($this->configuration['database']); return $this->connection; }
php
public function connect() { if (!isset($this->configuration['host']) || !isset($this->configuration['database'])) { throw new NoSQLDriverException('Can not connect to MongoDB because configuration for this driver was not provided.'); } try { $this->connection = new \MongoDB\Client( $this->configuration['host'], $this->configuration['options'], $this->configuration['driver_options'] ); } catch (\Exception $e) { throw new NoSQLDriverException('Can not connect to storage because of: '.$e->getMessage(), $e->getCode(), $e); } $this->db = $this->connection->selectDatabase($this->configuration['database']); return $this->connection; }
[ "public", "function", "connect", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "configuration", "[", "'host'", "]", ")", "||", "!", "isset", "(", "$", "this", "->", "configuration", "[", "'database'", "]", ")", ")", "{", "throw", "new", "NoSQLDriverException", "(", "'Can not connect to MongoDB because configuration for this driver was not provided.'", ")", ";", "}", "try", "{", "$", "this", "->", "connection", "=", "new", "\\", "MongoDB", "\\", "Client", "(", "$", "this", "->", "configuration", "[", "'host'", "]", ",", "$", "this", "->", "configuration", "[", "'options'", "]", ",", "$", "this", "->", "configuration", "[", "'driver_options'", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "NoSQLDriverException", "(", "'Can not connect to storage because of: '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "$", "this", "->", "db", "=", "$", "this", "->", "connection", "->", "selectDatabase", "(", "$", "this", "->", "configuration", "[", "'database'", "]", ")", ";", "return", "$", "this", "->", "connection", ";", "}" ]
Connect to the mongoDatabase. @return \MongoDB\Client @throws \Smartbox\Integration\FrameworkBundle\Components\DB\NoSQL\Exceptions\NoSQLDriverException
[ "Connect", "to", "the", "mongoDatabase", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/DB/NoSQL/Drivers/MongoDB/MongoDBDriver.php#L81-L100
28,723
smartboxgroup/integration-framework-bundle
Components/DB/NoSQL/Drivers/MongoDB/MongoDBDriver.php
MongoDBDriver.deleteById
public function deleteById($collection, $id) { try { $id = new \MongoDB\BSON\ObjectID((string) $id); } catch (\Exception $e) { return; } $queryOptions = new QueryOptions(); $queryOptions->setQueryParams([ '_id' => $id, ]); $this->ensureConnection(); $this->db->$collection->deleteOne($queryOptions->getQueryParams()); }
php
public function deleteById($collection, $id) { try { $id = new \MongoDB\BSON\ObjectID((string) $id); } catch (\Exception $e) { return; } $queryOptions = new QueryOptions(); $queryOptions->setQueryParams([ '_id' => $id, ]); $this->ensureConnection(); $this->db->$collection->deleteOne($queryOptions->getQueryParams()); }
[ "public", "function", "deleteById", "(", "$", "collection", ",", "$", "id", ")", "{", "try", "{", "$", "id", "=", "new", "\\", "MongoDB", "\\", "BSON", "\\", "ObjectID", "(", "(", "string", ")", "$", "id", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", ";", "}", "$", "queryOptions", "=", "new", "QueryOptions", "(", ")", ";", "$", "queryOptions", "->", "setQueryParams", "(", "[", "'_id'", "=>", "$", "id", ",", "]", ")", ";", "$", "this", "->", "ensureConnection", "(", ")", ";", "$", "this", "->", "db", "->", "$", "collection", "->", "deleteOne", "(", "$", "queryOptions", "->", "getQueryParams", "(", ")", ")", ";", "}" ]
Remove an entry of the mongo database. @param $collection @param $id
[ "Remove", "an", "entry", "of", "the", "mongo", "database", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/DB/NoSQL/Drivers/MongoDB/MongoDBDriver.php#L270-L285
28,724
smartboxgroup/integration-framework-bundle
Configurability/ConfigurableServiceHelper.php
ConfigurableServiceHelper.debug
protected function debug($actions, &$context) { if (!is_array($actions)) { return; } foreach ($actions as $action => $parameters) { if ('display' == $action) { foreach ($parameters as $var) { echo "\n"; echo $var.' => '; $command = 'print_r($'.$var.');'; eval($command); } flush(); ob_flush(); } if ('break' == $action && false !== $parameters) { if (function_exists('xdebug_break')) { xdebug_break(); } } if ('sleep' == $action) { echo 'Sleeping for '.$parameters.' seconds due to sleep step...'."\n"; sleep($parameters); } if ('exit' == $action && false !== $parameters) { echo 'Exit due to debug step'."\n"; exit; } } return; }
php
protected function debug($actions, &$context) { if (!is_array($actions)) { return; } foreach ($actions as $action => $parameters) { if ('display' == $action) { foreach ($parameters as $var) { echo "\n"; echo $var.' => '; $command = 'print_r($'.$var.');'; eval($command); } flush(); ob_flush(); } if ('break' == $action && false !== $parameters) { if (function_exists('xdebug_break')) { xdebug_break(); } } if ('sleep' == $action) { echo 'Sleeping for '.$parameters.' seconds due to sleep step...'."\n"; sleep($parameters); } if ('exit' == $action && false !== $parameters) { echo 'Exit due to debug step'."\n"; exit; } } return; }
[ "protected", "function", "debug", "(", "$", "actions", ",", "&", "$", "context", ")", "{", "if", "(", "!", "is_array", "(", "$", "actions", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "actions", "as", "$", "action", "=>", "$", "parameters", ")", "{", "if", "(", "'display'", "==", "$", "action", ")", "{", "foreach", "(", "$", "parameters", "as", "$", "var", ")", "{", "echo", "\"\\n\"", ";", "echo", "$", "var", ".", "' => '", ";", "$", "command", "=", "'print_r($'", ".", "$", "var", ".", "');'", ";", "eval", "(", "$", "command", ")", ";", "}", "flush", "(", ")", ";", "ob_flush", "(", ")", ";", "}", "if", "(", "'break'", "==", "$", "action", "&&", "false", "!==", "$", "parameters", ")", "{", "if", "(", "function_exists", "(", "'xdebug_break'", ")", ")", "{", "xdebug_break", "(", ")", ";", "}", "}", "if", "(", "'sleep'", "==", "$", "action", ")", "{", "echo", "'Sleeping for '", ".", "$", "parameters", ".", "' seconds due to sleep step...'", ".", "\"\\n\"", ";", "sleep", "(", "$", "parameters", ")", ";", "}", "if", "(", "'exit'", "==", "$", "action", "&&", "false", "!==", "$", "parameters", ")", "{", "echo", "'Exit due to debug step'", ".", "\"\\n\"", ";", "exit", ";", "}", "}", "return", ";", "}" ]
Nasty hack to be able to easily display context variables in producers. @param array $actions @param $context
[ "Nasty", "hack", "to", "be", "able", "to", "easily", "display", "context", "variables", "in", "producers", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Configurability/ConfigurableServiceHelper.php#L241-L276
28,725
abhi1693/yii2-config
components/Config.php
Config._setCache
private function _setCache() { if ($this->_cache !== null) { $this->_cache->set($this->cacheKey, $this->_data, $this->cacheDuration); } }
php
private function _setCache() { if ($this->_cache !== null) { $this->_cache->set($this->cacheKey, $this->_data, $this->cacheDuration); } }
[ "private", "function", "_setCache", "(", ")", "{", "if", "(", "$", "this", "->", "_cache", "!==", "null", ")", "{", "$", "this", "->", "_cache", "->", "set", "(", "$", "this", "->", "cacheKey", ",", "$", "this", "->", "_data", ",", "$", "this", "->", "cacheDuration", ")", ";", "}", "}" ]
Sets the cache
[ "Sets", "the", "cache" ]
1dd5161d3bc1e6e587e75e44218467ff644c22bf
https://github.com/abhi1693/yii2-config/blob/1dd5161d3bc1e6e587e75e44218467ff644c22bf/components/Config.php#L129-L134
28,726
abhi1693/yii2-config
components/Config.php
Config.get
public function get($name, $default = null) { if (is_array($name)) { $result = []; foreach ($name as $key => $value) { if (is_int($key)) { $result[$value] = $this->_get($value, $default); } else { $result[$key] = $this->_get($key, $value); } } return $result; } return $this->_get($name, $default); }
php
public function get($name, $default = null) { if (is_array($name)) { $result = []; foreach ($name as $key => $value) { if (is_int($key)) { $result[$value] = $this->_get($value, $default); } else { $result[$key] = $this->_get($key, $value); } } return $result; } return $this->_get($name, $default); }
[ "public", "function", "get", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "name", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "$", "result", "[", "$", "value", "]", "=", "$", "this", "->", "_get", "(", "$", "value", ",", "$", "default", ")", ";", "}", "else", "{", "$", "result", "[", "$", "key", "]", "=", "$", "this", "->", "_get", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}", "return", "$", "result", ";", "}", "return", "$", "this", "->", "_get", "(", "$", "name", ",", "$", "default", ")", ";", "}" ]
Get configuration variable @param $name @param mixed $default @return mixed
[ "Get", "configuration", "variable" ]
1dd5161d3bc1e6e587e75e44218467ff644c22bf
https://github.com/abhi1693/yii2-config/blob/1dd5161d3bc1e6e587e75e44218467ff644c22bf/components/Config.php#L143-L158
28,727
abhi1693/yii2-config
components/Config.php
Config._get
private function _get($name, $default = null) { return array_key_exists($name, $this->getData()) ? $this->getData()[$name] : $default; }
php
private function _get($name, $default = null) { return array_key_exists($name, $this->getData()) ? $this->getData()[$name] : $default; }
[ "private", "function", "_get", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "return", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "getData", "(", ")", ")", "?", "$", "this", "->", "getData", "(", ")", "[", "$", "name", "]", ":", "$", "default", ";", "}" ]
Find and decode configuration variable @param string $name @param mixed $default @return mixed
[ "Find", "and", "decode", "configuration", "variable" ]
1dd5161d3bc1e6e587e75e44218467ff644c22bf
https://github.com/abhi1693/yii2-config/blob/1dd5161d3bc1e6e587e75e44218467ff644c22bf/components/Config.php#L166-L169
28,728
abhi1693/yii2-config
components/Config.php
Config.getAll
public function getAll() { $result = []; foreach ($this->getData() as $key => $value) { $result[$key] = $this->get($key); } return $result; }
php
public function getAll() { $result = []; foreach ($this->getData() as $key => $value) { $result[$key] = $this->get($key); } return $result; }
[ "public", "function", "getAll", "(", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getData", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "this", "->", "get", "(", "$", "key", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns all parameters @return array
[ "Returns", "all", "parameters" ]
1dd5161d3bc1e6e587e75e44218467ff644c22bf
https://github.com/abhi1693/yii2-config/blob/1dd5161d3bc1e6e587e75e44218467ff644c22bf/components/Config.php#L176-L185
28,729
abhi1693/yii2-config
components/Config.php
Config.set
public function set($name, $value = null) { if (is_array($name)) { $insert = []; $delete = []; foreach ($name as $key => $val) { $val = $this->_merge($key, $val); $insert[] = [$key, $val]; $delete[] = $key; $this->_data[$key] = $val; } if (count($insert) > 0) { $this->_db->createCommand()->delete($this->tableName, ['IN', 'name', $delete])->execute(); $this->_db->createCommand()->batchInsert($this->tableName, ['name', 'value'], $insert)->execute(); } } else { $value = $this->_merge($name, $value); if (array_key_exists($name, $this->getData()) === false) { $this->_db->createCommand()->insert($this->tableName, ['name' => $name, 'value' => $value])->execute(); } else { $this->_db->createCommand()->update($this->tableName, ['value' => $value], 'name = :name', [':name' => $name])->execute(); } $this->_data[$name] = $value; } $this->_setCache(); }
php
public function set($name, $value = null) { if (is_array($name)) { $insert = []; $delete = []; foreach ($name as $key => $val) { $val = $this->_merge($key, $val); $insert[] = [$key, $val]; $delete[] = $key; $this->_data[$key] = $val; } if (count($insert) > 0) { $this->_db->createCommand()->delete($this->tableName, ['IN', 'name', $delete])->execute(); $this->_db->createCommand()->batchInsert($this->tableName, ['name', 'value'], $insert)->execute(); } } else { $value = $this->_merge($name, $value); if (array_key_exists($name, $this->getData()) === false) { $this->_db->createCommand()->insert($this->tableName, ['name' => $name, 'value' => $value])->execute(); } else { $this->_db->createCommand()->update($this->tableName, ['value' => $value], 'name = :name', [':name' => $name])->execute(); } $this->_data[$name] = $value; } $this->_setCache(); }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "$", "insert", "=", "[", "]", ";", "$", "delete", "=", "[", "]", ";", "foreach", "(", "$", "name", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "val", "=", "$", "this", "->", "_merge", "(", "$", "key", ",", "$", "val", ")", ";", "$", "insert", "[", "]", "=", "[", "$", "key", ",", "$", "val", "]", ";", "$", "delete", "[", "]", "=", "$", "key", ";", "$", "this", "->", "_data", "[", "$", "key", "]", "=", "$", "val", ";", "}", "if", "(", "count", "(", "$", "insert", ")", ">", "0", ")", "{", "$", "this", "->", "_db", "->", "createCommand", "(", ")", "->", "delete", "(", "$", "this", "->", "tableName", ",", "[", "'IN'", ",", "'name'", ",", "$", "delete", "]", ")", "->", "execute", "(", ")", ";", "$", "this", "->", "_db", "->", "createCommand", "(", ")", "->", "batchInsert", "(", "$", "this", "->", "tableName", ",", "[", "'name'", ",", "'value'", "]", ",", "$", "insert", ")", "->", "execute", "(", ")", ";", "}", "}", "else", "{", "$", "value", "=", "$", "this", "->", "_merge", "(", "$", "name", ",", "$", "value", ")", ";", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "getData", "(", ")", ")", "===", "false", ")", "{", "$", "this", "->", "_db", "->", "createCommand", "(", ")", "->", "insert", "(", "$", "this", "->", "tableName", ",", "[", "'name'", "=>", "$", "name", ",", "'value'", "=>", "$", "value", "]", ")", "->", "execute", "(", ")", ";", "}", "else", "{", "$", "this", "->", "_db", "->", "createCommand", "(", ")", "->", "update", "(", "$", "this", "->", "tableName", ",", "[", "'value'", "=>", "$", "value", "]", ",", "'name = :name'", ",", "[", "':name'", "=>", "$", "name", "]", ")", "->", "execute", "(", ")", ";", "}", "$", "this", "->", "_data", "[", "$", "name", "]", "=", "$", "value", ";", "}", "$", "this", "->", "_setCache", "(", ")", ";", "}" ]
Sets configuration variable @param $name @param mixed $value @return mixed
[ "Sets", "configuration", "variable" ]
1dd5161d3bc1e6e587e75e44218467ff644c22bf
https://github.com/abhi1693/yii2-config/blob/1dd5161d3bc1e6e587e75e44218467ff644c22bf/components/Config.php#L194-L223
28,730
smartboxgroup/integration-framework-bundle
Core/Itinerary/ItineraryResolver.php
ItineraryResolver.filterItineraryParamsToPropagate
public function filterItineraryParamsToPropagate($params) { $res = []; foreach ($params as $key => $value) { if (!empty($value) && is_string($value)) { $res[$key] = $value; } } return $res; }
php
public function filterItineraryParamsToPropagate($params) { $res = []; foreach ($params as $key => $value) { if (!empty($value) && is_string($value)) { $res[$key] = $value; } } return $res; }
[ "public", "function", "filterItineraryParamsToPropagate", "(", "$", "params", ")", "{", "$", "res", "=", "[", "]", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", "&&", "is_string", "(", "$", "value", ")", ")", "{", "$", "res", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "res", ";", "}" ]
Returns the parameters that should be propagated through the route using the exchange headers. @param $params @return array
[ "Returns", "the", "parameters", "that", "should", "be", "propagated", "through", "the", "route", "using", "the", "exchange", "headers", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Core/Itinerary/ItineraryResolver.php#L68-L79
28,731
smartboxgroup/integration-framework-bundle
Components/JsonFileLoader/JsonFileLoaderProtocol.php
JsonFileLoaderProtocol.getOptionsDescriptions
public function getOptionsDescriptions() { return array_merge_recursive(parent::getOptionsDescriptions(), [ self::OPTION_BASE_PATH => ['Base path to look for the json file', []], self::OPTION_FILENAME => ['Name of the file to load', []], self::OPTION_TYPE => ['Name of the type', []],//e.g. body or headers ]); }
php
public function getOptionsDescriptions() { return array_merge_recursive(parent::getOptionsDescriptions(), [ self::OPTION_BASE_PATH => ['Base path to look for the json file', []], self::OPTION_FILENAME => ['Name of the file to load', []], self::OPTION_TYPE => ['Name of the type', []],//e.g. body or headers ]); }
[ "public", "function", "getOptionsDescriptions", "(", ")", "{", "return", "array_merge_recursive", "(", "parent", "::", "getOptionsDescriptions", "(", ")", ",", "[", "self", "::", "OPTION_BASE_PATH", "=>", "[", "'Base path to look for the json file'", ",", "[", "]", "]", ",", "self", "::", "OPTION_FILENAME", "=>", "[", "'Name of the file to load'", ",", "[", "]", "]", ",", "self", "::", "OPTION_TYPE", "=>", "[", "'Name of the type'", ",", "[", "]", "]", ",", "//e.g. body or headers", "]", ")", ";", "}" ]
Key-Value array with the option name as key and the details as value. [OptionName => [description, array of valid values],..] @return array
[ "Key", "-", "Value", "array", "with", "the", "option", "name", "as", "key", "and", "the", "details", "as", "value", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/JsonFileLoader/JsonFileLoaderProtocol.php#L32-L39
28,732
netgen/ngsymfonytools
classes/ngsymfonytoolspathurloperator.php
NgSymfonyToolsPathUrlOperator.getPath
public static function getPath( $name, $parameters = array(), $relative = false ) { $serviceContainer = ezpKernel::instance()->getServiceContainer(); return $serviceContainer->get('router')->generate( $name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH ); }
php
public static function getPath( $name, $parameters = array(), $relative = false ) { $serviceContainer = ezpKernel::instance()->getServiceContainer(); return $serviceContainer->get('router')->generate( $name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH ); }
[ "public", "static", "function", "getPath", "(", "$", "name", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "relative", "=", "false", ")", "{", "$", "serviceContainer", "=", "ezpKernel", "::", "instance", "(", ")", "->", "getServiceContainer", "(", ")", ";", "return", "$", "serviceContainer", "->", "get", "(", "'router'", ")", "->", "generate", "(", "$", "name", ",", "$", "parameters", ",", "$", "relative", "?", "UrlGeneratorInterface", "::", "RELATIVE_PATH", ":", "UrlGeneratorInterface", "::", "ABSOLUTE_PATH", ")", ";", "}" ]
Returns the path for provided route and parameters @param string $name @param array $parameters @param bool $relative @return string
[ "Returns", "the", "path", "for", "provided", "route", "and", "parameters" ]
58abf97996ddd1d4f969d8c64ce6998b9d1a5c27
https://github.com/netgen/ngsymfonytools/blob/58abf97996ddd1d4f969d8c64ce6998b9d1a5c27/classes/ngsymfonytoolspathurloperator.php#L121-L130
28,733
netgen/ngsymfonytools
classes/ngsymfonytoolspathurloperator.php
NgSymfonyToolsPathUrlOperator.getUrl
public static function getUrl( $name, $parameters = array(), $schemeRelative = false ) { $serviceContainer = ezpKernel::instance()->getServiceContainer(); return $serviceContainer->get('router')->generate( $name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL ); }
php
public static function getUrl( $name, $parameters = array(), $schemeRelative = false ) { $serviceContainer = ezpKernel::instance()->getServiceContainer(); return $serviceContainer->get('router')->generate( $name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL ); }
[ "public", "static", "function", "getUrl", "(", "$", "name", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "schemeRelative", "=", "false", ")", "{", "$", "serviceContainer", "=", "ezpKernel", "::", "instance", "(", ")", "->", "getServiceContainer", "(", ")", ";", "return", "$", "serviceContainer", "->", "get", "(", "'router'", ")", "->", "generate", "(", "$", "name", ",", "$", "parameters", ",", "$", "schemeRelative", "?", "UrlGeneratorInterface", "::", "NETWORK_PATH", ":", "UrlGeneratorInterface", "::", "ABSOLUTE_URL", ")", ";", "}" ]
Returns the URL for provided route and parameters @param string $name @param array $parameters @param bool $schemeRelative @return string
[ "Returns", "the", "URL", "for", "provided", "route", "and", "parameters" ]
58abf97996ddd1d4f969d8c64ce6998b9d1a5c27
https://github.com/netgen/ngsymfonytools/blob/58abf97996ddd1d4f969d8c64ce6998b9d1a5c27/classes/ngsymfonytoolspathurloperator.php#L141-L150
28,734
seregazhuk/php-react-memcached
src/Client.php
Client.end
public function end(): void { $this->isEnding = true; if ($this->pool->isEmpty()) { $this->close(); } }
php
public function end(): void { $this->isEnding = true; if ($this->pool->isEmpty()) { $this->close(); } }
[ "public", "function", "end", "(", ")", ":", "void", "{", "$", "this", "->", "isEnding", "=", "true", ";", "if", "(", "$", "this", "->", "pool", "->", "isEmpty", "(", ")", ")", "{", "$", "this", "->", "close", "(", ")", ";", "}", "}" ]
Closes the connection when all requests are resolved
[ "Closes", "the", "connection", "when", "all", "requests", "are", "resolved" ]
4fa5bd0cd09a296b7abdcce07fc749e7c6c911e1
https://github.com/seregazhuk/php-react-memcached/blob/4fa5bd0cd09a296b7abdcce07fc749e7c6c911e1/src/Client.php#L146-L153
28,735
seregazhuk/php-react-memcached
src/Client.php
Client.close
public function close(): void { if ($this->isClosed) { return; } $this->isEnding = true; $this->isClosed = true; $this->connection->close(); $this->emit('close'); $this->pool->rejectAll(new ConnectionClosedException()); }
php
public function close(): void { if ($this->isClosed) { return; } $this->isEnding = true; $this->isClosed = true; $this->connection->close(); $this->emit('close'); $this->pool->rejectAll(new ConnectionClosedException()); }
[ "public", "function", "close", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "isClosed", ")", "{", "return", ";", "}", "$", "this", "->", "isEnding", "=", "true", ";", "$", "this", "->", "isClosed", "=", "true", ";", "$", "this", "->", "connection", "->", "close", "(", ")", ";", "$", "this", "->", "emit", "(", "'close'", ")", ";", "$", "this", "->", "pool", "->", "rejectAll", "(", "new", "ConnectionClosedException", "(", ")", ")", ";", "}" ]
Forces closing the connection and rejects all pending requests
[ "Forces", "closing", "the", "connection", "and", "rejects", "all", "pending", "requests" ]
4fa5bd0cd09a296b7abdcce07fc749e7c6c911e1
https://github.com/seregazhuk/php-react-memcached/blob/4fa5bd0cd09a296b7abdcce07fc749e7c6c911e1/src/Client.php#L158-L171
28,736
netgen/site-bundle
bundle/Topic/UrlGenerator.php
UrlGenerator.getTopicValueObject
private function getTopicValueObject(Tag $tag) { $rootLocation = $this->loadService->loadLocation( $this->configResolver->getParameter('content.tree_root.location_id') ); $query = new LocationQuery(); $query->limit = 1; $query->filter = new Criterion\LogicalAnd( [ new Criterion\Subtree($rootLocation->pathString), new Criterion\LogicalNot(new Criterion\LocationId($rootLocation->id)), new Criterion\Location\IsMainLocation(Criterion\Location\IsMainLocation::MAIN), new Criterion\Visibility(Criterion\Visibility::VISIBLE), new Criterion\ContentTypeIdentifier(['ng_topic']), new TagId($tag->id), ] ); $searchResult = $this->findService->findLocations($query); if (!empty($searchResult->searchHits)) { return $searchResult->searchHits[0]->valueObject; } return $tag; }
php
private function getTopicValueObject(Tag $tag) { $rootLocation = $this->loadService->loadLocation( $this->configResolver->getParameter('content.tree_root.location_id') ); $query = new LocationQuery(); $query->limit = 1; $query->filter = new Criterion\LogicalAnd( [ new Criterion\Subtree($rootLocation->pathString), new Criterion\LogicalNot(new Criterion\LocationId($rootLocation->id)), new Criterion\Location\IsMainLocation(Criterion\Location\IsMainLocation::MAIN), new Criterion\Visibility(Criterion\Visibility::VISIBLE), new Criterion\ContentTypeIdentifier(['ng_topic']), new TagId($tag->id), ] ); $searchResult = $this->findService->findLocations($query); if (!empty($searchResult->searchHits)) { return $searchResult->searchHits[0]->valueObject; } return $tag; }
[ "private", "function", "getTopicValueObject", "(", "Tag", "$", "tag", ")", "{", "$", "rootLocation", "=", "$", "this", "->", "loadService", "->", "loadLocation", "(", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'content.tree_root.location_id'", ")", ")", ";", "$", "query", "=", "new", "LocationQuery", "(", ")", ";", "$", "query", "->", "limit", "=", "1", ";", "$", "query", "->", "filter", "=", "new", "Criterion", "\\", "LogicalAnd", "(", "[", "new", "Criterion", "\\", "Subtree", "(", "$", "rootLocation", "->", "pathString", ")", ",", "new", "Criterion", "\\", "LogicalNot", "(", "new", "Criterion", "\\", "LocationId", "(", "$", "rootLocation", "->", "id", ")", ")", ",", "new", "Criterion", "\\", "Location", "\\", "IsMainLocation", "(", "Criterion", "\\", "Location", "\\", "IsMainLocation", "::", "MAIN", ")", ",", "new", "Criterion", "\\", "Visibility", "(", "Criterion", "\\", "Visibility", "::", "VISIBLE", ")", ",", "new", "Criterion", "\\", "ContentTypeIdentifier", "(", "[", "'ng_topic'", "]", ")", ",", "new", "TagId", "(", "$", "tag", "->", "id", ")", ",", "]", ")", ";", "$", "searchResult", "=", "$", "this", "->", "findService", "->", "findLocations", "(", "$", "query", ")", ";", "if", "(", "!", "empty", "(", "$", "searchResult", "->", "searchHits", ")", ")", "{", "return", "$", "searchResult", "->", "searchHits", "[", "0", "]", "->", "valueObject", ";", "}", "return", "$", "tag", ";", "}" ]
If exists, returns the location of the content with ng_topic identifier connected to provided tag. Otherwise, the tag itself is returned. @return \Netgen\EzPlatformSiteApi\API\Values\Location|\Netgen\TagsBundle\API\Repository\Values\Tags\Tag
[ "If", "exists", "returns", "the", "location", "of", "the", "content", "with", "ng_topic", "identifier", "connected", "to", "provided", "tag", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Topic/UrlGenerator.php#L65-L92
28,737
cedx/coveralls.php
lib/Http/Client.php
Client.upload
function upload(string $coverage, Configuration $configuration = null): void { $report = trim($coverage); if (!mb_strlen($report)) throw new \InvalidArgumentException('The specified coverage report is empty.'); $job = null; $isClover = mb_substr($report, 0, 5) == '<?xml' || mb_substr($report, 0, 10) == '<coverage'; if ($isClover) $job = Clover::parseReport($report); else { $token = mb_substr($report, 0, 3); if ($token == 'TN:' || $token == 'SF:') $job = Lcov::parseReport($report); } if (!$job) throw new \InvalidArgumentException('The specified coverage format is not supported.'); $this->updateJob($job, $configuration ?? Configuration::loadDefaults()); if (!$job->getRunAt()) $job->setRunAt(new \DateTime); try { which('git'); $git = GitData::fromRepository(); $branch = ($gitData = $job->getGit()) ? $gitData->getBranch() : ''; if ($git->getBranch() == 'HEAD' && mb_strlen($branch)) $git->setBranch($branch); $job->setGit($git); } catch (FinderException $e) {} $this->uploadJob($job); }
php
function upload(string $coverage, Configuration $configuration = null): void { $report = trim($coverage); if (!mb_strlen($report)) throw new \InvalidArgumentException('The specified coverage report is empty.'); $job = null; $isClover = mb_substr($report, 0, 5) == '<?xml' || mb_substr($report, 0, 10) == '<coverage'; if ($isClover) $job = Clover::parseReport($report); else { $token = mb_substr($report, 0, 3); if ($token == 'TN:' || $token == 'SF:') $job = Lcov::parseReport($report); } if (!$job) throw new \InvalidArgumentException('The specified coverage format is not supported.'); $this->updateJob($job, $configuration ?? Configuration::loadDefaults()); if (!$job->getRunAt()) $job->setRunAt(new \DateTime); try { which('git'); $git = GitData::fromRepository(); $branch = ($gitData = $job->getGit()) ? $gitData->getBranch() : ''; if ($git->getBranch() == 'HEAD' && mb_strlen($branch)) $git->setBranch($branch); $job->setGit($git); } catch (FinderException $e) {} $this->uploadJob($job); }
[ "function", "upload", "(", "string", "$", "coverage", ",", "Configuration", "$", "configuration", "=", "null", ")", ":", "void", "{", "$", "report", "=", "trim", "(", "$", "coverage", ")", ";", "if", "(", "!", "mb_strlen", "(", "$", "report", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'The specified coverage report is empty.'", ")", ";", "$", "job", "=", "null", ";", "$", "isClover", "=", "mb_substr", "(", "$", "report", ",", "0", ",", "5", ")", "==", "'<?xml'", "||", "mb_substr", "(", "$", "report", ",", "0", ",", "10", ")", "==", "'<coverage'", ";", "if", "(", "$", "isClover", ")", "$", "job", "=", "Clover", "::", "parseReport", "(", "$", "report", ")", ";", "else", "{", "$", "token", "=", "mb_substr", "(", "$", "report", ",", "0", ",", "3", ")", ";", "if", "(", "$", "token", "==", "'TN:'", "||", "$", "token", "==", "'SF:'", ")", "$", "job", "=", "Lcov", "::", "parseReport", "(", "$", "report", ")", ";", "}", "if", "(", "!", "$", "job", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'The specified coverage format is not supported.'", ")", ";", "$", "this", "->", "updateJob", "(", "$", "job", ",", "$", "configuration", "??", "Configuration", "::", "loadDefaults", "(", ")", ")", ";", "if", "(", "!", "$", "job", "->", "getRunAt", "(", ")", ")", "$", "job", "->", "setRunAt", "(", "new", "\\", "DateTime", ")", ";", "try", "{", "which", "(", "'git'", ")", ";", "$", "git", "=", "GitData", "::", "fromRepository", "(", ")", ";", "$", "branch", "=", "(", "$", "gitData", "=", "$", "job", "->", "getGit", "(", ")", ")", "?", "$", "gitData", "->", "getBranch", "(", ")", ":", "''", ";", "if", "(", "$", "git", "->", "getBranch", "(", ")", "==", "'HEAD'", "&&", "mb_strlen", "(", "$", "branch", ")", ")", "$", "git", "->", "setBranch", "(", "$", "branch", ")", ";", "$", "job", "->", "setGit", "(", "$", "git", ")", ";", "}", "catch", "(", "FinderException", "$", "e", ")", "{", "}", "$", "this", "->", "uploadJob", "(", "$", "job", ")", ";", "}" ]
Uploads the specified code coverage report to the Coveralls service. @param string $coverage A coverage report. @param Configuration $configuration The environment settings. @throws \InvalidArgumentException The specified coverage report is empty or its format is not supported.
[ "Uploads", "the", "specified", "code", "coverage", "report", "to", "the", "Coveralls", "service", "." ]
c196de0f92e06d5143ba90ebab18c8e384316cc0
https://github.com/cedx/coveralls.php/blob/c196de0f92e06d5143ba90ebab18c8e384316cc0/lib/Http/Client.php#L50-L76
28,738
cedx/coveralls.php
lib/Http/Client.php
Client.uploadJob
function uploadJob(Job $job): void { if (!$job->getRepoToken() && !$job->getServiceName()) throw new \InvalidArgumentException('The job does not meet the requirements.'); $uri = UriResolver::resolve($this->getEndPoint(), new Uri('jobs')); $body = new MultipartStream([[ 'contents' => json_encode($job, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 'filename' => 'coveralls.json', 'name' => 'json_file' ]]); $headers = [ 'content-length' => $body->getSize(), 'content-type' => "multipart/form-data; boundary={$body->getBoundary()}" ]; try { $request = new Request('POST', $uri, $headers, $body); $this->emit(new RequestEvent($request)); $response = (new HTTPClient())->send($request); $this->emit(new ResponseEvent($request, $response)); } catch (\Throwable $e) { throw new ClientException('An error occurred while uploading the report.', $uri, $e); } }
php
function uploadJob(Job $job): void { if (!$job->getRepoToken() && !$job->getServiceName()) throw new \InvalidArgumentException('The job does not meet the requirements.'); $uri = UriResolver::resolve($this->getEndPoint(), new Uri('jobs')); $body = new MultipartStream([[ 'contents' => json_encode($job, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 'filename' => 'coveralls.json', 'name' => 'json_file' ]]); $headers = [ 'content-length' => $body->getSize(), 'content-type' => "multipart/form-data; boundary={$body->getBoundary()}" ]; try { $request = new Request('POST', $uri, $headers, $body); $this->emit(new RequestEvent($request)); $response = (new HTTPClient())->send($request); $this->emit(new ResponseEvent($request, $response)); } catch (\Throwable $e) { throw new ClientException('An error occurred while uploading the report.', $uri, $e); } }
[ "function", "uploadJob", "(", "Job", "$", "job", ")", ":", "void", "{", "if", "(", "!", "$", "job", "->", "getRepoToken", "(", ")", "&&", "!", "$", "job", "->", "getServiceName", "(", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'The job does not meet the requirements.'", ")", ";", "$", "uri", "=", "UriResolver", "::", "resolve", "(", "$", "this", "->", "getEndPoint", "(", ")", ",", "new", "Uri", "(", "'jobs'", ")", ")", ";", "$", "body", "=", "new", "MultipartStream", "(", "[", "[", "'contents'", "=>", "json_encode", "(", "$", "job", ",", "JSON_UNESCAPED_SLASHES", "|", "JSON_UNESCAPED_UNICODE", ")", ",", "'filename'", "=>", "'coveralls.json'", ",", "'name'", "=>", "'json_file'", "]", "]", ")", ";", "$", "headers", "=", "[", "'content-length'", "=>", "$", "body", "->", "getSize", "(", ")", ",", "'content-type'", "=>", "\"multipart/form-data; boundary={$body->getBoundary()}\"", "]", ";", "try", "{", "$", "request", "=", "new", "Request", "(", "'POST'", ",", "$", "uri", ",", "$", "headers", ",", "$", "body", ")", ";", "$", "this", "->", "emit", "(", "new", "RequestEvent", "(", "$", "request", ")", ")", ";", "$", "response", "=", "(", "new", "HTTPClient", "(", ")", ")", "->", "send", "(", "$", "request", ")", ";", "$", "this", "->", "emit", "(", "new", "ResponseEvent", "(", "$", "request", ",", "$", "response", ")", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "throw", "new", "ClientException", "(", "'An error occurred while uploading the report.'", ",", "$", "uri", ",", "$", "e", ")", ";", "}", "}" ]
Uploads the specified job to the Coveralls service. @param Job $job The job to be uploaded. @throws \InvalidArgumentException The job does not meet the requirements. @throws ClientException An error occurred while uploading the report.
[ "Uploads", "the", "specified", "job", "to", "the", "Coveralls", "service", "." ]
c196de0f92e06d5143ba90ebab18c8e384316cc0
https://github.com/cedx/coveralls.php/blob/c196de0f92e06d5143ba90ebab18c8e384316cc0/lib/Http/Client.php#L84-L111
28,739
cedx/coveralls.php
lib/Http/Client.php
Client.updateJob
private function updateJob(Job $job, Configuration $config): void { if (isset($config['repo_token'])) $job->setRepoToken($config['repo_token']); else if (isset($config['repo_secret_token'])) $job->setRepoToken($config['repo_secret_token']); if (isset($config['parallel'])) $job->setParallel($config['parallel'] == 'true'); if (isset($config['run_at'])) $job->setRunAt(new \DateTime($config['run_at'])); if (isset($config['service_job_id'])) $job->setServiceJobId($config['service_job_id']); if (isset($config['service_name'])) $job->setServiceName($config['service_name']); if (isset($config['service_number'])) $job->setServiceNumber($config['service_number']); if (isset($config['service_pull_request'])) $job->setServicePullRequest($config['service_pull_request']); $hasGitData = count(array_filter($config->getKeys(), function($key) { return $key == 'service_branch' || mb_substr($key, 0, 4) == 'git_'; })) > 0; if (!$hasGitData) $job->setCommitSha($config['commit_sha'] ?: ''); else { $commit = new GitCommit($config['commit_sha'] ?: '', $config['git_message'] ?: ''); $commit->setAuthorEmail($config['git_author_email'] ?: ''); $commit->setAuthorName($config['git_author_name'] ?: ''); $commit->setCommitterEmail($config['git_committer_email'] ?: ''); $commit->setCommitterName($config['git_committer_email'] ?: ''); $job->setGit(new GitData($commit, $config['service_branch'] ?: '')); } }
php
private function updateJob(Job $job, Configuration $config): void { if (isset($config['repo_token'])) $job->setRepoToken($config['repo_token']); else if (isset($config['repo_secret_token'])) $job->setRepoToken($config['repo_secret_token']); if (isset($config['parallel'])) $job->setParallel($config['parallel'] == 'true'); if (isset($config['run_at'])) $job->setRunAt(new \DateTime($config['run_at'])); if (isset($config['service_job_id'])) $job->setServiceJobId($config['service_job_id']); if (isset($config['service_name'])) $job->setServiceName($config['service_name']); if (isset($config['service_number'])) $job->setServiceNumber($config['service_number']); if (isset($config['service_pull_request'])) $job->setServicePullRequest($config['service_pull_request']); $hasGitData = count(array_filter($config->getKeys(), function($key) { return $key == 'service_branch' || mb_substr($key, 0, 4) == 'git_'; })) > 0; if (!$hasGitData) $job->setCommitSha($config['commit_sha'] ?: ''); else { $commit = new GitCommit($config['commit_sha'] ?: '', $config['git_message'] ?: ''); $commit->setAuthorEmail($config['git_author_email'] ?: ''); $commit->setAuthorName($config['git_author_name'] ?: ''); $commit->setCommitterEmail($config['git_committer_email'] ?: ''); $commit->setCommitterName($config['git_committer_email'] ?: ''); $job->setGit(new GitData($commit, $config['service_branch'] ?: '')); } }
[ "private", "function", "updateJob", "(", "Job", "$", "job", ",", "Configuration", "$", "config", ")", ":", "void", "{", "if", "(", "isset", "(", "$", "config", "[", "'repo_token'", "]", ")", ")", "$", "job", "->", "setRepoToken", "(", "$", "config", "[", "'repo_token'", "]", ")", ";", "else", "if", "(", "isset", "(", "$", "config", "[", "'repo_secret_token'", "]", ")", ")", "$", "job", "->", "setRepoToken", "(", "$", "config", "[", "'repo_secret_token'", "]", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'parallel'", "]", ")", ")", "$", "job", "->", "setParallel", "(", "$", "config", "[", "'parallel'", "]", "==", "'true'", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'run_at'", "]", ")", ")", "$", "job", "->", "setRunAt", "(", "new", "\\", "DateTime", "(", "$", "config", "[", "'run_at'", "]", ")", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'service_job_id'", "]", ")", ")", "$", "job", "->", "setServiceJobId", "(", "$", "config", "[", "'service_job_id'", "]", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'service_name'", "]", ")", ")", "$", "job", "->", "setServiceName", "(", "$", "config", "[", "'service_name'", "]", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'service_number'", "]", ")", ")", "$", "job", "->", "setServiceNumber", "(", "$", "config", "[", "'service_number'", "]", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'service_pull_request'", "]", ")", ")", "$", "job", "->", "setServicePullRequest", "(", "$", "config", "[", "'service_pull_request'", "]", ")", ";", "$", "hasGitData", "=", "count", "(", "array_filter", "(", "$", "config", "->", "getKeys", "(", ")", ",", "function", "(", "$", "key", ")", "{", "return", "$", "key", "==", "'service_branch'", "||", "mb_substr", "(", "$", "key", ",", "0", ",", "4", ")", "==", "'git_'", ";", "}", ")", ")", ">", "0", ";", "if", "(", "!", "$", "hasGitData", ")", "$", "job", "->", "setCommitSha", "(", "$", "config", "[", "'commit_sha'", "]", "?", ":", "''", ")", ";", "else", "{", "$", "commit", "=", "new", "GitCommit", "(", "$", "config", "[", "'commit_sha'", "]", "?", ":", "''", ",", "$", "config", "[", "'git_message'", "]", "?", ":", "''", ")", ";", "$", "commit", "->", "setAuthorEmail", "(", "$", "config", "[", "'git_author_email'", "]", "?", ":", "''", ")", ";", "$", "commit", "->", "setAuthorName", "(", "$", "config", "[", "'git_author_name'", "]", "?", ":", "''", ")", ";", "$", "commit", "->", "setCommitterEmail", "(", "$", "config", "[", "'git_committer_email'", "]", "?", ":", "''", ")", ";", "$", "commit", "->", "setCommitterName", "(", "$", "config", "[", "'git_committer_email'", "]", "?", ":", "''", ")", ";", "$", "job", "->", "setGit", "(", "new", "GitData", "(", "$", "commit", ",", "$", "config", "[", "'service_branch'", "]", "?", ":", "''", ")", ")", ";", "}", "}" ]
Updates the properties of the specified job using the given configuration parameters. @param Job $job The job to update. @param Configuration $config The parameters to define.
[ "Updates", "the", "properties", "of", "the", "specified", "job", "using", "the", "given", "configuration", "parameters", "." ]
c196de0f92e06d5143ba90ebab18c8e384316cc0
https://github.com/cedx/coveralls.php/blob/c196de0f92e06d5143ba90ebab18c8e384316cc0/lib/Http/Client.php#L118-L143
28,740
netgen/site-bundle
bundle/ContextProvider/SessionContextProvider.php
SessionContextProvider.updateUserContext
public function updateUserContext(UserContext $context): void { if ($this->session->isStarted()) { $context->addParameter('sessionId', $this->session->getId()); } }
php
public function updateUserContext(UserContext $context): void { if ($this->session->isStarted()) { $context->addParameter('sessionId', $this->session->getId()); } }
[ "public", "function", "updateUserContext", "(", "UserContext", "$", "context", ")", ":", "void", "{", "if", "(", "$", "this", "->", "session", "->", "isStarted", "(", ")", ")", "{", "$", "context", "->", "addParameter", "(", "'sessionId'", ",", "$", "this", "->", "session", "->", "getId", "(", ")", ")", ";", "}", "}" ]
If the session is started, adds the session ID to user context. This allows varying the cache per session.
[ "If", "the", "session", "is", "started", "adds", "the", "session", "ID", "to", "user", "context", ".", "This", "allows", "varying", "the", "cache", "per", "session", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/ContextProvider/SessionContextProvider.php#L27-L32
28,741
smartboxgroup/integration-framework-bundle
Core/Processors/Routing/Multicast.php
Multicast.doProcess
protected function doProcess(Exchange $mainExchange, SerializableArray $processingContext) { foreach ($this->itineraries as $itinerary) { $exchange = new Exchange(); // Set headers if (!empty($mainExchange->getHeaders())) { $exchange->setHeaders($mainExchange->getHeaders()); } $exchange->setHeader(Exchange::HEADER_HANDLER, $mainExchange->getHeader(Exchange::HEADER_HANDLER)); $exchange->setHeader(Exchange::HEADER_PARENT_EXCHANGE, $mainExchange->getId()); $exchange->setHeader(Exchange::HEADER_FROM, $mainExchange->getHeader(Exchange::HEADER_FROM)); // Set Itinerary $exchange->getItinerary()->prepend($itinerary); $exchange->getItinerary()->setName('Multicast from "'.$mainExchange->getItinerary()->getName().'"'); // Set Message $msgCopy = unserialize(serialize($mainExchange->getIn())); $exchange->setIn($msgCopy); $event = new NewExchangeEvent($exchange); $event->setTimestampToCurrent(); $this->eventDispatcher->dispatch(NewExchangeEvent::TYPE_NEW_EXCHANGE_EVENT, $event); } }
php
protected function doProcess(Exchange $mainExchange, SerializableArray $processingContext) { foreach ($this->itineraries as $itinerary) { $exchange = new Exchange(); // Set headers if (!empty($mainExchange->getHeaders())) { $exchange->setHeaders($mainExchange->getHeaders()); } $exchange->setHeader(Exchange::HEADER_HANDLER, $mainExchange->getHeader(Exchange::HEADER_HANDLER)); $exchange->setHeader(Exchange::HEADER_PARENT_EXCHANGE, $mainExchange->getId()); $exchange->setHeader(Exchange::HEADER_FROM, $mainExchange->getHeader(Exchange::HEADER_FROM)); // Set Itinerary $exchange->getItinerary()->prepend($itinerary); $exchange->getItinerary()->setName('Multicast from "'.$mainExchange->getItinerary()->getName().'"'); // Set Message $msgCopy = unserialize(serialize($mainExchange->getIn())); $exchange->setIn($msgCopy); $event = new NewExchangeEvent($exchange); $event->setTimestampToCurrent(); $this->eventDispatcher->dispatch(NewExchangeEvent::TYPE_NEW_EXCHANGE_EVENT, $event); } }
[ "protected", "function", "doProcess", "(", "Exchange", "$", "mainExchange", ",", "SerializableArray", "$", "processingContext", ")", "{", "foreach", "(", "$", "this", "->", "itineraries", "as", "$", "itinerary", ")", "{", "$", "exchange", "=", "new", "Exchange", "(", ")", ";", "// Set headers", "if", "(", "!", "empty", "(", "$", "mainExchange", "->", "getHeaders", "(", ")", ")", ")", "{", "$", "exchange", "->", "setHeaders", "(", "$", "mainExchange", "->", "getHeaders", "(", ")", ")", ";", "}", "$", "exchange", "->", "setHeader", "(", "Exchange", "::", "HEADER_HANDLER", ",", "$", "mainExchange", "->", "getHeader", "(", "Exchange", "::", "HEADER_HANDLER", ")", ")", ";", "$", "exchange", "->", "setHeader", "(", "Exchange", "::", "HEADER_PARENT_EXCHANGE", ",", "$", "mainExchange", "->", "getId", "(", ")", ")", ";", "$", "exchange", "->", "setHeader", "(", "Exchange", "::", "HEADER_FROM", ",", "$", "mainExchange", "->", "getHeader", "(", "Exchange", "::", "HEADER_FROM", ")", ")", ";", "// Set Itinerary", "$", "exchange", "->", "getItinerary", "(", ")", "->", "prepend", "(", "$", "itinerary", ")", ";", "$", "exchange", "->", "getItinerary", "(", ")", "->", "setName", "(", "'Multicast from \"'", ".", "$", "mainExchange", "->", "getItinerary", "(", ")", "->", "getName", "(", ")", ".", "'\"'", ")", ";", "// Set Message", "$", "msgCopy", "=", "unserialize", "(", "serialize", "(", "$", "mainExchange", "->", "getIn", "(", ")", ")", ")", ";", "$", "exchange", "->", "setIn", "(", "$", "msgCopy", ")", ";", "$", "event", "=", "new", "NewExchangeEvent", "(", "$", "exchange", ")", ";", "$", "event", "->", "setTimestampToCurrent", "(", ")", ";", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "NewExchangeEvent", "::", "TYPE_NEW_EXCHANGE_EVENT", ",", "$", "event", ")", ";", "}", "}" ]
The current implementation assumes the existence of only one aggregation strategy which ignores the child exchanges. @param Exchange $mainExchange
[ "The", "current", "implementation", "assumes", "the", "existence", "of", "only", "one", "aggregation", "strategy", "which", "ignores", "the", "child", "exchanges", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Core/Processors/Routing/Multicast.php#L89-L115
28,742
netgen/site-bundle
bundle/Controller/PartsController.php
PartsController.viewRelatedItems
public function viewRelatedItems(Request $request, Content $content, string $fieldDefinitionIdentifier, string $template): Response { return $this->render( $template, [ 'content' => $content, 'location' => $content->mainLocation, 'field_identifier' => $fieldDefinitionIdentifier, 'related_items' => $this->locationResolver->loadRelations($content->mainLocation, $fieldDefinitionIdentifier), 'view_type' => $request->attributes->get('viewType') ?? 'line', ] ); }
php
public function viewRelatedItems(Request $request, Content $content, string $fieldDefinitionIdentifier, string $template): Response { return $this->render( $template, [ 'content' => $content, 'location' => $content->mainLocation, 'field_identifier' => $fieldDefinitionIdentifier, 'related_items' => $this->locationResolver->loadRelations($content->mainLocation, $fieldDefinitionIdentifier), 'view_type' => $request->attributes->get('viewType') ?? 'line', ] ); }
[ "public", "function", "viewRelatedItems", "(", "Request", "$", "request", ",", "Content", "$", "content", ",", "string", "$", "fieldDefinitionIdentifier", ",", "string", "$", "template", ")", ":", "Response", "{", "return", "$", "this", "->", "render", "(", "$", "template", ",", "[", "'content'", "=>", "$", "content", ",", "'location'", "=>", "$", "content", "->", "mainLocation", ",", "'field_identifier'", "=>", "$", "fieldDefinitionIdentifier", ",", "'related_items'", "=>", "$", "this", "->", "locationResolver", "->", "loadRelations", "(", "$", "content", "->", "mainLocation", ",", "$", "fieldDefinitionIdentifier", ")", ",", "'view_type'", "=>", "$", "request", "->", "attributes", "->", "get", "(", "'viewType'", ")", "??", "'line'", ",", "]", ")", ";", "}" ]
Action for rendering related items of a provided content.
[ "Action", "for", "rendering", "related", "items", "of", "a", "provided", "content", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Controller/PartsController.php#L36-L48
28,743
dereuromark/cakephp-markup
src/View/Helper/HighlighterHelper.php
HighlighterHelper.highlight
public function highlight($text, array $options = []) { if ($this->_config['debug']) { $this->_startTimer(); } $highlightedText = $this->_getHighlighter()->highlight($text, $options); if ($this->_config['debug']) { $highlightedText .= $this->_timeElapsedFormatted($this->_endTimer()); } return $highlightedText; }
php
public function highlight($text, array $options = []) { if ($this->_config['debug']) { $this->_startTimer(); } $highlightedText = $this->_getHighlighter()->highlight($text, $options); if ($this->_config['debug']) { $highlightedText .= $this->_timeElapsedFormatted($this->_endTimer()); } return $highlightedText; }
[ "public", "function", "highlight", "(", "$", "text", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "_config", "[", "'debug'", "]", ")", "{", "$", "this", "->", "_startTimer", "(", ")", ";", "}", "$", "highlightedText", "=", "$", "this", "->", "_getHighlighter", "(", ")", "->", "highlight", "(", "$", "text", ",", "$", "options", ")", ";", "if", "(", "$", "this", "->", "_config", "[", "'debug'", "]", ")", "{", "$", "highlightedText", ".=", "$", "this", "->", "_timeElapsedFormatted", "(", "$", "this", "->", "_endTimer", "(", ")", ")", ";", "}", "return", "$", "highlightedText", ";", "}" ]
Highlight a string. Options, depending on the specific highlighter class used: - templates - escape (defaults to true) - tabToSpaces (defaults to 4) - prefix (defaults to `language-`) @param string $text @param array $options @return string
[ "Highlight", "a", "string", "." ]
658c52b05b1e800b5640fceda77dce94eba90c2c
https://github.com/dereuromark/cakephp-markup/blob/658c52b05b1e800b5640fceda77dce94eba90c2c/src/View/Helper/HighlighterHelper.php#L58-L67
28,744
netgen/site-bundle
bundle/Menu/RelationListMenuBuilder.php
RelationListMenuBuilder.createRelationListMenu
public function createRelationListMenu(string $fieldIdentifier, $contentId = null): ItemInterface { $content = $contentId !== null ? $this->loadService->loadContent($contentId) : $this->siteInfoHelper->getSiteInfoContent(); $menu = $this->factory->createItem('root'); $menu->setAttribute('location-id', $content->mainLocationId); $menu->setExtra('ezlocation', $content->mainLocation); if (!$content->hasField($fieldIdentifier)) { return $menu; } $field = $content->getField($fieldIdentifier); if (!$field->value instanceof RelationListValue || $field->isEmpty()) { return $menu; } foreach ($field->value->destinationLocationIds as $locationId) { if (empty($locationId)) { $this->logger->error(sprintf('Empty location ID in RelationList field "%s" for content #%s', $fieldIdentifier, $content->id)); continue; } try { $location = $this->loadService->loadLocation($locationId); } catch (Throwable $t) { $this->logger->error($t->getMessage()); continue; } $menu->addChild(null, ['ezlocation' => $location]); } return $menu; }
php
public function createRelationListMenu(string $fieldIdentifier, $contentId = null): ItemInterface { $content = $contentId !== null ? $this->loadService->loadContent($contentId) : $this->siteInfoHelper->getSiteInfoContent(); $menu = $this->factory->createItem('root'); $menu->setAttribute('location-id', $content->mainLocationId); $menu->setExtra('ezlocation', $content->mainLocation); if (!$content->hasField($fieldIdentifier)) { return $menu; } $field = $content->getField($fieldIdentifier); if (!$field->value instanceof RelationListValue || $field->isEmpty()) { return $menu; } foreach ($field->value->destinationLocationIds as $locationId) { if (empty($locationId)) { $this->logger->error(sprintf('Empty location ID in RelationList field "%s" for content #%s', $fieldIdentifier, $content->id)); continue; } try { $location = $this->loadService->loadLocation($locationId); } catch (Throwable $t) { $this->logger->error($t->getMessage()); continue; } $menu->addChild(null, ['ezlocation' => $location]); } return $menu; }
[ "public", "function", "createRelationListMenu", "(", "string", "$", "fieldIdentifier", ",", "$", "contentId", "=", "null", ")", ":", "ItemInterface", "{", "$", "content", "=", "$", "contentId", "!==", "null", "?", "$", "this", "->", "loadService", "->", "loadContent", "(", "$", "contentId", ")", ":", "$", "this", "->", "siteInfoHelper", "->", "getSiteInfoContent", "(", ")", ";", "$", "menu", "=", "$", "this", "->", "factory", "->", "createItem", "(", "'root'", ")", ";", "$", "menu", "->", "setAttribute", "(", "'location-id'", ",", "$", "content", "->", "mainLocationId", ")", ";", "$", "menu", "->", "setExtra", "(", "'ezlocation'", ",", "$", "content", "->", "mainLocation", ")", ";", "if", "(", "!", "$", "content", "->", "hasField", "(", "$", "fieldIdentifier", ")", ")", "{", "return", "$", "menu", ";", "}", "$", "field", "=", "$", "content", "->", "getField", "(", "$", "fieldIdentifier", ")", ";", "if", "(", "!", "$", "field", "->", "value", "instanceof", "RelationListValue", "||", "$", "field", "->", "isEmpty", "(", ")", ")", "{", "return", "$", "menu", ";", "}", "foreach", "(", "$", "field", "->", "value", "->", "destinationLocationIds", "as", "$", "locationId", ")", "{", "if", "(", "empty", "(", "$", "locationId", ")", ")", "{", "$", "this", "->", "logger", "->", "error", "(", "sprintf", "(", "'Empty location ID in RelationList field \"%s\" for content #%s'", ",", "$", "fieldIdentifier", ",", "$", "content", "->", "id", ")", ")", ";", "continue", ";", "}", "try", "{", "$", "location", "=", "$", "this", "->", "loadService", "->", "loadLocation", "(", "$", "locationId", ")", ";", "}", "catch", "(", "Throwable", "$", "t", ")", "{", "$", "this", "->", "logger", "->", "error", "(", "$", "t", "->", "getMessage", "(", ")", ")", ";", "continue", ";", "}", "$", "menu", "->", "addChild", "(", "null", ",", "[", "'ezlocation'", "=>", "$", "location", "]", ")", ";", "}", "return", "$", "menu", ";", "}" ]
Creates the KNP menu from provided content and field identifier. @param mixed|null $contentId
[ "Creates", "the", "KNP", "menu", "from", "provided", "content", "and", "field", "identifier", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Menu/RelationListMenuBuilder.php#L55-L94
28,745
IconoCoders/otp-simple-sdk
Source/SimpleLiveUpdate.php
SimpleLiveUpdate.createHtmlForm
public function createHtmlForm($formName = 'SimplePayForm', $submitElement = 'button', $submitElementText = 'Start Payment') { if (count($this->errorMessage) > 0) { return false; } if (!$this->prepareFields("ORDER_HASH")) { $this->errorMessage[] = 'HASH FIELD: Missing hash field name'; return false; } $logString = ""; $this->luForm = "\n<form action='" . $this->baseUrl . $this->targetUrl . "' method='POST' id='" . $formName . "' accept-charset='UTF-8'>"; foreach ($this->formData as $name => $field) { if (is_array($field)) { foreach ($field as $subField) { $this->luForm .= $this->createHiddenField($name . "[]", $subField); $logString .= $name . '=' . $subField . "\n"; } } elseif (!is_array($field)) { if ($name == "BACK_REF" or $name == "TIMEOUT_URL") { $concat = '?'; if (strpos($field, '?') !== false) { $concat = '&'; } $field .= $concat . 'order_ref=' . $this->fieldData['ORDER_REF'] . '&order_currency=' . $this->fieldData['PRICES_CURRENCY']; $field = $this->protocol . '://' . $field; } $this->luForm .= $this->createHiddenField($name, $field); $logString .= $name . '=' . $field . "\n"; } } $this->luForm .= $this->createHiddenField("SDK_VERSION", $this->sdkVersion); $this->luForm .= $this->formSubmitElement($formName, $submitElement, $submitElementText); $this->luForm .= "\n</form>"; $this->logFunc("LiveUpdate", $this->formData, $this->formData['ORDER_REF']); $this->debugMessage[] = 'HASH CODE: ' . $this->hashCode; return $this->luForm; }
php
public function createHtmlForm($formName = 'SimplePayForm', $submitElement = 'button', $submitElementText = 'Start Payment') { if (count($this->errorMessage) > 0) { return false; } if (!$this->prepareFields("ORDER_HASH")) { $this->errorMessage[] = 'HASH FIELD: Missing hash field name'; return false; } $logString = ""; $this->luForm = "\n<form action='" . $this->baseUrl . $this->targetUrl . "' method='POST' id='" . $formName . "' accept-charset='UTF-8'>"; foreach ($this->formData as $name => $field) { if (is_array($field)) { foreach ($field as $subField) { $this->luForm .= $this->createHiddenField($name . "[]", $subField); $logString .= $name . '=' . $subField . "\n"; } } elseif (!is_array($field)) { if ($name == "BACK_REF" or $name == "TIMEOUT_URL") { $concat = '?'; if (strpos($field, '?') !== false) { $concat = '&'; } $field .= $concat . 'order_ref=' . $this->fieldData['ORDER_REF'] . '&order_currency=' . $this->fieldData['PRICES_CURRENCY']; $field = $this->protocol . '://' . $field; } $this->luForm .= $this->createHiddenField($name, $field); $logString .= $name . '=' . $field . "\n"; } } $this->luForm .= $this->createHiddenField("SDK_VERSION", $this->sdkVersion); $this->luForm .= $this->formSubmitElement($formName, $submitElement, $submitElementText); $this->luForm .= "\n</form>"; $this->logFunc("LiveUpdate", $this->formData, $this->formData['ORDER_REF']); $this->debugMessage[] = 'HASH CODE: ' . $this->hashCode; return $this->luForm; }
[ "public", "function", "createHtmlForm", "(", "$", "formName", "=", "'SimplePayForm'", ",", "$", "submitElement", "=", "'button'", ",", "$", "submitElementText", "=", "'Start Payment'", ")", "{", "if", "(", "count", "(", "$", "this", "->", "errorMessage", ")", ">", "0", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "prepareFields", "(", "\"ORDER_HASH\"", ")", ")", "{", "$", "this", "->", "errorMessage", "[", "]", "=", "'HASH FIELD: Missing hash field name'", ";", "return", "false", ";", "}", "$", "logString", "=", "\"\"", ";", "$", "this", "->", "luForm", "=", "\"\\n<form action='\"", ".", "$", "this", "->", "baseUrl", ".", "$", "this", "->", "targetUrl", ".", "\"' method='POST' id='\"", ".", "$", "formName", ".", "\"' accept-charset='UTF-8'>\"", ";", "foreach", "(", "$", "this", "->", "formData", "as", "$", "name", "=>", "$", "field", ")", "{", "if", "(", "is_array", "(", "$", "field", ")", ")", "{", "foreach", "(", "$", "field", "as", "$", "subField", ")", "{", "$", "this", "->", "luForm", ".=", "$", "this", "->", "createHiddenField", "(", "$", "name", ".", "\"[]\"", ",", "$", "subField", ")", ";", "$", "logString", ".=", "$", "name", ".", "'='", ".", "$", "subField", ".", "\"\\n\"", ";", "}", "}", "elseif", "(", "!", "is_array", "(", "$", "field", ")", ")", "{", "if", "(", "$", "name", "==", "\"BACK_REF\"", "or", "$", "name", "==", "\"TIMEOUT_URL\"", ")", "{", "$", "concat", "=", "'?'", ";", "if", "(", "strpos", "(", "$", "field", ",", "'?'", ")", "!==", "false", ")", "{", "$", "concat", "=", "'&'", ";", "}", "$", "field", ".=", "$", "concat", ".", "'order_ref='", ".", "$", "this", "->", "fieldData", "[", "'ORDER_REF'", "]", ".", "'&order_currency='", ".", "$", "this", "->", "fieldData", "[", "'PRICES_CURRENCY'", "]", ";", "$", "field", "=", "$", "this", "->", "protocol", ".", "'://'", ".", "$", "field", ";", "}", "$", "this", "->", "luForm", ".=", "$", "this", "->", "createHiddenField", "(", "$", "name", ",", "$", "field", ")", ";", "$", "logString", ".=", "$", "name", ".", "'='", ".", "$", "field", ".", "\"\\n\"", ";", "}", "}", "$", "this", "->", "luForm", ".=", "$", "this", "->", "createHiddenField", "(", "\"SDK_VERSION\"", ",", "$", "this", "->", "sdkVersion", ")", ";", "$", "this", "->", "luForm", ".=", "$", "this", "->", "formSubmitElement", "(", "$", "formName", ",", "$", "submitElement", ",", "$", "submitElementText", ")", ";", "$", "this", "->", "luForm", ".=", "\"\\n</form>\"", ";", "$", "this", "->", "logFunc", "(", "\"LiveUpdate\"", ",", "$", "this", "->", "formData", ",", "$", "this", "->", "formData", "[", "'ORDER_REF'", "]", ")", ";", "$", "this", "->", "debugMessage", "[", "]", "=", "'HASH CODE: '", ".", "$", "this", "->", "hashCode", ";", "return", "$", "this", "->", "luForm", ";", "}" ]
Generates a ready-to-insert HTML FORM @param string $formName The ID parameter of the form @param string $submitElement The type of the submit element ('button' or 'link') @param string $submitElementText The label for the submit element @return string HTML form
[ "Generates", "a", "ready", "-", "to", "-", "insert", "HTML", "FORM" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleLiveUpdate.php#L154-L191
28,746
IconoCoders/otp-simple-sdk
Source/SimpleLiveUpdate.php
SimpleLiveUpdate.formSubmitElement
protected function formSubmitElement($formName = '', $submitElement = 'button', $submitElementText = '') { switch ($submitElement) { case 'link': $element = "\n<a href='javascript:document.getElementById(\"" . $formName ."\").submit()'>" . addslashes($submitElementText) . "</a>"; break; case 'button': $element = "\n<button type='submit'>" . addslashes($submitElementText) . "</button>"; break; case 'auto': $element = "\n<button type='submit'>" . addslashes($submitElementText) . "</button>"; $element .= "\n<script language=\"javascript\" type=\"text/javascript\">document.getElementById(\"" . $formName . "\").submit();</script>"; break; default : $element = "\n<button type='submit'>" . addslashes($submitElementText) . "</button>"; break; } return $element; }
php
protected function formSubmitElement($formName = '', $submitElement = 'button', $submitElementText = '') { switch ($submitElement) { case 'link': $element = "\n<a href='javascript:document.getElementById(\"" . $formName ."\").submit()'>" . addslashes($submitElementText) . "</a>"; break; case 'button': $element = "\n<button type='submit'>" . addslashes($submitElementText) . "</button>"; break; case 'auto': $element = "\n<button type='submit'>" . addslashes($submitElementText) . "</button>"; $element .= "\n<script language=\"javascript\" type=\"text/javascript\">document.getElementById(\"" . $formName . "\").submit();</script>"; break; default : $element = "\n<button type='submit'>" . addslashes($submitElementText) . "</button>"; break; } return $element; }
[ "protected", "function", "formSubmitElement", "(", "$", "formName", "=", "''", ",", "$", "submitElement", "=", "'button'", ",", "$", "submitElementText", "=", "''", ")", "{", "switch", "(", "$", "submitElement", ")", "{", "case", "'link'", ":", "$", "element", "=", "\"\\n<a href='javascript:document.getElementById(\\\"\"", ".", "$", "formName", ".", "\"\\\").submit()'>\"", ".", "addslashes", "(", "$", "submitElementText", ")", ".", "\"</a>\"", ";", "break", ";", "case", "'button'", ":", "$", "element", "=", "\"\\n<button type='submit'>\"", ".", "addslashes", "(", "$", "submitElementText", ")", ".", "\"</button>\"", ";", "break", ";", "case", "'auto'", ":", "$", "element", "=", "\"\\n<button type='submit'>\"", ".", "addslashes", "(", "$", "submitElementText", ")", ".", "\"</button>\"", ";", "$", "element", ".=", "\"\\n<script language=\\\"javascript\\\" type=\\\"text/javascript\\\">document.getElementById(\\\"\"", ".", "$", "formName", ".", "\"\\\").submit();</script>\"", ";", "break", ";", "default", ":", "$", "element", "=", "\"\\n<button type='submit'>\"", ".", "addslashes", "(", "$", "submitElementText", ")", ".", "\"</button>\"", ";", "break", ";", "}", "return", "$", "element", ";", "}" ]
Generates HTML submit element @param string $formName The ID parameter of the form @param string $submitElement The type of the submit element ('button' or 'link') @param string $submitElementText The lebel for the submit element @return string HTML submit
[ "Generates", "HTML", "submit", "element" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleLiveUpdate.php#L204-L222
28,747
IconoCoders/otp-simple-sdk
Source/SimpleIpn.php
SimpleIpn.validateReceived
public function validateReceived() { $this->debugMessage[] = 'IPN VALIDATION: START'; if (!$this->ipnPostDataCheck()) { $this->debugMessage[] = 'IPN VALIDATION: END'; return false; } //'ORDERSTATUS' $this->logFunc("IPN", $this->postData, @$this->postData['REFNOEXT']); if (!in_array(trim($this->postData['ORDERSTATUS']), $this->successfulStatus)) { $this->errorMessage[] = 'INVALID IPN ORDER STATUS: ' . $this->postData['ORDERSTATUS']; $this->debugMessage[] = 'IPN VALIDATION: END'; return false; } $validationResult = false; $calculatedHashString = $this->createHashString($this->flatArray($this->postData, array("HASH"))); if ($calculatedHashString == $this->postData['HASH']) { $validationResult = true; } if ($validationResult) { $this->debugMessage[] = 'IPN VALIDATION: ' . 'SUCCESSFUL'; $this->debugMessage[] = 'IPN CALCULATED HASH: ' . $calculatedHashString; $this->debugMessage[] = 'IPN HASH: ' . $this->postData['HASH']; $this->debugMessage[] = 'IPN VALIDATION: END'; return true; } elseif (!$validationResult) { $this->errorMessage[] = 'IPN VALIDATION: ' . 'FAILED'; $this->errorMessage[] = 'IPN CALCULATED HASH: ' . $calculatedHashString; $this->errorMessage[] = 'IPN RECEIVED HASH: ' . $this->postData['HASH']; $this->debugMessage[] = 'IPN VALIDATION: END'; return false; } return false; }
php
public function validateReceived() { $this->debugMessage[] = 'IPN VALIDATION: START'; if (!$this->ipnPostDataCheck()) { $this->debugMessage[] = 'IPN VALIDATION: END'; return false; } //'ORDERSTATUS' $this->logFunc("IPN", $this->postData, @$this->postData['REFNOEXT']); if (!in_array(trim($this->postData['ORDERSTATUS']), $this->successfulStatus)) { $this->errorMessage[] = 'INVALID IPN ORDER STATUS: ' . $this->postData['ORDERSTATUS']; $this->debugMessage[] = 'IPN VALIDATION: END'; return false; } $validationResult = false; $calculatedHashString = $this->createHashString($this->flatArray($this->postData, array("HASH"))); if ($calculatedHashString == $this->postData['HASH']) { $validationResult = true; } if ($validationResult) { $this->debugMessage[] = 'IPN VALIDATION: ' . 'SUCCESSFUL'; $this->debugMessage[] = 'IPN CALCULATED HASH: ' . $calculatedHashString; $this->debugMessage[] = 'IPN HASH: ' . $this->postData['HASH']; $this->debugMessage[] = 'IPN VALIDATION: END'; return true; } elseif (!$validationResult) { $this->errorMessage[] = 'IPN VALIDATION: ' . 'FAILED'; $this->errorMessage[] = 'IPN CALCULATED HASH: ' . $calculatedHashString; $this->errorMessage[] = 'IPN RECEIVED HASH: ' . $this->postData['HASH']; $this->debugMessage[] = 'IPN VALIDATION: END'; return false; } return false; }
[ "public", "function", "validateReceived", "(", ")", "{", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN VALIDATION: START'", ";", "if", "(", "!", "$", "this", "->", "ipnPostDataCheck", "(", ")", ")", "{", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN VALIDATION: END'", ";", "return", "false", ";", "}", "//'ORDERSTATUS'", "$", "this", "->", "logFunc", "(", "\"IPN\"", ",", "$", "this", "->", "postData", ",", "@", "$", "this", "->", "postData", "[", "'REFNOEXT'", "]", ")", ";", "if", "(", "!", "in_array", "(", "trim", "(", "$", "this", "->", "postData", "[", "'ORDERSTATUS'", "]", ")", ",", "$", "this", "->", "successfulStatus", ")", ")", "{", "$", "this", "->", "errorMessage", "[", "]", "=", "'INVALID IPN ORDER STATUS: '", ".", "$", "this", "->", "postData", "[", "'ORDERSTATUS'", "]", ";", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN VALIDATION: END'", ";", "return", "false", ";", "}", "$", "validationResult", "=", "false", ";", "$", "calculatedHashString", "=", "$", "this", "->", "createHashString", "(", "$", "this", "->", "flatArray", "(", "$", "this", "->", "postData", ",", "array", "(", "\"HASH\"", ")", ")", ")", ";", "if", "(", "$", "calculatedHashString", "==", "$", "this", "->", "postData", "[", "'HASH'", "]", ")", "{", "$", "validationResult", "=", "true", ";", "}", "if", "(", "$", "validationResult", ")", "{", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN VALIDATION: '", ".", "'SUCCESSFUL'", ";", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN CALCULATED HASH: '", ".", "$", "calculatedHashString", ";", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN HASH: '", ".", "$", "this", "->", "postData", "[", "'HASH'", "]", ";", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN VALIDATION: END'", ";", "return", "true", ";", "}", "elseif", "(", "!", "$", "validationResult", ")", "{", "$", "this", "->", "errorMessage", "[", "]", "=", "'IPN VALIDATION: '", ".", "'FAILED'", ";", "$", "this", "->", "errorMessage", "[", "]", "=", "'IPN CALCULATED HASH: '", ".", "$", "calculatedHashString", ";", "$", "this", "->", "errorMessage", "[", "]", "=", "'IPN RECEIVED HASH: '", ".", "$", "this", "->", "postData", "[", "'HASH'", "]", ";", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN VALIDATION: END'", ";", "return", "false", ";", "}", "return", "false", ";", "}" ]
Validate recceived data against HMAC HASH @return boolean
[ "Validate", "recceived", "data", "against", "HMAC", "HASH" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleIpn.php#L81-L115
28,748
IconoCoders/otp-simple-sdk
Source/SimpleIpn.php
SimpleIpn.confirmReceived
public function confirmReceived() { $this->debugMessage[] = 'IPN CONFIRM: START'; if (!$this->ipnPostDataCheck()) { $this->debugMessage[] = 'IPN CONFIRM: END'; return false; } $serverDate = @date("YmdHis"); $hashArray = array( $this->postData['IPN_PID'][0], $this->postData['IPN_PNAME'][0], $this->postData['IPN_DATE'], $serverDate ); $hash = $this->createHashString($hashArray); $string = "<EPAYMENT>" . $serverDate . "|" . $hash . "</EPAYMENT>"; $this->debugMessage[] = 'IPN CONFIRM EPAYMENT: ' . $string; $this->debugMessage[] = 'IPN CONFIRM: END'; if ($this->echo) { echo $string; } return $string; }
php
public function confirmReceived() { $this->debugMessage[] = 'IPN CONFIRM: START'; if (!$this->ipnPostDataCheck()) { $this->debugMessage[] = 'IPN CONFIRM: END'; return false; } $serverDate = @date("YmdHis"); $hashArray = array( $this->postData['IPN_PID'][0], $this->postData['IPN_PNAME'][0], $this->postData['IPN_DATE'], $serverDate ); $hash = $this->createHashString($hashArray); $string = "<EPAYMENT>" . $serverDate . "|" . $hash . "</EPAYMENT>"; $this->debugMessage[] = 'IPN CONFIRM EPAYMENT: ' . $string; $this->debugMessage[] = 'IPN CONFIRM: END'; if ($this->echo) { echo $string; } return $string; }
[ "public", "function", "confirmReceived", "(", ")", "{", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN CONFIRM: START'", ";", "if", "(", "!", "$", "this", "->", "ipnPostDataCheck", "(", ")", ")", "{", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN CONFIRM: END'", ";", "return", "false", ";", "}", "$", "serverDate", "=", "@", "date", "(", "\"YmdHis\"", ")", ";", "$", "hashArray", "=", "array", "(", "$", "this", "->", "postData", "[", "'IPN_PID'", "]", "[", "0", "]", ",", "$", "this", "->", "postData", "[", "'IPN_PNAME'", "]", "[", "0", "]", ",", "$", "this", "->", "postData", "[", "'IPN_DATE'", "]", ",", "$", "serverDate", ")", ";", "$", "hash", "=", "$", "this", "->", "createHashString", "(", "$", "hashArray", ")", ";", "$", "string", "=", "\"<EPAYMENT>\"", ".", "$", "serverDate", ".", "\"|\"", ".", "$", "hash", ".", "\"</EPAYMENT>\"", ";", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN CONFIRM EPAYMENT: '", ".", "$", "string", ";", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN CONFIRM: END'", ";", "if", "(", "$", "this", "->", "echo", ")", "{", "echo", "$", "string", ";", "}", "return", "$", "string", ";", "}" ]
Creates INLINE string for corfirmation @return string $string <EPAYMENT> tag
[ "Creates", "INLINE", "string", "for", "corfirmation" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleIpn.php#L123-L146
28,749
IconoCoders/otp-simple-sdk
Source/SimpleIpn.php
SimpleIpn.ipnPostDataCheck
protected function ipnPostDataCheck() { if (count($this->postData) < 1 || !array_key_exists('REFNOEXT', $this->postData)) { $this->debugMessage[] = 'IPN POST: MISSING CONTENT'; $this->errorMessage[] = 'IPN POST: MISSING CONTENT'; return false; } return true; }
php
protected function ipnPostDataCheck() { if (count($this->postData) < 1 || !array_key_exists('REFNOEXT', $this->postData)) { $this->debugMessage[] = 'IPN POST: MISSING CONTENT'; $this->errorMessage[] = 'IPN POST: MISSING CONTENT'; return false; } return true; }
[ "protected", "function", "ipnPostDataCheck", "(", ")", "{", "if", "(", "count", "(", "$", "this", "->", "postData", ")", "<", "1", "||", "!", "array_key_exists", "(", "'REFNOEXT'", ",", "$", "this", "->", "postData", ")", ")", "{", "$", "this", "->", "debugMessage", "[", "]", "=", "'IPN POST: MISSING CONTENT'", ";", "$", "this", "->", "errorMessage", "[", "]", "=", "'IPN POST: MISSING CONTENT'", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check post data if contains REFNOEXT variable @return boolean
[ "Check", "post", "data", "if", "contains", "REFNOEXT", "variable" ]
d2808bf52e8d34be69414b444a00f1a9c8564930
https://github.com/IconoCoders/otp-simple-sdk/blob/d2808bf52e8d34be69414b444a00f1a9c8564930/Source/SimpleIpn.php#L154-L162
28,750
netgen/site-bundle
bundle/DependencyInjection/Compiler/XslRegisterPass.php
XslRegisterPass.process
public function process(ContainerBuilder $container): void { $scopes = array_merge( [ConfigResolver::SCOPE_DEFAULT], $container->getParameter('ezpublish.siteaccess.list') ); // Adding ezxml_tags.xsl to all scopes foreach ($scopes as $scope) { if (!$container->hasParameter("ezsettings.${scope}.fieldtypes.ezxml.custom_xsl")) { continue; } $xslConfig = $container->getParameter("ezsettings.${scope}.fieldtypes.ezxml.custom_xsl"); $xslConfig[] = ['path' => __DIR__ . '/../../Resources/xsl/ezxml_tags.xsl', 'priority' => 5000]; $container->setParameter("ezsettings.${scope}.fieldtypes.ezxml.custom_xsl", $xslConfig); } }
php
public function process(ContainerBuilder $container): void { $scopes = array_merge( [ConfigResolver::SCOPE_DEFAULT], $container->getParameter('ezpublish.siteaccess.list') ); // Adding ezxml_tags.xsl to all scopes foreach ($scopes as $scope) { if (!$container->hasParameter("ezsettings.${scope}.fieldtypes.ezxml.custom_xsl")) { continue; } $xslConfig = $container->getParameter("ezsettings.${scope}.fieldtypes.ezxml.custom_xsl"); $xslConfig[] = ['path' => __DIR__ . '/../../Resources/xsl/ezxml_tags.xsl', 'priority' => 5000]; $container->setParameter("ezsettings.${scope}.fieldtypes.ezxml.custom_xsl", $xslConfig); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", ":", "void", "{", "$", "scopes", "=", "array_merge", "(", "[", "ConfigResolver", "::", "SCOPE_DEFAULT", "]", ",", "$", "container", "->", "getParameter", "(", "'ezpublish.siteaccess.list'", ")", ")", ";", "// Adding ezxml_tags.xsl to all scopes", "foreach", "(", "$", "scopes", "as", "$", "scope", ")", "{", "if", "(", "!", "$", "container", "->", "hasParameter", "(", "\"ezsettings.${scope}.fieldtypes.ezxml.custom_xsl\"", ")", ")", "{", "continue", ";", "}", "$", "xslConfig", "=", "$", "container", "->", "getParameter", "(", "\"ezsettings.${scope}.fieldtypes.ezxml.custom_xsl\"", ")", ";", "$", "xslConfig", "[", "]", "=", "[", "'path'", "=>", "__DIR__", ".", "'/../../Resources/xsl/ezxml_tags.xsl'", ",", "'priority'", "=>", "5000", "]", ";", "$", "container", "->", "setParameter", "(", "\"ezsettings.${scope}.fieldtypes.ezxml.custom_xsl\"", ",", "$", "xslConfig", ")", ";", "}", "}" ]
Registers ezxml_tags.xsl as custom XSL stylesheet for ezxmltext field type.
[ "Registers", "ezxml_tags", ".", "xsl", "as", "custom", "XSL", "stylesheet", "for", "ezxmltext", "field", "type", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/DependencyInjection/Compiler/XslRegisterPass.php#L16-L33
28,751
alaxos/cakephp3-libs
src/View/Helper/AlaxosHtmlHelper.php
AlaxosHtmlHelper.encodeEmail
public function encodeEmail($email) { $this->includeAlaxosEncodeJS(); $js_code = '<script type="text/javascript">'; $email_id = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, 1) . intval(mt_rand()); //valid XHTML tag id can not start with a number $js_code .= 'alaxos_' . $email_id . '='; for($i = 0; $i < strlen($email); $i++) { $char = strtolower($email[$i]); switch($char) { case '.': $js_code .= 'l_dot.charAt(0)'; break; case '_': $js_code .= 'l_under.charAt(0)'; break; case '-': $js_code .= 'l_dash.charAt(0)'; break; case '@': $js_code .= 'l_at.charAt(0)'; break; default: $js_code .= 'l_' . $char . '.charAt(0)'; break; } $js_code .= ($i < strlen($email) - 1) ? '+' : ''; } if(!$this->getView()->getRequest()->is('ajax')) { $js_code .= ';' . $this->getConfig('jquery_variable') . '(document).ready(function(){ ' . $this->getConfig('jquery_variable') . '("#' . $email_id . '").attr("href", "mailto:" + alaxos_' . $email_id . ');' . $this->getConfig('jquery_variable') . '("#' . $email_id . '").html(alaxos_' . $email_id . '); });</script><a id="' . $email_id . '"><em>missing email</em></a>'; } else { $js_code .= ';' . $this->getConfig('jquery_variable') . '("#' . $email_id . '").attr("href", "mailto:" + alaxos_' . $email_id . ');' . $this->getConfig('jquery_variable') . '("#' . $email_id . '").html(alaxos_' . $email_id . ');</script><a id="' . $email_id . '"><em>missing email</em></a>'; } return $js_code; }
php
public function encodeEmail($email) { $this->includeAlaxosEncodeJS(); $js_code = '<script type="text/javascript">'; $email_id = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, 1) . intval(mt_rand()); //valid XHTML tag id can not start with a number $js_code .= 'alaxos_' . $email_id . '='; for($i = 0; $i < strlen($email); $i++) { $char = strtolower($email[$i]); switch($char) { case '.': $js_code .= 'l_dot.charAt(0)'; break; case '_': $js_code .= 'l_under.charAt(0)'; break; case '-': $js_code .= 'l_dash.charAt(0)'; break; case '@': $js_code .= 'l_at.charAt(0)'; break; default: $js_code .= 'l_' . $char . '.charAt(0)'; break; } $js_code .= ($i < strlen($email) - 1) ? '+' : ''; } if(!$this->getView()->getRequest()->is('ajax')) { $js_code .= ';' . $this->getConfig('jquery_variable') . '(document).ready(function(){ ' . $this->getConfig('jquery_variable') . '("#' . $email_id . '").attr("href", "mailto:" + alaxos_' . $email_id . ');' . $this->getConfig('jquery_variable') . '("#' . $email_id . '").html(alaxos_' . $email_id . '); });</script><a id="' . $email_id . '"><em>missing email</em></a>'; } else { $js_code .= ';' . $this->getConfig('jquery_variable') . '("#' . $email_id . '").attr("href", "mailto:" + alaxos_' . $email_id . ');' . $this->getConfig('jquery_variable') . '("#' . $email_id . '").html(alaxos_' . $email_id . ');</script><a id="' . $email_id . '"><em>missing email</em></a>'; } return $js_code; }
[ "public", "function", "encodeEmail", "(", "$", "email", ")", "{", "$", "this", "->", "includeAlaxosEncodeJS", "(", ")", ";", "$", "js_code", "=", "'<script type=\"text/javascript\">'", ";", "$", "email_id", "=", "substr", "(", "str_shuffle", "(", "'abcdefghijklmnopqrstuvwxyz'", ")", ",", "0", ",", "1", ")", ".", "intval", "(", "mt_rand", "(", ")", ")", ";", "//valid XHTML tag id can not start with a number", "$", "js_code", ".=", "'alaxos_'", ".", "$", "email_id", ".", "'='", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "email", ")", ";", "$", "i", "++", ")", "{", "$", "char", "=", "strtolower", "(", "$", "email", "[", "$", "i", "]", ")", ";", "switch", "(", "$", "char", ")", "{", "case", "'.'", ":", "$", "js_code", ".=", "'l_dot.charAt(0)'", ";", "break", ";", "case", "'_'", ":", "$", "js_code", ".=", "'l_under.charAt(0)'", ";", "break", ";", "case", "'-'", ":", "$", "js_code", ".=", "'l_dash.charAt(0)'", ";", "break", ";", "case", "'@'", ":", "$", "js_code", ".=", "'l_at.charAt(0)'", ";", "break", ";", "default", ":", "$", "js_code", ".=", "'l_'", ".", "$", "char", ".", "'.charAt(0)'", ";", "break", ";", "}", "$", "js_code", ".=", "(", "$", "i", "<", "strlen", "(", "$", "email", ")", "-", "1", ")", "?", "'+'", ":", "''", ";", "}", "if", "(", "!", "$", "this", "->", "getView", "(", ")", "->", "getRequest", "(", ")", "->", "is", "(", "'ajax'", ")", ")", "{", "$", "js_code", ".=", "';'", ".", "$", "this", "->", "getConfig", "(", "'jquery_variable'", ")", ".", "'(document).ready(function(){\t'", ".", "$", "this", "->", "getConfig", "(", "'jquery_variable'", ")", ".", "'(\"#'", ".", "$", "email_id", ".", "'\").attr(\"href\", \"mailto:\" + alaxos_'", ".", "$", "email_id", ".", "');'", ".", "$", "this", "->", "getConfig", "(", "'jquery_variable'", ")", ".", "'(\"#'", ".", "$", "email_id", ".", "'\").html(alaxos_'", ".", "$", "email_id", ".", "');\t});</script><a id=\"'", ".", "$", "email_id", ".", "'\"><em>missing email</em></a>'", ";", "}", "else", "{", "$", "js_code", ".=", "';'", ".", "$", "this", "->", "getConfig", "(", "'jquery_variable'", ")", ".", "'(\"#'", ".", "$", "email_id", ".", "'\").attr(\"href\", \"mailto:\" + alaxos_'", ".", "$", "email_id", ".", "');'", ".", "$", "this", "->", "getConfig", "(", "'jquery_variable'", ")", ".", "'(\"#'", ".", "$", "email_id", ".", "'\").html(alaxos_'", ".", "$", "email_id", ".", "');</script><a id=\"'", ".", "$", "email_id", ".", "'\"><em>missing email</em></a>'", ";", "}", "return", "$", "js_code", ";", "}" ]
Return a string that is a JS encoded email address. Printing this JS string instead of the plain email text should reduce the probability to get the email harvested by spamming robots. Note: The returned string is made of a <script> block and a <a> block. @param $email
[ "Return", "a", "string", "that", "is", "a", "JS", "encoded", "email", "address", "." ]
685e9f17a3fbe3550c59a03a65c4d75df763e804
https://github.com/alaxos/cakephp3-libs/blob/685e9f17a3fbe3550c59a03a65c4d75df763e804/src/View/Helper/AlaxosHtmlHelper.php#L242-L287
28,752
alaxos/cakephp3-libs
src/Model/Behavior/TimezonedBehavior.php
TimezonedBehavior.prepareTimezonedDatetimeValuesForSaving
public function prepareTimezonedDatetimeValuesForSaving(\ArrayObject $data) { $display_timezone = null; if(Configure::check('display_timezone')) { $display_timezone = Configure::read('display_timezone'); } elseif(Configure::check('default_display_timezone')) { $display_timezone = Configure::read('default_display_timezone'); } $server_default_timezone = date_default_timezone_get(); if(!empty($display_timezone) && !empty($server_default_timezone)) { foreach($data as $field => $value) { if(isset($value) && !empty($value)) { $fieldtype = $this->_table->getSchema()->getColumn($field)['type']; if($fieldtype == 'datetime') { if(is_string($value)) { $data[$field] = Time::parse($value, $display_timezone)->setTimezone($server_default_timezone); } elseif(is_a($value, 'Cake\I18n\Time')) { $value->setTimezone($server_default_timezone); } } elseif($fieldtype == 'date') { if(is_string($value)) { $data[$field] = Time::parse($value, $display_timezone); } } } } } }
php
public function prepareTimezonedDatetimeValuesForSaving(\ArrayObject $data) { $display_timezone = null; if(Configure::check('display_timezone')) { $display_timezone = Configure::read('display_timezone'); } elseif(Configure::check('default_display_timezone')) { $display_timezone = Configure::read('default_display_timezone'); } $server_default_timezone = date_default_timezone_get(); if(!empty($display_timezone) && !empty($server_default_timezone)) { foreach($data as $field => $value) { if(isset($value) && !empty($value)) { $fieldtype = $this->_table->getSchema()->getColumn($field)['type']; if($fieldtype == 'datetime') { if(is_string($value)) { $data[$field] = Time::parse($value, $display_timezone)->setTimezone($server_default_timezone); } elseif(is_a($value, 'Cake\I18n\Time')) { $value->setTimezone($server_default_timezone); } } elseif($fieldtype == 'date') { if(is_string($value)) { $data[$field] = Time::parse($value, $display_timezone); } } } } } }
[ "public", "function", "prepareTimezonedDatetimeValuesForSaving", "(", "\\", "ArrayObject", "$", "data", ")", "{", "$", "display_timezone", "=", "null", ";", "if", "(", "Configure", "::", "check", "(", "'display_timezone'", ")", ")", "{", "$", "display_timezone", "=", "Configure", "::", "read", "(", "'display_timezone'", ")", ";", "}", "elseif", "(", "Configure", "::", "check", "(", "'default_display_timezone'", ")", ")", "{", "$", "display_timezone", "=", "Configure", "::", "read", "(", "'default_display_timezone'", ")", ";", "}", "$", "server_default_timezone", "=", "date_default_timezone_get", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "display_timezone", ")", "&&", "!", "empty", "(", "$", "server_default_timezone", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "field", "=>", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "value", ")", "&&", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "fieldtype", "=", "$", "this", "->", "_table", "->", "getSchema", "(", ")", "->", "getColumn", "(", "$", "field", ")", "[", "'type'", "]", ";", "if", "(", "$", "fieldtype", "==", "'datetime'", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "data", "[", "$", "field", "]", "=", "Time", "::", "parse", "(", "$", "value", ",", "$", "display_timezone", ")", "->", "setTimezone", "(", "$", "server_default_timezone", ")", ";", "}", "elseif", "(", "is_a", "(", "$", "value", ",", "'Cake\\I18n\\Time'", ")", ")", "{", "$", "value", "->", "setTimezone", "(", "$", "server_default_timezone", ")", ";", "}", "}", "elseif", "(", "$", "fieldtype", "==", "'date'", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "data", "[", "$", "field", "]", "=", "Time", "::", "parse", "(", "$", "value", ",", "$", "display_timezone", ")", ";", "}", "}", "}", "}", "}", "}" ]
Convert datetime strings that are entered in the display time zone to UTC Time objects that will allow to save datetime in UTC @param \ArrayObject $data
[ "Convert", "datetime", "strings", "that", "are", "entered", "in", "the", "display", "time", "zone", "to", "UTC", "Time", "objects", "that", "will", "allow", "to", "save", "datetime", "in", "UTC" ]
685e9f17a3fbe3550c59a03a65c4d75df763e804
https://github.com/alaxos/cakephp3-libs/blob/685e9f17a3fbe3550c59a03a65c4d75df763e804/src/Model/Behavior/TimezonedBehavior.php#L27-L71
28,753
netgen/site-bundle
bundle/EventListener/User/PostActivateEventListener.php
PostActivateEventListener.onPostActivate
public function onPostActivate(PostActivateEvent $event): void { $user = $event->getUser(); $this->ezUserAccountKeyRepository->removeByUserId($user->id); $this->ngUserSettingRepository->activateUser($user->id); $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.welcome.subject', $this->configResolver->getParameter('template.user.mail.welcome', 'ngsite'), [ 'user' => $user, ] ); }
php
public function onPostActivate(PostActivateEvent $event): void { $user = $event->getUser(); $this->ezUserAccountKeyRepository->removeByUserId($user->id); $this->ngUserSettingRepository->activateUser($user->id); $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.welcome.subject', $this->configResolver->getParameter('template.user.mail.welcome', 'ngsite'), [ 'user' => $user, ] ); }
[ "public", "function", "onPostActivate", "(", "PostActivateEvent", "$", "event", ")", ":", "void", "{", "$", "user", "=", "$", "event", "->", "getUser", "(", ")", ";", "$", "this", "->", "ezUserAccountKeyRepository", "->", "removeByUserId", "(", "$", "user", "->", "id", ")", ";", "$", "this", "->", "ngUserSettingRepository", "->", "activateUser", "(", "$", "user", "->", "id", ")", ";", "$", "this", "->", "mailHelper", "->", "sendMail", "(", "[", "$", "user", "->", "email", "=>", "$", "this", "->", "getUserName", "(", "$", "user", ")", "]", ",", "'ngsite.user.welcome.subject'", ",", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'template.user.mail.welcome'", ",", "'ngsite'", ")", ",", "[", "'user'", "=>", "$", "user", ",", "]", ")", ";", "}" ]
Listens to the event triggered after the user activation has been finished. Event contains information about activated user.
[ "Listens", "to", "the", "event", "triggered", "after", "the", "user", "activation", "has", "been", "finished", ".", "Event", "contains", "information", "about", "activated", "user", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/EventListener/User/PostActivateEventListener.php#L30-L46
28,754
nilportugues/php-api-transformer
src/Transformer/Helpers/RecursiveFormatterHelper.php
RecursiveFormatterHelper.namespaceAsArrayKey
public static function namespaceAsArrayKey(string $key) : string { $keys = \explode('\\', $key); $className = \end($keys); return self::camelCaseToUnderscore($className); }
php
public static function namespaceAsArrayKey(string $key) : string { $keys = \explode('\\', $key); $className = \end($keys); return self::camelCaseToUnderscore($className); }
[ "public", "static", "function", "namespaceAsArrayKey", "(", "string", "$", "key", ")", ":", "string", "{", "$", "keys", "=", "\\", "explode", "(", "'\\\\'", ",", "$", "key", ")", ";", "$", "className", "=", "\\", "end", "(", "$", "keys", ")", ";", "return", "self", "::", "camelCaseToUnderscore", "(", "$", "className", ")", ";", "}" ]
Given a class name will return its name without the namespace and in under_score to be used as a key in an array. @param string $key @return string
[ "Given", "a", "class", "name", "will", "return", "its", "name", "without", "the", "namespace", "and", "in", "under_score", "to", "be", "used", "as", "a", "key", "in", "an", "array", "." ]
a9f20fbe1580d98e3d462a0ebe13fb7595cbd683
https://github.com/nilportugues/php-api-transformer/blob/a9f20fbe1580d98e3d462a0ebe13fb7595cbd683/src/Transformer/Helpers/RecursiveFormatterHelper.php#L26-L32
28,755
nilportugues/php-api-transformer
src/Transformer/Helpers/RecursiveFormatterHelper.php
RecursiveFormatterHelper.camelCaseToUnderscore
public static function camelCaseToUnderscore(string $camel, string $splitter = '_') : string { $camel = \preg_replace( '/(?!^)[[:upper:]][[:lower:]]/', '$0', \preg_replace('/(?!^)[[:upper:]]+/', $splitter.'$0', $camel) ); return \strtolower($camel); }
php
public static function camelCaseToUnderscore(string $camel, string $splitter = '_') : string { $camel = \preg_replace( '/(?!^)[[:upper:]][[:lower:]]/', '$0', \preg_replace('/(?!^)[[:upper:]]+/', $splitter.'$0', $camel) ); return \strtolower($camel); }
[ "public", "static", "function", "camelCaseToUnderscore", "(", "string", "$", "camel", ",", "string", "$", "splitter", "=", "'_'", ")", ":", "string", "{", "$", "camel", "=", "\\", "preg_replace", "(", "'/(?!^)[[:upper:]][[:lower:]]/'", ",", "'$0'", ",", "\\", "preg_replace", "(", "'/(?!^)[[:upper:]]+/'", ",", "$", "splitter", ".", "'$0'", ",", "$", "camel", ")", ")", ";", "return", "\\", "strtolower", "(", "$", "camel", ")", ";", "}" ]
Transforms a given string from camelCase to under_score style. @param string $camel @param string $splitter @return string
[ "Transforms", "a", "given", "string", "from", "camelCase", "to", "under_score", "style", "." ]
a9f20fbe1580d98e3d462a0ebe13fb7595cbd683
https://github.com/nilportugues/php-api-transformer/blob/a9f20fbe1580d98e3d462a0ebe13fb7595cbd683/src/Transformer/Helpers/RecursiveFormatterHelper.php#L42-L51
28,756
netgen/site-bundle
bundle/Entity/Repository/EzUserAccountKeyRepository.php
EzUserAccountKeyRepository.create
public function create($userId): EzUserAccountKey { $this->removeByUserId($userId); $randomBytes = false; if (function_exists('openssl_random_pseudo_bytes')) { $randomBytes = openssl_random_pseudo_bytes(32); } if ($randomBytes === false) { $randomBytes = mt_rand(); } $hash = md5($userId . ':' . microtime() . ':' . $randomBytes); $userAccount = new EzUserAccountKey(); $userAccount->setHash($hash); $userAccount->setTime(time()); $userAccount->setUserId($userId); $this->getEntityManager()->persist($userAccount); $this->getEntityManager()->flush(); return $userAccount; }
php
public function create($userId): EzUserAccountKey { $this->removeByUserId($userId); $randomBytes = false; if (function_exists('openssl_random_pseudo_bytes')) { $randomBytes = openssl_random_pseudo_bytes(32); } if ($randomBytes === false) { $randomBytes = mt_rand(); } $hash = md5($userId . ':' . microtime() . ':' . $randomBytes); $userAccount = new EzUserAccountKey(); $userAccount->setHash($hash); $userAccount->setTime(time()); $userAccount->setUserId($userId); $this->getEntityManager()->persist($userAccount); $this->getEntityManager()->flush(); return $userAccount; }
[ "public", "function", "create", "(", "$", "userId", ")", ":", "EzUserAccountKey", "{", "$", "this", "->", "removeByUserId", "(", "$", "userId", ")", ";", "$", "randomBytes", "=", "false", ";", "if", "(", "function_exists", "(", "'openssl_random_pseudo_bytes'", ")", ")", "{", "$", "randomBytes", "=", "openssl_random_pseudo_bytes", "(", "32", ")", ";", "}", "if", "(", "$", "randomBytes", "===", "false", ")", "{", "$", "randomBytes", "=", "mt_rand", "(", ")", ";", "}", "$", "hash", "=", "md5", "(", "$", "userId", ".", "':'", ".", "microtime", "(", ")", ".", "':'", ".", "$", "randomBytes", ")", ";", "$", "userAccount", "=", "new", "EzUserAccountKey", "(", ")", ";", "$", "userAccount", "->", "setHash", "(", "$", "hash", ")", ";", "$", "userAccount", "->", "setTime", "(", "time", "(", ")", ")", ";", "$", "userAccount", "->", "setUserId", "(", "$", "userId", ")", ";", "$", "this", "->", "getEntityManager", "(", ")", "->", "persist", "(", "$", "userAccount", ")", ";", "$", "this", "->", "getEntityManager", "(", ")", "->", "flush", "(", ")", ";", "return", "$", "userAccount", ";", "}" ]
Creates a user account key. @param mixed $userId @return \Netgen\Bundle\SiteBundle\Entity\EzUserAccountKey
[ "Creates", "a", "user", "account", "key", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Entity/Repository/EzUserAccountKeyRepository.php#L19-L44
28,757
netgen/site-bundle
bundle/Entity/Repository/EzUserAccountKeyRepository.php
EzUserAccountKeyRepository.removeByHash
public function removeByHash(string $hash): void { $results = $this->findBy(['hashKey' => $hash]); foreach ($results as $result) { $this->getEntityManager()->remove($result); } $this->getEntityManager()->flush(); }
php
public function removeByHash(string $hash): void { $results = $this->findBy(['hashKey' => $hash]); foreach ($results as $result) { $this->getEntityManager()->remove($result); } $this->getEntityManager()->flush(); }
[ "public", "function", "removeByHash", "(", "string", "$", "hash", ")", ":", "void", "{", "$", "results", "=", "$", "this", "->", "findBy", "(", "[", "'hashKey'", "=>", "$", "hash", "]", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "this", "->", "getEntityManager", "(", ")", "->", "remove", "(", "$", "result", ")", ";", "}", "$", "this", "->", "getEntityManager", "(", ")", "->", "flush", "(", ")", ";", "}" ]
Removes user account key by user hash. @param string $hash
[ "Removes", "user", "account", "key", "by", "user", "hash", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Entity/Repository/EzUserAccountKeyRepository.php#L79-L88
28,758
spiral/core
src/ContainerScope.php
ContainerScope.runScope
public static function runScope(ContainerInterface $container, callable $scope) { list ($previous, self::$container) = [self::$container, $container]; try { return $scope(); } catch (\Throwable $e) { throw $e; } finally { self::$container = $previous; } }
php
public static function runScope(ContainerInterface $container, callable $scope) { list ($previous, self::$container) = [self::$container, $container]; try { return $scope(); } catch (\Throwable $e) { throw $e; } finally { self::$container = $previous; } }
[ "public", "static", "function", "runScope", "(", "ContainerInterface", "$", "container", ",", "callable", "$", "scope", ")", "{", "list", "(", "$", "previous", ",", "self", "::", "$", "container", ")", "=", "[", "self", "::", "$", "container", ",", "$", "container", "]", ";", "try", "{", "return", "$", "scope", "(", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "finally", "{", "self", "::", "$", "container", "=", "$", "previous", ";", "}", "}" ]
Invokes given closure or function withing global IoC scope. @param ContainerInterface $container @param callable $scope @return mixed @throws \Throwable
[ "Invokes", "given", "closure", "or", "function", "withing", "global", "IoC", "scope", "." ]
02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e
https://github.com/spiral/core/blob/02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e/src/ContainerScope.php#L44-L54
28,759
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.getFileHandle
protected function getFileHandle($fullPath, $mode) { $key = md5($fullPath.$mode); if (array_key_exists($key, $this->openFileHandles)) { $handle = $this->openFileHandles[$key]; } else { $handle = fopen($fullPath, $mode); $this->openFileHandles[$key] = $handle; } if ('stream' !== get_resource_type($handle)) { throw new \Exception('The file handle is not a file stream!'); } if (false !== strpos($mode, 'w')) { if ('stream' === !is_writeable($fullPath)) { throw new \Exception('The file handle in the context is not writeable!'); } } return $handle; }
php
protected function getFileHandle($fullPath, $mode) { $key = md5($fullPath.$mode); if (array_key_exists($key, $this->openFileHandles)) { $handle = $this->openFileHandles[$key]; } else { $handle = fopen($fullPath, $mode); $this->openFileHandles[$key] = $handle; } if ('stream' !== get_resource_type($handle)) { throw new \Exception('The file handle is not a file stream!'); } if (false !== strpos($mode, 'w')) { if ('stream' === !is_writeable($fullPath)) { throw new \Exception('The file handle in the context is not writeable!'); } } return $handle; }
[ "protected", "function", "getFileHandle", "(", "$", "fullPath", ",", "$", "mode", ")", "{", "$", "key", "=", "md5", "(", "$", "fullPath", ".", "$", "mode", ")", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "openFileHandles", ")", ")", "{", "$", "handle", "=", "$", "this", "->", "openFileHandles", "[", "$", "key", "]", ";", "}", "else", "{", "$", "handle", "=", "fopen", "(", "$", "fullPath", ",", "$", "mode", ")", ";", "$", "this", "->", "openFileHandles", "[", "$", "key", "]", "=", "$", "handle", ";", "}", "if", "(", "'stream'", "!==", "get_resource_type", "(", "$", "handle", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'The file handle is not a file stream!'", ")", ";", "}", "if", "(", "false", "!==", "strpos", "(", "$", "mode", ",", "'w'", ")", ")", "{", "if", "(", "'stream'", "===", "!", "is_writeable", "(", "$", "fullPath", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'The file handle in the context is not writeable!'", ")", ";", "}", "}", "return", "$", "handle", ";", "}" ]
Open a file handle and store the hash so we can reuse it. @param $fullPath @param $mode @return resource @throws \Exception
[ "Open", "a", "file", "handle", "and", "store", "the", "hash", "so", "we", "can", "reuse", "it", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L69-L90
28,760
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.writeToFile
protected function writeToFile(array &$stepActionParams, array &$endpointOptions, array &$context) { $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_FILE_NAME, self::PARAM_CSV_ROWS, ]); $params = $stepParamsResolver->resolve($stepActionParams); $filePath = $params[self::PARAM_FILE_NAME]; $fullPath = $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$filePath; $rows = $params[self::PARAM_CSV_ROWS]; //open the file, reset the pointer to zero, create it if not already created $fileHandle = fopen($fullPath, 'w'); foreach ($rows as $row) { if (!is_array($row)) { $type = gettype($row); throw new \InvalidArgumentException("Row in Rows is not an array, {$type} given."); } fputcsv($fileHandle, $row, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER], $endpointOptions[CsvConfigurableProtocol::OPTION_ENCLOSURE], $endpointOptions[CsvConfigurableProtocol::OPTION_ESCAPE_CHAR]); } fclose($fileHandle); }
php
protected function writeToFile(array &$stepActionParams, array &$endpointOptions, array &$context) { $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_FILE_NAME, self::PARAM_CSV_ROWS, ]); $params = $stepParamsResolver->resolve($stepActionParams); $filePath = $params[self::PARAM_FILE_NAME]; $fullPath = $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$filePath; $rows = $params[self::PARAM_CSV_ROWS]; //open the file, reset the pointer to zero, create it if not already created $fileHandle = fopen($fullPath, 'w'); foreach ($rows as $row) { if (!is_array($row)) { $type = gettype($row); throw new \InvalidArgumentException("Row in Rows is not an array, {$type} given."); } fputcsv($fileHandle, $row, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER], $endpointOptions[CsvConfigurableProtocol::OPTION_ENCLOSURE], $endpointOptions[CsvConfigurableProtocol::OPTION_ESCAPE_CHAR]); } fclose($fileHandle); }
[ "protected", "function", "writeToFile", "(", "array", "&", "$", "stepActionParams", ",", "array", "&", "$", "endpointOptions", ",", "array", "&", "$", "context", ")", "{", "$", "stepParamsResolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "stepParamsResolver", "->", "setRequired", "(", "[", "self", "::", "PARAM_FILE_NAME", ",", "self", "::", "PARAM_CSV_ROWS", ",", "]", ")", ";", "$", "params", "=", "$", "stepParamsResolver", "->", "resolve", "(", "$", "stepActionParams", ")", ";", "$", "filePath", "=", "$", "params", "[", "self", "::", "PARAM_FILE_NAME", "]", ";", "$", "fullPath", "=", "$", "this", "->", "getRootPath", "(", "$", "endpointOptions", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "filePath", ";", "$", "rows", "=", "$", "params", "[", "self", "::", "PARAM_CSV_ROWS", "]", ";", "//open the file, reset the pointer to zero, create it if not already created", "$", "fileHandle", "=", "fopen", "(", "$", "fullPath", ",", "'w'", ")", ";", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "if", "(", "!", "is_array", "(", "$", "row", ")", ")", "{", "$", "type", "=", "gettype", "(", "$", "row", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Row in Rows is not an array, {$type} given.\"", ")", ";", "}", "fputcsv", "(", "$", "fileHandle", ",", "$", "row", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_DELIMITER", "]", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_ENCLOSURE", "]", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_ESCAPE_CHAR", "]", ")", ";", "}", "fclose", "(", "$", "fileHandle", ")", ";", "}" ]
Write rows out to a csv file. Required Params: - CsvConfigurableProducer::PARAM_CSV_ROWS Optional Params: - CsvConfigurableProducer::PARAM_FILE_NAME @param array $stepActionParams @param array $endpointOptions @param array $context
[ "Write", "rows", "out", "to", "a", "csv", "file", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L191-L218
28,761
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.appendLines
protected function appendLines(array &$stepActionParams, array &$endpointOptions, array &$context) { $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_CSV_ROWS, ]); $stepParamsResolver->setDefault(self::PARAM_FILE_NAME, $endpointOptions[CsvConfigurableProtocol::OPTION_PATH]); $stepParamsResolver->setDefault(self::PARAM_HEADERS, null); $params = $stepParamsResolver->resolve($stepActionParams); $filePath = $params[self::PARAM_FILE_NAME]; $fullPath = $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$filePath; $rows = $params[self::PARAM_CSV_ROWS]; $headers = $params[self::PARAM_HEADERS]; if (is_array($headers) && !file_exists($fullPath)) { $rows = array_merge([$headers], $rows); } $fileHandle = $this->getFileHandle($fullPath, 'a'); foreach ($rows as $row) { if (!is_array($row)) { $type = gettype($row); throw new \InvalidArgumentException("Row in Rows is not an array, {$type} given."); } fputcsv($fileHandle, $row, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER], $endpointOptions[CsvConfigurableProtocol::OPTION_ENCLOSURE], $endpointOptions[CsvConfigurableProtocol::OPTION_ESCAPE_CHAR]); } }
php
protected function appendLines(array &$stepActionParams, array &$endpointOptions, array &$context) { $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_CSV_ROWS, ]); $stepParamsResolver->setDefault(self::PARAM_FILE_NAME, $endpointOptions[CsvConfigurableProtocol::OPTION_PATH]); $stepParamsResolver->setDefault(self::PARAM_HEADERS, null); $params = $stepParamsResolver->resolve($stepActionParams); $filePath = $params[self::PARAM_FILE_NAME]; $fullPath = $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$filePath; $rows = $params[self::PARAM_CSV_ROWS]; $headers = $params[self::PARAM_HEADERS]; if (is_array($headers) && !file_exists($fullPath)) { $rows = array_merge([$headers], $rows); } $fileHandle = $this->getFileHandle($fullPath, 'a'); foreach ($rows as $row) { if (!is_array($row)) { $type = gettype($row); throw new \InvalidArgumentException("Row in Rows is not an array, {$type} given."); } fputcsv($fileHandle, $row, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER], $endpointOptions[CsvConfigurableProtocol::OPTION_ENCLOSURE], $endpointOptions[CsvConfigurableProtocol::OPTION_ESCAPE_CHAR]); } }
[ "protected", "function", "appendLines", "(", "array", "&", "$", "stepActionParams", ",", "array", "&", "$", "endpointOptions", ",", "array", "&", "$", "context", ")", "{", "$", "stepParamsResolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "stepParamsResolver", "->", "setRequired", "(", "[", "self", "::", "PARAM_CSV_ROWS", ",", "]", ")", ";", "$", "stepParamsResolver", "->", "setDefault", "(", "self", "::", "PARAM_FILE_NAME", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_PATH", "]", ")", ";", "$", "stepParamsResolver", "->", "setDefault", "(", "self", "::", "PARAM_HEADERS", ",", "null", ")", ";", "$", "params", "=", "$", "stepParamsResolver", "->", "resolve", "(", "$", "stepActionParams", ")", ";", "$", "filePath", "=", "$", "params", "[", "self", "::", "PARAM_FILE_NAME", "]", ";", "$", "fullPath", "=", "$", "this", "->", "getRootPath", "(", "$", "endpointOptions", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "filePath", ";", "$", "rows", "=", "$", "params", "[", "self", "::", "PARAM_CSV_ROWS", "]", ";", "$", "headers", "=", "$", "params", "[", "self", "::", "PARAM_HEADERS", "]", ";", "if", "(", "is_array", "(", "$", "headers", ")", "&&", "!", "file_exists", "(", "$", "fullPath", ")", ")", "{", "$", "rows", "=", "array_merge", "(", "[", "$", "headers", "]", ",", "$", "rows", ")", ";", "}", "$", "fileHandle", "=", "$", "this", "->", "getFileHandle", "(", "$", "fullPath", ",", "'a'", ")", ";", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "if", "(", "!", "is_array", "(", "$", "row", ")", ")", "{", "$", "type", "=", "gettype", "(", "$", "row", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Row in Rows is not an array, {$type} given.\"", ")", ";", "}", "fputcsv", "(", "$", "fileHandle", ",", "$", "row", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_DELIMITER", "]", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_ENCLOSURE", "]", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_ESCAPE_CHAR", "]", ")", ";", "}", "}" ]
Write an array of lines to a csv file in to a context variable it is assumed the file handle is in the context. Required Params: - CsvConfigurableProducer::PARAM_CSV_ROWS @param array $stepActionParams @param array $endpointOptions @param array $context
[ "Write", "an", "array", "of", "lines", "to", "a", "csv", "file", "in", "to", "a", "context", "variable", "it", "is", "assumed", "the", "file", "handle", "is", "in", "the", "context", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L231-L261
28,762
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.readFile
protected function readFile(array &$stepActionParams, array &$endpointOptions, array &$context) { $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_FILE_NAME, self::PARAM_CONTEXT_RESULT_NAME, ]); $params = $stepParamsResolver->resolve($stepActionParams); $filePath = $params[self::PARAM_FILE_NAME]; $fullPath = $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$filePath; $contextResultName = $params[self::PARAM_CONTEXT_RESULT_NAME]; $maxLineLength = $endpointOptions[CsvConfigurableProtocol::OPTION_MAX_LENGTH]; //open the file, reset the pointer to zero $fileHandle = fopen($fullPath, 'r'); $rows = []; while (false !== ($row = fgetcsv($fileHandle, $maxLineLength, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER]))) { $rows[] = $row; } fclose($fileHandle); $context[$contextResultName] = $rows; }
php
protected function readFile(array &$stepActionParams, array &$endpointOptions, array &$context) { $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_FILE_NAME, self::PARAM_CONTEXT_RESULT_NAME, ]); $params = $stepParamsResolver->resolve($stepActionParams); $filePath = $params[self::PARAM_FILE_NAME]; $fullPath = $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$filePath; $contextResultName = $params[self::PARAM_CONTEXT_RESULT_NAME]; $maxLineLength = $endpointOptions[CsvConfigurableProtocol::OPTION_MAX_LENGTH]; //open the file, reset the pointer to zero $fileHandle = fopen($fullPath, 'r'); $rows = []; while (false !== ($row = fgetcsv($fileHandle, $maxLineLength, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER]))) { $rows[] = $row; } fclose($fileHandle); $context[$contextResultName] = $rows; }
[ "protected", "function", "readFile", "(", "array", "&", "$", "stepActionParams", ",", "array", "&", "$", "endpointOptions", ",", "array", "&", "$", "context", ")", "{", "$", "stepParamsResolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "stepParamsResolver", "->", "setRequired", "(", "[", "self", "::", "PARAM_FILE_NAME", ",", "self", "::", "PARAM_CONTEXT_RESULT_NAME", ",", "]", ")", ";", "$", "params", "=", "$", "stepParamsResolver", "->", "resolve", "(", "$", "stepActionParams", ")", ";", "$", "filePath", "=", "$", "params", "[", "self", "::", "PARAM_FILE_NAME", "]", ";", "$", "fullPath", "=", "$", "this", "->", "getRootPath", "(", "$", "endpointOptions", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "filePath", ";", "$", "contextResultName", "=", "$", "params", "[", "self", "::", "PARAM_CONTEXT_RESULT_NAME", "]", ";", "$", "maxLineLength", "=", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_MAX_LENGTH", "]", ";", "//open the file, reset the pointer to zero", "$", "fileHandle", "=", "fopen", "(", "$", "fullPath", ",", "'r'", ")", ";", "$", "rows", "=", "[", "]", ";", "while", "(", "false", "!==", "(", "$", "row", "=", "fgetcsv", "(", "$", "fileHandle", ",", "$", "maxLineLength", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_DELIMITER", "]", ")", ")", ")", "{", "$", "rows", "[", "]", "=", "$", "row", ";", "}", "fclose", "(", "$", "fileHandle", ")", ";", "$", "context", "[", "$", "contextResultName", "]", "=", "$", "rows", ";", "}" ]
Read a csv file in to a context variable. Required Params: - CsvConfigurableProducer::PARAM_CONTEXT_RESULT_NAME Optional Params: - CsvConfigurableProducer::PARAM_FILE_NAME @param array $stepActionParams @param array $endpointOptions @param array $context
[ "Read", "a", "csv", "file", "in", "to", "a", "context", "variable", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L275-L302
28,763
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.readLines
protected function readLines(array &$stepActionParams, array &$endpointOptions, array &$context) { $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_CONTEXT_RESULT_NAME, ]); $stepParamsResolver->setDefault(self::PARAM_MAX_LINES, 1); $stepParamsResolver->setDefault(self::PARAM_FILE_NAME, null); $params = $stepParamsResolver->resolve($stepActionParams); $fullPath = $this->getRootPath($endpointOptions); if (null !== $params[self::PARAM_FILE_NAME]) { if (DIRECTORY_SEPARATOR !== substr($fullPath, -1)) { $fullPath .= DIRECTORY_SEPARATOR; } $fullPath .= $params[self::PARAM_FILE_NAME]; } $fileHandle = $this->getFileHandle($fullPath, 'r'); $contextResultName = $params[self::PARAM_CONTEXT_RESULT_NAME]; $maxLines = $params[self::PARAM_MAX_LINES]; $maxLineLength = $endpointOptions[CsvConfigurableProtocol::OPTION_MAX_LENGTH]; $rows = []; $i = 0; while ($i < $maxLines) { $row = fgetcsv($fileHandle, $maxLineLength, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER]); if (false === $row) { break; } $rows[] = $row; ++$i; } if (0 === count($rows)) { throw new NoResultsException("No more results from $fullPath"); } $context[self::KEY_RESULTS][$contextResultName] = $rows; }
php
protected function readLines(array &$stepActionParams, array &$endpointOptions, array &$context) { $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_CONTEXT_RESULT_NAME, ]); $stepParamsResolver->setDefault(self::PARAM_MAX_LINES, 1); $stepParamsResolver->setDefault(self::PARAM_FILE_NAME, null); $params = $stepParamsResolver->resolve($stepActionParams); $fullPath = $this->getRootPath($endpointOptions); if (null !== $params[self::PARAM_FILE_NAME]) { if (DIRECTORY_SEPARATOR !== substr($fullPath, -1)) { $fullPath .= DIRECTORY_SEPARATOR; } $fullPath .= $params[self::PARAM_FILE_NAME]; } $fileHandle = $this->getFileHandle($fullPath, 'r'); $contextResultName = $params[self::PARAM_CONTEXT_RESULT_NAME]; $maxLines = $params[self::PARAM_MAX_LINES]; $maxLineLength = $endpointOptions[CsvConfigurableProtocol::OPTION_MAX_LENGTH]; $rows = []; $i = 0; while ($i < $maxLines) { $row = fgetcsv($fileHandle, $maxLineLength, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER]); if (false === $row) { break; } $rows[] = $row; ++$i; } if (0 === count($rows)) { throw new NoResultsException("No more results from $fullPath"); } $context[self::KEY_RESULTS][$contextResultName] = $rows; }
[ "protected", "function", "readLines", "(", "array", "&", "$", "stepActionParams", ",", "array", "&", "$", "endpointOptions", ",", "array", "&", "$", "context", ")", "{", "$", "stepParamsResolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "stepParamsResolver", "->", "setRequired", "(", "[", "self", "::", "PARAM_CONTEXT_RESULT_NAME", ",", "]", ")", ";", "$", "stepParamsResolver", "->", "setDefault", "(", "self", "::", "PARAM_MAX_LINES", ",", "1", ")", ";", "$", "stepParamsResolver", "->", "setDefault", "(", "self", "::", "PARAM_FILE_NAME", ",", "null", ")", ";", "$", "params", "=", "$", "stepParamsResolver", "->", "resolve", "(", "$", "stepActionParams", ")", ";", "$", "fullPath", "=", "$", "this", "->", "getRootPath", "(", "$", "endpointOptions", ")", ";", "if", "(", "null", "!==", "$", "params", "[", "self", "::", "PARAM_FILE_NAME", "]", ")", "{", "if", "(", "DIRECTORY_SEPARATOR", "!==", "substr", "(", "$", "fullPath", ",", "-", "1", ")", ")", "{", "$", "fullPath", ".=", "DIRECTORY_SEPARATOR", ";", "}", "$", "fullPath", ".=", "$", "params", "[", "self", "::", "PARAM_FILE_NAME", "]", ";", "}", "$", "fileHandle", "=", "$", "this", "->", "getFileHandle", "(", "$", "fullPath", ",", "'r'", ")", ";", "$", "contextResultName", "=", "$", "params", "[", "self", "::", "PARAM_CONTEXT_RESULT_NAME", "]", ";", "$", "maxLines", "=", "$", "params", "[", "self", "::", "PARAM_MAX_LINES", "]", ";", "$", "maxLineLength", "=", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_MAX_LENGTH", "]", ";", "$", "rows", "=", "[", "]", ";", "$", "i", "=", "0", ";", "while", "(", "$", "i", "<", "$", "maxLines", ")", "{", "$", "row", "=", "fgetcsv", "(", "$", "fileHandle", ",", "$", "maxLineLength", ",", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_DELIMITER", "]", ")", ";", "if", "(", "false", "===", "$", "row", ")", "{", "break", ";", "}", "$", "rows", "[", "]", "=", "$", "row", ";", "++", "$", "i", ";", "}", "if", "(", "0", "===", "count", "(", "$", "rows", ")", ")", "{", "throw", "new", "NoResultsException", "(", "\"No more results from $fullPath\"", ")", ";", "}", "$", "context", "[", "self", "::", "KEY_RESULTS", "]", "[", "$", "contextResultName", "]", "=", "$", "rows", ";", "}" ]
Read a line from a csv file in to a context variable it is assumed the file handle is in the context. Required Params: - CsvConfigurableProducer::PARAM_CONTEXT_RESULT_NAME Optional Params: - CsvConfigurableProducer::PARAM_MAX_LINES Defaults to 1 @param array $stepActionParams @param array $endpointOptions @param array $context @throws NoResultsException if there are no more lines to consume
[ "Read", "a", "line", "from", "a", "csv", "file", "in", "to", "a", "context", "variable", "it", "is", "assumed", "the", "file", "handle", "is", "in", "the", "context", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L319-L363
28,764
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.copyFile
protected function copyFile(array &$stepActionParams, array &$endpointOptions, array &$context) { $rootPath = $this->getRootPath($endpointOptions, $stepActionParams); $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_FILE_NAME, self::PARAM_NEW_FILE_PATH, ]); $params = $stepParamsResolver->resolve($stepActionParams); $newFilePath = $params[self::PARAM_NEW_FILE_PATH]; $newFullPath = $rootPath.DIRECTORY_SEPARATOR.$newFilePath; $originalFilePath = $params[self::PARAM_FILE_NAME]; $originalFullPath = $rootPath.DIRECTORY_SEPARATOR.$originalFilePath; copy($originalFullPath, $newFullPath); }
php
protected function copyFile(array &$stepActionParams, array &$endpointOptions, array &$context) { $rootPath = $this->getRootPath($endpointOptions, $stepActionParams); $stepParamsResolver = new OptionsResolver(); $stepParamsResolver->setRequired([ self::PARAM_FILE_NAME, self::PARAM_NEW_FILE_PATH, ]); $params = $stepParamsResolver->resolve($stepActionParams); $newFilePath = $params[self::PARAM_NEW_FILE_PATH]; $newFullPath = $rootPath.DIRECTORY_SEPARATOR.$newFilePath; $originalFilePath = $params[self::PARAM_FILE_NAME]; $originalFullPath = $rootPath.DIRECTORY_SEPARATOR.$originalFilePath; copy($originalFullPath, $newFullPath); }
[ "protected", "function", "copyFile", "(", "array", "&", "$", "stepActionParams", ",", "array", "&", "$", "endpointOptions", ",", "array", "&", "$", "context", ")", "{", "$", "rootPath", "=", "$", "this", "->", "getRootPath", "(", "$", "endpointOptions", ",", "$", "stepActionParams", ")", ";", "$", "stepParamsResolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "stepParamsResolver", "->", "setRequired", "(", "[", "self", "::", "PARAM_FILE_NAME", ",", "self", "::", "PARAM_NEW_FILE_PATH", ",", "]", ")", ";", "$", "params", "=", "$", "stepParamsResolver", "->", "resolve", "(", "$", "stepActionParams", ")", ";", "$", "newFilePath", "=", "$", "params", "[", "self", "::", "PARAM_NEW_FILE_PATH", "]", ";", "$", "newFullPath", "=", "$", "rootPath", ".", "DIRECTORY_SEPARATOR", ".", "$", "newFilePath", ";", "$", "originalFilePath", "=", "$", "params", "[", "self", "::", "PARAM_FILE_NAME", "]", ";", "$", "originalFullPath", "=", "$", "rootPath", ".", "DIRECTORY_SEPARATOR", ".", "$", "originalFilePath", ";", "copy", "(", "$", "originalFullPath", ",", "$", "newFullPath", ")", ";", "}" ]
Copy a file for this producer. Required Params: - CsvConfigurableProducer::PARAM_NEW_FILE_PATH Optional Params: - CsvConfigurableProducer::PARAM_FILE_NAME @param array $stepActionParams @param array $endpointOptions @param array $context
[ "Copy", "a", "file", "for", "this", "producer", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L424-L442
28,765
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.createFile
protected function createFile(array &$stepActionParams, array &$endpointOptions, array &$context) { $fullPath = $this->getFullPath($endpointOptions, $stepActionParams); $fileHandle = fopen($fullPath, 'w'); fclose($fileHandle); }
php
protected function createFile(array &$stepActionParams, array &$endpointOptions, array &$context) { $fullPath = $this->getFullPath($endpointOptions, $stepActionParams); $fileHandle = fopen($fullPath, 'w'); fclose($fileHandle); }
[ "protected", "function", "createFile", "(", "array", "&", "$", "stepActionParams", ",", "array", "&", "$", "endpointOptions", ",", "array", "&", "$", "context", ")", "{", "$", "fullPath", "=", "$", "this", "->", "getFullPath", "(", "$", "endpointOptions", ",", "$", "stepActionParams", ")", ";", "$", "fileHandle", "=", "fopen", "(", "$", "fullPath", ",", "'w'", ")", ";", "fclose", "(", "$", "fileHandle", ")", ";", "}" ]
Create a new blank file. Required Params: - CsvConfigurableProducer::PARAM_NEW_FILE_PATH Optional Params: - CsvConfigurableProducer::PARAM_FILE_NAME @param array $stepActionParams @param array $endpointOptions @param array $context
[ "Create", "a", "new", "blank", "file", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L456-L462
28,766
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.getFilePath
protected function getFilePath(array $endpointOptions, $stepActionParams) { if (array_key_exists(self::PARAM_FILE_NAME, $stepActionParams)) { return $stepActionParams[self::PARAM_FILE_NAME]; } else { return $endpointOptions[CsvConfigurableProtocol::OPTION_PATH]; } }
php
protected function getFilePath(array $endpointOptions, $stepActionParams) { if (array_key_exists(self::PARAM_FILE_NAME, $stepActionParams)) { return $stepActionParams[self::PARAM_FILE_NAME]; } else { return $endpointOptions[CsvConfigurableProtocol::OPTION_PATH]; } }
[ "protected", "function", "getFilePath", "(", "array", "$", "endpointOptions", ",", "$", "stepActionParams", ")", "{", "if", "(", "array_key_exists", "(", "self", "::", "PARAM_FILE_NAME", ",", "$", "stepActionParams", ")", ")", "{", "return", "$", "stepActionParams", "[", "self", "::", "PARAM_FILE_NAME", "]", ";", "}", "else", "{", "return", "$", "endpointOptions", "[", "CsvConfigurableProtocol", "::", "OPTION_PATH", "]", ";", "}", "}" ]
Resolve the file path from the configuration use the configured default path if none is set. @param array $endpointOptions @param array $stepActionParams @return string The file path to the file as in the configuration
[ "Resolve", "the", "file", "path", "from", "the", "configuration", "use", "the", "configured", "default", "path", "if", "none", "is", "set", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L485-L492
28,767
smartboxgroup/integration-framework-bundle
Components/FileService/Csv/CsvConfigurableStepsProvider.php
CsvConfigurableStepsProvider.getFullPath
protected function getFullPath(array $endpointOptions, $stepActionParams) { return $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$this->getFilePath($endpointOptions, $stepActionParams); }
php
protected function getFullPath(array $endpointOptions, $stepActionParams) { return $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$this->getFilePath($endpointOptions, $stepActionParams); }
[ "protected", "function", "getFullPath", "(", "array", "$", "endpointOptions", ",", "$", "stepActionParams", ")", "{", "return", "$", "this", "->", "getRootPath", "(", "$", "endpointOptions", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "getFilePath", "(", "$", "endpointOptions", ",", "$", "stepActionParams", ")", ";", "}" ]
resolve the full path to the file in the configuration. @param array $endpointOptions @param array $stepActionParams @return string A full path to the file from the configuration
[ "resolve", "the", "full", "path", "to", "the", "file", "in", "the", "configuration", "." ]
5f0bf8ff86337a51f6d208bd38df39017643b905
https://github.com/smartboxgroup/integration-framework-bundle/blob/5f0bf8ff86337a51f6d208bd38df39017643b905/Components/FileService/Csv/CsvConfigurableStepsProvider.php#L502-L505
28,768
netgen/site-bundle
bundle/EventListener/NoViewTemplateEventListener.php
NoViewTemplateEventListener.getController
public function getController(FilterControllerEvent $event): void { if (!$this->enabled || $event->getRequestType() !== Kernel::MASTER_REQUEST) { return; } $request = $event->getRequest(); $view = $request->attributes->get('view'); if (!$view instanceof View || $view->getViewType() !== 'full') { return; } if (is_string($view->getTemplateIdentifier())) { return; } $event->setController( function (): RedirectResponse { $rootLocationId = $this->configResolver->getParameter('content.tree_root.location_id'); return new RedirectResponse( $this->urlGenerator->generate('ez_urlalias', ['locationId' => $rootLocationId]), RedirectResponse::HTTP_MOVED_PERMANENTLY ); } ); }
php
public function getController(FilterControllerEvent $event): void { if (!$this->enabled || $event->getRequestType() !== Kernel::MASTER_REQUEST) { return; } $request = $event->getRequest(); $view = $request->attributes->get('view'); if (!$view instanceof View || $view->getViewType() !== 'full') { return; } if (is_string($view->getTemplateIdentifier())) { return; } $event->setController( function (): RedirectResponse { $rootLocationId = $this->configResolver->getParameter('content.tree_root.location_id'); return new RedirectResponse( $this->urlGenerator->generate('ez_urlalias', ['locationId' => $rootLocationId]), RedirectResponse::HTTP_MOVED_PERMANENTLY ); } ); }
[ "public", "function", "getController", "(", "FilterControllerEvent", "$", "event", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "enabled", "||", "$", "event", "->", "getRequestType", "(", ")", "!==", "Kernel", "::", "MASTER_REQUEST", ")", "{", "return", ";", "}", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "$", "view", "=", "$", "request", "->", "attributes", "->", "get", "(", "'view'", ")", ";", "if", "(", "!", "$", "view", "instanceof", "View", "||", "$", "view", "->", "getViewType", "(", ")", "!==", "'full'", ")", "{", "return", ";", "}", "if", "(", "is_string", "(", "$", "view", "->", "getTemplateIdentifier", "(", ")", ")", ")", "{", "return", ";", "}", "$", "event", "->", "setController", "(", "function", "(", ")", ":", "RedirectResponse", "{", "$", "rootLocationId", "=", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'content.tree_root.location_id'", ")", ";", "return", "new", "RedirectResponse", "(", "$", "this", "->", "urlGenerator", "->", "generate", "(", "'ez_urlalias'", ",", "[", "'locationId'", "=>", "$", "rootLocationId", "]", ")", ",", "RedirectResponse", "::", "HTTP_MOVED_PERMANENTLY", ")", ";", "}", ")", ";", "}" ]
Redirects to the frontpage for any full view that does not have a template configured.
[ "Redirects", "to", "the", "frontpage", "for", "any", "full", "view", "that", "does", "not", "have", "a", "template", "configured", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/EventListener/NoViewTemplateEventListener.php#L56-L83
28,769
spiral/router
src/UriHandler.php
UriHandler.match
public function match(UriInterface $uri, array $defaults): ?array { if (!$this->isCompiled()) { $this->compile(); } $matches = []; if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) { return null; } $matches = array_intersect_key($matches, $this->options); return array_merge($this->options, $defaults, $matches); }
php
public function match(UriInterface $uri, array $defaults): ?array { if (!$this->isCompiled()) { $this->compile(); } $matches = []; if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) { return null; } $matches = array_intersect_key($matches, $this->options); return array_merge($this->options, $defaults, $matches); }
[ "public", "function", "match", "(", "UriInterface", "$", "uri", ",", "array", "$", "defaults", ")", ":", "?", "array", "{", "if", "(", "!", "$", "this", "->", "isCompiled", "(", ")", ")", "{", "$", "this", "->", "compile", "(", ")", ";", "}", "$", "matches", "=", "[", "]", ";", "if", "(", "!", "preg_match", "(", "$", "this", "->", "compiled", ",", "$", "this", "->", "fetchTarget", "(", "$", "uri", ")", ",", "$", "matches", ")", ")", "{", "return", "null", ";", "}", "$", "matches", "=", "array_intersect_key", "(", "$", "matches", ",", "$", "this", "->", "options", ")", ";", "return", "array_merge", "(", "$", "this", "->", "options", ",", "$", "defaults", ",", "$", "matches", ")", ";", "}" ]
Match given url against compiled template and return matches array or null if pattern does not match. @param UriInterface $uri @param array $defaults @return array|null
[ "Match", "given", "url", "against", "compiled", "template", "and", "return", "matches", "array", "or", "null", "if", "pattern", "does", "not", "match", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/UriHandler.php#L116-L130
28,770
spiral/router
src/UriHandler.php
UriHandler.uri
public function uri($parameters = [], array $defaults = []): UriInterface { if (!$this->isCompiled()) { $this->compile(); } $parameters = array_merge( $this->options, $defaults, $this->fetchOptions($parameters, $query) ); foreach ($this->constrains as $key => $values) { if (empty($parameters[$key])) { throw new UriHandlerException("Unable to generate Uri, parameter `{$key}` is missing."); } } //Uri without empty blocks (pretty stupid implementation) $path = $this->interpolate($this->template, $parameters); //Uri with added prefix $uri = new Uri(($this->matchHost ? '' : $this->prefix) . trim($path, '/')); return empty($query) ? $uri : $uri->withQuery(http_build_query($query)); }
php
public function uri($parameters = [], array $defaults = []): UriInterface { if (!$this->isCompiled()) { $this->compile(); } $parameters = array_merge( $this->options, $defaults, $this->fetchOptions($parameters, $query) ); foreach ($this->constrains as $key => $values) { if (empty($parameters[$key])) { throw new UriHandlerException("Unable to generate Uri, parameter `{$key}` is missing."); } } //Uri without empty blocks (pretty stupid implementation) $path = $this->interpolate($this->template, $parameters); //Uri with added prefix $uri = new Uri(($this->matchHost ? '' : $this->prefix) . trim($path, '/')); return empty($query) ? $uri : $uri->withQuery(http_build_query($query)); }
[ "public", "function", "uri", "(", "$", "parameters", "=", "[", "]", ",", "array", "$", "defaults", "=", "[", "]", ")", ":", "UriInterface", "{", "if", "(", "!", "$", "this", "->", "isCompiled", "(", ")", ")", "{", "$", "this", "->", "compile", "(", ")", ";", "}", "$", "parameters", "=", "array_merge", "(", "$", "this", "->", "options", ",", "$", "defaults", ",", "$", "this", "->", "fetchOptions", "(", "$", "parameters", ",", "$", "query", ")", ")", ";", "foreach", "(", "$", "this", "->", "constrains", "as", "$", "key", "=>", "$", "values", ")", "{", "if", "(", "empty", "(", "$", "parameters", "[", "$", "key", "]", ")", ")", "{", "throw", "new", "UriHandlerException", "(", "\"Unable to generate Uri, parameter `{$key}` is missing.\"", ")", ";", "}", "}", "//Uri without empty blocks (pretty stupid implementation)", "$", "path", "=", "$", "this", "->", "interpolate", "(", "$", "this", "->", "template", ",", "$", "parameters", ")", ";", "//Uri with added prefix", "$", "uri", "=", "new", "Uri", "(", "(", "$", "this", "->", "matchHost", "?", "''", ":", "$", "this", "->", "prefix", ")", ".", "trim", "(", "$", "path", ",", "'/'", ")", ")", ";", "return", "empty", "(", "$", "query", ")", "?", "$", "uri", ":", "$", "uri", "->", "withQuery", "(", "http_build_query", "(", "$", "query", ")", ")", ";", "}" ]
Generate Uri for a given parameters and default values. @param array|\Traversable $parameters @param array $defaults @return UriInterface
[ "Generate", "Uri", "for", "a", "given", "parameters", "and", "default", "values", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/UriHandler.php#L139-L164
28,771
spiral/router
src/UriHandler.php
UriHandler.fetchOptions
private function fetchOptions($parameters, &$query): array { $allowed = array_keys($this->options); $result = []; foreach ($parameters as $key => $parameter) { if (is_numeric($key) && isset($allowed[$key])) { // this segment fetched keys from given parameters either by name or by position $key = $allowed[$key]; } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) { // all additional parameters given in array form can be glued to query string $query[$key] = $parameter; continue; } //String must be normalized here if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) { $result[$key] = $this->slugify->slugify($parameter); continue; } $result[$key] = (string)$parameter; } return $result; }
php
private function fetchOptions($parameters, &$query): array { $allowed = array_keys($this->options); $result = []; foreach ($parameters as $key => $parameter) { if (is_numeric($key) && isset($allowed[$key])) { // this segment fetched keys from given parameters either by name or by position $key = $allowed[$key]; } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) { // all additional parameters given in array form can be glued to query string $query[$key] = $parameter; continue; } //String must be normalized here if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) { $result[$key] = $this->slugify->slugify($parameter); continue; } $result[$key] = (string)$parameter; } return $result; }
[ "private", "function", "fetchOptions", "(", "$", "parameters", ",", "&", "$", "query", ")", ":", "array", "{", "$", "allowed", "=", "array_keys", "(", "$", "this", "->", "options", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "parameters", "as", "$", "key", "=>", "$", "parameter", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", "&&", "isset", "(", "$", "allowed", "[", "$", "key", "]", ")", ")", "{", "// this segment fetched keys from given parameters either by name or by position", "$", "key", "=", "$", "allowed", "[", "$", "key", "]", ";", "}", "elseif", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "options", ")", "&&", "is_array", "(", "$", "parameters", ")", ")", "{", "// all additional parameters given in array form can be glued to query string", "$", "query", "[", "$", "key", "]", "=", "$", "parameter", ";", "continue", ";", "}", "//String must be normalized here", "if", "(", "is_string", "(", "$", "parameter", ")", "&&", "!", "preg_match", "(", "'/^[a-z\\-_0-9]+$/i'", ",", "$", "parameter", ")", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "this", "->", "slugify", "->", "slugify", "(", "$", "parameter", ")", ";", "continue", ";", "}", "$", "result", "[", "$", "key", "]", "=", "(", "string", ")", "$", "parameter", ";", "}", "return", "$", "result", ";", "}" ]
Fetch uri segments and query parameters. @param \Traversable|array $parameters @param array|null $query Query parameters. @return array
[ "Fetch", "uri", "segments", "and", "query", "parameters", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/UriHandler.php#L173-L198
28,772
spiral/router
src/UriHandler.php
UriHandler.fetchTarget
private function fetchTarget(UriInterface $uri): string { $path = $uri->getPath(); if (empty($path) || $path[0] !== '/') { $path = '/' . $path; } if ($this->matchHost) { $uri = $uri->getHost() . $path; } else { $uri = substr($path, strlen($this->prefix)); } return trim($uri, '/'); }
php
private function fetchTarget(UriInterface $uri): string { $path = $uri->getPath(); if (empty($path) || $path[0] !== '/') { $path = '/' . $path; } if ($this->matchHost) { $uri = $uri->getHost() . $path; } else { $uri = substr($path, strlen($this->prefix)); } return trim($uri, '/'); }
[ "private", "function", "fetchTarget", "(", "UriInterface", "$", "uri", ")", ":", "string", "{", "$", "path", "=", "$", "uri", "->", "getPath", "(", ")", ";", "if", "(", "empty", "(", "$", "path", ")", "||", "$", "path", "[", "0", "]", "!==", "'/'", ")", "{", "$", "path", "=", "'/'", ".", "$", "path", ";", "}", "if", "(", "$", "this", "->", "matchHost", ")", "{", "$", "uri", "=", "$", "uri", "->", "getHost", "(", ")", ".", "$", "path", ";", "}", "else", "{", "$", "uri", "=", "substr", "(", "$", "path", ",", "strlen", "(", "$", "this", "->", "prefix", ")", ")", ";", "}", "return", "trim", "(", "$", "uri", ",", "'/'", ")", ";", "}" ]
Part of uri path which is being matched. @param UriInterface $uri @return string
[ "Part", "of", "uri", "path", "which", "is", "being", "matched", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/UriHandler.php#L206-L221
28,773
spiral/router
src/UriHandler.php
UriHandler.compile
private function compile() { $options = $replaces = []; $pattern = rtrim(ltrim($this->pattern, ':/'), '/'); // correct [/ first occurrence] if (strpos($pattern, '[/') === 0) { $pattern = '[' . substr($pattern, 2); } if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) { $variables = array_combine($matches[1], $matches[2]); foreach ($variables as $key => $segment) { $segment = $this->prepareSegment($key, $segment); $replaces["<$key>"] = "(?P<$key>$segment)"; $options[] = $key; } } $template = preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern); $options = array_fill_keys($options, null); foreach ($this->constrains as $key => $value) { if ($value instanceof Autofill) { // only forces value replacement, not required to be presented as parameter continue; } if (!array_key_exists($key, $options)) { throw new ConstrainException(sprintf( "Route `%s` does not define routing parameter `<%s>`.", $this->pattern, $key )); } } $this->compiled = '/^' . strtr($template, $replaces + self::PATTERN_REPLACES) . '$/iu'; $this->template = stripslashes(str_replace('?', '', $template)); $this->options = $options; }
php
private function compile() { $options = $replaces = []; $pattern = rtrim(ltrim($this->pattern, ':/'), '/'); // correct [/ first occurrence] if (strpos($pattern, '[/') === 0) { $pattern = '[' . substr($pattern, 2); } if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) { $variables = array_combine($matches[1], $matches[2]); foreach ($variables as $key => $segment) { $segment = $this->prepareSegment($key, $segment); $replaces["<$key>"] = "(?P<$key>$segment)"; $options[] = $key; } } $template = preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern); $options = array_fill_keys($options, null); foreach ($this->constrains as $key => $value) { if ($value instanceof Autofill) { // only forces value replacement, not required to be presented as parameter continue; } if (!array_key_exists($key, $options)) { throw new ConstrainException(sprintf( "Route `%s` does not define routing parameter `<%s>`.", $this->pattern, $key )); } } $this->compiled = '/^' . strtr($template, $replaces + self::PATTERN_REPLACES) . '$/iu'; $this->template = stripslashes(str_replace('?', '', $template)); $this->options = $options; }
[ "private", "function", "compile", "(", ")", "{", "$", "options", "=", "$", "replaces", "=", "[", "]", ";", "$", "pattern", "=", "rtrim", "(", "ltrim", "(", "$", "this", "->", "pattern", ",", "':/'", ")", ",", "'/'", ")", ";", "// correct [/ first occurrence]", "if", "(", "strpos", "(", "$", "pattern", ",", "'[/'", ")", "===", "0", ")", "{", "$", "pattern", "=", "'['", ".", "substr", "(", "$", "pattern", ",", "2", ")", ";", "}", "if", "(", "preg_match_all", "(", "'/<(\\w+):?(.*?)?>/'", ",", "$", "pattern", ",", "$", "matches", ")", ")", "{", "$", "variables", "=", "array_combine", "(", "$", "matches", "[", "1", "]", ",", "$", "matches", "[", "2", "]", ")", ";", "foreach", "(", "$", "variables", "as", "$", "key", "=>", "$", "segment", ")", "{", "$", "segment", "=", "$", "this", "->", "prepareSegment", "(", "$", "key", ",", "$", "segment", ")", ";", "$", "replaces", "[", "\"<$key>\"", "]", "=", "\"(?P<$key>$segment)\"", ";", "$", "options", "[", "]", "=", "$", "key", ";", "}", "}", "$", "template", "=", "preg_replace", "(", "'/<(\\w+):?.*?>/'", ",", "'<\\1>'", ",", "$", "pattern", ")", ";", "$", "options", "=", "array_fill_keys", "(", "$", "options", ",", "null", ")", ";", "foreach", "(", "$", "this", "->", "constrains", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Autofill", ")", "{", "// only forces value replacement, not required to be presented as parameter", "continue", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "options", ")", ")", "{", "throw", "new", "ConstrainException", "(", "sprintf", "(", "\"Route `%s` does not define routing parameter `<%s>`.\"", ",", "$", "this", "->", "pattern", ",", "$", "key", ")", ")", ";", "}", "}", "$", "this", "->", "compiled", "=", "'/^'", ".", "strtr", "(", "$", "template", ",", "$", "replaces", "+", "self", "::", "PATTERN_REPLACES", ")", ".", "'$/iu'", ";", "$", "this", "->", "template", "=", "stripslashes", "(", "str_replace", "(", "'?'", ",", "''", ",", "$", "template", ")", ")", ";", "$", "this", "->", "options", "=", "$", "options", ";", "}" ]
Compile route matcher into regexp.
[ "Compile", "route", "matcher", "into", "regexp", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/UriHandler.php#L226-L267
28,774
spiral/router
src/UriHandler.php
UriHandler.interpolate
private function interpolate(string $string, array $values): string { $replaces = []; foreach ($values as $key => $value) { $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; $replaces["<{$key}>"] = is_object($value) ? (string)$value : $value; } return strtr($string, $replaces + self::URI_FIXERS); }
php
private function interpolate(string $string, array $values): string { $replaces = []; foreach ($values as $key => $value) { $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; $replaces["<{$key}>"] = is_object($value) ? (string)$value : $value; } return strtr($string, $replaces + self::URI_FIXERS); }
[ "private", "function", "interpolate", "(", "string", "$", "string", ",", "array", "$", "values", ")", ":", "string", "{", "$", "replaces", "=", "[", "]", ";", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "value", "=", "(", "is_array", "(", "$", "value", ")", "||", "$", "value", "instanceof", "\\", "Closure", ")", "?", "''", ":", "$", "value", ";", "$", "replaces", "[", "\"<{$key}>\"", "]", "=", "is_object", "(", "$", "value", ")", "?", "(", "string", ")", "$", "value", ":", "$", "value", ";", "}", "return", "strtr", "(", "$", "string", ",", "$", "replaces", "+", "self", "::", "URI_FIXERS", ")", ";", "}" ]
Interpolate string with given values. @param string $string @param array $values @return string
[ "Interpolate", "string", "with", "given", "values", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/UriHandler.php#L276-L285
28,775
spiral/router
src/UriHandler.php
UriHandler.prepareSegment
private function prepareSegment(string $name, string $segment): string { if (!empty($segment)) { return $this->filterSegment($segment); } if (!isset($this->constrains[$name])) { return self::DEFAULT_SEGMENT; } if (is_array($this->constrains[$name])) { $values = array_map([$this, 'filterSegment'], $this->constrains[$name]); return join('|', $values); } return $this->filterSegment((string)$this->constrains[$name]); }
php
private function prepareSegment(string $name, string $segment): string { if (!empty($segment)) { return $this->filterSegment($segment); } if (!isset($this->constrains[$name])) { return self::DEFAULT_SEGMENT; } if (is_array($this->constrains[$name])) { $values = array_map([$this, 'filterSegment'], $this->constrains[$name]); return join('|', $values); } return $this->filterSegment((string)$this->constrains[$name]); }
[ "private", "function", "prepareSegment", "(", "string", "$", "name", ",", "string", "$", "segment", ")", ":", "string", "{", "if", "(", "!", "empty", "(", "$", "segment", ")", ")", "{", "return", "$", "this", "->", "filterSegment", "(", "$", "segment", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "constrains", "[", "$", "name", "]", ")", ")", "{", "return", "self", "::", "DEFAULT_SEGMENT", ";", "}", "if", "(", "is_array", "(", "$", "this", "->", "constrains", "[", "$", "name", "]", ")", ")", "{", "$", "values", "=", "array_map", "(", "[", "$", "this", ",", "'filterSegment'", "]", ",", "$", "this", "->", "constrains", "[", "$", "name", "]", ")", ";", "return", "join", "(", "'|'", ",", "$", "values", ")", ";", "}", "return", "$", "this", "->", "filterSegment", "(", "(", "string", ")", "$", "this", "->", "constrains", "[", "$", "name", "]", ")", ";", "}" ]
Prepares segment pattern with given constrains. @param string $name @param string $segment @return string
[ "Prepares", "segment", "pattern", "with", "given", "constrains", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/UriHandler.php#L294-L311
28,776
adminarchitect/options
src/Terranet/Options/Drivers/EloquentOptionsDriver.php
EloquentOptionsDriver.find
public function find($name, $default = null) { return ($options = $this->fetchAll()->lists('value', 'key')) && $options->has($name) ? $options->get($name) : $default; }
php
public function find($name, $default = null) { return ($options = $this->fetchAll()->lists('value', 'key')) && $options->has($name) ? $options->get($name) : $default; }
[ "public", "function", "find", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "return", "(", "$", "options", "=", "$", "this", "->", "fetchAll", "(", ")", "->", "lists", "(", "'value'", ",", "'key'", ")", ")", "&&", "$", "options", "->", "has", "(", "$", "name", ")", "?", "$", "options", "->", "get", "(", "$", "name", ")", ":", "$", "default", ";", "}" ]
Find an option by name. @param $name @param $default @return mixed
[ "Find", "an", "option", "by", "name", "." ]
b3b43dc3bfc34710143c8e34a79603e925f07fd2
https://github.com/adminarchitect/options/blob/b3b43dc3bfc34710143c8e34a79603e925f07fd2/src/Terranet/Options/Drivers/EloquentOptionsDriver.php#L34-L39
28,777
adminarchitect/options
src/Terranet/Options/Drivers/EloquentOptionsDriver.php
EloquentOptionsDriver.create
public function create($key, $value, $group = Manager::DEFAULT_GROUP) { return $this->createModel()->create([ 'key' => $key, 'value' => $value, 'group' => $group, ]); }
php
public function create($key, $value, $group = Manager::DEFAULT_GROUP) { return $this->createModel()->create([ 'key' => $key, 'value' => $value, 'group' => $group, ]); }
[ "public", "function", "create", "(", "$", "key", ",", "$", "value", ",", "$", "group", "=", "Manager", "::", "DEFAULT_GROUP", ")", "{", "return", "$", "this", "->", "createModel", "(", ")", "->", "create", "(", "[", "'key'", "=>", "$", "key", ",", "'value'", "=>", "$", "value", ",", "'group'", "=>", "$", "group", ",", "]", ")", ";", "}" ]
Create new option. @param string $key @param string $value @param string $group @return \Illuminate\Database\Eloquent\Model|$this
[ "Create", "new", "option", "." ]
b3b43dc3bfc34710143c8e34a79603e925f07fd2
https://github.com/adminarchitect/options/blob/b3b43dc3bfc34710143c8e34a79603e925f07fd2/src/Terranet/Options/Drivers/EloquentOptionsDriver.php#L103-L110
28,778
netgen/site-bundle
bundle/EventListener/User/PostRegisterEventListener.php
PostRegisterEventListener.onUserRegistered
public function onUserRegistered(PostRegisterEvent $event): void { $user = $event->getUser(); if ($user->enabled) { $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.welcome.subject', $this->configResolver->getParameter('template.user.mail.welcome', 'ngsite'), [ 'user' => $user, ] ); return; } $accountKey = $this->ezUserAccountKeyRepository->create($user->id); if ($this->configResolver->getParameter('user.require_admin_activation', 'ngsite')) { $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.activate.admin_activation_pending.subject', $this->configResolver->getParameter('template.user.mail.activate_admin_activation_pending', 'ngsite'), [ 'user' => $user, ] ); $adminEmail = $this->configResolver->getParameter('user.mail.admin_email', 'ngsite'); $adminName = $this->configResolver->getParameter('user.mail.admin_name', 'ngsite'); if (!empty($adminEmail)) { $this->mailHelper ->sendMail( !empty($adminName) ? [$adminEmail => $adminName] : [$adminEmail], 'ngsite.user.activate.admin_activation_required.subject', $this->configResolver->getParameter('template.user.mail.activate_admin_activation_required', 'ngsite'), [ 'user' => $user, ] ); } return; } $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.activate.subject', $this->configResolver->getParameter('template.user.mail.activate', 'ngsite'), [ 'user' => $user, 'hash' => $accountKey->getHash(), ] ); }
php
public function onUserRegistered(PostRegisterEvent $event): void { $user = $event->getUser(); if ($user->enabled) { $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.welcome.subject', $this->configResolver->getParameter('template.user.mail.welcome', 'ngsite'), [ 'user' => $user, ] ); return; } $accountKey = $this->ezUserAccountKeyRepository->create($user->id); if ($this->configResolver->getParameter('user.require_admin_activation', 'ngsite')) { $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.activate.admin_activation_pending.subject', $this->configResolver->getParameter('template.user.mail.activate_admin_activation_pending', 'ngsite'), [ 'user' => $user, ] ); $adminEmail = $this->configResolver->getParameter('user.mail.admin_email', 'ngsite'); $adminName = $this->configResolver->getParameter('user.mail.admin_name', 'ngsite'); if (!empty($adminEmail)) { $this->mailHelper ->sendMail( !empty($adminName) ? [$adminEmail => $adminName] : [$adminEmail], 'ngsite.user.activate.admin_activation_required.subject', $this->configResolver->getParameter('template.user.mail.activate_admin_activation_required', 'ngsite'), [ 'user' => $user, ] ); } return; } $this->mailHelper ->sendMail( [$user->email => $this->getUserName($user)], 'ngsite.user.activate.subject', $this->configResolver->getParameter('template.user.mail.activate', 'ngsite'), [ 'user' => $user, 'hash' => $accountKey->getHash(), ] ); }
[ "public", "function", "onUserRegistered", "(", "PostRegisterEvent", "$", "event", ")", ":", "void", "{", "$", "user", "=", "$", "event", "->", "getUser", "(", ")", ";", "if", "(", "$", "user", "->", "enabled", ")", "{", "$", "this", "->", "mailHelper", "->", "sendMail", "(", "[", "$", "user", "->", "email", "=>", "$", "this", "->", "getUserName", "(", "$", "user", ")", "]", ",", "'ngsite.user.welcome.subject'", ",", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'template.user.mail.welcome'", ",", "'ngsite'", ")", ",", "[", "'user'", "=>", "$", "user", ",", "]", ")", ";", "return", ";", "}", "$", "accountKey", "=", "$", "this", "->", "ezUserAccountKeyRepository", "->", "create", "(", "$", "user", "->", "id", ")", ";", "if", "(", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'user.require_admin_activation'", ",", "'ngsite'", ")", ")", "{", "$", "this", "->", "mailHelper", "->", "sendMail", "(", "[", "$", "user", "->", "email", "=>", "$", "this", "->", "getUserName", "(", "$", "user", ")", "]", ",", "'ngsite.user.activate.admin_activation_pending.subject'", ",", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'template.user.mail.activate_admin_activation_pending'", ",", "'ngsite'", ")", ",", "[", "'user'", "=>", "$", "user", ",", "]", ")", ";", "$", "adminEmail", "=", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'user.mail.admin_email'", ",", "'ngsite'", ")", ";", "$", "adminName", "=", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'user.mail.admin_name'", ",", "'ngsite'", ")", ";", "if", "(", "!", "empty", "(", "$", "adminEmail", ")", ")", "{", "$", "this", "->", "mailHelper", "->", "sendMail", "(", "!", "empty", "(", "$", "adminName", ")", "?", "[", "$", "adminEmail", "=>", "$", "adminName", "]", ":", "[", "$", "adminEmail", "]", ",", "'ngsite.user.activate.admin_activation_required.subject'", ",", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'template.user.mail.activate_admin_activation_required'", ",", "'ngsite'", ")", ",", "[", "'user'", "=>", "$", "user", ",", "]", ")", ";", "}", "return", ";", "}", "$", "this", "->", "mailHelper", "->", "sendMail", "(", "[", "$", "user", "->", "email", "=>", "$", "this", "->", "getUserName", "(", "$", "user", ")", "]", ",", "'ngsite.user.activate.subject'", ",", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'template.user.mail.activate'", ",", "'ngsite'", ")", ",", "[", "'user'", "=>", "$", "user", ",", "'hash'", "=>", "$", "accountKey", "->", "getHash", "(", ")", ",", "]", ")", ";", "}" ]
Listens to the event triggered after the user has been registered. The event contains information about registered user.
[ "Listens", "to", "the", "event", "triggered", "after", "the", "user", "has", "been", "registered", ".", "The", "event", "contains", "information", "about", "registered", "user", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/EventListener/User/PostRegisterEventListener.php#L30-L89
28,779
netgen/site-bundle
bundle/Routing/SiteLocationUrlAliasRouter.php
SiteLocationUrlAliasRouter.generate
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH): string { if (!$name instanceof Location) { throw new RouteNotFoundException('Could not match route'); } return $this->generator->generate( $name->innerLocation, $parameters, $referenceType ); }
php
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH): string { if (!$name instanceof Location) { throw new RouteNotFoundException('Could not match route'); } return $this->generator->generate( $name->innerLocation, $parameters, $referenceType ); }
[ "public", "function", "generate", "(", "$", "name", ",", "$", "parameters", "=", "[", "]", ",", "$", "referenceType", "=", "self", "::", "ABSOLUTE_PATH", ")", ":", "string", "{", "if", "(", "!", "$", "name", "instanceof", "Location", ")", "{", "throw", "new", "RouteNotFoundException", "(", "'Could not match route'", ")", ";", "}", "return", "$", "this", "->", "generator", "->", "generate", "(", "$", "name", "->", "innerLocation", ",", "$", "parameters", ",", "$", "referenceType", ")", ";", "}" ]
Generates a URL for Site API Location object, from the given parameters. @param mixed $name @param mixed $parameters @param mixed $referenceType
[ "Generates", "a", "URL", "for", "Site", "API", "Location", "object", "from", "the", "given", "parameters", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Routing/SiteLocationUrlAliasRouter.php#L50-L61
28,780
spiral/core
src/Container.php
Container.hasInjector
public function hasInjector(\ReflectionClass $reflection): bool { if (isset($this->injectors[$reflection->getName()])) { return true; } //Auto injection! return $reflection->isSubclassOf(InjectableInterface::class); }
php
public function hasInjector(\ReflectionClass $reflection): bool { if (isset($this->injectors[$reflection->getName()])) { return true; } //Auto injection! return $reflection->isSubclassOf(InjectableInterface::class); }
[ "public", "function", "hasInjector", "(", "\\", "ReflectionClass", "$", "reflection", ")", ":", "bool", "{", "if", "(", "isset", "(", "$", "this", "->", "injectors", "[", "$", "reflection", "->", "getName", "(", ")", "]", ")", ")", "{", "return", "true", ";", "}", "//Auto injection!", "return", "$", "reflection", "->", "isSubclassOf", "(", "InjectableInterface", "::", "class", ")", ";", "}" ]
Check if given class has associated injector. @param \ReflectionClass $reflection @return bool
[ "Check", "if", "given", "class", "has", "associated", "injector", "." ]
02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e
https://github.com/spiral/core/blob/02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e/src/Container.php#L338-L346
28,781
spiral/core
src/Container.php
Container.registerInstance
protected function registerInstance($instance, array $parameters) { //Declarative singletons (only when class received via direct get) if (empty($parameters) && $instance instanceof SingletonInterface) { $alias = get_class($instance); if (!isset($this->bindings[$alias])) { $this->bindings[$alias] = $instance; } } //Your code can go here (for example LoggerAwareInterface, custom hydration and etc) return $instance; }
php
protected function registerInstance($instance, array $parameters) { //Declarative singletons (only when class received via direct get) if (empty($parameters) && $instance instanceof SingletonInterface) { $alias = get_class($instance); if (!isset($this->bindings[$alias])) { $this->bindings[$alias] = $instance; } } //Your code can go here (for example LoggerAwareInterface, custom hydration and etc) return $instance; }
[ "protected", "function", "registerInstance", "(", "$", "instance", ",", "array", "$", "parameters", ")", "{", "//Declarative singletons (only when class received via direct get)", "if", "(", "empty", "(", "$", "parameters", ")", "&&", "$", "instance", "instanceof", "SingletonInterface", ")", "{", "$", "alias", "=", "get_class", "(", "$", "instance", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "bindings", "[", "$", "alias", "]", ")", ")", "{", "$", "this", "->", "bindings", "[", "$", "alias", "]", "=", "$", "instance", ";", "}", "}", "//Your code can go here (for example LoggerAwareInterface, custom hydration and etc)", "return", "$", "instance", ";", "}" ]
Register instance in container, might perform methods like auto-singletons, log populations and etc. Can be extended. @param object $instance Created object. @param array $parameters Parameters which been passed with created instance. @return object
[ "Register", "instance", "in", "container", "might", "perform", "methods", "like", "auto", "-", "singletons", "log", "populations", "and", "etc", ".", "Can", "be", "extended", "." ]
02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e
https://github.com/spiral/core/blob/02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e/src/Container.php#L436-L450
28,782
spiral/core
src/Container.php
Container.getInjector
private function getInjector(\ReflectionClass $reflection): InjectorInterface { if (isset($this->injectors[$reflection->getName()])) { //Stated directly $injector = $this->get($this->injectors[$reflection->getName()]); } else { //Auto-injection! $injector = $this->get($reflection->getConstant('INJECTOR')); } if (!$injector instanceof InjectorInterface) { throw new InjectionException(sprintf( "Class '%s' must be an instance of InjectorInterface for '%s'", get_class($injector), $reflection->getName() )); } return $injector; }
php
private function getInjector(\ReflectionClass $reflection): InjectorInterface { if (isset($this->injectors[$reflection->getName()])) { //Stated directly $injector = $this->get($this->injectors[$reflection->getName()]); } else { //Auto-injection! $injector = $this->get($reflection->getConstant('INJECTOR')); } if (!$injector instanceof InjectorInterface) { throw new InjectionException(sprintf( "Class '%s' must be an instance of InjectorInterface for '%s'", get_class($injector), $reflection->getName() )); } return $injector; }
[ "private", "function", "getInjector", "(", "\\", "ReflectionClass", "$", "reflection", ")", ":", "InjectorInterface", "{", "if", "(", "isset", "(", "$", "this", "->", "injectors", "[", "$", "reflection", "->", "getName", "(", ")", "]", ")", ")", "{", "//Stated directly", "$", "injector", "=", "$", "this", "->", "get", "(", "$", "this", "->", "injectors", "[", "$", "reflection", "->", "getName", "(", ")", "]", ")", ";", "}", "else", "{", "//Auto-injection!", "$", "injector", "=", "$", "this", "->", "get", "(", "$", "reflection", "->", "getConstant", "(", "'INJECTOR'", ")", ")", ";", "}", "if", "(", "!", "$", "injector", "instanceof", "InjectorInterface", ")", "{", "throw", "new", "InjectionException", "(", "sprintf", "(", "\"Class '%s' must be an instance of InjectorInterface for '%s'\"", ",", "get_class", "(", "$", "injector", ")", ",", "$", "reflection", "->", "getName", "(", ")", ")", ")", ";", "}", "return", "$", "injector", ";", "}" ]
Get injector associated with given class. @param \ReflectionClass $reflection @return InjectorInterface
[ "Get", "injector", "associated", "with", "given", "class", "." ]
02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e
https://github.com/spiral/core/blob/02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e/src/Container.php#L570-L589
28,783
spiral/core
src/Container.php
Container.assertType
private function assertType( \ReflectionParameter $parameter, \ReflectionFunctionAbstract $context, $value ) { if (is_null($value)) { if ( !$parameter->isOptional() && !($parameter->isDefaultValueAvailable() && $parameter->getDefaultValue() === null) ) { throw new ArgumentException($parameter, $context); } return; } $type = $parameter->getType(); if ($type == 'array' && !is_array($value)) { throw new ArgumentException($parameter, $context); } if (($type == 'int' || $type == 'float') && !is_numeric($value)) { throw new ArgumentException($parameter, $context); } if ($type == 'bool' && !is_bool($value) && !is_numeric($value)) { throw new ArgumentException($parameter, $context); } }
php
private function assertType( \ReflectionParameter $parameter, \ReflectionFunctionAbstract $context, $value ) { if (is_null($value)) { if ( !$parameter->isOptional() && !($parameter->isDefaultValueAvailable() && $parameter->getDefaultValue() === null) ) { throw new ArgumentException($parameter, $context); } return; } $type = $parameter->getType(); if ($type == 'array' && !is_array($value)) { throw new ArgumentException($parameter, $context); } if (($type == 'int' || $type == 'float') && !is_numeric($value)) { throw new ArgumentException($parameter, $context); } if ($type == 'bool' && !is_bool($value) && !is_numeric($value)) { throw new ArgumentException($parameter, $context); } }
[ "private", "function", "assertType", "(", "\\", "ReflectionParameter", "$", "parameter", ",", "\\", "ReflectionFunctionAbstract", "$", "context", ",", "$", "value", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "if", "(", "!", "$", "parameter", "->", "isOptional", "(", ")", "&&", "!", "(", "$", "parameter", "->", "isDefaultValueAvailable", "(", ")", "&&", "$", "parameter", "->", "getDefaultValue", "(", ")", "===", "null", ")", ")", "{", "throw", "new", "ArgumentException", "(", "$", "parameter", ",", "$", "context", ")", ";", "}", "return", ";", "}", "$", "type", "=", "$", "parameter", "->", "getType", "(", ")", ";", "if", "(", "$", "type", "==", "'array'", "&&", "!", "is_array", "(", "$", "value", ")", ")", "{", "throw", "new", "ArgumentException", "(", "$", "parameter", ",", "$", "context", ")", ";", "}", "if", "(", "(", "$", "type", "==", "'int'", "||", "$", "type", "==", "'float'", ")", "&&", "!", "is_numeric", "(", "$", "value", ")", ")", "{", "throw", "new", "ArgumentException", "(", "$", "parameter", ",", "$", "context", ")", ";", "}", "if", "(", "$", "type", "==", "'bool'", "&&", "!", "is_bool", "(", "$", "value", ")", "&&", "!", "is_numeric", "(", "$", "value", ")", ")", "{", "throw", "new", "ArgumentException", "(", "$", "parameter", ",", "$", "context", ")", ";", "}", "}" ]
Assert that given value are matched parameter type. @param \ReflectionParameter $parameter @param \ReflectionFunctionAbstract $context @param mixed $value @throws ArgumentException
[ "Assert", "that", "given", "value", "are", "matched", "parameter", "type", "." ]
02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e
https://github.com/spiral/core/blob/02580dff7f1fcbc5e74caa1f78ea84c0e4c0d92e/src/Container.php#L600-L629
28,784
netgen/site-bundle
bundle/EventListener/SetCsrfEnabledEventListener.php
SetCsrfEnabledEventListener.onKernelRequest
public function onKernelRequest(GetResponseEvent $event): void { $event->getRequest()->attributes->set( 'csrf_enabled', $this->csrfTokenManager instanceof CsrfTokenManager ); }
php
public function onKernelRequest(GetResponseEvent $event): void { $event->getRequest()->attributes->set( 'csrf_enabled', $this->csrfTokenManager instanceof CsrfTokenManager ); }
[ "public", "function", "onKernelRequest", "(", "GetResponseEvent", "$", "event", ")", ":", "void", "{", "$", "event", "->", "getRequest", "(", ")", "->", "attributes", "->", "set", "(", "'csrf_enabled'", ",", "$", "this", "->", "csrfTokenManager", "instanceof", "CsrfTokenManager", ")", ";", "}" ]
Sets the variable into request indicating if CSRF protection is enabled or not.
[ "Sets", "the", "variable", "into", "request", "indicating", "if", "CSRF", "protection", "is", "enabled", "or", "not", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/EventListener/SetCsrfEnabledEventListener.php#L37-L43
28,785
netgen/site-bundle
bundle/Helper/PathHelper.php
PathHelper.getPath
public function getPath($locationId, array $options = []): array { $optionsResolver = new OptionsResolver(); $this->configureOptions($optionsResolver); $options = $optionsResolver->resolve($options); $excludedContentTypes = []; if ( !$options['use_all_content_types'] && $this->configResolver->hasParameter('path_helper.excluded_content_types', 'ngsite') ) { $excludedContentTypes = $this->configResolver->getParameter('path_helper.excluded_content_types', 'ngsite'); if (!is_array($excludedContentTypes)) { $excludedContentTypes = []; } } // The root location can be defined at site access level $rootLocationId = (int) $this->configResolver->getParameter('content.tree_root.location_id'); $path = $this->loadService->loadLocation($locationId)->path; // Shift of location "1" from path as it is not a fully valid location and not readable by most users array_shift($path); $pathArray = []; $rootLocationFound = false; foreach ($path as $index => $pathItem) { if ((int) $pathItem === $rootLocationId) { $rootLocationFound = true; } if (!$rootLocationFound) { continue; } try { $location = $this->loadService->loadLocation($pathItem); } catch (UnauthorizedException $e) { return []; } if (!in_array($location->contentInfo->contentTypeIdentifier, $excludedContentTypes, true)) { $pathArray[] = [ 'text' => $location->contentInfo->name, 'url' => $location->id !== (int) $locationId ? $this->router->generate( $location, [], $options['absolute_url'] ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH ) : false, 'location' => $location, ]; } } return $pathArray; }
php
public function getPath($locationId, array $options = []): array { $optionsResolver = new OptionsResolver(); $this->configureOptions($optionsResolver); $options = $optionsResolver->resolve($options); $excludedContentTypes = []; if ( !$options['use_all_content_types'] && $this->configResolver->hasParameter('path_helper.excluded_content_types', 'ngsite') ) { $excludedContentTypes = $this->configResolver->getParameter('path_helper.excluded_content_types', 'ngsite'); if (!is_array($excludedContentTypes)) { $excludedContentTypes = []; } } // The root location can be defined at site access level $rootLocationId = (int) $this->configResolver->getParameter('content.tree_root.location_id'); $path = $this->loadService->loadLocation($locationId)->path; // Shift of location "1" from path as it is not a fully valid location and not readable by most users array_shift($path); $pathArray = []; $rootLocationFound = false; foreach ($path as $index => $pathItem) { if ((int) $pathItem === $rootLocationId) { $rootLocationFound = true; } if (!$rootLocationFound) { continue; } try { $location = $this->loadService->loadLocation($pathItem); } catch (UnauthorizedException $e) { return []; } if (!in_array($location->contentInfo->contentTypeIdentifier, $excludedContentTypes, true)) { $pathArray[] = [ 'text' => $location->contentInfo->name, 'url' => $location->id !== (int) $locationId ? $this->router->generate( $location, [], $options['absolute_url'] ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH ) : false, 'location' => $location, ]; } } return $pathArray; }
[ "public", "function", "getPath", "(", "$", "locationId", ",", "array", "$", "options", "=", "[", "]", ")", ":", "array", "{", "$", "optionsResolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "this", "->", "configureOptions", "(", "$", "optionsResolver", ")", ";", "$", "options", "=", "$", "optionsResolver", "->", "resolve", "(", "$", "options", ")", ";", "$", "excludedContentTypes", "=", "[", "]", ";", "if", "(", "!", "$", "options", "[", "'use_all_content_types'", "]", "&&", "$", "this", "->", "configResolver", "->", "hasParameter", "(", "'path_helper.excluded_content_types'", ",", "'ngsite'", ")", ")", "{", "$", "excludedContentTypes", "=", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'path_helper.excluded_content_types'", ",", "'ngsite'", ")", ";", "if", "(", "!", "is_array", "(", "$", "excludedContentTypes", ")", ")", "{", "$", "excludedContentTypes", "=", "[", "]", ";", "}", "}", "// The root location can be defined at site access level", "$", "rootLocationId", "=", "(", "int", ")", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'content.tree_root.location_id'", ")", ";", "$", "path", "=", "$", "this", "->", "loadService", "->", "loadLocation", "(", "$", "locationId", ")", "->", "path", ";", "// Shift of location \"1\" from path as it is not a fully valid location and not readable by most users", "array_shift", "(", "$", "path", ")", ";", "$", "pathArray", "=", "[", "]", ";", "$", "rootLocationFound", "=", "false", ";", "foreach", "(", "$", "path", "as", "$", "index", "=>", "$", "pathItem", ")", "{", "if", "(", "(", "int", ")", "$", "pathItem", "===", "$", "rootLocationId", ")", "{", "$", "rootLocationFound", "=", "true", ";", "}", "if", "(", "!", "$", "rootLocationFound", ")", "{", "continue", ";", "}", "try", "{", "$", "location", "=", "$", "this", "->", "loadService", "->", "loadLocation", "(", "$", "pathItem", ")", ";", "}", "catch", "(", "UnauthorizedException", "$", "e", ")", "{", "return", "[", "]", ";", "}", "if", "(", "!", "in_array", "(", "$", "location", "->", "contentInfo", "->", "contentTypeIdentifier", ",", "$", "excludedContentTypes", ",", "true", ")", ")", "{", "$", "pathArray", "[", "]", "=", "[", "'text'", "=>", "$", "location", "->", "contentInfo", "->", "name", ",", "'url'", "=>", "$", "location", "->", "id", "!==", "(", "int", ")", "$", "locationId", "?", "$", "this", "->", "router", "->", "generate", "(", "$", "location", ",", "[", "]", ",", "$", "options", "[", "'absolute_url'", "]", "?", "UrlGeneratorInterface", "::", "ABSOLUTE_URL", ":", "UrlGeneratorInterface", "::", "ABSOLUTE_PATH", ")", ":", "false", ",", "'location'", "=>", "$", "location", ",", "]", ";", "}", "}", "return", "$", "pathArray", ";", "}" ]
Returns the path array for provided location ID. @param int|string $locationId
[ "Returns", "the", "path", "array", "for", "provided", "location", "ID", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Helper/PathHelper.php#L46-L106
28,786
netgen/site-bundle
bundle/ContextProvider/UserContextProvider.php
UserContextProvider.updateUserContext
public function updateUserContext(UserContext $context): void { $context->addParameter( 'userId', $this->repository->getPermissionResolver()->getCurrentUserReference()->getUserId() ); }
php
public function updateUserContext(UserContext $context): void { $context->addParameter( 'userId', $this->repository->getPermissionResolver()->getCurrentUserReference()->getUserId() ); }
[ "public", "function", "updateUserContext", "(", "UserContext", "$", "context", ")", ":", "void", "{", "$", "context", "->", "addParameter", "(", "'userId'", ",", "$", "this", "->", "repository", "->", "getPermissionResolver", "(", ")", "->", "getCurrentUserReference", "(", ")", "->", "getUserId", "(", ")", ")", ";", "}" ]
Adds the current user ID to the user context. Allows varying the caches per user, without taking into the account session for example.
[ "Adds", "the", "current", "user", "ID", "to", "the", "user", "context", ".", "Allows", "varying", "the", "caches", "per", "user", "without", "taking", "into", "the", "account", "session", "for", "example", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/ContextProvider/UserContextProvider.php#L27-L33
28,787
netgen/site-bundle
bundle/Command/SymlinkCommand.php
SymlinkCommand.verifyAndSymlinkFile
protected function verifyAndSymlinkFile(string $source, string $destination, OutputInterface $output): void { if (!$this->fileSystem->exists(dirname($destination))) { $this->fileSystem->mkdir(dirname($destination), 0755); } if ($this->fileSystem->exists($destination) && !is_file($destination)) { $output->writeln('<comment>' . basename($destination) . '</comment> already exists in <comment>' . dirname($destination) . '/</comment> and is not a file/symlink. Skipping...'); return; } if ($this->forceSymlinks && is_link($destination)) { $this->fileSystem->remove($destination); } if (is_file($destination) && !is_link($destination)) { if ($this->fileSystem->exists($destination . '.original')) { $output->writeln('Cannot create backup file <comment>' . basename($destination) . '.original</comment> in <comment>' . dirname($destination) . '/</comment>. Skipping...'); return; } $this->fileSystem->rename($destination, $destination . '.original'); } if ($this->fileSystem->exists($destination)) { if (is_link($destination)) { $output->writeln('Skipped creating the symlink for <comment>' . basename($destination) . '</comment> in <comment>' . dirname($destination) . '/</comment>. Symlink already exists!'); } else { $output->writeln('Skipped creating the symlink for <comment>' . basename($destination) . '</comment> in <comment>' . dirname($destination) . '/</comment> due to an unknown error.'); } return; } $this->fileSystem->symlink( $this->fileSystem->makePathRelative( dirname($source), realpath(dirname($destination)) ) . basename($source), $destination ); }
php
protected function verifyAndSymlinkFile(string $source, string $destination, OutputInterface $output): void { if (!$this->fileSystem->exists(dirname($destination))) { $this->fileSystem->mkdir(dirname($destination), 0755); } if ($this->fileSystem->exists($destination) && !is_file($destination)) { $output->writeln('<comment>' . basename($destination) . '</comment> already exists in <comment>' . dirname($destination) . '/</comment> and is not a file/symlink. Skipping...'); return; } if ($this->forceSymlinks && is_link($destination)) { $this->fileSystem->remove($destination); } if (is_file($destination) && !is_link($destination)) { if ($this->fileSystem->exists($destination . '.original')) { $output->writeln('Cannot create backup file <comment>' . basename($destination) . '.original</comment> in <comment>' . dirname($destination) . '/</comment>. Skipping...'); return; } $this->fileSystem->rename($destination, $destination . '.original'); } if ($this->fileSystem->exists($destination)) { if (is_link($destination)) { $output->writeln('Skipped creating the symlink for <comment>' . basename($destination) . '</comment> in <comment>' . dirname($destination) . '/</comment>. Symlink already exists!'); } else { $output->writeln('Skipped creating the symlink for <comment>' . basename($destination) . '</comment> in <comment>' . dirname($destination) . '/</comment> due to an unknown error.'); } return; } $this->fileSystem->symlink( $this->fileSystem->makePathRelative( dirname($source), realpath(dirname($destination)) ) . basename($source), $destination ); }
[ "protected", "function", "verifyAndSymlinkFile", "(", "string", "$", "source", ",", "string", "$", "destination", ",", "OutputInterface", "$", "output", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "fileSystem", "->", "exists", "(", "dirname", "(", "$", "destination", ")", ")", ")", "{", "$", "this", "->", "fileSystem", "->", "mkdir", "(", "dirname", "(", "$", "destination", ")", ",", "0755", ")", ";", "}", "if", "(", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "destination", ")", "&&", "!", "is_file", "(", "$", "destination", ")", ")", "{", "$", "output", "->", "writeln", "(", "'<comment>'", ".", "basename", "(", "$", "destination", ")", ".", "'</comment> already exists in <comment>'", ".", "dirname", "(", "$", "destination", ")", ".", "'/</comment> and is not a file/symlink. Skipping...'", ")", ";", "return", ";", "}", "if", "(", "$", "this", "->", "forceSymlinks", "&&", "is_link", "(", "$", "destination", ")", ")", "{", "$", "this", "->", "fileSystem", "->", "remove", "(", "$", "destination", ")", ";", "}", "if", "(", "is_file", "(", "$", "destination", ")", "&&", "!", "is_link", "(", "$", "destination", ")", ")", "{", "if", "(", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "destination", ".", "'.original'", ")", ")", "{", "$", "output", "->", "writeln", "(", "'Cannot create backup file <comment>'", ".", "basename", "(", "$", "destination", ")", ".", "'.original</comment> in <comment>'", ".", "dirname", "(", "$", "destination", ")", ".", "'/</comment>. Skipping...'", ")", ";", "return", ";", "}", "$", "this", "->", "fileSystem", "->", "rename", "(", "$", "destination", ",", "$", "destination", ".", "'.original'", ")", ";", "}", "if", "(", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "destination", ")", ")", "{", "if", "(", "is_link", "(", "$", "destination", ")", ")", "{", "$", "output", "->", "writeln", "(", "'Skipped creating the symlink for <comment>'", ".", "basename", "(", "$", "destination", ")", ".", "'</comment> in <comment>'", ".", "dirname", "(", "$", "destination", ")", ".", "'/</comment>. Symlink already exists!'", ")", ";", "}", "else", "{", "$", "output", "->", "writeln", "(", "'Skipped creating the symlink for <comment>'", ".", "basename", "(", "$", "destination", ")", ".", "'</comment> in <comment>'", ".", "dirname", "(", "$", "destination", ")", ".", "'/</comment> due to an unknown error.'", ")", ";", "}", "return", ";", "}", "$", "this", "->", "fileSystem", "->", "symlink", "(", "$", "this", "->", "fileSystem", "->", "makePathRelative", "(", "dirname", "(", "$", "source", ")", ",", "realpath", "(", "dirname", "(", "$", "destination", ")", ")", ")", ".", "basename", "(", "$", "source", ")", ",", "$", "destination", ")", ";", "}" ]
Verify that source file can be symlinked to destination and do symlinking if it can.
[ "Verify", "that", "source", "file", "can", "be", "symlinked", "to", "destination", "and", "do", "symlinking", "if", "it", "can", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Command/SymlinkCommand.php#L34-L77
28,788
netgen/site-bundle
bundle/Command/SymlinkCommand.php
SymlinkCommand.verifyAndSymlinkDirectory
protected function verifyAndSymlinkDirectory(string $source, string $destination, OutputInterface $output): void { if ($this->fileSystem->exists($destination) && !is_link($destination)) { $output->writeln('<comment>' . basename($destination) . '</comment> already exists in <comment>' . dirname($destination) . '/</comment> and is not a symlink. Skipping...'); return; } if ($this->forceSymlinks && is_link($destination)) { $this->fileSystem->remove($destination); } if ($this->fileSystem->exists($destination)) { $output->writeln('Skipped creating the symlink for <comment>' . basename($destination) . '</comment> in <comment>' . dirname($destination) . '/</comment>. Symlink already exists!'); return; } $this->fileSystem->symlink( $this->fileSystem->makePathRelative( $source, realpath(dirname($destination)) ), $destination ); }
php
protected function verifyAndSymlinkDirectory(string $source, string $destination, OutputInterface $output): void { if ($this->fileSystem->exists($destination) && !is_link($destination)) { $output->writeln('<comment>' . basename($destination) . '</comment> already exists in <comment>' . dirname($destination) . '/</comment> and is not a symlink. Skipping...'); return; } if ($this->forceSymlinks && is_link($destination)) { $this->fileSystem->remove($destination); } if ($this->fileSystem->exists($destination)) { $output->writeln('Skipped creating the symlink for <comment>' . basename($destination) . '</comment> in <comment>' . dirname($destination) . '/</comment>. Symlink already exists!'); return; } $this->fileSystem->symlink( $this->fileSystem->makePathRelative( $source, realpath(dirname($destination)) ), $destination ); }
[ "protected", "function", "verifyAndSymlinkDirectory", "(", "string", "$", "source", ",", "string", "$", "destination", ",", "OutputInterface", "$", "output", ")", ":", "void", "{", "if", "(", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "destination", ")", "&&", "!", "is_link", "(", "$", "destination", ")", ")", "{", "$", "output", "->", "writeln", "(", "'<comment>'", ".", "basename", "(", "$", "destination", ")", ".", "'</comment> already exists in <comment>'", ".", "dirname", "(", "$", "destination", ")", ".", "'/</comment> and is not a symlink. Skipping...'", ")", ";", "return", ";", "}", "if", "(", "$", "this", "->", "forceSymlinks", "&&", "is_link", "(", "$", "destination", ")", ")", "{", "$", "this", "->", "fileSystem", "->", "remove", "(", "$", "destination", ")", ";", "}", "if", "(", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "destination", ")", ")", "{", "$", "output", "->", "writeln", "(", "'Skipped creating the symlink for <comment>'", ".", "basename", "(", "$", "destination", ")", ".", "'</comment> in <comment>'", ".", "dirname", "(", "$", "destination", ")", ".", "'/</comment>. Symlink already exists!'", ")", ";", "return", ";", "}", "$", "this", "->", "fileSystem", "->", "symlink", "(", "$", "this", "->", "fileSystem", "->", "makePathRelative", "(", "$", "source", ",", "realpath", "(", "dirname", "(", "$", "destination", ")", ")", ")", ",", "$", "destination", ")", ";", "}" ]
Verify that source directory can be symlinked to destination and do symlinking if it can.
[ "Verify", "that", "source", "directory", "can", "be", "symlinked", "to", "destination", "and", "do", "symlinking", "if", "it", "can", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/Command/SymlinkCommand.php#L82-L107
28,789
Prezent/prezent-crud-bundle
src/Templating/TemplateGuesser.php
TemplateGuesser.guessTemplateNames
public function guessTemplateNames($controller, Request $request) { if (is_object($controller) && method_exists($controller, '__invoke')) { $controller = [$controller, '__invoke']; } elseif (!is_array($controller)) { throw new \InvalidArgumentException(sprintf('First argument of %s must be an array callable or an object defining the magic method __invoke. "%s" given.', __METHOD__, gettype($controller))); } if (!is_string($controller[0])) { $controller[0] = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]); } $reflClass = new \ReflectionClass($controller[0]); $templates = []; do { $controller[0] = $reflClass->getName(); if ($template = $this->guessTemplateName($controller, $request)) { $templates[] = $template; } $reflClass = $reflClass->getParentClass(); } while ($reflClass); return $templates; }
php
public function guessTemplateNames($controller, Request $request) { if (is_object($controller) && method_exists($controller, '__invoke')) { $controller = [$controller, '__invoke']; } elseif (!is_array($controller)) { throw new \InvalidArgumentException(sprintf('First argument of %s must be an array callable or an object defining the magic method __invoke. "%s" given.', __METHOD__, gettype($controller))); } if (!is_string($controller[0])) { $controller[0] = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]); } $reflClass = new \ReflectionClass($controller[0]); $templates = []; do { $controller[0] = $reflClass->getName(); if ($template = $this->guessTemplateName($controller, $request)) { $templates[] = $template; } $reflClass = $reflClass->getParentClass(); } while ($reflClass); return $templates; }
[ "public", "function", "guessTemplateNames", "(", "$", "controller", ",", "Request", "$", "request", ")", "{", "if", "(", "is_object", "(", "$", "controller", ")", "&&", "method_exists", "(", "$", "controller", ",", "'__invoke'", ")", ")", "{", "$", "controller", "=", "[", "$", "controller", ",", "'__invoke'", "]", ";", "}", "elseif", "(", "!", "is_array", "(", "$", "controller", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'First argument of %s must be an array callable or an object defining the magic method __invoke. \"%s\" given.'", ",", "__METHOD__", ",", "gettype", "(", "$", "controller", ")", ")", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "controller", "[", "0", "]", ")", ")", "{", "$", "controller", "[", "0", "]", "=", "class_exists", "(", "'Doctrine\\Common\\Util\\ClassUtils'", ")", "?", "ClassUtils", "::", "getClass", "(", "$", "controller", "[", "0", "]", ")", ":", "get_class", "(", "$", "controller", "[", "0", "]", ")", ";", "}", "$", "reflClass", "=", "new", "\\", "ReflectionClass", "(", "$", "controller", "[", "0", "]", ")", ";", "$", "templates", "=", "[", "]", ";", "do", "{", "$", "controller", "[", "0", "]", "=", "$", "reflClass", "->", "getName", "(", ")", ";", "if", "(", "$", "template", "=", "$", "this", "->", "guessTemplateName", "(", "$", "controller", ",", "$", "request", ")", ")", "{", "$", "templates", "[", "]", "=", "$", "template", ";", "}", "$", "reflClass", "=", "$", "reflClass", "->", "getParentClass", "(", ")", ";", "}", "while", "(", "$", "reflClass", ")", ";", "return", "$", "templates", ";", "}" ]
Guess multiple possible template names based on the controller @param callable $controller An array storing the controller object and action method @param Request $request A Request instance @param string $engine @return string[] Array of template references @throws \InvalidArgumentException
[ "Guess", "multiple", "possible", "template", "names", "based", "on", "the", "controller" ]
bb8bcf92cecc2acae08b8a672876b4972175ca24
https://github.com/Prezent/prezent-crud-bundle/blob/bb8bcf92cecc2acae08b8a672876b4972175ca24/src/Templating/TemplateGuesser.php#L54-L82
28,790
netgen/site-bundle
bundle/EventListener/UserEventListener.php
UserEventListener.getUserName
protected function getUserName(User $user): string { $contentInfo = $this->repository->sudo( function (Repository $repository) use ($user): ContentInfo { return $this->loadService->loadContent($user->id)->contentInfo; } ); return $contentInfo->name; }
php
protected function getUserName(User $user): string { $contentInfo = $this->repository->sudo( function (Repository $repository) use ($user): ContentInfo { return $this->loadService->loadContent($user->id)->contentInfo; } ); return $contentInfo->name; }
[ "protected", "function", "getUserName", "(", "User", "$", "user", ")", ":", "string", "{", "$", "contentInfo", "=", "$", "this", "->", "repository", "->", "sudo", "(", "function", "(", "Repository", "$", "repository", ")", "use", "(", "$", "user", ")", ":", "ContentInfo", "{", "return", "$", "this", "->", "loadService", "->", "loadContent", "(", "$", "user", "->", "id", ")", "->", "contentInfo", ";", "}", ")", ";", "return", "$", "contentInfo", "->", "name", ";", "}" ]
Returns the translated user name.
[ "Returns", "the", "translated", "user", "name", "." ]
4198c8412ffdb6692b80d35e05c8ba331365b746
https://github.com/netgen/site-bundle/blob/4198c8412ffdb6692b80d35e05c8ba331365b746/bundle/EventListener/UserEventListener.php#L67-L76
28,791
spiral/router
src/Router.php
Router.matchRoute
protected function matchRoute(ServerRequestInterface $request): ?RouteInterface { foreach ($this->routes as $route) { // Matched route will return new route instance with matched parameters $matched = $route->match($request); if (!empty($matched)) { return $matched; } } if (!empty($this->default)) { return $this->default->match($request); } // unable to match any route return null; }
php
protected function matchRoute(ServerRequestInterface $request): ?RouteInterface { foreach ($this->routes as $route) { // Matched route will return new route instance with matched parameters $matched = $route->match($request); if (!empty($matched)) { return $matched; } } if (!empty($this->default)) { return $this->default->match($request); } // unable to match any route return null; }
[ "protected", "function", "matchRoute", "(", "ServerRequestInterface", "$", "request", ")", ":", "?", "RouteInterface", "{", "foreach", "(", "$", "this", "->", "routes", "as", "$", "route", ")", "{", "// Matched route will return new route instance with matched parameters", "$", "matched", "=", "$", "route", "->", "match", "(", "$", "request", ")", ";", "if", "(", "!", "empty", "(", "$", "matched", ")", ")", "{", "return", "$", "matched", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "default", ")", ")", "{", "return", "$", "this", "->", "default", "->", "match", "(", "$", "request", ")", ";", "}", "// unable to match any route", "return", "null", ";", "}" ]
Find route matched for given request. @param ServerRequestInterface $request @return null|RouteInterface
[ "Find", "route", "matched", "for", "given", "request", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/Router.php#L142-L159
28,792
spiral/router
src/Router.php
Router.configure
protected function configure(RouteInterface $route): RouteInterface { if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { // isolating route in a given container $route = $route->withContainer($this->container); } return $route->withPrefix($this->basePath); }
php
protected function configure(RouteInterface $route): RouteInterface { if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { // isolating route in a given container $route = $route->withContainer($this->container); } return $route->withPrefix($this->basePath); }
[ "protected", "function", "configure", "(", "RouteInterface", "$", "route", ")", ":", "RouteInterface", "{", "if", "(", "$", "route", "instanceof", "ContainerizedInterface", "&&", "!", "$", "route", "->", "hasContainer", "(", ")", ")", "{", "// isolating route in a given container", "$", "route", "=", "$", "route", "->", "withContainer", "(", "$", "this", "->", "container", ")", ";", "}", "return", "$", "route", "->", "withPrefix", "(", "$", "this", "->", "basePath", ")", ";", "}" ]
Configure route with needed dependencies. @param RouteInterface $route @return RouteInterface
[ "Configure", "route", "with", "needed", "dependencies", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/Router.php#L168-L176
28,793
spiral/router
src/CoreHandler.php
CoreHandler.withVerbActions
public function withVerbActions(bool $verbActions): CoreHandler { $handler = clone $this; $handler->verbActions = $verbActions; return $handler; }
php
public function withVerbActions(bool $verbActions): CoreHandler { $handler = clone $this; $handler->verbActions = $verbActions; return $handler; }
[ "public", "function", "withVerbActions", "(", "bool", "$", "verbActions", ")", ":", "CoreHandler", "{", "$", "handler", "=", "clone", "$", "this", ";", "$", "handler", "->", "verbActions", "=", "$", "verbActions", ";", "return", "$", "handler", ";", "}" ]
Disable or enable HTTP prefix for actions. @param bool $verbActions @return CoreHandler
[ "Disable", "or", "enable", "HTTP", "prefix", "for", "actions", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/CoreHandler.php#L79-L85
28,794
spiral/router
src/CoreHandler.php
CoreHandler.wrapResponse
private function wrapResponse(Response $response, $result = null, string $output = ''): Response { if ($result instanceof Response) { if (!empty($output) && $result->getBody()->isWritable()) { $result->getBody()->write($output); } return $result; } if (is_array($result) || $result instanceof \JsonSerializable) { $response = $this->writeJson($response, $result); } else { $response->getBody()->write($result); } //Always glue buffered output $response->getBody()->write($output); return $response; }
php
private function wrapResponse(Response $response, $result = null, string $output = ''): Response { if ($result instanceof Response) { if (!empty($output) && $result->getBody()->isWritable()) { $result->getBody()->write($output); } return $result; } if (is_array($result) || $result instanceof \JsonSerializable) { $response = $this->writeJson($response, $result); } else { $response->getBody()->write($result); } //Always glue buffered output $response->getBody()->write($output); return $response; }
[ "private", "function", "wrapResponse", "(", "Response", "$", "response", ",", "$", "result", "=", "null", ",", "string", "$", "output", "=", "''", ")", ":", "Response", "{", "if", "(", "$", "result", "instanceof", "Response", ")", "{", "if", "(", "!", "empty", "(", "$", "output", ")", "&&", "$", "result", "->", "getBody", "(", ")", "->", "isWritable", "(", ")", ")", "{", "$", "result", "->", "getBody", "(", ")", "->", "write", "(", "$", "output", ")", ";", "}", "return", "$", "result", ";", "}", "if", "(", "is_array", "(", "$", "result", ")", "||", "$", "result", "instanceof", "\\", "JsonSerializable", ")", "{", "$", "response", "=", "$", "this", "->", "writeJson", "(", "$", "response", ",", "$", "result", ")", ";", "}", "else", "{", "$", "response", "->", "getBody", "(", ")", "->", "write", "(", "$", "result", ")", ";", "}", "//Always glue buffered output", "$", "response", "->", "getBody", "(", ")", "->", "write", "(", "$", "output", ")", ";", "return", "$", "response", ";", "}" ]
Convert endpoint result into valid response. @param Response $response Initial pipeline response. @param mixed $result Generated endpoint output. @param string $output Buffer output. @return Response
[ "Convert", "endpoint", "result", "into", "valid", "response", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/CoreHandler.php#L149-L169
28,795
spiral/router
src/CoreHandler.php
CoreHandler.mapException
private function mapException(ControllerException $exception): ClientException { switch ($exception->getCode()) { case ControllerException::BAD_ACTION: //no break case ControllerException::NOT_FOUND: return new NotFoundException($exception->getMessage()); case ControllerException::FORBIDDEN: return new ForbiddenException($exception->getMessage()); default: return new BadRequestException($exception->getMessage()); } }
php
private function mapException(ControllerException $exception): ClientException { switch ($exception->getCode()) { case ControllerException::BAD_ACTION: //no break case ControllerException::NOT_FOUND: return new NotFoundException($exception->getMessage()); case ControllerException::FORBIDDEN: return new ForbiddenException($exception->getMessage()); default: return new BadRequestException($exception->getMessage()); } }
[ "private", "function", "mapException", "(", "ControllerException", "$", "exception", ")", ":", "ClientException", "{", "switch", "(", "$", "exception", "->", "getCode", "(", ")", ")", "{", "case", "ControllerException", "::", "BAD_ACTION", ":", "//no break", "case", "ControllerException", "::", "NOT_FOUND", ":", "return", "new", "NotFoundException", "(", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "case", "ControllerException", "::", "FORBIDDEN", ":", "return", "new", "ForbiddenException", "(", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "default", ":", "return", "new", "BadRequestException", "(", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Converts core specific ControllerException into HTTP ClientException. @param ControllerException $exception @return ClientException
[ "Converts", "core", "specific", "ControllerException", "into", "HTTP", "ClientException", "." ]
35721d06231d5650402eb93ac7f3ade00cd1b640
https://github.com/spiral/router/blob/35721d06231d5650402eb93ac7f3ade00cd1b640/src/CoreHandler.php#L177-L189
28,796
Atnic/laravel-generator
app/Database/Eloquent/Concerns/HasRelationships.php
HasRelationships.belongsToOne
public function belongsToOne($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null, $parentKey = null, $relatedKey = null, $relation = null) { // If no relationship name was passed, we will pull backtraces to get the // name of the calling function. We will use that function name as the // title of this relation since that is a great convention to apply. if (is_null($relation)) { $relation = $this->guessBelongsToOneRelation(); } // First, we'll need to determine the foreign key and "other key" for the // relationship. Once we have determined the keys we'll make the query // instances as well as the relationship instances we need for this. $instance = $this->newRelatedInstance($related); $foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey(); $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey(); // If no table name was provided, we can guess it by concatenating the two // models using underscores in alphabetical order. The two model names // are transformed to snake case from their default CamelCase also. if (is_null($table)) { $table = $this->joiningTable($related); } return $this->newBelongsToOne( $instance->newQuery(), $this, $table, $foreignPivotKey, $relatedPivotKey, $parentKey ?: $this->getKeyName(), $relatedKey ?: $instance->getKeyName(), $relation ); }
php
public function belongsToOne($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null, $parentKey = null, $relatedKey = null, $relation = null) { // If no relationship name was passed, we will pull backtraces to get the // name of the calling function. We will use that function name as the // title of this relation since that is a great convention to apply. if (is_null($relation)) { $relation = $this->guessBelongsToOneRelation(); } // First, we'll need to determine the foreign key and "other key" for the // relationship. Once we have determined the keys we'll make the query // instances as well as the relationship instances we need for this. $instance = $this->newRelatedInstance($related); $foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey(); $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey(); // If no table name was provided, we can guess it by concatenating the two // models using underscores in alphabetical order. The two model names // are transformed to snake case from their default CamelCase also. if (is_null($table)) { $table = $this->joiningTable($related); } return $this->newBelongsToOne( $instance->newQuery(), $this, $table, $foreignPivotKey, $relatedPivotKey, $parentKey ?: $this->getKeyName(), $relatedKey ?: $instance->getKeyName(), $relation ); }
[ "public", "function", "belongsToOne", "(", "$", "related", ",", "$", "table", "=", "null", ",", "$", "foreignPivotKey", "=", "null", ",", "$", "relatedPivotKey", "=", "null", ",", "$", "parentKey", "=", "null", ",", "$", "relatedKey", "=", "null", ",", "$", "relation", "=", "null", ")", "{", "// If no relationship name was passed, we will pull backtraces to get the", "// name of the calling function. We will use that function name as the", "// title of this relation since that is a great convention to apply.", "if", "(", "is_null", "(", "$", "relation", ")", ")", "{", "$", "relation", "=", "$", "this", "->", "guessBelongsToOneRelation", "(", ")", ";", "}", "// First, we'll need to determine the foreign key and \"other key\" for the", "// relationship. Once we have determined the keys we'll make the query", "// instances as well as the relationship instances we need for this.", "$", "instance", "=", "$", "this", "->", "newRelatedInstance", "(", "$", "related", ")", ";", "$", "foreignPivotKey", "=", "$", "foreignPivotKey", "?", ":", "$", "this", "->", "getForeignKey", "(", ")", ";", "$", "relatedPivotKey", "=", "$", "relatedPivotKey", "?", ":", "$", "instance", "->", "getForeignKey", "(", ")", ";", "// If no table name was provided, we can guess it by concatenating the two", "// models using underscores in alphabetical order. The two model names", "// are transformed to snake case from their default CamelCase also.", "if", "(", "is_null", "(", "$", "table", ")", ")", "{", "$", "table", "=", "$", "this", "->", "joiningTable", "(", "$", "related", ")", ";", "}", "return", "$", "this", "->", "newBelongsToOne", "(", "$", "instance", "->", "newQuery", "(", ")", ",", "$", "this", ",", "$", "table", ",", "$", "foreignPivotKey", ",", "$", "relatedPivotKey", ",", "$", "parentKey", "?", ":", "$", "this", "->", "getKeyName", "(", ")", ",", "$", "relatedKey", "?", ":", "$", "instance", "->", "getKeyName", "(", ")", ",", "$", "relation", ")", ";", "}" ]
Define a one-to-one via pivot relationship. @param string $related @param string $table @param string $foreignPivotKey @param string $relatedPivotKey @param string $parentKey @param string $relatedKey @param string $relation @return \Atnic\LaravelGenerator\Database\Eloquent\Relations\BelongsToOne
[ "Define", "a", "one", "-", "to", "-", "one", "via", "pivot", "relationship", "." ]
7bf53837a61af566b389255784dbbf1789020018
https://github.com/Atnic/laravel-generator/blob/7bf53837a61af566b389255784dbbf1789020018/app/Database/Eloquent/Concerns/HasRelationships.php#L88-L119
28,797
alaxos/cakephp3-libs
src/Lib/ShellTool.php
ShellTool.color
public static function color($text, $color) { if (isset(ShellTool::$colors[$color])) { return ShellTool::$colors[$color]['start'] . $text . ShellTool::$colors[$color]['close']; } else { return $text; } }
php
public static function color($text, $color) { if (isset(ShellTool::$colors[$color])) { return ShellTool::$colors[$color]['start'] . $text . ShellTool::$colors[$color]['close']; } else { return $text; } }
[ "public", "static", "function", "color", "(", "$", "text", ",", "$", "color", ")", "{", "if", "(", "isset", "(", "ShellTool", "::", "$", "colors", "[", "$", "color", "]", ")", ")", "{", "return", "ShellTool", "::", "$", "colors", "[", "$", "color", "]", "[", "'start'", "]", ".", "$", "text", ".", "ShellTool", "::", "$", "colors", "[", "$", "color", "]", "[", "'close'", "]", ";", "}", "else", "{", "return", "$", "text", ";", "}", "}" ]
Return the given text formatted in the given color @param string $text @param string $color @return string
[ "Return", "the", "given", "text", "formatted", "in", "the", "given", "color" ]
685e9f17a3fbe3550c59a03a65c4d75df763e804
https://github.com/alaxos/cakephp3-libs/blob/685e9f17a3fbe3550c59a03a65c4d75df763e804/src/Lib/ShellTool.php#L17-L24
28,798
nilportugues/php-api-transformer
src/Transformer/Helpers/RecursiveDeleteHelper.php
RecursiveDeleteHelper.deleteProperties
public static function deleteProperties(array &$mappings, array &$array, string $typeKey) { if (\array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) { $newArray = []; self::deleteMatchedClassProperties($mappings, $array, $typeKey, $newArray); if (!empty($newArray)) { $array = $newArray; } } }
php
public static function deleteProperties(array &$mappings, array &$array, string $typeKey) { if (\array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) { $newArray = []; self::deleteMatchedClassProperties($mappings, $array, $typeKey, $newArray); if (!empty($newArray)) { $array = $newArray; } } }
[ "public", "static", "function", "deleteProperties", "(", "array", "&", "$", "mappings", ",", "array", "&", "$", "array", ",", "string", "$", "typeKey", ")", "{", "if", "(", "\\", "array_key_exists", "(", "Serializer", "::", "CLASS_IDENTIFIER_KEY", ",", "$", "array", ")", ")", "{", "$", "newArray", "=", "[", "]", ";", "self", "::", "deleteMatchedClassProperties", "(", "$", "mappings", ",", "$", "array", ",", "$", "typeKey", ",", "$", "newArray", ")", ";", "if", "(", "!", "empty", "(", "$", "newArray", ")", ")", "{", "$", "array", "=", "$", "newArray", ";", "}", "}", "}" ]
Removes a sets if keys for a given class using recursion. @param \NilPortugues\Api\Mapping\Mapping[] $mappings @param array $array Array with data @param string $typeKey Scope to do the replacement.
[ "Removes", "a", "sets", "if", "keys", "for", "a", "given", "class", "using", "recursion", "." ]
a9f20fbe1580d98e3d462a0ebe13fb7595cbd683
https://github.com/nilportugues/php-api-transformer/blob/a9f20fbe1580d98e3d462a0ebe13fb7595cbd683/src/Transformer/Helpers/RecursiveDeleteHelper.php#L79-L90
28,799
cedx/coveralls.php
lib/GitCommit.php
GitCommit.fromJson
static function fromJson(object $map): self { return (new static(isset($map->id) && is_string($map->id) ? $map->id : '', isset($map->message) && is_string($map->message) ? $map->message : '')) ->setAuthorEmail(isset($map->author_email) && is_string($map->author_email) ? $map->author_email : '') ->setAuthorName(isset($map->author_name) && is_string($map->author_name) ? $map->author_name : '') ->setCommitterEmail(isset($map->committer_email) && is_string($map->committer_email) ? $map->committer_email : '') ->setCommitterName(isset($map->committer_name) && is_string($map->committer_name) ? $map->committer_name : ''); }
php
static function fromJson(object $map): self { return (new static(isset($map->id) && is_string($map->id) ? $map->id : '', isset($map->message) && is_string($map->message) ? $map->message : '')) ->setAuthorEmail(isset($map->author_email) && is_string($map->author_email) ? $map->author_email : '') ->setAuthorName(isset($map->author_name) && is_string($map->author_name) ? $map->author_name : '') ->setCommitterEmail(isset($map->committer_email) && is_string($map->committer_email) ? $map->committer_email : '') ->setCommitterName(isset($map->committer_name) && is_string($map->committer_name) ? $map->committer_name : ''); }
[ "static", "function", "fromJson", "(", "object", "$", "map", ")", ":", "self", "{", "return", "(", "new", "static", "(", "isset", "(", "$", "map", "->", "id", ")", "&&", "is_string", "(", "$", "map", "->", "id", ")", "?", "$", "map", "->", "id", ":", "''", ",", "isset", "(", "$", "map", "->", "message", ")", "&&", "is_string", "(", "$", "map", "->", "message", ")", "?", "$", "map", "->", "message", ":", "''", ")", ")", "->", "setAuthorEmail", "(", "isset", "(", "$", "map", "->", "author_email", ")", "&&", "is_string", "(", "$", "map", "->", "author_email", ")", "?", "$", "map", "->", "author_email", ":", "''", ")", "->", "setAuthorName", "(", "isset", "(", "$", "map", "->", "author_name", ")", "&&", "is_string", "(", "$", "map", "->", "author_name", ")", "?", "$", "map", "->", "author_name", ":", "''", ")", "->", "setCommitterEmail", "(", "isset", "(", "$", "map", "->", "committer_email", ")", "&&", "is_string", "(", "$", "map", "->", "committer_email", ")", "?", "$", "map", "->", "committer_email", ":", "''", ")", "->", "setCommitterName", "(", "isset", "(", "$", "map", "->", "committer_name", ")", "&&", "is_string", "(", "$", "map", "->", "committer_name", ")", "?", "$", "map", "->", "committer_name", ":", "''", ")", ";", "}" ]
Creates a new Git commit from the specified JSON map. @param object $map A JSON map representing a Git commit. @return static The instance corresponding to the specified JSON map.
[ "Creates", "a", "new", "Git", "commit", "from", "the", "specified", "JSON", "map", "." ]
c196de0f92e06d5143ba90ebab18c8e384316cc0
https://github.com/cedx/coveralls.php/blob/c196de0f92e06d5143ba90ebab18c8e384316cc0/lib/GitCommit.php#L40-L46