id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
37,800
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSet.php
SortedSet.remove
public function remove($value) { foreach ($this->values as $i => $v) { if ($value == $v) { unset($this->values[$i]); break; } } $this->stateChanged(); }
php
public function remove($value) { foreach ($this->values as $i => $v) { if ($value == $v) { unset($this->values[$i]); break; } } $this->stateChanged(); }
[ "public", "function", "remove", "(", "$", "value", ")", "{", "foreach", "(", "$", "this", "->", "values", "as", "$", "i", "=>", "$", "v", ")", "{", "if", "(", "$", "value", "==", "$", "v", ")", "{", "unset", "(", "$", "this", "->", "values", "[", "$", "i", "]", ")", ";", "break", ";", "}", "}", "$", "this", "->", "stateChanged", "(", ")", ";", "}" ]
Removes a value from the set, if present @param int|float|string|bool $value @return void
[ "Removes", "a", "value", "from", "the", "set", "if", "present" ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSet.php#L108-L117
37,801
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSet.php
SortedSet.stateChanged
private function stateChanged() { if (count($this->values)) { $this->values = array_unique(array_values($this->values)); sort($this->values); } }
php
private function stateChanged() { if (count($this->values)) { $this->values = array_unique(array_values($this->values)); sort($this->values); } }
[ "private", "function", "stateChanged", "(", ")", "{", "if", "(", "count", "(", "$", "this", "->", "values", ")", ")", "{", "$", "this", "->", "values", "=", "array_unique", "(", "array_values", "(", "$", "this", "->", "values", ")", ")", ";", "sort", "(", "$", "this", "->", "values", ")", ";", "}", "}" ]
Ensured uniqueness and sorted values @return void
[ "Ensured", "uniqueness", "and", "sorted", "values" ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSet.php#L136-L142
37,802
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/DependencyInjection/ZichtFrameworkExtraExtension.php
ZichtFrameworkExtraExtension.addUglifyConfiguration
public function addUglifyConfiguration($uglifyConfigFile, $isDebug, ContainerBuilder $container) { if (!is_file($uglifyConfigFile)) { throw new InvalidConfigurationException( "zicht_framework_extra.uglify setting '$uglifyConfigFile' is not a file" ); } $container->addResource(new FileResource($uglifyConfigFile)); try { $uglifyConfig = Yaml::parse(file_get_contents($uglifyConfigFile)); } catch (\Exception $e) { throw new InvalidConfigurationException( "zicht_framework_extra.uglify setting '$uglifyConfigFile' could not be read", 0, $e ); } $global = new Definition( 'Zicht\Bundle\FrameworkExtraBundle\Twig\UglifyGlobal', array( $uglifyConfig, $isDebug ) ); $global->addTag('twig.global'); $global->addMethodCall('setDebug', array($isDebug)); $container->getDefinition('zicht_twig_extension')->addMethodCall('setGlobal', array('zicht_uglify', $global)); }
php
public function addUglifyConfiguration($uglifyConfigFile, $isDebug, ContainerBuilder $container) { if (!is_file($uglifyConfigFile)) { throw new InvalidConfigurationException( "zicht_framework_extra.uglify setting '$uglifyConfigFile' is not a file" ); } $container->addResource(new FileResource($uglifyConfigFile)); try { $uglifyConfig = Yaml::parse(file_get_contents($uglifyConfigFile)); } catch (\Exception $e) { throw new InvalidConfigurationException( "zicht_framework_extra.uglify setting '$uglifyConfigFile' could not be read", 0, $e ); } $global = new Definition( 'Zicht\Bundle\FrameworkExtraBundle\Twig\UglifyGlobal', array( $uglifyConfig, $isDebug ) ); $global->addTag('twig.global'); $global->addMethodCall('setDebug', array($isDebug)); $container->getDefinition('zicht_twig_extension')->addMethodCall('setGlobal', array('zicht_uglify', $global)); }
[ "public", "function", "addUglifyConfiguration", "(", "$", "uglifyConfigFile", ",", "$", "isDebug", ",", "ContainerBuilder", "$", "container", ")", "{", "if", "(", "!", "is_file", "(", "$", "uglifyConfigFile", ")", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "\"zicht_framework_extra.uglify setting '$uglifyConfigFile' is not a file\"", ")", ";", "}", "$", "container", "->", "addResource", "(", "new", "FileResource", "(", "$", "uglifyConfigFile", ")", ")", ";", "try", "{", "$", "uglifyConfig", "=", "Yaml", "::", "parse", "(", "file_get_contents", "(", "$", "uglifyConfigFile", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "\"zicht_framework_extra.uglify setting '$uglifyConfigFile' could not be read\"", ",", "0", ",", "$", "e", ")", ";", "}", "$", "global", "=", "new", "Definition", "(", "'Zicht\\Bundle\\FrameworkExtraBundle\\Twig\\UglifyGlobal'", ",", "array", "(", "$", "uglifyConfig", ",", "$", "isDebug", ")", ")", ";", "$", "global", "->", "addTag", "(", "'twig.global'", ")", ";", "$", "global", "->", "addMethodCall", "(", "'setDebug'", ",", "array", "(", "$", "isDebug", ")", ")", ";", "$", "container", "->", "getDefinition", "(", "'zicht_twig_extension'", ")", "->", "addMethodCall", "(", "'setGlobal'", ",", "array", "(", "'zicht_uglify'", ",", "$", "global", ")", ")", ";", "}" ]
Adds the uglify configuration @param string $uglifyConfigFile @param boolean $isDebug @param \Symfony\Component\DependencyInjection\ContainerBuilder $container @return void @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
[ "Adds", "the", "uglify", "configuration" ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/DependencyInjection/ZichtFrameworkExtraExtension.php#L32-L63
37,803
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/DependencyInjection/ZichtFrameworkExtraExtension.php
ZichtFrameworkExtraExtension.addRequirejsConfiguration
public function addRequirejsConfiguration($requirejsConfigFile, $isDebug, ContainerBuilder $container) { if (!is_file($requirejsConfigFile)) { throw new InvalidConfigurationException( "zicht_framework_extra.requirejs setting '$requirejsConfigFile' is not a file" ); } $container->addResource(new FileResource($requirejsConfigFile)); try { $requirejsConfig = Yaml::parse($requirejsConfigFile); } catch (\Exception $e) { throw new InvalidConfigurationException( "zicht_framework_extra.requirejs setting '$requirejsConfigFile' could not be read", 0, $e ); } $global = new Definition( 'Zicht\Bundle\FrameworkExtraBundle\Twig\RequirejsGlobal', array( $requirejsConfig, $isDebug ) ); $global->addTag('twig.global'); $global->addMethodCall('setDebug', array($isDebug)); $container->getDefinition('zicht_twig_extension')->addMethodCall('setGlobal', array('zicht_requirejs', $global)); }
php
public function addRequirejsConfiguration($requirejsConfigFile, $isDebug, ContainerBuilder $container) { if (!is_file($requirejsConfigFile)) { throw new InvalidConfigurationException( "zicht_framework_extra.requirejs setting '$requirejsConfigFile' is not a file" ); } $container->addResource(new FileResource($requirejsConfigFile)); try { $requirejsConfig = Yaml::parse($requirejsConfigFile); } catch (\Exception $e) { throw new InvalidConfigurationException( "zicht_framework_extra.requirejs setting '$requirejsConfigFile' could not be read", 0, $e ); } $global = new Definition( 'Zicht\Bundle\FrameworkExtraBundle\Twig\RequirejsGlobal', array( $requirejsConfig, $isDebug ) ); $global->addTag('twig.global'); $global->addMethodCall('setDebug', array($isDebug)); $container->getDefinition('zicht_twig_extension')->addMethodCall('setGlobal', array('zicht_requirejs', $global)); }
[ "public", "function", "addRequirejsConfiguration", "(", "$", "requirejsConfigFile", ",", "$", "isDebug", ",", "ContainerBuilder", "$", "container", ")", "{", "if", "(", "!", "is_file", "(", "$", "requirejsConfigFile", ")", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "\"zicht_framework_extra.requirejs setting '$requirejsConfigFile' is not a file\"", ")", ";", "}", "$", "container", "->", "addResource", "(", "new", "FileResource", "(", "$", "requirejsConfigFile", ")", ")", ";", "try", "{", "$", "requirejsConfig", "=", "Yaml", "::", "parse", "(", "$", "requirejsConfigFile", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "\"zicht_framework_extra.requirejs setting '$requirejsConfigFile' could not be read\"", ",", "0", ",", "$", "e", ")", ";", "}", "$", "global", "=", "new", "Definition", "(", "'Zicht\\Bundle\\FrameworkExtraBundle\\Twig\\RequirejsGlobal'", ",", "array", "(", "$", "requirejsConfig", ",", "$", "isDebug", ")", ")", ";", "$", "global", "->", "addTag", "(", "'twig.global'", ")", ";", "$", "global", "->", "addMethodCall", "(", "'setDebug'", ",", "array", "(", "$", "isDebug", ")", ")", ";", "$", "container", "->", "getDefinition", "(", "'zicht_twig_extension'", ")", "->", "addMethodCall", "(", "'setGlobal'", ",", "array", "(", "'zicht_requirejs'", ",", "$", "global", ")", ")", ";", "}" ]
Adds the requirejs configuration @param string $requirejsConfigFile @param boolean $isDebug @param \Symfony\Component\DependencyInjection\ContainerBuilder $container @return void @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
[ "Adds", "the", "requirejs", "configuration" ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/DependencyInjection/ZichtFrameworkExtraExtension.php#L75-L104
37,804
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.add
public function add($key, $value) { if (!isset($this->values[$key])) { $this->values[$key] = new SortedSet(); } $this->values[$key]->add($value); $this->stateChanged(); }
php
public function add($key, $value) { if (!isset($this->values[$key])) { $this->values[$key] = new SortedSet(); } $this->values[$key]->add($value); $this->stateChanged(); }
[ "public", "function", "add", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "values", "[", "$", "key", "]", "=", "new", "SortedSet", "(", ")", ";", "}", "$", "this", "->", "values", "[", "$", "key", "]", "->", "add", "(", "$", "value", ")", ";", "$", "this", "->", "stateChanged", "(", ")", ";", "}" ]
Add a value to the given map key. @param string $key @param int|float|string|bool $value @return void
[ "Add", "a", "value", "to", "the", "given", "map", "key", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L54-L61
37,805
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.replace
public function replace($key, $values) { $this->values[$key] = new SortedSet($values); $this->stateChanged(); }
php
public function replace($key, $values) { $this->values[$key] = new SortedSet($values); $this->stateChanged(); }
[ "public", "function", "replace", "(", "$", "key", ",", "$", "values", ")", "{", "$", "this", "->", "values", "[", "$", "key", "]", "=", "new", "SortedSet", "(", "$", "values", ")", ";", "$", "this", "->", "stateChanged", "(", ")", ";", "}" ]
Replaces the map key with the specified set of values. @param string $key @param array $values @return void
[ "Replaces", "the", "map", "key", "with", "the", "specified", "set", "of", "values", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L71-L75
37,806
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.get
public function get($key) { if (isset($this->values[$key])) { return $this->values[$key]->toArray(); } return array(); }
php
public function get($key) { if (isset($this->values[$key])) { return $this->values[$key]->toArray(); } return array(); }
[ "public", "function", "get", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "values", "[", "$", "key", "]", "->", "toArray", "(", ")", ";", "}", "return", "array", "(", ")", ";", "}" ]
Returns the set of values associated with the given key as an array. Returns an empty array if the key is not present. @param string $key @return array
[ "Returns", "the", "set", "of", "values", "associated", "with", "the", "given", "key", "as", "an", "array", ".", "Returns", "an", "empty", "array", "if", "the", "key", "is", "not", "present", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L85-L92
37,807
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.contains
public function contains($key, $value) { if (isset($this->values[$key])) { return $this->values[$key]->contains($value); } return false; }
php
public function contains($key, $value) { if (isset($this->values[$key])) { return $this->values[$key]->contains($value); } return false; }
[ "public", "function", "contains", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "values", "[", "$", "key", "]", "->", "contains", "(", "$", "value", ")", ";", "}", "return", "false", ";", "}" ]
Checks if a value is associated with the given key. @param string $key @param int|float|string|bool $value @return bool
[ "Checks", "if", "a", "value", "is", "associated", "with", "the", "given", "key", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L102-L109
37,808
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.remove
public function remove($key, $value) { if (isset($this->values[$key])) { $this->values[$key]->remove($value); } $this->stateChanged(); }
php
public function remove($key, $value) { if (isset($this->values[$key])) { $this->values[$key]->remove($value); } $this->stateChanged(); }
[ "public", "function", "remove", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "values", "[", "$", "key", "]", "->", "remove", "(", "$", "value", ")", ";", "}", "$", "this", "->", "stateChanged", "(", ")", ";", "}" ]
Removes the given value from the map associated with the given key. @param string $key @param int|float|string|bool $value @return void
[ "Removes", "the", "given", "value", "from", "the", "map", "associated", "with", "the", "given", "key", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L131-L137
37,809
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.removeKey
public function removeKey($key) { if (isset($this->values[$key])) { unset($this->values[$key]); } $this->stateChanged(); }
php
public function removeKey($key) { if (isset($this->values[$key])) { unset($this->values[$key]); } $this->stateChanged(); }
[ "public", "function", "removeKey", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ";", "}", "$", "this", "->", "stateChanged", "(", ")", ";", "}" ]
Removes an entire set of values associated with the given key. @param string $key @return void
[ "Removes", "an", "entire", "set", "of", "values", "associated", "with", "the", "given", "key", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L146-L152
37,810
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.merge
public function merge($key, $values) { foreach ((array)$values as $value) { $this->add($key, $value); } $this->stateChanged(); }
php
public function merge($key, $values) { foreach ((array)$values as $value) { $this->add($key, $value); } $this->stateChanged(); }
[ "public", "function", "merge", "(", "$", "key", ",", "$", "values", ")", "{", "foreach", "(", "(", "array", ")", "$", "values", "as", "$", "value", ")", "{", "$", "this", "->", "add", "(", "$", "key", ",", "$", "value", ")", ";", "}", "$", "this", "->", "stateChanged", "(", ")", ";", "}" ]
Merges a set of values into the given key's set. @param string $key @param \Traversable $values @return void
[ "Merges", "a", "set", "of", "values", "into", "the", "given", "key", "s", "set", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L162-L168
37,811
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.mergeAll
public function mergeAll(array $values) { foreach ($values as $key => $value) { $this->merge($key, $value); } }
php
public function mergeAll(array $values) { foreach ($values as $key => $value) { $this->merge($key, $value); } }
[ "public", "function", "mergeAll", "(", "array", "$", "values", ")", "{", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "merge", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Merge an entire map into the current map. @param array $values @return void
[ "Merge", "an", "entire", "map", "into", "the", "current", "map", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L177-L182
37,812
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.toArray
public function toArray() { $ret = array(); foreach (array_keys($this->values) as $key) { $ret[$key] = $this->get($key); } return $ret; }
php
public function toArray() { $ret = array(); foreach (array_keys($this->values) as $key) { $ret[$key] = $this->get($key); } return $ret; }
[ "public", "function", "toArray", "(", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "array_keys", "(", "$", "this", "->", "values", ")", "as", "$", "key", ")", "{", "$", "ret", "[", "$", "key", "]", "=", "$", "this", "->", "get", "(", "$", "key", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Returns the map as an array, with all values representing the set of values associated with that key as an array @return array
[ "Returns", "the", "map", "as", "an", "array", "with", "all", "values", "representing", "the", "set", "of", "values", "associated", "with", "that", "key", "as", "an", "array" ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L191-L199
37,813
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php
SortedSetMap.stateChanged
private function stateChanged() { $keys = array_keys($this->values); foreach ($keys as $key) { if (!count($this->values[$key])) { unset($this->values[$key]); } } ksort($this->values); }
php
private function stateChanged() { $keys = array_keys($this->values); foreach ($keys as $key) { if (!count($this->values[$key])) { unset($this->values[$key]); } } ksort($this->values); }
[ "private", "function", "stateChanged", "(", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "this", "->", "values", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "!", "count", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ";", "}", "}", "ksort", "(", "$", "this", "->", "values", ")", ";", "}" ]
Ensures all empty sets are removed, and sorts the sets by key name. @return void
[ "Ensures", "all", "empty", "sets", "are", "removed", "and", "sorts", "the", "sets", "by", "key", "name", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Util/SortedSetMap.php#L207-L216
37,814
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Twig/ControlStructures/WithNode.php
WithNode.compileArgument
public function compileArgument($compiler, $argument) { if (empty($argument['name'])) { $compiler ->write('(array) ') ->subcompile($argument['value']); } else { $compiler ->write('array(') ->repr($argument['name']) ->raw(' => ') ->subcompile($argument['value']) ->raw(')'); } }
php
public function compileArgument($compiler, $argument) { if (empty($argument['name'])) { $compiler ->write('(array) ') ->subcompile($argument['value']); } else { $compiler ->write('array(') ->repr($argument['name']) ->raw(' => ') ->subcompile($argument['value']) ->raw(')'); } }
[ "public", "function", "compileArgument", "(", "$", "compiler", ",", "$", "argument", ")", "{", "if", "(", "empty", "(", "$", "argument", "[", "'name'", "]", ")", ")", "{", "$", "compiler", "->", "write", "(", "'(array) '", ")", "->", "subcompile", "(", "$", "argument", "[", "'value'", "]", ")", ";", "}", "else", "{", "$", "compiler", "->", "write", "(", "'array('", ")", "->", "repr", "(", "$", "argument", "[", "'name'", "]", ")", "->", "raw", "(", "' => '", ")", "->", "subcompile", "(", "$", "argument", "[", "'value'", "]", ")", "->", "raw", "(", "')'", ")", ";", "}", "}" ]
Compiles the 'with' argument. @param Twig_Compiler $compiler @param mixed $argument @return void
[ "Compiles", "the", "with", "argument", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Twig/ControlStructures/WithNode.php#L113-L127
37,815
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Helper/AnnotationRegistry.php
AnnotationRegistry.addAnnotation
public function addAnnotation($name, $value, $priority = 0) { $annotation = $this->getAnnotation($name); $new_annotation = array('name' => $name, 'value' => $value, 'priority' => $priority); if (!empty($annotation)) { if ($priority > $annotation['value']['priority']) { $this->setAnnotation($annotation['key'], $new_annotation); } } else { $this->annotations[]= $new_annotation; } }
php
public function addAnnotation($name, $value, $priority = 0) { $annotation = $this->getAnnotation($name); $new_annotation = array('name' => $name, 'value' => $value, 'priority' => $priority); if (!empty($annotation)) { if ($priority > $annotation['value']['priority']) { $this->setAnnotation($annotation['key'], $new_annotation); } } else { $this->annotations[]= $new_annotation; } }
[ "public", "function", "addAnnotation", "(", "$", "name", ",", "$", "value", ",", "$", "priority", "=", "0", ")", "{", "$", "annotation", "=", "$", "this", "->", "getAnnotation", "(", "$", "name", ")", ";", "$", "new_annotation", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'value'", "=>", "$", "value", ",", "'priority'", "=>", "$", "priority", ")", ";", "if", "(", "!", "empty", "(", "$", "annotation", ")", ")", "{", "if", "(", "$", "priority", ">", "$", "annotation", "[", "'value'", "]", "[", "'priority'", "]", ")", "{", "$", "this", "->", "setAnnotation", "(", "$", "annotation", "[", "'key'", "]", ",", "$", "new_annotation", ")", ";", "}", "}", "else", "{", "$", "this", "->", "annotations", "[", "]", "=", "$", "new_annotation", ";", "}", "}" ]
Add an annotation. @param string $name @param mixed $value @param int $priority @return void
[ "Add", "an", "annotation", "." ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Helper/AnnotationRegistry.php#L39-L50
37,816
zicht/url-bundle
src/Zicht/Bundle/UrlBundle/DependencyInjection/ZichtUrlExtension.php
ZichtUrlExtension.load
public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); $config = $this->processConfiguration(new Configuration(), $configs); if (!empty($config['unalias_subscriber'])) { // deprecation, remove in next major trigger_error('unalias_subscriber is no longer used. This has moved to form transformers.', E_USER_DEPRECATED); } if (isset($config['static_ref'])) { $container->getDefinition('zicht_url.static_refs')->addMethodCall('addAll', [$config['static_ref']]); } if (!empty($config['aliasing']) && $config['aliasing']['enabled'] === true) { $this->loadAliasingConfig($container, $config['aliasing'], $loader); $container->setAlias('zicht_url.sitemap_provider', new Alias('zicht_url.alias_sitemap_provider')); } else { $container->setAlias('zicht_url.sitemap_provider', new Alias('zicht_url.provider')); } if (!empty($config['logging'])) { $loader->load('logging.xml'); } if (!empty($config['admin'])) { $loader->load('admin.xml'); } if (!empty($aliasingConfig) && $config['caching']['enabled'] === true) { $loader->load('cache.xml'); $subscriberDefinition = $container->getDefinition('zicht_url.cache_subscriber'); $subscriberDefinition->replaceArgument(1, $config['caching']['entities']); } if (!empty($config['db_static_ref']) && $config['db_static_ref']['enabled'] === true) { $loader->load('db.xml'); } if ($container->hasDefinition('zicht_url.aliasing')) { $container->getDefinition('zicht_url.twig_extension')->addArgument(new Reference('zicht_url.aliasing')); } if ($container->hasDefinition('zicht_url.mapper.html')) { $container->getDefinition('zicht_url.mapper.html')->addMethodCall('addAttributes', [$config['html_attributes']]); } if ($container->hasDefinition('zicht_url.listener.strict_public_url')) { $container->getDefinition('zicht_url.listener.strict_public_url')->replaceArgument(0, $config['strict_public_url']); } if ($container->hasDefinition('zicht_url.validator.contains_url_alias')) { $container->getDefinition('zicht_url.validator.contains_url_alias')->replaceArgument(1, $config['strict_public_url']); } $formResources = $container->getParameter('twig.form.resources'); $formResources[] = 'ZichtUrlBundle::form_theme.html.twig'; $container->setParameter('twig.form.resources', $formResources); }
php
public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); $config = $this->processConfiguration(new Configuration(), $configs); if (!empty($config['unalias_subscriber'])) { // deprecation, remove in next major trigger_error('unalias_subscriber is no longer used. This has moved to form transformers.', E_USER_DEPRECATED); } if (isset($config['static_ref'])) { $container->getDefinition('zicht_url.static_refs')->addMethodCall('addAll', [$config['static_ref']]); } if (!empty($config['aliasing']) && $config['aliasing']['enabled'] === true) { $this->loadAliasingConfig($container, $config['aliasing'], $loader); $container->setAlias('zicht_url.sitemap_provider', new Alias('zicht_url.alias_sitemap_provider')); } else { $container->setAlias('zicht_url.sitemap_provider', new Alias('zicht_url.provider')); } if (!empty($config['logging'])) { $loader->load('logging.xml'); } if (!empty($config['admin'])) { $loader->load('admin.xml'); } if (!empty($aliasingConfig) && $config['caching']['enabled'] === true) { $loader->load('cache.xml'); $subscriberDefinition = $container->getDefinition('zicht_url.cache_subscriber'); $subscriberDefinition->replaceArgument(1, $config['caching']['entities']); } if (!empty($config['db_static_ref']) && $config['db_static_ref']['enabled'] === true) { $loader->load('db.xml'); } if ($container->hasDefinition('zicht_url.aliasing')) { $container->getDefinition('zicht_url.twig_extension')->addArgument(new Reference('zicht_url.aliasing')); } if ($container->hasDefinition('zicht_url.mapper.html')) { $container->getDefinition('zicht_url.mapper.html')->addMethodCall('addAttributes', [$config['html_attributes']]); } if ($container->hasDefinition('zicht_url.listener.strict_public_url')) { $container->getDefinition('zicht_url.listener.strict_public_url')->replaceArgument(0, $config['strict_public_url']); } if ($container->hasDefinition('zicht_url.validator.contains_url_alias')) { $container->getDefinition('zicht_url.validator.contains_url_alias')->replaceArgument(1, $config['strict_public_url']); } $formResources = $container->getParameter('twig.form.resources'); $formResources[] = 'ZichtUrlBundle::form_theme.html.twig'; $container->setParameter('twig.form.resources', $formResources); }
[ "public", "function", "load", "(", "array", "$", "configs", ",", "ContainerBuilder", "$", "container", ")", "{", "$", "loader", "=", "new", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ")", ";", "$", "loader", "->", "load", "(", "'services.xml'", ")", ";", "$", "config", "=", "$", "this", "->", "processConfiguration", "(", "new", "Configuration", "(", ")", ",", "$", "configs", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "[", "'unalias_subscriber'", "]", ")", ")", "{", "// deprecation, remove in next major", "trigger_error", "(", "'unalias_subscriber is no longer used. This has moved to form transformers.'", ",", "E_USER_DEPRECATED", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'static_ref'", "]", ")", ")", "{", "$", "container", "->", "getDefinition", "(", "'zicht_url.static_refs'", ")", "->", "addMethodCall", "(", "'addAll'", ",", "[", "$", "config", "[", "'static_ref'", "]", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "config", "[", "'aliasing'", "]", ")", "&&", "$", "config", "[", "'aliasing'", "]", "[", "'enabled'", "]", "===", "true", ")", "{", "$", "this", "->", "loadAliasingConfig", "(", "$", "container", ",", "$", "config", "[", "'aliasing'", "]", ",", "$", "loader", ")", ";", "$", "container", "->", "setAlias", "(", "'zicht_url.sitemap_provider'", ",", "new", "Alias", "(", "'zicht_url.alias_sitemap_provider'", ")", ")", ";", "}", "else", "{", "$", "container", "->", "setAlias", "(", "'zicht_url.sitemap_provider'", ",", "new", "Alias", "(", "'zicht_url.provider'", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "config", "[", "'logging'", "]", ")", ")", "{", "$", "loader", "->", "load", "(", "'logging.xml'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "config", "[", "'admin'", "]", ")", ")", "{", "$", "loader", "->", "load", "(", "'admin.xml'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "aliasingConfig", ")", "&&", "$", "config", "[", "'caching'", "]", "[", "'enabled'", "]", "===", "true", ")", "{", "$", "loader", "->", "load", "(", "'cache.xml'", ")", ";", "$", "subscriberDefinition", "=", "$", "container", "->", "getDefinition", "(", "'zicht_url.cache_subscriber'", ")", ";", "$", "subscriberDefinition", "->", "replaceArgument", "(", "1", ",", "$", "config", "[", "'caching'", "]", "[", "'entities'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "config", "[", "'db_static_ref'", "]", ")", "&&", "$", "config", "[", "'db_static_ref'", "]", "[", "'enabled'", "]", "===", "true", ")", "{", "$", "loader", "->", "load", "(", "'db.xml'", ")", ";", "}", "if", "(", "$", "container", "->", "hasDefinition", "(", "'zicht_url.aliasing'", ")", ")", "{", "$", "container", "->", "getDefinition", "(", "'zicht_url.twig_extension'", ")", "->", "addArgument", "(", "new", "Reference", "(", "'zicht_url.aliasing'", ")", ")", ";", "}", "if", "(", "$", "container", "->", "hasDefinition", "(", "'zicht_url.mapper.html'", ")", ")", "{", "$", "container", "->", "getDefinition", "(", "'zicht_url.mapper.html'", ")", "->", "addMethodCall", "(", "'addAttributes'", ",", "[", "$", "config", "[", "'html_attributes'", "]", "]", ")", ";", "}", "if", "(", "$", "container", "->", "hasDefinition", "(", "'zicht_url.listener.strict_public_url'", ")", ")", "{", "$", "container", "->", "getDefinition", "(", "'zicht_url.listener.strict_public_url'", ")", "->", "replaceArgument", "(", "0", ",", "$", "config", "[", "'strict_public_url'", "]", ")", ";", "}", "if", "(", "$", "container", "->", "hasDefinition", "(", "'zicht_url.validator.contains_url_alias'", ")", ")", "{", "$", "container", "->", "getDefinition", "(", "'zicht_url.validator.contains_url_alias'", ")", "->", "replaceArgument", "(", "1", ",", "$", "config", "[", "'strict_public_url'", "]", ")", ";", "}", "$", "formResources", "=", "$", "container", "->", "getParameter", "(", "'twig.form.resources'", ")", ";", "$", "formResources", "[", "]", "=", "'ZichtUrlBundle::form_theme.html.twig'", ";", "$", "container", "->", "setParameter", "(", "'twig.form.resources'", ",", "$", "formResources", ")", ";", "}" ]
Responds to the twig configuration parameter. @param array $configs @param ContainerBuilder $container @return void
[ "Responds", "to", "the", "twig", "configuration", "parameter", "." ]
4638524124c84b61c02d5194f8a28f34e9eb9845
https://github.com/zicht/url-bundle/blob/4638524124c84b61c02d5194f8a28f34e9eb9845/src/Zicht/Bundle/UrlBundle/DependencyInjection/ZichtUrlExtension.php#L27-L83
37,817
zicht/url-bundle
src/Zicht/Bundle/UrlBundle/DependencyInjection/ZichtUrlExtension.php
ZichtUrlExtension.loadAliasingConfig
protected function loadAliasingConfig(ContainerBuilder $container, $aliasingConfig, $loader) { $loader->load('aliasing.xml'); $listenerDefinition = $container->getDefinition('zicht_url.aliasing_listener'); if ($aliasingConfig['exclude_patterns']) { $listenerDefinition->addMethodCall('setExcludePatterns', [$aliasingConfig['exclude_patterns']]); } $listenerDefinition->addMethodCall('setIsParamsEnabled', [$aliasingConfig['enable_params']]); if ($aliasingConfig['automatic_entities']) { $automaticAliasDoctrineDefinition = $container->getDefinition('zicht_url.aliasing.doctrine.subscriber'); foreach ($aliasingConfig['automatic_entities'] as $entityClass) { $automaticAliasDoctrineDefinition->addMethodCall('addEntityClass', [$entityClass]); } } }
php
protected function loadAliasingConfig(ContainerBuilder $container, $aliasingConfig, $loader) { $loader->load('aliasing.xml'); $listenerDefinition = $container->getDefinition('zicht_url.aliasing_listener'); if ($aliasingConfig['exclude_patterns']) { $listenerDefinition->addMethodCall('setExcludePatterns', [$aliasingConfig['exclude_patterns']]); } $listenerDefinition->addMethodCall('setIsParamsEnabled', [$aliasingConfig['enable_params']]); if ($aliasingConfig['automatic_entities']) { $automaticAliasDoctrineDefinition = $container->getDefinition('zicht_url.aliasing.doctrine.subscriber'); foreach ($aliasingConfig['automatic_entities'] as $entityClass) { $automaticAliasDoctrineDefinition->addMethodCall('addEntityClass', [$entityClass]); } } }
[ "protected", "function", "loadAliasingConfig", "(", "ContainerBuilder", "$", "container", ",", "$", "aliasingConfig", ",", "$", "loader", ")", "{", "$", "loader", "->", "load", "(", "'aliasing.xml'", ")", ";", "$", "listenerDefinition", "=", "$", "container", "->", "getDefinition", "(", "'zicht_url.aliasing_listener'", ")", ";", "if", "(", "$", "aliasingConfig", "[", "'exclude_patterns'", "]", ")", "{", "$", "listenerDefinition", "->", "addMethodCall", "(", "'setExcludePatterns'", ",", "[", "$", "aliasingConfig", "[", "'exclude_patterns'", "]", "]", ")", ";", "}", "$", "listenerDefinition", "->", "addMethodCall", "(", "'setIsParamsEnabled'", ",", "[", "$", "aliasingConfig", "[", "'enable_params'", "]", "]", ")", ";", "if", "(", "$", "aliasingConfig", "[", "'automatic_entities'", "]", ")", "{", "$", "automaticAliasDoctrineDefinition", "=", "$", "container", "->", "getDefinition", "(", "'zicht_url.aliasing.doctrine.subscriber'", ")", ";", "foreach", "(", "$", "aliasingConfig", "[", "'automatic_entities'", "]", "as", "$", "entityClass", ")", "{", "$", "automaticAliasDoctrineDefinition", "->", "addMethodCall", "(", "'addEntityClass'", ",", "[", "$", "entityClass", "]", ")", ";", "}", "}", "}" ]
Load the aliasing config. @param ContainerBuilder $container @param array $aliasingConfig @param XmlFileLoader $loader @return void
[ "Load", "the", "aliasing", "config", "." ]
4638524124c84b61c02d5194f8a28f34e9eb9845
https://github.com/zicht/url-bundle/blob/4638524124c84b61c02d5194f8a28f34e9eb9845/src/Zicht/Bundle/UrlBundle/DependencyInjection/ZichtUrlExtension.php#L93-L111
37,818
zicht/url-bundle
src/Zicht/Bundle/UrlBundle/Twig/UrlExtension.php
UrlExtension.objectUrl
public function objectUrl($object, $defaultIfNotFound = null) { try { $ret = $this->provider->url($object); } catch (UnsupportedException $e) { if (null === $defaultIfNotFound) { throw $e; } else { if (true === $defaultIfNotFound) { $ret = (string)$object; } else { $ret = $defaultIfNotFound; } } } return $ret; }
php
public function objectUrl($object, $defaultIfNotFound = null) { try { $ret = $this->provider->url($object); } catch (UnsupportedException $e) { if (null === $defaultIfNotFound) { throw $e; } else { if (true === $defaultIfNotFound) { $ret = (string)$object; } else { $ret = $defaultIfNotFound; } } } return $ret; }
[ "public", "function", "objectUrl", "(", "$", "object", ",", "$", "defaultIfNotFound", "=", "null", ")", "{", "try", "{", "$", "ret", "=", "$", "this", "->", "provider", "->", "url", "(", "$", "object", ")", ";", "}", "catch", "(", "UnsupportedException", "$", "e", ")", "{", "if", "(", "null", "===", "$", "defaultIfNotFound", ")", "{", "throw", "$", "e", ";", "}", "else", "{", "if", "(", "true", "===", "$", "defaultIfNotFound", ")", "{", "$", "ret", "=", "(", "string", ")", "$", "object", ";", "}", "else", "{", "$", "ret", "=", "$", "defaultIfNotFound", ";", "}", "}", "}", "return", "$", "ret", ";", "}" ]
Returns an url based on the passed object. @param object $object @param mixed $defaultIfNotFound @return string
[ "Returns", "an", "url", "based", "on", "the", "passed", "object", "." ]
4638524124c84b61c02d5194f8a28f34e9eb9845
https://github.com/zicht/url-bundle/blob/4638524124c84b61c02d5194f8a28f34e9eb9845/src/Zicht/Bundle/UrlBundle/Twig/UrlExtension.php#L74-L90
37,819
zicht/url-bundle
src/Zicht/Bundle/UrlBundle/Twig/UrlExtension.php
UrlExtension.staticRef
public function staticRef($name, $params = null) { $name = (string)$name; if (!isset($this->static_refs[$name])) { try { $this->static_refs[$name] = $this->provider->url($name); } catch (UnsupportedException $e) { $this->static_refs[$name] = '/[static_reference: ' . $name . ']'; } } $ret = $this->static_refs[$name]; if ($params) { $ret .= '?' . http_build_query($params, 0, '&'); } return $ret; }
php
public function staticRef($name, $params = null) { $name = (string)$name; if (!isset($this->static_refs[$name])) { try { $this->static_refs[$name] = $this->provider->url($name); } catch (UnsupportedException $e) { $this->static_refs[$name] = '/[static_reference: ' . $name . ']'; } } $ret = $this->static_refs[$name]; if ($params) { $ret .= '?' . http_build_query($params, 0, '&'); } return $ret; }
[ "public", "function", "staticRef", "(", "$", "name", ",", "$", "params", "=", "null", ")", "{", "$", "name", "=", "(", "string", ")", "$", "name", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "static_refs", "[", "$", "name", "]", ")", ")", "{", "try", "{", "$", "this", "->", "static_refs", "[", "$", "name", "]", "=", "$", "this", "->", "provider", "->", "url", "(", "$", "name", ")", ";", "}", "catch", "(", "UnsupportedException", "$", "e", ")", "{", "$", "this", "->", "static_refs", "[", "$", "name", "]", "=", "'/[static_reference: '", ".", "$", "name", ".", "']'", ";", "}", "}", "$", "ret", "=", "$", "this", "->", "static_refs", "[", "$", "name", "]", ";", "if", "(", "$", "params", ")", "{", "$", "ret", ".=", "'?'", ".", "http_build_query", "(", "$", "params", ",", "0", ",", "'&'", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Returns a static reference, i.e. an url that is provided based on a simple string. @param string $name @param array $params @return string
[ "Returns", "a", "static", "reference", "i", ".", "e", ".", "an", "url", "that", "is", "provided", "based", "on", "a", "simple", "string", "." ]
4638524124c84b61c02d5194f8a28f34e9eb9845
https://github.com/zicht/url-bundle/blob/4638524124c84b61c02d5194f8a28f34e9eb9845/src/Zicht/Bundle/UrlBundle/Twig/UrlExtension.php#L100-L117
37,820
zicht/url-bundle
src/Zicht/Bundle/UrlBundle/Logging/Logging.php
Logging.createLog
public function createLog(Request $request, $message) { return new ErrorLog( $message, new \DateTime(), $request->headers->get('referer', null), $request->headers->get('user-agent', null), $request->getClientIp(), $request->getRequestUri() ); }
php
public function createLog(Request $request, $message) { return new ErrorLog( $message, new \DateTime(), $request->headers->get('referer', null), $request->headers->get('user-agent', null), $request->getClientIp(), $request->getRequestUri() ); }
[ "public", "function", "createLog", "(", "Request", "$", "request", ",", "$", "message", ")", "{", "return", "new", "ErrorLog", "(", "$", "message", ",", "new", "\\", "DateTime", "(", ")", ",", "$", "request", "->", "headers", "->", "get", "(", "'referer'", ",", "null", ")", ",", "$", "request", "->", "headers", "->", "get", "(", "'user-agent'", ",", "null", ")", ",", "$", "request", "->", "getClientIp", "(", ")", ",", "$", "request", "->", "getRequestUri", "(", ")", ")", ";", "}" ]
Create a log entry for the passed request. @param \Symfony\Component\HttpFoundation\Request $request @param string $message @return \Zicht\Bundle\UrlBundle\Entity\ErrorLog
[ "Create", "a", "log", "entry", "for", "the", "passed", "request", "." ]
4638524124c84b61c02d5194f8a28f34e9eb9845
https://github.com/zicht/url-bundle/blob/4638524124c84b61c02d5194f8a28f34e9eb9845/src/Zicht/Bundle/UrlBundle/Logging/Logging.php#L32-L42
37,821
zicht/url-bundle
src/Zicht/Bundle/UrlBundle/Logging/Logging.php
Logging.flush
public function flush($entry) { $this->manager->persist($entry); $this->manager->flush($entry); }
php
public function flush($entry) { $this->manager->persist($entry); $this->manager->flush($entry); }
[ "public", "function", "flush", "(", "$", "entry", ")", "{", "$", "this", "->", "manager", "->", "persist", "(", "$", "entry", ")", ";", "$", "this", "->", "manager", "->", "flush", "(", "$", "entry", ")", ";", "}" ]
Persist the log and flush the manager. @param ErrorLog $entry @return void
[ "Persist", "the", "log", "and", "flush", "the", "manager", "." ]
4638524124c84b61c02d5194f8a28f34e9eb9845
https://github.com/zicht/url-bundle/blob/4638524124c84b61c02d5194f8a28f34e9eb9845/src/Zicht/Bundle/UrlBundle/Logging/Logging.php#L51-L55
37,822
zicht/url-bundle
src/Zicht/Bundle/UrlBundle/Aliasing/Doctrine/RemoveAliasSubscriber.php
RemoveAliasSubscriber.preRemove
public function preRemove($e) { $entity = $e->getObject(); if ($entity instanceof $this->className) { // schedule alias removal (this needs to be done before the entity is removed and loses its id) $this->container->get($this->aliaserServiceId)->removeAlias($entity, true); } }
php
public function preRemove($e) { $entity = $e->getObject(); if ($entity instanceof $this->className) { // schedule alias removal (this needs to be done before the entity is removed and loses its id) $this->container->get($this->aliaserServiceId)->removeAlias($entity, true); } }
[ "public", "function", "preRemove", "(", "$", "e", ")", "{", "$", "entity", "=", "$", "e", "->", "getObject", "(", ")", ";", "if", "(", "$", "entity", "instanceof", "$", "this", "->", "className", ")", "{", "// schedule alias removal (this needs to be done before the entity is removed and loses its id)", "$", "this", "->", "container", "->", "get", "(", "$", "this", "->", "aliaserServiceId", ")", "->", "removeAlias", "(", "$", "entity", ",", "true", ")", ";", "}", "}" ]
Schedule an object's alias to be deleted. @param LifecycleEventArgs $e @return void
[ "Schedule", "an", "object", "s", "alias", "to", "be", "deleted", "." ]
4638524124c84b61c02d5194f8a28f34e9eb9845
https://github.com/zicht/url-bundle/blob/4638524124c84b61c02d5194f8a28f34e9eb9845/src/Zicht/Bundle/UrlBundle/Aliasing/Doctrine/RemoveAliasSubscriber.php#L34-L42
37,823
zicht/url-bundle
src/Zicht/Bundle/UrlBundle/Controller/StaticReferenceController.php
StaticReferenceController.redirectAction
public function redirectAction(Request $request, $name, $code = 301) { return new RedirectResponse( $this->get('zicht_url.provider')->url($name), $code ); }
php
public function redirectAction(Request $request, $name, $code = 301) { return new RedirectResponse( $this->get('zicht_url.provider')->url($name), $code ); }
[ "public", "function", "redirectAction", "(", "Request", "$", "request", ",", "$", "name", ",", "$", "code", "=", "301", ")", "{", "return", "new", "RedirectResponse", "(", "$", "this", "->", "get", "(", "'zicht_url.provider'", ")", "->", "url", "(", "$", "name", ")", ",", "$", "code", ")", ";", "}" ]
Redirects to the url provided by the main url provider service. @param Request $request @param string $name @param int $code @return \Symfony\Component\HttpFoundation\RedirectResponse @Route("/_static-ref/{name}")
[ "Redirects", "to", "the", "url", "provided", "by", "the", "main", "url", "provider", "service", "." ]
4638524124c84b61c02d5194f8a28f34e9eb9845
https://github.com/zicht/url-bundle/blob/4638524124c84b61c02d5194f8a28f34e9eb9845/src/Zicht/Bundle/UrlBundle/Controller/StaticReferenceController.php#L28-L34
37,824
zicht/framework-extra-bundle
src/Zicht/Bundle/FrameworkExtraBundle/Command/ValidateEntityCommand.php
ValidateEntityCommand.getAllEntities
protected function getAllEntities() { $allMeta = $this ->getContainer() ->get('doctrine') ->getManager() ->getMetadataFactory() ->getAllMetadata(); /** @var \Doctrine\ORM\Mapping\ClassMetadata $meta */ foreach ($allMeta as $meta) { if (!$meta->isMappedSuperclass && empty($meta->subClasses)) { yield $meta->getName(); } } }
php
protected function getAllEntities() { $allMeta = $this ->getContainer() ->get('doctrine') ->getManager() ->getMetadataFactory() ->getAllMetadata(); /** @var \Doctrine\ORM\Mapping\ClassMetadata $meta */ foreach ($allMeta as $meta) { if (!$meta->isMappedSuperclass && empty($meta->subClasses)) { yield $meta->getName(); } } }
[ "protected", "function", "getAllEntities", "(", ")", "{", "$", "allMeta", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'doctrine'", ")", "->", "getManager", "(", ")", "->", "getMetadataFactory", "(", ")", "->", "getAllMetadata", "(", ")", ";", "/** @var \\Doctrine\\ORM\\Mapping\\ClassMetadata $meta */", "foreach", "(", "$", "allMeta", "as", "$", "meta", ")", "{", "if", "(", "!", "$", "meta", "->", "isMappedSuperclass", "&&", "empty", "(", "$", "meta", "->", "subClasses", ")", ")", "{", "yield", "$", "meta", "->", "getName", "(", ")", ";", "}", "}", "}" ]
get all entities @return \Generator
[ "get", "all", "entities" ]
8482ca491aabdec565b15bf6c10c588a98c458a5
https://github.com/zicht/framework-extra-bundle/blob/8482ca491aabdec565b15bf6c10c588a98c458a5/src/Zicht/Bundle/FrameworkExtraBundle/Command/ValidateEntityCommand.php#L63-L78
37,825
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.translateMessage
protected function translateMessage($message, array $parameters = array()) { return $this->translator->trans($message, $parameters, $this->transDomain); }
php
protected function translateMessage($message, array $parameters = array()) { return $this->translator->trans($message, $parameters, $this->transDomain); }
[ "protected", "function", "translateMessage", "(", "$", "message", ",", "array", "$", "parameters", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "translator", "->", "trans", "(", "$", "message", ",", "$", "parameters", ",", "$", "this", "->", "transDomain", ")", ";", "}" ]
Translate a single message @param string $message @return string @codeCoverageIgnore
[ "Translate", "a", "single", "message" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L107-L110
37,826
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.siftQueue
public function siftQueue() { foreach ($this->queue as $name => $form) { $blockName = $form->getConfig()->getOption('block_name'); if ('_token' == $name || 'entry' == $blockName || $form->getParent()) { unset($this->queue[$name]); } } return $this; }
php
public function siftQueue() { foreach ($this->queue as $name => $form) { $blockName = $form->getConfig()->getOption('block_name'); if ('_token' == $name || 'entry' == $blockName || $form->getParent()) { unset($this->queue[$name]); } } return $this; }
[ "public", "function", "siftQueue", "(", ")", "{", "foreach", "(", "$", "this", "->", "queue", "as", "$", "name", "=>", "$", "form", ")", "{", "$", "blockName", "=", "$", "form", "->", "getConfig", "(", ")", "->", "getOption", "(", "'block_name'", ")", ";", "if", "(", "'_token'", "==", "$", "name", "||", "'entry'", "==", "$", "blockName", "||", "$", "form", "->", "getParent", "(", ")", ")", "{", "unset", "(", "$", "this", "->", "queue", "[", "$", "name", "]", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Removes from the queue elements which are not parent forms and should not be processes @return $this
[ "Removes", "from", "the", "queue", "elements", "which", "are", "not", "parent", "forms", "and", "should", "not", "be", "processes" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L198-L208
37,827
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.createJsModel
public function createJsModel(Form $form) { $this->currentElement = $form; $conf = $form->getConfig(); // If field is disabled or has no any validations if (false === $conf->getOption('js_validation')) { return null; } $model = new JsFormElement; $model->id = $this->getElementId($form); $model->name = $form->getName(); $model->type = get_class($conf->getType()->getInnerType()); $model->invalidMessage = $this->translateMessage( $conf->getOption('invalid_message'), $conf->getOption('invalid_message_parameters') ); $model->transformers = $this->normalizeViewTransformers( $form, $this->parseTransformers($conf->getViewTransformers()) ); $model->bubbling = $conf->getOption('error_bubbling'); $model->data = $this->getValidationData($form); $model->children = $this->processChildren($form); $prototype = $form->getConfig()->getAttribute('prototype'); if ($prototype) { $model->prototype = $this->createJsModel($prototype); } // Return self id to add it as child to the parent model return $model; }
php
public function createJsModel(Form $form) { $this->currentElement = $form; $conf = $form->getConfig(); // If field is disabled or has no any validations if (false === $conf->getOption('js_validation')) { return null; } $model = new JsFormElement; $model->id = $this->getElementId($form); $model->name = $form->getName(); $model->type = get_class($conf->getType()->getInnerType()); $model->invalidMessage = $this->translateMessage( $conf->getOption('invalid_message'), $conf->getOption('invalid_message_parameters') ); $model->transformers = $this->normalizeViewTransformers( $form, $this->parseTransformers($conf->getViewTransformers()) ); $model->bubbling = $conf->getOption('error_bubbling'); $model->data = $this->getValidationData($form); $model->children = $this->processChildren($form); $prototype = $form->getConfig()->getAttribute('prototype'); if ($prototype) { $model->prototype = $this->createJsModel($prototype); } // Return self id to add it as child to the parent model return $model; }
[ "public", "function", "createJsModel", "(", "Form", "$", "form", ")", "{", "$", "this", "->", "currentElement", "=", "$", "form", ";", "$", "conf", "=", "$", "form", "->", "getConfig", "(", ")", ";", "// If field is disabled or has no any validations", "if", "(", "false", "===", "$", "conf", "->", "getOption", "(", "'js_validation'", ")", ")", "{", "return", "null", ";", "}", "$", "model", "=", "new", "JsFormElement", ";", "$", "model", "->", "id", "=", "$", "this", "->", "getElementId", "(", "$", "form", ")", ";", "$", "model", "->", "name", "=", "$", "form", "->", "getName", "(", ")", ";", "$", "model", "->", "type", "=", "get_class", "(", "$", "conf", "->", "getType", "(", ")", "->", "getInnerType", "(", ")", ")", ";", "$", "model", "->", "invalidMessage", "=", "$", "this", "->", "translateMessage", "(", "$", "conf", "->", "getOption", "(", "'invalid_message'", ")", ",", "$", "conf", "->", "getOption", "(", "'invalid_message_parameters'", ")", ")", ";", "$", "model", "->", "transformers", "=", "$", "this", "->", "normalizeViewTransformers", "(", "$", "form", ",", "$", "this", "->", "parseTransformers", "(", "$", "conf", "->", "getViewTransformers", "(", ")", ")", ")", ";", "$", "model", "->", "bubbling", "=", "$", "conf", "->", "getOption", "(", "'error_bubbling'", ")", ";", "$", "model", "->", "data", "=", "$", "this", "->", "getValidationData", "(", "$", "form", ")", ";", "$", "model", "->", "children", "=", "$", "this", "->", "processChildren", "(", "$", "form", ")", ";", "$", "prototype", "=", "$", "form", "->", "getConfig", "(", ")", "->", "getAttribute", "(", "'prototype'", ")", ";", "if", "(", "$", "prototype", ")", "{", "$", "model", "->", "prototype", "=", "$", "this", "->", "createJsModel", "(", "$", "prototype", ")", ";", "}", "// Return self id to add it as child to the parent model", "return", "$", "model", ";", "}" ]
The main function that creates nested model @param Form $form @return null|JsFormElement
[ "The", "main", "function", "that", "creates", "nested", "model" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L234-L267
37,828
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.processChildren
protected function processChildren($form) { $result = array(); // If this field has children - process them foreach ($form as $name => $child) { if ($this->isProcessableElement($child)) { $childModel = $this->createJsModel($child); if (null !== $childModel) { $result[$name] = $childModel; } } } return $result; }
php
protected function processChildren($form) { $result = array(); // If this field has children - process them foreach ($form as $name => $child) { if ($this->isProcessableElement($child)) { $childModel = $this->createJsModel($child); if (null !== $childModel) { $result[$name] = $childModel; } } } return $result; }
[ "protected", "function", "processChildren", "(", "$", "form", ")", "{", "$", "result", "=", "array", "(", ")", ";", "// If this field has children - process them", "foreach", "(", "$", "form", "as", "$", "name", "=>", "$", "child", ")", "{", "if", "(", "$", "this", "->", "isProcessableElement", "(", "$", "child", ")", ")", "{", "$", "childModel", "=", "$", "this", "->", "createJsModel", "(", "$", "child", ")", ";", "if", "(", "null", "!==", "$", "childModel", ")", "{", "$", "result", "[", "$", "name", "]", "=", "$", "childModel", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Create the JsFormElement for all the children of specified element @param null|Form $form @return array
[ "Create", "the", "JsFormElement", "for", "all", "the", "children", "of", "specified", "element" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L276-L290
37,829
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.getElementId
protected function getElementId(Form $form) { /** @var Form $parent */ $parent = $form->getParent(); if (null !== $parent) { return $this->getElementId($parent) . '_' . $form->getName(); } else { return $form->getName(); } }
php
protected function getElementId(Form $form) { /** @var Form $parent */ $parent = $form->getParent(); if (null !== $parent) { return $this->getElementId($parent) . '_' . $form->getName(); } else { return $form->getName(); } }
[ "protected", "function", "getElementId", "(", "Form", "$", "form", ")", "{", "/** @var Form $parent */", "$", "parent", "=", "$", "form", "->", "getParent", "(", ")", ";", "if", "(", "null", "!==", "$", "parent", ")", "{", "return", "$", "this", "->", "getElementId", "(", "$", "parent", ")", ".", "'_'", ".", "$", "form", "->", "getName", "(", ")", ";", "}", "else", "{", "return", "$", "form", "->", "getName", "(", ")", ";", "}", "}" ]
Generate an Id for the element by merging the current element name with all the parents names @param Form $form @return string
[ "Generate", "an", "Id", "for", "the", "element", "by", "merging", "the", "current", "element", "name", "with", "all", "the", "parents", "names" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L300-L309
37,830
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.getValidationGroups
protected function getValidationGroups(Form $form) { $result = array('Default'); $groups = $form->getConfig()->getOption('validation_groups'); if (empty($groups)) { // Try to get groups from a parent if ($form->getParent()) { $result = $this->getValidationGroups($form->getParent()); } } elseif (is_array($groups)) { // If groups is an array - return groups as is $result = $groups; } elseif ($groups instanceof \Closure) { // If groups is a Closure - return the form class name to look for javascript $result = $this->getElementId($form); } return $result; }
php
protected function getValidationGroups(Form $form) { $result = array('Default'); $groups = $form->getConfig()->getOption('validation_groups'); if (empty($groups)) { // Try to get groups from a parent if ($form->getParent()) { $result = $this->getValidationGroups($form->getParent()); } } elseif (is_array($groups)) { // If groups is an array - return groups as is $result = $groups; } elseif ($groups instanceof \Closure) { // If groups is a Closure - return the form class name to look for javascript $result = $this->getElementId($form); } return $result; }
[ "protected", "function", "getValidationGroups", "(", "Form", "$", "form", ")", "{", "$", "result", "=", "array", "(", "'Default'", ")", ";", "$", "groups", "=", "$", "form", "->", "getConfig", "(", ")", "->", "getOption", "(", "'validation_groups'", ")", ";", "if", "(", "empty", "(", "$", "groups", ")", ")", "{", "// Try to get groups from a parent", "if", "(", "$", "form", "->", "getParent", "(", ")", ")", "{", "$", "result", "=", "$", "this", "->", "getValidationGroups", "(", "$", "form", "->", "getParent", "(", ")", ")", ";", "}", "}", "elseif", "(", "is_array", "(", "$", "groups", ")", ")", "{", "// If groups is an array - return groups as is", "$", "result", "=", "$", "groups", ";", "}", "elseif", "(", "$", "groups", "instanceof", "\\", "Closure", ")", "{", "// If groups is a Closure - return the form class name to look for javascript", "$", "result", "=", "$", "this", "->", "getElementId", "(", "$", "form", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get validation groups for the specified form @param Form|FormInterface $form @return array|string
[ "Get", "validation", "groups", "for", "the", "specified", "form" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L421-L440
37,831
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.parseTransformers
protected function parseTransformers(array $transformers) { $result = array(); foreach ($transformers as $trans) { $item = array(); $reflect = new \ReflectionClass($trans); $properties = $reflect->getProperties(); foreach ($properties as $prop) { $item[$prop->getName()] = $this->getTransformerParam($trans, $prop->getName()); } $item['name'] = get_class($trans); $result[] = $item; } return $result; }
php
protected function parseTransformers(array $transformers) { $result = array(); foreach ($transformers as $trans) { $item = array(); $reflect = new \ReflectionClass($trans); $properties = $reflect->getProperties(); foreach ($properties as $prop) { $item[$prop->getName()] = $this->getTransformerParam($trans, $prop->getName()); } $item['name'] = get_class($trans); $result[] = $item; } return $result; }
[ "protected", "function", "parseTransformers", "(", "array", "$", "transformers", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "transformers", "as", "$", "trans", ")", "{", "$", "item", "=", "array", "(", ")", ";", "$", "reflect", "=", "new", "\\", "ReflectionClass", "(", "$", "trans", ")", ";", "$", "properties", "=", "$", "reflect", "->", "getProperties", "(", ")", ";", "foreach", "(", "$", "properties", "as", "$", "prop", ")", "{", "$", "item", "[", "$", "prop", "->", "getName", "(", ")", "]", "=", "$", "this", "->", "getTransformerParam", "(", "$", "trans", ",", "$", "prop", "->", "getName", "(", ")", ")", ";", "}", "$", "item", "[", "'name'", "]", "=", "get_class", "(", "$", "trans", ")", ";", "$", "result", "[", "]", "=", "$", "item", ";", "}", "return", "$", "result", ";", "}" ]
Convert transformers objects to data arrays @param array $transformers @return array
[ "Convert", "transformers", "objects", "to", "data", "arrays" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L487-L504
37,832
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.getTransformerParam
protected function getTransformerParam(DataTransformerInterface $transformer, $paramName) { $reflection = new \ReflectionProperty($transformer, $paramName); $reflection->setAccessible(true); $value = $reflection->getValue($transformer); $result = null; if ('transformers' === $paramName && is_array($value)) { $result = $this->parseTransformers($value); } elseif (is_scalar($value) || is_array($value)) { $result = $value; } elseif ($value instanceof ChoiceListInterface) { $result = array_values($value->getChoices()); } return $result; }
php
protected function getTransformerParam(DataTransformerInterface $transformer, $paramName) { $reflection = new \ReflectionProperty($transformer, $paramName); $reflection->setAccessible(true); $value = $reflection->getValue($transformer); $result = null; if ('transformers' === $paramName && is_array($value)) { $result = $this->parseTransformers($value); } elseif (is_scalar($value) || is_array($value)) { $result = $value; } elseif ($value instanceof ChoiceListInterface) { $result = array_values($value->getChoices()); } return $result; }
[ "protected", "function", "getTransformerParam", "(", "DataTransformerInterface", "$", "transformer", ",", "$", "paramName", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionProperty", "(", "$", "transformer", ",", "$", "paramName", ")", ";", "$", "reflection", "->", "setAccessible", "(", "true", ")", ";", "$", "value", "=", "$", "reflection", "->", "getValue", "(", "$", "transformer", ")", ";", "$", "result", "=", "null", ";", "if", "(", "'transformers'", "===", "$", "paramName", "&&", "is_array", "(", "$", "value", ")", ")", "{", "$", "result", "=", "$", "this", "->", "parseTransformers", "(", "$", "value", ")", ";", "}", "elseif", "(", "is_scalar", "(", "$", "value", ")", "||", "is_array", "(", "$", "value", ")", ")", "{", "$", "result", "=", "$", "value", ";", "}", "elseif", "(", "$", "value", "instanceof", "ChoiceListInterface", ")", "{", "$", "result", "=", "array_values", "(", "$", "value", "->", "getChoices", "(", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get the specified non-public transformer property @param DataTransformerInterface $transformer @param string $paramName @return mixed
[ "Get", "the", "specified", "non", "-", "public", "transformer", "property" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L514-L530
37,833
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.parseGetters
protected function parseGetters(array $getters) { $result = array(); foreach ($getters as $getter) { $result[$getter->getName()] = $this->parseConstraints((array)$getter->getConstraints()); } return $result; }
php
protected function parseGetters(array $getters) { $result = array(); foreach ($getters as $getter) { $result[$getter->getName()] = $this->parseConstraints((array)$getter->getConstraints()); } return $result; }
[ "protected", "function", "parseGetters", "(", "array", "$", "getters", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "getters", "as", "$", "getter", ")", "{", "$", "result", "[", "$", "getter", "->", "getName", "(", ")", "]", "=", "$", "this", "->", "parseConstraints", "(", "(", "array", ")", "$", "getter", "->", "getConstraints", "(", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Converts list of the GetterMetadata objects to a data array @param GetterMetadata[] $getters @return array
[ "Converts", "list", "of", "the", "GetterMetadata", "objects", "to", "a", "data", "array" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L539-L547
37,834
formapro/JsFormValidatorBundle
Factory/JsFormValidatorFactory.php
JsFormValidatorFactory.parseConstraints
protected function parseConstraints(array $constraints) { $result = array(); foreach ($constraints as $item) { // Translate messages if need and add to result foreach ($item as $propName => $propValue) { if (false !== strpos(strtolower($propName), 'message')) { $item->{$propName} = $this->translateMessage($propValue); } } if ($item instanceof \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity) { $item = new UniqueEntity($item, $this->currentElement->getConfig()->getDataClass()); } $result[get_class($item)][] = $item; } return $result; }
php
protected function parseConstraints(array $constraints) { $result = array(); foreach ($constraints as $item) { // Translate messages if need and add to result foreach ($item as $propName => $propValue) { if (false !== strpos(strtolower($propName), 'message')) { $item->{$propName} = $this->translateMessage($propValue); } } if ($item instanceof \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity) { $item = new UniqueEntity($item, $this->currentElement->getConfig()->getDataClass()); } $result[get_class($item)][] = $item; } return $result; }
[ "protected", "function", "parseConstraints", "(", "array", "$", "constraints", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "constraints", "as", "$", "item", ")", "{", "// Translate messages if need and add to result", "foreach", "(", "$", "item", "as", "$", "propName", "=>", "$", "propValue", ")", "{", "if", "(", "false", "!==", "strpos", "(", "strtolower", "(", "$", "propName", ")", ",", "'message'", ")", ")", "{", "$", "item", "->", "{", "$", "propName", "}", "=", "$", "this", "->", "translateMessage", "(", "$", "propValue", ")", ";", "}", "}", "if", "(", "$", "item", "instanceof", "\\", "Symfony", "\\", "Bridge", "\\", "Doctrine", "\\", "Validator", "\\", "Constraints", "\\", "UniqueEntity", ")", "{", "$", "item", "=", "new", "UniqueEntity", "(", "$", "item", ",", "$", "this", "->", "currentElement", "->", "getConfig", "(", ")", "->", "getDataClass", "(", ")", ")", ";", "}", "$", "result", "[", "get_class", "(", "$", "item", ")", "]", "[", "]", "=", "$", "item", ";", "}", "return", "$", "result", ";", "}" ]
Converts list of constraints objects to a data array @param array $constraints @return array
[ "Converts", "list", "of", "constraints", "objects", "to", "a", "data", "array" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Factory/JsFormValidatorFactory.php#L556-L575
37,835
formapro/JsFormValidatorBundle
Model/JsModelAbstract.php
JsModelAbstract.phpValueToJs
public static function phpValueToJs($value) { // For object which has own __toString method if ($value instanceof JsModelAbstract) { return $value->toJsString(); } // For object which has own __toString method elseif (is_object($value) && method_exists($value, '__toString')) { return self::phpValueToJs($value->__toString()); } // For an object or associative array elseif (is_object($value) || (is_array($value) && array_values($value) !== $value)) { $jsObject = array(); foreach ($value as $paramName => $paramValue) { $paramName = addcslashes($paramName, '\'\\'); $jsObject[] = "'$paramName':" . self::phpValueToJs($paramValue); } return sprintf('{%1$s}', implode($jsObject, ',')); } // For a sequential array elseif (is_array($value)) { $jsArray = array(); foreach ($value as $item) { $jsArray[] = self::phpValueToJs($item); } return sprintf('[%1$s]', implode($jsArray, ',')); } // For string elseif (is_string($value)) { $value = addcslashes($value, '\'\\'); return "'$value'"; } // For boolean elseif (is_bool($value)) { return true === $value ? 'true' : 'false'; } // For numbers elseif (is_numeric($value)) { return $value; } // For null elseif (is_null($value)) { return 'null'; } // Otherwise else { return 'undefined'; } }
php
public static function phpValueToJs($value) { // For object which has own __toString method if ($value instanceof JsModelAbstract) { return $value->toJsString(); } // For object which has own __toString method elseif (is_object($value) && method_exists($value, '__toString')) { return self::phpValueToJs($value->__toString()); } // For an object or associative array elseif (is_object($value) || (is_array($value) && array_values($value) !== $value)) { $jsObject = array(); foreach ($value as $paramName => $paramValue) { $paramName = addcslashes($paramName, '\'\\'); $jsObject[] = "'$paramName':" . self::phpValueToJs($paramValue); } return sprintf('{%1$s}', implode($jsObject, ',')); } // For a sequential array elseif (is_array($value)) { $jsArray = array(); foreach ($value as $item) { $jsArray[] = self::phpValueToJs($item); } return sprintf('[%1$s]', implode($jsArray, ',')); } // For string elseif (is_string($value)) { $value = addcslashes($value, '\'\\'); return "'$value'"; } // For boolean elseif (is_bool($value)) { return true === $value ? 'true' : 'false'; } // For numbers elseif (is_numeric($value)) { return $value; } // For null elseif (is_null($value)) { return 'null'; } // Otherwise else { return 'undefined'; } }
[ "public", "static", "function", "phpValueToJs", "(", "$", "value", ")", "{", "// For object which has own __toString method", "if", "(", "$", "value", "instanceof", "JsModelAbstract", ")", "{", "return", "$", "value", "->", "toJsString", "(", ")", ";", "}", "// For object which has own __toString method", "elseif", "(", "is_object", "(", "$", "value", ")", "&&", "method_exists", "(", "$", "value", ",", "'__toString'", ")", ")", "{", "return", "self", "::", "phpValueToJs", "(", "$", "value", "->", "__toString", "(", ")", ")", ";", "}", "// For an object or associative array", "elseif", "(", "is_object", "(", "$", "value", ")", "||", "(", "is_array", "(", "$", "value", ")", "&&", "array_values", "(", "$", "value", ")", "!==", "$", "value", ")", ")", "{", "$", "jsObject", "=", "array", "(", ")", ";", "foreach", "(", "$", "value", "as", "$", "paramName", "=>", "$", "paramValue", ")", "{", "$", "paramName", "=", "addcslashes", "(", "$", "paramName", ",", "'\\'\\\\'", ")", ";", "$", "jsObject", "[", "]", "=", "\"'$paramName':\"", ".", "self", "::", "phpValueToJs", "(", "$", "paramValue", ")", ";", "}", "return", "sprintf", "(", "'{%1$s}'", ",", "implode", "(", "$", "jsObject", ",", "','", ")", ")", ";", "}", "// For a sequential array", "elseif", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "jsArray", "=", "array", "(", ")", ";", "foreach", "(", "$", "value", "as", "$", "item", ")", "{", "$", "jsArray", "[", "]", "=", "self", "::", "phpValueToJs", "(", "$", "item", ")", ";", "}", "return", "sprintf", "(", "'[%1$s]'", ",", "implode", "(", "$", "jsArray", ",", "','", ")", ")", ";", "}", "// For string", "elseif", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "value", "=", "addcslashes", "(", "$", "value", ",", "'\\'\\\\'", ")", ";", "return", "\"'$value'\"", ";", "}", "// For boolean", "elseif", "(", "is_bool", "(", "$", "value", ")", ")", "{", "return", "true", "===", "$", "value", "?", "'true'", ":", "'false'", ";", "}", "// For numbers", "elseif", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "// For null", "elseif", "(", "is_null", "(", "$", "value", ")", ")", "{", "return", "'null'", ";", "}", "// Otherwise", "else", "{", "return", "'undefined'", ";", "}", "}" ]
Convert php value to the Javascript formatted string @param mixed $value @return string
[ "Convert", "php", "value", "to", "the", "Javascript", "formatted", "string" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Model/JsModelAbstract.php#L39-L90
37,836
formapro/JsFormValidatorBundle
Controller/AjaxController.php
AjaxController.checkUniqueEntityAction
public function checkUniqueEntityAction(Request $request) { $data = $request->request->all(); foreach ($data['data'] as $value) { // If field(s) has an empty value and it should be ignored if ((bool) $data['ignoreNull'] && ('' === $value || is_null($value))) { // Just return a positive result return new JsonResponse(true); } } $entity = $this ->get('doctrine') ->getRepository($data['entityName']) ->{$data['repositoryMethod']}($data['data']) ; return new JsonResponse(empty($entity)); }
php
public function checkUniqueEntityAction(Request $request) { $data = $request->request->all(); foreach ($data['data'] as $value) { // If field(s) has an empty value and it should be ignored if ((bool) $data['ignoreNull'] && ('' === $value || is_null($value))) { // Just return a positive result return new JsonResponse(true); } } $entity = $this ->get('doctrine') ->getRepository($data['entityName']) ->{$data['repositoryMethod']}($data['data']) ; return new JsonResponse(empty($entity)); }
[ "public", "function", "checkUniqueEntityAction", "(", "Request", "$", "request", ")", "{", "$", "data", "=", "$", "request", "->", "request", "->", "all", "(", ")", ";", "foreach", "(", "$", "data", "[", "'data'", "]", "as", "$", "value", ")", "{", "// If field(s) has an empty value and it should be ignored", "if", "(", "(", "bool", ")", "$", "data", "[", "'ignoreNull'", "]", "&&", "(", "''", "===", "$", "value", "||", "is_null", "(", "$", "value", ")", ")", ")", "{", "// Just return a positive result", "return", "new", "JsonResponse", "(", "true", ")", ";", "}", "}", "$", "entity", "=", "$", "this", "->", "get", "(", "'doctrine'", ")", "->", "getRepository", "(", "$", "data", "[", "'entityName'", "]", ")", "->", "{", "$", "data", "[", "'repositoryMethod'", "]", "}", "(", "$", "data", "[", "'data'", "]", ")", ";", "return", "new", "JsonResponse", "(", "empty", "(", "$", "entity", ")", ")", ";", "}" ]
This is simplified analog for the UniqueEntity validator @param \Symfony\Component\HttpFoundation\Request $request @return JsonResponse
[ "This", "is", "simplified", "analog", "for", "the", "UniqueEntity", "validator" ]
c1cb6b0d40506c6056dc20d3d8378964f76b896f
https://github.com/formapro/JsFormValidatorBundle/blob/c1cb6b0d40506c6056dc20d3d8378964f76b896f/Controller/AjaxController.php#L24-L42
37,837
vitalets/x-editable-yii
EditableSaver.php
EditableSaver.checkErrors
public function checkErrors() { if ($this->model->hasErrors()) { $msg = array(); foreach($this->model->getErrors() as $attribute => $errors) { $msg = array_merge($msg, $errors); } //todo: show several messages. should be checked in x-editable js //$this->error(join("\n", $msg)); $this->error($msg[0]); } }
php
public function checkErrors() { if ($this->model->hasErrors()) { $msg = array(); foreach($this->model->getErrors() as $attribute => $errors) { $msg = array_merge($msg, $errors); } //todo: show several messages. should be checked in x-editable js //$this->error(join("\n", $msg)); $this->error($msg[0]); } }
[ "public", "function", "checkErrors", "(", ")", "{", "if", "(", "$", "this", "->", "model", "->", "hasErrors", "(", ")", ")", "{", "$", "msg", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "model", "->", "getErrors", "(", ")", "as", "$", "attribute", "=>", "$", "errors", ")", "{", "$", "msg", "=", "array_merge", "(", "$", "msg", ",", "$", "errors", ")", ";", "}", "//todo: show several messages. should be checked in x-editable js", "//$this->error(join(\"\\n\", $msg));", "$", "this", "->", "error", "(", "$", "msg", "[", "0", "]", ")", ";", "}", "}" ]
errors as CHttpException @param $msg @throws CHttpException
[ "errors", "as", "CHttpException" ]
06faae330f3bdb150cf33dfb7e7e0c731e376647
https://github.com/vitalets/x-editable-yii/blob/06faae330f3bdb150cf33dfb7e7e0c731e376647/EditableSaver.php#L196-L207
37,838
sskaje/mqtt
mqtt/Message.php
Message.Create
static public function Create($message_type, MQTT $mqtt) { if (!isset(Message::$name[$message_type])) { throw new Exception('Message type not defined'); } $class = __NAMESPACE__ . '\\Message\\' . self::$name[$message_type]; return new $class($mqtt); }
php
static public function Create($message_type, MQTT $mqtt) { if (!isset(Message::$name[$message_type])) { throw new Exception('Message type not defined'); } $class = __NAMESPACE__ . '\\Message\\' . self::$name[$message_type]; return new $class($mqtt); }
[ "static", "public", "function", "Create", "(", "$", "message_type", ",", "MQTT", "$", "mqtt", ")", "{", "if", "(", "!", "isset", "(", "Message", "::", "$", "name", "[", "$", "message_type", "]", ")", ")", "{", "throw", "new", "Exception", "(", "'Message type not defined'", ")", ";", "}", "$", "class", "=", "__NAMESPACE__", ".", "'\\\\Message\\\\'", ".", "self", "::", "$", "name", "[", "$", "message_type", "]", ";", "return", "new", "$", "class", "(", "$", "mqtt", ")", ";", "}" ]
Create Message Object @param int $message_type @param MQTT $mqtt @return mixed @throws Exception
[ "Create", "Message", "Object" ]
38cf01a177ed8e6ff387cdefcf11ba42594e330f
https://github.com/sskaje/mqtt/blob/38cf01a177ed8e6ff387cdefcf11ba42594e330f/mqtt/Message.php#L130-L139
37,839
sskaje/mqtt
mqtt/SocketClient.php
SocketClient.set_blocking
public function set_blocking() { if (!$this->socket || !is_resource($this->socket)) return false; Debug::Log(Debug::DEBUG, 'SOCKET: blocking mode: ON'); stream_set_blocking($this->socket, true); return true; }
php
public function set_blocking() { if (!$this->socket || !is_resource($this->socket)) return false; Debug::Log(Debug::DEBUG, 'SOCKET: blocking mode: ON'); stream_set_blocking($this->socket, true); return true; }
[ "public", "function", "set_blocking", "(", ")", "{", "if", "(", "!", "$", "this", "->", "socket", "||", "!", "is_resource", "(", "$", "this", "->", "socket", ")", ")", "return", "false", ";", "Debug", "::", "Log", "(", "Debug", "::", "DEBUG", ",", "'SOCKET: blocking mode: ON'", ")", ";", "stream_set_blocking", "(", "$", "this", "->", "socket", ",", "true", ")", ";", "return", "true", ";", "}" ]
Set Blocking Mode
[ "Set", "Blocking", "Mode" ]
38cf01a177ed8e6ff387cdefcf11ba42594e330f
https://github.com/sskaje/mqtt/blob/38cf01a177ed8e6ff387cdefcf11ba42594e330f/mqtt/SocketClient.php#L136-L142
37,840
vitalets/x-editable-yii
EditableConfig.php
EditableConfig.init
public function init() { parent::init(); if(empty($this->defaults)) $this->defaults = array(); //copy mode from first level config to defaults (for compability) if(empty($this->defaults['mode'])) $this->defaults['mode'] = $this->mode; $defaults = CJavaScript::encode($this->defaults); Yii::app()->getClientScript()->registerScript( 'editable-defaults', 'if($.fn.editable) $.extend($.fn.editable.defaults, '.$defaults.');' ); }
php
public function init() { parent::init(); if(empty($this->defaults)) $this->defaults = array(); //copy mode from first level config to defaults (for compability) if(empty($this->defaults['mode'])) $this->defaults['mode'] = $this->mode; $defaults = CJavaScript::encode($this->defaults); Yii::app()->getClientScript()->registerScript( 'editable-defaults', 'if($.fn.editable) $.extend($.fn.editable.defaults, '.$defaults.');' ); }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "defaults", ")", ")", "$", "this", "->", "defaults", "=", "array", "(", ")", ";", "//copy mode from first level config to defaults (for compability)", "if", "(", "empty", "(", "$", "this", "->", "defaults", "[", "'mode'", "]", ")", ")", "$", "this", "->", "defaults", "[", "'mode'", "]", "=", "$", "this", "->", "mode", ";", "$", "defaults", "=", "CJavaScript", "::", "encode", "(", "$", "this", "->", "defaults", ")", ";", "Yii", "::", "app", "(", ")", "->", "getClientScript", "(", ")", "->", "registerScript", "(", "'editable-defaults'", ",", "'if($.fn.editable) $.extend($.fn.editable.defaults, '", ".", "$", "defaults", ".", "');'", ")", ";", "}" ]
initializes editable component and sets defaults
[ "initializes", "editable", "component", "and", "sets", "defaults" ]
06faae330f3bdb150cf33dfb7e7e0c731e376647
https://github.com/vitalets/x-editable-yii/blob/06faae330f3bdb150cf33dfb7e7e0c731e376647/EditableConfig.php#L41-L51
37,841
sskaje/mqtt
mqtt/MQTT.php
MQTT.publish_sync
public function publish_sync($topic, $message, $qos=0, $retain=0, &$msgid=0) { # set default call_handler # initial dup = 0 $dup = 0; # initial msgid = 0 $msgid = 0; # non blocking $this->socket->set_non_blocking(); $r = $this->do_publish($topic, $message, $qos, $retain, $msgid, $dup); if ($qos == 0) { return $r['ret']; } # loop do { $r = $this->handle_message(); if (!$r) { usleep(10000); continue; } $finished = $qos == 1 ? $this->cmdstore->isEmpty(Message::PUBACK, $msgid) : ( $this->cmdstore->isEmpty(Message::PUBREC, $msgid) && $this->cmdstore->isEmpty(Message::PUBCOMP, $msgid) ); if (!$finished) { # retry publish $this->handle_publish($msgid); } else { return true; } } while (true); return false; }
php
public function publish_sync($topic, $message, $qos=0, $retain=0, &$msgid=0) { # set default call_handler # initial dup = 0 $dup = 0; # initial msgid = 0 $msgid = 0; # non blocking $this->socket->set_non_blocking(); $r = $this->do_publish($topic, $message, $qos, $retain, $msgid, $dup); if ($qos == 0) { return $r['ret']; } # loop do { $r = $this->handle_message(); if (!$r) { usleep(10000); continue; } $finished = $qos == 1 ? $this->cmdstore->isEmpty(Message::PUBACK, $msgid) : ( $this->cmdstore->isEmpty(Message::PUBREC, $msgid) && $this->cmdstore->isEmpty(Message::PUBCOMP, $msgid) ); if (!$finished) { # retry publish $this->handle_publish($msgid); } else { return true; } } while (true); return false; }
[ "public", "function", "publish_sync", "(", "$", "topic", ",", "$", "message", ",", "$", "qos", "=", "0", ",", "$", "retain", "=", "0", ",", "&", "$", "msgid", "=", "0", ")", "{", "# set default call_handler", "# initial dup = 0", "$", "dup", "=", "0", ";", "# initial msgid = 0", "$", "msgid", "=", "0", ";", "# non blocking", "$", "this", "->", "socket", "->", "set_non_blocking", "(", ")", ";", "$", "r", "=", "$", "this", "->", "do_publish", "(", "$", "topic", ",", "$", "message", ",", "$", "qos", ",", "$", "retain", ",", "$", "msgid", ",", "$", "dup", ")", ";", "if", "(", "$", "qos", "==", "0", ")", "{", "return", "$", "r", "[", "'ret'", "]", ";", "}", "# loop", "do", "{", "$", "r", "=", "$", "this", "->", "handle_message", "(", ")", ";", "if", "(", "!", "$", "r", ")", "{", "usleep", "(", "10000", ")", ";", "continue", ";", "}", "$", "finished", "=", "$", "qos", "==", "1", "?", "$", "this", "->", "cmdstore", "->", "isEmpty", "(", "Message", "::", "PUBACK", ",", "$", "msgid", ")", ":", "(", "$", "this", "->", "cmdstore", "->", "isEmpty", "(", "Message", "::", "PUBREC", ",", "$", "msgid", ")", "&&", "$", "this", "->", "cmdstore", "->", "isEmpty", "(", "Message", "::", "PUBCOMP", ",", "$", "msgid", ")", ")", ";", "if", "(", "!", "$", "finished", ")", "{", "# retry publish", "$", "this", "->", "handle_publish", "(", "$", "msgid", ")", ";", "}", "else", "{", "return", "true", ";", "}", "}", "while", "(", "true", ")", ";", "return", "false", ";", "}" ]
Publish Message to topic synchronized @param string $topic @param string $message @param int $qos @param int $retain @param int & $msgid @return array|bool @throws Exception
[ "Publish", "Message", "to", "topic", "synchronized" ]
38cf01a177ed8e6ff387cdefcf11ba42594e330f
https://github.com/sskaje/mqtt/blob/38cf01a177ed8e6ff387cdefcf11ba42594e330f/mqtt/MQTT.php#L446-L489
37,842
sskaje/mqtt
mqtt/MQTT.php
MQTT.message_write
protected function message_write(Base $object, & $length=0) { Debug::Log(Debug::DEBUG, 'Message write: message_type='.Message::$name[$object->getMessageType()]); $length = 0; $message = $object->build($length); $bytes_written = $this->socket->write($message, $length); return $bytes_written; }
php
protected function message_write(Base $object, & $length=0) { Debug::Log(Debug::DEBUG, 'Message write: message_type='.Message::$name[$object->getMessageType()]); $length = 0; $message = $object->build($length); $bytes_written = $this->socket->write($message, $length); return $bytes_written; }
[ "protected", "function", "message_write", "(", "Base", "$", "object", ",", "&", "$", "length", "=", "0", ")", "{", "Debug", "::", "Log", "(", "Debug", "::", "DEBUG", ",", "'Message write: message_type='", ".", "Message", "::", "$", "name", "[", "$", "object", "->", "getMessageType", "(", ")", "]", ")", ";", "$", "length", "=", "0", ";", "$", "message", "=", "$", "object", "->", "build", "(", "$", "length", ")", ";", "$", "bytes_written", "=", "$", "this", "->", "socket", "->", "write", "(", "$", "message", ",", "$", "length", ")", ";", "return", "$", "bytes_written", ";", "}" ]
Write Message Object @param Message\Base $object @param int & $length @return int @throws Exception
[ "Write", "Message", "Object" ]
38cf01a177ed8e6ff387cdefcf11ba42594e330f
https://github.com/sskaje/mqtt/blob/38cf01a177ed8e6ff387cdefcf11ba42594e330f/mqtt/MQTT.php#L1221-L1228
37,843
glooby/task-bundle
src/DependencyInjection/Compiler/RegisterSchedulesPass.php
RegisterSchedulesPass.isTaskImplementation
private function isTaskImplementation($class) { if (!isset($this->implementations[$class])) { $reflectionClass = new \ReflectionClass($class); $this->implementations[$class] = $reflectionClass->implementsInterface(TaskInterface::class); } return $this->implementations[$class]; }
php
private function isTaskImplementation($class) { if (!isset($this->implementations[$class])) { $reflectionClass = new \ReflectionClass($class); $this->implementations[$class] = $reflectionClass->implementsInterface(TaskInterface::class); } return $this->implementations[$class]; }
[ "private", "function", "isTaskImplementation", "(", "$", "class", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "implementations", "[", "$", "class", "]", ")", ")", "{", "$", "reflectionClass", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "$", "this", "->", "implementations", "[", "$", "class", "]", "=", "$", "reflectionClass", "->", "implementsInterface", "(", "TaskInterface", "::", "class", ")", ";", "}", "return", "$", "this", "->", "implementations", "[", "$", "class", "]", ";", "}" ]
Returns whether the class implements TaskInterface. @param string $class @return bool
[ "Returns", "whether", "the", "class", "implements", "TaskInterface", "." ]
3c97bc6a5e32f6d34bf86265a970ade707271f71
https://github.com/glooby/task-bundle/blob/3c97bc6a5e32f6d34bf86265a970ade707271f71/src/DependencyInjection/Compiler/RegisterSchedulesPass.php#L42-L50
37,844
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTable.php
StatsTable.removeColumns
public function removeColumns(array $columns) { $columnsMap = array_flip($columns); $this->removeColumnsInLine($this->headers, $columnsMap); $this->removeColumnsInLine($this->aggregations, $columnsMap); $this->removeColumnsInLine($this->dataFormats, $columnsMap); $this->removeColumnsInLine($this->aggregationsFormats, $columnsMap); foreach ($this->data as &$line) { $this->removeColumnsInLine($line, $columnsMap); } return $this; }
php
public function removeColumns(array $columns) { $columnsMap = array_flip($columns); $this->removeColumnsInLine($this->headers, $columnsMap); $this->removeColumnsInLine($this->aggregations, $columnsMap); $this->removeColumnsInLine($this->dataFormats, $columnsMap); $this->removeColumnsInLine($this->aggregationsFormats, $columnsMap); foreach ($this->data as &$line) { $this->removeColumnsInLine($line, $columnsMap); } return $this; }
[ "public", "function", "removeColumns", "(", "array", "$", "columns", ")", "{", "$", "columnsMap", "=", "array_flip", "(", "$", "columns", ")", ";", "$", "this", "->", "removeColumnsInLine", "(", "$", "this", "->", "headers", ",", "$", "columnsMap", ")", ";", "$", "this", "->", "removeColumnsInLine", "(", "$", "this", "->", "aggregations", ",", "$", "columnsMap", ")", ";", "$", "this", "->", "removeColumnsInLine", "(", "$", "this", "->", "dataFormats", ",", "$", "columnsMap", ")", ";", "$", "this", "->", "removeColumnsInLine", "(", "$", "this", "->", "aggregationsFormats", ",", "$", "columnsMap", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "&", "$", "line", ")", "{", "$", "this", "->", "removeColumnsInLine", "(", "$", "line", ",", "$", "columnsMap", ")", ";", "}", "return", "$", "this", ";", "}" ]
Remove columns in table @param array $columns @return StatsTable
[ "Remove", "columns", "in", "table" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTable.php#L108-L122
37,845
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTable.php
StatsTable.removeColumnsInLine
protected function removeColumnsInLine(array &$line, array $columnsMap) { foreach ($line as $k => $v) { if (array_key_exists($k, $columnsMap)) { unset($line[$k]); } } }
php
protected function removeColumnsInLine(array &$line, array $columnsMap) { foreach ($line as $k => $v) { if (array_key_exists($k, $columnsMap)) { unset($line[$k]); } } }
[ "protected", "function", "removeColumnsInLine", "(", "array", "&", "$", "line", ",", "array", "$", "columnsMap", ")", "{", "foreach", "(", "$", "line", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "array_key_exists", "(", "$", "k", ",", "$", "columnsMap", ")", ")", "{", "unset", "(", "$", "line", "[", "$", "k", "]", ")", ";", "}", "}", "}" ]
Internal helper to remove columns for a line. @param array $line Line to filter. Referenced. @param array $columnsMap An array indexed by columns to exclude. Value doesn't matter. @return void
[ "Internal", "helper", "to", "remove", "columns", "for", "a", "line", "." ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTable.php#L132-L139
37,846
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTable.php
StatsTable.sortMultipleColumn
public function sortMultipleColumn($columns) { $compareFuncList = []; foreach($columns as $colName=>$asc) { $columnFormat = array_key_exists($colName, $this->dataFormats) ? $this->dataFormats[$colName] : Format::STRING; $compareFuncList[$colName] = $this->_getFunctionForFormat($columnFormat, $asc); } $this->uSortMultipleColumn($compareFuncList); return $this; }
php
public function sortMultipleColumn($columns) { $compareFuncList = []; foreach($columns as $colName=>$asc) { $columnFormat = array_key_exists($colName, $this->dataFormats) ? $this->dataFormats[$colName] : Format::STRING; $compareFuncList[$colName] = $this->_getFunctionForFormat($columnFormat, $asc); } $this->uSortMultipleColumn($compareFuncList); return $this; }
[ "public", "function", "sortMultipleColumn", "(", "$", "columns", ")", "{", "$", "compareFuncList", "=", "[", "]", ";", "foreach", "(", "$", "columns", "as", "$", "colName", "=>", "$", "asc", ")", "{", "$", "columnFormat", "=", "array_key_exists", "(", "$", "colName", ",", "$", "this", "->", "dataFormats", ")", "?", "$", "this", "->", "dataFormats", "[", "$", "colName", "]", ":", "Format", "::", "STRING", ";", "$", "compareFuncList", "[", "$", "colName", "]", "=", "$", "this", "->", "_getFunctionForFormat", "(", "$", "columnFormat", ",", "$", "asc", ")", ";", "}", "$", "this", "->", "uSortMultipleColumn", "(", "$", "compareFuncList", ")", ";", "return", "$", "this", ";", "}" ]
Sort stats table by multiple column @param array $columns Associative array : KEY=> column name (string), VALUE=> Sort direction (boolean) @return $this
[ "Sort", "stats", "table", "by", "multiple", "column" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTable.php#L170-L180
37,847
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTable.php
StatsTable.uSortMultipleColumn
public function uSortMultipleColumn($columns) { $dataFormats = $this->dataFormats; $sort = function ($a, $b) use ($columns, $dataFormats) { foreach ($columns as $colName => $fn) { $tmp = $fn($a[$colName], $b[$colName]); if ($tmp !== 0) { return $tmp; } } return 0; }; uasort($this->data, $sort); return $this; }
php
public function uSortMultipleColumn($columns) { $dataFormats = $this->dataFormats; $sort = function ($a, $b) use ($columns, $dataFormats) { foreach ($columns as $colName => $fn) { $tmp = $fn($a[$colName], $b[$colName]); if ($tmp !== 0) { return $tmp; } } return 0; }; uasort($this->data, $sort); return $this; }
[ "public", "function", "uSortMultipleColumn", "(", "$", "columns", ")", "{", "$", "dataFormats", "=", "$", "this", "->", "dataFormats", ";", "$", "sort", "=", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "columns", ",", "$", "dataFormats", ")", "{", "foreach", "(", "$", "columns", "as", "$", "colName", "=>", "$", "fn", ")", "{", "$", "tmp", "=", "$", "fn", "(", "$", "a", "[", "$", "colName", "]", ",", "$", "b", "[", "$", "colName", "]", ")", ";", "if", "(", "$", "tmp", "!==", "0", ")", "{", "return", "$", "tmp", ";", "}", "}", "return", "0", ";", "}", ";", "uasort", "(", "$", "this", "->", "data", ",", "$", "sort", ")", ";", "return", "$", "this", ";", "}" ]
Sort stats table by multiple column with a custom compare function @param $columns $columns Associative array : KEY=> column name (string), VALUE=> Custom function (function) @return $this
[ "Sort", "stats", "table", "by", "multiple", "column", "with", "a", "custom", "compare", "function" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTable.php#L187-L202
37,848
igraal/stats-table
lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php
ExcelDumper.dump
public function dump(StatsTable $statsTable) { $excel = new Spreadsheet(); $excel->getDefaultStyle()->applyFromArray($this->getDefaultStyleArray()); $sheet = $excel->getActiveSheet(); $row = 1; $data = $statsTable->getData(); $width = count(reset($data)); // HEADERS // if ($this->enableHeaders) { $headerStyle = new Style(); $headerStyle->applyFromArray($this->getHeadersStyleArray()); $col = 0; foreach ($statsTable->getHeaders() as $header) { $sheet->setCellValueByColumnAndRow($col, $row, $header); $col++; } $sheet->duplicateStyle($headerStyle, 'A1:'. Coordinate::stringFromColumnIndex($width-1).'1'); $row++; } // DATA // foreach ($statsTable->getData() as $data) { $this->applyValues($sheet, $row, $data, $statsTable->getDataFormats()); $row++; } // AGGREGATIONS // if ($this->enableAggregation) { $this->applyValues($sheet, $row, $statsTable->getAggregations(), $statsTable->getAggregationsFormats(), $this->getAggregationsStyleArray()); } // FINAL FORMATTING // for ($col = 0; $col < $width; $col++) { $sheet ->getColumnDimension(Coordinate::stringFromColumnIndex($col)) ->setAutoSize(true); } $xlsDumper = new Xlsx($excel); $pFilename = @tempnam(sys_get_temp_dir(), 'phpxltmp'); $xlsDumper->save($pFilename); $contents = file_get_contents($pFilename); @unlink($pFilename); unset($excel); unset($xlsDumper); return $contents; }
php
public function dump(StatsTable $statsTable) { $excel = new Spreadsheet(); $excel->getDefaultStyle()->applyFromArray($this->getDefaultStyleArray()); $sheet = $excel->getActiveSheet(); $row = 1; $data = $statsTable->getData(); $width = count(reset($data)); // HEADERS // if ($this->enableHeaders) { $headerStyle = new Style(); $headerStyle->applyFromArray($this->getHeadersStyleArray()); $col = 0; foreach ($statsTable->getHeaders() as $header) { $sheet->setCellValueByColumnAndRow($col, $row, $header); $col++; } $sheet->duplicateStyle($headerStyle, 'A1:'. Coordinate::stringFromColumnIndex($width-1).'1'); $row++; } // DATA // foreach ($statsTable->getData() as $data) { $this->applyValues($sheet, $row, $data, $statsTable->getDataFormats()); $row++; } // AGGREGATIONS // if ($this->enableAggregation) { $this->applyValues($sheet, $row, $statsTable->getAggregations(), $statsTable->getAggregationsFormats(), $this->getAggregationsStyleArray()); } // FINAL FORMATTING // for ($col = 0; $col < $width; $col++) { $sheet ->getColumnDimension(Coordinate::stringFromColumnIndex($col)) ->setAutoSize(true); } $xlsDumper = new Xlsx($excel); $pFilename = @tempnam(sys_get_temp_dir(), 'phpxltmp'); $xlsDumper->save($pFilename); $contents = file_get_contents($pFilename); @unlink($pFilename); unset($excel); unset($xlsDumper); return $contents; }
[ "public", "function", "dump", "(", "StatsTable", "$", "statsTable", ")", "{", "$", "excel", "=", "new", "Spreadsheet", "(", ")", ";", "$", "excel", "->", "getDefaultStyle", "(", ")", "->", "applyFromArray", "(", "$", "this", "->", "getDefaultStyleArray", "(", ")", ")", ";", "$", "sheet", "=", "$", "excel", "->", "getActiveSheet", "(", ")", ";", "$", "row", "=", "1", ";", "$", "data", "=", "$", "statsTable", "->", "getData", "(", ")", ";", "$", "width", "=", "count", "(", "reset", "(", "$", "data", ")", ")", ";", "// HEADERS //", "if", "(", "$", "this", "->", "enableHeaders", ")", "{", "$", "headerStyle", "=", "new", "Style", "(", ")", ";", "$", "headerStyle", "->", "applyFromArray", "(", "$", "this", "->", "getHeadersStyleArray", "(", ")", ")", ";", "$", "col", "=", "0", ";", "foreach", "(", "$", "statsTable", "->", "getHeaders", "(", ")", "as", "$", "header", ")", "{", "$", "sheet", "->", "setCellValueByColumnAndRow", "(", "$", "col", ",", "$", "row", ",", "$", "header", ")", ";", "$", "col", "++", ";", "}", "$", "sheet", "->", "duplicateStyle", "(", "$", "headerStyle", ",", "'A1:'", ".", "Coordinate", "::", "stringFromColumnIndex", "(", "$", "width", "-", "1", ")", ".", "'1'", ")", ";", "$", "row", "++", ";", "}", "// DATA //", "foreach", "(", "$", "statsTable", "->", "getData", "(", ")", "as", "$", "data", ")", "{", "$", "this", "->", "applyValues", "(", "$", "sheet", ",", "$", "row", ",", "$", "data", ",", "$", "statsTable", "->", "getDataFormats", "(", ")", ")", ";", "$", "row", "++", ";", "}", "// AGGREGATIONS //", "if", "(", "$", "this", "->", "enableAggregation", ")", "{", "$", "this", "->", "applyValues", "(", "$", "sheet", ",", "$", "row", ",", "$", "statsTable", "->", "getAggregations", "(", ")", ",", "$", "statsTable", "->", "getAggregationsFormats", "(", ")", ",", "$", "this", "->", "getAggregationsStyleArray", "(", ")", ")", ";", "}", "// FINAL FORMATTING //", "for", "(", "$", "col", "=", "0", ";", "$", "col", "<", "$", "width", ";", "$", "col", "++", ")", "{", "$", "sheet", "->", "getColumnDimension", "(", "Coordinate", "::", "stringFromColumnIndex", "(", "$", "col", ")", ")", "->", "setAutoSize", "(", "true", ")", ";", "}", "$", "xlsDumper", "=", "new", "Xlsx", "(", "$", "excel", ")", ";", "$", "pFilename", "=", "@", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "'phpxltmp'", ")", ";", "$", "xlsDumper", "->", "save", "(", "$", "pFilename", ")", ";", "$", "contents", "=", "file_get_contents", "(", "$", "pFilename", ")", ";", "@", "unlink", "(", "$", "pFilename", ")", ";", "unset", "(", "$", "excel", ")", ";", "unset", "(", "$", "xlsDumper", ")", ";", "return", "$", "contents", ";", "}" ]
Dumps the stats table @param StatsTable $statsTable @return string @throws \Exception
[ "Dumps", "the", "stats", "table" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php#L64-L118
37,849
igraal/stats-table
lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php
ExcelDumper.getDefaultStyleArrayForRow
protected function getDefaultStyleArrayForRow($row) { $style = $this->getDefaultStyleForFilledCells(); if ($this->getOption(self::OPTION_ZEBRA)) { if (($row % 2) == 0) { $bgColor = $this->getOption(self::OPTION_ZEBRA_COLOR_EVEN); } else { $bgColor = $this->getOption(self::OPTION_ZEBRA_COLOR_ODD); } if ($bgColor) { $style['fill'] = [ 'fillType' => Fill::FILL_SOLID, 'color' => ['argb' => $bgColor], ]; } } return $style; }
php
protected function getDefaultStyleArrayForRow($row) { $style = $this->getDefaultStyleForFilledCells(); if ($this->getOption(self::OPTION_ZEBRA)) { if (($row % 2) == 0) { $bgColor = $this->getOption(self::OPTION_ZEBRA_COLOR_EVEN); } else { $bgColor = $this->getOption(self::OPTION_ZEBRA_COLOR_ODD); } if ($bgColor) { $style['fill'] = [ 'fillType' => Fill::FILL_SOLID, 'color' => ['argb' => $bgColor], ]; } } return $style; }
[ "protected", "function", "getDefaultStyleArrayForRow", "(", "$", "row", ")", "{", "$", "style", "=", "$", "this", "->", "getDefaultStyleForFilledCells", "(", ")", ";", "if", "(", "$", "this", "->", "getOption", "(", "self", "::", "OPTION_ZEBRA", ")", ")", "{", "if", "(", "(", "$", "row", "%", "2", ")", "==", "0", ")", "{", "$", "bgColor", "=", "$", "this", "->", "getOption", "(", "self", "::", "OPTION_ZEBRA_COLOR_EVEN", ")", ";", "}", "else", "{", "$", "bgColor", "=", "$", "this", "->", "getOption", "(", "self", "::", "OPTION_ZEBRA_COLOR_ODD", ")", ";", "}", "if", "(", "$", "bgColor", ")", "{", "$", "style", "[", "'fill'", "]", "=", "[", "'fillType'", "=>", "Fill", "::", "FILL_SOLID", ",", "'color'", "=>", "[", "'argb'", "=>", "$", "bgColor", "]", ",", "]", ";", "}", "}", "return", "$", "style", ";", "}" ]
Get default style for a given row @param integer $row @return array
[ "Get", "default", "style", "for", "a", "given", "row" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php#L155-L175
37,850
igraal/stats-table
lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php
ExcelDumper.getOption
public function getOption($optionName) { if (array_key_exists($optionName, $this->options)) { return $this->options[$optionName]; } else { return null; } }
php
public function getOption($optionName) { if (array_key_exists($optionName, $this->options)) { return $this->options[$optionName]; } else { return null; } }
[ "public", "function", "getOption", "(", "$", "optionName", ")", "{", "if", "(", "array_key_exists", "(", "$", "optionName", ",", "$", "this", "->", "options", ")", ")", "{", "return", "$", "this", "->", "options", "[", "$", "optionName", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Gets an option @param $optionName @return null
[ "Gets", "an", "option" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php#L230-L237
37,851
igraal/stats-table
lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php
ExcelDumper.applyValues
protected function applyValues(Worksheet $sheet, $row, $values, $formats, $styleArray = []) { $col = 0; foreach ($values as $index => $value) { $this->applyValue($sheet, $col, $row, $value, array_key_exists($index, $formats) ? $formats[$index] : Format::STRING, $styleArray); $col++; } }
php
protected function applyValues(Worksheet $sheet, $row, $values, $formats, $styleArray = []) { $col = 0; foreach ($values as $index => $value) { $this->applyValue($sheet, $col, $row, $value, array_key_exists($index, $formats) ? $formats[$index] : Format::STRING, $styleArray); $col++; } }
[ "protected", "function", "applyValues", "(", "Worksheet", "$", "sheet", ",", "$", "row", ",", "$", "values", ",", "$", "formats", ",", "$", "styleArray", "=", "[", "]", ")", "{", "$", "col", "=", "0", ";", "foreach", "(", "$", "values", "as", "$", "index", "=>", "$", "value", ")", "{", "$", "this", "->", "applyValue", "(", "$", "sheet", ",", "$", "col", ",", "$", "row", ",", "$", "value", ",", "array_key_exists", "(", "$", "index", ",", "$", "formats", ")", "?", "$", "formats", "[", "$", "index", "]", ":", "Format", "::", "STRING", ",", "$", "styleArray", ")", ";", "$", "col", "++", ";", "}", "}" ]
Set values in specific row @param Worksheet $sheet The worksheet @param integer $row The selected row @param array $values The values to insert @param array $formats Associative arrays with formats @param array $styleArray An array representing the style @throws \Exception
[ "Set", "values", "in", "specific", "row" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php#L248-L255
37,852
igraal/stats-table
lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php
ExcelDumper.applyValue
protected function applyValue(Worksheet $sheet, $col, $row, $value, $format, $styleArray = []) { if (0 == count($styleArray)) { $styleArray = $this->getDefaultStyleArrayForRow($row); } $style = new Style(); $style->applyFromArray($styleArray); switch ($format) { case Format::DATE: if (!($value instanceof \DateTime)) { $date = new \DateTime($value); } else { $date = $value; } $value = Date::PHPToExcel($date); $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2); break; case Format::DATETIME: if (!($value instanceof \DateTime)) { $date = new \DateTime($value); } else { $date = $value; } $value = Date::PHPToExcel($date); $style->getNumberFormat()->setFormatCode(self::FORMAT_DATETIME); break; case Format::FLOAT2: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1); break; case Format::INTEGER: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER); break; case Format::MONEY: case Format::MONEY2: $style->getNumberFormat()->setFormatCode(self::FORMAT_EUR); break; case Format::PCT: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_PERCENTAGE); break; case Format::PCT2: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_PERCENTAGE_00); break; case Format::STRING: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); break; } $sheet->setCellValueByColumnAndRow($col, $row, $value); $sheet->duplicateStyle($style, Coordinate::stringFromColumnIndex($col).$row); }
php
protected function applyValue(Worksheet $sheet, $col, $row, $value, $format, $styleArray = []) { if (0 == count($styleArray)) { $styleArray = $this->getDefaultStyleArrayForRow($row); } $style = new Style(); $style->applyFromArray($styleArray); switch ($format) { case Format::DATE: if (!($value instanceof \DateTime)) { $date = new \DateTime($value); } else { $date = $value; } $value = Date::PHPToExcel($date); $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2); break; case Format::DATETIME: if (!($value instanceof \DateTime)) { $date = new \DateTime($value); } else { $date = $value; } $value = Date::PHPToExcel($date); $style->getNumberFormat()->setFormatCode(self::FORMAT_DATETIME); break; case Format::FLOAT2: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1); break; case Format::INTEGER: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER); break; case Format::MONEY: case Format::MONEY2: $style->getNumberFormat()->setFormatCode(self::FORMAT_EUR); break; case Format::PCT: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_PERCENTAGE); break; case Format::PCT2: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_PERCENTAGE_00); break; case Format::STRING: $style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); break; } $sheet->setCellValueByColumnAndRow($col, $row, $value); $sheet->duplicateStyle($style, Coordinate::stringFromColumnIndex($col).$row); }
[ "protected", "function", "applyValue", "(", "Worksheet", "$", "sheet", ",", "$", "col", ",", "$", "row", ",", "$", "value", ",", "$", "format", ",", "$", "styleArray", "=", "[", "]", ")", "{", "if", "(", "0", "==", "count", "(", "$", "styleArray", ")", ")", "{", "$", "styleArray", "=", "$", "this", "->", "getDefaultStyleArrayForRow", "(", "$", "row", ")", ";", "}", "$", "style", "=", "new", "Style", "(", ")", ";", "$", "style", "->", "applyFromArray", "(", "$", "styleArray", ")", ";", "switch", "(", "$", "format", ")", "{", "case", "Format", "::", "DATE", ":", "if", "(", "!", "(", "$", "value", "instanceof", "\\", "DateTime", ")", ")", "{", "$", "date", "=", "new", "\\", "DateTime", "(", "$", "value", ")", ";", "}", "else", "{", "$", "date", "=", "$", "value", ";", "}", "$", "value", "=", "Date", "::", "PHPToExcel", "(", "$", "date", ")", ";", "$", "style", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "NumberFormat", "::", "FORMAT_DATE_YYYYMMDD2", ")", ";", "break", ";", "case", "Format", "::", "DATETIME", ":", "if", "(", "!", "(", "$", "value", "instanceof", "\\", "DateTime", ")", ")", "{", "$", "date", "=", "new", "\\", "DateTime", "(", "$", "value", ")", ";", "}", "else", "{", "$", "date", "=", "$", "value", ";", "}", "$", "value", "=", "Date", "::", "PHPToExcel", "(", "$", "date", ")", ";", "$", "style", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "self", "::", "FORMAT_DATETIME", ")", ";", "break", ";", "case", "Format", "::", "FLOAT2", ":", "$", "style", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "NumberFormat", "::", "FORMAT_NUMBER_COMMA_SEPARATED1", ")", ";", "break", ";", "case", "Format", "::", "INTEGER", ":", "$", "style", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "NumberFormat", "::", "FORMAT_NUMBER", ")", ";", "break", ";", "case", "Format", "::", "MONEY", ":", "case", "Format", "::", "MONEY2", ":", "$", "style", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "self", "::", "FORMAT_EUR", ")", ";", "break", ";", "case", "Format", "::", "PCT", ":", "$", "style", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "NumberFormat", "::", "FORMAT_PERCENTAGE", ")", ";", "break", ";", "case", "Format", "::", "PCT2", ":", "$", "style", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "NumberFormat", "::", "FORMAT_PERCENTAGE_00", ")", ";", "break", ";", "case", "Format", "::", "STRING", ":", "$", "style", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "NumberFormat", "::", "FORMAT_TEXT", ")", ";", "break", ";", "}", "$", "sheet", "->", "setCellValueByColumnAndRow", "(", "$", "col", ",", "$", "row", ",", "$", "value", ")", ";", "$", "sheet", "->", "duplicateStyle", "(", "$", "style", ",", "Coordinate", "::", "stringFromColumnIndex", "(", "$", "col", ")", ".", "$", "row", ")", ";", "}" ]
Set value in specific cell @param Worksheet $sheet The worksheet @param integer $col The selected column @param integer $row The selected row @param array $value The values to insert @param array $format Associative arrays with formats @param array $styleArray An array representing the style @throws \Exception
[ "Set", "value", "in", "specific", "cell" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php#L267-L325
37,853
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.addIndexesAsColumn
public function addIndexesAsColumn($columnName, $headerName = null, $format = null, AggregationInterface $aggregation = null, $metaData = []) { $values = []; foreach ($this->indexes as $index) { $values[$index] = $index; } $column = new StatsColumnBuilder( $values, $headerName, $format, $aggregation, $metaData ); $columns = array_reverse($this->columns); $columns[$columnName] = $column; $this->columns = $columns; }
php
public function addIndexesAsColumn($columnName, $headerName = null, $format = null, AggregationInterface $aggregation = null, $metaData = []) { $values = []; foreach ($this->indexes as $index) { $values[$index] = $index; } $column = new StatsColumnBuilder( $values, $headerName, $format, $aggregation, $metaData ); $columns = array_reverse($this->columns); $columns[$columnName] = $column; $this->columns = $columns; }
[ "public", "function", "addIndexesAsColumn", "(", "$", "columnName", ",", "$", "headerName", "=", "null", ",", "$", "format", "=", "null", ",", "AggregationInterface", "$", "aggregation", "=", "null", ",", "$", "metaData", "=", "[", "]", ")", "{", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "indexes", "as", "$", "index", ")", "{", "$", "values", "[", "$", "index", "]", "=", "$", "index", ";", "}", "$", "column", "=", "new", "StatsColumnBuilder", "(", "$", "values", ",", "$", "headerName", ",", "$", "format", ",", "$", "aggregation", ",", "$", "metaData", ")", ";", "$", "columns", "=", "array_reverse", "(", "$", "this", "->", "columns", ")", ";", "$", "columns", "[", "$", "columnName", "]", "=", "$", "column", ";", "$", "this", "->", "columns", "=", "$", "columns", ";", "}" ]
Add index of data as a new column @param $columnName @param null $headerName @param null $format @param AggregationInterface $aggregation
[ "Add", "index", "of", "data", "as", "a", "new", "column" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L62-L80
37,854
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.appendTable
public function appendTable( $table, $headers, $formats, $aggregations, $columnNames = [], $defaultValues = [], $metaData = [] ) { $this->defaultValues = array_merge($this->defaultValues, $defaultValues); if (count($columnNames) === 0 && count($table) !== 0) { $columnNames = array_keys(reset($table)); } if (count($columnNames) === 0 && count($headers) !== 0) { $columnNames = array_keys($headers); } foreach ($columnNames as $columnName) { $column = new StatsColumnBuilder( $this->getAssocColumn($table, $columnName), $this->getParameter($headers, $columnName, $columnName), $this->getParameter($formats, $columnName), $this->getParameter($aggregations, $columnName), $this->getParameter($metaData, $columnName, []) ); if (count($this->defaultValues)) { $column->insureIsFilled($this->indexes, $this->defaultValues[$columnName]); } $this->columns[$columnName] = $column; } }
php
public function appendTable( $table, $headers, $formats, $aggregations, $columnNames = [], $defaultValues = [], $metaData = [] ) { $this->defaultValues = array_merge($this->defaultValues, $defaultValues); if (count($columnNames) === 0 && count($table) !== 0) { $columnNames = array_keys(reset($table)); } if (count($columnNames) === 0 && count($headers) !== 0) { $columnNames = array_keys($headers); } foreach ($columnNames as $columnName) { $column = new StatsColumnBuilder( $this->getAssocColumn($table, $columnName), $this->getParameter($headers, $columnName, $columnName), $this->getParameter($formats, $columnName), $this->getParameter($aggregations, $columnName), $this->getParameter($metaData, $columnName, []) ); if (count($this->defaultValues)) { $column->insureIsFilled($this->indexes, $this->defaultValues[$columnName]); } $this->columns[$columnName] = $column; } }
[ "public", "function", "appendTable", "(", "$", "table", ",", "$", "headers", ",", "$", "formats", ",", "$", "aggregations", ",", "$", "columnNames", "=", "[", "]", ",", "$", "defaultValues", "=", "[", "]", ",", "$", "metaData", "=", "[", "]", ")", "{", "$", "this", "->", "defaultValues", "=", "array_merge", "(", "$", "this", "->", "defaultValues", ",", "$", "defaultValues", ")", ";", "if", "(", "count", "(", "$", "columnNames", ")", "===", "0", "&&", "count", "(", "$", "table", ")", "!==", "0", ")", "{", "$", "columnNames", "=", "array_keys", "(", "reset", "(", "$", "table", ")", ")", ";", "}", "if", "(", "count", "(", "$", "columnNames", ")", "===", "0", "&&", "count", "(", "$", "headers", ")", "!==", "0", ")", "{", "$", "columnNames", "=", "array_keys", "(", "$", "headers", ")", ";", "}", "foreach", "(", "$", "columnNames", "as", "$", "columnName", ")", "{", "$", "column", "=", "new", "StatsColumnBuilder", "(", "$", "this", "->", "getAssocColumn", "(", "$", "table", ",", "$", "columnName", ")", ",", "$", "this", "->", "getParameter", "(", "$", "headers", ",", "$", "columnName", ",", "$", "columnName", ")", ",", "$", "this", "->", "getParameter", "(", "$", "formats", ",", "$", "columnName", ")", ",", "$", "this", "->", "getParameter", "(", "$", "aggregations", ",", "$", "columnName", ")", ",", "$", "this", "->", "getParameter", "(", "$", "metaData", ",", "$", "columnName", ",", "[", "]", ")", ")", ";", "if", "(", "count", "(", "$", "this", "->", "defaultValues", ")", ")", "{", "$", "column", "->", "insureIsFilled", "(", "$", "this", "->", "indexes", ",", "$", "this", "->", "defaultValues", "[", "$", "columnName", "]", ")", ";", "}", "$", "this", "->", "columns", "[", "$", "columnName", "]", "=", "$", "column", ";", "}", "}" ]
Append columns given a table @param array $table @param string[] $headers @param string[] $formats @param AggregationInterface[] $aggregations @param string[] $columnNames @param mixed[] $defaultValues
[ "Append", "columns", "given", "a", "table" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L92-L126
37,855
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.getParameter
private function getParameter($values, $key, $defaultValue = null) { return array_key_exists($key, $values) ? $values[$key] : $defaultValue; }
php
private function getParameter($values, $key, $defaultValue = null) { return array_key_exists($key, $values) ? $values[$key] : $defaultValue; }
[ "private", "function", "getParameter", "(", "$", "values", ",", "$", "key", ",", "$", "defaultValue", "=", "null", ")", "{", "return", "array_key_exists", "(", "$", "key", ",", "$", "values", ")", "?", "$", "values", "[", "$", "key", "]", ":", "$", "defaultValue", ";", "}" ]
Get an indexed value in a table. Same as ParameterBag @param array $values @param mixed $key @param mixed $defaultValue @return mixed
[ "Get", "an", "indexed", "value", "in", "a", "table", ".", "Same", "as", "ParameterBag" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L135-L138
37,856
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.getAssocColumn
public function getAssocColumn($table, $columnName, $defaultValue = null) { $values = []; foreach ($table as $key => $line) { if (array_key_exists($columnName, $line)) { $values[$key] = $line[$columnName]; } else { $values[$key] = $defaultValue; } } return $values; }
php
public function getAssocColumn($table, $columnName, $defaultValue = null) { $values = []; foreach ($table as $key => $line) { if (array_key_exists($columnName, $line)) { $values[$key] = $line[$columnName]; } else { $values[$key] = $defaultValue; } } return $values; }
[ "public", "function", "getAssocColumn", "(", "$", "table", ",", "$", "columnName", ",", "$", "defaultValue", "=", "null", ")", "{", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "table", "as", "$", "key", "=>", "$", "line", ")", "{", "if", "(", "array_key_exists", "(", "$", "columnName", ",", "$", "line", ")", ")", "{", "$", "values", "[", "$", "key", "]", "=", "$", "line", "[", "$", "columnName", "]", ";", "}", "else", "{", "$", "values", "[", "$", "key", "]", "=", "$", "defaultValue", ";", "}", "}", "return", "$", "values", ";", "}" ]
Returns an associative table only with selected column. Fill with default value if column not in a row @param array $table @param string $columnName @param mixed $defaultValue @return array The column
[ "Returns", "an", "associative", "table", "only", "with", "selected", "column", ".", "Fill", "with", "default", "value", "if", "column", "not", "in", "a", "row" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L148-L160
37,857
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.getColumn
public function getColumn($columnName) { if (!array_key_exists($columnName, $this->columns)) { throw new \InvalidArgumentException('Unable to find column '.$columnName.' in columns '.join(',', array_keys($this->columns))); } return $this->columns[$columnName]; }
php
public function getColumn($columnName) { if (!array_key_exists($columnName, $this->columns)) { throw new \InvalidArgumentException('Unable to find column '.$columnName.' in columns '.join(',', array_keys($this->columns))); } return $this->columns[$columnName]; }
[ "public", "function", "getColumn", "(", "$", "columnName", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "columnName", ",", "$", "this", "->", "columns", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unable to find column '", ".", "$", "columnName", ".", "' in columns '", ".", "join", "(", "','", ",", "array_keys", "(", "$", "this", "->", "columns", ")", ")", ")", ";", "}", "return", "$", "this", "->", "columns", "[", "$", "columnName", "]", ";", "}" ]
Retrieve a column @return StatsColumnBuilder @throws \InvalidArgumentException
[ "Retrieve", "a", "column" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L167-L174
37,858
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.addDynamicColumn
public function addDynamicColumn($columnName, DynamicColumnBuilderInterface $dynamicColumn, $header = '', $format = null, AggregationInterface $aggregation = null, $metaData = []) { $values = $dynamicColumn->buildColumnValues($this); $this->columns[$columnName] = new StatsColumnBuilder($values, $header, $format, $aggregation, $metaData); }
php
public function addDynamicColumn($columnName, DynamicColumnBuilderInterface $dynamicColumn, $header = '', $format = null, AggregationInterface $aggregation = null, $metaData = []) { $values = $dynamicColumn->buildColumnValues($this); $this->columns[$columnName] = new StatsColumnBuilder($values, $header, $format, $aggregation, $metaData); }
[ "public", "function", "addDynamicColumn", "(", "$", "columnName", ",", "DynamicColumnBuilderInterface", "$", "dynamicColumn", ",", "$", "header", "=", "''", ",", "$", "format", "=", "null", ",", "AggregationInterface", "$", "aggregation", "=", "null", ",", "$", "metaData", "=", "[", "]", ")", "{", "$", "values", "=", "$", "dynamicColumn", "->", "buildColumnValues", "(", "$", "this", ")", ";", "$", "this", "->", "columns", "[", "$", "columnName", "]", "=", "new", "StatsColumnBuilder", "(", "$", "values", ",", "$", "header", ",", "$", "format", ",", "$", "aggregation", ",", "$", "metaData", ")", ";", "}" ]
Add a dynamic column @param mixed $columnName @param DynamicColumnBuilderInterface $dynamicColumn @param string $header @param string $format @param AggregationInterface $aggregation
[ "Add", "a", "dynamic", "column" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L194-L198
37,859
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.build
public function build($columns = []) { $headers = []; $data = []; $dataFormats = []; $aggregations = []; $aggregationsFormats = []; $metaData = []; foreach ($this->indexes as $index) { $columnsNames = array_keys($this->columns); $line = []; foreach ($columnsNames as $columnName) { $columnValues = $this->columns[$columnName]->getValues(); $line = array_merge($line, [$columnName => $columnValues[$index]]); } $data[$index] = $this->orderColumns($line, $columns); } foreach ($this->columns as $columnName => $column) { $dataFormats[$columnName] = $column->getFormat(); $headers = array_merge($headers, [$columnName => $column->getHeaderName()]); $metaData = array_merge($metaData, [$columnName => $column->getMetaData()]); $columnAggregation = $column->getAggregation(); if ($columnAggregation) { $aggregationValue = $columnAggregation->aggregate($this); $aggregationsFormats[$columnName] = $columnAggregation->getFormat(); } else { $aggregationValue = null; } $aggregations = array_merge($aggregations, [$columnName => $aggregationValue]); } $headers = $this->orderColumns($headers, $columns); $metaData = $this->orderColumns($metaData, $columns); $aggregations = $this->orderColumns($aggregations, $columns); return new StatsTable($data, $headers, $aggregations, $dataFormats, $aggregationsFormats, $metaData); }
php
public function build($columns = []) { $headers = []; $data = []; $dataFormats = []; $aggregations = []; $aggregationsFormats = []; $metaData = []; foreach ($this->indexes as $index) { $columnsNames = array_keys($this->columns); $line = []; foreach ($columnsNames as $columnName) { $columnValues = $this->columns[$columnName]->getValues(); $line = array_merge($line, [$columnName => $columnValues[$index]]); } $data[$index] = $this->orderColumns($line, $columns); } foreach ($this->columns as $columnName => $column) { $dataFormats[$columnName] = $column->getFormat(); $headers = array_merge($headers, [$columnName => $column->getHeaderName()]); $metaData = array_merge($metaData, [$columnName => $column->getMetaData()]); $columnAggregation = $column->getAggregation(); if ($columnAggregation) { $aggregationValue = $columnAggregation->aggregate($this); $aggregationsFormats[$columnName] = $columnAggregation->getFormat(); } else { $aggregationValue = null; } $aggregations = array_merge($aggregations, [$columnName => $aggregationValue]); } $headers = $this->orderColumns($headers, $columns); $metaData = $this->orderColumns($metaData, $columns); $aggregations = $this->orderColumns($aggregations, $columns); return new StatsTable($data, $headers, $aggregations, $dataFormats, $aggregationsFormats, $metaData); }
[ "public", "function", "build", "(", "$", "columns", "=", "[", "]", ")", "{", "$", "headers", "=", "[", "]", ";", "$", "data", "=", "[", "]", ";", "$", "dataFormats", "=", "[", "]", ";", "$", "aggregations", "=", "[", "]", ";", "$", "aggregationsFormats", "=", "[", "]", ";", "$", "metaData", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "indexes", "as", "$", "index", ")", "{", "$", "columnsNames", "=", "array_keys", "(", "$", "this", "->", "columns", ")", ";", "$", "line", "=", "[", "]", ";", "foreach", "(", "$", "columnsNames", "as", "$", "columnName", ")", "{", "$", "columnValues", "=", "$", "this", "->", "columns", "[", "$", "columnName", "]", "->", "getValues", "(", ")", ";", "$", "line", "=", "array_merge", "(", "$", "line", ",", "[", "$", "columnName", "=>", "$", "columnValues", "[", "$", "index", "]", "]", ")", ";", "}", "$", "data", "[", "$", "index", "]", "=", "$", "this", "->", "orderColumns", "(", "$", "line", ",", "$", "columns", ")", ";", "}", "foreach", "(", "$", "this", "->", "columns", "as", "$", "columnName", "=>", "$", "column", ")", "{", "$", "dataFormats", "[", "$", "columnName", "]", "=", "$", "column", "->", "getFormat", "(", ")", ";", "$", "headers", "=", "array_merge", "(", "$", "headers", ",", "[", "$", "columnName", "=>", "$", "column", "->", "getHeaderName", "(", ")", "]", ")", ";", "$", "metaData", "=", "array_merge", "(", "$", "metaData", ",", "[", "$", "columnName", "=>", "$", "column", "->", "getMetaData", "(", ")", "]", ")", ";", "$", "columnAggregation", "=", "$", "column", "->", "getAggregation", "(", ")", ";", "if", "(", "$", "columnAggregation", ")", "{", "$", "aggregationValue", "=", "$", "columnAggregation", "->", "aggregate", "(", "$", "this", ")", ";", "$", "aggregationsFormats", "[", "$", "columnName", "]", "=", "$", "columnAggregation", "->", "getFormat", "(", ")", ";", "}", "else", "{", "$", "aggregationValue", "=", "null", ";", "}", "$", "aggregations", "=", "array_merge", "(", "$", "aggregations", ",", "[", "$", "columnName", "=>", "$", "aggregationValue", "]", ")", ";", "}", "$", "headers", "=", "$", "this", "->", "orderColumns", "(", "$", "headers", ",", "$", "columns", ")", ";", "$", "metaData", "=", "$", "this", "->", "orderColumns", "(", "$", "metaData", ",", "$", "columns", ")", ";", "$", "aggregations", "=", "$", "this", "->", "orderColumns", "(", "$", "aggregations", ",", "$", "columns", ")", ";", "return", "new", "StatsTable", "(", "$", "data", ",", "$", "headers", ",", "$", "aggregations", ",", "$", "dataFormats", ",", "$", "aggregationsFormats", ",", "$", "metaData", ")", ";", "}" ]
Build the data @param array $columns Desired columns @return StatsTable
[ "Build", "the", "data" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L218-L261
37,860
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.orderColumns
public static function orderColumns($table, $columns) { // If no columns given, return table as-is if (!$columns) { return $table; } // Order $result = []; foreach ($columns as $column) { if (array_key_exists($column, $table)) { $result[$column] = $table[$column]; } } return $result; }
php
public static function orderColumns($table, $columns) { // If no columns given, return table as-is if (!$columns) { return $table; } // Order $result = []; foreach ($columns as $column) { if (array_key_exists($column, $table)) { $result[$column] = $table[$column]; } } return $result; }
[ "public", "static", "function", "orderColumns", "(", "$", "table", ",", "$", "columns", ")", "{", "// If no columns given, return table as-is", "if", "(", "!", "$", "columns", ")", "{", "return", "$", "table", ";", "}", "// Order", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "if", "(", "array_key_exists", "(", "$", "column", ",", "$", "table", ")", ")", "{", "$", "result", "[", "$", "column", "]", "=", "$", "table", "[", "$", "column", "]", ";", "}", "}", "return", "$", "result", ";", "}" ]
Order table columns given columns table @param array $table @param array $columns @return array
[ "Order", "table", "columns", "given", "columns", "table" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L269-L285
37,861
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsTableBuilder.php
StatsTableBuilder.groupBy
public function groupBy($columns, array $excludeColumns = []) { $groupedData = []; $statsTable = $this->build(); foreach ($statsTable->getData() as $line) { $key = join( '-_##_-', array_map( function ($c) use ($line) { return $line[$c]; }, $columns ) ); $groupedData[$key][] = $line; } $filterLine = function ($line) use ($excludeColumns) { foreach ($excludeColumns as $c) { unset($line[$c]); } return $line; }; $headers = $filterLine( array_map( function (StatsColumnBuilder $c) { return $c->getHeaderName(); }, $this->columns ) ); $formats = $filterLine( array_map( function (StatsColumnBuilder $c) { return $c->getFormat(); }, $this->columns ) ); $aggregations = $filterLine( array_map( function (StatsColumnBuilder $c) { return $c->getAggregation(); }, $this->columns ) ); $metaData = $filterLine( array_map( function (StatsColumnBuilder $c) { return $c->getMetaData(); }, $this->columns ) ); $data = []; foreach ($groupedData as $lines) { $tmpAggregations = $aggregations; // Add static aggragation for group by fields foreach ($columns as $column) { $oneLine = current($lines); $value = $oneLine[$column]; $tmpAggregations[$column] = new StaticAggregation($value, Format::STRING); } $tmpTableBuilder = new StatsTableBuilder( array_map($filterLine, $lines), $headers, $formats, $tmpAggregations, [], [], null, $metaData ); $tmpTable = $tmpTableBuilder->build(); $data[] = $tmpTable->getAggregations(); } return new StatsTableBuilder( $data, $headers, $formats, $aggregations, [], [], null, $metaData ); }
php
public function groupBy($columns, array $excludeColumns = []) { $groupedData = []; $statsTable = $this->build(); foreach ($statsTable->getData() as $line) { $key = join( '-_##_-', array_map( function ($c) use ($line) { return $line[$c]; }, $columns ) ); $groupedData[$key][] = $line; } $filterLine = function ($line) use ($excludeColumns) { foreach ($excludeColumns as $c) { unset($line[$c]); } return $line; }; $headers = $filterLine( array_map( function (StatsColumnBuilder $c) { return $c->getHeaderName(); }, $this->columns ) ); $formats = $filterLine( array_map( function (StatsColumnBuilder $c) { return $c->getFormat(); }, $this->columns ) ); $aggregations = $filterLine( array_map( function (StatsColumnBuilder $c) { return $c->getAggregation(); }, $this->columns ) ); $metaData = $filterLine( array_map( function (StatsColumnBuilder $c) { return $c->getMetaData(); }, $this->columns ) ); $data = []; foreach ($groupedData as $lines) { $tmpAggregations = $aggregations; // Add static aggragation for group by fields foreach ($columns as $column) { $oneLine = current($lines); $value = $oneLine[$column]; $tmpAggregations[$column] = new StaticAggregation($value, Format::STRING); } $tmpTableBuilder = new StatsTableBuilder( array_map($filterLine, $lines), $headers, $formats, $tmpAggregations, [], [], null, $metaData ); $tmpTable = $tmpTableBuilder->build(); $data[] = $tmpTable->getAggregations(); } return new StatsTableBuilder( $data, $headers, $formats, $aggregations, [], [], null, $metaData ); }
[ "public", "function", "groupBy", "(", "$", "columns", ",", "array", "$", "excludeColumns", "=", "[", "]", ")", "{", "$", "groupedData", "=", "[", "]", ";", "$", "statsTable", "=", "$", "this", "->", "build", "(", ")", ";", "foreach", "(", "$", "statsTable", "->", "getData", "(", ")", "as", "$", "line", ")", "{", "$", "key", "=", "join", "(", "'-_##_-'", ",", "array_map", "(", "function", "(", "$", "c", ")", "use", "(", "$", "line", ")", "{", "return", "$", "line", "[", "$", "c", "]", ";", "}", ",", "$", "columns", ")", ")", ";", "$", "groupedData", "[", "$", "key", "]", "[", "]", "=", "$", "line", ";", "}", "$", "filterLine", "=", "function", "(", "$", "line", ")", "use", "(", "$", "excludeColumns", ")", "{", "foreach", "(", "$", "excludeColumns", "as", "$", "c", ")", "{", "unset", "(", "$", "line", "[", "$", "c", "]", ")", ";", "}", "return", "$", "line", ";", "}", ";", "$", "headers", "=", "$", "filterLine", "(", "array_map", "(", "function", "(", "StatsColumnBuilder", "$", "c", ")", "{", "return", "$", "c", "->", "getHeaderName", "(", ")", ";", "}", ",", "$", "this", "->", "columns", ")", ")", ";", "$", "formats", "=", "$", "filterLine", "(", "array_map", "(", "function", "(", "StatsColumnBuilder", "$", "c", ")", "{", "return", "$", "c", "->", "getFormat", "(", ")", ";", "}", ",", "$", "this", "->", "columns", ")", ")", ";", "$", "aggregations", "=", "$", "filterLine", "(", "array_map", "(", "function", "(", "StatsColumnBuilder", "$", "c", ")", "{", "return", "$", "c", "->", "getAggregation", "(", ")", ";", "}", ",", "$", "this", "->", "columns", ")", ")", ";", "$", "metaData", "=", "$", "filterLine", "(", "array_map", "(", "function", "(", "StatsColumnBuilder", "$", "c", ")", "{", "return", "$", "c", "->", "getMetaData", "(", ")", ";", "}", ",", "$", "this", "->", "columns", ")", ")", ";", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "groupedData", "as", "$", "lines", ")", "{", "$", "tmpAggregations", "=", "$", "aggregations", ";", "// Add static aggragation for group by fields", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "$", "oneLine", "=", "current", "(", "$", "lines", ")", ";", "$", "value", "=", "$", "oneLine", "[", "$", "column", "]", ";", "$", "tmpAggregations", "[", "$", "column", "]", "=", "new", "StaticAggregation", "(", "$", "value", ",", "Format", "::", "STRING", ")", ";", "}", "$", "tmpTableBuilder", "=", "new", "StatsTableBuilder", "(", "array_map", "(", "$", "filterLine", ",", "$", "lines", ")", ",", "$", "headers", ",", "$", "formats", ",", "$", "tmpAggregations", ",", "[", "]", ",", "[", "]", ",", "null", ",", "$", "metaData", ")", ";", "$", "tmpTable", "=", "$", "tmpTableBuilder", "->", "build", "(", ")", ";", "$", "data", "[", "]", "=", "$", "tmpTable", "->", "getAggregations", "(", ")", ";", "}", "return", "new", "StatsTableBuilder", "(", "$", "data", ",", "$", "headers", ",", "$", "formats", ",", "$", "aggregations", ",", "[", "]", ",", "[", "]", ",", "null", ",", "$", "metaData", ")", ";", "}" ]
Do a groupBy on columns, using aggregations to aggregate data per line @param string|array $columns Columns to aggregate @param array $excludeColumns Irrelevant columns to exclude @return StatsTableBuilder
[ "Do", "a", "groupBy", "on", "columns", "using", "aggregations", "to", "aggregate", "data", "per", "line" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsTableBuilder.php#L303-L398
37,862
igraal/stats-table
lib/IgraalOSL/StatsTable/Dumper/JSON/JSONDumper.php
JSONDumper.formatValue
protected function formatValue($format, $value) { switch ($format) { case Format::DATE: case Format::DATETIME: if ($value instanceof \DateTime) { return $value->format('c'); } break; case Format::FLOAT2: case Format::MONEY2: return floatval(sprintf("%.2f", $value)); case Format::PCT2: return floatval(sprintf('%.2f', $value*100)); case Format::PCT: return intval(sprintf('%d', $value*100)); case Format::INTEGER: case Format::MONEY: return intval(sprintf("%d", $value)); } return $value; }
php
protected function formatValue($format, $value) { switch ($format) { case Format::DATE: case Format::DATETIME: if ($value instanceof \DateTime) { return $value->format('c'); } break; case Format::FLOAT2: case Format::MONEY2: return floatval(sprintf("%.2f", $value)); case Format::PCT2: return floatval(sprintf('%.2f', $value*100)); case Format::PCT: return intval(sprintf('%d', $value*100)); case Format::INTEGER: case Format::MONEY: return intval(sprintf("%d", $value)); } return $value; }
[ "protected", "function", "formatValue", "(", "$", "format", ",", "$", "value", ")", "{", "switch", "(", "$", "format", ")", "{", "case", "Format", "::", "DATE", ":", "case", "Format", "::", "DATETIME", ":", "if", "(", "$", "value", "instanceof", "\\", "DateTime", ")", "{", "return", "$", "value", "->", "format", "(", "'c'", ")", ";", "}", "break", ";", "case", "Format", "::", "FLOAT2", ":", "case", "Format", "::", "MONEY2", ":", "return", "floatval", "(", "sprintf", "(", "\"%.2f\"", ",", "$", "value", ")", ")", ";", "case", "Format", "::", "PCT2", ":", "return", "floatval", "(", "sprintf", "(", "'%.2f'", ",", "$", "value", "*", "100", ")", ")", ";", "case", "Format", "::", "PCT", ":", "return", "intval", "(", "sprintf", "(", "'%d'", ",", "$", "value", "*", "100", ")", ")", ";", "case", "Format", "::", "INTEGER", ":", "case", "Format", "::", "MONEY", ":", "return", "intval", "(", "sprintf", "(", "\"%d\"", ",", "$", "value", ")", ")", ";", "}", "return", "$", "value", ";", "}" ]
Format values for JSON @param $format @param $value @return float|int|string
[ "Format", "values", "for", "JSON" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/Dumper/JSON/JSONDumper.php#L58-L84
37,863
igraal/stats-table
lib/IgraalOSL/StatsTable/StatsColumnBuilder.php
StatsColumnBuilder.insureIsFilled
public function insureIsFilled($indexes, $defaultValue) { $newValues = []; foreach ($indexes as $index) { $newValues[$index] = array_key_exists($index, $this->values) ? $this->values[$index] : $defaultValue; } $this->values = $newValues; }
php
public function insureIsFilled($indexes, $defaultValue) { $newValues = []; foreach ($indexes as $index) { $newValues[$index] = array_key_exists($index, $this->values) ? $this->values[$index] : $defaultValue; } $this->values = $newValues; }
[ "public", "function", "insureIsFilled", "(", "$", "indexes", ",", "$", "defaultValue", ")", "{", "$", "newValues", "=", "[", "]", ";", "foreach", "(", "$", "indexes", "as", "$", "index", ")", "{", "$", "newValues", "[", "$", "index", "]", "=", "array_key_exists", "(", "$", "index", ",", "$", "this", "->", "values", ")", "?", "$", "this", "->", "values", "[", "$", "index", "]", ":", "$", "defaultValue", ";", "}", "$", "this", "->", "values", "=", "$", "newValues", ";", "}" ]
Ensure column is filled with given indexes. If not, it will be filled with default values @param $indexes @param $defaultValue
[ "Ensure", "column", "is", "filled", "with", "given", "indexes", ".", "If", "not", "it", "will", "be", "filled", "with", "default", "values" ]
b3649f9a929567d0c585187f50331d61bcb3453f
https://github.com/igraal/stats-table/blob/b3649f9a929567d0c585187f50331d61bcb3453f/lib/IgraalOSL/StatsTable/StatsColumnBuilder.php#L112-L119
37,864
DevMarketer/LaravelEasyNav
src/DevMarketer/EasyNav/EasyNav.php
EasyNav.hasSegment
public function hasSegment($slugs, $segments = 1, $active = NULL) { $this->setActive($active); $segments = (!is_array($segments) ? [$segments] : $segments); $slugs = (!is_array($slugs) ? [$slugs] : $slugs); foreach ($slugs as $slug) { foreach ($segments as $segment) { if ($this->request->segment($segment) == $slug) return $this->active; } } return ''; }
php
public function hasSegment($slugs, $segments = 1, $active = NULL) { $this->setActive($active); $segments = (!is_array($segments) ? [$segments] : $segments); $slugs = (!is_array($slugs) ? [$slugs] : $slugs); foreach ($slugs as $slug) { foreach ($segments as $segment) { if ($this->request->segment($segment) == $slug) return $this->active; } } return ''; }
[ "public", "function", "hasSegment", "(", "$", "slugs", ",", "$", "segments", "=", "1", ",", "$", "active", "=", "NULL", ")", "{", "$", "this", "->", "setActive", "(", "$", "active", ")", ";", "$", "segments", "=", "(", "!", "is_array", "(", "$", "segments", ")", "?", "[", "$", "segments", "]", ":", "$", "segments", ")", ";", "$", "slugs", "=", "(", "!", "is_array", "(", "$", "slugs", ")", "?", "[", "$", "slugs", "]", ":", "$", "slugs", ")", ";", "foreach", "(", "$", "slugs", "as", "$", "slug", ")", "{", "foreach", "(", "$", "segments", "as", "$", "segment", ")", "{", "if", "(", "$", "this", "->", "request", "->", "segment", "(", "$", "segment", ")", "==", "$", "slug", ")", "return", "$", "this", "->", "active", ";", "}", "}", "return", "''", ";", "}" ]
returns the active class if the defined segment exists in the current request URI @param string|array $slugs @param int|array $segments @param string|NULL $active @return string
[ "returns", "the", "active", "class", "if", "the", "defined", "segment", "exists", "in", "the", "current", "request", "URI" ]
517a7d5a35f443574c0ce883d458849cae7b3330
https://github.com/DevMarketer/LaravelEasyNav/blob/517a7d5a35f443574c0ce883d458849cae7b3330/src/DevMarketer/EasyNav/EasyNav.php#L56-L67
37,865
DevMarketer/LaravelEasyNav
src/DevMarketer/EasyNav/EasyNav.php
EasyNav.isRoute
public function isRoute($route, $active = NULL) { $this->setActive($active); return ($this->request->routeIs($route) ? $this->active : ''); }
php
public function isRoute($route, $active = NULL) { $this->setActive($active); return ($this->request->routeIs($route) ? $this->active : ''); }
[ "public", "function", "isRoute", "(", "$", "route", ",", "$", "active", "=", "NULL", ")", "{", "$", "this", "->", "setActive", "(", "$", "active", ")", ";", "return", "(", "$", "this", "->", "request", "->", "routeIs", "(", "$", "route", ")", "?", "$", "this", "->", "active", ":", "''", ")", ";", "}" ]
Receives a named route and returns true or false depending if the current URL is equal to the named route provided. @param string $route @param string|NULL $active @return string
[ "Receives", "a", "named", "route", "and", "returns", "true", "or", "false", "depending", "if", "the", "current", "URL", "is", "equal", "to", "the", "named", "route", "provided", "." ]
517a7d5a35f443574c0ce883d458849cae7b3330
https://github.com/DevMarketer/LaravelEasyNav/blob/517a7d5a35f443574c0ce883d458849cae7b3330/src/DevMarketer/EasyNav/EasyNav.php#L90-L94
37,866
DevMarketer/LaravelEasyNav
src/DevMarketer/EasyNav/EasyNav.php
EasyNav.isResource
public function isResource($resource, $prefix = NULL, $active = NULL, $strict = false) { $this->setActive($active); if ($prefix && is_string($prefix)) { $prefix = str_replace('.', '/', $prefix); $search = trim($prefix,'/').'/'.trim($resource, '/'); } else { $search = trim($resource, '/'); } return ($this->pathContains($search, $strict) ? $this->active : ''); }
php
public function isResource($resource, $prefix = NULL, $active = NULL, $strict = false) { $this->setActive($active); if ($prefix && is_string($prefix)) { $prefix = str_replace('.', '/', $prefix); $search = trim($prefix,'/').'/'.trim($resource, '/'); } else { $search = trim($resource, '/'); } return ($this->pathContains($search, $strict) ? $this->active : ''); }
[ "public", "function", "isResource", "(", "$", "resource", ",", "$", "prefix", "=", "NULL", ",", "$", "active", "=", "NULL", ",", "$", "strict", "=", "false", ")", "{", "$", "this", "->", "setActive", "(", "$", "active", ")", ";", "if", "(", "$", "prefix", "&&", "is_string", "(", "$", "prefix", ")", ")", "{", "$", "prefix", "=", "str_replace", "(", "'.'", ",", "'/'", ",", "$", "prefix", ")", ";", "$", "search", "=", "trim", "(", "$", "prefix", ",", "'/'", ")", ".", "'/'", ".", "trim", "(", "$", "resource", ",", "'/'", ")", ";", "}", "else", "{", "$", "search", "=", "trim", "(", "$", "resource", ",", "'/'", ")", ";", "}", "return", "(", "$", "this", "->", "pathContains", "(", "$", "search", ",", "$", "strict", ")", "?", "$", "this", "->", "active", ":", "''", ")", ";", "}" ]
Checks if current page is one of a specified resouce provided in the function. Also accepts a prefix or strict mode to optionally prevent false-positives @param string $resource @param string|NULL $prefix @param string $active @param bool $strict @return string
[ "Checks", "if", "current", "page", "is", "one", "of", "a", "specified", "resouce", "provided", "in", "the", "function", ".", "Also", "accepts", "a", "prefix", "or", "strict", "mode", "to", "optionally", "prevent", "false", "-", "positives" ]
517a7d5a35f443574c0ce883d458849cae7b3330
https://github.com/DevMarketer/LaravelEasyNav/blob/517a7d5a35f443574c0ce883d458849cae7b3330/src/DevMarketer/EasyNav/EasyNav.php#L107-L117
37,867
RNCryptor/RNCryptor-php
src/RNCryptor/Encryptor.php
Encryptor.encrypt
public function encrypt($plaintext, $password, $version = Cryptor::DEFAULT_SCHEMA_VERSION, $base64Encode = true) { $this->configure($version); $components = $this->makeComponents($version); $components->headers->encSalt = $this->makeSalt(); $components->headers->hmacSalt = $this->makeSalt(); $components->headers->iv = $this->makeIv($this->config->ivLength); $encKey = $this->makeKey($components->headers->encSalt, $password); $hmacKey = $this->makeKey($components->headers->hmacSalt, $password); return $this->encryptFromComponents($plaintext, $components, $encKey, $hmacKey, $base64Encode); }
php
public function encrypt($plaintext, $password, $version = Cryptor::DEFAULT_SCHEMA_VERSION, $base64Encode = true) { $this->configure($version); $components = $this->makeComponents($version); $components->headers->encSalt = $this->makeSalt(); $components->headers->hmacSalt = $this->makeSalt(); $components->headers->iv = $this->makeIv($this->config->ivLength); $encKey = $this->makeKey($components->headers->encSalt, $password); $hmacKey = $this->makeKey($components->headers->hmacSalt, $password); return $this->encryptFromComponents($plaintext, $components, $encKey, $hmacKey, $base64Encode); }
[ "public", "function", "encrypt", "(", "$", "plaintext", ",", "$", "password", ",", "$", "version", "=", "Cryptor", "::", "DEFAULT_SCHEMA_VERSION", ",", "$", "base64Encode", "=", "true", ")", "{", "$", "this", "->", "configure", "(", "$", "version", ")", ";", "$", "components", "=", "$", "this", "->", "makeComponents", "(", "$", "version", ")", ";", "$", "components", "->", "headers", "->", "encSalt", "=", "$", "this", "->", "makeSalt", "(", ")", ";", "$", "components", "->", "headers", "->", "hmacSalt", "=", "$", "this", "->", "makeSalt", "(", ")", ";", "$", "components", "->", "headers", "->", "iv", "=", "$", "this", "->", "makeIv", "(", "$", "this", "->", "config", "->", "ivLength", ")", ";", "$", "encKey", "=", "$", "this", "->", "makeKey", "(", "$", "components", "->", "headers", "->", "encSalt", ",", "$", "password", ")", ";", "$", "hmacKey", "=", "$", "this", "->", "makeKey", "(", "$", "components", "->", "headers", "->", "hmacSalt", ",", "$", "password", ")", ";", "return", "$", "this", "->", "encryptFromComponents", "(", "$", "plaintext", ",", "$", "components", ",", "$", "encKey", ",", "$", "hmacKey", ",", "$", "base64Encode", ")", ";", "}" ]
Encrypt plaintext using RNCryptor's algorithm @param string $plaintext Text to be encrypted @param string $password Password to use @param int $version (Optional) RNCryptor schema version to use. @throws \Exception If the provided version (if any) is unsupported @return string Encrypted, Base64-encoded string
[ "Encrypt", "plaintext", "using", "RNCryptor", "s", "algorithm" ]
bf07c357461994b223bb4e3433cf442902f6e68b
https://github.com/RNCryptor/RNCryptor-php/blob/bf07c357461994b223bb4e3433cf442902f6e68b/src/RNCryptor/Encryptor.php#L23-L36
37,868
RNCryptor/RNCryptor-php
src/RNCryptor/Decryptor.php
Decryptor.decrypt
public function decrypt($encryptedBase64Data, $password) { $components = $this->unpackEncryptedBase64Data($encryptedBase64Data); if (!$this->hmacIsValid($components, $password)) { return false; } $key = $this->makeKey($components->headers->encSalt, $password); if ($this->config->mode == 'ctr') { return $this->aesCtrLittleEndianCrypt($components->ciphertext, $key, $components->headers->iv); } $iv = (string)$components->headers->iv; $method = $this->config->algorithm . 'cbc'; return openssl_decrypt($components->ciphertext, $method, $key, OPENSSL_RAW_DATA, (string)$iv); }
php
public function decrypt($encryptedBase64Data, $password) { $components = $this->unpackEncryptedBase64Data($encryptedBase64Data); if (!$this->hmacIsValid($components, $password)) { return false; } $key = $this->makeKey($components->headers->encSalt, $password); if ($this->config->mode == 'ctr') { return $this->aesCtrLittleEndianCrypt($components->ciphertext, $key, $components->headers->iv); } $iv = (string)$components->headers->iv; $method = $this->config->algorithm . 'cbc'; return openssl_decrypt($components->ciphertext, $method, $key, OPENSSL_RAW_DATA, (string)$iv); }
[ "public", "function", "decrypt", "(", "$", "encryptedBase64Data", ",", "$", "password", ")", "{", "$", "components", "=", "$", "this", "->", "unpackEncryptedBase64Data", "(", "$", "encryptedBase64Data", ")", ";", "if", "(", "!", "$", "this", "->", "hmacIsValid", "(", "$", "components", ",", "$", "password", ")", ")", "{", "return", "false", ";", "}", "$", "key", "=", "$", "this", "->", "makeKey", "(", "$", "components", "->", "headers", "->", "encSalt", ",", "$", "password", ")", ";", "if", "(", "$", "this", "->", "config", "->", "mode", "==", "'ctr'", ")", "{", "return", "$", "this", "->", "aesCtrLittleEndianCrypt", "(", "$", "components", "->", "ciphertext", ",", "$", "key", ",", "$", "components", "->", "headers", "->", "iv", ")", ";", "}", "$", "iv", "=", "(", "string", ")", "$", "components", "->", "headers", "->", "iv", ";", "$", "method", "=", "$", "this", "->", "config", "->", "algorithm", ".", "'cbc'", ";", "return", "openssl_decrypt", "(", "$", "components", "->", "ciphertext", ",", "$", "method", ",", "$", "key", ",", "OPENSSL_RAW_DATA", ",", "(", "string", ")", "$", "iv", ")", ";", "}" ]
Decrypt RNCryptor-encrypted data @param string $base64EncryptedData Encrypted, Base64-encoded text @param string $password Password the text was encoded with @throws Exception If the detected version is unsupported @return string|false Decrypted string, or false if decryption failed
[ "Decrypt", "RNCryptor", "-", "encrypted", "data" ]
bf07c357461994b223bb4e3433cf442902f6e68b
https://github.com/RNCryptor/RNCryptor-php/blob/bf07c357461994b223bb4e3433cf442902f6e68b/src/RNCryptor/Decryptor.php#L22-L39
37,869
serverfireteam/blog
src/models/Blog.php
Blog.getUrl
function getUrl(){ return \Config::get('app.url') .'/blog/post/'. $this->id . '/' . \Serverfireteam\blog\BlogController::seoUrl($this->title); }
php
function getUrl(){ return \Config::get('app.url') .'/blog/post/'. $this->id . '/' . \Serverfireteam\blog\BlogController::seoUrl($this->title); }
[ "function", "getUrl", "(", ")", "{", "return", "\\", "Config", "::", "get", "(", "'app.url'", ")", ".", "'/blog/post/'", ".", "$", "this", "->", "id", ".", "'/'", ".", "\\", "Serverfireteam", "\\", "blog", "\\", "BlogController", "::", "seoUrl", "(", "$", "this", "->", "title", ")", ";", "}" ]
return url of blog post
[ "return", "url", "of", "blog", "post" ]
d6f7aadc51b21b5ac9d216aa06615e680c5eb20f
https://github.com/serverfireteam/blog/blob/d6f7aadc51b21b5ac9d216aa06615e680c5eb20f/src/models/Blog.php#L19-L21
37,870
serverfireteam/blog
src/controllers/BlogController.php
BlogController.getShare
public function getShare($id,$social) { $url = ''; $post = \App\Blog::find($id); if($post == NULL){ App::abort(404); } // add social point if it is not robot if (!isset($_SERVER['HTTP_USER_AGENT']) && !preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) { $post->socialPoint ++; $post->save(); } switch ($social){ case 'twitter' : $url = 'https://twitter.com/home?status='; $url .= $post['title'] . ' ' . $post->getUrl(); break; case 'facebook' : $url = 'https://www.facebook.com/sharer/sharer.php?u='; $url .= $post->getUrl(); break; case 'googlePlus' : $url = 'https://plus.google.com/share?url='; $url .= $post->getUrl(); break; case 'linkedIn' : $url = 'https://www.linkedin.com/shareArticle?mini=true&'; $url .= 'url='.$post->getUrl().'&title='.$post['title'].'&summary=&source='; break; } return \Redirect::to($url); }
php
public function getShare($id,$social) { $url = ''; $post = \App\Blog::find($id); if($post == NULL){ App::abort(404); } // add social point if it is not robot if (!isset($_SERVER['HTTP_USER_AGENT']) && !preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) { $post->socialPoint ++; $post->save(); } switch ($social){ case 'twitter' : $url = 'https://twitter.com/home?status='; $url .= $post['title'] . ' ' . $post->getUrl(); break; case 'facebook' : $url = 'https://www.facebook.com/sharer/sharer.php?u='; $url .= $post->getUrl(); break; case 'googlePlus' : $url = 'https://plus.google.com/share?url='; $url .= $post->getUrl(); break; case 'linkedIn' : $url = 'https://www.linkedin.com/shareArticle?mini=true&'; $url .= 'url='.$post->getUrl().'&title='.$post['title'].'&summary=&source='; break; } return \Redirect::to($url); }
[ "public", "function", "getShare", "(", "$", "id", ",", "$", "social", ")", "{", "$", "url", "=", "''", ";", "$", "post", "=", "\\", "App", "\\", "Blog", "::", "find", "(", "$", "id", ")", ";", "if", "(", "$", "post", "==", "NULL", ")", "{", "App", "::", "abort", "(", "404", ")", ";", "}", "// add social point if it is not robot", "if", "(", "!", "isset", "(", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ")", "&&", "!", "preg_match", "(", "'/bot|crawl|slurp|spider/i'", ",", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ")", ")", "{", "$", "post", "->", "socialPoint", "++", ";", "$", "post", "->", "save", "(", ")", ";", "}", "switch", "(", "$", "social", ")", "{", "case", "'twitter'", ":", "$", "url", "=", "'https://twitter.com/home?status='", ";", "$", "url", ".=", "$", "post", "[", "'title'", "]", ".", "' '", ".", "$", "post", "->", "getUrl", "(", ")", ";", "break", ";", "case", "'facebook'", ":", "$", "url", "=", "'https://www.facebook.com/sharer/sharer.php?u='", ";", "$", "url", ".=", "$", "post", "->", "getUrl", "(", ")", ";", "break", ";", "case", "'googlePlus'", ":", "$", "url", "=", "'https://plus.google.com/share?url='", ";", "$", "url", ".=", "$", "post", "->", "getUrl", "(", ")", ";", "break", ";", "case", "'linkedIn'", ":", "$", "url", "=", "'https://www.linkedin.com/shareArticle?mini=true&'", ";", "$", "url", ".=", "'url='", ".", "$", "post", "->", "getUrl", "(", ")", ".", "'&title='", ".", "$", "post", "[", "'title'", "]", ".", "'&summary=&source='", ";", "break", ";", "}", "return", "\\", "Redirect", "::", "to", "(", "$", "url", ")", ";", "}" ]
Add the point to
[ "Add", "the", "point", "to" ]
d6f7aadc51b21b5ac9d216aa06615e680c5eb20f
https://github.com/serverfireteam/blog/blob/d6f7aadc51b21b5ac9d216aa06615e680c5eb20f/src/controllers/BlogController.php#L57-L89
37,871
ollyxar/websockets
src/Handler.php
Handler.listenSocket
protected function listenSocket(): Generator { yield Dispatcher::listenRead($this->server); $handle = fopen($this->locker, 'a'); if ($handle && flock($handle, LOCK_EX)) { yield Dispatcher::async($this->acceptSocket()); flock($handle, LOCK_UN); } fclose($handle); yield Dispatcher::async($this->listenSocket()); }
php
protected function listenSocket(): Generator { yield Dispatcher::listenRead($this->server); $handle = fopen($this->locker, 'a'); if ($handle && flock($handle, LOCK_EX)) { yield Dispatcher::async($this->acceptSocket()); flock($handle, LOCK_UN); } fclose($handle); yield Dispatcher::async($this->listenSocket()); }
[ "protected", "function", "listenSocket", "(", ")", ":", "Generator", "{", "yield", "Dispatcher", "::", "listenRead", "(", "$", "this", "->", "server", ")", ";", "$", "handle", "=", "fopen", "(", "$", "this", "->", "locker", ",", "'a'", ")", ";", "if", "(", "$", "handle", "&&", "flock", "(", "$", "handle", ",", "LOCK_EX", ")", ")", "{", "yield", "Dispatcher", "::", "async", "(", "$", "this", "->", "acceptSocket", "(", ")", ")", ";", "flock", "(", "$", "handle", ",", "LOCK_UN", ")", ";", "}", "fclose", "(", "$", "handle", ")", ";", "yield", "Dispatcher", "::", "async", "(", "$", "this", "->", "listenSocket", "(", ")", ")", ";", "}" ]
Main socket listener @return Generator
[ "Main", "socket", "listener" ]
2c5972f3ad37b682620661306c866ecebb048be4
https://github.com/ollyxar/websockets/blob/2c5972f3ad37b682620661306c866ecebb048be4/src/Handler.php#L185-L197
37,872
ollyxar/websockets
src/Handler.php
Handler.afterHandshake
protected function afterHandshake($socket): Generator { Logger::log('worker', $this->pid, 'connection accepted for', (int)$socket); $this->clients[(int)$socket] = $socket; yield Dispatcher::async($this->onConnect($socket)); yield Dispatcher::async($this->read($socket)); }
php
protected function afterHandshake($socket): Generator { Logger::log('worker', $this->pid, 'connection accepted for', (int)$socket); $this->clients[(int)$socket] = $socket; yield Dispatcher::async($this->onConnect($socket)); yield Dispatcher::async($this->read($socket)); }
[ "protected", "function", "afterHandshake", "(", "$", "socket", ")", ":", "Generator", "{", "Logger", "::", "log", "(", "'worker'", ",", "$", "this", "->", "pid", ",", "'connection accepted for'", ",", "(", "int", ")", "$", "socket", ")", ";", "$", "this", "->", "clients", "[", "(", "int", ")", "$", "socket", "]", "=", "$", "socket", ";", "yield", "Dispatcher", "::", "async", "(", "$", "this", "->", "onConnect", "(", "$", "socket", ")", ")", ";", "yield", "Dispatcher", "::", "async", "(", "$", "this", "->", "read", "(", "$", "socket", ")", ")", ";", "}" ]
Process headers after handshake success @param $socket @return Generator
[ "Process", "headers", "after", "handshake", "success" ]
2c5972f3ad37b682620661306c866ecebb048be4
https://github.com/ollyxar/websockets/blob/2c5972f3ad37b682620661306c866ecebb048be4/src/Handler.php#L217-L223
37,873
ollyxar/websockets
src/Handler.php
Handler.onMasterMessage
protected function onMasterMessage(string $message): Generator { yield Dispatcher::async($this->broadcast(Frame::encode($message), false)); }
php
protected function onMasterMessage(string $message): Generator { yield Dispatcher::async($this->broadcast(Frame::encode($message), false)); }
[ "protected", "function", "onMasterMessage", "(", "string", "$", "message", ")", ":", "Generator", "{", "yield", "Dispatcher", "::", "async", "(", "$", "this", "->", "broadcast", "(", "Frame", "::", "encode", "(", "$", "message", ")", ",", "false", ")", ")", ";", "}" ]
This method called when message received from the Master. @param string $message @return Generator
[ "This", "method", "called", "when", "message", "received", "from", "the", "Master", "." ]
2c5972f3ad37b682620661306c866ecebb048be4
https://github.com/ollyxar/websockets/blob/2c5972f3ad37b682620661306c866ecebb048be4/src/Handler.php#L259-L262
37,874
stevenmaguire/uber-php
src/GetSetTrait.php
GetSetTrait.updateAttribute
private function updateAttribute($attribute, $value) { if (property_exists($this, $attribute)) { $this->$attribute = $value; } return $this; }
php
private function updateAttribute($attribute, $value) { if (property_exists($this, $attribute)) { $this->$attribute = $value; } return $this; }
[ "private", "function", "updateAttribute", "(", "$", "attribute", ",", "$", "value", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "$", "attribute", ")", ")", "{", "$", "this", "->", "$", "attribute", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Updates a specific attribute of the current object. @param string $attribute @param string|boolean|integer $value @return object
[ "Updates", "a", "specific", "attribute", "of", "the", "current", "object", "." ]
6a5710dda83102aaef23c8f14e73a493d58963e9
https://github.com/stevenmaguire/uber-php/blob/6a5710dda83102aaef23c8f14e73a493d58963e9/src/GetSetTrait.php#L89-L96
37,875
rakuten-ws/rws-php-sdk
lib/RakutenRws/Client.php
RakutenRws_Client.getAuthorizeUrl
public function getAuthorizeUrl($scope) { $url = 'https://app.rakuten.co.jp/services/authorize'; $parameter = array(); $parameter = array( 'response_type' => 'code', 'client_id' => $this->developerId, 'redirect_uri' => $this->redirectUrl, 'scope' => $scope ); return $url.'?'.http_build_query($parameter); }
php
public function getAuthorizeUrl($scope) { $url = 'https://app.rakuten.co.jp/services/authorize'; $parameter = array(); $parameter = array( 'response_type' => 'code', 'client_id' => $this->developerId, 'redirect_uri' => $this->redirectUrl, 'scope' => $scope ); return $url.'?'.http_build_query($parameter); }
[ "public", "function", "getAuthorizeUrl", "(", "$", "scope", ")", "{", "$", "url", "=", "'https://app.rakuten.co.jp/services/authorize'", ";", "$", "parameter", "=", "array", "(", ")", ";", "$", "parameter", "=", "array", "(", "'response_type'", "=>", "'code'", ",", "'client_id'", "=>", "$", "this", "->", "developerId", ",", "'redirect_uri'", "=>", "$", "this", "->", "redirectUrl", ",", "'scope'", "=>", "$", "scope", ")", ";", "return", "$", "url", ".", "'?'", ".", "http_build_query", "(", "$", "parameter", ")", ";", "}" ]
Gets OAuth2 Authorize URL @param string $scope The scopes that is separated by ',' @return string The Authorize URL
[ "Gets", "OAuth2", "Authorize", "URL" ]
ca9c78d8f3bc8714a4366a9a3a247bc2788a41eb
https://github.com/rakuten-ws/rws-php-sdk/blob/ca9c78d8f3bc8714a4366a9a3a247bc2788a41eb/lib/RakutenRws/Client.php#L136-L148
37,876
rakuten-ws/rws-php-sdk
lib/RakutenRws/Client.php
RakutenRws_Client.fetchAccessTokenFromCode
public function fetchAccessTokenFromCode($code = null) { if ($code === null) { if (!isset($_GET['code'])) { throw new LogicException("A parameter code is not set."); } $code = $_GET['code']; } $url = $this->getAccessTokenUrl(); $parameter = array( 'grant_type' => 'authorization_code', 'client_id' => $this->developerId, 'client_secret' => $this->secret, 'code' => $code, 'redirect_uri' => $this->redirectUrl ); $response = $this->httpClient->post( $url, $parameter ); if ($response->getCode() == 200) { $this->accessTokenInfo = json_decode($response->getContents(), true); if (isset($this->accessTokenInfo['access_token'])) { $this->accessToken = $this->accessTokenInfo['access_token']; return $this->accessToken; } } return null; }
php
public function fetchAccessTokenFromCode($code = null) { if ($code === null) { if (!isset($_GET['code'])) { throw new LogicException("A parameter code is not set."); } $code = $_GET['code']; } $url = $this->getAccessTokenUrl(); $parameter = array( 'grant_type' => 'authorization_code', 'client_id' => $this->developerId, 'client_secret' => $this->secret, 'code' => $code, 'redirect_uri' => $this->redirectUrl ); $response = $this->httpClient->post( $url, $parameter ); if ($response->getCode() == 200) { $this->accessTokenInfo = json_decode($response->getContents(), true); if (isset($this->accessTokenInfo['access_token'])) { $this->accessToken = $this->accessTokenInfo['access_token']; return $this->accessToken; } } return null; }
[ "public", "function", "fetchAccessTokenFromCode", "(", "$", "code", "=", "null", ")", "{", "if", "(", "$", "code", "===", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "_GET", "[", "'code'", "]", ")", ")", "{", "throw", "new", "LogicException", "(", "\"A parameter code is not set.\"", ")", ";", "}", "$", "code", "=", "$", "_GET", "[", "'code'", "]", ";", "}", "$", "url", "=", "$", "this", "->", "getAccessTokenUrl", "(", ")", ";", "$", "parameter", "=", "array", "(", "'grant_type'", "=>", "'authorization_code'", ",", "'client_id'", "=>", "$", "this", "->", "developerId", ",", "'client_secret'", "=>", "$", "this", "->", "secret", ",", "'code'", "=>", "$", "code", ",", "'redirect_uri'", "=>", "$", "this", "->", "redirectUrl", ")", ";", "$", "response", "=", "$", "this", "->", "httpClient", "->", "post", "(", "$", "url", ",", "$", "parameter", ")", ";", "if", "(", "$", "response", "->", "getCode", "(", ")", "==", "200", ")", "{", "$", "this", "->", "accessTokenInfo", "=", "json_decode", "(", "$", "response", "->", "getContents", "(", ")", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "accessTokenInfo", "[", "'access_token'", "]", ")", ")", "{", "$", "this", "->", "accessToken", "=", "$", "this", "->", "accessTokenInfo", "[", "'access_token'", "]", ";", "return", "$", "this", "->", "accessToken", ";", "}", "}", "return", "null", ";", "}" ]
Fetches OAuth2 AccessToken from Code @param string $code The Code @return string The Access Token, If response is invalid return null @throws LogicException
[ "Fetches", "OAuth2", "AccessToken", "from", "Code" ]
ca9c78d8f3bc8714a4366a9a3a247bc2788a41eb
https://github.com/rakuten-ws/rws-php-sdk/blob/ca9c78d8f3bc8714a4366a9a3a247bc2788a41eb/lib/RakutenRws/Client.php#L167-L201
37,877
ollyxar/websockets
src/Server.php
Server.makeSocket
protected function makeSocket(): void { if ($this->useSSL) { if (!file_exists($this->cert)) { throw new \Exception('Cert file not found'); } $context = stream_context_create([ 'ssl' => [ 'local_cert' => $this->cert, 'passphrase' => $this->passPhrase, 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, 'verify_depth' => 0 ] ]); $protocol = 'ssl'; } else { $context = stream_context_create(); $protocol = 'tcp'; } $this->socket = stream_socket_server("$protocol://{$this->host}:{$this->port}", $errorNumber, $errorString, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context); if ($this->useConnector) { if (file_exists(static::$connector)) { unlink(static::$connector); } $this->unixConnector = stream_socket_server('unix://' . static::$connector, $errorNumber, $errorString, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN); chmod(static::$connector, 0777); } if (!$this->socket) { throw new SocketException($errorString, $errorNumber); } }
php
protected function makeSocket(): void { if ($this->useSSL) { if (!file_exists($this->cert)) { throw new \Exception('Cert file not found'); } $context = stream_context_create([ 'ssl' => [ 'local_cert' => $this->cert, 'passphrase' => $this->passPhrase, 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, 'verify_depth' => 0 ] ]); $protocol = 'ssl'; } else { $context = stream_context_create(); $protocol = 'tcp'; } $this->socket = stream_socket_server("$protocol://{$this->host}:{$this->port}", $errorNumber, $errorString, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context); if ($this->useConnector) { if (file_exists(static::$connector)) { unlink(static::$connector); } $this->unixConnector = stream_socket_server('unix://' . static::$connector, $errorNumber, $errorString, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN); chmod(static::$connector, 0777); } if (!$this->socket) { throw new SocketException($errorString, $errorNumber); } }
[ "protected", "function", "makeSocket", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "useSSL", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "cert", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Cert file not found'", ")", ";", "}", "$", "context", "=", "stream_context_create", "(", "[", "'ssl'", "=>", "[", "'local_cert'", "=>", "$", "this", "->", "cert", ",", "'passphrase'", "=>", "$", "this", "->", "passPhrase", ",", "'verify_peer'", "=>", "false", ",", "'verify_peer_name'", "=>", "false", ",", "'allow_self_signed'", "=>", "true", ",", "'verify_depth'", "=>", "0", "]", "]", ")", ";", "$", "protocol", "=", "'ssl'", ";", "}", "else", "{", "$", "context", "=", "stream_context_create", "(", ")", ";", "$", "protocol", "=", "'tcp'", ";", "}", "$", "this", "->", "socket", "=", "stream_socket_server", "(", "\"$protocol://{$this->host}:{$this->port}\"", ",", "$", "errorNumber", ",", "$", "errorString", ",", "STREAM_SERVER_BIND", "|", "STREAM_SERVER_LISTEN", ",", "$", "context", ")", ";", "if", "(", "$", "this", "->", "useConnector", ")", "{", "if", "(", "file_exists", "(", "static", "::", "$", "connector", ")", ")", "{", "unlink", "(", "static", "::", "$", "connector", ")", ";", "}", "$", "this", "->", "unixConnector", "=", "stream_socket_server", "(", "'unix://'", ".", "static", "::", "$", "connector", ",", "$", "errorNumber", ",", "$", "errorString", ",", "STREAM_SERVER_BIND", "|", "STREAM_SERVER_LISTEN", ")", ";", "chmod", "(", "static", "::", "$", "connector", ",", "0777", ")", ";", "}", "if", "(", "!", "$", "this", "->", "socket", ")", "{", "throw", "new", "SocketException", "(", "$", "errorString", ",", "$", "errorNumber", ")", ";", "}", "}" ]
Make server sockets @throws SocketException|\Exception @return void
[ "Make", "server", "sockets" ]
2c5972f3ad37b682620661306c866ecebb048be4
https://github.com/ollyxar/websockets/blob/2c5972f3ad37b682620661306c866ecebb048be4/src/Server.php#L64-L102
37,878
ollyxar/websockets
src/Server.php
Server.spawn
protected function spawn(): array { $pid = $master = null; $workers = []; for ($i = 0; $i < $this->workerCount; $i++) { $pair = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $pid = pcntl_fork(); if ($pid == -1) { throw new ForkException('Cannot fork process'); } elseif ($pid) { fclose($pair[0]); $workers[$pid] = $pair[1]; } else { fclose($pair[1]); $master = $pair[0]; break; } } return [$pid, $master, $workers]; }
php
protected function spawn(): array { $pid = $master = null; $workers = []; for ($i = 0; $i < $this->workerCount; $i++) { $pair = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $pid = pcntl_fork(); if ($pid == -1) { throw new ForkException('Cannot fork process'); } elseif ($pid) { fclose($pair[0]); $workers[$pid] = $pair[1]; } else { fclose($pair[1]); $master = $pair[0]; break; } } return [$pid, $master, $workers]; }
[ "protected", "function", "spawn", "(", ")", ":", "array", "{", "$", "pid", "=", "$", "master", "=", "null", ";", "$", "workers", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "this", "->", "workerCount", ";", "$", "i", "++", ")", "{", "$", "pair", "=", "stream_socket_pair", "(", "STREAM_PF_UNIX", ",", "STREAM_SOCK_STREAM", ",", "STREAM_IPPROTO_IP", ")", ";", "$", "pid", "=", "pcntl_fork", "(", ")", ";", "if", "(", "$", "pid", "==", "-", "1", ")", "{", "throw", "new", "ForkException", "(", "'Cannot fork process'", ")", ";", "}", "elseif", "(", "$", "pid", ")", "{", "fclose", "(", "$", "pair", "[", "0", "]", ")", ";", "$", "workers", "[", "$", "pid", "]", "=", "$", "pair", "[", "1", "]", ";", "}", "else", "{", "fclose", "(", "$", "pair", "[", "1", "]", ")", ";", "$", "master", "=", "$", "pair", "[", "0", "]", ";", "break", ";", "}", "}", "return", "[", "$", "pid", ",", "$", "master", ",", "$", "workers", "]", ";", "}" ]
Spawning process to avoid system limits and increase performance @throws ForkException @return array
[ "Spawning", "process", "to", "avoid", "system", "limits", "and", "increase", "performance" ]
2c5972f3ad37b682620661306c866ecebb048be4
https://github.com/ollyxar/websockets/blob/2c5972f3ad37b682620661306c866ecebb048be4/src/Server.php#L110-L133
37,879
ollyxar/websockets
src/Server.php
Server.handleSignals
protected function handleSignals(): void { foreach ([SIGTERM, SIGQUIT, SIGABRT, SIGINT] as $signal) { pcntl_signal($signal, function ($signal) { $this->terminate($signal); }); } }
php
protected function handleSignals(): void { foreach ([SIGTERM, SIGQUIT, SIGABRT, SIGINT] as $signal) { pcntl_signal($signal, function ($signal) { $this->terminate($signal); }); } }
[ "protected", "function", "handleSignals", "(", ")", ":", "void", "{", "foreach", "(", "[", "SIGTERM", ",", "SIGQUIT", ",", "SIGABRT", ",", "SIGINT", "]", "as", "$", "signal", ")", "{", "pcntl_signal", "(", "$", "signal", ",", "function", "(", "$", "signal", ")", "{", "$", "this", "->", "terminate", "(", "$", "signal", ")", ";", "}", ")", ";", "}", "}" ]
Process system signals @return void
[ "Process", "system", "signals" ]
2c5972f3ad37b682620661306c866ecebb048be4
https://github.com/ollyxar/websockets/blob/2c5972f3ad37b682620661306c866ecebb048be4/src/Server.php#L155-L162
37,880
ollyxar/websockets
src/Logger.php
Logger.log
public static function log($speakerType, $speakerId, $message, $raw = ''): void { if (!static::$enabled) { return; } switch ($speakerType) { case 'master': $speaker = "\033[1;34m" . $speakerId . "\033[0m"; break; default: $speaker = "\033[1;35m" . $speakerId . "\033[0m"; } $log = "\033[1;37m"; try { $log .= \DateTime::createFromFormat('U.u', microtime(true))->format("i:s:u"); } catch (\Throwable $exception) { $log .= 'cannot get current time. God damn fast!'; } $log .= "\033[0m "; $log .= $speaker . " "; $log .= "\033[1;32m" . $message . "\033[0m "; $log .= "\033[42m" . $raw . "\033[0m\n"; print $log; }
php
public static function log($speakerType, $speakerId, $message, $raw = ''): void { if (!static::$enabled) { return; } switch ($speakerType) { case 'master': $speaker = "\033[1;34m" . $speakerId . "\033[0m"; break; default: $speaker = "\033[1;35m" . $speakerId . "\033[0m"; } $log = "\033[1;37m"; try { $log .= \DateTime::createFromFormat('U.u', microtime(true))->format("i:s:u"); } catch (\Throwable $exception) { $log .= 'cannot get current time. God damn fast!'; } $log .= "\033[0m "; $log .= $speaker . " "; $log .= "\033[1;32m" . $message . "\033[0m "; $log .= "\033[42m" . $raw . "\033[0m\n"; print $log; }
[ "public", "static", "function", "log", "(", "$", "speakerType", ",", "$", "speakerId", ",", "$", "message", ",", "$", "raw", "=", "''", ")", ":", "void", "{", "if", "(", "!", "static", "::", "$", "enabled", ")", "{", "return", ";", "}", "switch", "(", "$", "speakerType", ")", "{", "case", "'master'", ":", "$", "speaker", "=", "\"\\033[1;34m\"", ".", "$", "speakerId", ".", "\"\\033[0m\"", ";", "break", ";", "default", ":", "$", "speaker", "=", "\"\\033[1;35m\"", ".", "$", "speakerId", ".", "\"\\033[0m\"", ";", "}", "$", "log", "=", "\"\\033[1;37m\"", ";", "try", "{", "$", "log", ".=", "\\", "DateTime", "::", "createFromFormat", "(", "'U.u'", ",", "microtime", "(", "true", ")", ")", "->", "format", "(", "\"i:s:u\"", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "exception", ")", "{", "$", "log", ".=", "'cannot get current time. God damn fast!'", ";", "}", "$", "log", ".=", "\"\\033[0m \"", ";", "$", "log", ".=", "$", "speaker", ".", "\" \"", ";", "$", "log", ".=", "\"\\033[1;32m\"", ".", "$", "message", ".", "\"\\033[0m \"", ";", "$", "log", ".=", "\"\\033[42m\"", ".", "$", "raw", ".", "\"\\033[0m\\n\"", ";", "print", "$", "log", ";", "}" ]
Printing info into console @param $speakerType @param $speakerId @param $message @param string $raw @return void
[ "Printing", "info", "into", "console" ]
2c5972f3ad37b682620661306c866ecebb048be4
https://github.com/ollyxar/websockets/blob/2c5972f3ad37b682620661306c866ecebb048be4/src/Logger.php#L41-L68
37,881
stevenmaguire/uber-php
src/Client.php
Client.applyConfiguration
private function applyConfiguration($configuration = []) { array_walk($configuration, function ($value, $key) { $this->updateAttribute($key, $value); }); }
php
private function applyConfiguration($configuration = []) { array_walk($configuration, function ($value, $key) { $this->updateAttribute($key, $value); }); }
[ "private", "function", "applyConfiguration", "(", "$", "configuration", "=", "[", "]", ")", "{", "array_walk", "(", "$", "configuration", ",", "function", "(", "$", "value", ",", "$", "key", ")", "{", "$", "this", "->", "updateAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", ")", ";", "}" ]
Applies configuration to client. @param array $configuration @return void
[ "Applies", "configuration", "to", "client", "." ]
6a5710dda83102aaef23c8f14e73a493d58963e9
https://github.com/stevenmaguire/uber-php/blob/6a5710dda83102aaef23c8f14e73a493d58963e9/src/Client.php#L87-L92
37,882
stevenmaguire/uber-php
src/Client.php
Client.getConfigForVerbAndParameters
private function getConfigForVerbAndParameters($verb, $parameters = []) { $config = [ 'headers' => $this->getHeaders() ]; if (!empty($parameters)) { if (strtolower($verb) == 'get') { $config['query'] = $parameters; } else { $config['json'] = $parameters; } } return $config; }
php
private function getConfigForVerbAndParameters($verb, $parameters = []) { $config = [ 'headers' => $this->getHeaders() ]; if (!empty($parameters)) { if (strtolower($verb) == 'get') { $config['query'] = $parameters; } else { $config['json'] = $parameters; } } return $config; }
[ "private", "function", "getConfigForVerbAndParameters", "(", "$", "verb", ",", "$", "parameters", "=", "[", "]", ")", "{", "$", "config", "=", "[", "'headers'", "=>", "$", "this", "->", "getHeaders", "(", ")", "]", ";", "if", "(", "!", "empty", "(", "$", "parameters", ")", ")", "{", "if", "(", "strtolower", "(", "$", "verb", ")", "==", "'get'", ")", "{", "$", "config", "[", "'query'", "]", "=", "$", "parameters", ";", "}", "else", "{", "$", "config", "[", "'json'", "]", "=", "$", "parameters", ";", "}", "}", "return", "$", "config", ";", "}" ]
Gets HttpClient config for verb and parameters. @param string $verb @param array $parameters @return array
[ "Gets", "HttpClient", "config", "for", "verb", "and", "parameters", "." ]
6a5710dda83102aaef23c8f14e73a493d58963e9
https://github.com/stevenmaguire/uber-php/blob/6a5710dda83102aaef23c8f14e73a493d58963e9/src/Client.php#L116-L131
37,883
stevenmaguire/uber-php
src/Client.php
Client.getUrlFromPath
public function getUrlFromPath($path) { $path = ltrim($path, '/'); $host = 'https://'.($this->use_sandbox ? 'sandbox-' : '').'api.uber.com'; return $host.($this->version ? '/'.$this->version : '').'/'.$path; }
php
public function getUrlFromPath($path) { $path = ltrim($path, '/'); $host = 'https://'.($this->use_sandbox ? 'sandbox-' : '').'api.uber.com'; return $host.($this->version ? '/'.$this->version : '').'/'.$path; }
[ "public", "function", "getUrlFromPath", "(", "$", "path", ")", "{", "$", "path", "=", "ltrim", "(", "$", "path", ",", "'/'", ")", ";", "$", "host", "=", "'https://'", ".", "(", "$", "this", "->", "use_sandbox", "?", "'sandbox-'", ":", "''", ")", ".", "'api.uber.com'", ";", "return", "$", "host", ".", "(", "$", "this", "->", "version", "?", "'/'", ".", "$", "this", "->", "version", ":", "''", ")", ".", "'/'", ".", "$", "path", ";", "}" ]
Builds url from path. @param string $path @return string Url
[ "Builds", "url", "from", "path", "." ]
6a5710dda83102aaef23c8f14e73a493d58963e9
https://github.com/stevenmaguire/uber-php/blob/6a5710dda83102aaef23c8f14e73a493d58963e9/src/Client.php#L153-L160
37,884
stevenmaguire/uber-php
src/Client.php
Client.handleRequestException
private function handleRequestException(HttpClientException $e) { if ($response = $e->getResponse()) { $exception = new Exception($response->getReasonPhrase(), $response->getStatusCode(), $e); $exception->setBody(json_decode($response->getBody())); throw $exception; } throw new Exception($e->getMessage(), 500, $e); }
php
private function handleRequestException(HttpClientException $e) { if ($response = $e->getResponse()) { $exception = new Exception($response->getReasonPhrase(), $response->getStatusCode(), $e); $exception->setBody(json_decode($response->getBody())); throw $exception; } throw new Exception($e->getMessage(), 500, $e); }
[ "private", "function", "handleRequestException", "(", "HttpClientException", "$", "e", ")", "{", "if", "(", "$", "response", "=", "$", "e", "->", "getResponse", "(", ")", ")", "{", "$", "exception", "=", "new", "Exception", "(", "$", "response", "->", "getReasonPhrase", "(", ")", ",", "$", "response", "->", "getStatusCode", "(", ")", ",", "$", "e", ")", ";", "$", "exception", "->", "setBody", "(", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", ")", ")", ";", "throw", "$", "exception", ";", "}", "throw", "new", "Exception", "(", "$", "e", "->", "getMessage", "(", ")", ",", "500", ",", "$", "e", ")", ";", "}" ]
Handles http client exceptions. @param HttpClientException $e @return void @throws Exception
[ "Handles", "http", "client", "exceptions", "." ]
6a5710dda83102aaef23c8f14e73a493d58963e9
https://github.com/stevenmaguire/uber-php/blob/6a5710dda83102aaef23c8f14e73a493d58963e9/src/Client.php#L170-L180
37,885
stevenmaguire/uber-php
src/Client.php
Client.parseRateLimitFromResponse
private function parseRateLimitFromResponse(Response $response) { $rateLimitHeaders = array_filter([ $response->getHeader('X-Rate-Limit-Limit'), $response->getHeader('X-Rate-Limit-Remaining'), $response->getHeader('X-Rate-Limit-Reset') ]); if (count($rateLimitHeaders) == 3) { $rateLimitClass = new ReflectionClass(RateLimit::class); $this->rate_limit = $rateLimitClass->newInstanceArgs($rateLimitHeaders); } }
php
private function parseRateLimitFromResponse(Response $response) { $rateLimitHeaders = array_filter([ $response->getHeader('X-Rate-Limit-Limit'), $response->getHeader('X-Rate-Limit-Remaining'), $response->getHeader('X-Rate-Limit-Reset') ]); if (count($rateLimitHeaders) == 3) { $rateLimitClass = new ReflectionClass(RateLimit::class); $this->rate_limit = $rateLimitClass->newInstanceArgs($rateLimitHeaders); } }
[ "private", "function", "parseRateLimitFromResponse", "(", "Response", "$", "response", ")", "{", "$", "rateLimitHeaders", "=", "array_filter", "(", "[", "$", "response", "->", "getHeader", "(", "'X-Rate-Limit-Limit'", ")", ",", "$", "response", "->", "getHeader", "(", "'X-Rate-Limit-Remaining'", ")", ",", "$", "response", "->", "getHeader", "(", "'X-Rate-Limit-Reset'", ")", "]", ")", ";", "if", "(", "count", "(", "$", "rateLimitHeaders", ")", "==", "3", ")", "{", "$", "rateLimitClass", "=", "new", "ReflectionClass", "(", "RateLimit", "::", "class", ")", ";", "$", "this", "->", "rate_limit", "=", "$", "rateLimitClass", "->", "newInstanceArgs", "(", "$", "rateLimitHeaders", ")", ";", "}", "}" ]
Attempts to pull rate limit headers from response and add to client. @param Response $response @return void
[ "Attempts", "to", "pull", "rate", "limit", "headers", "from", "response", "and", "add", "to", "client", "." ]
6a5710dda83102aaef23c8f14e73a493d58963e9
https://github.com/stevenmaguire/uber-php/blob/6a5710dda83102aaef23c8f14e73a493d58963e9/src/Client.php#L209-L221
37,886
stevenmaguire/uber-php
src/Client.php
Client.request
protected function request($verb, $path, $parameters = []) { $client = $this->httpClient; $url = $this->getUrlFromPath($path); $verb = strtolower($verb); $config = $this->getConfigForVerbAndParameters($verb, $parameters); try { $response = $client->$verb($url, $config); } catch (HttpClientException $e) { $this->handleRequestException($e); } $this->parseRateLimitFromResponse($response); return json_decode($response->getBody()); }
php
protected function request($verb, $path, $parameters = []) { $client = $this->httpClient; $url = $this->getUrlFromPath($path); $verb = strtolower($verb); $config = $this->getConfigForVerbAndParameters($verb, $parameters); try { $response = $client->$verb($url, $config); } catch (HttpClientException $e) { $this->handleRequestException($e); } $this->parseRateLimitFromResponse($response); return json_decode($response->getBody()); }
[ "protected", "function", "request", "(", "$", "verb", ",", "$", "path", ",", "$", "parameters", "=", "[", "]", ")", "{", "$", "client", "=", "$", "this", "->", "httpClient", ";", "$", "url", "=", "$", "this", "->", "getUrlFromPath", "(", "$", "path", ")", ";", "$", "verb", "=", "strtolower", "(", "$", "verb", ")", ";", "$", "config", "=", "$", "this", "->", "getConfigForVerbAndParameters", "(", "$", "verb", ",", "$", "parameters", ")", ";", "try", "{", "$", "response", "=", "$", "client", "->", "$", "verb", "(", "$", "url", ",", "$", "config", ")", ";", "}", "catch", "(", "HttpClientException", "$", "e", ")", "{", "$", "this", "->", "handleRequestException", "(", "$", "e", ")", ";", "}", "$", "this", "->", "parseRateLimitFromResponse", "(", "$", "response", ")", ";", "return", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "}" ]
Makes a request to the Uber API and returns the response. @param string $verb The Http verb to use @param string $path The path of the APi after the domain @param array $parameters Parameters @return stdClass The JSON response from the request @throws Exception
[ "Makes", "a", "request", "to", "the", "Uber", "API", "and", "returns", "the", "response", "." ]
6a5710dda83102aaef23c8f14e73a493d58963e9
https://github.com/stevenmaguire/uber-php/blob/6a5710dda83102aaef23c8f14e73a493d58963e9/src/Client.php#L233-L249
37,887
machour/yii2-notifications
commands/NotificationsController.php
NotificationsController.actionClean
public function actionClean() { $class = $this->module->notificationClass; // Delete all notifications seen or flashed $criteria = ['or', ['seen=1'], ['flashed=1']]; // Delete old notification according to expiration time setting if ( $this->module->expirationTime > 0 ) { $criteria[] = ['<', 'created_at', time()-$this->module->expirationTime ]; } $records_deleted = $class::deleteAll($criteria); echo "$records_deleted obsolete notifications removed\n"; }
php
public function actionClean() { $class = $this->module->notificationClass; // Delete all notifications seen or flashed $criteria = ['or', ['seen=1'], ['flashed=1']]; // Delete old notification according to expiration time setting if ( $this->module->expirationTime > 0 ) { $criteria[] = ['<', 'created_at', time()-$this->module->expirationTime ]; } $records_deleted = $class::deleteAll($criteria); echo "$records_deleted obsolete notifications removed\n"; }
[ "public", "function", "actionClean", "(", ")", "{", "$", "class", "=", "$", "this", "->", "module", "->", "notificationClass", ";", "// Delete all notifications seen or flashed", "$", "criteria", "=", "[", "'or'", ",", "[", "'seen=1'", "]", ",", "[", "'flashed=1'", "]", "]", ";", "// Delete old notification according to expiration time setting", "if", "(", "$", "this", "->", "module", "->", "expirationTime", ">", "0", ")", "{", "$", "criteria", "[", "]", "=", "[", "'<'", ",", "'created_at'", ",", "time", "(", ")", "-", "$", "this", "->", "module", "->", "expirationTime", "]", ";", "}", "$", "records_deleted", "=", "$", "class", "::", "deleteAll", "(", "$", "criteria", ")", ";", "echo", "\"$records_deleted obsolete notifications removed\\n\"", ";", "}" ]
Clean obsolete notifications
[ "Clean", "obsolete", "notifications" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/commands/NotificationsController.php#L14-L29
37,888
machour/yii2-notifications
models/Notification.php
Notification.warning
public static function warning($key, $user_id, $key_id = null) { return static::notify($key, $user_id, $key_id, self::TYPE_WARNING); }
php
public static function warning($key, $user_id, $key_id = null) { return static::notify($key, $user_id, $key_id, self::TYPE_WARNING); }
[ "public", "static", "function", "warning", "(", "$", "key", ",", "$", "user_id", ",", "$", "key_id", "=", "null", ")", "{", "return", "static", "::", "notify", "(", "$", "key", ",", "$", "user_id", ",", "$", "key_id", ",", "self", "::", "TYPE_WARNING", ")", ";", "}" ]
Creates a warning notification @param string $key @param integer $user_id The user id that will get the notification @param string $key_id The notification key id @return bool Returns TRUE on success, FALSE on failure
[ "Creates", "a", "warning", "notification" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/models/Notification.php#L117-L120
37,889
machour/yii2-notifications
models/Notification.php
Notification.error
public static function error($key, $user_id, $key_id = null) { return static::notify($key, $user_id, $key_id, self::TYPE_ERROR); }
php
public static function error($key, $user_id, $key_id = null) { return static::notify($key, $user_id, $key_id, self::TYPE_ERROR); }
[ "public", "static", "function", "error", "(", "$", "key", ",", "$", "user_id", ",", "$", "key_id", "=", "null", ")", "{", "return", "static", "::", "notify", "(", "$", "key", ",", "$", "user_id", ",", "$", "key_id", ",", "self", "::", "TYPE_ERROR", ")", ";", "}" ]
Creates an error notification @param string $key @param integer $user_id The user id that will get the notification @param string $key_id The notification key id @return bool Returns TRUE on success, FALSE on failure
[ "Creates", "an", "error", "notification" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/models/Notification.php#L131-L134
37,890
machour/yii2-notifications
models/Notification.php
Notification.success
public static function success($key, $user_id, $key_id = null) { return static::notify($key, $user_id, $key_id, self::TYPE_SUCCESS); }
php
public static function success($key, $user_id, $key_id = null) { return static::notify($key, $user_id, $key_id, self::TYPE_SUCCESS); }
[ "public", "static", "function", "success", "(", "$", "key", ",", "$", "user_id", ",", "$", "key_id", "=", "null", ")", "{", "return", "static", "::", "notify", "(", "$", "key", ",", "$", "user_id", ",", "$", "key_id", ",", "self", "::", "TYPE_SUCCESS", ")", ";", "}" ]
Creates a success notification @param string $key @param integer $user_id The user id that will get the notification @param string $key_id The notification key id @return bool Returns TRUE on success, FALSE on failure
[ "Creates", "a", "success", "notification" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/models/Notification.php#L145-L148
37,891
machour/yii2-notifications
widgets/NotificationsAsset.php
NotificationsAsset.getFilename
public static function getFilename($theme, $type) { $filename = 'themes/' . $theme . '.' . $type; if (file_exists(Yii::getAlias(self::$assetsDirectory) . $filename)) { return $filename; } return false; }
php
public static function getFilename($theme, $type) { $filename = 'themes/' . $theme . '.' . $type; if (file_exists(Yii::getAlias(self::$assetsDirectory) . $filename)) { return $filename; } return false; }
[ "public", "static", "function", "getFilename", "(", "$", "theme", ",", "$", "type", ")", "{", "$", "filename", "=", "'themes/'", ".", "$", "theme", ".", "'.'", ".", "$", "type", ";", "if", "(", "file_exists", "(", "Yii", "::", "getAlias", "(", "self", "::", "$", "assetsDirectory", ")", ".", "$", "filename", ")", ")", "{", "return", "$", "filename", ";", "}", "return", "false", ";", "}" ]
Gets the required theme filename if it exists @param string $theme The theme name @param string $type The resource type. Either "js" or "css" @return bool|string Returns the filename if it exists, or FALSE.
[ "Gets", "the", "required", "theme", "filename", "if", "it", "exists" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/widgets/NotificationsAsset.php#L60-L67
37,892
machour/yii2-notifications
widgets/NotificationsAsset.php
NotificationsAsset.getTimeAgoI18n
public static function getTimeAgoI18n($locale) { $pattern = 'locales/jquery.timeago.%s.js'; $filename = sprintf($pattern, $locale); if (file_exists(Yii::getAlias(self::$assetsDirectory) . $filename)) { return $filename; } else { // try harder by shortening the locale $locale = substr($locale, 0, 2); $filename = sprintf($pattern, $locale); if (file_exists(Yii::getAlias(self::$assetsDirectory) . $filename)) { return $filename; } } return false; }
php
public static function getTimeAgoI18n($locale) { $pattern = 'locales/jquery.timeago.%s.js'; $filename = sprintf($pattern, $locale); if (file_exists(Yii::getAlias(self::$assetsDirectory) . $filename)) { return $filename; } else { // try harder by shortening the locale $locale = substr($locale, 0, 2); $filename = sprintf($pattern, $locale); if (file_exists(Yii::getAlias(self::$assetsDirectory) . $filename)) { return $filename; } } return false; }
[ "public", "static", "function", "getTimeAgoI18n", "(", "$", "locale", ")", "{", "$", "pattern", "=", "'locales/jquery.timeago.%s.js'", ";", "$", "filename", "=", "sprintf", "(", "$", "pattern", ",", "$", "locale", ")", ";", "if", "(", "file_exists", "(", "Yii", "::", "getAlias", "(", "self", "::", "$", "assetsDirectory", ")", ".", "$", "filename", ")", ")", "{", "return", "$", "filename", ";", "}", "else", "{", "// try harder by shortening the locale", "$", "locale", "=", "substr", "(", "$", "locale", ",", "0", ",", "2", ")", ";", "$", "filename", "=", "sprintf", "(", "$", "pattern", ",", "$", "locale", ")", ";", "if", "(", "file_exists", "(", "Yii", "::", "getAlias", "(", "self", "::", "$", "assetsDirectory", ")", ".", "$", "filename", ")", ")", "{", "return", "$", "filename", ";", "}", "}", "return", "false", ";", "}" ]
Gets the jQuery timeago locale file based on the current Yii language @return bool|string Returns the path to the locale file, or FALSE if it does not exist.
[ "Gets", "the", "jQuery", "timeago", "locale", "file", "based", "on", "the", "current", "Yii", "language" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/widgets/NotificationsAsset.php#L75-L90
37,893
machour/yii2-notifications
controllers/NotificationsController.php
NotificationsController.actionRnr
public function actionRnr($id) { $notification = $this->actionRead($id); return $this->redirect(Url::to($notification->getRoute())); }
php
public function actionRnr($id) { $notification = $this->actionRead($id); return $this->redirect(Url::to($notification->getRoute())); }
[ "public", "function", "actionRnr", "(", "$", "id", ")", "{", "$", "notification", "=", "$", "this", "->", "actionRead", "(", "$", "id", ")", ";", "return", "$", "this", "->", "redirect", "(", "Url", "::", "to", "(", "$", "notification", "->", "getRoute", "(", ")", ")", ")", ";", "}" ]
Marks a notification as read and redirects the user to the final route @param int $id The notification id @return Response @throws HttpException Throws an exception if the notification is not found, or if it don't belongs to the logged in user
[ "Marks", "a", "notification", "as", "read", "and", "redirects", "the", "user", "to", "the", "final", "route" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/controllers/NotificationsController.php#L85-L89
37,894
machour/yii2-notifications
controllers/NotificationsController.php
NotificationsController.actionRead
public function actionRead($id) { $notification = $this->getNotification($id); $notification->seen = 1; $notification->save(); return $notification; }
php
public function actionRead($id) { $notification = $this->getNotification($id); $notification->seen = 1; $notification->save(); return $notification; }
[ "public", "function", "actionRead", "(", "$", "id", ")", "{", "$", "notification", "=", "$", "this", "->", "getNotification", "(", "$", "id", ")", ";", "$", "notification", "->", "seen", "=", "1", ";", "$", "notification", "->", "save", "(", ")", ";", "return", "$", "notification", ";", "}" ]
Marks a notification as read @param int $id The notification id @return Notification The updated notification record @throws HttpException Throws an exception if the notification is not found, or if it don't belongs to the logged in user
[ "Marks", "a", "notification", "as", "read" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/controllers/NotificationsController.php#L99-L107
37,895
machour/yii2-notifications
controllers/NotificationsController.php
NotificationsController.actionReadAll
public function actionReadAll() { $notificationsIds = Yii::$app->request->post('ids', []); foreach ($notificationsIds as $id) { $notification = $this->getNotification($id); $notification->seen = 1; $notification->save(); } return true; }
php
public function actionReadAll() { $notificationsIds = Yii::$app->request->post('ids', []); foreach ($notificationsIds as $id) { $notification = $this->getNotification($id); $notification->seen = 1; $notification->save(); } return true; }
[ "public", "function", "actionReadAll", "(", ")", "{", "$", "notificationsIds", "=", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", "'ids'", ",", "[", "]", ")", ";", "foreach", "(", "$", "notificationsIds", "as", "$", "id", ")", "{", "$", "notification", "=", "$", "this", "->", "getNotification", "(", "$", "id", ")", ";", "$", "notification", "->", "seen", "=", "1", ";", "$", "notification", "->", "save", "(", ")", ";", "}", "return", "true", ";", "}" ]
Marks all notification as read @throws HttpException Throws an exception if the notification is not found, or if it don't belongs to the logged in user
[ "Marks", "all", "notification", "as", "read" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/controllers/NotificationsController.php#L115-L127
37,896
machour/yii2-notifications
controllers/NotificationsController.php
NotificationsController.actionDeleteAll
public function actionDeleteAll() { $notificationsIds = Yii::$app->request->post('ids', []); foreach ($notificationsIds as $id) { $notification = $this->getNotification($id); $notification->delete(); } return true; }
php
public function actionDeleteAll() { $notificationsIds = Yii::$app->request->post('ids', []); foreach ($notificationsIds as $id) { $notification = $this->getNotification($id); $notification->delete(); } return true; }
[ "public", "function", "actionDeleteAll", "(", ")", "{", "$", "notificationsIds", "=", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", "'ids'", ",", "[", "]", ")", ";", "foreach", "(", "$", "notificationsIds", "as", "$", "id", ")", "{", "$", "notification", "=", "$", "this", "->", "getNotification", "(", "$", "id", ")", ";", "$", "notification", "->", "delete", "(", ")", ";", "}", "return", "true", ";", "}" ]
Delete all notifications @throws HttpException Throws an exception if the notification is not found, or if it don't belongs to the logged in user
[ "Delete", "all", "notifications" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/controllers/NotificationsController.php#L135-L146
37,897
machour/yii2-notifications
controllers/NotificationsController.php
NotificationsController.getNotification
private function getNotification($id) { /** @var Notification $notification */ $class = $this->notificationClass; $notification = $class::findOne($id); if (!$notification) { throw new HttpException(404, "Unknown notification"); } if ($notification->user_id != $this->user_id) { throw new HttpException(500, "Not your notification"); } return $notification; }
php
private function getNotification($id) { /** @var Notification $notification */ $class = $this->notificationClass; $notification = $class::findOne($id); if (!$notification) { throw new HttpException(404, "Unknown notification"); } if ($notification->user_id != $this->user_id) { throw new HttpException(500, "Not your notification"); } return $notification; }
[ "private", "function", "getNotification", "(", "$", "id", ")", "{", "/** @var Notification $notification */", "$", "class", "=", "$", "this", "->", "notificationClass", ";", "$", "notification", "=", "$", "class", "::", "findOne", "(", "$", "id", ")", ";", "if", "(", "!", "$", "notification", ")", "{", "throw", "new", "HttpException", "(", "404", ",", "\"Unknown notification\"", ")", ";", "}", "if", "(", "$", "notification", "->", "user_id", "!=", "$", "this", "->", "user_id", ")", "{", "throw", "new", "HttpException", "(", "500", ",", "\"Not your notification\"", ")", ";", "}", "return", "$", "notification", ";", "}" ]
Gets a notification by id @param int $id The notification id @return Notification @throws HttpException Throws an exception if the notification is not found, or if it don't belongs to the logged in user
[ "Gets", "a", "notification", "by", "id" ]
56c1dcb593c024f06ce4701818096e20c845e950
https://github.com/machour/yii2-notifications/blob/56c1dcb593c024f06ce4701818096e20c845e950/controllers/NotificationsController.php#L181-L195
37,898
shvetsgroup/laravel-email-database-log
src/ShvetsGroup/LaravelEmailDatabaseLog/EmailLogger.php
EmailLogger.formatAddressField
function formatAddressField($message, $field) { $headers = $message->getHeaders(); if (!$headers->has($field)) { return null; } $mailboxes = $headers->get($field)->getFieldBodyModel(); $strings = []; foreach ($mailboxes as $email => $name) { $mailboxStr = $email; if (null !== $name) { $mailboxStr = $name . ' <' . $mailboxStr . '>'; } $strings[] = $mailboxStr; } return implode(', ', $strings); }
php
function formatAddressField($message, $field) { $headers = $message->getHeaders(); if (!$headers->has($field)) { return null; } $mailboxes = $headers->get($field)->getFieldBodyModel(); $strings = []; foreach ($mailboxes as $email => $name) { $mailboxStr = $email; if (null !== $name) { $mailboxStr = $name . ' <' . $mailboxStr . '>'; } $strings[] = $mailboxStr; } return implode(', ', $strings); }
[ "function", "formatAddressField", "(", "$", "message", ",", "$", "field", ")", "{", "$", "headers", "=", "$", "message", "->", "getHeaders", "(", ")", ";", "if", "(", "!", "$", "headers", "->", "has", "(", "$", "field", ")", ")", "{", "return", "null", ";", "}", "$", "mailboxes", "=", "$", "headers", "->", "get", "(", "$", "field", ")", "->", "getFieldBodyModel", "(", ")", ";", "$", "strings", "=", "[", "]", ";", "foreach", "(", "$", "mailboxes", "as", "$", "email", "=>", "$", "name", ")", "{", "$", "mailboxStr", "=", "$", "email", ";", "if", "(", "null", "!==", "$", "name", ")", "{", "$", "mailboxStr", "=", "$", "name", ".", "' <'", ".", "$", "mailboxStr", ".", "'>'", ";", "}", "$", "strings", "[", "]", "=", "$", "mailboxStr", ";", "}", "return", "implode", "(", "', '", ",", "$", "strings", ")", ";", "}" ]
Format address strings for sender, to, cc, bcc. @param $message @param $field @return null|string
[ "Format", "address", "strings", "for", "sender", "to", "cc", "bcc", "." ]
8710cb82e0d69151fe632d450814c4e95367e022
https://github.com/shvetsgroup/laravel-email-database-log/blob/8710cb82e0d69151fe632d450814c4e95367e022/src/ShvetsGroup/LaravelEmailDatabaseLog/EmailLogger.php#L39-L58
37,899
guillermomartinez/filemanager-laravel
src/Pqb/FilemanagerLaravel/plugins/rsc/cloudfiles.php
CF_Authentication.load_cached_credentials
function load_cached_credentials($auth_token, $storage_url, $cdnm_url) { if(!$storage_url || !$cdnm_url) { throw new SyntaxException("Missing Required Interface URL's!"); } if(!$auth_token) { throw new SyntaxException("Missing Auth Token!"); } $this->storage_url = $storage_url; $this->cdnm_url = $cdnm_url; $this->auth_token = $auth_token; return True; }
php
function load_cached_credentials($auth_token, $storage_url, $cdnm_url) { if(!$storage_url || !$cdnm_url) { throw new SyntaxException("Missing Required Interface URL's!"); } if(!$auth_token) { throw new SyntaxException("Missing Auth Token!"); } $this->storage_url = $storage_url; $this->cdnm_url = $cdnm_url; $this->auth_token = $auth_token; return True; }
[ "function", "load_cached_credentials", "(", "$", "auth_token", ",", "$", "storage_url", ",", "$", "cdnm_url", ")", "{", "if", "(", "!", "$", "storage_url", "||", "!", "$", "cdnm_url", ")", "{", "throw", "new", "SyntaxException", "(", "\"Missing Required Interface URL's!\"", ")", ";", "}", "if", "(", "!", "$", "auth_token", ")", "{", "throw", "new", "SyntaxException", "(", "\"Missing Auth Token!\"", ")", ";", "}", "$", "this", "->", "storage_url", "=", "$", "storage_url", ";", "$", "this", "->", "cdnm_url", "=", "$", "cdnm_url", ";", "$", "this", "->", "auth_token", "=", "$", "auth_token", ";", "return", "True", ";", "}" ]
Use Cached Token and Storage URL's rather then grabbing from the Auth System Example: <code> #Create an Auth instance $auth = new CF_Authentication(); #Pass Cached URL's and Token as Args $auth->load_cached_credentials("auth_token", "storage_url", "cdn_management_url"); </code> @param string $auth_token A Cloud Files Auth Token (Required) @param string $storage_url The Cloud Files Storage URL (Required) @param string $cdnm_url CDN Management URL (Required) @return boolean <kbd>True</kbd> if successful @throws SyntaxException If any of the Required Arguments are missing
[ "Use", "Cached", "Token", "and", "Storage", "URL", "s", "rather", "then", "grabbing", "from", "the", "Auth", "System" ]
e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563
https://github.com/guillermomartinez/filemanager-laravel/blob/e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563/src/Pqb/FilemanagerLaravel/plugins/rsc/cloudfiles.php#L242-L257