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
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
200
artscorestudio/layout-bundle
DependencyInjection/ASFLayoutExtension.php
ASFLayoutExtension.addTwbsInAssetic
protected function addTwbsInAssetic(ContainerBuilder $container, array $config) { if ($config['twbs_dir'] !== false && !is_null($config['twbs_dir'])) { // Twitter Bootstrap javascript files $inputs = array(); foreach ($config['js'] as $file) { $inputs[] = $config['twbs_dir'].'/'.$file; } $container->prependExtensionConfig('assetic', array( 'assets' => array( 'twbs_js' => array( 'inputs' => $inputs, ), ), )); // Twitter Bootstrap Less files or CSS files if (count($config['less']) > 0 && count($config['css']) > 0) { throw new InvalidConfigurationException('You can\'t have less files and css files in your Twitter Bootstrap Configuration, choose one.'); } elseif (count($config['less']) > 0) { $inputs = array(); foreach ($config['less'] as $file) { $inputs[] = $config['twbs_dir'].'/'.$file; } $container->prependExtensionConfig('assetic', array( 'assets' => array( 'twbs_css' => array( 'inputs' => $inputs, ), ), )); } elseif (count($config['css']) > 0) { $inputs = array(); foreach ($config['css'] as $file) { $inputs[] = $config['twbs_dir'].'/'.$file; } $container->prependExtensionConfig('assetic', array( 'assets' => array( 'twbs_css' => array( 'inputs' => $inputs, ), ), )); } } }
php
protected function addTwbsInAssetic(ContainerBuilder $container, array $config) { if ($config['twbs_dir'] !== false && !is_null($config['twbs_dir'])) { // Twitter Bootstrap javascript files $inputs = array(); foreach ($config['js'] as $file) { $inputs[] = $config['twbs_dir'].'/'.$file; } $container->prependExtensionConfig('assetic', array( 'assets' => array( 'twbs_js' => array( 'inputs' => $inputs, ), ), )); // Twitter Bootstrap Less files or CSS files if (count($config['less']) > 0 && count($config['css']) > 0) { throw new InvalidConfigurationException('You can\'t have less files and css files in your Twitter Bootstrap Configuration, choose one.'); } elseif (count($config['less']) > 0) { $inputs = array(); foreach ($config['less'] as $file) { $inputs[] = $config['twbs_dir'].'/'.$file; } $container->prependExtensionConfig('assetic', array( 'assets' => array( 'twbs_css' => array( 'inputs' => $inputs, ), ), )); } elseif (count($config['css']) > 0) { $inputs = array(); foreach ($config['css'] as $file) { $inputs[] = $config['twbs_dir'].'/'.$file; } $container->prependExtensionConfig('assetic', array( 'assets' => array( 'twbs_css' => array( 'inputs' => $inputs, ), ), )); } } }
[ "protected", "function", "addTwbsInAssetic", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "if", "(", "$", "config", "[", "'twbs_dir'", "]", "!==", "false", "&&", "!", "is_null", "(", "$", "config", "[", "'twbs_dir'", "]", ")", ")", "{", "// Twitter Bootstrap javascript files", "$", "inputs", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "[", "'js'", "]", "as", "$", "file", ")", "{", "$", "inputs", "[", "]", "=", "$", "config", "[", "'twbs_dir'", "]", ".", "'/'", ".", "$", "file", ";", "}", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'assets'", "=>", "array", "(", "'twbs_js'", "=>", "array", "(", "'inputs'", "=>", "$", "inputs", ",", ")", ",", ")", ",", ")", ")", ";", "// Twitter Bootstrap Less files or CSS files", "if", "(", "count", "(", "$", "config", "[", "'less'", "]", ")", ">", "0", "&&", "count", "(", "$", "config", "[", "'css'", "]", ")", ">", "0", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "'You can\\'t have less files and css files in your Twitter Bootstrap Configuration, choose one.'", ")", ";", "}", "elseif", "(", "count", "(", "$", "config", "[", "'less'", "]", ")", ">", "0", ")", "{", "$", "inputs", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "[", "'less'", "]", "as", "$", "file", ")", "{", "$", "inputs", "[", "]", "=", "$", "config", "[", "'twbs_dir'", "]", ".", "'/'", ".", "$", "file", ";", "}", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'assets'", "=>", "array", "(", "'twbs_css'", "=>", "array", "(", "'inputs'", "=>", "$", "inputs", ",", ")", ",", ")", ",", ")", ")", ";", "}", "elseif", "(", "count", "(", "$", "config", "[", "'css'", "]", ")", ">", "0", ")", "{", "$", "inputs", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "[", "'css'", "]", "as", "$", "file", ")", "{", "$", "inputs", "[", "]", "=", "$", "config", "[", "'twbs_dir'", "]", ".", "'/'", ".", "$", "file", ";", "}", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'assets'", "=>", "array", "(", "'twbs_css'", "=>", "array", "(", "'inputs'", "=>", "$", "inputs", ",", ")", ",", ")", ",", ")", ")", ";", "}", "}", "}" ]
Adding Twitter Bootstrap in Assetic. @param ContainerBuilder $container @param array $config @throws InvalidConfigurationException : You can't have less files and css files configured
[ "Adding", "Twitter", "Bootstrap", "in", "Assetic", "." ]
5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740
https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/DependencyInjection/ASFLayoutExtension.php#L202-L251
201
artscorestudio/layout-bundle
DependencyInjection/ASFLayoutExtension.php
ASFLayoutExtension.addSelect2InAssetic
protected function addSelect2InAssetic(ContainerBuilder $container, array $config) { if ($config['js'] !== false && $config['css'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'select2_js' => $config['js'], 'select2_css' => $config['css'], ), )); } elseif ($config['js'] === false && $config['css'] !== false) { throw new InvalidConfigurationException('You have enabled select2 supports but js parameter is missing.'); } elseif ($config['js'] !== false && $config['css'] === false) { throw new InvalidConfigurationException('You have enabled select2 supports but css parameter is missing.'); } }
php
protected function addSelect2InAssetic(ContainerBuilder $container, array $config) { if ($config['js'] !== false && $config['css'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'select2_js' => $config['js'], 'select2_css' => $config['css'], ), )); } elseif ($config['js'] === false && $config['css'] !== false) { throw new InvalidConfigurationException('You have enabled select2 supports but js parameter is missing.'); } elseif ($config['js'] !== false && $config['css'] === false) { throw new InvalidConfigurationException('You have enabled select2 supports but css parameter is missing.'); } }
[ "protected", "function", "addSelect2InAssetic", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "if", "(", "$", "config", "[", "'js'", "]", "!==", "false", "&&", "$", "config", "[", "'css'", "]", "!==", "false", ")", "{", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'assets'", "=>", "array", "(", "'select2_js'", "=>", "$", "config", "[", "'js'", "]", ",", "'select2_css'", "=>", "$", "config", "[", "'css'", "]", ",", ")", ",", ")", ")", ";", "}", "elseif", "(", "$", "config", "[", "'js'", "]", "===", "false", "&&", "$", "config", "[", "'css'", "]", "!==", "false", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "'You have enabled select2 supports but js parameter is missing.'", ")", ";", "}", "elseif", "(", "$", "config", "[", "'js'", "]", "!==", "false", "&&", "$", "config", "[", "'css'", "]", "===", "false", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "'You have enabled select2 supports but css parameter is missing.'", ")", ";", "}", "}" ]
Adding Select2 in Assetic. @param ContainerBuilder $container @param array $config @throws InvalidConfigurationException : "Js path not set or CSS path not set"
[ "Adding", "Select2", "in", "Assetic", "." ]
5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740
https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/DependencyInjection/ASFLayoutExtension.php#L261-L275
202
artscorestudio/layout-bundle
DependencyInjection/ASFLayoutExtension.php
ASFLayoutExtension.addBazingaJsTranslationInAssetic
protected function addBazingaJsTranslationInAssetic(ContainerBuilder $container, array $config) { if ($config['bz_translator_js'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'bz_translator_js' => $config['bz_translator_js'], 'bz_translator_config' => $config['bz_translator_config'], 'bz_translations_files' => $config['bz_translations_files'], ), )); } }
php
protected function addBazingaJsTranslationInAssetic(ContainerBuilder $container, array $config) { if ($config['bz_translator_js'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'bz_translator_js' => $config['bz_translator_js'], 'bz_translator_config' => $config['bz_translator_config'], 'bz_translations_files' => $config['bz_translations_files'], ), )); } }
[ "protected", "function", "addBazingaJsTranslationInAssetic", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "if", "(", "$", "config", "[", "'bz_translator_js'", "]", "!==", "false", ")", "{", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'assets'", "=>", "array", "(", "'bz_translator_js'", "=>", "$", "config", "[", "'bz_translator_js'", "]", ",", "'bz_translator_config'", "=>", "$", "config", "[", "'bz_translator_config'", "]", ",", "'bz_translations_files'", "=>", "$", "config", "[", "'bz_translations_files'", "]", ",", ")", ",", ")", ")", ";", "}", "}" ]
Adding Bazinga Js Translation in Assetic. @param ContainerBuilder $container @param array $config
[ "Adding", "Bazinga", "Js", "Translation", "in", "Assetic", "." ]
5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740
https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/DependencyInjection/ASFLayoutExtension.php#L283-L294
203
artscorestudio/layout-bundle
DependencyInjection/ASFLayoutExtension.php
ASFLayoutExtension.addTinyMCEInAssetic
protected function addTinyMCEInAssetic(ContainerBuilder $container, array $config) { if ($config['tinymce_dir'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'tinymce_js' => $config['tinymce_dir'].'/'.$config['js'], 'config' => $config['config'], ), )); } }
php
protected function addTinyMCEInAssetic(ContainerBuilder $container, array $config) { if ($config['tinymce_dir'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'tinymce_js' => $config['tinymce_dir'].'/'.$config['js'], 'config' => $config['config'], ), )); } }
[ "protected", "function", "addTinyMCEInAssetic", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "if", "(", "$", "config", "[", "'tinymce_dir'", "]", "!==", "false", ")", "{", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'assets'", "=>", "array", "(", "'tinymce_js'", "=>", "$", "config", "[", "'tinymce_dir'", "]", ".", "'/'", ".", "$", "config", "[", "'js'", "]", ",", "'config'", "=>", "$", "config", "[", "'config'", "]", ",", ")", ",", ")", ")", ";", "}", "}" ]
Adding TinyMCE In Assetic. @param ContainerBuilder $container @param array $config
[ "Adding", "TinyMCE", "In", "Assetic", "." ]
5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740
https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/DependencyInjection/ASFLayoutExtension.php#L319-L329
204
artscorestudio/layout-bundle
DependencyInjection/ASFLayoutExtension.php
ASFLayoutExtension.addJqueryTagsInputInAssetic
protected function addJqueryTagsInputInAssetic(ContainerBuilder $container, array $config) { if ($config['js'] !== false && $config['css'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'jquerytagsinput_js' => $config['js'], 'jquerytagsinput_css' => $config['css'], ), )); } elseif ($config['js'] === false && $config['css'] !== false) { throw new InvalidConfigurationException('You have enabled jQuery Tags Input supports but js parameter is missing.'); } elseif ($config['js'] !== false && $config['css'] === false) { throw new InvalidConfigurationException('You have enabled jQuery Tags Input supports but css parameter is missing.'); } }
php
protected function addJqueryTagsInputInAssetic(ContainerBuilder $container, array $config) { if ($config['js'] !== false && $config['css'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'jquerytagsinput_js' => $config['js'], 'jquerytagsinput_css' => $config['css'], ), )); } elseif ($config['js'] === false && $config['css'] !== false) { throw new InvalidConfigurationException('You have enabled jQuery Tags Input supports but js parameter is missing.'); } elseif ($config['js'] !== false && $config['css'] === false) { throw new InvalidConfigurationException('You have enabled jQuery Tags Input supports but css parameter is missing.'); } }
[ "protected", "function", "addJqueryTagsInputInAssetic", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "if", "(", "$", "config", "[", "'js'", "]", "!==", "false", "&&", "$", "config", "[", "'css'", "]", "!==", "false", ")", "{", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'assets'", "=>", "array", "(", "'jquerytagsinput_js'", "=>", "$", "config", "[", "'js'", "]", ",", "'jquerytagsinput_css'", "=>", "$", "config", "[", "'css'", "]", ",", ")", ",", ")", ")", ";", "}", "elseif", "(", "$", "config", "[", "'js'", "]", "===", "false", "&&", "$", "config", "[", "'css'", "]", "!==", "false", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "'You have enabled jQuery Tags Input supports but js parameter is missing.'", ")", ";", "}", "elseif", "(", "$", "config", "[", "'js'", "]", "!==", "false", "&&", "$", "config", "[", "'css'", "]", "===", "false", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "'You have enabled jQuery Tags Input supports but css parameter is missing.'", ")", ";", "}", "}" ]
Adding jQuery Tags Input Plugin in Assetic. @param ContainerBuilder $container @param array $config @throws InvalidConfigurationException : "Js path not set or CSS path not set"
[ "Adding", "jQuery", "Tags", "Input", "Plugin", "in", "Assetic", "." ]
5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740
https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/DependencyInjection/ASFLayoutExtension.php#L339-L353
205
artscorestudio/layout-bundle
DependencyInjection/ASFLayoutExtension.php
ASFLayoutExtension.addPrismJSInAssetic
protected function addPrismJSInAssetic(ContainerBuilder $container, array $config) { if ($config['js'] !== false && $config['css'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'prismjs_js' => $config['js'], 'prismjs_css' => $config['css'], ), )); } elseif ($config['js'] === false && $config['css'] !== false) { throw new InvalidConfigurationException('You have enabled PrismJS supports but js parameter is missing.'); } elseif ($config['js'] !== false && $config['css'] === false) { throw new InvalidConfigurationException('You have enabled PrismJS supports but css parameter is missing.'); } }
php
protected function addPrismJSInAssetic(ContainerBuilder $container, array $config) { if ($config['js'] !== false && $config['css'] !== false) { $container->prependExtensionConfig('assetic', array( 'assets' => array( 'prismjs_js' => $config['js'], 'prismjs_css' => $config['css'], ), )); } elseif ($config['js'] === false && $config['css'] !== false) { throw new InvalidConfigurationException('You have enabled PrismJS supports but js parameter is missing.'); } elseif ($config['js'] !== false && $config['css'] === false) { throw new InvalidConfigurationException('You have enabled PrismJS supports but css parameter is missing.'); } }
[ "protected", "function", "addPrismJSInAssetic", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "if", "(", "$", "config", "[", "'js'", "]", "!==", "false", "&&", "$", "config", "[", "'css'", "]", "!==", "false", ")", "{", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'assets'", "=>", "array", "(", "'prismjs_js'", "=>", "$", "config", "[", "'js'", "]", ",", "'prismjs_css'", "=>", "$", "config", "[", "'css'", "]", ",", ")", ",", ")", ")", ";", "}", "elseif", "(", "$", "config", "[", "'js'", "]", "===", "false", "&&", "$", "config", "[", "'css'", "]", "!==", "false", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "'You have enabled PrismJS supports but js parameter is missing.'", ")", ";", "}", "elseif", "(", "$", "config", "[", "'js'", "]", "!==", "false", "&&", "$", "config", "[", "'css'", "]", "===", "false", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "'You have enabled PrismJS supports but css parameter is missing.'", ")", ";", "}", "}" ]
Adding PrismJS in Assetic. @param ContainerBuilder $container @param array $config @throws InvalidConfigurationException : "Js path not set or CSS path not set"
[ "Adding", "PrismJS", "in", "Assetic", "." ]
5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740
https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/DependencyInjection/ASFLayoutExtension.php#L363-L377
206
ellipsephp/validation
src/RulesParser.php
RulesParser.getRuleFactory
private function getRuleFactory(string $name): callable { if (array_key_exists($name, $this->factories)) { return $this->factories[$name]; } throw new RuleFactoryNotDefinedException($name); }
php
private function getRuleFactory(string $name): callable { if (array_key_exists($name, $this->factories)) { return $this->factories[$name]; } throw new RuleFactoryNotDefinedException($name); }
[ "private", "function", "getRuleFactory", "(", "string", "$", "name", ")", ":", "callable", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "factories", ")", ")", "{", "return", "$", "this", "->", "factories", "[", "$", "name", "]", ";", "}", "throw", "new", "RuleFactoryNotDefinedException", "(", "$", "name", ")", ";", "}" ]
Return the rule factory associated to the given name. @param string $name @return callable
[ "Return", "the", "rule", "factory", "associated", "to", "the", "given", "name", "." ]
5a7e11807099165ff6217bf8c38df4b21d99599d
https://github.com/ellipsephp/validation/blob/5a7e11807099165ff6217bf8c38df4b21d99599d/src/RulesParser.php#L33-L42
207
ellipsephp/validation
src/RulesParser.php
RulesParser.parseRulesDefinition
public function parseRulesDefinition($definition): RulesCollection { if (is_callable($definition)) { $definition = [$definition]; } if (is_string($definition)) { $definition = array_map('trim', explode('|', $definition)); } if (is_array($definition)) { $keys = array_keys($definition); return array_reduce($keys, function ($rules, $key) use ($definition) { $definition = $definition[$key]; $rule = $this->parseRuleDefinition($key, $definition); return $rules->withRule($rule); }, new RulesCollection); } throw new InvalidRuleFormatException($definition); }
php
public function parseRulesDefinition($definition): RulesCollection { if (is_callable($definition)) { $definition = [$definition]; } if (is_string($definition)) { $definition = array_map('trim', explode('|', $definition)); } if (is_array($definition)) { $keys = array_keys($definition); return array_reduce($keys, function ($rules, $key) use ($definition) { $definition = $definition[$key]; $rule = $this->parseRuleDefinition($key, $definition); return $rules->withRule($rule); }, new RulesCollection); } throw new InvalidRuleFormatException($definition); }
[ "public", "function", "parseRulesDefinition", "(", "$", "definition", ")", ":", "RulesCollection", "{", "if", "(", "is_callable", "(", "$", "definition", ")", ")", "{", "$", "definition", "=", "[", "$", "definition", "]", ";", "}", "if", "(", "is_string", "(", "$", "definition", ")", ")", "{", "$", "definition", "=", "array_map", "(", "'trim'", ",", "explode", "(", "'|'", ",", "$", "definition", ")", ")", ";", "}", "if", "(", "is_array", "(", "$", "definition", ")", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "definition", ")", ";", "return", "array_reduce", "(", "$", "keys", ",", "function", "(", "$", "rules", ",", "$", "key", ")", "use", "(", "$", "definition", ")", "{", "$", "definition", "=", "$", "definition", "[", "$", "key", "]", ";", "$", "rule", "=", "$", "this", "->", "parseRuleDefinition", "(", "$", "key", ",", "$", "definition", ")", ";", "return", "$", "rules", "->", "withRule", "(", "$", "rule", ")", ";", "}", ",", "new", "RulesCollection", ")", ";", "}", "throw", "new", "InvalidRuleFormatException", "(", "$", "definition", ")", ";", "}" ]
Return a rules collection from a rule definition. It can be either a callable, an array of callables, an array of factory names or a string of rule factory names. @param mixed $definition @return \Ellipse\Validation\RulesCollection
[ "Return", "a", "rules", "collection", "from", "a", "rule", "definition", ".", "It", "can", "be", "either", "a", "callable", "an", "array", "of", "callables", "an", "array", "of", "factory", "names", "or", "a", "string", "of", "rule", "factory", "names", "." ]
5a7e11807099165ff6217bf8c38df4b21d99599d
https://github.com/ellipsephp/validation/blob/5a7e11807099165ff6217bf8c38df4b21d99599d/src/RulesParser.php#L52-L83
208
ellipsephp/validation
src/RulesParser.php
RulesParser.parseRuleDefinition
private function parseRuleDefinition($key, $definition): Rule { if (is_string($definition)) { $parts = preg_split('/:/', $definition, 2); $factory_name = $parts[0]; $parameters = $parts[1] ?? null; $parameters = ! is_null($parameters) ? explode(',', $parameters) : []; $factory_name = trim($factory_name); $parameters = array_map('trim', $parameters); $factory = $this->getRuleFactory($factory_name); $name = is_string($key) ? $key : $factory_name; $validate = $factory($parameters); return new Rule($name, $validate); } // is_callable must be AFTER is_string, otherwise factories named like a // php function can't be used (ex: date). if (is_callable($definition)) { return new Rule((string) $key, $definition); } throw new InvalidRuleFormatException($definition); }
php
private function parseRuleDefinition($key, $definition): Rule { if (is_string($definition)) { $parts = preg_split('/:/', $definition, 2); $factory_name = $parts[0]; $parameters = $parts[1] ?? null; $parameters = ! is_null($parameters) ? explode(',', $parameters) : []; $factory_name = trim($factory_name); $parameters = array_map('trim', $parameters); $factory = $this->getRuleFactory($factory_name); $name = is_string($key) ? $key : $factory_name; $validate = $factory($parameters); return new Rule($name, $validate); } // is_callable must be AFTER is_string, otherwise factories named like a // php function can't be used (ex: date). if (is_callable($definition)) { return new Rule((string) $key, $definition); } throw new InvalidRuleFormatException($definition); }
[ "private", "function", "parseRuleDefinition", "(", "$", "key", ",", "$", "definition", ")", ":", "Rule", "{", "if", "(", "is_string", "(", "$", "definition", ")", ")", "{", "$", "parts", "=", "preg_split", "(", "'/:/'", ",", "$", "definition", ",", "2", ")", ";", "$", "factory_name", "=", "$", "parts", "[", "0", "]", ";", "$", "parameters", "=", "$", "parts", "[", "1", "]", "??", "null", ";", "$", "parameters", "=", "!", "is_null", "(", "$", "parameters", ")", "?", "explode", "(", "','", ",", "$", "parameters", ")", ":", "[", "]", ";", "$", "factory_name", "=", "trim", "(", "$", "factory_name", ")", ";", "$", "parameters", "=", "array_map", "(", "'trim'", ",", "$", "parameters", ")", ";", "$", "factory", "=", "$", "this", "->", "getRuleFactory", "(", "$", "factory_name", ")", ";", "$", "name", "=", "is_string", "(", "$", "key", ")", "?", "$", "key", ":", "$", "factory_name", ";", "$", "validate", "=", "$", "factory", "(", "$", "parameters", ")", ";", "return", "new", "Rule", "(", "$", "name", ",", "$", "validate", ")", ";", "}", "// is_callable must be AFTER is_string, otherwise factories named like a", "// php function can't be used (ex: date).", "if", "(", "is_callable", "(", "$", "definition", ")", ")", "{", "return", "new", "Rule", "(", "(", "string", ")", "$", "key", ",", "$", "definition", ")", ";", "}", "throw", "new", "InvalidRuleFormatException", "(", "$", "definition", ")", ";", "}" ]
Return a rule from a rule key and the associated definition. It can be either a callable or a rule factory name with optional parameters. @param string $key @param mixed $definition @return \Ellipse\Validation\Rule
[ "Return", "a", "rule", "from", "a", "rule", "key", "and", "the", "associated", "definition", ".", "It", "can", "be", "either", "a", "callable", "or", "a", "rule", "factory", "name", "with", "optional", "parameters", "." ]
5a7e11807099165ff6217bf8c38df4b21d99599d
https://github.com/ellipsephp/validation/blob/5a7e11807099165ff6217bf8c38df4b21d99599d/src/RulesParser.php#L93-L127
209
CatLabInteractive/Neuron
src/Neuron/Net/Response.php
Response.table
public static function table ($data) { $in = new self (); $in->setData ($data); $in->setOutput (new Table ()); return $in; }
php
public static function table ($data) { $in = new self (); $in->setData ($data); $in->setOutput (new Table ()); return $in; }
[ "public", "static", "function", "table", "(", "$", "data", ")", "{", "$", "in", "=", "new", "self", "(", ")", ";", "$", "in", "->", "setData", "(", "$", "data", ")", ";", "$", "in", "->", "setOutput", "(", "new", "Table", "(", ")", ")", ";", "return", "$", "in", ";", "}" ]
Show the data in a html table. @param $data @return Response
[ "Show", "the", "data", "in", "a", "html", "table", "." ]
67dca5349891e23b31a96dcdead893b9491a1b8b
https://github.com/CatLabInteractive/Neuron/blob/67dca5349891e23b31a96dcdead893b9491a1b8b/src/Neuron/Net/Response.php#L76-L82
210
CatLabInteractive/Neuron
src/Neuron/Net/Response.php
Response.print_r
public static function print_r ($data) { $in = new self (); $in->setData ($data); $in->setOutput (new PrintR()); return $in; }
php
public static function print_r ($data) { $in = new self (); $in->setData ($data); $in->setOutput (new PrintR()); return $in; }
[ "public", "static", "function", "print_r", "(", "$", "data", ")", "{", "$", "in", "=", "new", "self", "(", ")", ";", "$", "in", "->", "setData", "(", "$", "data", ")", ";", "$", "in", "->", "setOutput", "(", "new", "PrintR", "(", ")", ")", ";", "return", "$", "in", ";", "}" ]
Show the data in print_r form, html. @param $data @return Response
[ "Show", "the", "data", "in", "print_r", "form", "html", "." ]
67dca5349891e23b31a96dcdead893b9491a1b8b
https://github.com/CatLabInteractive/Neuron/blob/67dca5349891e23b31a96dcdead893b9491a1b8b/src/Neuron/Net/Response.php#L89-L95
211
CatLabInteractive/Neuron
src/Neuron/Net/Response.php
Response.proxy
public static function proxy ($request) { if (!$request instanceof Request) { $url = $request; $request = new Request (); $request->setUrl ($url); $request->setMethod (Request::METHOD_GET); } return Client::getInstance ()->process ($request); }
php
public static function proxy ($request) { if (!$request instanceof Request) { $url = $request; $request = new Request (); $request->setUrl ($url); $request->setMethod (Request::METHOD_GET); } return Client::getInstance ()->process ($request); }
[ "public", "static", "function", "proxy", "(", "$", "request", ")", "{", "if", "(", "!", "$", "request", "instanceof", "Request", ")", "{", "$", "url", "=", "$", "request", ";", "$", "request", "=", "new", "Request", "(", ")", ";", "$", "request", "->", "setUrl", "(", "$", "url", ")", ";", "$", "request", "->", "setMethod", "(", "Request", "::", "METHOD_GET", ")", ";", "}", "return", "Client", "::", "getInstance", "(", ")", "->", "process", "(", "$", "request", ")", ";", "}" ]
Proxy a request. @param string|Request $request Url or Request object. @return Response
[ "Proxy", "a", "request", "." ]
67dca5349891e23b31a96dcdead893b9491a1b8b
https://github.com/CatLabInteractive/Neuron/blob/67dca5349891e23b31a96dcdead893b9491a1b8b/src/Neuron/Net/Response.php#L169-L180
212
CatLabInteractive/Neuron
src/Neuron/Net/Response.php
Response.setRedirect
public function setRedirect ($url) { $this->setHeader ('Location', $url); $this->setStatus (302); $this->setData (array ('message' => 'Redirecting to ' . $url)); return $this; }
php
public function setRedirect ($url) { $this->setHeader ('Location', $url); $this->setStatus (302); $this->setData (array ('message' => 'Redirecting to ' . $url)); return $this; }
[ "public", "function", "setRedirect", "(", "$", "url", ")", "{", "$", "this", "->", "setHeader", "(", "'Location'", ",", "$", "url", ")", ";", "$", "this", "->", "setStatus", "(", "302", ")", ";", "$", "this", "->", "setData", "(", "array", "(", "'message'", "=>", "'Redirecting to '", ".", "$", "url", ")", ")", ";", "return", "$", "this", ";", "}" ]
Set a response to be a redirect. @param $url @return $this
[ "Set", "a", "response", "to", "be", "a", "redirect", "." ]
67dca5349891e23b31a96dcdead893b9491a1b8b
https://github.com/CatLabInteractive/Neuron/blob/67dca5349891e23b31a96dcdead893b9491a1b8b/src/Neuron/Net/Response.php#L202-L209
213
CatLabInteractive/Neuron
src/Neuron/Router.php
Router.match
public function match ($methods, $pattern, $fn) { $pattern = $this->baseroute . '/' . trim($pattern, '/'); $pattern = $this->baseroute ? rtrim($pattern, '/') : $pattern; $route = new Route ($pattern); $route->setFunction ($fn); $route->setModule ($this->module); foreach (explode('|', $methods) as $method) { $this->routes[$method][] = $route; } return $route; }
php
public function match ($methods, $pattern, $fn) { $pattern = $this->baseroute . '/' . trim($pattern, '/'); $pattern = $this->baseroute ? rtrim($pattern, '/') : $pattern; $route = new Route ($pattern); $route->setFunction ($fn); $route->setModule ($this->module); foreach (explode('|', $methods) as $method) { $this->routes[$method][] = $route; } return $route; }
[ "public", "function", "match", "(", "$", "methods", ",", "$", "pattern", ",", "$", "fn", ")", "{", "$", "pattern", "=", "$", "this", "->", "baseroute", ".", "'/'", ".", "trim", "(", "$", "pattern", ",", "'/'", ")", ";", "$", "pattern", "=", "$", "this", "->", "baseroute", "?", "rtrim", "(", "$", "pattern", ",", "'/'", ")", ":", "$", "pattern", ";", "$", "route", "=", "new", "Route", "(", "$", "pattern", ")", ";", "$", "route", "->", "setFunction", "(", "$", "fn", ")", ";", "$", "route", "->", "setModule", "(", "$", "this", "->", "module", ")", ";", "foreach", "(", "explode", "(", "'|'", ",", "$", "methods", ")", "as", "$", "method", ")", "{", "$", "this", "->", "routes", "[", "$", "method", "]", "[", "]", "=", "$", "route", ";", "}", "return", "$", "route", ";", "}" ]
Store a route and a handling function to be executed when accessed using one of the specified methods @param string $methods Allowed methods, | delimited @param string $pattern A route pattern such as /about/system @param mixed $fn The handling function to be executed @return Route
[ "Store", "a", "route", "and", "a", "handling", "function", "to", "be", "executed", "when", "accessed", "using", "one", "of", "the", "specified", "methods" ]
67dca5349891e23b31a96dcdead893b9491a1b8b
https://github.com/CatLabInteractive/Neuron/blob/67dca5349891e23b31a96dcdead893b9491a1b8b/src/Neuron/Router.php#L64-L78
214
cstabor/screw
src/Screw/Str.php
Str.toSnakeCase
public static function toSnakeCase($name) { $temp_array = array(); for($i=0;$i<strlen($name);$i++){ $ascii_code = ord($name[$i]); if($ascii_code >= 65 && $ascii_code <= 90){ if($i == 0){ $temp_array[] = chr($ascii_code + 32); }else{ $temp_array[] = '_'.chr($ascii_code + 32); } }else{ $temp_array[] = $name[$i]; } } return implode('',$temp_array); }
php
public static function toSnakeCase($name) { $temp_array = array(); for($i=0;$i<strlen($name);$i++){ $ascii_code = ord($name[$i]); if($ascii_code >= 65 && $ascii_code <= 90){ if($i == 0){ $temp_array[] = chr($ascii_code + 32); }else{ $temp_array[] = '_'.chr($ascii_code + 32); } }else{ $temp_array[] = $name[$i]; } } return implode('',$temp_array); }
[ "public", "static", "function", "toSnakeCase", "(", "$", "name", ")", "{", "$", "temp_array", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "name", ")", ";", "$", "i", "++", ")", "{", "$", "ascii_code", "=", "ord", "(", "$", "name", "[", "$", "i", "]", ")", ";", "if", "(", "$", "ascii_code", ">=", "65", "&&", "$", "ascii_code", "<=", "90", ")", "{", "if", "(", "$", "i", "==", "0", ")", "{", "$", "temp_array", "[", "]", "=", "chr", "(", "$", "ascii_code", "+", "32", ")", ";", "}", "else", "{", "$", "temp_array", "[", "]", "=", "'_'", ".", "chr", "(", "$", "ascii_code", "+", "32", ")", ";", "}", "}", "else", "{", "$", "temp_array", "[", "]", "=", "$", "name", "[", "$", "i", "]", ";", "}", "}", "return", "implode", "(", "''", ",", "$", "temp_array", ")", ";", "}" ]
userName -> user_name @param string $name @return string
[ "userName", "-", ">", "user_name" ]
c160c2b740bd1e0e72535fddf1c15cab99558669
https://github.com/cstabor/screw/blob/c160c2b740bd1e0e72535fddf1c15cab99558669/src/Screw/Str.php#L238-L253
215
sebardo/core
CoreBundle/Controller/ParameterController.php
ParameterController.showAction
public function showAction(Parameter $entity) { $deleteForm = $this->createDeleteForm($entity); return array( 'entity' => $entity, 'delete_form' => $deleteForm->createView(), ); }
php
public function showAction(Parameter $entity) { $deleteForm = $this->createDeleteForm($entity); return array( 'entity' => $entity, 'delete_form' => $deleteForm->createView(), ); }
[ "public", "function", "showAction", "(", "Parameter", "$", "entity", ")", "{", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "entity", ")", ";", "return", "array", "(", "'entity'", "=>", "$", "entity", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Finds and displays a parameter entity. @Route("/{id}") @Method("GET") @Template()
[ "Finds", "and", "displays", "a", "parameter", "entity", "." ]
d063334639dd717406c97ea4da9f4b260d0af4f4
https://github.com/sebardo/core/blob/d063334639dd717406c97ea4da9f4b260d0af4f4/CoreBundle/Controller/ParameterController.php#L95-L103
216
sebardo/core
CoreBundle/Controller/ParameterController.php
ParameterController.createDeleteForm
private function createDeleteForm(Parameter $entity) { return $this->createFormBuilder() ->setAction($this->generateUrl('core_parameter_delete', array('id' => $entity->getId()))) ->setMethod('DELETE') ->getForm() ; }
php
private function createDeleteForm(Parameter $entity) { return $this->createFormBuilder() ->setAction($this->generateUrl('core_parameter_delete', array('id' => $entity->getId()))) ->setMethod('DELETE') ->getForm() ; }
[ "private", "function", "createDeleteForm", "(", "Parameter", "$", "entity", ")", "{", "return", "$", "this", "->", "createFormBuilder", "(", ")", "->", "setAction", "(", "$", "this", "->", "generateUrl", "(", "'core_parameter_delete'", ",", "array", "(", "'id'", "=>", "$", "entity", "->", "getId", "(", ")", ")", ")", ")", "->", "setMethod", "(", "'DELETE'", ")", "->", "getForm", "(", ")", ";", "}" ]
Creates a form to delete a parameter entity. @param Parameter $parameter The parameter entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "delete", "a", "parameter", "entity", "." ]
d063334639dd717406c97ea4da9f4b260d0af4f4
https://github.com/sebardo/core/blob/d063334639dd717406c97ea4da9f4b260d0af4f4/CoreBundle/Controller/ParameterController.php#L168-L175
217
SocietyCMS/Core
Validators/BaseValidator.php
BaseValidator.passes
public function passes($action = null) { $this->data = $this->sanitize($this->data); $rules = $this->getRules($action); $validator = $this->validator->make($this->data, $rules); if ($validator->fails()) { $this->errors = $validator->messages(); return false; } return true; }
php
public function passes($action = null) { $this->data = $this->sanitize($this->data); $rules = $this->getRules($action); $validator = $this->validator->make($this->data, $rules); if ($validator->fails()) { $this->errors = $validator->messages(); return false; } return true; }
[ "public", "function", "passes", "(", "$", "action", "=", "null", ")", "{", "$", "this", "->", "data", "=", "$", "this", "->", "sanitize", "(", "$", "this", "->", "data", ")", ";", "$", "rules", "=", "$", "this", "->", "getRules", "(", "$", "action", ")", ";", "$", "validator", "=", "$", "this", "->", "validator", "->", "make", "(", "$", "this", "->", "data", ",", "$", "rules", ")", ";", "if", "(", "$", "validator", "->", "fails", "(", ")", ")", "{", "$", "this", "->", "errors", "=", "$", "validator", "->", "messages", "(", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Pass the data and the rules to the validator. @param string $action @return bool
[ "Pass", "the", "data", "and", "the", "rules", "to", "the", "validator", "." ]
fb6be1b1dd46c89a976c02feb998e9af01ddca54
https://github.com/SocietyCMS/Core/blob/fb6be1b1dd46c89a976c02feb998e9af01ddca54/Validators/BaseValidator.php#L37-L51
218
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.exchangeArray
public function exchangeArray($dataSet) { if (is_object($dataSet)) { switch(true) { case is_callable(array($dataSet, 'getArrayCopy'), false): $dataSet = $dataSet->getArrayCopy(); break; case is_callable(array($dataSet, 'toArray'), false): $dataSet = $dataSet->toArray(); break; case is_callable(array($dataSet, '__toArray'), false): $dataSet = $dataSet->__toArray(); break; case ($dataSet instanceof \stdClass): $dataSet = (array)$dataSet; break; default: throw new \InvalidArgumentException(vsprintf( '%s - Unable to exchange data with object of class "%s".', array(get_class($this), get_class($dataSet))) ); } } if (is_array($dataSet)) { $prevStorage = $this->_storage; $this->_storage = $dataSet; $this->_modified = true; return $prevStorage; } throw new \InvalidArgumentException(vsprintf( '%s::exchangeArray expects parameter 1 to be array or object, "%s" seen.', array(get_class($this), gettype($dataSet)) )); }
php
public function exchangeArray($dataSet) { if (is_object($dataSet)) { switch(true) { case is_callable(array($dataSet, 'getArrayCopy'), false): $dataSet = $dataSet->getArrayCopy(); break; case is_callable(array($dataSet, 'toArray'), false): $dataSet = $dataSet->toArray(); break; case is_callable(array($dataSet, '__toArray'), false): $dataSet = $dataSet->__toArray(); break; case ($dataSet instanceof \stdClass): $dataSet = (array)$dataSet; break; default: throw new \InvalidArgumentException(vsprintf( '%s - Unable to exchange data with object of class "%s".', array(get_class($this), get_class($dataSet))) ); } } if (is_array($dataSet)) { $prevStorage = $this->_storage; $this->_storage = $dataSet; $this->_modified = true; return $prevStorage; } throw new \InvalidArgumentException(vsprintf( '%s::exchangeArray expects parameter 1 to be array or object, "%s" seen.', array(get_class($this), gettype($dataSet)) )); }
[ "public", "function", "exchangeArray", "(", "$", "dataSet", ")", "{", "if", "(", "is_object", "(", "$", "dataSet", ")", ")", "{", "switch", "(", "true", ")", "{", "case", "is_callable", "(", "array", "(", "$", "dataSet", ",", "'getArrayCopy'", ")", ",", "false", ")", ":", "$", "dataSet", "=", "$", "dataSet", "->", "getArrayCopy", "(", ")", ";", "break", ";", "case", "is_callable", "(", "array", "(", "$", "dataSet", ",", "'toArray'", ")", ",", "false", ")", ":", "$", "dataSet", "=", "$", "dataSet", "->", "toArray", "(", ")", ";", "break", ";", "case", "is_callable", "(", "array", "(", "$", "dataSet", ",", "'__toArray'", ")", ",", "false", ")", ":", "$", "dataSet", "=", "$", "dataSet", "->", "__toArray", "(", ")", ";", "break", ";", "case", "(", "$", "dataSet", "instanceof", "\\", "stdClass", ")", ":", "$", "dataSet", "=", "(", "array", ")", "$", "dataSet", ";", "break", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "vsprintf", "(", "'%s - Unable to exchange data with object of class \"%s\".'", ",", "array", "(", "get_class", "(", "$", "this", ")", ",", "get_class", "(", "$", "dataSet", ")", ")", ")", ")", ";", "}", "}", "if", "(", "is_array", "(", "$", "dataSet", ")", ")", "{", "$", "prevStorage", "=", "$", "this", "->", "_storage", ";", "$", "this", "->", "_storage", "=", "$", "dataSet", ";", "$", "this", "->", "_modified", "=", "true", ";", "return", "$", "prevStorage", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "vsprintf", "(", "'%s::exchangeArray expects parameter 1 to be array or object, \"%s\" seen.'", ",", "array", "(", "get_class", "(", "$", "this", ")", ",", "gettype", "(", "$", "dataSet", ")", ")", ")", ")", ";", "}" ]
This method was inspired by Zend Framework 2.2.x PhpReferenceCompatibility class @link https://github.com/zendframework/zf2/blob/release-2.2.6/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php#L179 @param $dataSet @return array @throws \InvalidArgumentException
[ "This", "method", "was", "inspired", "by", "Zend", "Framework", "2", ".", "2", ".", "x", "PhpReferenceCompatibility", "class" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L370-L409
219
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.exists
public function exists($func) { if (!is_callable($func, false, $callable_name)) throw new \InvalidArgumentException(get_class($this).'::exists - Un-callable "$func" value seen!'); foreach($this->_storage as $key => $value) { if (call_user_func($func, $key, $value)) return true; } return false; }
php
public function exists($func) { if (!is_callable($func, false, $callable_name)) throw new \InvalidArgumentException(get_class($this).'::exists - Un-callable "$func" value seen!'); foreach($this->_storage as $key => $value) { if (call_user_func($func, $key, $value)) return true; } return false; }
[ "public", "function", "exists", "(", "$", "func", ")", "{", "if", "(", "!", "is_callable", "(", "$", "func", ",", "false", ",", "$", "callable_name", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "get_class", "(", "$", "this", ")", ".", "'::exists - Un-callable \"$func\" value seen!'", ")", ";", "foreach", "(", "$", "this", "->", "_storage", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "call_user_func", "(", "$", "func", ",", "$", "key", ",", "$", "value", ")", ")", "return", "true", ";", "}", "return", "false", ";", "}" ]
Custom "contains" method @param callable $func @throws \InvalidArgumentException @return bool
[ "Custom", "contains", "method" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L452-L464
220
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.remove
public function remove($index) { if (isset($this->_storage[$index]) || array_key_exists($index, $this->_storage)) { $this->_modified = true; $removed = $this->_storage[$index]; unset($this->_storage[$index]); return $removed; } return null; }
php
public function remove($index) { if (isset($this->_storage[$index]) || array_key_exists($index, $this->_storage)) { $this->_modified = true; $removed = $this->_storage[$index]; unset($this->_storage[$index]); return $removed; } return null; }
[ "public", "function", "remove", "(", "$", "index", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_storage", "[", "$", "index", "]", ")", "||", "array_key_exists", "(", "$", "index", ",", "$", "this", "->", "_storage", ")", ")", "{", "$", "this", "->", "_modified", "=", "true", ";", "$", "removed", "=", "$", "this", "->", "_storage", "[", "$", "index", "]", ";", "unset", "(", "$", "this", "->", "_storage", "[", "$", "index", "]", ")", ";", "return", "$", "removed", ";", "}", "return", "null", ";", "}" ]
Remove and return an element @param $index @return mixed|null
[ "Remove", "and", "return", "an", "element" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L482-L493
221
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.map
public function map($func) { if (is_callable($func, false)) return $this->initNew(array_map($func, $this->_storage)); throw new \InvalidArgumentException(vsprintf( '%s::map - Un-callable "$func" value seen!', array(get_class($this))) ); }
php
public function map($func) { if (is_callable($func, false)) return $this->initNew(array_map($func, $this->_storage)); throw new \InvalidArgumentException(vsprintf( '%s::map - Un-callable "$func" value seen!', array(get_class($this))) ); }
[ "public", "function", "map", "(", "$", "func", ")", "{", "if", "(", "is_callable", "(", "$", "func", ",", "false", ")", ")", "return", "$", "this", "->", "initNew", "(", "array_map", "(", "$", "func", ",", "$", "this", "->", "_storage", ")", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "vsprintf", "(", "'%s::map - Un-callable \"$func\" value seen!'", ",", "array", "(", "get_class", "(", "$", "this", ")", ")", ")", ")", ";", "}" ]
Applies array_map to this collection, and returns a new object. @link http://us1.php.net/array_map The scope "static" is used so that an instance of the extended class is returned. @param callable $func @throws \InvalidArgumentException @return \DCarbone\CollectionPlusInterface
[ "Applies", "array_map", "to", "this", "collection", "and", "returns", "a", "new", "object", "." ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L568-L577
222
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.filter
public function filter($func = null) { if (null === $func) return $this->initNew(array_filter($this->_storage)); if (is_callable($func, false)) return $this->initNew(array_filter($this->_storage, $func)); throw new \InvalidArgumentException(vsprintf( '%s::filter - Un-callable "$func" value seen!', array(get_class($this))) ); }
php
public function filter($func = null) { if (null === $func) return $this->initNew(array_filter($this->_storage)); if (is_callable($func, false)) return $this->initNew(array_filter($this->_storage, $func)); throw new \InvalidArgumentException(vsprintf( '%s::filter - Un-callable "$func" value seen!', array(get_class($this))) ); }
[ "public", "function", "filter", "(", "$", "func", "=", "null", ")", "{", "if", "(", "null", "===", "$", "func", ")", "return", "$", "this", "->", "initNew", "(", "array_filter", "(", "$", "this", "->", "_storage", ")", ")", ";", "if", "(", "is_callable", "(", "$", "func", ",", "false", ")", ")", "return", "$", "this", "->", "initNew", "(", "array_filter", "(", "$", "this", "->", "_storage", ",", "$", "func", ")", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "vsprintf", "(", "'%s::filter - Un-callable \"$func\" value seen!'", ",", "array", "(", "get_class", "(", "$", "this", ")", ")", ")", ")", ";", "}" ]
Applies array_filter to internal collection, returns new instance with resulting values. @link http://www.php.net/manual/en/function.array-filter.php Inspired by: @link http://www.doctrine-project.org/api/common/2.3/source-class-Doctrine.Common.Collections.ArrayCollection.html#377-387 @param callable $func @throws \InvalidArgumentException @return \DCarbone\CollectionPlusInterface
[ "Applies", "array_filter", "to", "internal", "collection", "returns", "new", "instance", "with", "resulting", "values", "." ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L592-L604
223
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.sort
public function sort($flags = SORT_REGULAR) { $this->_modified = true; return sort($this->_storage, $flags); }
php
public function sort($flags = SORT_REGULAR) { $this->_modified = true; return sort($this->_storage, $flags); }
[ "public", "function", "sort", "(", "$", "flags", "=", "SORT_REGULAR", ")", "{", "$", "this", "->", "_modified", "=", "true", ";", "return", "sort", "(", "$", "this", "->", "_storage", ",", "$", "flags", ")", ";", "}" ]
Sort values by standard PHP sort method @link http://www.php.net/manual/en/function.sort.php @param int $flags @return bool
[ "Sort", "values", "by", "standard", "PHP", "sort", "method" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L654-L658
224
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.rsort
public function rsort($flags = SORT_REGULAR) { $this->_modified = true; return rsort($this->_storage, $flags); }
php
public function rsort($flags = SORT_REGULAR) { $this->_modified = true; return rsort($this->_storage, $flags); }
[ "public", "function", "rsort", "(", "$", "flags", "=", "SORT_REGULAR", ")", "{", "$", "this", "->", "_modified", "=", "true", ";", "return", "rsort", "(", "$", "this", "->", "_storage", ",", "$", "flags", ")", ";", "}" ]
Reverse sort values @link http://www.php.net/manual/en/function.rsort.php @param int $flags @return bool
[ "Reverse", "sort", "values" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L668-L672
225
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.ksort
public function ksort($flags = SORT_REGULAR) { $this->_modified = true; return ksort($this->_storage, $flags); }
php
public function ksort($flags = SORT_REGULAR) { $this->_modified = true; return ksort($this->_storage, $flags); }
[ "public", "function", "ksort", "(", "$", "flags", "=", "SORT_REGULAR", ")", "{", "$", "this", "->", "_modified", "=", "true", ";", "return", "ksort", "(", "$", "this", "->", "_storage", ",", "$", "flags", ")", ";", "}" ]
Sort by keys @link http://www.php.net/manual/en/function.ksort.php @param int $flags @return bool
[ "Sort", "by", "keys" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L696-L700
226
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.krsort
public function krsort($flags = SORT_REGULAR) { $this->_modified = true; return krsort($this->_storage, $flags); }
php
public function krsort($flags = SORT_REGULAR) { $this->_modified = true; return krsort($this->_storage, $flags); }
[ "public", "function", "krsort", "(", "$", "flags", "=", "SORT_REGULAR", ")", "{", "$", "this", "->", "_modified", "=", "true", ";", "return", "krsort", "(", "$", "this", "->", "_storage", ",", "$", "flags", ")", ";", "}" ]
Reverse sort by keys @link http://www.php.net/manual/en/function.krsort.php @param int $flags @return bool
[ "Reverse", "sort", "by", "keys" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L710-L714
227
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.asort
public function asort($flags = SORT_REGULAR) { $this->_modified = true; return asort($this->_storage, $flags); }
php
public function asort($flags = SORT_REGULAR) { $this->_modified = true; return asort($this->_storage, $flags); }
[ "public", "function", "asort", "(", "$", "flags", "=", "SORT_REGULAR", ")", "{", "$", "this", "->", "_modified", "=", "true", ";", "return", "asort", "(", "$", "this", "->", "_storage", ",", "$", "flags", ")", ";", "}" ]
Sort values while retaining indices. @link http://www.php.net/manual/en/function.asort.php @param int $flags @return bool
[ "Sort", "values", "while", "retaining", "indices", "." ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L738-L742
228
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus.arsort
public function arsort($flags = SORT_REGULAR) { $this->_modified = true; return arsort($this->_storage, $flags); }
php
public function arsort($flags = SORT_REGULAR) { $this->_modified = true; return arsort($this->_storage, $flags); }
[ "public", "function", "arsort", "(", "$", "flags", "=", "SORT_REGULAR", ")", "{", "$", "this", "->", "_modified", "=", "true", ";", "return", "arsort", "(", "$", "this", "->", "_storage", ",", "$", "flags", ")", ";", "}" ]
Reverse sort values while retaining indices @link http://www.php.net/manual/en/function.arsort.php @param int $flags @return bool
[ "Reverse", "sort", "values", "while", "retaining", "indices" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L752-L756
229
dcarbone/collection-plus
src/AbstractCollectionPlus.php
AbstractCollectionPlus._updateFirstLastKeys
private function _updateFirstLastKeys() { end($this->_storage); $this->_lastKey = key($this->_storage); reset($this->_storage); $this->_firstKey = key($this->_storage); $this->_modified = false; }
php
private function _updateFirstLastKeys() { end($this->_storage); $this->_lastKey = key($this->_storage); reset($this->_storage); $this->_firstKey = key($this->_storage); $this->_modified = false; }
[ "private", "function", "_updateFirstLastKeys", "(", ")", "{", "end", "(", "$", "this", "->", "_storage", ")", ";", "$", "this", "->", "_lastKey", "=", "key", "(", "$", "this", "->", "_storage", ")", ";", "reset", "(", "$", "this", "->", "_storage", ")", ";", "$", "this", "->", "_firstKey", "=", "key", "(", "$", "this", "->", "_storage", ")", ";", "$", "this", "->", "_modified", "=", "false", ";", "}" ]
Update internal references to first and last keys in collection
[ "Update", "internal", "references", "to", "first", "and", "last", "keys", "in", "collection" ]
d0790ec06ff84f01aec752fa4aa768653e69c2b5
https://github.com/dcarbone/collection-plus/blob/d0790ec06ff84f01aec752fa4aa768653e69c2b5/src/AbstractCollectionPlus.php#L823-L831
230
SergioMadness/framework
framework/components/observer/traits/Subject.php
Subject.notify
public function notify($type = 'default') { if (isset($this->observers[$type])) { foreach ($this->observers[$type] as $obs) { $obs->update($this); } } return $this; }
php
public function notify($type = 'default') { if (isset($this->observers[$type])) { foreach ($this->observers[$type] as $obs) { $obs->update($this); } } return $this; }
[ "public", "function", "notify", "(", "$", "type", "=", "'default'", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "observers", "[", "$", "type", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "observers", "[", "$", "type", "]", "as", "$", "obs", ")", "{", "$", "obs", "->", "update", "(", "$", "this", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Notify observers by type @param string $type
[ "Notify", "observers", "by", "type" ]
a5038eb926a5038b9a331d0cb6a68d7fc3cf1f1e
https://github.com/SergioMadness/framework/blob/a5038eb926a5038b9a331d0cb6a68d7fc3cf1f1e/framework/components/observer/traits/Subject.php#L56-L64
231
harvestcloud/CoreBundle
Controller/Order/DefaultController.php
DefaultController.mark_ready_for_dispatchAction
public function mark_ready_for_dispatchAction(Order $order) { $order->markReadyForDispatchBySeller(); $em = $this->getDoctrine()->getEntityManager(); $em->persist($order); $em->flush(); return $this->redirect($this->generateUrl('Order_show', array( 'id' => $order->getNumberForPath() ))); }
php
public function mark_ready_for_dispatchAction(Order $order) { $order->markReadyForDispatchBySeller(); $em = $this->getDoctrine()->getEntityManager(); $em->persist($order); $em->flush(); return $this->redirect($this->generateUrl('Order_show', array( 'id' => $order->getNumberForPath() ))); }
[ "public", "function", "mark_ready_for_dispatchAction", "(", "Order", "$", "order", ")", "{", "$", "order", "->", "markReadyForDispatchBySeller", "(", ")", ";", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getEntityManager", "(", ")", ";", "$", "em", "->", "persist", "(", "$", "order", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'Order_show'", ",", "array", "(", "'id'", "=>", "$", "order", "->", "getNumberForPath", "(", ")", ")", ")", ")", ";", "}" ]
mark ready for dispatch @author Tom Haskins-Vaughan <tom@harvestcloud.com> @since 2012-05-14 @Route("/{id}/mark-ready-for-dispatch") @ParamConverter("order", class="HarvestCloudCoreBundle:Order") @param Order $order
[ "mark", "ready", "for", "dispatch" ]
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Controller/Order/DefaultController.php#L194-L205
232
harvestcloud/CoreBundle
Controller/Order/DefaultController.php
DefaultController.mark_as_ready_to_pickupAction
public function mark_as_ready_to_pickupAction(Order $order) { $order->markReadyForPickupFromHub(); $message = \Swift_Message::newInstance() ->setSubject('Your order is ready to be picked up') ->setFrom(array('no-reply@harvestcloud.com' => 'Harvest Cloud')) ->setTo(array('tom@templestreetmedia.com' => 'Tom Haskins-Vaughan')) ->setBody($this->renderView( 'HarvestCloudEmailBundle:Buyer:order_ready_to_pickup.txt.twig', array( 'order' => $order ))) ; $this->get('mailer')->send($message); $em = $this->getDoctrine()->getEntityManager(); $em->persist($order); $em->flush(); return $this->redirect($this->generateUrl('Order_show', array( 'id' => $order->getNumberForPath() ))); }
php
public function mark_as_ready_to_pickupAction(Order $order) { $order->markReadyForPickupFromHub(); $message = \Swift_Message::newInstance() ->setSubject('Your order is ready to be picked up') ->setFrom(array('no-reply@harvestcloud.com' => 'Harvest Cloud')) ->setTo(array('tom@templestreetmedia.com' => 'Tom Haskins-Vaughan')) ->setBody($this->renderView( 'HarvestCloudEmailBundle:Buyer:order_ready_to_pickup.txt.twig', array( 'order' => $order ))) ; $this->get('mailer')->send($message); $em = $this->getDoctrine()->getEntityManager(); $em->persist($order); $em->flush(); return $this->redirect($this->generateUrl('Order_show', array( 'id' => $order->getNumberForPath() ))); }
[ "public", "function", "mark_as_ready_to_pickupAction", "(", "Order", "$", "order", ")", "{", "$", "order", "->", "markReadyForPickupFromHub", "(", ")", ";", "$", "message", "=", "\\", "Swift_Message", "::", "newInstance", "(", ")", "->", "setSubject", "(", "'Your order is ready to be picked up'", ")", "->", "setFrom", "(", "array", "(", "'no-reply@harvestcloud.com'", "=>", "'Harvest Cloud'", ")", ")", "->", "setTo", "(", "array", "(", "'tom@templestreetmedia.com'", "=>", "'Tom Haskins-Vaughan'", ")", ")", "->", "setBody", "(", "$", "this", "->", "renderView", "(", "'HarvestCloudEmailBundle:Buyer:order_ready_to_pickup.txt.twig'", ",", "array", "(", "'order'", "=>", "$", "order", ")", ")", ")", ";", "$", "this", "->", "get", "(", "'mailer'", ")", "->", "send", "(", "$", "message", ")", ";", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getEntityManager", "(", ")", ";", "$", "em", "->", "persist", "(", "$", "order", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'Order_show'", ",", "array", "(", "'id'", "=>", "$", "order", "->", "getNumberForPath", "(", ")", ")", ")", ")", ";", "}" ]
mark as ready to pickup @author Tom Haskins-Vaughan <tom@harvestcloud.com> @since 2012-05-15 @Route("/{id}/mark-as-ready-to-pickup") @ParamConverter("order", class="HarvestCloudCoreBundle:Order") @param Order $order
[ "mark", "as", "ready", "to", "pickup" ]
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Controller/Order/DefaultController.php#L318-L341
233
marando/phpSOFA
src/Marando/IAU/iauAtciqz.php
iauAtciqz.Atciqz
public static function Atciqz($rc, $dc, iauASTROM &$astrom, &$ri, &$di) { $pco = []; $pnat = []; $ppr = []; $pi = []; $w; /* BCRS coordinate direction (unit vector). */ IAU::S2c($rc, $dc, $pco); /* Light deflection by the Sun, giving BCRS natural direction. */ IAU::Ldsun($pco, $astrom->eh, $astrom->em, $pnat); /* Aberration, giving GCRS proper direction. */ IAU::Ab($pnat, $astrom->v, $astrom->em, $astrom->bm1, $ppr); /* Bias-precession-nutation, giving CIRS proper direction. */ IAU::Rxp($astrom->bpn, $ppr, $pi); /* CIRS RA,Dec. */ IAU::C2s($pi, $w, $di); $ri = IAU::Anp($w); /* Finished. */ }
php
public static function Atciqz($rc, $dc, iauASTROM &$astrom, &$ri, &$di) { $pco = []; $pnat = []; $ppr = []; $pi = []; $w; /* BCRS coordinate direction (unit vector). */ IAU::S2c($rc, $dc, $pco); /* Light deflection by the Sun, giving BCRS natural direction. */ IAU::Ldsun($pco, $astrom->eh, $astrom->em, $pnat); /* Aberration, giving GCRS proper direction. */ IAU::Ab($pnat, $astrom->v, $astrom->em, $astrom->bm1, $ppr); /* Bias-precession-nutation, giving CIRS proper direction. */ IAU::Rxp($astrom->bpn, $ppr, $pi); /* CIRS RA,Dec. */ IAU::C2s($pi, $w, $di); $ri = IAU::Anp($w); /* Finished. */ }
[ "public", "static", "function", "Atciqz", "(", "$", "rc", ",", "$", "dc", ",", "iauASTROM", "&", "$", "astrom", ",", "&", "$", "ri", ",", "&", "$", "di", ")", "{", "$", "pco", "=", "[", "]", ";", "$", "pnat", "=", "[", "]", ";", "$", "ppr", "=", "[", "]", ";", "$", "pi", "=", "[", "]", ";", "$", "w", ";", "/* BCRS coordinate direction (unit vector). */", "IAU", "::", "S2c", "(", "$", "rc", ",", "$", "dc", ",", "$", "pco", ")", ";", "/* Light deflection by the Sun, giving BCRS natural direction. */", "IAU", "::", "Ldsun", "(", "$", "pco", ",", "$", "astrom", "->", "eh", ",", "$", "astrom", "->", "em", ",", "$", "pnat", ")", ";", "/* Aberration, giving GCRS proper direction. */", "IAU", "::", "Ab", "(", "$", "pnat", ",", "$", "astrom", "->", "v", ",", "$", "astrom", "->", "em", ",", "$", "astrom", "->", "bm1", ",", "$", "ppr", ")", ";", "/* Bias-precession-nutation, giving CIRS proper direction. */", "IAU", "::", "Rxp", "(", "$", "astrom", "->", "bpn", ",", "$", "ppr", ",", "$", "pi", ")", ";", "/* CIRS RA,Dec. */", "IAU", "::", "C2s", "(", "$", "pi", ",", "$", "w", ",", "$", "di", ")", ";", "$", "ri", "=", "IAU", "::", "Anp", "(", "$", "w", ")", ";", "/* Finished. */", "}" ]
- - - - - - - - - - i a u A t c i q z - - - - - - - - - - Quick ICRS to CIRS transformation, given precomputed star- independent astrometry parameters, and assuming zero parallax and proper motion. Use of this function is appropriate when efficiency is important and where many star positions are to be transformed for one date. The star-independent parameters can be obtained by calling one of the functions iauApci[13], iauApcg[13], iauApco[13] or iauApcs[13]. The corresponding function for the case of non-zero parallax and proper motion is iauAtciq. This function is part of the International Astronomical Union's SOFA (Standards of Fundamental Astronomy) software collection. Status: support function. Given: rc,dc double ICRS astrometric RA,Dec (radians) astrom iauASTROM* star-independent astrometry parameters: pmt double PM time interval (SSB, Julian years) eb double[3] SSB to observer (vector, au) eh double[3] Sun to observer (unit vector) em double distance from Sun to observer (au) v double[3] barycentric observer velocity (vector, c) bm1 double sqrt(1-|v|^2): reciprocal of Lorenz factor bpn double[3][3] bias-precession-nutation matrix along double longitude + s' (radians) xpl double polar motion xp wrt local meridian (radians) ypl double polar motion yp wrt local meridian (radians) sphi double sine of geodetic latitude cphi double cosine of geodetic latitude diurab double magnitude of diurnal aberration vector eral double "local" Earth rotation angle (radians) refa double refraction constant A (radians) refb double refraction constant B (radians) Returned: ri,di double CIRS RA,Dec (radians) Note: All the vectors are with respect to BCRS axes. References: Urban, S. & Seidelmann, P. K. (eds), Explanatory Supplement to the Astronomical Almanac, 3rd ed., University Science Books (2013). Klioner, Sergei A., "A practical relativistic model for micro- arcsecond astrometry in space", Astr. J. 125, 1580-1597 (2003). Called: iauS2c spherical coordinates to unit vector iauLdsun light deflection due to Sun iauAb stellar aberration iauRxp product of r-matrix and p-vector iauC2s p-vector to spherical iauAnp normalize angle into range +/- pi This revision: 2013 October 9 SOFA release 2015-02-09 Copyright (C) 2015 IAU SOFA Board. See notes at end.
[ "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "i", "a", "u", "A", "t", "c", "i", "q", "z", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-" ]
757fa49fe335ae1210eaa7735473fd4388b13f07
https://github.com/marando/phpSOFA/blob/757fa49fe335ae1210eaa7735473fd4388b13f07/src/Marando/IAU/iauAtciqz.php#L79-L103
234
themichaelhall/bluemvc-forms
src/Select.php
Select.addOption
public function addOption(OptionInterface $option): void { $option->setSelected($option->getValue() === $this->value); if ($option->getValue() === '') { $this->hasEmptyOption = true; } $this->options[] = $option; }
php
public function addOption(OptionInterface $option): void { $option->setSelected($option->getValue() === $this->value); if ($option->getValue() === '') { $this->hasEmptyOption = true; } $this->options[] = $option; }
[ "public", "function", "addOption", "(", "OptionInterface", "$", "option", ")", ":", "void", "{", "$", "option", "->", "setSelected", "(", "$", "option", "->", "getValue", "(", ")", "===", "$", "this", "->", "value", ")", ";", "if", "(", "$", "option", "->", "getValue", "(", ")", "===", "''", ")", "{", "$", "this", "->", "hasEmptyOption", "=", "true", ";", "}", "$", "this", "->", "options", "[", "]", "=", "$", "option", ";", "}" ]
Adds on option. @since 1.0.0 @param OptionInterface $option The option.
[ "Adds", "on", "option", "." ]
8f0e29aaf71eba70b50697384b22edaf72f2f45b
https://github.com/themichaelhall/bluemvc-forms/blob/8f0e29aaf71eba70b50697384b22edaf72f2f45b/src/Select.php#L49-L58
235
villermen/data-handling
src/DataHandling.php
DataHandling.sanitizeUrl
public static function sanitizeUrl($url) { $url = trim($url); if (!$url) { return null; } if (!preg_match("/^https?:\/\//i", $url)) { $url = "http://" . $url; } return self::sanitizeString($url); }
php
public static function sanitizeUrl($url) { $url = trim($url); if (!$url) { return null; } if (!preg_match("/^https?:\/\//i", $url)) { $url = "http://" . $url; } return self::sanitizeString($url); }
[ "public", "static", "function", "sanitizeUrl", "(", "$", "url", ")", "{", "$", "url", "=", "trim", "(", "$", "url", ")", ";", "if", "(", "!", "$", "url", ")", "{", "return", "null", ";", "}", "if", "(", "!", "preg_match", "(", "\"/^https?:\\/\\//i\"", ",", "$", "url", ")", ")", "{", "$", "url", "=", "\"http://\"", ".", "$", "url", ";", "}", "return", "self", "::", "sanitizeString", "(", "$", "url", ")", ";", "}" ]
Prefixes the url with a protocol if it has none, to prevent local lookups. @param string $url @return string|null
[ "Prefixes", "the", "url", "with", "a", "protocol", "if", "it", "has", "none", "to", "prevent", "local", "lookups", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L40-L53
236
villermen/data-handling
src/DataHandling.php
DataHandling.sanitizeText
public static function sanitizeText($text) { if (!$text) { return null; } $allowedTagNames = [ "b", "strong", "i", "em", "br" ]; $marker = "\&8slkc7\\"; // Create a one-to-one conversion array for easy replacing $allowedTagConversion = []; foreach($allowedTagNames as $allowedTagName) { $allowedTagConversion["<{$allowedTagName}>"] = "{$marker}{$allowedTagName}{$marker}"; $allowedTagConversion["<{$allowedTagName}/>"] = "{$marker}{$allowedTagName}/{$marker}"; $allowedTagConversion["<{$allowedTagName} />"] = "{$marker}{$allowedTagName} /{$marker}"; $allowedTagConversion["</{$allowedTagName}>"] = "{$marker}/{$allowedTagName}{$marker}"; } // Convert to BB-like tags before sanitizing and then revert $text = str_ireplace(array_keys($allowedTagConversion), array_values($allowedTagConversion), $text); $text = self::sanitizeString($text); if (!$text) { return null; } return str_ireplace(array_values($allowedTagConversion), array_keys($allowedTagConversion), $text); }
php
public static function sanitizeText($text) { if (!$text) { return null; } $allowedTagNames = [ "b", "strong", "i", "em", "br" ]; $marker = "\&8slkc7\\"; // Create a one-to-one conversion array for easy replacing $allowedTagConversion = []; foreach($allowedTagNames as $allowedTagName) { $allowedTagConversion["<{$allowedTagName}>"] = "{$marker}{$allowedTagName}{$marker}"; $allowedTagConversion["<{$allowedTagName}/>"] = "{$marker}{$allowedTagName}/{$marker}"; $allowedTagConversion["<{$allowedTagName} />"] = "{$marker}{$allowedTagName} /{$marker}"; $allowedTagConversion["</{$allowedTagName}>"] = "{$marker}/{$allowedTagName}{$marker}"; } // Convert to BB-like tags before sanitizing and then revert $text = str_ireplace(array_keys($allowedTagConversion), array_values($allowedTagConversion), $text); $text = self::sanitizeString($text); if (!$text) { return null; } return str_ireplace(array_values($allowedTagConversion), array_keys($allowedTagConversion), $text); }
[ "public", "static", "function", "sanitizeText", "(", "$", "text", ")", "{", "if", "(", "!", "$", "text", ")", "{", "return", "null", ";", "}", "$", "allowedTagNames", "=", "[", "\"b\"", ",", "\"strong\"", ",", "\"i\"", ",", "\"em\"", ",", "\"br\"", "]", ";", "$", "marker", "=", "\"\\&8slkc7\\\\\"", ";", "// Create a one-to-one conversion array for easy replacing", "$", "allowedTagConversion", "=", "[", "]", ";", "foreach", "(", "$", "allowedTagNames", "as", "$", "allowedTagName", ")", "{", "$", "allowedTagConversion", "[", "\"<{$allowedTagName}>\"", "]", "=", "\"{$marker}{$allowedTagName}{$marker}\"", ";", "$", "allowedTagConversion", "[", "\"<{$allowedTagName}/>\"", "]", "=", "\"{$marker}{$allowedTagName}/{$marker}\"", ";", "$", "allowedTagConversion", "[", "\"<{$allowedTagName} />\"", "]", "=", "\"{$marker}{$allowedTagName} /{$marker}\"", ";", "$", "allowedTagConversion", "[", "\"</{$allowedTagName}>\"", "]", "=", "\"{$marker}/{$allowedTagName}{$marker}\"", ";", "}", "// Convert to BB-like tags before sanitizing and then revert", "$", "text", "=", "str_ireplace", "(", "array_keys", "(", "$", "allowedTagConversion", ")", ",", "array_values", "(", "$", "allowedTagConversion", ")", ",", "$", "text", ")", ";", "$", "text", "=", "self", "::", "sanitizeString", "(", "$", "text", ")", ";", "if", "(", "!", "$", "text", ")", "{", "return", "null", ";", "}", "return", "str_ireplace", "(", "array_values", "(", "$", "allowedTagConversion", ")", ",", "array_keys", "(", "$", "allowedTagConversion", ")", ",", "$", "text", ")", ";", "}" ]
Same as sanitizeString but allows linebreaks and strong and italic text. @param $text @return string|null
[ "Same", "as", "sanitizeString", "but", "allows", "linebreaks", "and", "strong", "and", "italic", "text", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L61-L90
237
villermen/data-handling
src/DataHandling.php
DataHandling.sanitizeString
public static function sanitizeString($string) { if (!$string) { return null; } // Remove linebreaks and HTML tags $string = str_ireplace(["\r\n", "\n", "\r"], " ", $string); $string = html_entity_decode($string, ENT_NOQUOTES, "UTF-8"); $string = trim(strip_tags($string)); if (!$string) { return null; } return (string)$string; }
php
public static function sanitizeString($string) { if (!$string) { return null; } // Remove linebreaks and HTML tags $string = str_ireplace(["\r\n", "\n", "\r"], " ", $string); $string = html_entity_decode($string, ENT_NOQUOTES, "UTF-8"); $string = trim(strip_tags($string)); if (!$string) { return null; } return (string)$string; }
[ "public", "static", "function", "sanitizeString", "(", "$", "string", ")", "{", "if", "(", "!", "$", "string", ")", "{", "return", "null", ";", "}", "// Remove linebreaks and HTML tags", "$", "string", "=", "str_ireplace", "(", "[", "\"\\r\\n\"", ",", "\"\\n\"", ",", "\"\\r\"", "]", ",", "\" \"", ",", "$", "string", ")", ";", "$", "string", "=", "html_entity_decode", "(", "$", "string", ",", "ENT_NOQUOTES", ",", "\"UTF-8\"", ")", ";", "$", "string", "=", "trim", "(", "strip_tags", "(", "$", "string", ")", ")", ";", "if", "(", "!", "$", "string", ")", "{", "return", "null", ";", "}", "return", "(", "string", ")", "$", "string", ";", "}" ]
Trims string, removes tags and linebreaks. Returns null if string equals false, before or after conversion. @param $string @return string|null
[ "Trims", "string", "removes", "tags", "and", "linebreaks", ".", "Returns", "null", "if", "string", "equals", "false", "before", "or", "after", "conversion", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L99-L115
238
villermen/data-handling
src/DataHandling.php
DataHandling.sanitizeUrlParts
public static function sanitizeUrlParts($urlPartOrUrlParts, ...$additionalUrlParts) { if (is_array($urlPartOrUrlParts)) { $urlParts = $urlPartOrUrlParts; } else { $urlParts = array_merge([$urlPartOrUrlParts], $additionalUrlParts); } $sanitizedUrlParts = []; foreach ($urlParts as $urlPart) { $urlPart = self::sanitizeString($urlPart); // Replace accented characters for their regular counterparts $urlPart = str_replace(array_keys(self::ACCENTED_CHARACTERS), array_values(self::ACCENTED_CHARACTERS), $urlPart); // Collapse spaces, dashes and underscores into single dashes $urlPart = preg_replace("/[\s-_]+/", "-", $urlPart); $urlPart = strtolower($urlPart); // Remove any leftover invalid characters $urlPart = preg_replace("/[^a-z0-9\\-\\.]/", "", $urlPart); // Trim possibly existing dashes at start and end of string $urlPart = trim($urlPart, "-"); $sanitizedUrlParts[] = $urlPart; } return implode("/", $sanitizedUrlParts); }
php
public static function sanitizeUrlParts($urlPartOrUrlParts, ...$additionalUrlParts) { if (is_array($urlPartOrUrlParts)) { $urlParts = $urlPartOrUrlParts; } else { $urlParts = array_merge([$urlPartOrUrlParts], $additionalUrlParts); } $sanitizedUrlParts = []; foreach ($urlParts as $urlPart) { $urlPart = self::sanitizeString($urlPart); // Replace accented characters for their regular counterparts $urlPart = str_replace(array_keys(self::ACCENTED_CHARACTERS), array_values(self::ACCENTED_CHARACTERS), $urlPart); // Collapse spaces, dashes and underscores into single dashes $urlPart = preg_replace("/[\s-_]+/", "-", $urlPart); $urlPart = strtolower($urlPart); // Remove any leftover invalid characters $urlPart = preg_replace("/[^a-z0-9\\-\\.]/", "", $urlPart); // Trim possibly existing dashes at start and end of string $urlPart = trim($urlPart, "-"); $sanitizedUrlParts[] = $urlPart; } return implode("/", $sanitizedUrlParts); }
[ "public", "static", "function", "sanitizeUrlParts", "(", "$", "urlPartOrUrlParts", ",", "...", "$", "additionalUrlParts", ")", "{", "if", "(", "is_array", "(", "$", "urlPartOrUrlParts", ")", ")", "{", "$", "urlParts", "=", "$", "urlPartOrUrlParts", ";", "}", "else", "{", "$", "urlParts", "=", "array_merge", "(", "[", "$", "urlPartOrUrlParts", "]", ",", "$", "additionalUrlParts", ")", ";", "}", "$", "sanitizedUrlParts", "=", "[", "]", ";", "foreach", "(", "$", "urlParts", "as", "$", "urlPart", ")", "{", "$", "urlPart", "=", "self", "::", "sanitizeString", "(", "$", "urlPart", ")", ";", "// Replace accented characters for their regular counterparts", "$", "urlPart", "=", "str_replace", "(", "array_keys", "(", "self", "::", "ACCENTED_CHARACTERS", ")", ",", "array_values", "(", "self", "::", "ACCENTED_CHARACTERS", ")", ",", "$", "urlPart", ")", ";", "// Collapse spaces, dashes and underscores into single dashes", "$", "urlPart", "=", "preg_replace", "(", "\"/[\\s-_]+/\"", ",", "\"-\"", ",", "$", "urlPart", ")", ";", "$", "urlPart", "=", "strtolower", "(", "$", "urlPart", ")", ";", "// Remove any leftover invalid characters", "$", "urlPart", "=", "preg_replace", "(", "\"/[^a-z0-9\\\\-\\\\.]/\"", ",", "\"\"", ",", "$", "urlPart", ")", ";", "// Trim possibly existing dashes at start and end of string", "$", "urlPart", "=", "trim", "(", "$", "urlPart", ",", "\"-\"", ")", ";", "$", "sanitizedUrlParts", "[", "]", "=", "$", "urlPart", ";", "}", "return", "implode", "(", "\"/\"", ",", "$", "sanitizedUrlParts", ")", ";", "}" ]
Sanitize, or SEOify url part. Will result in a string with only dashes, dots and alphanumeric characters. Arguments are joined by slashes. If an array of parts is given as the first argument, each one will be processed and returned as one string with slashes between parts. @param string|string[] $urlPartOrUrlParts An array of parts or a single part. @param string[] $additionalUrlParts Additional url parts, if the first argument is not an array. @return string
[ "Sanitize", "or", "SEOify", "url", "part", ".", "Will", "result", "in", "a", "string", "with", "only", "dashes", "dots", "and", "alphanumeric", "characters", ".", "Arguments", "are", "joined", "by", "slashes", ".", "If", "an", "array", "of", "parts", "is", "given", "as", "the", "first", "argument", "each", "one", "will", "be", "processed", "and", "returned", "as", "one", "string", "with", "slashes", "between", "parts", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L168-L198
239
villermen/data-handling
src/DataHandling.php
DataHandling.explode
public static function explode($string, $characters = ";>|/\\<") { $string = self::sanitizeString($string); if ($string === null) { return []; } // Convert characters into a safe regular expression $splitRegex = ""; for ($i = 0; $i < strlen($characters); $i++) { $splitRegex .= "\\" . $characters[$i]; } $splitRegex = "/[" . $splitRegex . "]/"; $rawElements = preg_split($splitRegex, $string); $elements = []; foreach($rawElements as $rawElement) { $element = self::sanitizeString($rawElement); if ($element !== null) { $elements[] = $element; } } return $elements; }
php
public static function explode($string, $characters = ";>|/\\<") { $string = self::sanitizeString($string); if ($string === null) { return []; } // Convert characters into a safe regular expression $splitRegex = ""; for ($i = 0; $i < strlen($characters); $i++) { $splitRegex .= "\\" . $characters[$i]; } $splitRegex = "/[" . $splitRegex . "]/"; $rawElements = preg_split($splitRegex, $string); $elements = []; foreach($rawElements as $rawElement) { $element = self::sanitizeString($rawElement); if ($element !== null) { $elements[] = $element; } } return $elements; }
[ "public", "static", "function", "explode", "(", "$", "string", ",", "$", "characters", "=", "\";>|/\\\\<\"", ")", "{", "$", "string", "=", "self", "::", "sanitizeString", "(", "$", "string", ")", ";", "if", "(", "$", "string", "===", "null", ")", "{", "return", "[", "]", ";", "}", "// Convert characters into a safe regular expression", "$", "splitRegex", "=", "\"\"", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "characters", ")", ";", "$", "i", "++", ")", "{", "$", "splitRegex", ".=", "\"\\\\\"", ".", "$", "characters", "[", "$", "i", "]", ";", "}", "$", "splitRegex", "=", "\"/[\"", ".", "$", "splitRegex", ".", "\"]/\"", ";", "$", "rawElements", "=", "preg_split", "(", "$", "splitRegex", ",", "$", "string", ")", ";", "$", "elements", "=", "[", "]", ";", "foreach", "(", "$", "rawElements", "as", "$", "rawElement", ")", "{", "$", "element", "=", "self", "::", "sanitizeString", "(", "$", "rawElement", ")", ";", "if", "(", "$", "element", "!==", "null", ")", "{", "$", "elements", "[", "]", "=", "$", "element", ";", "}", "}", "return", "$", "elements", ";", "}" ]
Explodes a string into an array after performing sanitization on each element. @param string $string @param string $characters @return string[]
[ "Explodes", "a", "string", "into", "an", "array", "after", "performing", "sanitization", "on", "each", "element", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L323-L349
240
villermen/data-handling
src/DataHandling.php
DataHandling.implode
public static function implode($array, $separator = " > ") { if ($array === null) { return ""; } $elements = []; foreach($array as $rawElement) { $element = self::sanitizeString($rawElement); if ($element !== null) { $elements[] = $element; } } return implode($separator, $elements); }
php
public static function implode($array, $separator = " > ") { if ($array === null) { return ""; } $elements = []; foreach($array as $rawElement) { $element = self::sanitizeString($rawElement); if ($element !== null) { $elements[] = $element; } } return implode($separator, $elements); }
[ "public", "static", "function", "implode", "(", "$", "array", ",", "$", "separator", "=", "\" > \"", ")", "{", "if", "(", "$", "array", "===", "null", ")", "{", "return", "\"\"", ";", "}", "$", "elements", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "rawElement", ")", "{", "$", "element", "=", "self", "::", "sanitizeString", "(", "$", "rawElement", ")", ";", "if", "(", "$", "element", "!==", "null", ")", "{", "$", "elements", "[", "]", "=", "$", "element", ";", "}", "}", "return", "implode", "(", "$", "separator", ",", "$", "elements", ")", ";", "}" ]
Implodes an array into a string after performing sanitization on each element. @param string[] $array @param string $separator @return string
[ "Implodes", "an", "array", "into", "a", "string", "after", "performing", "sanitization", "on", "each", "element", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L358-L374
241
villermen/data-handling
src/DataHandling.php
DataHandling.startsWith
public static function startsWith($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, false, false, false); }
php
public static function startsWith($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, false, false, false); }
[ "public", "static", "function", "startsWith", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ")", "{", "return", "self", "::", "startsWithInternal", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ",", "false", ",", "false", ",", "false", ")", ";", "}" ]
Returns whether the value of the given strings start with any of the supplied options. @param string|string[] $stringOrStrings @param string|string[] $optionOrOptions @return bool
[ "Returns", "whether", "the", "value", "of", "the", "given", "strings", "start", "with", "any", "of", "the", "supplied", "options", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L383-L386
242
villermen/data-handling
src/DataHandling.php
DataHandling.endsWith
public static function endsWith($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, true, false, false); }
php
public static function endsWith($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, true, false, false); }
[ "public", "static", "function", "endsWith", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ")", "{", "return", "self", "::", "startsWithInternal", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ",", "true", ",", "false", ",", "false", ")", ";", "}" ]
Returns whether the value of the given strings end with any of the supplied options. @param string|string[] $stringOrStrings @param string|string[] $optionOrOptions @return bool
[ "Returns", "whether", "the", "value", "of", "the", "given", "strings", "end", "with", "any", "of", "the", "supplied", "options", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L395-L398
243
villermen/data-handling
src/DataHandling.php
DataHandling.startsWithInsensitive
public static function startsWithInsensitive($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, false, false, true); }
php
public static function startsWithInsensitive($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, false, false, true); }
[ "public", "static", "function", "startsWithInsensitive", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ")", "{", "return", "self", "::", "startsWithInternal", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ",", "false", ",", "false", ",", "true", ")", ";", "}" ]
Returns whether the case insensitive value of the given strings start with any of the supplied options. @param string|string[] $stringOrStrings @param string|string[] $optionOrOptions @return bool
[ "Returns", "whether", "the", "case", "insensitive", "value", "of", "the", "given", "strings", "start", "with", "any", "of", "the", "supplied", "options", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L407-L410
244
villermen/data-handling
src/DataHandling.php
DataHandling.endsWithInsensitive
public static function endsWithInsensitive($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, true, false, true); }
php
public static function endsWithInsensitive($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, true, false, true); }
[ "public", "static", "function", "endsWithInsensitive", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ")", "{", "return", "self", "::", "startsWithInternal", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ",", "true", ",", "false", ",", "true", ")", ";", "}" ]
Returns whether the case insensitive value of the given string ends with any of the supplied options. @param string|string[] $stringOrStrings @param string|string[] $optionOrOptions @return bool
[ "Returns", "whether", "the", "case", "insensitive", "value", "of", "the", "given", "string", "ends", "with", "any", "of", "the", "supplied", "options", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L419-L422
245
villermen/data-handling
src/DataHandling.php
DataHandling.startsWithAlphanumeric
public static function startsWithAlphanumeric($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, false, true, false); }
php
public static function startsWithAlphanumeric($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, false, true, false); }
[ "public", "static", "function", "startsWithAlphanumeric", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ")", "{", "return", "self", "::", "startsWithInternal", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ",", "false", ",", "true", ",", "false", ")", ";", "}" ]
Returns whether the alphanumeric value of the given strings start with any of the supplied options. @param string|string[] $stringOrStrings @param string|string[] $optionOrOptions A string depicting a first @return bool
[ "Returns", "whether", "the", "alphanumeric", "value", "of", "the", "given", "strings", "start", "with", "any", "of", "the", "supplied", "options", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L431-L434
246
villermen/data-handling
src/DataHandling.php
DataHandling.endsWithAlphanumeric
public static function endsWithAlphanumeric($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, true, true, false); }
php
public static function endsWithAlphanumeric($stringOrStrings, $optionOrOptions) { return self::startsWithInternal($stringOrStrings, $optionOrOptions, true, true, false); }
[ "public", "static", "function", "endsWithAlphanumeric", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ")", "{", "return", "self", "::", "startsWithInternal", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ",", "true", ",", "true", ",", "false", ")", ";", "}" ]
Returns whether the alphanumeric value of the given strings end with any of the supplied options. @param string|string[] $stringOrStrings @param string|string[] $optionOrOptions @return bool
[ "Returns", "whether", "the", "alphanumeric", "value", "of", "the", "given", "strings", "end", "with", "any", "of", "the", "supplied", "options", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L443-L446
247
villermen/data-handling
src/DataHandling.php
DataHandling.startsWithInternal
private static function startsWithInternal($stringOrStrings, $optionOrOptions, $matchEnd, $alphanumeric, $caseInsensitive) { $strings = is_array($stringOrStrings) ? $stringOrStrings : [$stringOrStrings]; $options = is_array($optionOrOptions) ? $optionOrOptions : [$optionOrOptions]; foreach($strings as $string) { $stringMatched = false; if ($alphanumeric) { $string = self::sanitizeAlphanumeric($string); } foreach($options as $option) { if ($alphanumeric) { $option = self::sanitizeAlphanumeric($option); } if (strlen($option) <= strlen($string) && substr_compare($string, $option, $matchEnd ? -strlen($option) : 0, strlen($option), $caseInsensitive) === 0) { $stringMatched = true; break; } } if (!$stringMatched) { return false; } } return true; }
php
private static function startsWithInternal($stringOrStrings, $optionOrOptions, $matchEnd, $alphanumeric, $caseInsensitive) { $strings = is_array($stringOrStrings) ? $stringOrStrings : [$stringOrStrings]; $options = is_array($optionOrOptions) ? $optionOrOptions : [$optionOrOptions]; foreach($strings as $string) { $stringMatched = false; if ($alphanumeric) { $string = self::sanitizeAlphanumeric($string); } foreach($options as $option) { if ($alphanumeric) { $option = self::sanitizeAlphanumeric($option); } if (strlen($option) <= strlen($string) && substr_compare($string, $option, $matchEnd ? -strlen($option) : 0, strlen($option), $caseInsensitive) === 0) { $stringMatched = true; break; } } if (!$stringMatched) { return false; } } return true; }
[ "private", "static", "function", "startsWithInternal", "(", "$", "stringOrStrings", ",", "$", "optionOrOptions", ",", "$", "matchEnd", ",", "$", "alphanumeric", ",", "$", "caseInsensitive", ")", "{", "$", "strings", "=", "is_array", "(", "$", "stringOrStrings", ")", "?", "$", "stringOrStrings", ":", "[", "$", "stringOrStrings", "]", ";", "$", "options", "=", "is_array", "(", "$", "optionOrOptions", ")", "?", "$", "optionOrOptions", ":", "[", "$", "optionOrOptions", "]", ";", "foreach", "(", "$", "strings", "as", "$", "string", ")", "{", "$", "stringMatched", "=", "false", ";", "if", "(", "$", "alphanumeric", ")", "{", "$", "string", "=", "self", "::", "sanitizeAlphanumeric", "(", "$", "string", ")", ";", "}", "foreach", "(", "$", "options", "as", "$", "option", ")", "{", "if", "(", "$", "alphanumeric", ")", "{", "$", "option", "=", "self", "::", "sanitizeAlphanumeric", "(", "$", "option", ")", ";", "}", "if", "(", "strlen", "(", "$", "option", ")", "<=", "strlen", "(", "$", "string", ")", "&&", "substr_compare", "(", "$", "string", ",", "$", "option", ",", "$", "matchEnd", "?", "-", "strlen", "(", "$", "option", ")", ":", "0", ",", "strlen", "(", "$", "option", ")", ",", "$", "caseInsensitive", ")", "===", "0", ")", "{", "$", "stringMatched", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "stringMatched", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Internal method used by all startsWith and endsWith methods to keep code in one place. @param string|string[] $stringOrStrings @param string|string[] $optionOrOptions @param bool $matchEnd @param bool $alphanumeric @param bool $caseInsensitive @return bool
[ "Internal", "method", "used", "by", "all", "startsWith", "and", "endsWith", "methods", "to", "keep", "code", "in", "one", "place", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L458-L488
248
villermen/data-handling
src/DataHandling.php
DataHandling.encodeUri
public static function encodeUri($uri) { $uri = self::removeSchemeFromUri($uri, $scheme); $uri = rawurlencode($uri); // Decode slashes $uri = str_replace("%2F", "/", $uri); return $scheme . $uri; }
php
public static function encodeUri($uri) { $uri = self::removeSchemeFromUri($uri, $scheme); $uri = rawurlencode($uri); // Decode slashes $uri = str_replace("%2F", "/", $uri); return $scheme . $uri; }
[ "public", "static", "function", "encodeUri", "(", "$", "uri", ")", "{", "$", "uri", "=", "self", "::", "removeSchemeFromUri", "(", "$", "uri", ",", "$", "scheme", ")", ";", "$", "uri", "=", "rawurlencode", "(", "$", "uri", ")", ";", "// Decode slashes", "$", "uri", "=", "str_replace", "(", "\"%2F\"", ",", "\"/\"", ",", "$", "uri", ")", ";", "return", "$", "scheme", ".", "$", "uri", ";", "}" ]
Encodes a full URI, leaving the slashes and scheme intact. @param string $uri @return string
[ "Encodes", "a", "full", "URI", "leaving", "the", "slashes", "and", "scheme", "intact", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L513-L522
249
villermen/data-handling
src/DataHandling.php
DataHandling.formatPath
public static function formatPath($pathOrPaths, ...$additionalPaths) { $path = rawurldecode(self::mergePaths($pathOrPaths, ...$additionalPaths)); $path = self::removeSchemeFromUri($path, $scheme); // Remove self-referencing path parts (resolving already takes care of this) $replacements = 0; do { $path = str_replace(["/./", "//"], "/", $path, $replacements); } while ($replacements > 0); // Replace parent directory paths if possible $pathParts = explode("/", $path); $ignoredParts = 0; do { $parentKey = array_search("..", array_slice($pathParts, $ignoredParts, null, true)); // Don't remove .. if it starts the path if ($parentKey > 0) { switch ($pathParts[$parentKey - 1]) { // Don't remove root / but remove ..'s directly after it case "": unset($pathParts[$parentKey]); break; // Keep consecutive ..'s (only possible if the path starts with them) case "..": $ignoredParts++; break; // Collapse default: unset($pathParts[$parentKey - 1]); unset($pathParts[$parentKey]); break; } $pathParts = array_values($pathParts); } else { $ignoredParts++; } } while ($parentKey !== false); $path = implode("/", $pathParts); return $scheme . $path; }
php
public static function formatPath($pathOrPaths, ...$additionalPaths) { $path = rawurldecode(self::mergePaths($pathOrPaths, ...$additionalPaths)); $path = self::removeSchemeFromUri($path, $scheme); // Remove self-referencing path parts (resolving already takes care of this) $replacements = 0; do { $path = str_replace(["/./", "//"], "/", $path, $replacements); } while ($replacements > 0); // Replace parent directory paths if possible $pathParts = explode("/", $path); $ignoredParts = 0; do { $parentKey = array_search("..", array_slice($pathParts, $ignoredParts, null, true)); // Don't remove .. if it starts the path if ($parentKey > 0) { switch ($pathParts[$parentKey - 1]) { // Don't remove root / but remove ..'s directly after it case "": unset($pathParts[$parentKey]); break; // Keep consecutive ..'s (only possible if the path starts with them) case "..": $ignoredParts++; break; // Collapse default: unset($pathParts[$parentKey - 1]); unset($pathParts[$parentKey]); break; } $pathParts = array_values($pathParts); } else { $ignoredParts++; } } while ($parentKey !== false); $path = implode("/", $pathParts); return $scheme . $path; }
[ "public", "static", "function", "formatPath", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", "{", "$", "path", "=", "rawurldecode", "(", "self", "::", "mergePaths", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", ")", ";", "$", "path", "=", "self", "::", "removeSchemeFromUri", "(", "$", "path", ",", "$", "scheme", ")", ";", "// Remove self-referencing path parts (resolving already takes care of this)", "$", "replacements", "=", "0", ";", "do", "{", "$", "path", "=", "str_replace", "(", "[", "\"/./\"", ",", "\"//\"", "]", ",", "\"/\"", ",", "$", "path", ",", "$", "replacements", ")", ";", "}", "while", "(", "$", "replacements", ">", "0", ")", ";", "// Replace parent directory paths if possible", "$", "pathParts", "=", "explode", "(", "\"/\"", ",", "$", "path", ")", ";", "$", "ignoredParts", "=", "0", ";", "do", "{", "$", "parentKey", "=", "array_search", "(", "\"..\"", ",", "array_slice", "(", "$", "pathParts", ",", "$", "ignoredParts", ",", "null", ",", "true", ")", ")", ";", "// Don't remove .. if it starts the path", "if", "(", "$", "parentKey", ">", "0", ")", "{", "switch", "(", "$", "pathParts", "[", "$", "parentKey", "-", "1", "]", ")", "{", "// Don't remove root / but remove ..'s directly after it", "case", "\"\"", ":", "unset", "(", "$", "pathParts", "[", "$", "parentKey", "]", ")", ";", "break", ";", "// Keep consecutive ..'s (only possible if the path starts with them)", "case", "\"..\"", ":", "$", "ignoredParts", "++", ";", "break", ";", "// Collapse", "default", ":", "unset", "(", "$", "pathParts", "[", "$", "parentKey", "-", "1", "]", ")", ";", "unset", "(", "$", "pathParts", "[", "$", "parentKey", "]", ")", ";", "break", ";", "}", "$", "pathParts", "=", "array_values", "(", "$", "pathParts", ")", ";", "}", "else", "{", "$", "ignoredParts", "++", ";", "}", "}", "while", "(", "$", "parentKey", "!==", "false", ")", ";", "$", "path", "=", "implode", "(", "\"/\"", ",", "$", "pathParts", ")", ";", "return", "$", "scheme", ".", "$", "path", ";", "}" ]
Formats a file path to a uniform representation. Multiple paths can be given and will be concatenated. @param string|string[] $pathOrPaths @param string[] $additionalPaths @return string
[ "Formats", "a", "file", "path", "to", "a", "uniform", "representation", ".", "Multiple", "paths", "can", "be", "given", "and", "will", "be", "concatenated", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L532-L579
250
villermen/data-handling
src/DataHandling.php
DataHandling.formatAndResolvePath
public static function formatAndResolvePath($pathOrPaths, ...$additionalPaths) { $path = rawurldecode(self::mergePaths($pathOrPaths, ...$additionalPaths)); $path = realpath($path); if (!$path) { throw new DataHandlingException("Given path does not exist."); } return self::formatPath($path); }
php
public static function formatAndResolvePath($pathOrPaths, ...$additionalPaths) { $path = rawurldecode(self::mergePaths($pathOrPaths, ...$additionalPaths)); $path = realpath($path); if (!$path) { throw new DataHandlingException("Given path does not exist."); } return self::formatPath($path); }
[ "public", "static", "function", "formatAndResolvePath", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", "{", "$", "path", "=", "rawurldecode", "(", "self", "::", "mergePaths", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", ")", ";", "$", "path", "=", "realpath", "(", "$", "path", ")", ";", "if", "(", "!", "$", "path", ")", "{", "throw", "new", "DataHandlingException", "(", "\"Given path does not exist.\"", ")", ";", "}", "return", "self", "::", "formatPath", "(", "$", "path", ")", ";", "}" ]
Resolves and formats a path. @param string|string[] $pathOrPaths @param string[] $additionalPaths @return string @throws DataHandlingException
[ "Resolves", "and", "formats", "a", "path", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L589-L599
251
villermen/data-handling
src/DataHandling.php
DataHandling.mergePaths
public static function mergePaths($pathOrPaths, ...$additionalPaths) { if (is_array($pathOrPaths)) { $paths = $pathOrPaths; } else { $paths = array_merge([$pathOrPaths], $additionalPaths); } $paths = array_values($paths); $prefix = ""; $suffix = ""; if (count($paths) > 0) { // Save root for first path if (self::startsWith($paths[0], ["/", "\\"])) { $prefix = "/"; } // Save separator for last path if (self::endsWith($paths[count($paths) - 1], ["/", "\\"])) { $suffix = "/"; } } // Remove leading and trailing separators from parts to not end up with repeated separators (or root by non-first argument and empty root) array_walk($paths, function(&$path) { $path = str_replace("\\", "/", $path); $path = trim($path, "/"); }); // Remove empty parts to not end up with repeated separators $paths = array_filter($paths); $path = implode("/", $paths); // Only add suffix if there is a path, to prevent suffix from making root if ($path) { $path .= $suffix; } return $prefix . $path; }
php
public static function mergePaths($pathOrPaths, ...$additionalPaths) { if (is_array($pathOrPaths)) { $paths = $pathOrPaths; } else { $paths = array_merge([$pathOrPaths], $additionalPaths); } $paths = array_values($paths); $prefix = ""; $suffix = ""; if (count($paths) > 0) { // Save root for first path if (self::startsWith($paths[0], ["/", "\\"])) { $prefix = "/"; } // Save separator for last path if (self::endsWith($paths[count($paths) - 1], ["/", "\\"])) { $suffix = "/"; } } // Remove leading and trailing separators from parts to not end up with repeated separators (or root by non-first argument and empty root) array_walk($paths, function(&$path) { $path = str_replace("\\", "/", $path); $path = trim($path, "/"); }); // Remove empty parts to not end up with repeated separators $paths = array_filter($paths); $path = implode("/", $paths); // Only add suffix if there is a path, to prevent suffix from making root if ($path) { $path .= $suffix; } return $prefix . $path; }
[ "public", "static", "function", "mergePaths", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", "{", "if", "(", "is_array", "(", "$", "pathOrPaths", ")", ")", "{", "$", "paths", "=", "$", "pathOrPaths", ";", "}", "else", "{", "$", "paths", "=", "array_merge", "(", "[", "$", "pathOrPaths", "]", ",", "$", "additionalPaths", ")", ";", "}", "$", "paths", "=", "array_values", "(", "$", "paths", ")", ";", "$", "prefix", "=", "\"\"", ";", "$", "suffix", "=", "\"\"", ";", "if", "(", "count", "(", "$", "paths", ")", ">", "0", ")", "{", "// Save root for first path", "if", "(", "self", "::", "startsWith", "(", "$", "paths", "[", "0", "]", ",", "[", "\"/\"", ",", "\"\\\\\"", "]", ")", ")", "{", "$", "prefix", "=", "\"/\"", ";", "}", "// Save separator for last path", "if", "(", "self", "::", "endsWith", "(", "$", "paths", "[", "count", "(", "$", "paths", ")", "-", "1", "]", ",", "[", "\"/\"", ",", "\"\\\\\"", "]", ")", ")", "{", "$", "suffix", "=", "\"/\"", ";", "}", "}", "// Remove leading and trailing separators from parts to not end up with repeated separators (or root by non-first argument and empty root)", "array_walk", "(", "$", "paths", ",", "function", "(", "&", "$", "path", ")", "{", "$", "path", "=", "str_replace", "(", "\"\\\\\"", ",", "\"/\"", ",", "$", "path", ")", ";", "$", "path", "=", "trim", "(", "$", "path", ",", "\"/\"", ")", ";", "}", ")", ";", "// Remove empty parts to not end up with repeated separators", "$", "paths", "=", "array_filter", "(", "$", "paths", ")", ";", "$", "path", "=", "implode", "(", "\"/\"", ",", "$", "paths", ")", ";", "// Only add suffix if there is a path, to prevent suffix from making root", "if", "(", "$", "path", ")", "{", "$", "path", ".=", "$", "suffix", ";", "}", "return", "$", "prefix", ".", "$", "path", ";", "}" ]
Merges path parts into one path. Only the first argument can cause the path to become absolute. @param string|string[] $pathOrPaths @param string[] $additionalPaths @return string
[ "Merges", "path", "parts", "into", "one", "path", ".", "Only", "the", "first", "argument", "can", "cause", "the", "path", "to", "become", "absolute", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L609-L650
252
villermen/data-handling
src/DataHandling.php
DataHandling.makePathRelative
public static function makePathRelative($path, $rootDirectory) { $rootDirectory = self::formatDirectory($rootDirectory); $path = self::formatPath($path); if (!self::startsWith(self::formatDirectory($path), $rootDirectory)) { throw new DataHandlingException("Path is not part of the given root directory."); } return substr_replace($path, "", 0, strlen($rootDirectory)); }
php
public static function makePathRelative($path, $rootDirectory) { $rootDirectory = self::formatDirectory($rootDirectory); $path = self::formatPath($path); if (!self::startsWith(self::formatDirectory($path), $rootDirectory)) { throw new DataHandlingException("Path is not part of the given root directory."); } return substr_replace($path, "", 0, strlen($rootDirectory)); }
[ "public", "static", "function", "makePathRelative", "(", "$", "path", ",", "$", "rootDirectory", ")", "{", "$", "rootDirectory", "=", "self", "::", "formatDirectory", "(", "$", "rootDirectory", ")", ";", "$", "path", "=", "self", "::", "formatPath", "(", "$", "path", ")", ";", "if", "(", "!", "self", "::", "startsWith", "(", "self", "::", "formatDirectory", "(", "$", "path", ")", ",", "$", "rootDirectory", ")", ")", "{", "throw", "new", "DataHandlingException", "(", "\"Path is not part of the given root directory.\"", ")", ";", "}", "return", "substr_replace", "(", "$", "path", ",", "\"\"", ",", "0", ",", "strlen", "(", "$", "rootDirectory", ")", ")", ";", "}" ]
Makes given path relative to the given root directory. @param string $path @param string $rootDirectory @return string @throws DataHandlingException Thrown when the path is not part of the given root directory.
[ "Makes", "given", "path", "relative", "to", "the", "given", "root", "directory", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L660-L670
253
villermen/data-handling
src/DataHandling.php
DataHandling.formatDirectory
public static function formatDirectory($pathOrPaths, ...$additionalPaths) { $directory = self::formatPath($pathOrPaths, ...$additionalPaths); if ($directory) { $directory = rtrim($directory, "/") . "/"; } return $directory; }
php
public static function formatDirectory($pathOrPaths, ...$additionalPaths) { $directory = self::formatPath($pathOrPaths, ...$additionalPaths); if ($directory) { $directory = rtrim($directory, "/") . "/"; } return $directory; }
[ "public", "static", "function", "formatDirectory", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", "{", "$", "directory", "=", "self", "::", "formatPath", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", ";", "if", "(", "$", "directory", ")", "{", "$", "directory", "=", "rtrim", "(", "$", "directory", ",", "\"/\"", ")", ".", "\"/\"", ";", "}", "return", "$", "directory", ";", "}" ]
Formats a directory path to a uniform representation. Basically formatPath but with a trailing slash. @param string|string[] $pathOrPaths @param string[] $additionalPaths @return string
[ "Formats", "a", "directory", "path", "to", "a", "uniform", "representation", ".", "Basically", "formatPath", "but", "with", "a", "trailing", "slash", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L680-L689
254
villermen/data-handling
src/DataHandling.php
DataHandling.formatAndResolveDirectory
public static function formatAndResolveDirectory($pathOrPaths, ...$additionalPaths) { $directory = self::formatAndResolvePath($pathOrPaths, ...$additionalPaths); if ($directory) { $directory = rtrim($directory, "/") . "/"; } return $directory; }
php
public static function formatAndResolveDirectory($pathOrPaths, ...$additionalPaths) { $directory = self::formatAndResolvePath($pathOrPaths, ...$additionalPaths); if ($directory) { $directory = rtrim($directory, "/") . "/"; } return $directory; }
[ "public", "static", "function", "formatAndResolveDirectory", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", "{", "$", "directory", "=", "self", "::", "formatAndResolvePath", "(", "$", "pathOrPaths", ",", "...", "$", "additionalPaths", ")", ";", "if", "(", "$", "directory", ")", "{", "$", "directory", "=", "rtrim", "(", "$", "directory", ",", "\"/\"", ")", ".", "\"/\"", ";", "}", "return", "$", "directory", ";", "}" ]
Resolves and formats a directory. @param string|string[] $pathOrPaths @param string[] $additionalPaths @return string @throws DataHandlingException
[ "Resolves", "and", "formats", "a", "directory", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L699-L708
255
villermen/data-handling
src/DataHandling.php
DataHandling.formatBytesize
public static function formatBytesize($size) { $suffixes = [ "B", "KiB", "MiB", "GiB", "TiB" //, "PiB", "EiB", "ZiB", "YiB" ]; $level = 1; for ($exponent = 0; $exponent < count($suffixes); $exponent++) { $nextLevel = pow(1024, $exponent + 1); if ($nextLevel > $size) { $smallSize = $size / $level; if ($smallSize < 10) { $decimals = 2; } elseif ($smallSize < 100) { $decimals = 1; } else { $decimals = 0; } return round($smallSize, $decimals) . " " . $suffixes[$exponent]; } $level = $nextLevel; } return "Large."; }
php
public static function formatBytesize($size) { $suffixes = [ "B", "KiB", "MiB", "GiB", "TiB" //, "PiB", "EiB", "ZiB", "YiB" ]; $level = 1; for ($exponent = 0; $exponent < count($suffixes); $exponent++) { $nextLevel = pow(1024, $exponent + 1); if ($nextLevel > $size) { $smallSize = $size / $level; if ($smallSize < 10) { $decimals = 2; } elseif ($smallSize < 100) { $decimals = 1; } else { $decimals = 0; } return round($smallSize, $decimals) . " " . $suffixes[$exponent]; } $level = $nextLevel; } return "Large."; }
[ "public", "static", "function", "formatBytesize", "(", "$", "size", ")", "{", "$", "suffixes", "=", "[", "\"B\"", ",", "\"KiB\"", ",", "\"MiB\"", ",", "\"GiB\"", ",", "\"TiB\"", "//, \"PiB\", \"EiB\", \"ZiB\", \"YiB\"", "]", ";", "$", "level", "=", "1", ";", "for", "(", "$", "exponent", "=", "0", ";", "$", "exponent", "<", "count", "(", "$", "suffixes", ")", ";", "$", "exponent", "++", ")", "{", "$", "nextLevel", "=", "pow", "(", "1024", ",", "$", "exponent", "+", "1", ")", ";", "if", "(", "$", "nextLevel", ">", "$", "size", ")", "{", "$", "smallSize", "=", "$", "size", "/", "$", "level", ";", "if", "(", "$", "smallSize", "<", "10", ")", "{", "$", "decimals", "=", "2", ";", "}", "elseif", "(", "$", "smallSize", "<", "100", ")", "{", "$", "decimals", "=", "1", ";", "}", "else", "{", "$", "decimals", "=", "0", ";", "}", "return", "round", "(", "$", "smallSize", ",", "$", "decimals", ")", ".", "\" \"", ".", "$", "suffixes", "[", "$", "exponent", "]", ";", "}", "$", "level", "=", "$", "nextLevel", ";", "}", "return", "\"Large.\"", ";", "}" ]
Returns a suffixed and shortened indication of an amount of bytes. @param int $size @return string
[ "Returns", "a", "suffixed", "and", "shortened", "indication", "of", "an", "amount", "of", "bytes", "." ]
034958556b136e43f3f6a03f0289e32c1887895e
https://github.com/villermen/data-handling/blob/034958556b136e43f3f6a03f0289e32c1887895e/src/DataHandling.php#L716-L744
256
bkdotcom/Toolbox
src/User.php
User.authenticateSocial
public function authenticateSocial($authResponse) { $this->debug->groupCollapsed(__METHOD__); $return = false; $providerkey = $authResponse['auth']['uid']; $query = 'SELECT * FROM `user_social` WHERE `providerkey` = '.$this->db->quoteValue($providerkey); $users = $this->db->query($query)[0]; $this->debug->table($users, 'users'); if ($users) { $userid = $users[0]['userid']; $this->log('login', $userid, array('provider'=>$authResponse['auth']['provider'])); $return = $userid; } $this->debug->groupEnd(); return $return; }
php
public function authenticateSocial($authResponse) { $this->debug->groupCollapsed(__METHOD__); $return = false; $providerkey = $authResponse['auth']['uid']; $query = 'SELECT * FROM `user_social` WHERE `providerkey` = '.$this->db->quoteValue($providerkey); $users = $this->db->query($query)[0]; $this->debug->table($users, 'users'); if ($users) { $userid = $users[0]['userid']; $this->log('login', $userid, array('provider'=>$authResponse['auth']['provider'])); $return = $userid; } $this->debug->groupEnd(); return $return; }
[ "public", "function", "authenticateSocial", "(", "$", "authResponse", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "return", "=", "false", ";", "$", "providerkey", "=", "$", "authResponse", "[", "'auth'", "]", "[", "'uid'", "]", ";", "$", "query", "=", "'SELECT * FROM `user_social` WHERE `providerkey` = '", ".", "$", "this", "->", "db", "->", "quoteValue", "(", "$", "providerkey", ")", ";", "$", "users", "=", "$", "this", "->", "db", "->", "query", "(", "$", "query", ")", "[", "0", "]", ";", "$", "this", "->", "debug", "->", "table", "(", "$", "users", ",", "'users'", ")", ";", "if", "(", "$", "users", ")", "{", "$", "userid", "=", "$", "users", "[", "0", "]", "[", "'userid'", "]", ";", "$", "this", "->", "log", "(", "'login'", ",", "$", "userid", ",", "array", "(", "'provider'", "=>", "$", "authResponse", "[", "'auth'", "]", "[", "'provider'", "]", ")", ")", ";", "$", "return", "=", "$", "userid", ";", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "return", ";", "}" ]
check if auth response user exists in auth_social table does not load any user info @param array $authResponse Opauth auth response array @return mixed userid or false
[ "check", "if", "auth", "response", "user", "exists", "in", "auth_social", "table", "does", "not", "load", "any", "user", "info" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L175-L190
257
bkdotcom/Toolbox
src/User.php
User.create
public function create($vals) { $this->debug->groupCollapsed(__METHOD__); $return = array( 'success' => true, 'errorDesc' => '', 'userid' => null, ); $noQuoteCols = array( 'createdon', 'lastactivity', ); $vals = array_change_key_case($vals); $vals['createdon'] = 'NOW()'; $vals['lastactivity'] = 'NOW()'; $valsOther = array(); $cols = $this->db->getColProperties('user'); $this->debug->table($cols, 'cols'); $col_names = array_keys($cols); foreach ($vals as $k => $v) { if (isset($this->cfg['userForeignKeys'][$k])) { $fka = $this->cfg['userForeignKeys'][$k]; $k_new = $fka['userCol']; $v_new = Str::quickTemp('('.$fka['getValQuery'].')', array('value'=>$this->db->quoteValue($v))); unset($vals[$k]); $vals[$k_new] = $v_new; $noQuoteCols[] = $k_new; } elseif (!in_array($k, $col_names)) { $valsOther[$k] = $v; unset($vals[$k]); } } $result = $this->db->rowMan('user', $vals, null, $noQuoteCols); $this->debug->log('result', $result); if ($result) { $this->debug->info('user created'); $userid = $result; $this->log('userCreate', $userid); if (!empty($valsOther)) { $return = $this->update($valsOther, $userid); } $return['userid'] = $userid; } else { $return['success'] = false; $return['errorDesc'] = $this->db->error; } $this->debug->log('return', $return); $this->debug->groupEnd(); return $return; }
php
public function create($vals) { $this->debug->groupCollapsed(__METHOD__); $return = array( 'success' => true, 'errorDesc' => '', 'userid' => null, ); $noQuoteCols = array( 'createdon', 'lastactivity', ); $vals = array_change_key_case($vals); $vals['createdon'] = 'NOW()'; $vals['lastactivity'] = 'NOW()'; $valsOther = array(); $cols = $this->db->getColProperties('user'); $this->debug->table($cols, 'cols'); $col_names = array_keys($cols); foreach ($vals as $k => $v) { if (isset($this->cfg['userForeignKeys'][$k])) { $fka = $this->cfg['userForeignKeys'][$k]; $k_new = $fka['userCol']; $v_new = Str::quickTemp('('.$fka['getValQuery'].')', array('value'=>$this->db->quoteValue($v))); unset($vals[$k]); $vals[$k_new] = $v_new; $noQuoteCols[] = $k_new; } elseif (!in_array($k, $col_names)) { $valsOther[$k] = $v; unset($vals[$k]); } } $result = $this->db->rowMan('user', $vals, null, $noQuoteCols); $this->debug->log('result', $result); if ($result) { $this->debug->info('user created'); $userid = $result; $this->log('userCreate', $userid); if (!empty($valsOther)) { $return = $this->update($valsOther, $userid); } $return['userid'] = $userid; } else { $return['success'] = false; $return['errorDesc'] = $this->db->error; } $this->debug->log('return', $return); $this->debug->groupEnd(); return $return; }
[ "public", "function", "create", "(", "$", "vals", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "return", "=", "array", "(", "'success'", "=>", "true", ",", "'errorDesc'", "=>", "''", ",", "'userid'", "=>", "null", ",", ")", ";", "$", "noQuoteCols", "=", "array", "(", "'createdon'", ",", "'lastactivity'", ",", ")", ";", "$", "vals", "=", "array_change_key_case", "(", "$", "vals", ")", ";", "$", "vals", "[", "'createdon'", "]", "=", "'NOW()'", ";", "$", "vals", "[", "'lastactivity'", "]", "=", "'NOW()'", ";", "$", "valsOther", "=", "array", "(", ")", ";", "$", "cols", "=", "$", "this", "->", "db", "->", "getColProperties", "(", "'user'", ")", ";", "$", "this", "->", "debug", "->", "table", "(", "$", "cols", ",", "'cols'", ")", ";", "$", "col_names", "=", "array_keys", "(", "$", "cols", ")", ";", "foreach", "(", "$", "vals", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "cfg", "[", "'userForeignKeys'", "]", "[", "$", "k", "]", ")", ")", "{", "$", "fka", "=", "$", "this", "->", "cfg", "[", "'userForeignKeys'", "]", "[", "$", "k", "]", ";", "$", "k_new", "=", "$", "fka", "[", "'userCol'", "]", ";", "$", "v_new", "=", "Str", "::", "quickTemp", "(", "'('", ".", "$", "fka", "[", "'getValQuery'", "]", ".", "')'", ",", "array", "(", "'value'", "=>", "$", "this", "->", "db", "->", "quoteValue", "(", "$", "v", ")", ")", ")", ";", "unset", "(", "$", "vals", "[", "$", "k", "]", ")", ";", "$", "vals", "[", "$", "k_new", "]", "=", "$", "v_new", ";", "$", "noQuoteCols", "[", "]", "=", "$", "k_new", ";", "}", "elseif", "(", "!", "in_array", "(", "$", "k", ",", "$", "col_names", ")", ")", "{", "$", "valsOther", "[", "$", "k", "]", "=", "$", "v", ";", "unset", "(", "$", "vals", "[", "$", "k", "]", ")", ";", "}", "}", "$", "result", "=", "$", "this", "->", "db", "->", "rowMan", "(", "'user'", ",", "$", "vals", ",", "null", ",", "$", "noQuoteCols", ")", ";", "$", "this", "->", "debug", "->", "log", "(", "'result'", ",", "$", "result", ")", ";", "if", "(", "$", "result", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'user created'", ")", ";", "$", "userid", "=", "$", "result", ";", "$", "this", "->", "log", "(", "'userCreate'", ",", "$", "userid", ")", ";", "if", "(", "!", "empty", "(", "$", "valsOther", ")", ")", "{", "$", "return", "=", "$", "this", "->", "update", "(", "$", "valsOther", ",", "$", "userid", ")", ";", "}", "$", "return", "[", "'userid'", "]", "=", "$", "userid", ";", "}", "else", "{", "$", "return", "[", "'success'", "]", "=", "false", ";", "$", "return", "[", "'errorDesc'", "]", "=", "$", "this", "->", "db", "->", "error", ";", "}", "$", "this", "->", "debug", "->", "log", "(", "'return'", ",", "$", "return", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "return", ";", "}" ]
Creates user in DB Does NOT load user into current session @param array $vals values @return array
[ "Creates", "user", "in", "DB", "Does", "NOT", "load", "user", "into", "current", "session" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L200-L249
258
bkdotcom/Toolbox
src/User.php
User.logout
public function logout() { $this->debug->groupCollapsed(__METHOD__); if ($this->auth) { $this->setPersistToken(false); // more efficient to remove first (while session still exists) $this->log('logout'); } ArrayUtil::path($_SESSION, $this->cfg['sessionPath'], array()); // clear session $this->userid = null; $this->auth = 0; $this->debug->groupEnd(); return; }
php
public function logout() { $this->debug->groupCollapsed(__METHOD__); if ($this->auth) { $this->setPersistToken(false); // more efficient to remove first (while session still exists) $this->log('logout'); } ArrayUtil::path($_SESSION, $this->cfg['sessionPath'], array()); // clear session $this->userid = null; $this->auth = 0; $this->debug->groupEnd(); return; }
[ "public", "function", "logout", "(", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "if", "(", "$", "this", "->", "auth", ")", "{", "$", "this", "->", "setPersistToken", "(", "false", ")", ";", "// more efficient to remove first (while session still exists)", "$", "this", "->", "log", "(", "'logout'", ")", ";", "}", "ArrayUtil", "::", "path", "(", "$", "_SESSION", ",", "$", "this", "->", "cfg", "[", "'sessionPath'", "]", ",", "array", "(", ")", ")", ";", "// clear session", "$", "this", "->", "userid", "=", "null", ";", "$", "this", "->", "auth", "=", "0", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", ";", "}" ]
Log user out @return void
[ "Log", "user", "out" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L359-L371
259
bkdotcom/Toolbox
src/User.php
User.search
public function search($vals) { $this->debug->groupCollapsed(__METHOD__); $this->debug->log('vals', $vals); $return = array(); if ($vals) { $where = array(); $where_or = array(); if (!empty($vals['username'])) { $where_or[] = '`username` = '.$this->db->quoteValue($vals['username']); unset($vals['username']); } if (!empty($vals['email'])) { $where_or[] = '`email` = '.$this->db->quoteValue($vals['email']); unset($vals['email']); } if ($where_or) { $where[] = '( '.implode(' OR ', $where_or).' )'; } foreach ($vals as $k => $v) { $col = '`'.$k.'`'; if ($k == 'userid') { $col = '`user`.'.$col; } $where[] = $col.' = '.$this->db->quoteValue($v); } $where = !empty($where) ? ' WHERE '.implode(' AND ', $where) : ''; $query = 'SELECT * FROM `user`' .' LEFT JOIN `user_auth` USING (`userid`)' // .' LEFT JOIN `specialties` USING (`specialtyid`)' .$where; $return = $this->db->query($query)[0]; } $this->debug->table($return, 'return'); $this->debug->groupEnd(); return $return; }
php
public function search($vals) { $this->debug->groupCollapsed(__METHOD__); $this->debug->log('vals', $vals); $return = array(); if ($vals) { $where = array(); $where_or = array(); if (!empty($vals['username'])) { $where_or[] = '`username` = '.$this->db->quoteValue($vals['username']); unset($vals['username']); } if (!empty($vals['email'])) { $where_or[] = '`email` = '.$this->db->quoteValue($vals['email']); unset($vals['email']); } if ($where_or) { $where[] = '( '.implode(' OR ', $where_or).' )'; } foreach ($vals as $k => $v) { $col = '`'.$k.'`'; if ($k == 'userid') { $col = '`user`.'.$col; } $where[] = $col.' = '.$this->db->quoteValue($v); } $where = !empty($where) ? ' WHERE '.implode(' AND ', $where) : ''; $query = 'SELECT * FROM `user`' .' LEFT JOIN `user_auth` USING (`userid`)' // .' LEFT JOIN `specialties` USING (`specialtyid`)' .$where; $return = $this->db->query($query)[0]; } $this->debug->table($return, 'return'); $this->debug->groupEnd(); return $return; }
[ "public", "function", "search", "(", "$", "vals", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "this", "->", "debug", "->", "log", "(", "'vals'", ",", "$", "vals", ")", ";", "$", "return", "=", "array", "(", ")", ";", "if", "(", "$", "vals", ")", "{", "$", "where", "=", "array", "(", ")", ";", "$", "where_or", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "vals", "[", "'username'", "]", ")", ")", "{", "$", "where_or", "[", "]", "=", "'`username` = '", ".", "$", "this", "->", "db", "->", "quoteValue", "(", "$", "vals", "[", "'username'", "]", ")", ";", "unset", "(", "$", "vals", "[", "'username'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "vals", "[", "'email'", "]", ")", ")", "{", "$", "where_or", "[", "]", "=", "'`email` = '", ".", "$", "this", "->", "db", "->", "quoteValue", "(", "$", "vals", "[", "'email'", "]", ")", ";", "unset", "(", "$", "vals", "[", "'email'", "]", ")", ";", "}", "if", "(", "$", "where_or", ")", "{", "$", "where", "[", "]", "=", "'( '", ".", "implode", "(", "' OR '", ",", "$", "where_or", ")", ".", "' )'", ";", "}", "foreach", "(", "$", "vals", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "col", "=", "'`'", ".", "$", "k", ".", "'`'", ";", "if", "(", "$", "k", "==", "'userid'", ")", "{", "$", "col", "=", "'`user`.'", ".", "$", "col", ";", "}", "$", "where", "[", "]", "=", "$", "col", ".", "' = '", ".", "$", "this", "->", "db", "->", "quoteValue", "(", "$", "v", ")", ";", "}", "$", "where", "=", "!", "empty", "(", "$", "where", ")", "?", "' WHERE '", ".", "implode", "(", "' AND '", ",", "$", "where", ")", ":", "''", ";", "$", "query", "=", "'SELECT * FROM `user`'", ".", "' LEFT JOIN `user_auth` USING (`userid`)'", "// .' LEFT JOIN `specialties` USING (`specialtyid`)'", ".", "$", "where", ";", "$", "return", "=", "$", "this", "->", "db", "->", "query", "(", "$", "query", ")", "[", "0", "]", ";", "}", "$", "this", "->", "debug", "->", "table", "(", "$", "return", ",", "'return'", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "return", ";", "}" ]
search for user by username, email, or userid @param array $vals values @return array rows
[ "search", "for", "user", "by", "username", "email", "or", "userid" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L380-L418
260
bkdotcom/Toolbox
src/User.php
User.setCurrent
public function setCurrent($userid) { $this->debug->groupCollapsed(__METHOD__, $userid); Session::start(); $user = $this->get($userid); // initialize session array ArrayUtil::path($_SESSION, $this->cfg['sessionPath'], array()); // create link to session array // $this->user = &ArrayUtil::path($_SESSION, $this->cfg['sessionPath']); $path = $this->cfg['sessionPath']; if (!\is_array($path)) { $path = \array_filter(\preg_split('#[\./]#', $path), 'strlen'); } $this->user =& $_SESSION; foreach ($path as $k) { if (!isset($this->user[$k])) { $this->user[$k] = array(); } $this->user =& $this->user[$k]; } // load session array $this->user = $user; $this->user['_ts_cur'] = time(); $this->userid = $this->user['userid']; $this->update(array('lastactivity'=>'NOW()')); $this->debug->groupEnd(); return; }
php
public function setCurrent($userid) { $this->debug->groupCollapsed(__METHOD__, $userid); Session::start(); $user = $this->get($userid); // initialize session array ArrayUtil::path($_SESSION, $this->cfg['sessionPath'], array()); // create link to session array // $this->user = &ArrayUtil::path($_SESSION, $this->cfg['sessionPath']); $path = $this->cfg['sessionPath']; if (!\is_array($path)) { $path = \array_filter(\preg_split('#[\./]#', $path), 'strlen'); } $this->user =& $_SESSION; foreach ($path as $k) { if (!isset($this->user[$k])) { $this->user[$k] = array(); } $this->user =& $this->user[$k]; } // load session array $this->user = $user; $this->user['_ts_cur'] = time(); $this->userid = $this->user['userid']; $this->update(array('lastactivity'=>'NOW()')); $this->debug->groupEnd(); return; }
[ "public", "function", "setCurrent", "(", "$", "userid", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ",", "$", "userid", ")", ";", "Session", "::", "start", "(", ")", ";", "$", "user", "=", "$", "this", "->", "get", "(", "$", "userid", ")", ";", "// initialize session array", "ArrayUtil", "::", "path", "(", "$", "_SESSION", ",", "$", "this", "->", "cfg", "[", "'sessionPath'", "]", ",", "array", "(", ")", ")", ";", "// create link to session array", "// $this->user = &ArrayUtil::path($_SESSION, $this->cfg['sessionPath']);", "$", "path", "=", "$", "this", "->", "cfg", "[", "'sessionPath'", "]", ";", "if", "(", "!", "\\", "is_array", "(", "$", "path", ")", ")", "{", "$", "path", "=", "\\", "array_filter", "(", "\\", "preg_split", "(", "'#[\\./]#'", ",", "$", "path", ")", ",", "'strlen'", ")", ";", "}", "$", "this", "->", "user", "=", "&", "$", "_SESSION", ";", "foreach", "(", "$", "path", "as", "$", "k", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "user", "[", "$", "k", "]", ")", ")", "{", "$", "this", "->", "user", "[", "$", "k", "]", "=", "array", "(", ")", ";", "}", "$", "this", "->", "user", "=", "&", "$", "this", "->", "user", "[", "$", "k", "]", ";", "}", "// load session array", "$", "this", "->", "user", "=", "$", "user", ";", "$", "this", "->", "user", "[", "'_ts_cur'", "]", "=", "time", "(", ")", ";", "$", "this", "->", "userid", "=", "$", "this", "->", "user", "[", "'userid'", "]", ";", "$", "this", "->", "update", "(", "array", "(", "'lastactivity'", "=>", "'NOW()'", ")", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", ";", "}" ]
Set current user by userid @param integer $userid userid @return void
[ "Set", "current", "user", "by", "userid" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L427-L454
261
bkdotcom/Toolbox
src/User.php
User.setPersistToken
public function setPersistToken($set = true) { $this->debug->groupCollapsed(__METHOD__); $cookieParams = $this->cfg['persistCookie']; $return = null; if ($set) { $token = $this->genToken(); // raw binary $cookieParams['value'] = array( 'username' => $this->user['username'], 'token' => $token, ); #$this->debug->log('value', $cookie['value']); Cookie::set($cookieParams); // store cookie / username combo in db $values = array( 'userid' => $this->userid, 'token_hash' => sha1($token), ); $this->db->rowMan('persist_tokens', $values); $return = $cookieParams['value']; } elseif (isset($_COOKIE[ $cookieParams['name'] ])) { $vals = Cookie::get($cookieParams['name']); if (is_array($vals) && isset($vals['username']) && isset($vals['token'])) { // remove token from db // determine userid $userid = null; if (isset($this->user['username']) && $this->user['username'] === $vals['username']) { $userid = $this->userid; } else { $users = $this->search(array('username'=>$vals['username'])); if ($users) { $userid = $users[0]['userid']; } } if ($userid) { $where = array( 'userid' => $userid, 'token_hash' => sha1($vals['token']), ); $this->db->rowMan('persist_tokens', null, $where); } // remove cookie $cookieParams['value'] = null; Cookie::set($cookieParams); } } $this->debug->groupEnd(); return $return; }
php
public function setPersistToken($set = true) { $this->debug->groupCollapsed(__METHOD__); $cookieParams = $this->cfg['persistCookie']; $return = null; if ($set) { $token = $this->genToken(); // raw binary $cookieParams['value'] = array( 'username' => $this->user['username'], 'token' => $token, ); #$this->debug->log('value', $cookie['value']); Cookie::set($cookieParams); // store cookie / username combo in db $values = array( 'userid' => $this->userid, 'token_hash' => sha1($token), ); $this->db->rowMan('persist_tokens', $values); $return = $cookieParams['value']; } elseif (isset($_COOKIE[ $cookieParams['name'] ])) { $vals = Cookie::get($cookieParams['name']); if (is_array($vals) && isset($vals['username']) && isset($vals['token'])) { // remove token from db // determine userid $userid = null; if (isset($this->user['username']) && $this->user['username'] === $vals['username']) { $userid = $this->userid; } else { $users = $this->search(array('username'=>$vals['username'])); if ($users) { $userid = $users[0]['userid']; } } if ($userid) { $where = array( 'userid' => $userid, 'token_hash' => sha1($vals['token']), ); $this->db->rowMan('persist_tokens', null, $where); } // remove cookie $cookieParams['value'] = null; Cookie::set($cookieParams); } } $this->debug->groupEnd(); return $return; }
[ "public", "function", "setPersistToken", "(", "$", "set", "=", "true", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "cookieParams", "=", "$", "this", "->", "cfg", "[", "'persistCookie'", "]", ";", "$", "return", "=", "null", ";", "if", "(", "$", "set", ")", "{", "$", "token", "=", "$", "this", "->", "genToken", "(", ")", ";", "// raw binary", "$", "cookieParams", "[", "'value'", "]", "=", "array", "(", "'username'", "=>", "$", "this", "->", "user", "[", "'username'", "]", ",", "'token'", "=>", "$", "token", ",", ")", ";", "#$this->debug->log('value', $cookie['value']);", "Cookie", "::", "set", "(", "$", "cookieParams", ")", ";", "// store cookie / username combo in db", "$", "values", "=", "array", "(", "'userid'", "=>", "$", "this", "->", "userid", ",", "'token_hash'", "=>", "sha1", "(", "$", "token", ")", ",", ")", ";", "$", "this", "->", "db", "->", "rowMan", "(", "'persist_tokens'", ",", "$", "values", ")", ";", "$", "return", "=", "$", "cookieParams", "[", "'value'", "]", ";", "}", "elseif", "(", "isset", "(", "$", "_COOKIE", "[", "$", "cookieParams", "[", "'name'", "]", "]", ")", ")", "{", "$", "vals", "=", "Cookie", "::", "get", "(", "$", "cookieParams", "[", "'name'", "]", ")", ";", "if", "(", "is_array", "(", "$", "vals", ")", "&&", "isset", "(", "$", "vals", "[", "'username'", "]", ")", "&&", "isset", "(", "$", "vals", "[", "'token'", "]", ")", ")", "{", "// remove token from db", "// determine userid", "$", "userid", "=", "null", ";", "if", "(", "isset", "(", "$", "this", "->", "user", "[", "'username'", "]", ")", "&&", "$", "this", "->", "user", "[", "'username'", "]", "===", "$", "vals", "[", "'username'", "]", ")", "{", "$", "userid", "=", "$", "this", "->", "userid", ";", "}", "else", "{", "$", "users", "=", "$", "this", "->", "search", "(", "array", "(", "'username'", "=>", "$", "vals", "[", "'username'", "]", ")", ")", ";", "if", "(", "$", "users", ")", "{", "$", "userid", "=", "$", "users", "[", "0", "]", "[", "'userid'", "]", ";", "}", "}", "if", "(", "$", "userid", ")", "{", "$", "where", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'token_hash'", "=>", "sha1", "(", "$", "vals", "[", "'token'", "]", ")", ",", ")", ";", "$", "this", "->", "db", "->", "rowMan", "(", "'persist_tokens'", ",", "null", ",", "$", "where", ")", ";", "}", "// remove cookie", "$", "cookieParams", "[", "'value'", "]", "=", "null", ";", "Cookie", "::", "set", "(", "$", "cookieParams", ")", ";", "}", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "return", ";", "}" ]
sets cookie stores unsalted SHA1 hash in db @param boolean $set true (false to remove cookie); @return mixed set: array (cookie value), remove: null
[ "sets", "cookie", "stores", "unsalted", "SHA1", "hash", "in", "db" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L500-L548
262
bkdotcom/Toolbox
src/User.php
User.socialLink
public function socialLink($provider, $providerKey, $userid = null) { $this->debug->groupCollapsed(__METHOD__); if ($userid === null) { $userid = $this->userid; } $vals = array( 'userid' => $userid, 'provider' => strtolower($provider), 'providerkey' => $providerKey, ); /* search if social is linked to another account */ $where = array( 'provider' => strtolower($provider), 'providerkey' => $providerKey, ); /* foreach ($where as $k => $v) { unset($where[$k]); $where[] = '`'.$k.'`='.$this->db->quoteValue($v); } $where = implode(' AND ', $where); */ $found = $this->db->query('SELECT * FROM `user_social` '.$this->db->buildWhere($where))[0]; if ($found) { $this->socialUnlink($found[0]['provider'], $found[0]['providerkey']); } $this->db->rowMan('user_social', $vals); $this->log('socialLink', $userid, array( 'provider' => strtolower($provider), 'providerKey' => $providerKey, )); $this->debug->groupEnd(); return; }
php
public function socialLink($provider, $providerKey, $userid = null) { $this->debug->groupCollapsed(__METHOD__); if ($userid === null) { $userid = $this->userid; } $vals = array( 'userid' => $userid, 'provider' => strtolower($provider), 'providerkey' => $providerKey, ); /* search if social is linked to another account */ $where = array( 'provider' => strtolower($provider), 'providerkey' => $providerKey, ); /* foreach ($where as $k => $v) { unset($where[$k]); $where[] = '`'.$k.'`='.$this->db->quoteValue($v); } $where = implode(' AND ', $where); */ $found = $this->db->query('SELECT * FROM `user_social` '.$this->db->buildWhere($where))[0]; if ($found) { $this->socialUnlink($found[0]['provider'], $found[0]['providerkey']); } $this->db->rowMan('user_social', $vals); $this->log('socialLink', $userid, array( 'provider' => strtolower($provider), 'providerKey' => $providerKey, )); $this->debug->groupEnd(); return; }
[ "public", "function", "socialLink", "(", "$", "provider", ",", "$", "providerKey", ",", "$", "userid", "=", "null", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "if", "(", "$", "userid", "===", "null", ")", "{", "$", "userid", "=", "$", "this", "->", "userid", ";", "}", "$", "vals", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'provider'", "=>", "strtolower", "(", "$", "provider", ")", ",", "'providerkey'", "=>", "$", "providerKey", ",", ")", ";", "/*\n\t\t\tsearch if social is linked to another account\n\t\t*/", "$", "where", "=", "array", "(", "'provider'", "=>", "strtolower", "(", "$", "provider", ")", ",", "'providerkey'", "=>", "$", "providerKey", ",", ")", ";", "/*\n\t\tforeach ($where as $k => $v) {\n\t\t\tunset($where[$k]);\n\t\t\t$where[] = '`'.$k.'`='.$this->db->quoteValue($v);\n\t\t}\n\t\t$where = implode(' AND ', $where);\n\t\t*/", "$", "found", "=", "$", "this", "->", "db", "->", "query", "(", "'SELECT * FROM `user_social` '", ".", "$", "this", "->", "db", "->", "buildWhere", "(", "$", "where", ")", ")", "[", "0", "]", ";", "if", "(", "$", "found", ")", "{", "$", "this", "->", "socialUnlink", "(", "$", "found", "[", "0", "]", "[", "'provider'", "]", ",", "$", "found", "[", "0", "]", "[", "'providerkey'", "]", ")", ";", "}", "$", "this", "->", "db", "->", "rowMan", "(", "'user_social'", ",", "$", "vals", ")", ";", "$", "this", "->", "log", "(", "'socialLink'", ",", "$", "userid", ",", "array", "(", "'provider'", "=>", "strtolower", "(", "$", "provider", ")", ",", "'providerKey'", "=>", "$", "providerKey", ",", ")", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", ";", "}" ]
Link user to a authentication provider @param string $provider Facebook, Twiter, etc @param string $providerKey UID provided by provider @param integer $userid optional @todo check if providerKey linked to another account... if so remove that linkage @return void
[ "Link", "user", "to", "a", "authentication", "provider" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L561-L597
263
bkdotcom/Toolbox
src/User.php
User.socialUnlink
public function socialUnlink($provider, $userid = null) { $this->debug->groupCollapsed(__METHOD__); if ($userid === null) { $userid = $this->userid; } $where = array( 'userid' => $userid, 'provider' => strtolower($provider), ); $this->db->rowMan('user_social', null, $where); $this->log('sociaUnlink', $userid, array( 'provider' => strtolower($provider), )); $this->debug->groupEnd(); return; }
php
public function socialUnlink($provider, $userid = null) { $this->debug->groupCollapsed(__METHOD__); if ($userid === null) { $userid = $this->userid; } $where = array( 'userid' => $userid, 'provider' => strtolower($provider), ); $this->db->rowMan('user_social', null, $where); $this->log('sociaUnlink', $userid, array( 'provider' => strtolower($provider), )); $this->debug->groupEnd(); return; }
[ "public", "function", "socialUnlink", "(", "$", "provider", ",", "$", "userid", "=", "null", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "if", "(", "$", "userid", "===", "null", ")", "{", "$", "userid", "=", "$", "this", "->", "userid", ";", "}", "$", "where", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'provider'", "=>", "strtolower", "(", "$", "provider", ")", ",", ")", ";", "$", "this", "->", "db", "->", "rowMan", "(", "'user_social'", ",", "null", ",", "$", "where", ")", ";", "$", "this", "->", "log", "(", "'sociaUnlink'", ",", "$", "userid", ",", "array", "(", "'provider'", "=>", "strtolower", "(", "$", "provider", ")", ",", ")", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", ";", "}" ]
unlink user from authentication provider @param string $provider Facebook, Twiter, etc @param integer $userid optional @return void
[ "unlink", "user", "from", "authentication", "provider" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L607-L623
264
bkdotcom/Toolbox
src/User.php
User.verifyEmailToken
public function verifyEmailToken($token) { $this->debug->groupCollapsed(__METHOD__); $return = false; $token = base64_decode($token); $vals = array( 'token_hash' => $this->db->quoteValue(sha1($token)), ); $query = Str::quickTemp('SELECT * FROM `email_tokens` WHERE `token_hash` = [::token_hash::]', $vals); $rows = $this->db->query($query)[0]; $this->debug->table($rows, 'rows'); if ($rows) { // found token in table $return = $rows[0]['userid']; // remove the token $where = $vals; $this->db->rowMan('email_tokens', null, $where); $this->log('pwForgotTokenSuccess', $rows[0]['userid']); } else { $this->log('pwForgotTokenFail'); } $this->debug->groupEnd(); return $return; }
php
public function verifyEmailToken($token) { $this->debug->groupCollapsed(__METHOD__); $return = false; $token = base64_decode($token); $vals = array( 'token_hash' => $this->db->quoteValue(sha1($token)), ); $query = Str::quickTemp('SELECT * FROM `email_tokens` WHERE `token_hash` = [::token_hash::]', $vals); $rows = $this->db->query($query)[0]; $this->debug->table($rows, 'rows'); if ($rows) { // found token in table $return = $rows[0]['userid']; // remove the token $where = $vals; $this->db->rowMan('email_tokens', null, $where); $this->log('pwForgotTokenSuccess', $rows[0]['userid']); } else { $this->log('pwForgotTokenFail'); } $this->debug->groupEnd(); return $return; }
[ "public", "function", "verifyEmailToken", "(", "$", "token", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "return", "=", "false", ";", "$", "token", "=", "base64_decode", "(", "$", "token", ")", ";", "$", "vals", "=", "array", "(", "'token_hash'", "=>", "$", "this", "->", "db", "->", "quoteValue", "(", "sha1", "(", "$", "token", ")", ")", ",", ")", ";", "$", "query", "=", "Str", "::", "quickTemp", "(", "'SELECT * FROM `email_tokens`\n\t\t\tWHERE `token_hash` = [::token_hash::]'", ",", "$", "vals", ")", ";", "$", "rows", "=", "$", "this", "->", "db", "->", "query", "(", "$", "query", ")", "[", "0", "]", ";", "$", "this", "->", "debug", "->", "table", "(", "$", "rows", ",", "'rows'", ")", ";", "if", "(", "$", "rows", ")", "{", "// found token in table", "$", "return", "=", "$", "rows", "[", "0", "]", "[", "'userid'", "]", ";", "// remove the token", "$", "where", "=", "$", "vals", ";", "$", "this", "->", "db", "->", "rowMan", "(", "'email_tokens'", ",", "null", ",", "$", "where", ")", ";", "$", "this", "->", "log", "(", "'pwForgotTokenSuccess'", ",", "$", "rows", "[", "0", "]", "[", "'userid'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "log", "(", "'pwForgotTokenFail'", ")", ";", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "return", ";", "}" ]
verifies a token sent via email searches for token in db if found will remove from db @param string $token token value @return mixed userid or false
[ "verifies", "a", "token", "sent", "via", "email", "searches", "for", "token", "in", "db", "if", "found", "will", "remove", "from", "db" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L715-L739
265
bkdotcom/Toolbox
src/User.php
User.genToken
private function genToken($tokenLen = null) { $this->debug->groupCollapsed(__METHOD__); $tokenLen = isset($tokenLen) ? $tokenLen : $this->cfg['tokenLen']; $token = ''; if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) { $token = mcrypt_create_iv($tokenLen, MCRYPT_DEV_URANDOM); } if (empty($token) && function_exists('openssl_random_pseudo_bytes')) { $token = openssl_random_pseudo_bytes($tokenLen); } if (empty($token) && is_readable('/dev/urandom')) { $file = fopen('/dev/urandom', 'r'); $len = strlen($token); while ($len < $tokenLen) { $token .= fread($file, $tokenLen - $len); $len = strlen($token); } fclose($file); } $this->debug->log('token', $token); $this->debug->groupEnd(); return $token; }
php
private function genToken($tokenLen = null) { $this->debug->groupCollapsed(__METHOD__); $tokenLen = isset($tokenLen) ? $tokenLen : $this->cfg['tokenLen']; $token = ''; if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) { $token = mcrypt_create_iv($tokenLen, MCRYPT_DEV_URANDOM); } if (empty($token) && function_exists('openssl_random_pseudo_bytes')) { $token = openssl_random_pseudo_bytes($tokenLen); } if (empty($token) && is_readable('/dev/urandom')) { $file = fopen('/dev/urandom', 'r'); $len = strlen($token); while ($len < $tokenLen) { $token .= fread($file, $tokenLen - $len); $len = strlen($token); } fclose($file); } $this->debug->log('token', $token); $this->debug->groupEnd(); return $token; }
[ "private", "function", "genToken", "(", "$", "tokenLen", "=", "null", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "tokenLen", "=", "isset", "(", "$", "tokenLen", ")", "?", "$", "tokenLen", ":", "$", "this", "->", "cfg", "[", "'tokenLen'", "]", ";", "$", "token", "=", "''", ";", "if", "(", "function_exists", "(", "'mcrypt_create_iv'", ")", "&&", "!", "defined", "(", "'PHALANGER'", ")", ")", "{", "$", "token", "=", "mcrypt_create_iv", "(", "$", "tokenLen", ",", "MCRYPT_DEV_URANDOM", ")", ";", "}", "if", "(", "empty", "(", "$", "token", ")", "&&", "function_exists", "(", "'openssl_random_pseudo_bytes'", ")", ")", "{", "$", "token", "=", "openssl_random_pseudo_bytes", "(", "$", "tokenLen", ")", ";", "}", "if", "(", "empty", "(", "$", "token", ")", "&&", "is_readable", "(", "'/dev/urandom'", ")", ")", "{", "$", "file", "=", "fopen", "(", "'/dev/urandom'", ",", "'r'", ")", ";", "$", "len", "=", "strlen", "(", "$", "token", ")", ";", "while", "(", "$", "len", "<", "$", "tokenLen", ")", "{", "$", "token", ".=", "fread", "(", "$", "file", ",", "$", "tokenLen", "-", "$", "len", ")", ";", "$", "len", "=", "strlen", "(", "$", "token", ")", ";", "}", "fclose", "(", "$", "file", ")", ";", "}", "$", "this", "->", "debug", "->", "log", "(", "'token'", ",", "$", "token", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "token", ";", "}" ]
generate crypto strength token @param integer $tokenLen optional token length (bytes) @return string raw binary string
[ "generate", "crypto", "strength", "token" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L748-L773
266
bkdotcom/Toolbox
src/User.php
User.hashPassword
private function hashPassword($pwClear) { $this->debug->groupCollapsed(__METHOD__); $this->debug->time('hash'); $hash = password_hash($pwClear, $this->cfg['passwordHashAlgo'], $this->cfg['passwordHashOptions']); $this->debug->log('hash', strlen($hash), $hash); $this->debug->timeEnd('hash'); $this->debug->groupEnd(); return $hash; }
php
private function hashPassword($pwClear) { $this->debug->groupCollapsed(__METHOD__); $this->debug->time('hash'); $hash = password_hash($pwClear, $this->cfg['passwordHashAlgo'], $this->cfg['passwordHashOptions']); $this->debug->log('hash', strlen($hash), $hash); $this->debug->timeEnd('hash'); $this->debug->groupEnd(); return $hash; }
[ "private", "function", "hashPassword", "(", "$", "pwClear", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "this", "->", "debug", "->", "time", "(", "'hash'", ")", ";", "$", "hash", "=", "password_hash", "(", "$", "pwClear", ",", "$", "this", "->", "cfg", "[", "'passwordHashAlgo'", "]", ",", "$", "this", "->", "cfg", "[", "'passwordHashOptions'", "]", ")", ";", "$", "this", "->", "debug", "->", "log", "(", "'hash'", ",", "strlen", "(", "$", "hash", ")", ",", "$", "hash", ")", ";", "$", "this", "->", "debug", "->", "timeEnd", "(", "'hash'", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "hash", ";", "}" ]
returns hashed password @param string $pwClear clear-text password @return string hased pw
[ "returns", "hashed", "password" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L782-L791
267
bkdotcom/Toolbox
src/User.php
User.resume
private function resume() { $this->debug->groupCollapsed(__METHOD__); if (isset($_SESSION)) { $this->user = ArrayUtil::pathGet($_SESSION, $this->cfg['sessionPath']); } /* Session? */ if (!empty($this->user)) { $this->debug->info('resuming from session'); if (isset($this->user['_ts_cur'])) { $this->user['lastactivity'] = $this->user['_ts_cur']; } $this->userid = $this->user['userid']; $this->auth_via = 'session'; $this->auth = 2; if ($this->user['lastactivity'] + $this->cfg['maxIdle'] < time()) { $this->debug->warn('idle'); $this->debug->log('lastactivity', $this->user['lastactivity']); $this->auth = 0; } else { $this->update(array('lastactivity'=>'NOW()')); } } /* Persist cookie? */ if (empty($this->auth) && isset($_COOKIE[ $this->cfg['persistCookie']['name'] ])) { $persist_vals = Cookie::get($this->cfg['persistCookie']['name']); $userid = isset($persist_vals['username']) && isset($persist_vals['token']) ? $this->verifyPersistToken($persist_vals['username'], $persist_vals['token']) // drops from db if found : null; if ($userid) { $this->debug->info('resuming from persist token'); $this->setCurrent($userid); $this->setPersistToken(); $this->auth_via = 'cookie'; $this->auth = 1; } } /* Social Cookie? */ if (empty($this->auth)) { } if (!empty($this->auth)) { $this->user['_ts_cur'] = time(); } $this->debug->groupEnd(); }
php
private function resume() { $this->debug->groupCollapsed(__METHOD__); if (isset($_SESSION)) { $this->user = ArrayUtil::pathGet($_SESSION, $this->cfg['sessionPath']); } /* Session? */ if (!empty($this->user)) { $this->debug->info('resuming from session'); if (isset($this->user['_ts_cur'])) { $this->user['lastactivity'] = $this->user['_ts_cur']; } $this->userid = $this->user['userid']; $this->auth_via = 'session'; $this->auth = 2; if ($this->user['lastactivity'] + $this->cfg['maxIdle'] < time()) { $this->debug->warn('idle'); $this->debug->log('lastactivity', $this->user['lastactivity']); $this->auth = 0; } else { $this->update(array('lastactivity'=>'NOW()')); } } /* Persist cookie? */ if (empty($this->auth) && isset($_COOKIE[ $this->cfg['persistCookie']['name'] ])) { $persist_vals = Cookie::get($this->cfg['persistCookie']['name']); $userid = isset($persist_vals['username']) && isset($persist_vals['token']) ? $this->verifyPersistToken($persist_vals['username'], $persist_vals['token']) // drops from db if found : null; if ($userid) { $this->debug->info('resuming from persist token'); $this->setCurrent($userid); $this->setPersistToken(); $this->auth_via = 'cookie'; $this->auth = 1; } } /* Social Cookie? */ if (empty($this->auth)) { } if (!empty($this->auth)) { $this->user['_ts_cur'] = time(); } $this->debug->groupEnd(); }
[ "private", "function", "resume", "(", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "if", "(", "isset", "(", "$", "_SESSION", ")", ")", "{", "$", "this", "->", "user", "=", "ArrayUtil", "::", "pathGet", "(", "$", "_SESSION", ",", "$", "this", "->", "cfg", "[", "'sessionPath'", "]", ")", ";", "}", "/*\n\t\t\tSession?\n\t\t*/", "if", "(", "!", "empty", "(", "$", "this", "->", "user", ")", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'resuming from session'", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "user", "[", "'_ts_cur'", "]", ")", ")", "{", "$", "this", "->", "user", "[", "'lastactivity'", "]", "=", "$", "this", "->", "user", "[", "'_ts_cur'", "]", ";", "}", "$", "this", "->", "userid", "=", "$", "this", "->", "user", "[", "'userid'", "]", ";", "$", "this", "->", "auth_via", "=", "'session'", ";", "$", "this", "->", "auth", "=", "2", ";", "if", "(", "$", "this", "->", "user", "[", "'lastactivity'", "]", "+", "$", "this", "->", "cfg", "[", "'maxIdle'", "]", "<", "time", "(", ")", ")", "{", "$", "this", "->", "debug", "->", "warn", "(", "'idle'", ")", ";", "$", "this", "->", "debug", "->", "log", "(", "'lastactivity'", ",", "$", "this", "->", "user", "[", "'lastactivity'", "]", ")", ";", "$", "this", "->", "auth", "=", "0", ";", "}", "else", "{", "$", "this", "->", "update", "(", "array", "(", "'lastactivity'", "=>", "'NOW()'", ")", ")", ";", "}", "}", "/*\n\t\t\tPersist cookie?\n\t\t*/", "if", "(", "empty", "(", "$", "this", "->", "auth", ")", "&&", "isset", "(", "$", "_COOKIE", "[", "$", "this", "->", "cfg", "[", "'persistCookie'", "]", "[", "'name'", "]", "]", ")", ")", "{", "$", "persist_vals", "=", "Cookie", "::", "get", "(", "$", "this", "->", "cfg", "[", "'persistCookie'", "]", "[", "'name'", "]", ")", ";", "$", "userid", "=", "isset", "(", "$", "persist_vals", "[", "'username'", "]", ")", "&&", "isset", "(", "$", "persist_vals", "[", "'token'", "]", ")", "?", "$", "this", "->", "verifyPersistToken", "(", "$", "persist_vals", "[", "'username'", "]", ",", "$", "persist_vals", "[", "'token'", "]", ")", "// drops from db if found", ":", "null", ";", "if", "(", "$", "userid", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'resuming from persist token'", ")", ";", "$", "this", "->", "setCurrent", "(", "$", "userid", ")", ";", "$", "this", "->", "setPersistToken", "(", ")", ";", "$", "this", "->", "auth_via", "=", "'cookie'", ";", "$", "this", "->", "auth", "=", "1", ";", "}", "}", "/*\n\t\t\tSocial Cookie?\n\t\t*/", "if", "(", "empty", "(", "$", "this", "->", "auth", ")", ")", "{", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "auth", ")", ")", "{", "$", "this", "->", "user", "[", "'_ts_cur'", "]", "=", "time", "(", ")", ";", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "}" ]
attempts to load user data from session or via persistant login cookie @return void
[ "attempts", "to", "load", "user", "data", "from", "session", "or", "via", "persistant", "login", "cookie" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/User.php#L826-L876
268
sypherlev/blueprint
src/QueryBuilders/Postgres/PostgresSource.php
PostgresSource.lastInsertId
public function lastInsertId($name = null) { // checking for nulls, Postgres doesn't handle nulls at all here if(is_null($name)) { throw new \Exception('Postgres requires a sequence name to get the last insert ID'); } // use the primary key to try to get the sequence name $primary_key = $this->getPrimaryKey($name); $id = $this->pdo->lastInsertId($name.'_'.$primary_key.'_seq'); if($id === false || is_null($id)) { throw new \Exception("Can't get last insert ID for ".$name."; you must supply the correct sequence name."); } return $id; }
php
public function lastInsertId($name = null) { // checking for nulls, Postgres doesn't handle nulls at all here if(is_null($name)) { throw new \Exception('Postgres requires a sequence name to get the last insert ID'); } // use the primary key to try to get the sequence name $primary_key = $this->getPrimaryKey($name); $id = $this->pdo->lastInsertId($name.'_'.$primary_key.'_seq'); if($id === false || is_null($id)) { throw new \Exception("Can't get last insert ID for ".$name."; you must supply the correct sequence name."); } return $id; }
[ "public", "function", "lastInsertId", "(", "$", "name", "=", "null", ")", "{", "// checking for nulls, Postgres doesn't handle nulls at all here", "if", "(", "is_null", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Postgres requires a sequence name to get the last insert ID'", ")", ";", "}", "// use the primary key to try to get the sequence name", "$", "primary_key", "=", "$", "this", "->", "getPrimaryKey", "(", "$", "name", ")", ";", "$", "id", "=", "$", "this", "->", "pdo", "->", "lastInsertId", "(", "$", "name", ".", "'_'", ".", "$", "primary_key", ".", "'_seq'", ")", ";", "if", "(", "$", "id", "===", "false", "||", "is_null", "(", "$", "id", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Can't get last insert ID for \"", ".", "$", "name", ".", "\"; you must supply the correct sequence name.\"", ")", ";", "}", "return", "$", "id", ";", "}" ]
Wrappers for some useful PDO functions
[ "Wrappers", "for", "some", "useful", "PDO", "functions" ]
11e36d5aae192f179cc7a2872013d4190d52f2e5
https://github.com/sypherlev/blueprint/blob/11e36d5aae192f179cc7a2872013d4190d52f2e5/src/QueryBuilders/Postgres/PostgresSource.php#L224-L238
269
sellerlabs/nucleus
src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php
ComplexFactory.toLeftFoldable
public static function toLeftFoldable($input) { Arguments::define(Boa::leftFoldable())->check($input); if ($input instanceof LeftFoldableInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return static::toList($input); } if ($input instanceof Traversable) { return new TraversableLeftFoldable($input); } throw new CoreException('Unable to build LeftFoldable'); }
php
public static function toLeftFoldable($input) { Arguments::define(Boa::leftFoldable())->check($input); if ($input instanceof LeftFoldableInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return static::toList($input); } if ($input instanceof Traversable) { return new TraversableLeftFoldable($input); } throw new CoreException('Unable to build LeftFoldable'); }
[ "public", "static", "function", "toLeftFoldable", "(", "$", "input", ")", "{", "Arguments", "::", "define", "(", "Boa", "::", "leftFoldable", "(", ")", ")", "->", "check", "(", "$", "input", ")", ";", "if", "(", "$", "input", "instanceof", "LeftFoldableInterface", ")", "{", "return", "$", "input", ";", "}", "if", "(", "is_array", "(", "$", "input", ")", "||", "$", "input", "instanceof", "ArrayObject", ")", "{", "return", "static", "::", "toList", "(", "$", "input", ")", ";", "}", "if", "(", "$", "input", "instanceof", "Traversable", ")", "{", "return", "new", "TraversableLeftFoldable", "(", "$", "input", ")", ";", "}", "throw", "new", "CoreException", "(", "'Unable to build LeftFoldable'", ")", ";", "}" ]
Wrap the provided value inside a LeftFoldable. @param array|ArrayObject|Traversable|LeftFoldableInterface $input @return ArrayList|TraversableLeftFoldable @throws CoreException @throws InvalidArgumentException
[ "Wrap", "the", "provided", "value", "inside", "a", "LeftFoldable", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php#L41-L58
270
sellerlabs/nucleus
src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php
ComplexFactory.toFunctor
public static function toFunctor($input) { Arguments::define(Boa::leftFoldable())->check($input); if ($input instanceof FunctorInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return static::toList($input); } throw new CoreException('Unable to build Functor'); }
php
public static function toFunctor($input) { Arguments::define(Boa::leftFoldable())->check($input); if ($input instanceof FunctorInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return static::toList($input); } throw new CoreException('Unable to build Functor'); }
[ "public", "static", "function", "toFunctor", "(", "$", "input", ")", "{", "Arguments", "::", "define", "(", "Boa", "::", "leftFoldable", "(", ")", ")", "->", "check", "(", "$", "input", ")", ";", "if", "(", "$", "input", "instanceof", "FunctorInterface", ")", "{", "return", "$", "input", ";", "}", "if", "(", "is_array", "(", "$", "input", ")", "||", "$", "input", "instanceof", "ArrayObject", ")", "{", "return", "static", "::", "toList", "(", "$", "input", ")", ";", "}", "throw", "new", "CoreException", "(", "'Unable to build Functor'", ")", ";", "}" ]
Wrap the provided value inside a Functor. @param array|ArrayObject|Traversable|FunctorInterface $input @return ArrayList|TraversableLeftFoldable @throws CoreException
[ "Wrap", "the", "provided", "value", "inside", "a", "Functor", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php#L68-L81
271
sellerlabs/nucleus
src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php
ComplexFactory.toList
public static function toList($input) { Arguments::define(Boa::lst())->check($input); if ($input instanceof ListInterface) { return $input; } return ArrayList::of($input); }
php
public static function toList($input) { Arguments::define(Boa::lst())->check($input); if ($input instanceof ListInterface) { return $input; } return ArrayList::of($input); }
[ "public", "static", "function", "toList", "(", "$", "input", ")", "{", "Arguments", "::", "define", "(", "Boa", "::", "lst", "(", ")", ")", "->", "check", "(", "$", "input", ")", ";", "if", "(", "$", "input", "instanceof", "ListInterface", ")", "{", "return", "$", "input", ";", "}", "return", "ArrayList", "::", "of", "(", "$", "input", ")", ";", "}" ]
Wrap provided value inside a List. @param array|ArrayObject|ListInterface $input @return ArrayList @throws InvalidArgumentException
[ "Wrap", "provided", "value", "inside", "a", "List", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php#L91-L100
272
sellerlabs/nucleus
src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php
ComplexFactory.toFoldable
public static function toFoldable($input) { Arguments::define(Boa::foldable())->check($input); if ($input instanceof FoldableInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return static::toList($input); } throw new CoreException('Unable to build Foldable'); }
php
public static function toFoldable($input) { Arguments::define(Boa::foldable())->check($input); if ($input instanceof FoldableInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return static::toList($input); } throw new CoreException('Unable to build Foldable'); }
[ "public", "static", "function", "toFoldable", "(", "$", "input", ")", "{", "Arguments", "::", "define", "(", "Boa", "::", "foldable", "(", ")", ")", "->", "check", "(", "$", "input", ")", ";", "if", "(", "$", "input", "instanceof", "FoldableInterface", ")", "{", "return", "$", "input", ";", "}", "if", "(", "is_array", "(", "$", "input", ")", "||", "$", "input", "instanceof", "ArrayObject", ")", "{", "return", "static", "::", "toList", "(", "$", "input", ")", ";", "}", "throw", "new", "CoreException", "(", "'Unable to build Foldable'", ")", ";", "}" ]
Wrap provided value inside a Foldable. @param array|ArrayObject|FoldableInterface $input @return ArrayList @throws CoreException @throws InvalidArgumentException
[ "Wrap", "provided", "value", "inside", "a", "Foldable", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php#L111-L124
273
sellerlabs/nucleus
src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php
ComplexFactory.toReadMap
public static function toReadMap($input) { Arguments::define(Boa::readMap())->check($input); if ($input instanceof ReadMapInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject || $input instanceof ArrayAccess ) { return static::toMap($input); } if ($input instanceof Traversable) { return new TraversableLeftFoldable($input); } throw new CoreException('Unable to build ReadMap'); }
php
public static function toReadMap($input) { Arguments::define(Boa::readMap())->check($input); if ($input instanceof ReadMapInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject || $input instanceof ArrayAccess ) { return static::toMap($input); } if ($input instanceof Traversable) { return new TraversableLeftFoldable($input); } throw new CoreException('Unable to build ReadMap'); }
[ "public", "static", "function", "toReadMap", "(", "$", "input", ")", "{", "Arguments", "::", "define", "(", "Boa", "::", "readMap", "(", ")", ")", "->", "check", "(", "$", "input", ")", ";", "if", "(", "$", "input", "instanceof", "ReadMapInterface", ")", "{", "return", "$", "input", ";", "}", "if", "(", "is_array", "(", "$", "input", ")", "||", "$", "input", "instanceof", "ArrayObject", "||", "$", "input", "instanceof", "ArrayAccess", ")", "{", "return", "static", "::", "toMap", "(", "$", "input", ")", ";", "}", "if", "(", "$", "input", "instanceof", "Traversable", ")", "{", "return", "new", "TraversableLeftFoldable", "(", "$", "input", ")", ";", "}", "throw", "new", "CoreException", "(", "'Unable to build ReadMap'", ")", ";", "}" ]
Wrap the provided value inside a ReadMap. @param array|ArrayObject|ArrayAccess|Traversable|ReadMapInterface $input @return ArrayAccessMap|ArrayList|TraversableLeftFoldable @throws CoreException @throws InvalidArgumentException
[ "Wrap", "the", "provided", "value", "inside", "a", "ReadMap", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php#L135-L155
274
sellerlabs/nucleus
src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php
ComplexFactory.toMap
public static function toMap($input) { Arguments::define(Boa::map())->check($input); if ($input instanceof MapInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return new ArrayMap($input); } if ($input instanceof ArrayAccess) { return new ArrayAccessMap($input); } throw new CoreException('Unable to build Map'); }
php
public static function toMap($input) { Arguments::define(Boa::map())->check($input); if ($input instanceof MapInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return new ArrayMap($input); } if ($input instanceof ArrayAccess) { return new ArrayAccessMap($input); } throw new CoreException('Unable to build Map'); }
[ "public", "static", "function", "toMap", "(", "$", "input", ")", "{", "Arguments", "::", "define", "(", "Boa", "::", "map", "(", ")", ")", "->", "check", "(", "$", "input", ")", ";", "if", "(", "$", "input", "instanceof", "MapInterface", ")", "{", "return", "$", "input", ";", "}", "if", "(", "is_array", "(", "$", "input", ")", "||", "$", "input", "instanceof", "ArrayObject", ")", "{", "return", "new", "ArrayMap", "(", "$", "input", ")", ";", "}", "if", "(", "$", "input", "instanceof", "ArrayAccess", ")", "{", "return", "new", "ArrayAccessMap", "(", "$", "input", ")", ";", "}", "throw", "new", "CoreException", "(", "'Unable to build Map'", ")", ";", "}" ]
Wrap the provided value inside a Map. @param array|ArrayObject|ArrayAccess|MapInterface $input @return ArrayAccessMap|ArrayList @throws CoreException @throws InvalidArgumentException
[ "Wrap", "the", "provided", "value", "inside", "a", "Map", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/Factories/ComplexFactory.php#L166-L183
275
gap-db/orm
GapOrm/Mapper/OrmMapper.php
OrmMapper.clearParams
protected function clearParams() { $this->limit = null; $this->limitStart = false; $this->limitEnd = false; $this->where = null; $this->orderBy = null; $this->groupBy = null; $this->in = null; $this->params = []; $this->joins = []; $this->query = ''; }
php
protected function clearParams() { $this->limit = null; $this->limitStart = false; $this->limitEnd = false; $this->where = null; $this->orderBy = null; $this->groupBy = null; $this->in = null; $this->params = []; $this->joins = []; $this->query = ''; }
[ "protected", "function", "clearParams", "(", ")", "{", "$", "this", "->", "limit", "=", "null", ";", "$", "this", "->", "limitStart", "=", "false", ";", "$", "this", "->", "limitEnd", "=", "false", ";", "$", "this", "->", "where", "=", "null", ";", "$", "this", "->", "orderBy", "=", "null", ";", "$", "this", "->", "groupBy", "=", "null", ";", "$", "this", "->", "in", "=", "null", ";", "$", "this", "->", "params", "=", "[", "]", ";", "$", "this", "->", "joins", "=", "[", "]", ";", "$", "this", "->", "query", "=", "''", ";", "}" ]
Set params default value
[ "Set", "params", "default", "value" ]
bcd8e3d27b19b14814d3207489071c4a250a6ac5
https://github.com/gap-db/orm/blob/bcd8e3d27b19b14814d3207489071c4a250a6ac5/GapOrm/Mapper/OrmMapper.php#L238-L250
276
rafaelnajera/matcher
Matcher/Condition.php
Condition.match
public function match($input) { if ($this->token instanceof Token) { if ($this->token->matches($input)) { return true; } return false; } if ($this->token === $input) { return true; } return false; }
php
public function match($input) { if ($this->token instanceof Token) { if ($this->token->matches($input)) { return true; } return false; } if ($this->token === $input) { return true; } return false; }
[ "public", "function", "match", "(", "$", "input", ")", "{", "if", "(", "$", "this", "->", "token", "instanceof", "Token", ")", "{", "if", "(", "$", "this", "->", "token", "->", "matches", "(", "$", "input", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}", "if", "(", "$", "this", "->", "token", "===", "$", "input", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns true is the given token matches the Condition's token @param any|Token $input @return boolean
[ "Returns", "true", "is", "the", "given", "token", "matches", "the", "Condition", "s", "token" ]
f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf
https://github.com/rafaelnajera/matcher/blob/f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf/Matcher/Condition.php#L70-L83
277
rafaelnajera/matcher
Matcher/Condition.php
Condition.matched
public function matched($input) { if ($this->token instanceof Token) { return $this->token->matched($input); } return $input; }
php
public function matched($input) { if ($this->token instanceof Token) { return $this->token->matched($input); } return $input; }
[ "public", "function", "matched", "(", "$", "input", ")", "{", "if", "(", "$", "this", "->", "token", "instanceof", "Token", ")", "{", "return", "$", "this", "->", "token", "->", "matched", "(", "$", "input", ")", ";", "}", "return", "$", "input", ";", "}" ]
Returns information about the matched token. If the condition's token implements the Token interface the token's matched() method will be called. If not, returns a copy of the token @return any
[ "Returns", "information", "about", "the", "matched", "token", "." ]
f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf
https://github.com/rafaelnajera/matcher/blob/f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf/Matcher/Condition.php#L94-L101
278
cundd/test-flight
src/Output/AbstractPrinter.php
AbstractPrinter.colorize
public function colorize(string $startColor, string $text, string $endColor = self::NORMAL): string { if ($this->getEnableColoredOutput()) { return $startColor . $text . $endColor; } return $text; }
php
public function colorize(string $startColor, string $text, string $endColor = self::NORMAL): string { if ($this->getEnableColoredOutput()) { return $startColor . $text . $endColor; } return $text; }
[ "public", "function", "colorize", "(", "string", "$", "startColor", ",", "string", "$", "text", ",", "string", "$", "endColor", "=", "self", "::", "NORMAL", ")", ":", "string", "{", "if", "(", "$", "this", "->", "getEnableColoredOutput", "(", ")", ")", "{", "return", "$", "startColor", ".", "$", "text", ".", "$", "endColor", ";", "}", "return", "$", "text", ";", "}" ]
Wrap the text in colors @param string $startColor @param string $text @param string $endColor @return string
[ "Wrap", "the", "text", "in", "colors" ]
9d8424dfb586f823f9dad2dcb81ff3986e255d56
https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Output/AbstractPrinter.php#L178-L185
279
Puzzlout/FrameworkMvcLegacy
src/Core/DirectoryManager.php
DirectoryManager.GetFileNames
public static function GetFileNames($dir, $filters = array()) { $filenames = array_diff(scandir($dir), array('..', '.')); if (count($filters > 0)) { $filenames = self::FilterArray($filenames, $filters); } return $filenames; }
php
public static function GetFileNames($dir, $filters = array()) { $filenames = array_diff(scandir($dir), array('..', '.')); if (count($filters > 0)) { $filenames = self::FilterArray($filenames, $filters); } return $filenames; }
[ "public", "static", "function", "GetFileNames", "(", "$", "dir", ",", "$", "filters", "=", "array", "(", ")", ")", "{", "$", "filenames", "=", "array_diff", "(", "scandir", "(", "$", "dir", ")", ",", "array", "(", "'..'", ",", "'.'", ")", ")", ";", "if", "(", "count", "(", "$", "filters", ">", "0", ")", ")", "{", "$", "filenames", "=", "self", "::", "FilterArray", "(", "$", "filenames", ",", "$", "filters", ")", ";", "}", "return", "$", "filenames", ";", "}" ]
Get the file paths for the current directory @param string $dir Directory value to scan. @return array List of files found in directory scanned.
[ "Get", "the", "file", "paths", "for", "the", "current", "directory" ]
14e0fc5b16978cbd209f552ee9c649f66a0dfc6e
https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Core/DirectoryManager.php#L39-L45
280
Puzzlout/FrameworkMvcLegacy
src/Core/DirectoryManager.php
DirectoryManager.FilterArray
public static function FilterArray($targetArray, $valuesToRemove) { if (is_array($valuesToRemove)) { foreach ($valuesToRemove as $value) { if (($key = array_search($value, $targetArray)) !== false) { unset($targetArray[$key]); } else { //todo: log that the $value to remove was not found. } } } else { //todo: log that the call was made but that $valuesToRemove was not an array. } return $targetArray; }
php
public static function FilterArray($targetArray, $valuesToRemove) { if (is_array($valuesToRemove)) { foreach ($valuesToRemove as $value) { if (($key = array_search($value, $targetArray)) !== false) { unset($targetArray[$key]); } else { //todo: log that the $value to remove was not found. } } } else { //todo: log that the call was made but that $valuesToRemove was not an array. } return $targetArray; }
[ "public", "static", "function", "FilterArray", "(", "$", "targetArray", ",", "$", "valuesToRemove", ")", "{", "if", "(", "is_array", "(", "$", "valuesToRemove", ")", ")", "{", "foreach", "(", "$", "valuesToRemove", "as", "$", "value", ")", "{", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "value", ",", "$", "targetArray", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "targetArray", "[", "$", "key", "]", ")", ";", "}", "else", "{", "//todo: log that the $value to remove was not found.", "}", "}", "}", "else", "{", "//todo: log that the call was made but that $valuesToRemove was not an array.", "}", "return", "$", "targetArray", ";", "}" ]
Filter values out of a given array of values. @param array (of mixed) $targetArray : the list of values @param array(of mixed) $valuesToRemove : the values to remove from $targetArray
[ "Filter", "values", "out", "of", "a", "given", "array", "of", "values", "." ]
14e0fc5b16978cbd209f552ee9c649f66a0dfc6e
https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Core/DirectoryManager.php#L122-L135
281
Puzzlout/FrameworkMvcLegacy
src/Core/DirectoryManager.php
DirectoryManager.GetApplicationRootDir
public static function GetApplicationRootDir() { return \Puzzlout\Framework\Enums\ApplicationFolderName::AppsFolderName . "APP_NAME" . \Puzzlout\Framework\Enums\ApplicationFolderName::ViewsFolderName; }
php
public static function GetApplicationRootDir() { return \Puzzlout\Framework\Enums\ApplicationFolderName::AppsFolderName . "APP_NAME" . \Puzzlout\Framework\Enums\ApplicationFolderName::ViewsFolderName; }
[ "public", "static", "function", "GetApplicationRootDir", "(", ")", "{", "return", "\\", "Puzzlout", "\\", "Framework", "\\", "Enums", "\\", "ApplicationFolderName", "::", "AppsFolderName", ".", "\"APP_NAME\"", ".", "\\", "Puzzlout", "\\", "Framework", "\\", "Enums", "\\", "ApplicationFolderName", "::", "ViewsFolderName", ";", "}" ]
Get the directory where are stored the current Application views. @return string The directory
[ "Get", "the", "directory", "where", "are", "stored", "the", "current", "Application", "views", "." ]
14e0fc5b16978cbd209f552ee9c649f66a0dfc6e
https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Core/DirectoryManager.php#L151-L155
282
bishopb/vanilla
library/database/class.mysqlstructure.php
Gdn_MySQLStructure.View
public function View($Name, $SQL) { if(is_string($SQL)) { $SQLString = $SQL; $SQL = NULL; } else { $SQLString = $SQL->GetSelect(); } $Result = $this->Query('create or replace view '.$this->_DatabasePrefix.$Name." as \n".$SQLString); if(!is_null($SQL)) { $SQL->Reset(); } }
php
public function View($Name, $SQL) { if(is_string($SQL)) { $SQLString = $SQL; $SQL = NULL; } else { $SQLString = $SQL->GetSelect(); } $Result = $this->Query('create or replace view '.$this->_DatabasePrefix.$Name." as \n".$SQLString); if(!is_null($SQL)) { $SQL->Reset(); } }
[ "public", "function", "View", "(", "$", "Name", ",", "$", "SQL", ")", "{", "if", "(", "is_string", "(", "$", "SQL", ")", ")", "{", "$", "SQLString", "=", "$", "SQL", ";", "$", "SQL", "=", "NULL", ";", "}", "else", "{", "$", "SQLString", "=", "$", "SQL", "->", "GetSelect", "(", ")", ";", "}", "$", "Result", "=", "$", "this", "->", "Query", "(", "'create or replace view '", ".", "$", "this", "->", "_DatabasePrefix", ".", "$", "Name", ".", "\" as \\n\"", ".", "$", "SQLString", ")", ";", "if", "(", "!", "is_null", "(", "$", "SQL", ")", ")", "{", "$", "SQL", "->", "Reset", "(", ")", ";", "}", "}" ]
Specifies the name of the view to create or modify. @param string $Name The name of the view. @param string $Query The actual query to create as the view. Typically this can be generated with the $Database object.
[ "Specifies", "the", "name", "of", "the", "view", "to", "create", "or", "modify", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/database/class.mysqlstructure.php#L138-L150
283
vinala/kernel
src/Validation/ValidationResult.php
ValidationResult.error
public function error() { $errors = $this->validator->errors(); $this->error = empty($errors) ?: array_pop($errors)[0]; return $this->error; }
php
public function error() { $errors = $this->validator->errors(); $this->error = empty($errors) ?: array_pop($errors)[0]; return $this->error; }
[ "public", "function", "error", "(", ")", "{", "$", "errors", "=", "$", "this", "->", "validator", "->", "errors", "(", ")", ";", "$", "this", "->", "error", "=", "empty", "(", "$", "errors", ")", "?", ":", "array_pop", "(", "$", "errors", ")", "[", "0", "]", ";", "return", "$", "this", "->", "error", ";", "}" ]
Get first validation error if exists. @return string
[ "Get", "first", "validation", "error", "if", "exists", "." ]
346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a
https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Validation/ValidationResult.php#L74-L81
284
squire-assistant/console
Input/InputOption.php
InputOption.equals
public function equals(InputOption $option) { return $option->getName() === $this->getName() && $option->getShortcut() === $this->getShortcut() && $option->getDefault() === $this->getDefault() && $option->isArray() === $this->isArray() && $option->isValueRequired() === $this->isValueRequired() && $option->isValueOptional() === $this->isValueOptional() ; }
php
public function equals(InputOption $option) { return $option->getName() === $this->getName() && $option->getShortcut() === $this->getShortcut() && $option->getDefault() === $this->getDefault() && $option->isArray() === $this->isArray() && $option->isValueRequired() === $this->isValueRequired() && $option->isValueOptional() === $this->isValueOptional() ; }
[ "public", "function", "equals", "(", "InputOption", "$", "option", ")", "{", "return", "$", "option", "->", "getName", "(", ")", "===", "$", "this", "->", "getName", "(", ")", "&&", "$", "option", "->", "getShortcut", "(", ")", "===", "$", "this", "->", "getShortcut", "(", ")", "&&", "$", "option", "->", "getDefault", "(", ")", "===", "$", "this", "->", "getDefault", "(", ")", "&&", "$", "option", "->", "isArray", "(", ")", "===", "$", "this", "->", "isArray", "(", ")", "&&", "$", "option", "->", "isValueRequired", "(", ")", "===", "$", "this", "->", "isValueRequired", "(", ")", "&&", "$", "option", "->", "isValueOptional", "(", ")", "===", "$", "this", "->", "isValueOptional", "(", ")", ";", "}" ]
Checks whether the given option equals this one. @param InputOption $option option to compare @return bool
[ "Checks", "whether", "the", "given", "option", "equals", "this", "one", "." ]
9e16b975a3b9403af52e2d1b465a625e8936076c
https://github.com/squire-assistant/console/blob/9e16b975a3b9403af52e2d1b465a625e8936076c/Input/InputOption.php#L202-L211
285
DivideBV/PHPDivideIQ
src/Settings.php
Settings.getPath
public function getPath($serviceName) { if (in_array($serviceName, $this->services)) { return str_replace('_', '/', $serviceName); } else { $services = implode(', ', $this->services); throw new \Exception("Service \"{$serviceName}\" is not one of: {$services}"); } }
php
public function getPath($serviceName) { if (in_array($serviceName, $this->services)) { return str_replace('_', '/', $serviceName); } else { $services = implode(', ', $this->services); throw new \Exception("Service \"{$serviceName}\" is not one of: {$services}"); } }
[ "public", "function", "getPath", "(", "$", "serviceName", ")", "{", "if", "(", "in_array", "(", "$", "serviceName", ",", "$", "this", "->", "services", ")", ")", "{", "return", "str_replace", "(", "'_'", ",", "'/'", ",", "$", "serviceName", ")", ";", "}", "else", "{", "$", "services", "=", "implode", "(", "', '", ",", "$", "this", "->", "services", ")", ";", "throw", "new", "\\", "Exception", "(", "\"Service \\\"{$serviceName}\\\" is not one of: {$services}\"", ")", ";", "}", "}" ]
Gets the path of a service. @param string $serviceName @return string
[ "Gets", "the", "path", "of", "a", "service", "." ]
bd12e3c226b061d7152f93ab1195fbaaf074b20d
https://github.com/DivideBV/PHPDivideIQ/blob/bd12e3c226b061d7152f93ab1195fbaaf074b20d/src/Settings.php#L57-L65
286
Laralabs/connection-loader
src/Laralabs/ConnectionLoader/ConnectionLoader.php
ConnectionLoader.checkConnections
public static function checkConnections($connection_name, $table, $check) { if($check === true) { $connections = DB::connection($connection_name)->table($table)->get(); foreach($connections as $connection) { $name = $connection->name; try{ $testConnection = DB::connection($name)->getPdo(); }catch(\Exception $e) { $error = $e->getMessage(); \error_log($error); } if(!empty($testConnection) && empty($error)) { $update = DB::connection($connection_name)->table($table)->where('name', $name)->update(['status' => true]); } else { $update = DB::connection($connection_name)->table($table)->where('name', $name)->update(['status' => false]); } } } }
php
public static function checkConnections($connection_name, $table, $check) { if($check === true) { $connections = DB::connection($connection_name)->table($table)->get(); foreach($connections as $connection) { $name = $connection->name; try{ $testConnection = DB::connection($name)->getPdo(); }catch(\Exception $e) { $error = $e->getMessage(); \error_log($error); } if(!empty($testConnection) && empty($error)) { $update = DB::connection($connection_name)->table($table)->where('name', $name)->update(['status' => true]); } else { $update = DB::connection($connection_name)->table($table)->where('name', $name)->update(['status' => false]); } } } }
[ "public", "static", "function", "checkConnections", "(", "$", "connection_name", ",", "$", "table", ",", "$", "check", ")", "{", "if", "(", "$", "check", "===", "true", ")", "{", "$", "connections", "=", "DB", "::", "connection", "(", "$", "connection_name", ")", "->", "table", "(", "$", "table", ")", "->", "get", "(", ")", ";", "foreach", "(", "$", "connections", "as", "$", "connection", ")", "{", "$", "name", "=", "$", "connection", "->", "name", ";", "try", "{", "$", "testConnection", "=", "DB", "::", "connection", "(", "$", "name", ")", "->", "getPdo", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "error", "=", "$", "e", "->", "getMessage", "(", ")", ";", "\\", "error_log", "(", "$", "error", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "testConnection", ")", "&&", "empty", "(", "$", "error", ")", ")", "{", "$", "update", "=", "DB", "::", "connection", "(", "$", "connection_name", ")", "->", "table", "(", "$", "table", ")", "->", "where", "(", "'name'", ",", "$", "name", ")", "->", "update", "(", "[", "'status'", "=>", "true", "]", ")", ";", "}", "else", "{", "$", "update", "=", "DB", "::", "connection", "(", "$", "connection_name", ")", "->", "table", "(", "$", "table", ")", "->", "where", "(", "'name'", ",", "$", "name", ")", "->", "update", "(", "[", "'status'", "=>", "false", "]", ")", ";", "}", "}", "}", "}" ]
checkConnections function. If enabled in the configuration file this will check the connections and update the status field in the table provided for each connection with a boolean value. @param $connection_name @param $table @param $check
[ "checkConnections", "function", "." ]
97afc738d54d6c8b2e01af02dcd5b5d0f699e9d0
https://github.com/Laralabs/connection-loader/blob/97afc738d54d6c8b2e01af02dcd5b5d0f699e9d0/src/Laralabs/ConnectionLoader/ConnectionLoader.php#L194-L221
287
Laralabs/connection-loader
src/Laralabs/ConnectionLoader/ConnectionLoader.php
ConnectionLoader.random_string
public static function random_string($length) { $key = ''; $keys = array_merge(range(0, 9), range('a', 'z')); for ($i = 0; $i < $length; $i++) { $key .= $keys[array_rand($keys)]; } return $key; }
php
public static function random_string($length) { $key = ''; $keys = array_merge(range(0, 9), range('a', 'z')); for ($i = 0; $i < $length; $i++) { $key .= $keys[array_rand($keys)]; } return $key; }
[ "public", "static", "function", "random_string", "(", "$", "length", ")", "{", "$", "key", "=", "''", ";", "$", "keys", "=", "array_merge", "(", "range", "(", "0", ",", "9", ")", ",", "range", "(", "'a'", ",", "'z'", ")", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "key", ".=", "$", "keys", "[", "array_rand", "(", "$", "keys", ")", "]", ";", "}", "return", "$", "key", ";", "}" ]
random_string function Does what it says on the tin. @param $length @return string
[ "random_string", "function", "Does", "what", "it", "says", "on", "the", "tin", "." ]
97afc738d54d6c8b2e01af02dcd5b5d0f699e9d0
https://github.com/Laralabs/connection-loader/blob/97afc738d54d6c8b2e01af02dcd5b5d0f699e9d0/src/Laralabs/ConnectionLoader/ConnectionLoader.php#L231-L240
288
digipolisgent/openbib-id-api
src/Value/DateTime/DateTime.php
DateTime.fromXml
public static function fromXml(\DOMNodeList $xml) { $value = null; if ($xml->length > 0) { $value = new \DateTimeImmutable($xml->item(0)->textContent); } return new static($value); }
php
public static function fromXml(\DOMNodeList $xml) { $value = null; if ($xml->length > 0) { $value = new \DateTimeImmutable($xml->item(0)->textContent); } return new static($value); }
[ "public", "static", "function", "fromXml", "(", "\\", "DOMNodeList", "$", "xml", ")", "{", "$", "value", "=", "null", ";", "if", "(", "$", "xml", "->", "length", ">", "0", ")", "{", "$", "value", "=", "new", "\\", "DateTimeImmutable", "(", "$", "xml", "->", "item", "(", "0", ")", "->", "textContent", ")", ";", "}", "return", "new", "static", "(", "$", "value", ")", ";", "}" ]
Builds a DateTime object from XML. @param \DOMNodeList $xml The xml tag containing the date. @return DateTime A DateTime object.
[ "Builds", "a", "DateTime", "object", "from", "XML", "." ]
79f58dec53a91f44333d10fa4ef79f85f31fc2de
https://github.com/digipolisgent/openbib-id-api/blob/79f58dec53a91f44333d10fa4ef79f85f31fc2de/src/Value/DateTime/DateTime.php#L37-L44
289
ringoteam/phpredmon-lib
src/Ringo/PhpRedmon/Model/Instance.php
Instance.addDatabase
public function addDatabase(Database $database) { if(!$this->getDatabases()->contains($database)) { $database->setId($this->getDatabases()->count()); $database->setInstance($this); $this->getDatabases()->add($database); } }
php
public function addDatabase(Database $database) { if(!$this->getDatabases()->contains($database)) { $database->setId($this->getDatabases()->count()); $database->setInstance($this); $this->getDatabases()->add($database); } }
[ "public", "function", "addDatabase", "(", "Database", "$", "database", ")", "{", "if", "(", "!", "$", "this", "->", "getDatabases", "(", ")", "->", "contains", "(", "$", "database", ")", ")", "{", "$", "database", "->", "setId", "(", "$", "this", "->", "getDatabases", "(", ")", "->", "count", "(", ")", ")", ";", "$", "database", "->", "setInstance", "(", "$", "this", ")", ";", "$", "this", "->", "getDatabases", "(", ")", "->", "add", "(", "$", "database", ")", ";", "}", "}" ]
Add database to the list @param Database $database
[ "Add", "database", "to", "the", "list" ]
41223e2a392bd168174d544186da6ef48b3d3e92
https://github.com/ringoteam/phpredmon-lib/blob/41223e2a392bd168174d544186da6ef48b3d3e92/src/Ringo/PhpRedmon/Model/Instance.php#L96-L103
290
ringoteam/phpredmon-lib
src/Ringo/PhpRedmon/Model/Instance.php
Instance.removeDatabase
public function removeDatabase(Database $database) { if($this->getDatabases()->contains($database)) { $this->getDatabases()->remove($database); } }
php
public function removeDatabase(Database $database) { if($this->getDatabases()->contains($database)) { $this->getDatabases()->remove($database); } }
[ "public", "function", "removeDatabase", "(", "Database", "$", "database", ")", "{", "if", "(", "$", "this", "->", "getDatabases", "(", ")", "->", "contains", "(", "$", "database", ")", ")", "{", "$", "this", "->", "getDatabases", "(", ")", "->", "remove", "(", "$", "database", ")", ";", "}", "}" ]
Remove database from the list @param Database $database
[ "Remove", "database", "from", "the", "list" ]
41223e2a392bd168174d544186da6ef48b3d3e92
https://github.com/ringoteam/phpredmon-lib/blob/41223e2a392bd168174d544186da6ef48b3d3e92/src/Ringo/PhpRedmon/Model/Instance.php#L110-L115
291
oaugustus/direct-silex-provider
src/Direct/DirectServiceProvider.php
DirectServiceProvider.boot
public function boot(Application $app) { // the direct api route $app->get('/api.js', function(Application $app){ return $app['direct.api']->getApi(); })->bind('directapi'); // the direct api route remoting description $app->get('/remoting.js', function(Application $app){ return $app['direct.api']->getRemoting(); }); // the direct router route $app->post('/route', function(Application $app){ // handle the route return $app['direct.router']->route(); }); }
php
public function boot(Application $app) { // the direct api route $app->get('/api.js', function(Application $app){ return $app['direct.api']->getApi(); })->bind('directapi'); // the direct api route remoting description $app->get('/remoting.js', function(Application $app){ return $app['direct.api']->getRemoting(); }); // the direct router route $app->post('/route', function(Application $app){ // handle the route return $app['direct.router']->route(); }); }
[ "public", "function", "boot", "(", "Application", "$", "app", ")", "{", "// the direct api route", "$", "app", "->", "get", "(", "'/api.js'", ",", "function", "(", "Application", "$", "app", ")", "{", "return", "$", "app", "[", "'direct.api'", "]", "->", "getApi", "(", ")", ";", "}", ")", "->", "bind", "(", "'directapi'", ")", ";", "// the direct api route remoting description", "$", "app", "->", "get", "(", "'/remoting.js'", ",", "function", "(", "Application", "$", "app", ")", "{", "return", "$", "app", "[", "'direct.api'", "]", "->", "getRemoting", "(", ")", ";", "}", ")", ";", "// the direct router route", "$", "app", "->", "post", "(", "'/route'", ",", "function", "(", "Application", "$", "app", ")", "{", "// handle the route", "return", "$", "app", "[", "'direct.router'", "]", "->", "route", "(", ")", ";", "}", ")", ";", "}" ]
Setup the application. @param Application $app
[ "Setup", "the", "application", "." ]
8d92afdf5ede04c3048cde82b9879de7e1d6c153
https://github.com/oaugustus/direct-silex-provider/blob/8d92afdf5ede04c3048cde82b9879de7e1d6c153/src/Direct/DirectServiceProvider.php#L48-L65
292
Jinxes/layton
Layton/Database/Manager/Connection.php
Connection.execute
public function execute($sql, array $parameters = []) { $sth = $this->prepare($sql); $sth->execute($parameters); return $sth; }
php
public function execute($sql, array $parameters = []) { $sth = $this->prepare($sql); $sth->execute($parameters); return $sth; }
[ "public", "function", "execute", "(", "$", "sql", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "sth", "=", "$", "this", "->", "prepare", "(", "$", "sql", ")", ";", "$", "sth", "->", "execute", "(", "$", "parameters", ")", ";", "return", "$", "sth", ";", "}" ]
Prepares and executes a prepared statement @param string $sql @param array $parameters @return \PDOStatement
[ "Prepares", "and", "executes", "a", "prepared", "statement" ]
27b8eab2c59b9887eb93e40a533eb77cc5690584
https://github.com/Jinxes/layton/blob/27b8eab2c59b9887eb93e40a533eb77cc5690584/Layton/Database/Manager/Connection.php#L44-L49
293
budkit/budkit-framework
src/Budkit/Event/Observer.php
Observer.trigger
public function trigger($event) { if (is_string($event)) { $event = new Event($event); } $listeners = $this->getListeners($event->name); if (empty($listeners)) { return $event; } //print_r($listeners); //die; //Priorities... the bigger the more urgent $urgency = ksort($listeners, SORT_NUMERIC); $callbacks = array_reverse($listeners, true); //Loop through callbacks; foreach ($callbacks as $priority => $listener) { if ($event->isStopped()) { break; } foreach ($listener as $callback) { if ($event->isStopped()) { break; } $this->propergate($event, $callback); } } return $event; }
php
public function trigger($event) { if (is_string($event)) { $event = new Event($event); } $listeners = $this->getListeners($event->name); if (empty($listeners)) { return $event; } //print_r($listeners); //die; //Priorities... the bigger the more urgent $urgency = ksort($listeners, SORT_NUMERIC); $callbacks = array_reverse($listeners, true); //Loop through callbacks; foreach ($callbacks as $priority => $listener) { if ($event->isStopped()) { break; } foreach ($listener as $callback) { if ($event->isStopped()) { break; } $this->propergate($event, $callback); } } return $event; }
[ "public", "function", "trigger", "(", "$", "event", ")", "{", "if", "(", "is_string", "(", "$", "event", ")", ")", "{", "$", "event", "=", "new", "Event", "(", "$", "event", ")", ";", "}", "$", "listeners", "=", "$", "this", "->", "getListeners", "(", "$", "event", "->", "name", ")", ";", "if", "(", "empty", "(", "$", "listeners", ")", ")", "{", "return", "$", "event", ";", "}", "//print_r($listeners);", "//die;", "//Priorities... the bigger the more urgent", "$", "urgency", "=", "ksort", "(", "$", "listeners", ",", "SORT_NUMERIC", ")", ";", "$", "callbacks", "=", "array_reverse", "(", "$", "listeners", ",", "true", ")", ";", "//Loop through callbacks;", "foreach", "(", "$", "callbacks", "as", "$", "priority", "=>", "$", "listener", ")", "{", "if", "(", "$", "event", "->", "isStopped", "(", ")", ")", "{", "break", ";", "}", "foreach", "(", "$", "listener", "as", "$", "callback", ")", "{", "if", "(", "$", "event", "->", "isStopped", "(", ")", ")", "{", "break", ";", "}", "$", "this", "->", "propergate", "(", "$", "event", ",", "$", "callback", ")", ";", "}", "}", "return", "$", "event", ";", "}" ]
Triggers an event; @param string $eventName @return void @author Livingstone Fultang
[ "Triggers", "an", "event", ";" ]
0635061815fe07a8c63f9514b845d199b3c0d485
https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Event/Observer.php#L110-L145
294
budkit/budkit-framework
src/Budkit/Event/Observer.php
Observer.getListeners
public function getListeners($eventName = null) { if (empty($eventName)) return $this->listeners; if (!empty($eventName) && !isset($this->listeners[$eventName])) return []; return $this->listeners[$eventName]; }
php
public function getListeners($eventName = null) { if (empty($eventName)) return $this->listeners; if (!empty($eventName) && !isset($this->listeners[$eventName])) return []; return $this->listeners[$eventName]; }
[ "public", "function", "getListeners", "(", "$", "eventName", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "eventName", ")", ")", "return", "$", "this", "->", "listeners", ";", "if", "(", "!", "empty", "(", "$", "eventName", ")", "&&", "!", "isset", "(", "$", "this", "->", "listeners", "[", "$", "eventName", "]", ")", ")", "return", "[", "]", ";", "return", "$", "this", "->", "listeners", "[", "$", "eventName", "]", ";", "}" ]
Returns the callbacks attached to a specific event; @param string $eventName @return void @author Livingstone Fultang
[ "Returns", "the", "callbacks", "attached", "to", "a", "specific", "event", ";" ]
0635061815fe07a8c63f9514b845d199b3c0d485
https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Event/Observer.php#L155-L162
295
budkit/budkit-framework
src/Budkit/Event/Observer.php
Observer.propergate
protected function propergate(&$event, $callback) { //Pass the event, the data can be obtained from $event->data; $result = call_user_func($callback['callable'], $event, $callback['params']); //Result false can be indication of an error? if ($result === false) { $event->stop(); } //Anything new to say? if ($result !== null) { $event->setResult($result); } }
php
protected function propergate(&$event, $callback) { //Pass the event, the data can be obtained from $event->data; $result = call_user_func($callback['callable'], $event, $callback['params']); //Result false can be indication of an error? if ($result === false) { $event->stop(); } //Anything new to say? if ($result !== null) { $event->setResult($result); } }
[ "protected", "function", "propergate", "(", "&", "$", "event", ",", "$", "callback", ")", "{", "//Pass the event, the data can be obtained from $event->data;", "$", "result", "=", "call_user_func", "(", "$", "callback", "[", "'callable'", "]", ",", "$", "event", ",", "$", "callback", "[", "'params'", "]", ")", ";", "//Result false can be indication of an error?", "if", "(", "$", "result", "===", "false", ")", "{", "$", "event", "->", "stop", "(", ")", ";", "}", "//Anything new to say?", "if", "(", "$", "result", "!==", "null", ")", "{", "$", "event", "->", "setResult", "(", "$", "result", ")", ";", "}", "}" ]
Propergate the event to all callbacks; @param string $event @param string $callback @return void @author Livingstone Fultang
[ "Propergate", "the", "event", "to", "all", "callbacks", ";" ]
0635061815fe07a8c63f9514b845d199b3c0d485
https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Event/Observer.php#L173-L188
296
newmythmedia/events
src/Events.php
Events.listeners
public function listeners($event_name) { // Read in our config/events file so that we have them all! if (! $this->have_read_from_file) { $this->readConfigFile(); } if (! isset($this->listeners[$event_name])) { return []; } // The list is not sorted if (! $this->listeners[$event_name][0]) { // Sort it! array_multisort($this->listeners[$event_name][1], SORT_NUMERIC, $this->listeners[$event_name][2]); // Mark it as sorted already! $this->listeners[$event_name][0] = true; } return $this->listeners[$event_name][2]; }
php
public function listeners($event_name) { // Read in our config/events file so that we have them all! if (! $this->have_read_from_file) { $this->readConfigFile(); } if (! isset($this->listeners[$event_name])) { return []; } // The list is not sorted if (! $this->listeners[$event_name][0]) { // Sort it! array_multisort($this->listeners[$event_name][1], SORT_NUMERIC, $this->listeners[$event_name][2]); // Mark it as sorted already! $this->listeners[$event_name][0] = true; } return $this->listeners[$event_name][2]; }
[ "public", "function", "listeners", "(", "$", "event_name", ")", "{", "// Read in our config/events file so that we have them all!", "if", "(", "!", "$", "this", "->", "have_read_from_file", ")", "{", "$", "this", "->", "readConfigFile", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "listeners", "[", "$", "event_name", "]", ")", ")", "{", "return", "[", "]", ";", "}", "// The list is not sorted", "if", "(", "!", "$", "this", "->", "listeners", "[", "$", "event_name", "]", "[", "0", "]", ")", "{", "// Sort it!", "array_multisort", "(", "$", "this", "->", "listeners", "[", "$", "event_name", "]", "[", "1", "]", ",", "SORT_NUMERIC", ",", "$", "this", "->", "listeners", "[", "$", "event_name", "]", "[", "2", "]", ")", ";", "// Mark it as sorted already!", "$", "this", "->", "listeners", "[", "$", "event_name", "]", "[", "0", "]", "=", "true", ";", "}", "return", "$", "this", "->", "listeners", "[", "$", "event_name", "]", "[", "2", "]", ";", "}" ]
Returns an array of listeners for a single event. They are sorted by priority. If the listener could not be found, returns FALSE, or TRUE if it was removed. @param $event_name @return array
[ "Returns", "an", "array", "of", "listeners", "for", "a", "single", "event", ".", "They", "are", "sorted", "by", "priority", "." ]
8a769b02ce682c9662ab65d6a48e2ceac178450f
https://github.com/newmythmedia/events/blob/8a769b02ce682c9662ab65d6a48e2ceac178450f/src/Events.php#L157-L181
297
newmythmedia/events
src/Events.php
Events.removeListener
public function removeListener($event_name, callable $listener) { // Read in our config/events file so that we have them all! if (! $this->have_read_from_file) { $this->readConfigFile(); } if (! isset($this->listeners[$event_name])) { return false; } foreach ($this->listeners[$event_name][2] as $index => $check) { if ($check === $listener) { unset($this->listeners[$event_name][1][$index]); unset($this->listeners[$event_name][2][$index]); return true; } } return false; }
php
public function removeListener($event_name, callable $listener) { // Read in our config/events file so that we have them all! if (! $this->have_read_from_file) { $this->readConfigFile(); } if (! isset($this->listeners[$event_name])) { return false; } foreach ($this->listeners[$event_name][2] as $index => $check) { if ($check === $listener) { unset($this->listeners[$event_name][1][$index]); unset($this->listeners[$event_name][2][$index]); return true; } } return false; }
[ "public", "function", "removeListener", "(", "$", "event_name", ",", "callable", "$", "listener", ")", "{", "// Read in our config/events file so that we have them all!", "if", "(", "!", "$", "this", "->", "have_read_from_file", ")", "{", "$", "this", "->", "readConfigFile", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "listeners", "[", "$", "event_name", "]", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "this", "->", "listeners", "[", "$", "event_name", "]", "[", "2", "]", "as", "$", "index", "=>", "$", "check", ")", "{", "if", "(", "$", "check", "===", "$", "listener", ")", "{", "unset", "(", "$", "this", "->", "listeners", "[", "$", "event_name", "]", "[", "1", "]", "[", "$", "index", "]", ")", ";", "unset", "(", "$", "this", "->", "listeners", "[", "$", "event_name", "]", "[", "2", "]", "[", "$", "index", "]", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Removes a single listener from an event. If the listener couldn't be found, returns FALSE, else TRUE if it was removed. @param $event_name @param callable $listener @return bool
[ "Removes", "a", "single", "listener", "from", "an", "event", "." ]
8a769b02ce682c9662ab65d6a48e2ceac178450f
https://github.com/newmythmedia/events/blob/8a769b02ce682c9662ab65d6a48e2ceac178450f/src/Events.php#L195-L220
298
gnkw/http
src/Gnkw/Http/Resource.php
Resource.xml
public function xml($type = 'dom') { $xml = $this->content; $type = trim(strtolower($type)); switch($type) { case 'dom': $xml = new \DOMDocument(); $xml->loadXML($this->content); break; case 'simple': $xml = new \SimpleXMLElement($this->content); break; } return $xml; }
php
public function xml($type = 'dom') { $xml = $this->content; $type = trim(strtolower($type)); switch($type) { case 'dom': $xml = new \DOMDocument(); $xml->loadXML($this->content); break; case 'simple': $xml = new \SimpleXMLElement($this->content); break; } return $xml; }
[ "public", "function", "xml", "(", "$", "type", "=", "'dom'", ")", "{", "$", "xml", "=", "$", "this", "->", "content", ";", "$", "type", "=", "trim", "(", "strtolower", "(", "$", "type", ")", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "'dom'", ":", "$", "xml", "=", "new", "\\", "DOMDocument", "(", ")", ";", "$", "xml", "->", "loadXML", "(", "$", "this", "->", "content", ")", ";", "break", ";", "case", "'simple'", ":", "$", "xml", "=", "new", "\\", "SimpleXMLElement", "(", "$", "this", "->", "content", ")", ";", "break", ";", "}", "return", "$", "xml", ";", "}" ]
Return the xml object of the ressource @param string $type The type of object (dom or simple) > dom = DOMDocument > simple = SimpleXMLElement @return DOMDocument or SimpleXMLElement
[ "Return", "the", "xml", "object", "of", "the", "ressource" ]
93b76d775cf5d3c4f6e49a48ac91c8ab39efa1e3
https://github.com/gnkw/http/blob/93b76d775cf5d3c4f6e49a48ac91c8ab39efa1e3/src/Gnkw/Http/Resource.php#L115-L131
299
gnkw/http
src/Gnkw/Http/Resource.php
Resource.content
public function content($arg=null) { switch($this->format) { case 'json': if(!isset($arg)) { $arg = false; } return $this->json($arg); break; case 'xml' : if(!isset($arg)) { $arg = 'dom'; } return $this->xml($arg); break; default : return $this->getContent(); break; } }
php
public function content($arg=null) { switch($this->format) { case 'json': if(!isset($arg)) { $arg = false; } return $this->json($arg); break; case 'xml' : if(!isset($arg)) { $arg = 'dom'; } return $this->xml($arg); break; default : return $this->getContent(); break; } }
[ "public", "function", "content", "(", "$", "arg", "=", "null", ")", "{", "switch", "(", "$", "this", "->", "format", ")", "{", "case", "'json'", ":", "if", "(", "!", "isset", "(", "$", "arg", ")", ")", "{", "$", "arg", "=", "false", ";", "}", "return", "$", "this", "->", "json", "(", "$", "arg", ")", ";", "break", ";", "case", "'xml'", ":", "if", "(", "!", "isset", "(", "$", "arg", ")", ")", "{", "$", "arg", "=", "'dom'", ";", "}", "return", "$", "this", "->", "xml", "(", "$", "arg", ")", ";", "break", ";", "default", ":", "return", "$", "this", "->", "getContent", "(", ")", ";", "break", ";", "}", "}" ]
Get the content of the ressource Return a result depending on the type of the resource @param mixed $arg The possible argument(s) of the method to call @return mixed
[ "Get", "the", "content", "of", "the", "ressource", "Return", "a", "result", "depending", "on", "the", "type", "of", "the", "resource" ]
93b76d775cf5d3c4f6e49a48ac91c8ab39efa1e3
https://github.com/gnkw/http/blob/93b76d775cf5d3c4f6e49a48ac91c8ab39efa1e3/src/Gnkw/Http/Resource.php#L157-L179