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
22,200
CalderaWP/metaplate-core
src/file_load.php
file_load.load
public static function load( $file ) { add_filter( 'calderawp_file_locator_allow_extensions', function( $allowed, $context ) { if ( self::$context === $context ) { $allowed = array( 'html', 'htm' ); } return $allowed; }, 10, 2 ); $file = file_locator::locate( $file, self::$context, true ); if ( is_string( $file ) ) { return array( 'html' => array( 'code' => file_get_contents( $file ) ) ); } }
php
public static function load( $file ) { add_filter( 'calderawp_file_locator_allow_extensions', function( $allowed, $context ) { if ( self::$context === $context ) { $allowed = array( 'html', 'htm' ); } return $allowed; }, 10, 2 ); $file = file_locator::locate( $file, self::$context, true ); if ( is_string( $file ) ) { return array( 'html' => array( 'code' => file_get_contents( $file ) ) ); } }
[ "public", "static", "function", "load", "(", "$", "file", ")", "{", "add_filter", "(", "'calderawp_file_locator_allow_extensions'", ",", "function", "(", "$", "allowed", ",", "$", "context", ")", "{", "if", "(", "self", "::", "$", "context", "===", "$", "context", ")", "{", "$", "allowed", "=", "array", "(", "'html'", ",", "'htm'", ")", ";", "}", "return", "$", "allowed", ";", "}", ",", "10", ",", "2", ")", ";", "$", "file", "=", "file_locator", "::", "locate", "(", "$", "file", ",", "self", "::", "$", "context", ",", "true", ")", ";", "if", "(", "is_string", "(", "$", "file", ")", ")", "{", "return", "array", "(", "'html'", "=>", "array", "(", "'code'", "=>", "file_get_contents", "(", "$", "file", ")", ")", ")", ";", "}", "}" ]
Attempts to load a file and if so, puts its contents in an array as expected by Metaplate @param string $file File path. Can be relative to current theme or absolute. Must be .html or .htm @return array|void Returns an array 'html' => file contents if possible.
[ "Attempts", "to", "load", "a", "file", "and", "if", "so", "puts", "its", "contents", "in", "an", "array", "as", "expected", "by", "Metaplate" ]
15ede9c4250ab23112a32f8e45d5393f8278bbb8
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/file_load.php#L38-L57
22,201
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/options.php
ezcBaseOptions.merge
public function merge( array $newOptions ) { foreach ( $newOptions as $key => $value ) { $this->__set( $key, $value ); } }
php
public function merge( array $newOptions ) { foreach ( $newOptions as $key => $value ) { $this->__set( $key, $value ); } }
[ "public", "function", "merge", "(", "array", "$", "newOptions", ")", "{", "foreach", "(", "$", "newOptions", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "__set", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Merge an array into the actual options object. This method merges an array of new options into the actual options object. @throws ezcBasePropertyNotFoundException If trying to access a non existent property. @throws ezcBaseValueException If the value for a property is out of range. @param array(string=>mixed) $newOptions The new options.
[ "Merge", "an", "array", "into", "the", "actual", "options", "object", ".", "This", "method", "merges", "an", "array", "of", "new", "options", "into", "the", "actual", "options", "object", "." ]
b0afc661105f0a2f65d49abac13956cc93c5188d
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/options.php#L56-L62
22,202
brick/di
src/Injector.php
Injector.invoke
public function invoke(callable $function, array $parameters = []) { $reflection = $this->reflectionTools->getReflectionFunction($function); $parameters = $this->getFunctionParameters($reflection, $parameters); return call_user_func_array($function, $parameters); }
php
public function invoke(callable $function, array $parameters = []) { $reflection = $this->reflectionTools->getReflectionFunction($function); $parameters = $this->getFunctionParameters($reflection, $parameters); return call_user_func_array($function, $parameters); }
[ "public", "function", "invoke", "(", "callable", "$", "function", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "reflection", "=", "$", "this", "->", "reflectionTools", "->", "getReflectionFunction", "(", "$", "function", ")", ";", "$", "parameters", "=", "$", "this", "->", "getFunctionParameters", "(", "$", "reflection", ",", "$", "parameters", ")", ";", "return", "call_user_func_array", "(", "$", "function", ",", "$", "parameters", ")", ";", "}" ]
Invokes a function after resolving its parameters. If the given parameters match the function parameter names, the given values are used. Otherwise, the function parameters are resolved using the ValueResolver. @param callable $function The function to invoke. @param array $parameters An associative array of values for the function parameters. @return mixed The result of the function call. @throws UnresolvedValueException If a function parameter could not be resolved.
[ "Invokes", "a", "function", "after", "resolving", "its", "parameters", "." ]
6ced82ab3623b8f1470317d38cbd2de855e7aa3d
https://github.com/brick/di/blob/6ced82ab3623b8f1470317d38cbd2de855e7aa3d/src/Injector.php#L53-L59
22,203
brick/di
src/Injector.php
Injector.instantiate
public function instantiate(string $class, array $parameters = []) { $class = new \ReflectionClass($class); $instance = $class->newInstanceWithoutConstructor(); $this->inject($instance); $constructor = $class->getConstructor(); if ($constructor) { $parameters = $this->getFunctionParameters($constructor, $parameters); $constructor->setAccessible(true); $constructor->invokeArgs($instance, $parameters); } return $instance; }
php
public function instantiate(string $class, array $parameters = []) { $class = new \ReflectionClass($class); $instance = $class->newInstanceWithoutConstructor(); $this->inject($instance); $constructor = $class->getConstructor(); if ($constructor) { $parameters = $this->getFunctionParameters($constructor, $parameters); $constructor->setAccessible(true); $constructor->invokeArgs($instance, $parameters); } return $instance; }
[ "public", "function", "instantiate", "(", "string", "$", "class", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "$", "instance", "=", "$", "class", "->", "newInstanceWithoutConstructor", "(", ")", ";", "$", "this", "->", "inject", "(", "$", "instance", ")", ";", "$", "constructor", "=", "$", "class", "->", "getConstructor", "(", ")", ";", "if", "(", "$", "constructor", ")", "{", "$", "parameters", "=", "$", "this", "->", "getFunctionParameters", "(", "$", "constructor", ",", "$", "parameters", ")", ";", "$", "constructor", "->", "setAccessible", "(", "true", ")", ";", "$", "constructor", "->", "invokeArgs", "(", "$", "instance", ",", "$", "parameters", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Instantiates a class by resolving its constructor parameters, and injects dependencies in the resulting object. If the given parameters match the constructor parameter names, the given values are used. Otherwise, the constructor parameters are resolved using the ValueResolver. @param string $class The name of the class to instantiate. @param array $parameters An associative array of values for the constructor parameters. @return object The instantiated object. @throws UnresolvedValueException If a function parameter could not be resolved.
[ "Instantiates", "a", "class", "by", "resolving", "its", "constructor", "parameters", "and", "injects", "dependencies", "in", "the", "resulting", "object", "." ]
6ced82ab3623b8f1470317d38cbd2de855e7aa3d
https://github.com/brick/di/blob/6ced82ab3623b8f1470317d38cbd2de855e7aa3d/src/Injector.php#L74-L90
22,204
brick/di
src/Injector.php
Injector.inject
public function inject($object) : void { $reflection = new \ReflectionObject($object); $this->injectProperties($reflection, $object); $this->injectMethods($reflection, $object); }
php
public function inject($object) : void { $reflection = new \ReflectionObject($object); $this->injectProperties($reflection, $object); $this->injectMethods($reflection, $object); }
[ "public", "function", "inject", "(", "$", "object", ")", ":", "void", "{", "$", "reflection", "=", "new", "\\", "ReflectionObject", "(", "$", "object", ")", ";", "$", "this", "->", "injectProperties", "(", "$", "reflection", ",", "$", "object", ")", ";", "$", "this", "->", "injectMethods", "(", "$", "reflection", ",", "$", "object", ")", ";", "}" ]
Injects dependencies in an object. Properties are injected first, then methods. @param object $object The object to inject dependencies in. @return void
[ "Injects", "dependencies", "in", "an", "object", "." ]
6ced82ab3623b8f1470317d38cbd2de855e7aa3d
https://github.com/brick/di/blob/6ced82ab3623b8f1470317d38cbd2de855e7aa3d/src/Injector.php#L101-L107
22,205
brick/di
src/Injector.php
Injector.getFunctionParameters
private function getFunctionParameters(\ReflectionFunctionAbstract $function, array $parameters = []) : array { $result = []; foreach ($function->getParameters() as $parameter) { $name = $parameter->getName(); if (array_key_exists($name, $parameters)) { $value = $parameters[$name]; } else { $value = $this->resolver->getParameterValue($parameter); } if ($parameter->isVariadic()) { $result = array_merge($result, $value); } else { $result[] = $value; } } return $result; }
php
private function getFunctionParameters(\ReflectionFunctionAbstract $function, array $parameters = []) : array { $result = []; foreach ($function->getParameters() as $parameter) { $name = $parameter->getName(); if (array_key_exists($name, $parameters)) { $value = $parameters[$name]; } else { $value = $this->resolver->getParameterValue($parameter); } if ($parameter->isVariadic()) { $result = array_merge($result, $value); } else { $result[] = $value; } } return $result; }
[ "private", "function", "getFunctionParameters", "(", "\\", "ReflectionFunctionAbstract", "$", "function", ",", "array", "$", "parameters", "=", "[", "]", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "function", "->", "getParameters", "(", ")", "as", "$", "parameter", ")", "{", "$", "name", "=", "$", "parameter", "->", "getName", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "parameters", ")", ")", "{", "$", "value", "=", "$", "parameters", "[", "$", "name", "]", ";", "}", "else", "{", "$", "value", "=", "$", "this", "->", "resolver", "->", "getParameterValue", "(", "$", "parameter", ")", ";", "}", "if", "(", "$", "parameter", "->", "isVariadic", "(", ")", ")", "{", "$", "result", "=", "array_merge", "(", "$", "result", ",", "$", "value", ")", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns an associative array of parameters to call a given function. The parameters are indexed by name, and returned in the same order as they are defined. @param \ReflectionFunctionAbstract $function The reflection of the function. @param array $parameters An optional array of parameters indexed by name. @return array The parameters to call the function with. @throws UnresolvedValueException If a function parameter could not be resolved.
[ "Returns", "an", "associative", "array", "of", "parameters", "to", "call", "a", "given", "function", "." ]
6ced82ab3623b8f1470317d38cbd2de855e7aa3d
https://github.com/brick/di/blob/6ced82ab3623b8f1470317d38cbd2de855e7aa3d/src/Injector.php#L155-L176
22,206
ajant/SimpleArrayLibrary
src/Categories/Checkers.php
Checkers.allElementsEqual
public static function allElementsEqual(array $haystack, $needle = null) { $return = true; // if both arguments have been passed, use value argument (regardless of whether it is null or not if (func_num_args() == 2) { $compareAgainst = $needle; } // only one argument has been passed, so compare elements only to each other else { $compareAgainst = reset($haystack); } foreach ($haystack as $element) { if ($compareAgainst != $element) { $return = false; break; } } return $return; }
php
public static function allElementsEqual(array $haystack, $needle = null) { $return = true; // if both arguments have been passed, use value argument (regardless of whether it is null or not if (func_num_args() == 2) { $compareAgainst = $needle; } // only one argument has been passed, so compare elements only to each other else { $compareAgainst = reset($haystack); } foreach ($haystack as $element) { if ($compareAgainst != $element) { $return = false; break; } } return $return; }
[ "public", "static", "function", "allElementsEqual", "(", "array", "$", "haystack", ",", "$", "needle", "=", "null", ")", "{", "$", "return", "=", "true", ";", "// if both arguments have been passed, use value argument (regardless of whether it is null or not", "if", "(", "func_num_args", "(", ")", "==", "2", ")", "{", "$", "compareAgainst", "=", "$", "needle", ";", "}", "// only one argument has been passed, so compare elements only to each other", "else", "{", "$", "compareAgainst", "=", "reset", "(", "$", "haystack", ")", ";", "}", "foreach", "(", "$", "haystack", "as", "$", "element", ")", "{", "if", "(", "$", "compareAgainst", "!=", "$", "element", ")", "{", "$", "return", "=", "false", ";", "break", ";", "}", "}", "return", "$", "return", ";", "}" ]
Checks if all elements of the array have same value @param array $haystack @param mixed $needle @return boolean
[ "Checks", "if", "all", "elements", "of", "the", "array", "have", "same", "value" ]
374877c0f20a22a914eb3680eb1cf39e424071be
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Checkers.php#L17-L35
22,207
PHPPowertools/HTML5
src/PowerTools/HTML5/Elements.php
HTML5_Elements.isA
public static function isA($name, $mask) { if (!static::isElement($name)) { return false; } return (static::element($name) & $mask) == $mask; }
php
public static function isA($name, $mask) { if (!static::isElement($name)) { return false; } return (static::element($name) & $mask) == $mask; }
[ "public", "static", "function", "isA", "(", "$", "name", ",", "$", "mask", ")", "{", "if", "(", "!", "static", "::", "isElement", "(", "$", "name", ")", ")", "{", "return", "false", ";", "}", "return", "(", "static", "::", "element", "(", "$", "name", ")", "&", "$", "mask", ")", "==", "$", "mask", ";", "}" ]
Check whether the given element meets the given criterion. Example: Elements::isA('script', Elements::TEXT_RAW); // Returns true. Elements::isA('script', Elements::TEXT_RCDATA); // Returns false. @param string $name The element name. @param int $mask One of the constants on this class. @return boolean true if the element matches the mask, false otherwise.
[ "Check", "whether", "the", "given", "element", "meets", "the", "given", "criterion", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Elements.php#L560-L566
22,208
PHPPowertools/HTML5
src/PowerTools/HTML5/Elements.php
HTML5_Elements.element
public static function element($name) { if (isset(static::$html5[$name])) { return static::$html5[$name]; } if (isset(static::$svg[$name])) { return static::$svg[$name]; } if (isset(static::$mathml[$name])) { return static::$mathml[$name]; } return false; }
php
public static function element($name) { if (isset(static::$html5[$name])) { return static::$html5[$name]; } if (isset(static::$svg[$name])) { return static::$svg[$name]; } if (isset(static::$mathml[$name])) { return static::$mathml[$name]; } return false; }
[ "public", "static", "function", "element", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "static", "::", "$", "html5", "[", "$", "name", "]", ")", ")", "{", "return", "static", "::", "$", "html5", "[", "$", "name", "]", ";", "}", "if", "(", "isset", "(", "static", "::", "$", "svg", "[", "$", "name", "]", ")", ")", "{", "return", "static", "::", "$", "svg", "[", "$", "name", "]", ";", "}", "if", "(", "isset", "(", "static", "::", "$", "mathml", "[", "$", "name", "]", ")", ")", "{", "return", "static", "::", "$", "mathml", "[", "$", "name", "]", ";", "}", "return", "false", ";", "}" ]
Get the element mask for the given element name. @param string $name The name of the element. @return int The element mask.
[ "Get", "the", "element", "mask", "for", "the", "given", "element", "name", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Elements.php#L631-L643
22,209
PHPPowertools/HTML5
src/PowerTools/HTML5/Elements.php
HTML5_Elements.normalizeSvgElement
public static function normalizeSvgElement($name) { $name = strtolower($name); if (isset(static::$svgCaseSensitiveElementMap[$name])) { $name = static::$svgCaseSensitiveElementMap[$name]; } return $name; }
php
public static function normalizeSvgElement($name) { $name = strtolower($name); if (isset(static::$svgCaseSensitiveElementMap[$name])) { $name = static::$svgCaseSensitiveElementMap[$name]; } return $name; }
[ "public", "static", "function", "normalizeSvgElement", "(", "$", "name", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "static", "::", "$", "svgCaseSensitiveElementMap", "[", "$", "name", "]", ")", ")", "{", "$", "name", "=", "static", "::", "$", "svgCaseSensitiveElementMap", "[", "$", "name", "]", ";", "}", "return", "$", "name", ";", "}" ]
Normalize a SVG element name to its proper case and form. @param string $name The name of the element. @return string The normalized form of the element name.
[ "Normalize", "a", "SVG", "element", "name", "to", "its", "proper", "case", "and", "form", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Elements.php#L653-L660
22,210
PHPPowertools/HTML5
src/PowerTools/HTML5/Elements.php
HTML5_Elements.normalizeSvgAttribute
public static function normalizeSvgAttribute($name) { $name = strtolower($name); if (isset(static::$svgCaseSensitiveAttributeMap[$name])) { $name = static::$svgCaseSensitiveAttributeMap[$name]; } return $name; }
php
public static function normalizeSvgAttribute($name) { $name = strtolower($name); if (isset(static::$svgCaseSensitiveAttributeMap[$name])) { $name = static::$svgCaseSensitiveAttributeMap[$name]; } return $name; }
[ "public", "static", "function", "normalizeSvgAttribute", "(", "$", "name", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "static", "::", "$", "svgCaseSensitiveAttributeMap", "[", "$", "name", "]", ")", ")", "{", "$", "name", "=", "static", "::", "$", "svgCaseSensitiveAttributeMap", "[", "$", "name", "]", ";", "}", "return", "$", "name", ";", "}" ]
Normalize a SVG attribute name to its proper case and form. @param string $name The name of the attribute. @return string The normalized form of the attribute name.
[ "Normalize", "a", "SVG", "attribute", "name", "to", "its", "proper", "case", "and", "form", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Elements.php#L670-L677
22,211
spiral-modules/listing
source/Listing/Filters/SearchFilter.php
SearchFilter.summarize
private function summarize(array $whereClause, $selector) { switch (count($whereClause)) { case 1: return $whereClause[0]; default: if ($selector instanceof RecordSelector) { return ['@OR' => $whereClause]; } if ($selector instanceof DocumentSelector) { return ['$or' => $whereClause]; } } return []; }
php
private function summarize(array $whereClause, $selector) { switch (count($whereClause)) { case 1: return $whereClause[0]; default: if ($selector instanceof RecordSelector) { return ['@OR' => $whereClause]; } if ($selector instanceof DocumentSelector) { return ['$or' => $whereClause]; } } return []; }
[ "private", "function", "summarize", "(", "array", "$", "whereClause", ",", "$", "selector", ")", "{", "switch", "(", "count", "(", "$", "whereClause", ")", ")", "{", "case", "1", ":", "return", "$", "whereClause", "[", "0", "]", ";", "default", ":", "if", "(", "$", "selector", "instanceof", "RecordSelector", ")", "{", "return", "[", "'@OR'", "=>", "$", "whereClause", "]", ";", "}", "if", "(", "$", "selector", "instanceof", "DocumentSelector", ")", "{", "return", "[", "'$or'", "=>", "$", "whereClause", "]", ";", "}", "}", "return", "[", "]", ";", "}" ]
Summarize expression array. @param array $whereClause @param RecordSelector|DocumentSelector $selector @return array
[ "Summarize", "expression", "array", "." ]
89abe8939ce91cbf61b51b99e93ce1e57c8af83c
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Filters/SearchFilter.php#L171-L188
22,212
nabab/bbn
src/bbn/x.php
x.log
public static function log($st, $file='misc'){ if ( \defined('BBN_DATA_PATH') ){ if ( !\is_string($file) ){ $file = 'misc'; } $log_file = BBN_DATA_PATH.'logs/'.$file.'.log'; $backtrace = array_filter(debug_backtrace(), function($a){ return $a['function'] === 'log'; }); $i = end($backtrace); $r = "[".date('d/m/Y H:i:s')."]\t".$i['file']." - line ".$i['line']. self::get_dump($st).PHP_EOL; if ( php_sapi_name() === 'cli' ){ global $argv; if ( isset($argv[2]) && ($argv[2] === 'log') ){ echo self::get_dump($st).PHP_EOL; } } $s = ( file_exists($log_file) ) ? filesize($log_file) : 0; if ( $s > 1048576 ){ file_put_contents($log_file.'.old', file_get_contents($log_file), FILE_APPEND); file_put_contents($log_file, $r); } else{ file_put_contents($log_file, $r, FILE_APPEND); } } }
php
public static function log($st, $file='misc'){ if ( \defined('BBN_DATA_PATH') ){ if ( !\is_string($file) ){ $file = 'misc'; } $log_file = BBN_DATA_PATH.'logs/'.$file.'.log'; $backtrace = array_filter(debug_backtrace(), function($a){ return $a['function'] === 'log'; }); $i = end($backtrace); $r = "[".date('d/m/Y H:i:s')."]\t".$i['file']." - line ".$i['line']. self::get_dump($st).PHP_EOL; if ( php_sapi_name() === 'cli' ){ global $argv; if ( isset($argv[2]) && ($argv[2] === 'log') ){ echo self::get_dump($st).PHP_EOL; } } $s = ( file_exists($log_file) ) ? filesize($log_file) : 0; if ( $s > 1048576 ){ file_put_contents($log_file.'.old', file_get_contents($log_file), FILE_APPEND); file_put_contents($log_file, $r); } else{ file_put_contents($log_file, $r, FILE_APPEND); } } }
[ "public", "static", "function", "log", "(", "$", "st", ",", "$", "file", "=", "'misc'", ")", "{", "if", "(", "\\", "defined", "(", "'BBN_DATA_PATH'", ")", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "file", ")", ")", "{", "$", "file", "=", "'misc'", ";", "}", "$", "log_file", "=", "BBN_DATA_PATH", ".", "'logs/'", ".", "$", "file", ".", "'.log'", ";", "$", "backtrace", "=", "array_filter", "(", "debug_backtrace", "(", ")", ",", "function", "(", "$", "a", ")", "{", "return", "$", "a", "[", "'function'", "]", "===", "'log'", ";", "}", ")", ";", "$", "i", "=", "end", "(", "$", "backtrace", ")", ";", "$", "r", "=", "\"[\"", ".", "date", "(", "'d/m/Y H:i:s'", ")", ".", "\"]\\t\"", ".", "$", "i", "[", "'file'", "]", ".", "\" - line \"", ".", "$", "i", "[", "'line'", "]", ".", "self", "::", "get_dump", "(", "$", "st", ")", ".", "PHP_EOL", ";", "if", "(", "php_sapi_name", "(", ")", "===", "'cli'", ")", "{", "global", "$", "argv", ";", "if", "(", "isset", "(", "$", "argv", "[", "2", "]", ")", "&&", "(", "$", "argv", "[", "2", "]", "===", "'log'", ")", ")", "{", "echo", "self", "::", "get_dump", "(", "$", "st", ")", ".", "PHP_EOL", ";", "}", "}", "$", "s", "=", "(", "file_exists", "(", "$", "log_file", ")", ")", "?", "filesize", "(", "$", "log_file", ")", ":", "0", ";", "if", "(", "$", "s", ">", "1048576", ")", "{", "file_put_contents", "(", "$", "log_file", ".", "'.old'", ",", "file_get_contents", "(", "$", "log_file", ")", ",", "FILE_APPEND", ")", ";", "file_put_contents", "(", "$", "log_file", ",", "$", "r", ")", ";", "}", "else", "{", "file_put_contents", "(", "$", "log_file", ",", "$", "r", ",", "FILE_APPEND", ")", ";", "}", "}", "}" ]
Saves logs to a file. ```php \bbn\x::log('My text', 'FileName'); ``` @param mixed $st Item to log. @param string $file Filename, default: "misc". @return void
[ "Saves", "logs", "to", "a", "file", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L75-L103
22,213
nabab/bbn
src/bbn/x.php
x.log_error
public static function log_error($errno, $errstr, $errfile, $errline){ if ( \defined('BBN_DATA_PATH') ){ if ( is_dir(BBN_DATA_PATH.'logs') ){ $file = BBN_DATA_PATH.'logs/_php_error.json'; $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20); $r = false; if ( is_file($file) ){ $r = json_decode(file_get_contents($file), 1); } if ( !$r ){ $r = []; } $t = date('Y-m-d H:i:s'); if ( class_exists('\\bbn\\mvc') ){ $mvc = mvc::get_instance(); } $idx = self::find($r, [ 'type' => $errno, 'error' => $errstr, 'file' => $errfile, 'line' => $errline, 'request' => '' ]); if ( $idx !== false ){ $r[$idx]['count']++; $r[$idx]['last_date'] = $t; $r[$idx]['backtrace'] = $backtrace; } else{ $r[] = [ 'first_date' => $t, 'last_date' => $t, 'count' => 1, 'type' => $errno, 'error' => $errstr, 'file' => $errfile, 'line' => $errline, 'backtrace' => $backtrace, 'request' => '' //'context' => $context ]; } self::sort_by($r, 'last_date', 'DESC'); file_put_contents($file, json_encode($r, JSON_PRETTY_PRINT)); } if ( $errno > 8 ){ die($errstr); } } return false; }
php
public static function log_error($errno, $errstr, $errfile, $errline){ if ( \defined('BBN_DATA_PATH') ){ if ( is_dir(BBN_DATA_PATH.'logs') ){ $file = BBN_DATA_PATH.'logs/_php_error.json'; $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20); $r = false; if ( is_file($file) ){ $r = json_decode(file_get_contents($file), 1); } if ( !$r ){ $r = []; } $t = date('Y-m-d H:i:s'); if ( class_exists('\\bbn\\mvc') ){ $mvc = mvc::get_instance(); } $idx = self::find($r, [ 'type' => $errno, 'error' => $errstr, 'file' => $errfile, 'line' => $errline, 'request' => '' ]); if ( $idx !== false ){ $r[$idx]['count']++; $r[$idx]['last_date'] = $t; $r[$idx]['backtrace'] = $backtrace; } else{ $r[] = [ 'first_date' => $t, 'last_date' => $t, 'count' => 1, 'type' => $errno, 'error' => $errstr, 'file' => $errfile, 'line' => $errline, 'backtrace' => $backtrace, 'request' => '' //'context' => $context ]; } self::sort_by($r, 'last_date', 'DESC'); file_put_contents($file, json_encode($r, JSON_PRETTY_PRINT)); } if ( $errno > 8 ){ die($errstr); } } return false; }
[ "public", "static", "function", "log_error", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ")", "{", "if", "(", "\\", "defined", "(", "'BBN_DATA_PATH'", ")", ")", "{", "if", "(", "is_dir", "(", "BBN_DATA_PATH", ".", "'logs'", ")", ")", "{", "$", "file", "=", "BBN_DATA_PATH", ".", "'logs/_php_error.json'", ";", "$", "backtrace", "=", "debug_backtrace", "(", "DEBUG_BACKTRACE_IGNORE_ARGS", ",", "20", ")", ";", "$", "r", "=", "false", ";", "if", "(", "is_file", "(", "$", "file", ")", ")", "{", "$", "r", "=", "json_decode", "(", "file_get_contents", "(", "$", "file", ")", ",", "1", ")", ";", "}", "if", "(", "!", "$", "r", ")", "{", "$", "r", "=", "[", "]", ";", "}", "$", "t", "=", "date", "(", "'Y-m-d H:i:s'", ")", ";", "if", "(", "class_exists", "(", "'\\\\bbn\\\\mvc'", ")", ")", "{", "$", "mvc", "=", "mvc", "::", "get_instance", "(", ")", ";", "}", "$", "idx", "=", "self", "::", "find", "(", "$", "r", ",", "[", "'type'", "=>", "$", "errno", ",", "'error'", "=>", "$", "errstr", ",", "'file'", "=>", "$", "errfile", ",", "'line'", "=>", "$", "errline", ",", "'request'", "=>", "''", "]", ")", ";", "if", "(", "$", "idx", "!==", "false", ")", "{", "$", "r", "[", "$", "idx", "]", "[", "'count'", "]", "++", ";", "$", "r", "[", "$", "idx", "]", "[", "'last_date'", "]", "=", "$", "t", ";", "$", "r", "[", "$", "idx", "]", "[", "'backtrace'", "]", "=", "$", "backtrace", ";", "}", "else", "{", "$", "r", "[", "]", "=", "[", "'first_date'", "=>", "$", "t", ",", "'last_date'", "=>", "$", "t", ",", "'count'", "=>", "1", ",", "'type'", "=>", "$", "errno", ",", "'error'", "=>", "$", "errstr", ",", "'file'", "=>", "$", "errfile", ",", "'line'", "=>", "$", "errline", ",", "'backtrace'", "=>", "$", "backtrace", ",", "'request'", "=>", "''", "//'context' => $context", "]", ";", "}", "self", "::", "sort_by", "(", "$", "r", ",", "'last_date'", ",", "'DESC'", ")", ";", "file_put_contents", "(", "$", "file", ",", "json_encode", "(", "$", "r", ",", "JSON_PRETTY_PRINT", ")", ")", ";", "}", "if", "(", "$", "errno", ">", "8", ")", "{", "die", "(", "$", "errstr", ")", ";", "}", "}", "return", "false", ";", "}" ]
Puts the PHP errors into a JSON file. @param string $errno The text to save. @param string $errstr The file's name, default: "misc". @param $errfile @param $errline @return bool
[ "Puts", "the", "PHP", "errors", "into", "a", "JSON", "file", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L114-L164
22,214
nabab/bbn
src/bbn/x.php
x.merge_objects
public static function merge_objects($o1, $o2){ $args = \func_get_args(); /* @todo check if it's working with more than 2 object arguments */ if ( \count($args) > 2 ){ for ( $i = \count($args) - 1; $i > 1; $i-- ){ $args[$i-1] = self::merge_arrays($args[$i-1], $args[$i]); } $o2 = $args[1]; } $a1 = self::to_array($o1); $a2 = self::to_array($o2); $res = self::merge_arrays($a1, $a2); return self::to_object($res); }
php
public static function merge_objects($o1, $o2){ $args = \func_get_args(); /* @todo check if it's working with more than 2 object arguments */ if ( \count($args) > 2 ){ for ( $i = \count($args) - 1; $i > 1; $i-- ){ $args[$i-1] = self::merge_arrays($args[$i-1], $args[$i]); } $o2 = $args[1]; } $a1 = self::to_array($o1); $a2 = self::to_array($o2); $res = self::merge_arrays($a1, $a2); return self::to_object($res); }
[ "public", "static", "function", "merge_objects", "(", "$", "o1", ",", "$", "o2", ")", "{", "$", "args", "=", "\\", "func_get_args", "(", ")", ";", "/* @todo check if it's working with more than 2 object arguments */", "if", "(", "\\", "count", "(", "$", "args", ")", ">", "2", ")", "{", "for", "(", "$", "i", "=", "\\", "count", "(", "$", "args", ")", "-", "1", ";", "$", "i", ">", "1", ";", "$", "i", "--", ")", "{", "$", "args", "[", "$", "i", "-", "1", "]", "=", "self", "::", "merge_arrays", "(", "$", "args", "[", "$", "i", "-", "1", "]", ",", "$", "args", "[", "$", "i", "]", ")", ";", "}", "$", "o2", "=", "$", "args", "[", "1", "]", ";", "}", "$", "a1", "=", "self", "::", "to_array", "(", "$", "o1", ")", ";", "$", "a2", "=", "self", "::", "to_array", "(", "$", "o2", ")", ";", "$", "res", "=", "self", "::", "merge_arrays", "(", "$", "a1", ",", "$", "a2", ")", ";", "return", "self", "::", "to_object", "(", "$", "res", ")", ";", "}" ]
Returns to a merged object from two objects. ```php class A { public $a = 10; public $b = 20; }; class B { public $c = 30; public $d = 40; }; $obj1 = new A; $obj2 = new B; \bbn\x::merge_objects($obj1, $obj2); // object {'a': 10, 'b': 20, 'c': 30, 'd': 40} ``` @param object $o1 The first object to merge. @param object $o2 The second object to merge. @return object The merged object.
[ "Returns", "to", "a", "merged", "object", "from", "two", "objects", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L191-L204
22,215
nabab/bbn
src/bbn/x.php
x.merge_arrays
public static function merge_arrays(array $a1, array $a2){ $args = \func_get_args(); if ( \count($args) > 2 ){ for ( $i = \count($args) - 1; $i > 1; $i-- ){ $args[$i-1] = self::merge_arrays($args[$i-1], $args[$i]); } $a2 = $args[1]; } if ( (self::is_assoc($a1) || empty($a1)) && (self::is_assoc($a2) || empty($a2)) ){ $keys = array_unique(array_merge(array_keys($a1), array_keys($a2))); $r = []; foreach ( $keys as $k ){ if ( !array_key_exists($k, $a1) && !array_key_exists($k, $a2) ){ continue; } else if ( !array_key_exists($k, $a2) ){ $r[$k] = $a1[$k]; } else if ( !array_key_exists($k, $a1) || !\is_array($a2[$k]) || !\is_array($a1[$k]) || is_numeric(key($a2[$k])) ){ $r[$k] = $a2[$k]; } else{ $r[$k] = self::merge_arrays($a1[$k], $a2[$k]); } } } else{ $r = array_merge($a1, $a2); } return $r; }
php
public static function merge_arrays(array $a1, array $a2){ $args = \func_get_args(); if ( \count($args) > 2 ){ for ( $i = \count($args) - 1; $i > 1; $i-- ){ $args[$i-1] = self::merge_arrays($args[$i-1], $args[$i]); } $a2 = $args[1]; } if ( (self::is_assoc($a1) || empty($a1)) && (self::is_assoc($a2) || empty($a2)) ){ $keys = array_unique(array_merge(array_keys($a1), array_keys($a2))); $r = []; foreach ( $keys as $k ){ if ( !array_key_exists($k, $a1) && !array_key_exists($k, $a2) ){ continue; } else if ( !array_key_exists($k, $a2) ){ $r[$k] = $a1[$k]; } else if ( !array_key_exists($k, $a1) || !\is_array($a2[$k]) || !\is_array($a1[$k]) || is_numeric(key($a2[$k])) ){ $r[$k] = $a2[$k]; } else{ $r[$k] = self::merge_arrays($a1[$k], $a2[$k]); } } } else{ $r = array_merge($a1, $a2); } return $r; }
[ "public", "static", "function", "merge_arrays", "(", "array", "$", "a1", ",", "array", "$", "a2", ")", "{", "$", "args", "=", "\\", "func_get_args", "(", ")", ";", "if", "(", "\\", "count", "(", "$", "args", ")", ">", "2", ")", "{", "for", "(", "$", "i", "=", "\\", "count", "(", "$", "args", ")", "-", "1", ";", "$", "i", ">", "1", ";", "$", "i", "--", ")", "{", "$", "args", "[", "$", "i", "-", "1", "]", "=", "self", "::", "merge_arrays", "(", "$", "args", "[", "$", "i", "-", "1", "]", ",", "$", "args", "[", "$", "i", "]", ")", ";", "}", "$", "a2", "=", "$", "args", "[", "1", "]", ";", "}", "if", "(", "(", "self", "::", "is_assoc", "(", "$", "a1", ")", "||", "empty", "(", "$", "a1", ")", ")", "&&", "(", "self", "::", "is_assoc", "(", "$", "a2", ")", "||", "empty", "(", "$", "a2", ")", ")", ")", "{", "$", "keys", "=", "array_unique", "(", "array_merge", "(", "array_keys", "(", "$", "a1", ")", ",", "array_keys", "(", "$", "a2", ")", ")", ")", ";", "$", "r", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "k", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "k", ",", "$", "a1", ")", "&&", "!", "array_key_exists", "(", "$", "k", ",", "$", "a2", ")", ")", "{", "continue", ";", "}", "else", "if", "(", "!", "array_key_exists", "(", "$", "k", ",", "$", "a2", ")", ")", "{", "$", "r", "[", "$", "k", "]", "=", "$", "a1", "[", "$", "k", "]", ";", "}", "else", "if", "(", "!", "array_key_exists", "(", "$", "k", ",", "$", "a1", ")", "||", "!", "\\", "is_array", "(", "$", "a2", "[", "$", "k", "]", ")", "||", "!", "\\", "is_array", "(", "$", "a1", "[", "$", "k", "]", ")", "||", "is_numeric", "(", "key", "(", "$", "a2", "[", "$", "k", "]", ")", ")", ")", "{", "$", "r", "[", "$", "k", "]", "=", "$", "a2", "[", "$", "k", "]", ";", "}", "else", "{", "$", "r", "[", "$", "k", "]", "=", "self", "::", "merge_arrays", "(", "$", "a1", "[", "$", "k", "]", ",", "$", "a2", "[", "$", "k", "]", ")", ";", "}", "}", "}", "else", "{", "$", "r", "=", "array_merge", "(", "$", "a1", ",", "$", "a2", ")", ";", "}", "return", "$", "r", ";", "}" ]
Returns to a merged array from two or more arrays. ```php \bbn\x::merge_arrays([1, 'Test'], [2, 'Example']); // array [1, 'Test', 2, 'Example'] ``` @param array $a1 The first array to merge. @param array $a2 The second array to merge. @return array The merged array.
[ "Returns", "to", "a", "merged", "array", "from", "two", "or", "more", "arrays", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L217-L247
22,216
nabab/bbn
src/bbn/x.php
x.is_assoc
public static function is_assoc(array $r){ $keys = array_keys($r); $c = \count($keys); for ( $i = 0; $i < $c; $i++ ){ if ( $keys[$i] !== $i ){ return 1; } } return false; }
php
public static function is_assoc(array $r){ $keys = array_keys($r); $c = \count($keys); for ( $i = 0; $i < $c; $i++ ){ if ( $keys[$i] !== $i ){ return 1; } } return false; }
[ "public", "static", "function", "is_assoc", "(", "array", "$", "r", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "r", ")", ";", "$", "c", "=", "\\", "count", "(", "$", "keys", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "if", "(", "$", "keys", "[", "$", "i", "]", "!==", "$", "i", ")", "{", "return", "1", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the given array is associative. ```php \bbn\\x::is_assoc(['id' => 0, 'name' => 'Allison']); \bbn\\x::is_assoc(['Allison', 'John', 'Bert']); \bbn\\x::is_assoc([0 => "Allison", 1 => "John", 2 => "Bert"]); \bbn\\x::is_assoc([0 => "Allison", 1 => "John", 3 => "Bert"]); // boolean true // boolean false // boolean false // boolean true ``` @param array $r The array to check. @return bool
[ "Checks", "if", "the", "given", "array", "is", "associative", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L487-L496
22,217
nabab/bbn
src/bbn/x.php
x.get_dump
public static function get_dump(){ $args = \func_get_args(); $st = ''; foreach ( $args as $a ){ $r = $a; if ( \is_null($a) ){ $r = 'null'; } else if ( $a === false ){ $r = 'false'; } else if ( $a === true ){ $r = 'true'; } else if ( $a === 0 ){ $r = '0'; } else if ( $a === '' ){ $r = '""'; } else if ( $a === [] ){ $r = '[]'; } else if ( !$a ){ $r = '0'; } else if ( !\is_string($a) && \is_callable($a) ){ $r = 'Function'; } else if ( \is_object($a) ){ $n = \get_class($a); if ( $n === 'stdClass' ){ $r = str::export($a); } else{ $r = $n.' Object'; } } else if ( \is_array($a) ){ $r = str::export($a); } else if ( \is_resource($a) ){ $r = 'Resource '.get_resource_type($a); } else if ( str::is_buid($a) ){ $r = '0x'.bin2hex($a); } $st .= $r.PHP_EOL; } return PHP_EOL.$st.PHP_EOL; }
php
public static function get_dump(){ $args = \func_get_args(); $st = ''; foreach ( $args as $a ){ $r = $a; if ( \is_null($a) ){ $r = 'null'; } else if ( $a === false ){ $r = 'false'; } else if ( $a === true ){ $r = 'true'; } else if ( $a === 0 ){ $r = '0'; } else if ( $a === '' ){ $r = '""'; } else if ( $a === [] ){ $r = '[]'; } else if ( !$a ){ $r = '0'; } else if ( !\is_string($a) && \is_callable($a) ){ $r = 'Function'; } else if ( \is_object($a) ){ $n = \get_class($a); if ( $n === 'stdClass' ){ $r = str::export($a); } else{ $r = $n.' Object'; } } else if ( \is_array($a) ){ $r = str::export($a); } else if ( \is_resource($a) ){ $r = 'Resource '.get_resource_type($a); } else if ( str::is_buid($a) ){ $r = '0x'.bin2hex($a); } $st .= $r.PHP_EOL; } return PHP_EOL.$st.PHP_EOL; }
[ "public", "static", "function", "get_dump", "(", ")", "{", "$", "args", "=", "\\", "func_get_args", "(", ")", ";", "$", "st", "=", "''", ";", "foreach", "(", "$", "args", "as", "$", "a", ")", "{", "$", "r", "=", "$", "a", ";", "if", "(", "\\", "is_null", "(", "$", "a", ")", ")", "{", "$", "r", "=", "'null'", ";", "}", "else", "if", "(", "$", "a", "===", "false", ")", "{", "$", "r", "=", "'false'", ";", "}", "else", "if", "(", "$", "a", "===", "true", ")", "{", "$", "r", "=", "'true'", ";", "}", "else", "if", "(", "$", "a", "===", "0", ")", "{", "$", "r", "=", "'0'", ";", "}", "else", "if", "(", "$", "a", "===", "''", ")", "{", "$", "r", "=", "'\"\"'", ";", "}", "else", "if", "(", "$", "a", "===", "[", "]", ")", "{", "$", "r", "=", "'[]'", ";", "}", "else", "if", "(", "!", "$", "a", ")", "{", "$", "r", "=", "'0'", ";", "}", "else", "if", "(", "!", "\\", "is_string", "(", "$", "a", ")", "&&", "\\", "is_callable", "(", "$", "a", ")", ")", "{", "$", "r", "=", "'Function'", ";", "}", "else", "if", "(", "\\", "is_object", "(", "$", "a", ")", ")", "{", "$", "n", "=", "\\", "get_class", "(", "$", "a", ")", ";", "if", "(", "$", "n", "===", "'stdClass'", ")", "{", "$", "r", "=", "str", "::", "export", "(", "$", "a", ")", ";", "}", "else", "{", "$", "r", "=", "$", "n", ".", "' Object'", ";", "}", "}", "else", "if", "(", "\\", "is_array", "(", "$", "a", ")", ")", "{", "$", "r", "=", "str", "::", "export", "(", "$", "a", ")", ";", "}", "else", "if", "(", "\\", "is_resource", "(", "$", "a", ")", ")", "{", "$", "r", "=", "'Resource '", ".", "get_resource_type", "(", "$", "a", ")", ";", "}", "else", "if", "(", "str", "::", "is_buid", "(", "$", "a", ")", ")", "{", "$", "r", "=", "'0x'", ".", "bin2hex", "(", "$", "a", ")", ";", "}", "$", "st", ".=", "$", "r", ".", "PHP_EOL", ";", "}", "return", "PHP_EOL", ".", "$", "st", ".", "PHP_EOL", ";", "}" ]
Returns a dump of the given variable. @param mixed @return string
[ "Returns", "a", "dump", "of", "the", "given", "variable", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L504-L554
22,218
nabab/bbn
src/bbn/x.php
x.to_keypair
public static function to_keypair($arr, $protected = 1){ $num = \count($arr); $res = []; if ( ($num % 2) === 0 ){ $i = 0; while ( isset($arr[$i]) ){ if ( !\is_string($arr[$i]) || ( !$protected && !preg_match('/[0-9A-z\-_]+/8', str::cast($arr[$i])) ) ){ return false; } $res[$arr[$i]] = $arr[$i+1]; $i += 2; } } return $res; }
php
public static function to_keypair($arr, $protected = 1){ $num = \count($arr); $res = []; if ( ($num % 2) === 0 ){ $i = 0; while ( isset($arr[$i]) ){ if ( !\is_string($arr[$i]) || ( !$protected && !preg_match('/[0-9A-z\-_]+/8', str::cast($arr[$i])) ) ){ return false; } $res[$arr[$i]] = $arr[$i+1]; $i += 2; } } return $res; }
[ "public", "static", "function", "to_keypair", "(", "$", "arr", ",", "$", "protected", "=", "1", ")", "{", "$", "num", "=", "\\", "count", "(", "$", "arr", ")", ";", "$", "res", "=", "[", "]", ";", "if", "(", "(", "$", "num", "%", "2", ")", "===", "0", ")", "{", "$", "i", "=", "0", ";", "while", "(", "isset", "(", "$", "arr", "[", "$", "i", "]", ")", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "arr", "[", "$", "i", "]", ")", "||", "(", "!", "$", "protected", "&&", "!", "preg_match", "(", "'/[0-9A-z\\-_]+/8'", ",", "str", "::", "cast", "(", "$", "arr", "[", "$", "i", "]", ")", ")", ")", ")", "{", "return", "false", ";", "}", "$", "res", "[", "$", "arr", "[", "$", "i", "]", "]", "=", "$", "arr", "[", "$", "i", "+", "1", "]", ";", "$", "i", "+=", "2", ";", "}", "}", "return", "$", "res", ";", "}" ]
Converts a numeric array into an associative one, alternating key and value. ```php \bbn\x::to_keypair(['Test', 'TestFile', 'Example', 'ExampleFile']); // string ['Test' => 'TestFile', 'Example' => 'ExampleFile'] ``` @param array $arr The array. It must contain an even number of values @param bool $protected If false no index protection will be performed @return array|false
[ "Converts", "a", "numeric", "array", "into", "an", "associative", "one", "alternating", "key", "and", "value", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L653-L667
22,219
nabab/bbn
src/bbn/x.php
x.min_with_key
public static function min_with_key($array, $key){ if (!\is_array($array) || \count($array) == 0) return false; $min = $array[0][$key]; foreach($array as $a){ if($a[$key] < $min){ $min = $a[$key]; } } return $min; }
php
public static function min_with_key($array, $key){ if (!\is_array($array) || \count($array) == 0) return false; $min = $array[0][$key]; foreach($array as $a){ if($a[$key] < $min){ $min = $a[$key]; } } return $min; }
[ "public", "static", "function", "min_with_key", "(", "$", "array", ",", "$", "key", ")", "{", "if", "(", "!", "\\", "is_array", "(", "$", "array", ")", "||", "\\", "count", "(", "$", "array", ")", "==", "0", ")", "return", "false", ";", "$", "min", "=", "$", "array", "[", "0", "]", "[", "$", "key", "]", ";", "foreach", "(", "$", "array", "as", "$", "a", ")", "{", "if", "(", "$", "a", "[", "$", "key", "]", "<", "$", "min", ")", "{", "$", "min", "=", "$", "a", "[", "$", "key", "]", ";", "}", "}", "return", "$", "min", ";", "}" ]
Returns the minimum value of an index from a multidimensional array. ```php \bbn\x::min_with_key([ ['age' => 1, 'name' => 'Michelle'], ['age' => 8, 'name' => 'John'], ['age' => 45, 'name' => 'Sarah'], ['age' => 45, 'name' => 'Camilla'], ['age' => 2, 'name' => 'Allison'] ], 'age'); // int 1 ``` @param array $array A multidimensional array. @param string $key The index where to search. @return mixed value
[ "Returns", "the", "minimum", "value", "of", "an", "index", "from", "a", "multidimensional", "array", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L722-L731
22,220
nabab/bbn
src/bbn/x.php
x.debug
public static function debug($file=''){ $debug = array_map(function($a){ if ( isset($a['object']) ){ unset($a['object']); } return $a; }, debug_backtrace()); if ( empty($file) ){ self::hdump($debug); } else{ self::log($debug, $file); } }
php
public static function debug($file=''){ $debug = array_map(function($a){ if ( isset($a['object']) ){ unset($a['object']); } return $a; }, debug_backtrace()); if ( empty($file) ){ self::hdump($debug); } else{ self::log($debug, $file); } }
[ "public", "static", "function", "debug", "(", "$", "file", "=", "''", ")", "{", "$", "debug", "=", "array_map", "(", "function", "(", "$", "a", ")", "{", "if", "(", "isset", "(", "$", "a", "[", "'object'", "]", ")", ")", "{", "unset", "(", "$", "a", "[", "'object'", "]", ")", ";", "}", "return", "$", "a", ";", "}", ",", "debug_backtrace", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "file", ")", ")", "{", "self", "::", "hdump", "(", "$", "debug", ")", ";", "}", "else", "{", "self", "::", "log", "(", "$", "debug", ",", "$", "file", ")", ";", "}", "}" ]
Gets the backtrace and dumps or logs it into a file. ```php \bbn\x::dump(\bbn\x::debug()); ``` @param string $file The file to debug @return void
[ "Gets", "the", "backtrace", "and", "dumps", "or", "logs", "it", "into", "a", "file", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L742-L755
22,221
nabab/bbn
src/bbn/x.php
x.find
public static function find(array $ar, array $where){ //die(var_dump($where)); if ( !empty($where) ){ foreach ( $ar as $i => $v ){ $ok = 1; foreach ( $where as $k => $w ){ if ( !isset($v[$k]) || ($v[$k] !== $w) ){ $ok = false; break; } } if ( $ok ){ return $i; } } } return false; }
php
public static function find(array $ar, array $where){ //die(var_dump($where)); if ( !empty($where) ){ foreach ( $ar as $i => $v ){ $ok = 1; foreach ( $where as $k => $w ){ if ( !isset($v[$k]) || ($v[$k] !== $w) ){ $ok = false; break; } } if ( $ok ){ return $i; } } } return false; }
[ "public", "static", "function", "find", "(", "array", "$", "ar", ",", "array", "$", "where", ")", "{", "//die(var_dump($where));", "if", "(", "!", "empty", "(", "$", "where", ")", ")", "{", "foreach", "(", "$", "ar", "as", "$", "i", "=>", "$", "v", ")", "{", "$", "ok", "=", "1", ";", "foreach", "(", "$", "where", "as", "$", "k", "=>", "$", "w", ")", "{", "if", "(", "!", "isset", "(", "$", "v", "[", "$", "k", "]", ")", "||", "(", "$", "v", "[", "$", "k", "]", "!==", "$", "w", ")", ")", "{", "$", "ok", "=", "false", ";", "break", ";", "}", "}", "if", "(", "$", "ok", ")", "{", "return", "$", "i", ";", "}", "}", "}", "return", "false", ";", "}" ]
Returns the array's first index, which satisfies the 'where' condition. ```php \bbn\x::hdump(\bbn\x::find([[ 'id' => 1, 'name' => 'Andrew', 'fname' => 'Williams' ], [ 'id' => 2, 'name' => 'Albert', 'fname' => 'Taylor' ], [ 'id' => 3, 'name' => 'Mike', 'fname' => 'Smith' ], [ 'id' => 4, 'name' => 'John', 'fname' => 'White' ]], ['id' => 4])); // int 3 \bbn\x::hdump(\bbn\x::find([[ 'id' => 1, 'name' => 'Andrew', 'fname' => 'Williams' ], [ 'id' => 2, 'name' => 'Albert', 'fname' => 'Taylor' ], [ 'id' => 3, 'name' => 'Mike', 'fname' => 'Smith' ], [ 'id' => 4, 'name' => 'John', 'fname' => 'White' ]], ['name' => 'Albert', 'fname' => 'Taylor'])); // int 1 ``` @param array $ar The search within the array @param array $where The where condition @return bool|int
[ "Returns", "the", "array", "s", "first", "index", "which", "satisfies", "the", "where", "condition", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L893-L910
22,222
nabab/bbn
src/bbn/x.php
x.get_field
public static function get_field(array $r, array $where, string $field){ if ( ($res = self::get_row($r, $where)) && isset($res[$field]) ){ return $res[$field]; } return false; }
php
public static function get_field(array $r, array $where, string $field){ if ( ($res = self::get_row($r, $where)) && isset($res[$field]) ){ return $res[$field]; } return false; }
[ "public", "static", "function", "get_field", "(", "array", "$", "r", ",", "array", "$", "where", ",", "string", "$", "field", ")", "{", "if", "(", "(", "$", "res", "=", "self", "::", "get_row", "(", "$", "r", ",", "$", "where", ")", ")", "&&", "isset", "(", "$", "res", "[", "$", "field", "]", ")", ")", "{", "return", "$", "res", "[", "$", "field", "]", ";", "}", "return", "false", ";", "}" ]
Returns the first value of a specific field of an array. ```php \bbn\x::dump(\bbn\x::get_row([[ 'id' => 1, 'name' => 'Andrew', 'fname' => 'Williams' ], [ 'id' => 2, 'name' => 'Albert', 'fname' => 'Taylor' ], [ 'id' => 3, 'name' => 'Mike', 'fname' => 'Smith' ], [ 'id' => 4, 'name' => 'John', 'fname' => 'White' ]], ['name' => 'Albert'],'id')); // int 2 ``` @param array $r The array @param array $where The where condition @param string $field The field where to look for @return bool|mixed
[ "Returns", "the", "first", "value", "of", "a", "specific", "field", "of", "an", "array", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L977-L982
22,223
nabab/bbn
src/bbn/x.php
x.sort
public static function sort(&$ar){ usort($ar, function($a, $b){ if ( !str::is_number($a, $b) ){ $a = str_replace('.', '0', str_replace('_', '1', str::change_case($a, 'lower'))); $b = str_replace('.', '0', str_replace('_', '1', str::change_case($b, 'lower'))); return strcmp($a, $b); } if ( $a > $b ){ return 1; } else if ($a == $b){ return 0; } return -1; }); }
php
public static function sort(&$ar){ usort($ar, function($a, $b){ if ( !str::is_number($a, $b) ){ $a = str_replace('.', '0', str_replace('_', '1', str::change_case($a, 'lower'))); $b = str_replace('.', '0', str_replace('_', '1', str::change_case($b, 'lower'))); return strcmp($a, $b); } if ( $a > $b ){ return 1; } else if ($a == $b){ return 0; } return -1; }); }
[ "public", "static", "function", "sort", "(", "&", "$", "ar", ")", "{", "usort", "(", "$", "ar", ",", "function", "(", "$", "a", ",", "$", "b", ")", "{", "if", "(", "!", "str", "::", "is_number", "(", "$", "a", ",", "$", "b", ")", ")", "{", "$", "a", "=", "str_replace", "(", "'.'", ",", "'0'", ",", "str_replace", "(", "'_'", ",", "'1'", ",", "str", "::", "change_case", "(", "$", "a", ",", "'lower'", ")", ")", ")", ";", "$", "b", "=", "str_replace", "(", "'.'", ",", "'0'", ",", "str_replace", "(", "'_'", ",", "'1'", ",", "str", "::", "change_case", "(", "$", "b", ",", "'lower'", ")", ")", ")", ";", "return", "strcmp", "(", "$", "a", ",", "$", "b", ")", ";", "}", "if", "(", "$", "a", ">", "$", "b", ")", "{", "return", "1", ";", "}", "else", "if", "(", "$", "a", "==", "$", "b", ")", "{", "return", "0", ";", "}", "return", "-", "1", ";", "}", ")", ";", "}" ]
Sorts the items of an array. ```php $var = [3, 2, 5, 6, 1]; \bbn\x::sort($var); \bbn\x::hdump($var); // array [1,2,3,5,6] ``` @param $ar array The reference of the array to sort @return void
[ "Sorts", "the", "items", "of", "an", "array", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1035-L1050
22,224
nabab/bbn
src/bbn/x.php
x.curl
public static function curl(string $url, array $param = null, array $options = ['post' => 1]){ $ch = curl_init(); self::$last_curl = $ch; curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if (\is_object($param) ){ $param = self::to_array($param); } if ( \defined('BBN_IS_SSL') && \defined('BBN_IS_DEV') && BBN_IS_SSL && BBN_IS_DEV ){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); } $options = array_change_key_case($options, CASE_UPPER); foreach ( $options as $opt => $val ){ if ( \defined('CURLOPT_'.$opt) ){ curl_setopt($ch, constant('CURLOPT_'.$opt), $val); } } if ( $param ){ if ( !empty($options['POST']) ){ curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); } else if ( !empty($options['DELETE']) ){ //die($url.'?'.http_build_query($param)); curl_setopt($ch, CURLOPT_URL, $url.'?'.http_build_query($param)); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); } else{ curl_setopt($ch, CURLOPT_URL, $url.'?'.http_build_query($param)); } } else{ curl_setopt($ch, CURLOPT_URL, $url); if ( !empty($options['DELETE']) ){ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); } } $r = curl_exec($ch); if ( !$r ){ self::log(["PROBLEME AVEC L'URL $url", curl_error($ch), curl_getinfo($ch)], 'curl'); } return $r; }
php
public static function curl(string $url, array $param = null, array $options = ['post' => 1]){ $ch = curl_init(); self::$last_curl = $ch; curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if (\is_object($param) ){ $param = self::to_array($param); } if ( \defined('BBN_IS_SSL') && \defined('BBN_IS_DEV') && BBN_IS_SSL && BBN_IS_DEV ){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); } $options = array_change_key_case($options, CASE_UPPER); foreach ( $options as $opt => $val ){ if ( \defined('CURLOPT_'.$opt) ){ curl_setopt($ch, constant('CURLOPT_'.$opt), $val); } } if ( $param ){ if ( !empty($options['POST']) ){ curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); } else if ( !empty($options['DELETE']) ){ //die($url.'?'.http_build_query($param)); curl_setopt($ch, CURLOPT_URL, $url.'?'.http_build_query($param)); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); } else{ curl_setopt($ch, CURLOPT_URL, $url.'?'.http_build_query($param)); } } else{ curl_setopt($ch, CURLOPT_URL, $url); if ( !empty($options['DELETE']) ){ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); } } $r = curl_exec($ch); if ( !$r ){ self::log(["PROBLEME AVEC L'URL $url", curl_error($ch), curl_getinfo($ch)], 'curl'); } return $r; }
[ "public", "static", "function", "curl", "(", "string", "$", "url", ",", "array", "$", "param", "=", "null", ",", "array", "$", "options", "=", "[", "'post'", "=>", "1", "]", ")", "{", "$", "ch", "=", "curl_init", "(", ")", ";", "self", "::", "$", "last_curl", "=", "$", "ch", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "1", ")", ";", "if", "(", "\\", "is_object", "(", "$", "param", ")", ")", "{", "$", "param", "=", "self", "::", "to_array", "(", "$", "param", ")", ";", "}", "if", "(", "\\", "defined", "(", "'BBN_IS_SSL'", ")", "&&", "\\", "defined", "(", "'BBN_IS_DEV'", ")", "&&", "BBN_IS_SSL", "&&", "BBN_IS_DEV", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "false", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "false", ")", ";", "//curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);", "}", "$", "options", "=", "array_change_key_case", "(", "$", "options", ",", "CASE_UPPER", ")", ";", "foreach", "(", "$", "options", "as", "$", "opt", "=>", "$", "val", ")", "{", "if", "(", "\\", "defined", "(", "'CURLOPT_'", ".", "$", "opt", ")", ")", "{", "curl_setopt", "(", "$", "ch", ",", "constant", "(", "'CURLOPT_'", ".", "$", "opt", ")", ",", "$", "val", ")", ";", "}", "}", "if", "(", "$", "param", ")", "{", "if", "(", "!", "empty", "(", "$", "options", "[", "'POST'", "]", ")", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "param", ")", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "options", "[", "'DELETE'", "]", ")", ")", "{", "//die($url.'?'.http_build_query($param));", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ".", "'?'", ".", "http_build_query", "(", "$", "param", ")", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CUSTOMREQUEST", ",", "'DELETE'", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "}", "else", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ".", "'?'", ".", "http_build_query", "(", "$", "param", ")", ")", ";", "}", "}", "else", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'DELETE'", "]", ")", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CUSTOMREQUEST", ",", "'DELETE'", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "}", "}", "$", "r", "=", "curl_exec", "(", "$", "ch", ")", ";", "if", "(", "!", "$", "r", ")", "{", "self", "::", "log", "(", "[", "\"PROBLEME AVEC L'URL $url\"", ",", "curl_error", "(", "$", "ch", ")", ",", "curl_getinfo", "(", "$", "ch", ")", "]", ",", "'curl'", ")", ";", "}", "return", "$", "r", ";", "}" ]
Makes a Curl call towards a URL and returns the result as a string. ```php $url = 'https://www.omdbapi.com/'; $param = ['t'=>'la vita è bella']; \bbn\x::hdump(\bbn\x::curl($url,$param, ['POST' => false])); // object {"Title":"La vita è bella","Year":"1943","Rated":"N/A","Released":"26 May 1943","Runtime":"76 min","Genre":"Comedy","Director":"Carlo Ludovico Bragaglia","Writer":"Carlo Ludovico Bragaglia (story and screenplay)","Actors":"Alberto Rabagliati, María Mercader, Anna Magnani, Carlo Campanini","Plot":"N/A","Language":"Italian","Country":"Italy","Awards":"N/A","Poster":"http://ia.media-imdb.com/images/M/MV5BYmYyNzA2YWQtNDgyZC00OWVkLWIwMTEtNTdhNDQwZjcwYTMwXkEyXkFqcGdeQXVyNTczNDAyMDc@._V1_SX300.jpg","Metascore":"N/A","imdbRating":"7.9","imdbVotes":"50","imdbID":"tt0036502","Type":"movie","Response":"True"} ``` @param string $url @param array $param @param array $options @return mixed
[ "Makes", "a", "Curl", "call", "towards", "a", "URL", "and", "returns", "the", "result", "as", "a", "string", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1143-L1189
22,225
nabab/bbn
src/bbn/x.php
x.get_tree
public static function get_tree($ar){ $res = []; foreach ( $ar as $k => $a ){ $r = ['text' => $k]; if ( \is_object($a) ){ $a = self::to_array($a); } if ( \is_array($a) ){ $r['items'] = self::get_tree($a); } else if ( \is_null($a) ){ $r['text'] .= ': null'; } else if ( $a === false ){ $r['text'] .= ': false'; } else if ( $a === true ){ $r['text'] .= ': true'; } else { $r['text'] .= ': '.(string)$a; } array_push($res, $r); } return $res; }
php
public static function get_tree($ar){ $res = []; foreach ( $ar as $k => $a ){ $r = ['text' => $k]; if ( \is_object($a) ){ $a = self::to_array($a); } if ( \is_array($a) ){ $r['items'] = self::get_tree($a); } else if ( \is_null($a) ){ $r['text'] .= ': null'; } else if ( $a === false ){ $r['text'] .= ': false'; } else if ( $a === true ){ $r['text'] .= ': true'; } else { $r['text'] .= ': '.(string)$a; } array_push($res, $r); } return $res; }
[ "public", "static", "function", "get_tree", "(", "$", "ar", ")", "{", "$", "res", "=", "[", "]", ";", "foreach", "(", "$", "ar", "as", "$", "k", "=>", "$", "a", ")", "{", "$", "r", "=", "[", "'text'", "=>", "$", "k", "]", ";", "if", "(", "\\", "is_object", "(", "$", "a", ")", ")", "{", "$", "a", "=", "self", "::", "to_array", "(", "$", "a", ")", ";", "}", "if", "(", "\\", "is_array", "(", "$", "a", ")", ")", "{", "$", "r", "[", "'items'", "]", "=", "self", "::", "get_tree", "(", "$", "a", ")", ";", "}", "else", "if", "(", "\\", "is_null", "(", "$", "a", ")", ")", "{", "$", "r", "[", "'text'", "]", ".=", "': null'", ";", "}", "else", "if", "(", "$", "a", "===", "false", ")", "{", "$", "r", "[", "'text'", "]", ".=", "': false'", ";", "}", "else", "if", "(", "$", "a", "===", "true", ")", "{", "$", "r", "[", "'text'", "]", ".=", "': true'", ";", "}", "else", "{", "$", "r", "[", "'text'", "]", ".=", "': '", ".", "(", "string", ")", "$", "a", ";", "}", "array_push", "(", "$", "res", ",", "$", "r", ")", ";", "}", "return", "$", "res", ";", "}" ]
Returns the given array or object as a tree structure ready for a JS tree. ```php \bbn\x::hdump(\bbn\x::get_tree([['id' => 1,'name' => 'Andrew','fname' => 'Williams','children' =>[['name' => 'Emma','age' => 6],['name' => 'Giorgio','age' => 9]]], ['id' => 2,'name' => 'Albert','fname' => 'Taylor','children' =>[['name' => 'Esther','age' => 6],['name' => 'Paul','age' => 9]]], ['id' => 3,'name' => 'Mike','fname' => 'Smith','children' =>[['name' => 'Sara','age' => 6],['name' => 'Fred','age' => 9]]]])); /* array [ [ "text" => 0, "items" => [ [ "text" => "id: 1", ], [ "text" => "name: Andrew", ], [ "text" => "fname: Williams", ], [ "text" => "children", "items" => [ [ "text" => 0, "items" => [ [ "text" => "name: Emma", ], [ "text" => "age: 6", ], ], ], [ "text" => 1, "items" => [ [ "text" => "name: Giorgio", ], [ "text" => "age: 9", ], ], ], ], ], ], ], [ "text" => 1, "items" => [ [ "text" => "id: 2", ], [ "text" => "name: Albert", ], [ "text" => "fname: Taylor", ], [ "text" => "children", "items" => [ [ "text" => 0, "items" => [ [ "text" => "name: Esther", ], [ "text" => "age: 6", ], ], ], [ "text" => 1, "items" => [ [ "text" => "name: Paul", ], [ "text" => "age: 9", ], ], ], ], ], ], ], [ "text" => 2, "items" => [ [ "text" => "id: 3", ], [ "text" => "name: Mike", ], [ "text" => "fname: Smith", ], [ "text" => "children", "items" => [ [ "text" => 0, "items" => [ [ "text" => "name: Sara", ], [ "text" => "age: 6", ], ], ], [ "text" => 1, "items" => [ [ "text" => "name: Fred", ], [ "text" => "age: 9", ], ], ], ], ], ], ], ] ``` @param array $ar @return array
[ "Returns", "the", "given", "array", "or", "object", "as", "a", "tree", "structure", "ready", "for", "a", "JS", "tree", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1227-L1252
22,226
nabab/bbn
src/bbn/x.php
x.is_same
public static function is_same(string $file1, string $file2, $strict = false){ if ( !is_file($file1) || !is_file($file2) ){ throw Exception("Boo! One of the files given to the x::is_same function doesn't exist"); } else{ $same = filesize($file1) === filesize($file2); if ( !$strict || !$same ){ return $same; } return filemtime($file1) === filemtime($file2); } }
php
public static function is_same(string $file1, string $file2, $strict = false){ if ( !is_file($file1) || !is_file($file2) ){ throw Exception("Boo! One of the files given to the x::is_same function doesn't exist"); } else{ $same = filesize($file1) === filesize($file2); if ( !$strict || !$same ){ return $same; } return filemtime($file1) === filemtime($file2); } }
[ "public", "static", "function", "is_same", "(", "string", "$", "file1", ",", "string", "$", "file2", ",", "$", "strict", "=", "false", ")", "{", "if", "(", "!", "is_file", "(", "$", "file1", ")", "||", "!", "is_file", "(", "$", "file2", ")", ")", "{", "throw", "Exception", "(", "\"Boo! One of the files given to the x::is_same function doesn't exist\"", ")", ";", "}", "else", "{", "$", "same", "=", "filesize", "(", "$", "file1", ")", "===", "filesize", "(", "$", "file2", ")", ";", "if", "(", "!", "$", "strict", "||", "!", "$", "same", ")", "{", "return", "$", "same", ";", "}", "return", "filemtime", "(", "$", "file1", ")", "===", "filemtime", "(", "$", "file2", ")", ";", "}", "}" ]
Checks if two files are the same. @param string $file1 @param string $file2 @param bool $strict @return bool
[ "Checks", "if", "two", "files", "are", "the", "same", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1385-L1396
22,227
nabab/bbn
src/bbn/x.php
x.to_excel
public static function to_excel(array $data, string $file, bool $with_titles = true): bool { $checked = false; $todo = []; foreach ( $data as $d ){ if ( !$checked && self::is_assoc($d) ){ if ( $with_titles ){ $line1 = []; $line2 = []; foreach ( $d as $k => $v ){ $line1[] = $k; $line2[] = ''; } $todo[] = $line1; $todo[] = $line2; } $checked = true; } $todo[] = array_values($d); } if ( count($todo) ){ $objPHPExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $objPHPExcel->getActiveSheet()->fromArray($todo, NULL, 'A1'); $objPHPExcel ->getDefaultStyle() ->getNumberFormat() ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT); $ow = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($objPHPExcel); $ow->save($file); return \is_file($file); } return false; }
php
public static function to_excel(array $data, string $file, bool $with_titles = true): bool { $checked = false; $todo = []; foreach ( $data as $d ){ if ( !$checked && self::is_assoc($d) ){ if ( $with_titles ){ $line1 = []; $line2 = []; foreach ( $d as $k => $v ){ $line1[] = $k; $line2[] = ''; } $todo[] = $line1; $todo[] = $line2; } $checked = true; } $todo[] = array_values($d); } if ( count($todo) ){ $objPHPExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $objPHPExcel->getActiveSheet()->fromArray($todo, NULL, 'A1'); $objPHPExcel ->getDefaultStyle() ->getNumberFormat() ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT); $ow = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($objPHPExcel); $ow->save($file); return \is_file($file); } return false; }
[ "public", "static", "function", "to_excel", "(", "array", "$", "data", ",", "string", "$", "file", ",", "bool", "$", "with_titles", "=", "true", ")", ":", "bool", "{", "$", "checked", "=", "false", ";", "$", "todo", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "d", ")", "{", "if", "(", "!", "$", "checked", "&&", "self", "::", "is_assoc", "(", "$", "d", ")", ")", "{", "if", "(", "$", "with_titles", ")", "{", "$", "line1", "=", "[", "]", ";", "$", "line2", "=", "[", "]", ";", "foreach", "(", "$", "d", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "line1", "[", "]", "=", "$", "k", ";", "$", "line2", "[", "]", "=", "''", ";", "}", "$", "todo", "[", "]", "=", "$", "line1", ";", "$", "todo", "[", "]", "=", "$", "line2", ";", "}", "$", "checked", "=", "true", ";", "}", "$", "todo", "[", "]", "=", "array_values", "(", "$", "d", ")", ";", "}", "if", "(", "count", "(", "$", "todo", ")", ")", "{", "$", "objPHPExcel", "=", "new", "\\", "PhpOffice", "\\", "PhpSpreadsheet", "\\", "Spreadsheet", "(", ")", ";", "$", "objPHPExcel", "->", "getActiveSheet", "(", ")", "->", "fromArray", "(", "$", "todo", ",", "NULL", ",", "'A1'", ")", ";", "$", "objPHPExcel", "->", "getDefaultStyle", "(", ")", "->", "getNumberFormat", "(", ")", "->", "setFormatCode", "(", "\\", "PhpOffice", "\\", "PhpSpreadsheet", "\\", "Style", "\\", "NumberFormat", "::", "FORMAT_TEXT", ")", ";", "$", "ow", "=", "new", "\\", "PhpOffice", "\\", "PhpSpreadsheet", "\\", "Writer", "\\", "Xlsx", "(", "$", "objPHPExcel", ")", ";", "$", "ow", "->", "save", "(", "$", "file", ")", ";", "return", "\\", "is_file", "(", "$", "file", ")", ";", "}", "return", "false", ";", "}" ]
Creates an Excel file from a given array. @param array $array The array to export @param string $file The file path @param bool $with_titles Set it to false if you don't want the columns titles. Default true @return bool
[ "Creates", "an", "Excel", "file", "from", "a", "given", "array", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1462-L1494
22,228
nabab/bbn
src/bbn/x.php
x.make_uid
public static function make_uid($binary = false, $hyphens = false){ $tmp = sprintf($hyphens ? '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' : '%04x%04x%04x%04x%04x%04x%04x%04x', // 32 bits for "time_low" mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 16 bits for "time_mid" mt_rand(0, 0xffff), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 mt_rand(0, 0x0fff) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 mt_rand(0, 0x3fff) | 0x8000, // 48 bits for "node" mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); return $binary ? hex2bin($tmp) : $tmp; }
php
public static function make_uid($binary = false, $hyphens = false){ $tmp = sprintf($hyphens ? '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' : '%04x%04x%04x%04x%04x%04x%04x%04x', // 32 bits for "time_low" mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 16 bits for "time_mid" mt_rand(0, 0xffff), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 mt_rand(0, 0x0fff) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 mt_rand(0, 0x3fff) | 0x8000, // 48 bits for "node" mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); return $binary ? hex2bin($tmp) : $tmp; }
[ "public", "static", "function", "make_uid", "(", "$", "binary", "=", "false", ",", "$", "hyphens", "=", "false", ")", "{", "$", "tmp", "=", "sprintf", "(", "$", "hyphens", "?", "'%04x%04x-%04x-%04x-%04x-%04x%04x%04x'", ":", "'%04x%04x%04x%04x%04x%04x%04x%04x'", ",", "// 32 bits for \"time_low\"", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "// 16 bits for \"time_mid\"", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "// 16 bits for \"time_hi_and_version\",", "// four most significant bits holds version number 4", "mt_rand", "(", "0", ",", "0x0fff", ")", "|", "0x4000", ",", "// 16 bits, 8 bits for \"clk_seq_hi_res\",", "// 8 bits for \"clk_seq_low\",", "// two most significant bits holds zero and one for variant DCE1.1", "mt_rand", "(", "0", ",", "0x3fff", ")", "|", "0x8000", ",", "// 48 bits for \"node\"", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "mt_rand", "(", "0", ",", "0xffff", ")", ")", ";", "return", "$", "binary", "?", "hex2bin", "(", "$", "tmp", ")", ":", "$", "tmp", ";", "}" ]
Makes a UID. @param bool $binary Set it to true if you want a binary UID @param bool $hypens Set it to true if you want hypens to seperate the UID @return string|bynary
[ "Makes", "a", "UID", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1503-L1525
22,229
nabab/bbn
src/bbn/x.php
x.convert_uids
public static function convert_uids($st){ if ( \is_array($st) || \is_object($st) ){ foreach ( $st as &$s ){ $s = self::convert_uids($s); } } else if ( \bbn\str::is_uid($st) ){ $st = bin2hex($st); } return $st; }
php
public static function convert_uids($st){ if ( \is_array($st) || \is_object($st) ){ foreach ( $st as &$s ){ $s = self::convert_uids($s); } } else if ( \bbn\str::is_uid($st) ){ $st = bin2hex($st); } return $st; }
[ "public", "static", "function", "convert_uids", "(", "$", "st", ")", "{", "if", "(", "\\", "is_array", "(", "$", "st", ")", "||", "\\", "is_object", "(", "$", "st", ")", ")", "{", "foreach", "(", "$", "st", "as", "&", "$", "s", ")", "{", "$", "s", "=", "self", "::", "convert_uids", "(", "$", "s", ")", ";", "}", "}", "else", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "st", ")", ")", "{", "$", "st", "=", "bin2hex", "(", "$", "st", ")", ";", "}", "return", "$", "st", ";", "}" ]
Converts a hex UID to a binary UID. You can also give an array or an object to convert the array's items or the object's properties. @param string|array|object $st @return string
[ "Converts", "a", "hex", "UID", "to", "a", "binary", "UID", ".", "You", "can", "also", "give", "an", "array", "or", "an", "object", "to", "convert", "the", "array", "s", "items", "or", "the", "object", "s", "properties", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1532-L1542
22,230
nabab/bbn
src/bbn/x.php
x.compare_floats
public static function compare_floats($v1, $v2, string $operator = '===', int $precision = 4): bool { $v1 = round((float)$v1 * pow(10, $precision)); $v2 = round((float)$v2 * pow(10, $precision)); switch ($operator ){ case '===': return $v1 === $v2; case '==': return $v1 == $v2; case '>=': return $v1 >= $v2; case '<=': return $v1 <= $v2; case '>': return $v1 > $v2; case '<': return $v1 < $v2; } return false; }
php
public static function compare_floats($v1, $v2, string $operator = '===', int $precision = 4): bool { $v1 = round((float)$v1 * pow(10, $precision)); $v2 = round((float)$v2 * pow(10, $precision)); switch ($operator ){ case '===': return $v1 === $v2; case '==': return $v1 == $v2; case '>=': return $v1 >= $v2; case '<=': return $v1 <= $v2; case '>': return $v1 > $v2; case '<': return $v1 < $v2; } return false; }
[ "public", "static", "function", "compare_floats", "(", "$", "v1", ",", "$", "v2", ",", "string", "$", "operator", "=", "'==='", ",", "int", "$", "precision", "=", "4", ")", ":", "bool", "{", "$", "v1", "=", "round", "(", "(", "float", ")", "$", "v1", "*", "pow", "(", "10", ",", "$", "precision", ")", ")", ";", "$", "v2", "=", "round", "(", "(", "float", ")", "$", "v2", "*", "pow", "(", "10", ",", "$", "precision", ")", ")", ";", "switch", "(", "$", "operator", ")", "{", "case", "'==='", ":", "return", "$", "v1", "===", "$", "v2", ";", "case", "'=='", ":", "return", "$", "v1", "==", "$", "v2", ";", "case", "'>='", ":", "return", "$", "v1", ">=", "$", "v2", ";", "case", "'<='", ":", "return", "$", "v1", "<=", "$", "v2", ";", "case", "'>'", ":", "return", "$", "v1", ">", "$", "v2", ";", "case", "'<'", ":", "return", "$", "v1", "<", "$", "v2", ";", "}", "return", "false", ";", "}" ]
Compares two float numbers with the given operator. @param float $v1 @param float $v2 @param string $operator @param int $precision @return boolean
[ "Compares", "two", "float", "numbers", "with", "the", "given", "operator", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1553-L1572
22,231
nabab/bbn
src/bbn/x.php
x.json_base64_decode
public static function json_base64_decode($st): ?array { $res = \is_string($st) ? json_decode($st, true) : $st; if ( \is_array($res) ){ foreach ( $res as $i => $a ){ if ( \is_array($a) ){ $res[$i] = self::json_base64_decode($a); } else if ( \is_string($a) ){ $res[$i] = base64_decode($a); } else{ $res[$i] = $a; } } return $res; } return null; }
php
public static function json_base64_decode($st): ?array { $res = \is_string($st) ? json_decode($st, true) : $st; if ( \is_array($res) ){ foreach ( $res as $i => $a ){ if ( \is_array($a) ){ $res[$i] = self::json_base64_decode($a); } else if ( \is_string($a) ){ $res[$i] = base64_decode($a); } else{ $res[$i] = $a; } } return $res; } return null; }
[ "public", "static", "function", "json_base64_decode", "(", "$", "st", ")", ":", "?", "array", "{", "$", "res", "=", "\\", "is_string", "(", "$", "st", ")", "?", "json_decode", "(", "$", "st", ",", "true", ")", ":", "$", "st", ";", "if", "(", "\\", "is_array", "(", "$", "res", ")", ")", "{", "foreach", "(", "$", "res", "as", "$", "i", "=>", "$", "a", ")", "{", "if", "(", "\\", "is_array", "(", "$", "a", ")", ")", "{", "$", "res", "[", "$", "i", "]", "=", "self", "::", "json_base64_decode", "(", "$", "a", ")", ";", "}", "else", "if", "(", "\\", "is_string", "(", "$", "a", ")", ")", "{", "$", "res", "[", "$", "i", "]", "=", "base64_decode", "(", "$", "a", ")", ";", "}", "else", "{", "$", "res", "[", "$", "i", "]", "=", "$", "a", ";", "}", "}", "return", "$", "res", ";", "}", "return", "null", ";", "}" ]
Decodes the base64 array's values. You can also give a JSON string of an array. @param string|array $st @result array
[ "Decodes", "the", "base64", "array", "s", "values", ".", "You", "can", "also", "give", "a", "JSON", "string", "of", "an", "array", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1604-L1622
22,232
nabab/bbn
src/bbn/x.php
x.index_by_first_val
public static function index_by_first_val(array $ar): array { if ( empty($ar) || !isset($ar[0]) || !\count($ar[0]) ){ return $ar; } $cols = array_keys($ar[0]); $idx = array_shift($cols); $num_cols = \count($cols); $res = []; foreach ( $ar as $d ){ $index = $d[$idx]; unset($d[$idx]); $res[$index] = $num_cols > 1 ? $d : $d[$cols[0]]; } return $res; }
php
public static function index_by_first_val(array $ar): array { if ( empty($ar) || !isset($ar[0]) || !\count($ar[0]) ){ return $ar; } $cols = array_keys($ar[0]); $idx = array_shift($cols); $num_cols = \count($cols); $res = []; foreach ( $ar as $d ){ $index = $d[$idx]; unset($d[$idx]); $res[$index] = $num_cols > 1 ? $d : $d[$cols[0]]; } return $res; }
[ "public", "static", "function", "index_by_first_val", "(", "array", "$", "ar", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "ar", ")", "||", "!", "isset", "(", "$", "ar", "[", "0", "]", ")", "||", "!", "\\", "count", "(", "$", "ar", "[", "0", "]", ")", ")", "{", "return", "$", "ar", ";", "}", "$", "cols", "=", "array_keys", "(", "$", "ar", "[", "0", "]", ")", ";", "$", "idx", "=", "array_shift", "(", "$", "cols", ")", ";", "$", "num_cols", "=", "\\", "count", "(", "$", "cols", ")", ";", "$", "res", "=", "[", "]", ";", "foreach", "(", "$", "ar", "as", "$", "d", ")", "{", "$", "index", "=", "$", "d", "[", "$", "idx", "]", ";", "unset", "(", "$", "d", "[", "$", "idx", "]", ")", ";", "$", "res", "[", "$", "index", "]", "=", "$", "num_cols", ">", "1", "?", "$", "d", ":", "$", "d", "[", "$", "cols", "[", "0", "]", "]", ";", "}", "return", "$", "res", ";", "}" ]
Creates an associative array based on the first array's value. @param array $ar @return array
[ "Creates", "an", "associative", "array", "based", "on", "the", "first", "array", "s", "value", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/x.php#L1629-L1644
22,233
fkooman/php-lib-http
src/fkooman/Http/Url.php
Url.getQueryString
public function getQueryString() { $requestUri = $this->getRequestUri(); if (false !== $qPos = mb_strpos($requestUri, '?')) { // has query string return mb_substr($requestUri, $qPos + 1); } return ''; }
php
public function getQueryString() { $requestUri = $this->getRequestUri(); if (false !== $qPos = mb_strpos($requestUri, '?')) { // has query string return mb_substr($requestUri, $qPos + 1); } return ''; }
[ "public", "function", "getQueryString", "(", ")", "{", "$", "requestUri", "=", "$", "this", "->", "getRequestUri", "(", ")", ";", "if", "(", "false", "!==", "$", "qPos", "=", "mb_strpos", "(", "$", "requestUri", ",", "'?'", ")", ")", "{", "// has query string", "return", "mb_substr", "(", "$", "requestUri", ",", "$", "qPos", "+", "1", ")", ";", "}", "return", "''", ";", "}" ]
The query string. @return string the query string, or empty string if no query string is available
[ "The", "query", "string", "." ]
94956a480459b7f6b880d61f21ef03e683deb995
https://github.com/fkooman/php-lib-http/blob/94956a480459b7f6b880d61f21ef03e683deb995/src/fkooman/Http/Url.php#L151-L161
22,234
fkooman/php-lib-http
src/fkooman/Http/Url.php
Url.getQueryStringAsArray
public function getQueryStringAsArray() { $queryString = $this->getQueryString(); if ('' === $queryString) { return []; } $queryStringArray = []; parse_str($queryString, $queryStringArray); return $queryStringArray; }
php
public function getQueryStringAsArray() { $queryString = $this->getQueryString(); if ('' === $queryString) { return []; } $queryStringArray = []; parse_str($queryString, $queryStringArray); return $queryStringArray; }
[ "public", "function", "getQueryStringAsArray", "(", ")", "{", "$", "queryString", "=", "$", "this", "->", "getQueryString", "(", ")", ";", "if", "(", "''", "===", "$", "queryString", ")", "{", "return", "[", "]", ";", "}", "$", "queryStringArray", "=", "[", "]", ";", "parse_str", "(", "$", "queryString", ",", "$", "queryStringArray", ")", ";", "return", "$", "queryStringArray", ";", "}" ]
The query string as array. @return array the query string as array. The array will be empty if the query string is empty
[ "The", "query", "string", "as", "array", "." ]
94956a480459b7f6b880d61f21ef03e683deb995
https://github.com/fkooman/php-lib-http/blob/94956a480459b7f6b880d61f21ef03e683deb995/src/fkooman/Http/Url.php#L169-L181
22,235
fkooman/php-lib-http
src/fkooman/Http/Url.php
Url.getQueryParameter
public function getQueryParameter($key) { $queryStringArray = $this->getQueryStringAsArray(); if (array_key_exists($key, $queryStringArray)) { return $queryStringArray[$key]; } return null; }
php
public function getQueryParameter($key) { $queryStringArray = $this->getQueryStringAsArray(); if (array_key_exists($key, $queryStringArray)) { return $queryStringArray[$key]; } return null; }
[ "public", "function", "getQueryParameter", "(", "$", "key", ")", "{", "$", "queryStringArray", "=", "$", "this", "->", "getQueryStringAsArray", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "queryStringArray", ")", ")", "{", "return", "$", "queryStringArray", "[", "$", "key", "]", ";", "}", "return", "null", ";", "}" ]
Return a specific query string parameter value. @param string $key the query parameter key to get @return mixed the query parameter value if it is set, or null if the parameter is not available
[ "Return", "a", "specific", "query", "string", "parameter", "value", "." ]
94956a480459b7f6b880d61f21ef03e683deb995
https://github.com/fkooman/php-lib-http/blob/94956a480459b7f6b880d61f21ef03e683deb995/src/fkooman/Http/Url.php#L191-L200
22,236
fkooman/php-lib-http
src/fkooman/Http/Url.php
Url.getRoot
public function getRoot() { $requestUri = $this->getRequestUri(); $pathInfo = $this->getPathInfo(); // remove query string from REQUEST_URI, if set if (false !== $qPos = mb_strpos($requestUri, '?')) { // has query string $requestUri = mb_substr($requestUri, 0, $qPos + 1); } // remove PATH_INFO from REQUEST_URI, if set if (false !== $pPos = mb_strrpos($requestUri, $pathInfo)) { // has PATH_INFO $requestUri = mb_substr($requestUri, 0, $pPos + 1); } return $requestUri; }
php
public function getRoot() { $requestUri = $this->getRequestUri(); $pathInfo = $this->getPathInfo(); // remove query string from REQUEST_URI, if set if (false !== $qPos = mb_strpos($requestUri, '?')) { // has query string $requestUri = mb_substr($requestUri, 0, $qPos + 1); } // remove PATH_INFO from REQUEST_URI, if set if (false !== $pPos = mb_strrpos($requestUri, $pathInfo)) { // has PATH_INFO $requestUri = mb_substr($requestUri, 0, $pPos + 1); } return $requestUri; }
[ "public", "function", "getRoot", "(", ")", "{", "$", "requestUri", "=", "$", "this", "->", "getRequestUri", "(", ")", ";", "$", "pathInfo", "=", "$", "this", "->", "getPathInfo", "(", ")", ";", "// remove query string from REQUEST_URI, if set", "if", "(", "false", "!==", "$", "qPos", "=", "mb_strpos", "(", "$", "requestUri", ",", "'?'", ")", ")", "{", "// has query string", "$", "requestUri", "=", "mb_substr", "(", "$", "requestUri", ",", "0", ",", "$", "qPos", "+", "1", ")", ";", "}", "// remove PATH_INFO from REQUEST_URI, if set", "if", "(", "false", "!==", "$", "pPos", "=", "mb_strrpos", "(", "$", "requestUri", ",", "$", "pathInfo", ")", ")", "{", "// has PATH_INFO", "$", "requestUri", "=", "mb_substr", "(", "$", "requestUri", ",", "0", ",", "$", "pPos", "+", "1", ")", ";", "}", "return", "$", "requestUri", ";", "}" ]
Get the REQUEST_URI without PATH_INFO and QUERY_STRING, taking server rewriting in consideration. Example (without URL rewriting): https://www.example.org/foo/index.php/bar?a=b will return: '/foo/index.php' Example (with URL rewriting to index.php): https://www.example.org/foo/bar?a=b will return: '/foo' Example (with URL rewriting to index.php without sub folder): https://www.example.org/bar?a=b will return: ''
[ "Get", "the", "REQUEST_URI", "without", "PATH_INFO", "and", "QUERY_STRING", "taking", "server", "rewriting", "in", "consideration", "." ]
94956a480459b7f6b880d61f21ef03e683deb995
https://github.com/fkooman/php-lib-http/blob/94956a480459b7f6b880d61f21ef03e683deb995/src/fkooman/Http/Url.php#L218-L236
22,237
fkooman/php-lib-http
src/fkooman/Http/Url.php
Url.getAuthority
public function getAuthority() { $scheme = $this->getScheme(); $serverName = $this->getHost(); $serverPort = $this->getPort(); $authority = sprintf('%s://%s', $scheme, $serverName); if (('https' === $scheme && 443 !== $serverPort) || ('http' === $scheme && 80 !== $serverPort)) { $authority .= sprintf(':%d', $serverPort); } return $authority; }
php
public function getAuthority() { $scheme = $this->getScheme(); $serverName = $this->getHost(); $serverPort = $this->getPort(); $authority = sprintf('%s://%s', $scheme, $serverName); if (('https' === $scheme && 443 !== $serverPort) || ('http' === $scheme && 80 !== $serverPort)) { $authority .= sprintf(':%d', $serverPort); } return $authority; }
[ "public", "function", "getAuthority", "(", ")", "{", "$", "scheme", "=", "$", "this", "->", "getScheme", "(", ")", ";", "$", "serverName", "=", "$", "this", "->", "getHost", "(", ")", ";", "$", "serverPort", "=", "$", "this", "->", "getPort", "(", ")", ";", "$", "authority", "=", "sprintf", "(", "'%s://%s'", ",", "$", "scheme", ",", "$", "serverName", ")", ";", "if", "(", "(", "'https'", "===", "$", "scheme", "&&", "443", "!==", "$", "serverPort", ")", "||", "(", "'http'", "===", "$", "scheme", "&&", "80", "!==", "$", "serverPort", ")", ")", "{", "$", "authority", ".=", "sprintf", "(", "':%d'", ",", "$", "serverPort", ")", ";", "}", "return", "$", "authority", ";", "}" ]
Get the authority part of the URL. That is, the scheme, host and optional port if it is not a standard port. @return string the authority part of the URL
[ "Get", "the", "authority", "part", "of", "the", "URL", ".", "That", "is", "the", "scheme", "host", "and", "optional", "port", "if", "it", "is", "not", "a", "standard", "port", "." ]
94956a480459b7f6b880d61f21ef03e683deb995
https://github.com/fkooman/php-lib-http/blob/94956a480459b7f6b880d61f21ef03e683deb995/src/fkooman/Http/Url.php#L252-L264
22,238
gdbots/iam-php
src/Policy.php
Policy.isGranted
public function isGranted(string $action): bool { if (empty($this->allowed)) { return false; } if (isset($this->denied[$action]) || isset($this->denied[self::WILDCARD])) { return false; } $rules = $this->getRules($action); foreach ($rules as $rule) { if (isset($this->denied[$rule])) { return false; } } foreach ($rules as $rule) { if (isset($this->allowed[$rule])) { return true; } } return false; }
php
public function isGranted(string $action): bool { if (empty($this->allowed)) { return false; } if (isset($this->denied[$action]) || isset($this->denied[self::WILDCARD])) { return false; } $rules = $this->getRules($action); foreach ($rules as $rule) { if (isset($this->denied[$rule])) { return false; } } foreach ($rules as $rule) { if (isset($this->allowed[$rule])) { return true; } } return false; }
[ "public", "function", "isGranted", "(", "string", "$", "action", ")", ":", "bool", "{", "if", "(", "empty", "(", "$", "this", "->", "allowed", ")", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "denied", "[", "$", "action", "]", ")", "||", "isset", "(", "$", "this", "->", "denied", "[", "self", "::", "WILDCARD", "]", ")", ")", "{", "return", "false", ";", "}", "$", "rules", "=", "$", "this", "->", "getRules", "(", "$", "action", ")", ";", "foreach", "(", "$", "rules", "as", "$", "rule", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "denied", "[", "$", "rule", "]", ")", ")", "{", "return", "false", ";", "}", "}", "foreach", "(", "$", "rules", "as", "$", "rule", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "allowed", "[", "$", "rule", "]", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns true if the policy should allow the action to be carried out. @param string $action @return bool
[ "Returns", "true", "if", "the", "policy", "should", "allow", "the", "action", "to", "be", "carried", "out", "." ]
3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3
https://github.com/gdbots/iam-php/blob/3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3/src/Policy.php#L61-L86
22,239
gdbots/iam-php
src/Policy.php
Policy.getRules
private function getRules(string $action): array { $rules = []; $parts = explode(self::DELIMITER, $action); while (array_pop($parts)) { $rules[] = implode(self::DELIMITER, $parts) . self::DELIMITER . self::WILDCARD; } $rules = array_reverse($rules); $rules[0] = trim($rules[0], self::DELIMITER); $rules[] = $action; return $rules; }
php
private function getRules(string $action): array { $rules = []; $parts = explode(self::DELIMITER, $action); while (array_pop($parts)) { $rules[] = implode(self::DELIMITER, $parts) . self::DELIMITER . self::WILDCARD; } $rules = array_reverse($rules); $rules[0] = trim($rules[0], self::DELIMITER); $rules[] = $action; return $rules; }
[ "private", "function", "getRules", "(", "string", "$", "action", ")", ":", "array", "{", "$", "rules", "=", "[", "]", ";", "$", "parts", "=", "explode", "(", "self", "::", "DELIMITER", ",", "$", "action", ")", ";", "while", "(", "array_pop", "(", "$", "parts", ")", ")", "{", "$", "rules", "[", "]", "=", "implode", "(", "self", "::", "DELIMITER", ",", "$", "parts", ")", ".", "self", "::", "DELIMITER", ".", "self", "::", "WILDCARD", ";", "}", "$", "rules", "=", "array_reverse", "(", "$", "rules", ")", ";", "$", "rules", "[", "0", "]", "=", "trim", "(", "$", "rules", "[", "0", "]", ",", "self", "::", "DELIMITER", ")", ";", "$", "rules", "[", "]", "=", "$", "action", ";", "return", "$", "rules", ";", "}" ]
Converts an action with potentially colon delimiters into a set of permissions to check for. @example An action of "acme:blog:command:publish-article" becomes an array of: [ '*', 'acme:*', 'acme:blog:*', 'acme:blog:command:*', 'acme:blog:command:publish-article', ] @param string $action @return string[]
[ "Converts", "an", "action", "with", "potentially", "colon", "delimiters", "into", "a", "set", "of", "permissions", "to", "check", "for", "." ]
3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3
https://github.com/gdbots/iam-php/blob/3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3/src/Policy.php#L127-L141
22,240
rhosocial/yii2-user
models/log/UserLoginTrait.php
UserLoginTrait.getLoginLogs
public function getLoginLogs() { /* @var $this User */ $class = $this->loginLogClass; try { return $class::getLatests($this, Login::GET_ALL_LATESTS); } catch (\Exception $ex) { Yii::error($ex->getMessage(), __METHOD__); return []; } }
php
public function getLoginLogs() { /* @var $this User */ $class = $this->loginLogClass; try { return $class::getLatests($this, Login::GET_ALL_LATESTS); } catch (\Exception $ex) { Yii::error($ex->getMessage(), __METHOD__); return []; } }
[ "public", "function", "getLoginLogs", "(", ")", "{", "/* @var $this User */", "$", "class", "=", "$", "this", "->", "loginLogClass", ";", "try", "{", "return", "$", "class", "::", "getLatests", "(", "$", "this", ",", "Login", "::", "GET_ALL_LATESTS", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "Yii", "::", "error", "(", "$", "ex", "->", "getMessage", "(", ")", ",", "__METHOD__", ")", ";", "return", "[", "]", ";", "}", "}" ]
Get login logs. @return Login[]
[ "Get", "login", "logs", "." ]
96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/models/log/UserLoginTrait.php#L35-L45
22,241
rhosocial/yii2-user
models/log/UserLoginTrait.php
UserLoginTrait.recordLogin
public function recordLogin($config = []) { if (empty($this->loginLogClass)) { return false; } $log = $this->create($this->loginLogClass, $config); try { return $log->save(); } catch (\Exception $ex) { Yii::error($ex->getMessage(), __METHOD__); } }
php
public function recordLogin($config = []) { if (empty($this->loginLogClass)) { return false; } $log = $this->create($this->loginLogClass, $config); try { return $log->save(); } catch (\Exception $ex) { Yii::error($ex->getMessage(), __METHOD__); } }
[ "public", "function", "recordLogin", "(", "$", "config", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "loginLogClass", ")", ")", "{", "return", "false", ";", "}", "$", "log", "=", "$", "this", "->", "create", "(", "$", "this", "->", "loginLogClass", ",", "$", "config", ")", ";", "try", "{", "return", "$", "log", "->", "save", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "Yii", "::", "error", "(", "$", "ex", "->", "getMessage", "(", ")", ",", "__METHOD__", ")", ";", "}", "}" ]
Record login. @param array $config @return mixed
[ "Record", "login", "." ]
96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/models/log/UserLoginTrait.php#L68-L79
22,242
jnaxo/country-codes
src/Store/api/Collection.php
Collection.setData
public function setData($collection, $resource_name = '') { $this->collection = collect(); if (!$this->resource_name) { $this->resource_name = empty($resource_name) ? 'undefined' : $resource_name; } $this->data = []; foreach ($collection as $item) { $this->collection->push(clone $item); $i = new Item($item, $this->resource_name); array_push($this->data, $i->getData()); } $this->response['data'] = $this->data; }
php
public function setData($collection, $resource_name = '') { $this->collection = collect(); if (!$this->resource_name) { $this->resource_name = empty($resource_name) ? 'undefined' : $resource_name; } $this->data = []; foreach ($collection as $item) { $this->collection->push(clone $item); $i = new Item($item, $this->resource_name); array_push($this->data, $i->getData()); } $this->response['data'] = $this->data; }
[ "public", "function", "setData", "(", "$", "collection", ",", "$", "resource_name", "=", "''", ")", "{", "$", "this", "->", "collection", "=", "collect", "(", ")", ";", "if", "(", "!", "$", "this", "->", "resource_name", ")", "{", "$", "this", "->", "resource_name", "=", "empty", "(", "$", "resource_name", ")", "?", "'undefined'", ":", "$", "resource_name", ";", "}", "$", "this", "->", "data", "=", "[", "]", ";", "foreach", "(", "$", "collection", "as", "$", "item", ")", "{", "$", "this", "->", "collection", "->", "push", "(", "clone", "$", "item", ")", ";", "$", "i", "=", "new", "Item", "(", "$", "item", ",", "$", "this", "->", "resource_name", ")", ";", "array_push", "(", "$", "this", "->", "data", ",", "$", "i", "->", "getData", "(", ")", ")", ";", "}", "$", "this", "->", "response", "[", "'data'", "]", "=", "$", "this", "->", "data", ";", "}" ]
Set collection data @param type $collection @param string $resource_name
[ "Set", "collection", "data" ]
ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9
https://github.com/jnaxo/country-codes/blob/ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9/src/Store/api/Collection.php#L87-L103
22,243
sciactive/nymph-server
src/Nymph.php
Nymph.configure
public static function configure($config = []) { $defaults = include dirname(__DIR__).'/conf/defaults.php'; self::$config = array_replace_recursive($defaults, $config); if (isset(self::$driver)) { if (self::$driver->connected) { self::$driver->disconnect(); } self::$driver = null; } $class = '\\Nymph\\Drivers\\'.self::$config['driver'].'Driver'; $Nymph = new $class(self::$config); if (class_exists('\\SciActive\\Hook')) { \SciActive\Hook::hookObject($Nymph, 'Nymph->'); } if (self::$config['pubsub']) { \Nymph\PubSub\HookMethods::setup(); } self::$driver = $Nymph; }
php
public static function configure($config = []) { $defaults = include dirname(__DIR__).'/conf/defaults.php'; self::$config = array_replace_recursive($defaults, $config); if (isset(self::$driver)) { if (self::$driver->connected) { self::$driver->disconnect(); } self::$driver = null; } $class = '\\Nymph\\Drivers\\'.self::$config['driver'].'Driver'; $Nymph = new $class(self::$config); if (class_exists('\\SciActive\\Hook')) { \SciActive\Hook::hookObject($Nymph, 'Nymph->'); } if (self::$config['pubsub']) { \Nymph\PubSub\HookMethods::setup(); } self::$driver = $Nymph; }
[ "public", "static", "function", "configure", "(", "$", "config", "=", "[", "]", ")", "{", "$", "defaults", "=", "include", "dirname", "(", "__DIR__", ")", ".", "'/conf/defaults.php'", ";", "self", "::", "$", "config", "=", "array_replace_recursive", "(", "$", "defaults", ",", "$", "config", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "driver", ")", ")", "{", "if", "(", "self", "::", "$", "driver", "->", "connected", ")", "{", "self", "::", "$", "driver", "->", "disconnect", "(", ")", ";", "}", "self", "::", "$", "driver", "=", "null", ";", "}", "$", "class", "=", "'\\\\Nymph\\\\Drivers\\\\'", ".", "self", "::", "$", "config", "[", "'driver'", "]", ".", "'Driver'", ";", "$", "Nymph", "=", "new", "$", "class", "(", "self", "::", "$", "config", ")", ";", "if", "(", "class_exists", "(", "'\\\\SciActive\\\\Hook'", ")", ")", "{", "\\", "SciActive", "\\", "Hook", "::", "hookObject", "(", "$", "Nymph", ",", "'Nymph->'", ")", ";", "}", "if", "(", "self", "::", "$", "config", "[", "'pubsub'", "]", ")", "{", "\\", "Nymph", "\\", "PubSub", "\\", "HookMethods", "::", "setup", "(", ")", ";", "}", "self", "::", "$", "driver", "=", "$", "Nymph", ";", "}" ]
Apply configuration to Nymph. $config should be an associative array of Nymph configuration. Use the following form: [ 'driver' => 'MySQL', 'pubsub' => true, 'MySql' => [ 'host' => '127.0.0.1' ] ] @param array $config An associative array of Nymph's configuration.
[ "Apply", "configuration", "to", "Nymph", "." ]
3c18dbf45c2750d07c798e14534dba87387beeba
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Nymph.php#L55-L76
22,244
sciactive/nymph-server
src/Nymph.php
Nymph.checkData
public static function checkData( &$data, &$sdata, $selectors, $guid = null, $tags = null, $typesAlreadyChecked = [], $dataValsAreadyChecked = [] ) { return self::$driver->checkData( $data, $sdata, $selectors, $guid, $tags, $typesAlreadyChecked, $dataValsAreadyChecked ); }
php
public static function checkData( &$data, &$sdata, $selectors, $guid = null, $tags = null, $typesAlreadyChecked = [], $dataValsAreadyChecked = [] ) { return self::$driver->checkData( $data, $sdata, $selectors, $guid, $tags, $typesAlreadyChecked, $dataValsAreadyChecked ); }
[ "public", "static", "function", "checkData", "(", "&", "$", "data", ",", "&", "$", "sdata", ",", "$", "selectors", ",", "$", "guid", "=", "null", ",", "$", "tags", "=", "null", ",", "$", "typesAlreadyChecked", "=", "[", "]", ",", "$", "dataValsAreadyChecked", "=", "[", "]", ")", "{", "return", "self", "::", "$", "driver", "->", "checkData", "(", "$", "data", ",", "$", "sdata", ",", "$", "selectors", ",", "$", "guid", ",", "$", "tags", ",", "$", "typesAlreadyChecked", ",", "$", "dataValsAreadyChecked", ")", ";", "}" ]
Check entity data to see if it matches given selectors. @param array $data An array of unserialized entity data. The data array should contain the cdate and mdate. @param array $sdata An array of serialized entity data. If a value here is checked, it will be unserialized and placed in the $data array. @param array $selectors An array of formatted selectors. @param int|null $guid The guid. If left null, guid will not be checked, and automatically considered passing. @param array|null $tags The tags array. If left null, tags will not be checked, and automatically considered passing. @param array $typesAlreadyChecked An array of clause types that have already been checked. They will be considered passing. @param array $dataValsAreadyChecked An array of data values that have already been checked. They will be considered passing if the value is identical. @return boolean Whether the entity data passes the given selectors.
[ "Check", "entity", "data", "to", "see", "if", "it", "matches", "given", "selectors", "." ]
3c18dbf45c2750d07c798e14534dba87387beeba
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Nymph.php#L101-L119
22,245
sciactive/nymph-server
src/Nymph.php
Nymph.hsort
public static function hsort( &$array, $property = null, $parentProperty = null, $caseSensitive = false, $reverse = false ) { return self::$driver->hsort( $array, $property, $parentProperty, $caseSensitive, $reverse ); }
php
public static function hsort( &$array, $property = null, $parentProperty = null, $caseSensitive = false, $reverse = false ) { return self::$driver->hsort( $array, $property, $parentProperty, $caseSensitive, $reverse ); }
[ "public", "static", "function", "hsort", "(", "&", "$", "array", ",", "$", "property", "=", "null", ",", "$", "parentProperty", "=", "null", ",", "$", "caseSensitive", "=", "false", ",", "$", "reverse", "=", "false", ")", "{", "return", "self", "::", "$", "driver", "->", "hsort", "(", "$", "array", ",", "$", "property", ",", "$", "parentProperty", ",", "$", "caseSensitive", ",", "$", "reverse", ")", ";", "}" ]
Sort an array of entities hierarchically by a specified property's value. Entities will be placed immediately after their parents. The $parentProperty property must hold either null, or the entity's parent. @param array &$array The array of entities. @param string|null $property The name of the property to sort entities by. @param string|null $parentProperty The name of the property which holds the parent of the entity. @param bool $caseSensitive Sort case sensitively. @param bool $reverse Reverse the sort order.
[ "Sort", "an", "array", "of", "entities", "hierarchically", "by", "a", "specified", "property", "s", "value", "." ]
3c18dbf45c2750d07c798e14534dba87387beeba
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Nymph.php#L160-L174
22,246
sciactive/nymph-server
src/Nymph.php
Nymph.sort
public static function sort( &$array, $property = null, $caseSensitive = false, $reverse = false ) { return self::$driver->sort( $array, $property, $caseSensitive, $reverse ); }
php
public static function sort( &$array, $property = null, $caseSensitive = false, $reverse = false ) { return self::$driver->sort( $array, $property, $caseSensitive, $reverse ); }
[ "public", "static", "function", "sort", "(", "&", "$", "array", ",", "$", "property", "=", "null", ",", "$", "caseSensitive", "=", "false", ",", "$", "reverse", "=", "false", ")", "{", "return", "self", "::", "$", "driver", "->", "sort", "(", "$", "array", ",", "$", "property", ",", "$", "caseSensitive", ",", "$", "reverse", ")", ";", "}" ]
Sort an array of entities by a specified property's value. @param array &$array The array of entities. @param string|null $property The name of the property to sort entities by. @param bool $caseSensitive Sort case sensitively. @param bool $reverse Reverse the sort order.
[ "Sort", "an", "array", "of", "entities", "by", "a", "specified", "property", "s", "value", "." ]
3c18dbf45c2750d07c798e14534dba87387beeba
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Nymph.php#L213-L225
22,247
infusephp/infuse
src/SymfonyHttpBridge.php
SymfonyHttpBridge.convertSymfonyRequest
public function convertSymfonyRequest(SymfonyRequest $request) { $session = $request->getSession(); if ($session) { $session = $session->all(); } else { $session = []; } // decode request parameters $parameters = $request->request->all(); if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH']) && 'json' == $request->getContentType()) { $parameters = json_decode($request->getContent(), true); } // NOTE: This is not entirely accurate to use $_FILES, however, // because Symfony converts $_FILES into an UploadedFile object // and Infuse expects the raw array, it makes compatibility difficult. $req = new Request($request->query->all(), $parameters, $request->cookies->all(), $_FILES, $request->server->all(), $session); $req->setParams($request->attributes->all()); return $req; }
php
public function convertSymfonyRequest(SymfonyRequest $request) { $session = $request->getSession(); if ($session) { $session = $session->all(); } else { $session = []; } // decode request parameters $parameters = $request->request->all(); if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH']) && 'json' == $request->getContentType()) { $parameters = json_decode($request->getContent(), true); } // NOTE: This is not entirely accurate to use $_FILES, however, // because Symfony converts $_FILES into an UploadedFile object // and Infuse expects the raw array, it makes compatibility difficult. $req = new Request($request->query->all(), $parameters, $request->cookies->all(), $_FILES, $request->server->all(), $session); $req->setParams($request->attributes->all()); return $req; }
[ "public", "function", "convertSymfonyRequest", "(", "SymfonyRequest", "$", "request", ")", "{", "$", "session", "=", "$", "request", "->", "getSession", "(", ")", ";", "if", "(", "$", "session", ")", "{", "$", "session", "=", "$", "session", "->", "all", "(", ")", ";", "}", "else", "{", "$", "session", "=", "[", "]", ";", "}", "// decode request parameters", "$", "parameters", "=", "$", "request", "->", "request", "->", "all", "(", ")", ";", "if", "(", "in_array", "(", "$", "request", "->", "getMethod", "(", ")", ",", "[", "'POST'", ",", "'PUT'", ",", "'PATCH'", "]", ")", "&&", "'json'", "==", "$", "request", "->", "getContentType", "(", ")", ")", "{", "$", "parameters", "=", "json_decode", "(", "$", "request", "->", "getContent", "(", ")", ",", "true", ")", ";", "}", "// NOTE: This is not entirely accurate to use $_FILES, however,", "// because Symfony converts $_FILES into an UploadedFile object", "// and Infuse expects the raw array, it makes compatibility difficult.", "$", "req", "=", "new", "Request", "(", "$", "request", "->", "query", "->", "all", "(", ")", ",", "$", "parameters", ",", "$", "request", "->", "cookies", "->", "all", "(", ")", ",", "$", "_FILES", ",", "$", "request", "->", "server", "->", "all", "(", ")", ",", "$", "session", ")", ";", "$", "req", "->", "setParams", "(", "$", "request", "->", "attributes", "->", "all", "(", ")", ")", ";", "return", "$", "req", ";", "}" ]
Converts a Symfony request object into an Infuse request object. @param SymfonyRequest $request @return Request
[ "Converts", "a", "Symfony", "request", "object", "into", "an", "Infuse", "request", "object", "." ]
7520b237c69f3d8a07d95d7481b26027ced2ed83
https://github.com/infusephp/infuse/blob/7520b237c69f3d8a07d95d7481b26027ced2ed83/src/SymfonyHttpBridge.php#L22-L44
22,248
infusephp/infuse
src/SymfonyHttpBridge.php
SymfonyHttpBridge.convertInfuseResponse
public function convertInfuseResponse(Response $res) { $response = new SymfonyResponse($res->getBody(), $res->getCode(), $res->headers()); // transfer cookies foreach ($res->cookies() as $name => $params) { list($value, $expire, $path, $domain, $secure, $httponly) = $params; $cookie = new Cookie($name, $value, $expire, $path, $domain, $secure, $httponly); $response->headers->setCookie($cookie); } return $response; }
php
public function convertInfuseResponse(Response $res) { $response = new SymfonyResponse($res->getBody(), $res->getCode(), $res->headers()); // transfer cookies foreach ($res->cookies() as $name => $params) { list($value, $expire, $path, $domain, $secure, $httponly) = $params; $cookie = new Cookie($name, $value, $expire, $path, $domain, $secure, $httponly); $response->headers->setCookie($cookie); } return $response; }
[ "public", "function", "convertInfuseResponse", "(", "Response", "$", "res", ")", "{", "$", "response", "=", "new", "SymfonyResponse", "(", "$", "res", "->", "getBody", "(", ")", ",", "$", "res", "->", "getCode", "(", ")", ",", "$", "res", "->", "headers", "(", ")", ")", ";", "// transfer cookies", "foreach", "(", "$", "res", "->", "cookies", "(", ")", "as", "$", "name", "=>", "$", "params", ")", "{", "list", "(", "$", "value", ",", "$", "expire", ",", "$", "path", ",", "$", "domain", ",", "$", "secure", ",", "$", "httponly", ")", "=", "$", "params", ";", "$", "cookie", "=", "new", "Cookie", "(", "$", "name", ",", "$", "value", ",", "$", "expire", ",", "$", "path", ",", "$", "domain", ",", "$", "secure", ",", "$", "httponly", ")", ";", "$", "response", "->", "headers", "->", "setCookie", "(", "$", "cookie", ")", ";", "}", "return", "$", "response", ";", "}" ]
Converts an Infuse response object into a Symfony response object. @param Response $res @return SymfonyResponse
[ "Converts", "an", "Infuse", "response", "object", "into", "a", "Symfony", "response", "object", "." ]
7520b237c69f3d8a07d95d7481b26027ced2ed83
https://github.com/infusephp/infuse/blob/7520b237c69f3d8a07d95d7481b26027ced2ed83/src/SymfonyHttpBridge.php#L53-L65
22,249
nabab/bbn
src/bbn/user/preferences.php
preferences._init_user
private function _init_user(bbn\user $user): preferences { $this->user = $user; $this->id_user = $this->user->get_id(); $this->id_group = $this->user->get_group(); return $this; }
php
private function _init_user(bbn\user $user): preferences { $this->user = $user; $this->id_user = $this->user->get_id(); $this->id_group = $this->user->get_group(); return $this; }
[ "private", "function", "_init_user", "(", "bbn", "\\", "user", "$", "user", ")", ":", "preferences", "{", "$", "this", "->", "user", "=", "$", "user", ";", "$", "this", "->", "id_user", "=", "$", "this", "->", "user", "->", "get_id", "(", ")", ";", "$", "this", "->", "id_group", "=", "$", "this", "->", "user", "->", "get_group", "(", ")", ";", "return", "$", "this", ";", "}" ]
Sets the user variables using a user object @param bbn\user $user @return preferences
[ "Sets", "the", "user", "variables", "using", "a", "user", "object" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L84-L90
22,250
nabab/bbn
src/bbn/user/preferences.php
preferences._insert
private function _insert(string $id_option, array $cfg): int { $json = ($tmp = $this->get_cfg(false, $cfg)) ? json_encode($tmp) : NULL; return $this->db->insert($this->class_cfg['table'], [ $this->fields['id_option'] => $id_option, $this->fields['num'] => $cfg[$this->fields['num']] ?? NULL, $this->fields['text'] => $cfg[$this->fields['text']] ?? NULL, $this->fields['id_link'] => $cfg[$this->fields['id_link']] ?? NULL, $this->fields['id_alias'] => $cfg[$this->fields['id_alias']] ?? NULL, $this->fields['id_user'] => $this->id_user, $this->fields['cfg'] => $json ]); }
php
private function _insert(string $id_option, array $cfg): int { $json = ($tmp = $this->get_cfg(false, $cfg)) ? json_encode($tmp) : NULL; return $this->db->insert($this->class_cfg['table'], [ $this->fields['id_option'] => $id_option, $this->fields['num'] => $cfg[$this->fields['num']] ?? NULL, $this->fields['text'] => $cfg[$this->fields['text']] ?? NULL, $this->fields['id_link'] => $cfg[$this->fields['id_link']] ?? NULL, $this->fields['id_alias'] => $cfg[$this->fields['id_alias']] ?? NULL, $this->fields['id_user'] => $this->id_user, $this->fields['cfg'] => $json ]); }
[ "private", "function", "_insert", "(", "string", "$", "id_option", ",", "array", "$", "cfg", ")", ":", "int", "{", "$", "json", "=", "(", "$", "tmp", "=", "$", "this", "->", "get_cfg", "(", "false", ",", "$", "cfg", ")", ")", "?", "json_encode", "(", "$", "tmp", ")", ":", "NULL", ";", "return", "$", "this", "->", "db", "->", "insert", "(", "$", "this", "->", "class_cfg", "[", "'table'", "]", ",", "[", "$", "this", "->", "fields", "[", "'id_option'", "]", "=>", "$", "id_option", ",", "$", "this", "->", "fields", "[", "'num'", "]", "=>", "$", "cfg", "[", "$", "this", "->", "fields", "[", "'num'", "]", "]", "??", "NULL", ",", "$", "this", "->", "fields", "[", "'text'", "]", "=>", "$", "cfg", "[", "$", "this", "->", "fields", "[", "'text'", "]", "]", "??", "NULL", ",", "$", "this", "->", "fields", "[", "'id_link'", "]", "=>", "$", "cfg", "[", "$", "this", "->", "fields", "[", "'id_link'", "]", "]", "??", "NULL", ",", "$", "this", "->", "fields", "[", "'id_alias'", "]", "=>", "$", "cfg", "[", "$", "this", "->", "fields", "[", "'id_alias'", "]", "]", "??", "NULL", ",", "$", "this", "->", "fields", "[", "'id_user'", "]", "=>", "$", "this", "->", "id_user", ",", "$", "this", "->", "fields", "[", "'cfg'", "]", "=>", "$", "json", "]", ")", ";", "}" ]
Actually inserts a row into the preferences table @param string $id_option @param array $cfg @return int
[ "Actually", "inserts", "a", "row", "into", "the", "preferences", "table" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L119-L131
22,251
nabab/bbn
src/bbn/user/preferences.php
preferences.retrieve_user_ids
public function retrieve_user_ids(string $id_option = null, string $id_user): ?array { return $this->_retrieve_ids($id_option, $id_user); }
php
public function retrieve_user_ids(string $id_option = null, string $id_user): ?array { return $this->_retrieve_ids($id_option, $id_user); }
[ "public", "function", "retrieve_user_ids", "(", "string", "$", "id_option", "=", "null", ",", "string", "$", "id_user", ")", ":", "?", "array", "{", "return", "$", "this", "->", "_retrieve_ids", "(", "$", "id_option", ",", "$", "id_user", ")", ";", "}" ]
Returns preferences' IDs from the option's ID and the given user ID @param null|string $id_option @param string $id_user @return array|null
[ "Returns", "preferences", "IDs", "from", "the", "option", "s", "ID", "and", "the", "given", "user", "ID" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L274-L277
22,252
nabab/bbn
src/bbn/user/preferences.php
preferences.retrieve_group_ids
public function retrieve_group_ids(string $id_option = null, string $id_group): ?array { return $this->_retrieve_ids($id_option, null, $id_group); }
php
public function retrieve_group_ids(string $id_option = null, string $id_group): ?array { return $this->_retrieve_ids($id_option, null, $id_group); }
[ "public", "function", "retrieve_group_ids", "(", "string", "$", "id_option", "=", "null", ",", "string", "$", "id_group", ")", ":", "?", "array", "{", "return", "$", "this", "->", "_retrieve_ids", "(", "$", "id_option", ",", "null", ",", "$", "id_group", ")", ";", "}" ]
Returns preferences' IDs from the option's ID and the given group ID @param null|string $id_option @param string $id_group @return array|null
[ "Returns", "preferences", "IDs", "from", "the", "option", "s", "ID", "and", "the", "given", "group", "ID" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L286-L289
22,253
nabab/bbn
src/bbn/user/preferences.php
preferences.has
public function has(string $id_option = null, bool $force = false): bool { if ( !$force && $this->user->is_dev() ){ return true; } return (bool)$this->retrieve_ids($id_option); }
php
public function has(string $id_option = null, bool $force = false): bool { if ( !$force && $this->user->is_dev() ){ return true; } return (bool)$this->retrieve_ids($id_option); }
[ "public", "function", "has", "(", "string", "$", "id_option", "=", "null", ",", "bool", "$", "force", "=", "false", ")", ":", "bool", "{", "if", "(", "!", "$", "force", "&&", "$", "this", "->", "user", "->", "is_dev", "(", ")", ")", "{", "return", "true", ";", "}", "return", "(", "bool", ")", "$", "this", "->", "retrieve_ids", "(", "$", "id_option", ")", ";", "}" ]
Returns true if the current user can access a preference, false otherwise @param string|null $id_option @param bool $force @return bool
[ "Returns", "true", "if", "the", "current", "user", "can", "access", "a", "preference", "false", "otherwise" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L298-L304
22,254
nabab/bbn
src/bbn/user/preferences.php
preferences.user_has
public function user_has(string $id_option, string $id_user): bool { return (bool)$this->_retrieve_ids($id_option, $id_user); }
php
public function user_has(string $id_option, string $id_user): bool { return (bool)$this->_retrieve_ids($id_option, $id_user); }
[ "public", "function", "user_has", "(", "string", "$", "id_option", ",", "string", "$", "id_user", ")", ":", "bool", "{", "return", "(", "bool", ")", "$", "this", "->", "_retrieve_ids", "(", "$", "id_option", ",", "$", "id_user", ")", ";", "}" ]
Checks if a user has the given preference @param string $id_option @param string $id_user @return bool
[ "Checks", "if", "a", "user", "has", "the", "given", "preference" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L313-L316
22,255
nabab/bbn
src/bbn/user/preferences.php
preferences.group_has
public function group_has(string $id_option, string $id_group): bool { return (bool)$this->_retrieve_ids($id_option, null, $id_group); }
php
public function group_has(string $id_option, string $id_group): bool { return (bool)$this->_retrieve_ids($id_option, null, $id_group); }
[ "public", "function", "group_has", "(", "string", "$", "id_option", ",", "string", "$", "id_group", ")", ":", "bool", "{", "return", "(", "bool", ")", "$", "this", "->", "_retrieve_ids", "(", "$", "id_option", ",", "null", ",", "$", "id_group", ")", ";", "}" ]
Checks if a group has the given preference @param string $id_option @param string $id_group @return bool
[ "Checks", "if", "a", "group", "has", "the", "given", "preference" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L325-L328
22,256
nabab/bbn
src/bbn/user/preferences.php
preferences.get
public function get(string $id, bool $with_config = true): ?array { if ( bbn\str::is_uid($id) ){ $cols = implode(', ', array_map(function($a){ return $a; }, $this->fields)); $table = $this->db->tsn($this->class_cfg['table'], true); $uid = $this->db->csn($this->fields['id'], true); $id_user = $this->db->csn($this->fields['id_user'], true); $id_group = $this->db->csn($this->fields['id_group'], true); $public = $this->db->csn($this->fields['public'], true); $sql = <<< MYSQL SELECT $cols FROM $table WHERE $uid = UNHEX(?) AND ($id_user = UNHEX(?) OR $id_group = UNHEX(?) OR $public = 1) MYSQL; if ( $row = $this->db->get_row($sql, $id, $this->id_user, $this->id_group) ){ $cfg = $row['cfg']; unset($row['cfg']); if ( ($cfg = json_decode($cfg, true)) && $with_config ){ $row = bbn\x::merge_arrays($cfg, $row); } return $row; } } return null; }
php
public function get(string $id, bool $with_config = true): ?array { if ( bbn\str::is_uid($id) ){ $cols = implode(', ', array_map(function($a){ return $a; }, $this->fields)); $table = $this->db->tsn($this->class_cfg['table'], true); $uid = $this->db->csn($this->fields['id'], true); $id_user = $this->db->csn($this->fields['id_user'], true); $id_group = $this->db->csn($this->fields['id_group'], true); $public = $this->db->csn($this->fields['public'], true); $sql = <<< MYSQL SELECT $cols FROM $table WHERE $uid = UNHEX(?) AND ($id_user = UNHEX(?) OR $id_group = UNHEX(?) OR $public = 1) MYSQL; if ( $row = $this->db->get_row($sql, $id, $this->id_user, $this->id_group) ){ $cfg = $row['cfg']; unset($row['cfg']); if ( ($cfg = json_decode($cfg, true)) && $with_config ){ $row = bbn\x::merge_arrays($cfg, $row); } return $row; } } return null; }
[ "public", "function", "get", "(", "string", "$", "id", ",", "bool", "$", "with_config", "=", "true", ")", ":", "?", "array", "{", "if", "(", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", ")", "{", "$", "cols", "=", "implode", "(", "', '", ",", "array_map", "(", "function", "(", "$", "a", ")", "{", "return", "$", "a", ";", "}", ",", "$", "this", "->", "fields", ")", ")", ";", "$", "table", "=", "$", "this", "->", "db", "->", "tsn", "(", "$", "this", "->", "class_cfg", "[", "'table'", "]", ",", "true", ")", ";", "$", "uid", "=", "$", "this", "->", "db", "->", "csn", "(", "$", "this", "->", "fields", "[", "'id'", "]", ",", "true", ")", ";", "$", "id_user", "=", "$", "this", "->", "db", "->", "csn", "(", "$", "this", "->", "fields", "[", "'id_user'", "]", ",", "true", ")", ";", "$", "id_group", "=", "$", "this", "->", "db", "->", "csn", "(", "$", "this", "->", "fields", "[", "'id_group'", "]", ",", "true", ")", ";", "$", "public", "=", "$", "this", "->", "db", "->", "csn", "(", "$", "this", "->", "fields", "[", "'public'", "]", ",", "true", ")", ";", "$", "sql", "=", " <<< MYSQL\nSELECT $cols\nFROM $table\nWHERE $uid = UNHEX(?)\nAND ($id_user = UNHEX(?)\nOR $id_group = UNHEX(?)\nOR $public = 1)\nMYSQL", ";", "if", "(", "$", "row", "=", "$", "this", "->", "db", "->", "get_row", "(", "$", "sql", ",", "$", "id", ",", "$", "this", "->", "id_user", ",", "$", "this", "->", "id_group", ")", ")", "{", "$", "cfg", "=", "$", "row", "[", "'cfg'", "]", ";", "unset", "(", "$", "row", "[", "'cfg'", "]", ")", ";", "if", "(", "(", "$", "cfg", "=", "json_decode", "(", "$", "cfg", ",", "true", ")", ")", "&&", "$", "with_config", ")", "{", "$", "row", "=", "bbn", "\\", "x", "::", "merge_arrays", "(", "$", "cfg", ",", "$", "row", ")", ";", "}", "return", "$", "row", ";", "}", "}", "return", "null", ";", "}" ]
Returns the current user's preference based on the given id, his own profile and his group's @param string $id @param bool $with_config @return array|null
[ "Returns", "the", "current", "user", "s", "preference", "based", "on", "the", "given", "id", "his", "own", "profile", "and", "his", "group", "s" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L433-L462
22,257
nabab/bbn
src/bbn/user/preferences.php
preferences.get_all
public function get_all(string $id_option = null, bool $with_config = true): ?array { if ( $id_option = $this->_get_id_option($id_option) ){ $fields = $this->fields; if ( !$with_config ){ unset($fields['cfg']); } $table = $this->db->tsn($this->class_table, true); $cols = implode(', ', array_map(function($a) use($table){ return $a === $this->fields['id'] ? "$table.$a" : "IFNULL(aliases.$a, $table.$a) AS $a"; }, $fields)); $id_opt = $this->db->cfn($this->fields['id_option'], $this->class_table, true); $id_user = $this->db->cfn($this->fields['id_user'], $this->class_table, true); $id_group = $this->db->cfn($this->fields['id_group'], $this->class_table, true); $num = $this->db->cfn($this->fields['num'], $this->class_table, true); $text = $this->db->cfn($this->fields['text'], $this->class_table, true); $id_alias = $this->db->cfn($this->fields['id_alias'], $this->class_table, true); $public = $this->db->cfn($this->fields['public'], $this->class_table, true); $sql = <<< MYSQL SELECT $cols FROM $table LEFT JOIN $table as aliases ON aliases.id = $id_alias WHERE $id_opt = UNHEX(?) AND ($id_user = UNHEX(?) OR $id_group = UNHEX(?) OR $public = 1) ORDER BY IFNULL($num, $text) MYSQL; if ( $rows = $this->db->get_rows($sql, $id_option, $this->id_user, $this->id_group) ){ return $with_config ? array_map(function($a){ $cfg = $a['cfg']; unset($a['cfg']); if ( ($cfg = json_decode($cfg, true)) ){ $a = bbn\x::merge_arrays($cfg, $a); } return $a; }, $rows) : $rows; } return []; } return null; }
php
public function get_all(string $id_option = null, bool $with_config = true): ?array { if ( $id_option = $this->_get_id_option($id_option) ){ $fields = $this->fields; if ( !$with_config ){ unset($fields['cfg']); } $table = $this->db->tsn($this->class_table, true); $cols = implode(', ', array_map(function($a) use($table){ return $a === $this->fields['id'] ? "$table.$a" : "IFNULL(aliases.$a, $table.$a) AS $a"; }, $fields)); $id_opt = $this->db->cfn($this->fields['id_option'], $this->class_table, true); $id_user = $this->db->cfn($this->fields['id_user'], $this->class_table, true); $id_group = $this->db->cfn($this->fields['id_group'], $this->class_table, true); $num = $this->db->cfn($this->fields['num'], $this->class_table, true); $text = $this->db->cfn($this->fields['text'], $this->class_table, true); $id_alias = $this->db->cfn($this->fields['id_alias'], $this->class_table, true); $public = $this->db->cfn($this->fields['public'], $this->class_table, true); $sql = <<< MYSQL SELECT $cols FROM $table LEFT JOIN $table as aliases ON aliases.id = $id_alias WHERE $id_opt = UNHEX(?) AND ($id_user = UNHEX(?) OR $id_group = UNHEX(?) OR $public = 1) ORDER BY IFNULL($num, $text) MYSQL; if ( $rows = $this->db->get_rows($sql, $id_option, $this->id_user, $this->id_group) ){ return $with_config ? array_map(function($a){ $cfg = $a['cfg']; unset($a['cfg']); if ( ($cfg = json_decode($cfg, true)) ){ $a = bbn\x::merge_arrays($cfg, $a); } return $a; }, $rows) : $rows; } return []; } return null; }
[ "public", "function", "get_all", "(", "string", "$", "id_option", "=", "null", ",", "bool", "$", "with_config", "=", "true", ")", ":", "?", "array", "{", "if", "(", "$", "id_option", "=", "$", "this", "->", "_get_id_option", "(", "$", "id_option", ")", ")", "{", "$", "fields", "=", "$", "this", "->", "fields", ";", "if", "(", "!", "$", "with_config", ")", "{", "unset", "(", "$", "fields", "[", "'cfg'", "]", ")", ";", "}", "$", "table", "=", "$", "this", "->", "db", "->", "tsn", "(", "$", "this", "->", "class_table", ",", "true", ")", ";", "$", "cols", "=", "implode", "(", "', '", ",", "array_map", "(", "function", "(", "$", "a", ")", "use", "(", "$", "table", ")", "{", "return", "$", "a", "===", "$", "this", "->", "fields", "[", "'id'", "]", "?", "\"$table.$a\"", ":", "\"IFNULL(aliases.$a, $table.$a) AS $a\"", ";", "}", ",", "$", "fields", ")", ")", ";", "$", "id_opt", "=", "$", "this", "->", "db", "->", "cfn", "(", "$", "this", "->", "fields", "[", "'id_option'", "]", ",", "$", "this", "->", "class_table", ",", "true", ")", ";", "$", "id_user", "=", "$", "this", "->", "db", "->", "cfn", "(", "$", "this", "->", "fields", "[", "'id_user'", "]", ",", "$", "this", "->", "class_table", ",", "true", ")", ";", "$", "id_group", "=", "$", "this", "->", "db", "->", "cfn", "(", "$", "this", "->", "fields", "[", "'id_group'", "]", ",", "$", "this", "->", "class_table", ",", "true", ")", ";", "$", "num", "=", "$", "this", "->", "db", "->", "cfn", "(", "$", "this", "->", "fields", "[", "'num'", "]", ",", "$", "this", "->", "class_table", ",", "true", ")", ";", "$", "text", "=", "$", "this", "->", "db", "->", "cfn", "(", "$", "this", "->", "fields", "[", "'text'", "]", ",", "$", "this", "->", "class_table", ",", "true", ")", ";", "$", "id_alias", "=", "$", "this", "->", "db", "->", "cfn", "(", "$", "this", "->", "fields", "[", "'id_alias'", "]", ",", "$", "this", "->", "class_table", ",", "true", ")", ";", "$", "public", "=", "$", "this", "->", "db", "->", "cfn", "(", "$", "this", "->", "fields", "[", "'public'", "]", ",", "$", "this", "->", "class_table", ",", "true", ")", ";", "$", "sql", "=", " <<< MYSQL\nSELECT $cols\nFROM $table\n LEFT JOIN $table as aliases\n ON aliases.id = $id_alias\nWHERE $id_opt = UNHEX(?)\nAND ($id_user = UNHEX(?)\nOR $id_group = UNHEX(?)\nOR $public = 1)\nORDER BY IFNULL($num, $text)\nMYSQL", ";", "if", "(", "$", "rows", "=", "$", "this", "->", "db", "->", "get_rows", "(", "$", "sql", ",", "$", "id_option", ",", "$", "this", "->", "id_user", ",", "$", "this", "->", "id_group", ")", ")", "{", "return", "$", "with_config", "?", "array_map", "(", "function", "(", "$", "a", ")", "{", "$", "cfg", "=", "$", "a", "[", "'cfg'", "]", ";", "unset", "(", "$", "a", "[", "'cfg'", "]", ")", ";", "if", "(", "(", "$", "cfg", "=", "json_decode", "(", "$", "cfg", ",", "true", ")", ")", ")", "{", "$", "a", "=", "bbn", "\\", "x", "::", "merge_arrays", "(", "$", "cfg", ",", "$", "a", ")", ";", "}", "return", "$", "a", ";", "}", ",", "$", "rows", ")", ":", "$", "rows", ";", "}", "return", "[", "]", ";", "}", "return", "null", ";", "}" ]
Returns an array of the current user's preferences based on the given id_option, his own profile and his group's @param null|string $id_option @param bool $with_config @return array|null
[ "Returns", "an", "array", "of", "the", "current", "user", "s", "preferences", "based", "on", "the", "given", "id_option", "his", "own", "profile", "and", "his", "group", "s" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L470-L513
22,258
nabab/bbn
src/bbn/user/preferences.php
preferences.set_by_option
public function set_by_option(string $id_option, array $cfg): int { if ( $id = $this->retrieve_user_ids($id_option, $this->id_user) ){ return $this->set($id[0], $cfg); } return $this->_insert($id_option, $cfg); }
php
public function set_by_option(string $id_option, array $cfg): int { if ( $id = $this->retrieve_user_ids($id_option, $this->id_user) ){ return $this->set($id[0], $cfg); } return $this->_insert($id_option, $cfg); }
[ "public", "function", "set_by_option", "(", "string", "$", "id_option", ",", "array", "$", "cfg", ")", ":", "int", "{", "if", "(", "$", "id", "=", "$", "this", "->", "retrieve_user_ids", "(", "$", "id_option", ",", "$", "this", "->", "id_user", ")", ")", "{", "return", "$", "this", "->", "set", "(", "$", "id", "[", "0", "]", ",", "$", "cfg", ")", ";", "}", "return", "$", "this", "->", "_insert", "(", "$", "id_option", ",", "$", "cfg", ")", ";", "}" ]
Sets the permission row for the current user by the option's ID @param string $id_option @param array $cfg @return int
[ "Sets", "the", "permission", "row", "for", "the", "current", "user", "by", "the", "option", "s", "ID" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L643-L649
22,259
nabab/bbn
src/bbn/user/preferences.php
preferences.set
public function set(string $id, array $cfg = null): int { return $this->db->update($this->class_cfg['table'], [ $this->fields['cfg'] => $cfg ? json_encode($this->get_cfg(false, $cfg)) : null ], [ $this->fields['id'] => $id ]); }
php
public function set(string $id, array $cfg = null): int { return $this->db->update($this->class_cfg['table'], [ $this->fields['cfg'] => $cfg ? json_encode($this->get_cfg(false, $cfg)) : null ], [ $this->fields['id'] => $id ]); }
[ "public", "function", "set", "(", "string", "$", "id", ",", "array", "$", "cfg", "=", "null", ")", ":", "int", "{", "return", "$", "this", "->", "db", "->", "update", "(", "$", "this", "->", "class_cfg", "[", "'table'", "]", ",", "[", "$", "this", "->", "fields", "[", "'cfg'", "]", "=>", "$", "cfg", "?", "json_encode", "(", "$", "this", "->", "get_cfg", "(", "false", ",", "$", "cfg", ")", ")", ":", "null", "]", ",", "[", "$", "this", "->", "fields", "[", "'id'", "]", "=>", "$", "id", "]", ")", ";", "}" ]
Sets the permission config for the current user by the preference's ID @param string $id @param array $cfg @return int
[ "Sets", "the", "permission", "config", "for", "the", "current", "user", "by", "the", "preference", "s", "ID" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L658-L665
22,260
nabab/bbn
src/bbn/user/preferences.php
preferences.update
public function update(string $id, array $cfg): int { return $this->db->update($this->class_cfg['table'], [ $this->fields['text'] => $cfg[$this->fields['text']] ?? NULL, $this->fields['num'] => $cfg[$this->fields['num']] ?? NULL, $this->fields['id_link'] => $cfg[$this->fields['id_link']] ?? NULL, $this->fields['id_alias'] => $cfg[$this->fields['id_alias']] ?? NULL, $this->fields['id_user'] => $this->id_user, $this->fields['cfg'] => ($mp = $this->get_cfg(false, $cfg)) ? json_encode($tmp) : NULL ], [ $this->fields['id'] => $id ]); }
php
public function update(string $id, array $cfg): int { return $this->db->update($this->class_cfg['table'], [ $this->fields['text'] => $cfg[$this->fields['text']] ?? NULL, $this->fields['num'] => $cfg[$this->fields['num']] ?? NULL, $this->fields['id_link'] => $cfg[$this->fields['id_link']] ?? NULL, $this->fields['id_alias'] => $cfg[$this->fields['id_alias']] ?? NULL, $this->fields['id_user'] => $this->id_user, $this->fields['cfg'] => ($mp = $this->get_cfg(false, $cfg)) ? json_encode($tmp) : NULL ], [ $this->fields['id'] => $id ]); }
[ "public", "function", "update", "(", "string", "$", "id", ",", "array", "$", "cfg", ")", ":", "int", "{", "return", "$", "this", "->", "db", "->", "update", "(", "$", "this", "->", "class_cfg", "[", "'table'", "]", ",", "[", "$", "this", "->", "fields", "[", "'text'", "]", "=>", "$", "cfg", "[", "$", "this", "->", "fields", "[", "'text'", "]", "]", "??", "NULL", ",", "$", "this", "->", "fields", "[", "'num'", "]", "=>", "$", "cfg", "[", "$", "this", "->", "fields", "[", "'num'", "]", "]", "??", "NULL", ",", "$", "this", "->", "fields", "[", "'id_link'", "]", "=>", "$", "cfg", "[", "$", "this", "->", "fields", "[", "'id_link'", "]", "]", "??", "NULL", ",", "$", "this", "->", "fields", "[", "'id_alias'", "]", "=>", "$", "cfg", "[", "$", "this", "->", "fields", "[", "'id_alias'", "]", "]", "??", "NULL", ",", "$", "this", "->", "fields", "[", "'id_user'", "]", "=>", "$", "this", "->", "id_user", ",", "$", "this", "->", "fields", "[", "'cfg'", "]", "=>", "(", "$", "mp", "=", "$", "this", "->", "get_cfg", "(", "false", ",", "$", "cfg", ")", ")", "?", "json_encode", "(", "$", "tmp", ")", ":", "NULL", "]", ",", "[", "$", "this", "->", "fields", "[", "'id'", "]", "=>", "$", "id", "]", ")", ";", "}" ]
Sets the permission row for the current user by the preference's ID @param string $id @param array $cfg @return int
[ "Sets", "the", "permission", "row", "for", "the", "current", "user", "by", "the", "preference", "s", "ID" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L674-L686
22,261
nabab/bbn
src/bbn/user/preferences.php
preferences.add
public function add(string $id_option = null, array $cfg): ?string { return ( ($id_option = $this->_get_id_option($id_option)) && $this->_insert($id_option, $cfg) ) ? $this->db->last_id() : null; }
php
public function add(string $id_option = null, array $cfg): ?string { return ( ($id_option = $this->_get_id_option($id_option)) && $this->_insert($id_option, $cfg) ) ? $this->db->last_id() : null; }
[ "public", "function", "add", "(", "string", "$", "id_option", "=", "null", ",", "array", "$", "cfg", ")", ":", "?", "string", "{", "return", "(", "(", "$", "id_option", "=", "$", "this", "->", "_get_id_option", "(", "$", "id_option", ")", ")", "&&", "$", "this", "->", "_insert", "(", "$", "id_option", ",", "$", "cfg", ")", ")", "?", "$", "this", "->", "db", "->", "last_id", "(", ")", ":", "null", ";", "}" ]
Adds a new preference for the given option for the current user. @param null|string $id_option @param array $cfg @return null|string
[ "Adds", "a", "new", "preference", "for", "the", "given", "option", "for", "the", "current", "user", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L703-L709
22,262
nabab/bbn
src/bbn/user/preferences.php
preferences.delete
public function delete($id): ?int { return $this->db->delete($this->class_cfg['table'], [$this->fields['id'] => $id]); }
php
public function delete($id): ?int { return $this->db->delete($this->class_cfg['table'], [$this->fields['id'] => $id]); }
[ "public", "function", "delete", "(", "$", "id", ")", ":", "?", "int", "{", "return", "$", "this", "->", "db", "->", "delete", "(", "$", "this", "->", "class_cfg", "[", "'table'", "]", ",", "[", "$", "this", "->", "fields", "[", "'id'", "]", "=>", "$", "id", "]", ")", ";", "}" ]
Deletes the given permission @param $id @return int|null
[ "Deletes", "the", "given", "permission" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L717-L720
22,263
nabab/bbn
src/bbn/user/preferences.php
preferences.delete_user_option
public function delete_user_option(string $id_option, string $id_user = null): ?int { if ( $id_option = $this->_get_id_option($id_option) ){ return $this->db->delete($this->class_cfg['table'], [ $this->fields['id_option'] => $id_option, $this->fields['id_user'] => $id_user ?: $this->id_user ]); } return null; }
php
public function delete_user_option(string $id_option, string $id_user = null): ?int { if ( $id_option = $this->_get_id_option($id_option) ){ return $this->db->delete($this->class_cfg['table'], [ $this->fields['id_option'] => $id_option, $this->fields['id_user'] => $id_user ?: $this->id_user ]); } return null; }
[ "public", "function", "delete_user_option", "(", "string", "$", "id_option", ",", "string", "$", "id_user", "=", "null", ")", ":", "?", "int", "{", "if", "(", "$", "id_option", "=", "$", "this", "->", "_get_id_option", "(", "$", "id_option", ")", ")", "{", "return", "$", "this", "->", "db", "->", "delete", "(", "$", "this", "->", "class_cfg", "[", "'table'", "]", ",", "[", "$", "this", "->", "fields", "[", "'id_option'", "]", "=>", "$", "id_option", ",", "$", "this", "->", "fields", "[", "'id_user'", "]", "=>", "$", "id_user", "?", ":", "$", "this", "->", "id_user", "]", ")", ";", "}", "return", "null", ";", "}" ]
Deletes all the given or current user's permissions for the given option @param null|string $id_option @param null|string $id_user @return null|int
[ "Deletes", "all", "the", "given", "or", "current", "user", "s", "permissions", "for", "the", "given", "option" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L729-L738
22,264
nabab/bbn
src/bbn/user/preferences.php
preferences.delete_group_option
public function delete_group_option(string $id_option, string $id_group): ?int { if ( $id_option = $this->_get_id_option($id_option) ){ return $this->db->delete($this->class_cfg['table'], [ $this->fields['id_option'] => $id_option, $this->fields['id_group'] => $id_group ]); } return null; }
php
public function delete_group_option(string $id_option, string $id_group): ?int { if ( $id_option = $this->_get_id_option($id_option) ){ return $this->db->delete($this->class_cfg['table'], [ $this->fields['id_option'] => $id_option, $this->fields['id_group'] => $id_group ]); } return null; }
[ "public", "function", "delete_group_option", "(", "string", "$", "id_option", ",", "string", "$", "id_group", ")", ":", "?", "int", "{", "if", "(", "$", "id_option", "=", "$", "this", "->", "_get_id_option", "(", "$", "id_option", ")", ")", "{", "return", "$", "this", "->", "db", "->", "delete", "(", "$", "this", "->", "class_cfg", "[", "'table'", "]", ",", "[", "$", "this", "->", "fields", "[", "'id_option'", "]", "=>", "$", "id_option", ",", "$", "this", "->", "fields", "[", "'id_group'", "]", "=>", "$", "id_group", "]", ")", ";", "}", "return", "null", ";", "}" ]
Deletes all the given group's permissions for the given option @param null|string $id_option @param string $id_group @return int|null
[ "Deletes", "all", "the", "given", "group", "s", "permissions", "for", "the", "given", "option" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L747-L756
22,265
nabab/bbn
src/bbn/user/preferences.php
preferences.get_shared
public function get_shared(string $id): ?array { if ( bbn\str::is_uid($id) ){ return $this->db->rselect_all($this->class_table, [ $this->fields['id'], $this->fields['id_user'], $this->fields['id_group'] ], [ $this->fields['id_alias'] => $id ]); } return null; }
php
public function get_shared(string $id): ?array { if ( bbn\str::is_uid($id) ){ return $this->db->rselect_all($this->class_table, [ $this->fields['id'], $this->fields['id_user'], $this->fields['id_group'] ], [ $this->fields['id_alias'] => $id ]); } return null; }
[ "public", "function", "get_shared", "(", "string", "$", "id", ")", ":", "?", "array", "{", "if", "(", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", ")", "{", "return", "$", "this", "->", "db", "->", "rselect_all", "(", "$", "this", "->", "class_table", ",", "[", "$", "this", "->", "fields", "[", "'id'", "]", ",", "$", "this", "->", "fields", "[", "'id_user'", "]", ",", "$", "this", "->", "fields", "[", "'id_group'", "]", "]", ",", "[", "$", "this", "->", "fields", "[", "'id_alias'", "]", "=>", "$", "id", "]", ")", ";", "}", "return", "null", ";", "}" ]
Returns an array @param string $id @return array|null
[ "Returns", "an", "array" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L849-L861
22,266
nabab/bbn
src/bbn/user/preferences.php
preferences.add_bit
public function add_bit(string $id_usr_opt, array $cfg): ?string { if ( ($id_usr_opt = $this->_get_id_option($id_usr_opt)) && ($c = $this->class_cfg['arch']['user_options_bits']) ){ $to_cfg = $this->get_bit_cfg(null, $cfg); if ( isset($to_cfg['items']) ){ unset($to_cfg['items']); } if ( !empty($to_cfg) ){ if ( !empty($cfg[$c['cfg']]) ){ if ( \bbn\str::is_json($cfg[$c['cfg']]) ){ $cfg[$c['cfg']] = json_decode($cfg[$c['cfg']], true); } if ( \is_array($cfg[$c['cfg']]) ){ $cfg[$c['cfg']] = array_merge($cfg[$c['cfg']], $to_cfg); } else { $cfg[$c['cfg']] = $to_cfg; } } else { $cfg[$c['cfg']] = $to_cfg; } $cfg[$c['cfg']] = json_encode($cfg[$c['cfg']]); } if ( $this->db->insert($this->class_cfg['tables']['user_options_bits'], [ $c['id_user_option'] => $id_usr_opt, $c['id_parent'] => $cfg[$c['id_parent']] ?? NULL, $c['id_option'] => $cfg[$c['id_option']] ?? NULL, $c['num'] => $cfg[$c['num']] ?? NULL, $c['text'] => $cfg[$c['text']] ?? '', $c['cfg'] => $cfg[$c['cfg']] ?? '', ]) ){ return $this->db->last_id(); } } return null; }
php
public function add_bit(string $id_usr_opt, array $cfg): ?string { if ( ($id_usr_opt = $this->_get_id_option($id_usr_opt)) && ($c = $this->class_cfg['arch']['user_options_bits']) ){ $to_cfg = $this->get_bit_cfg(null, $cfg); if ( isset($to_cfg['items']) ){ unset($to_cfg['items']); } if ( !empty($to_cfg) ){ if ( !empty($cfg[$c['cfg']]) ){ if ( \bbn\str::is_json($cfg[$c['cfg']]) ){ $cfg[$c['cfg']] = json_decode($cfg[$c['cfg']], true); } if ( \is_array($cfg[$c['cfg']]) ){ $cfg[$c['cfg']] = array_merge($cfg[$c['cfg']], $to_cfg); } else { $cfg[$c['cfg']] = $to_cfg; } } else { $cfg[$c['cfg']] = $to_cfg; } $cfg[$c['cfg']] = json_encode($cfg[$c['cfg']]); } if ( $this->db->insert($this->class_cfg['tables']['user_options_bits'], [ $c['id_user_option'] => $id_usr_opt, $c['id_parent'] => $cfg[$c['id_parent']] ?? NULL, $c['id_option'] => $cfg[$c['id_option']] ?? NULL, $c['num'] => $cfg[$c['num']] ?? NULL, $c['text'] => $cfg[$c['text']] ?? '', $c['cfg'] => $cfg[$c['cfg']] ?? '', ]) ){ return $this->db->last_id(); } } return null; }
[ "public", "function", "add_bit", "(", "string", "$", "id_usr_opt", ",", "array", "$", "cfg", ")", ":", "?", "string", "{", "if", "(", "(", "$", "id_usr_opt", "=", "$", "this", "->", "_get_id_option", "(", "$", "id_usr_opt", ")", ")", "&&", "(", "$", "c", "=", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options_bits'", "]", ")", ")", "{", "$", "to_cfg", "=", "$", "this", "->", "get_bit_cfg", "(", "null", ",", "$", "cfg", ")", ";", "if", "(", "isset", "(", "$", "to_cfg", "[", "'items'", "]", ")", ")", "{", "unset", "(", "$", "to_cfg", "[", "'items'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "to_cfg", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ")", ")", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_json", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ")", ")", "{", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "json_decode", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ",", "true", ")", ";", "}", "if", "(", "\\", "is_array", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ")", ")", "{", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "array_merge", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ",", "$", "to_cfg", ")", ";", "}", "else", "{", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "$", "to_cfg", ";", "}", "}", "else", "{", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "$", "to_cfg", ";", "}", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "json_encode", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ")", ";", "}", "if", "(", "$", "this", "->", "db", "->", "insert", "(", "$", "this", "->", "class_cfg", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "[", "$", "c", "[", "'id_user_option'", "]", "=>", "$", "id_usr_opt", ",", "$", "c", "[", "'id_parent'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'id_parent'", "]", "]", "??", "NULL", ",", "$", "c", "[", "'id_option'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'id_option'", "]", "]", "??", "NULL", ",", "$", "c", "[", "'num'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'num'", "]", "]", "??", "NULL", ",", "$", "c", "[", "'text'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'text'", "]", "]", "??", "''", ",", "$", "c", "[", "'cfg'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "??", "''", ",", "]", ")", ")", "{", "return", "$", "this", "->", "db", "->", "last_id", "(", ")", ";", "}", "}", "return", "null", ";", "}" ]
Adds a bit to a preference @param string $id_usr_opt The preference's ID @param array $cfg The bit's values @return string|null
[ "Adds", "a", "bit", "to", "a", "preference" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L948-L987
22,267
nabab/bbn
src/bbn/user/preferences.php
preferences.delete_bit
public function delete_bit(string $id): ?int { if ( \bbn\str::is_uid($id) ){ return $this->db->delete($this->class_cfg['tables']['user_options_bits'], [ $this->class_cfg['arch']['user_options_bits']['id'] => $id ]); } return null; }
php
public function delete_bit(string $id): ?int { if ( \bbn\str::is_uid($id) ){ return $this->db->delete($this->class_cfg['tables']['user_options_bits'], [ $this->class_cfg['arch']['user_options_bits']['id'] => $id ]); } return null; }
[ "public", "function", "delete_bit", "(", "string", "$", "id", ")", ":", "?", "int", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", ")", "{", "return", "$", "this", "->", "db", "->", "delete", "(", "$", "this", "->", "class_cfg", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "[", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options_bits'", "]", "[", "'id'", "]", "=>", "$", "id", "]", ")", ";", "}", "return", "null", ";", "}" ]
Deletes a preference's bit @param string The bit's ID @return int|null
[ "Deletes", "a", "preference", "s", "bit" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L996-L1004
22,268
nabab/bbn
src/bbn/user/preferences.php
preferences.update_bit
public function update_bit(string $id, array $cfg, $merge_config = false): ?int { if ( \bbn\str::is_uid($id) ){ $c = $this->class_cfg['arch']['user_options_bits']; $fields = array_values($c); if ( \array_key_exists($c['id'], $cfg) ){ unset($cfg[$c['id']]); } $to_cfg = $this->get_bit_cfg(null, $cfg); if ( isset($to_cfg['items']) ){ unset($to_cfg['items']); } if ( !empty($to_cfg) ){ if ( !empty($merge_config) && !empty($cfg[$c['cfg']]) ){ if ( \bbn\str::is_json($cfg[$c['cfg']]) ){ $cfg[$c['cfg']] = json_decode($cfg[$c['cfg']], true); } if ( \is_array($cfg[$c['cfg']]) ){ $cfg[$c['cfg']] = array_merge($cfg[$c['cfg']], $to_cfg); } else { $cfg[$c['cfg']] = $to_cfg; } } else { $cfg[$c['cfg']] = $to_cfg; } $cfg[$c['cfg']] = json_encode($cfg[$c['cfg']]); } return $this->db->update($this->class_cfg['tables']['user_options_bits'], [ $c['id_parent'] => $cfg[$c['id_parent']] ?? NULL, $c['id_option'] => $cfg[$c['id_option']] ?? NULL, $c['num'] => $cfg[$c['num']] ?? NULL, $c['text'] => $cfg[$c['text']] ?? '', $c['cfg'] => $cfg[$c['cfg']] ?? '', ], [ $c['id'] => $id ]); } return null; }
php
public function update_bit(string $id, array $cfg, $merge_config = false): ?int { if ( \bbn\str::is_uid($id) ){ $c = $this->class_cfg['arch']['user_options_bits']; $fields = array_values($c); if ( \array_key_exists($c['id'], $cfg) ){ unset($cfg[$c['id']]); } $to_cfg = $this->get_bit_cfg(null, $cfg); if ( isset($to_cfg['items']) ){ unset($to_cfg['items']); } if ( !empty($to_cfg) ){ if ( !empty($merge_config) && !empty($cfg[$c['cfg']]) ){ if ( \bbn\str::is_json($cfg[$c['cfg']]) ){ $cfg[$c['cfg']] = json_decode($cfg[$c['cfg']], true); } if ( \is_array($cfg[$c['cfg']]) ){ $cfg[$c['cfg']] = array_merge($cfg[$c['cfg']], $to_cfg); } else { $cfg[$c['cfg']] = $to_cfg; } } else { $cfg[$c['cfg']] = $to_cfg; } $cfg[$c['cfg']] = json_encode($cfg[$c['cfg']]); } return $this->db->update($this->class_cfg['tables']['user_options_bits'], [ $c['id_parent'] => $cfg[$c['id_parent']] ?? NULL, $c['id_option'] => $cfg[$c['id_option']] ?? NULL, $c['num'] => $cfg[$c['num']] ?? NULL, $c['text'] => $cfg[$c['text']] ?? '', $c['cfg'] => $cfg[$c['cfg']] ?? '', ], [ $c['id'] => $id ]); } return null; }
[ "public", "function", "update_bit", "(", "string", "$", "id", ",", "array", "$", "cfg", ",", "$", "merge_config", "=", "false", ")", ":", "?", "int", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", ")", "{", "$", "c", "=", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options_bits'", "]", ";", "$", "fields", "=", "array_values", "(", "$", "c", ")", ";", "if", "(", "\\", "array_key_exists", "(", "$", "c", "[", "'id'", "]", ",", "$", "cfg", ")", ")", "{", "unset", "(", "$", "cfg", "[", "$", "c", "[", "'id'", "]", "]", ")", ";", "}", "$", "to_cfg", "=", "$", "this", "->", "get_bit_cfg", "(", "null", ",", "$", "cfg", ")", ";", "if", "(", "isset", "(", "$", "to_cfg", "[", "'items'", "]", ")", ")", "{", "unset", "(", "$", "to_cfg", "[", "'items'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "to_cfg", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "merge_config", ")", "&&", "!", "empty", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ")", ")", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_json", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ")", ")", "{", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "json_decode", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ",", "true", ")", ";", "}", "if", "(", "\\", "is_array", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ")", ")", "{", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "array_merge", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ",", "$", "to_cfg", ")", ";", "}", "else", "{", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "$", "to_cfg", ";", "}", "}", "else", "{", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "$", "to_cfg", ";", "}", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "=", "json_encode", "(", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", ")", ";", "}", "return", "$", "this", "->", "db", "->", "update", "(", "$", "this", "->", "class_cfg", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "[", "$", "c", "[", "'id_parent'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'id_parent'", "]", "]", "??", "NULL", ",", "$", "c", "[", "'id_option'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'id_option'", "]", "]", "??", "NULL", ",", "$", "c", "[", "'num'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'num'", "]", "]", "??", "NULL", ",", "$", "c", "[", "'text'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'text'", "]", "]", "??", "''", ",", "$", "c", "[", "'cfg'", "]", "=>", "$", "cfg", "[", "$", "c", "[", "'cfg'", "]", "]", "??", "''", ",", "]", ",", "[", "$", "c", "[", "'id'", "]", "=>", "$", "id", "]", ")", ";", "}", "return", "null", ";", "}" ]
Updates a preference's bit @param string $id The bit's ID @param array The bit's values @return int|null
[ "Updates", "a", "preference", "s", "bit" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1013-L1053
22,269
nabab/bbn
src/bbn/user/preferences.php
preferences.get_bit
public function get_bit(string $id, bool $with_config = true): array { if ( \bbn\str::is_uid($id) && ($bit = $this->db->rselect($this->class_cfg['tables']['user_options_bits'], [], [ $this->class_cfg['arch']['user_options_bits']['id'] => $id ])) ){ if ( !empty($with_config) ){ return $this->explode_bit_cfg($bit); } return $bit; } return []; }
php
public function get_bit(string $id, bool $with_config = true): array { if ( \bbn\str::is_uid($id) && ($bit = $this->db->rselect($this->class_cfg['tables']['user_options_bits'], [], [ $this->class_cfg['arch']['user_options_bits']['id'] => $id ])) ){ if ( !empty($with_config) ){ return $this->explode_bit_cfg($bit); } return $bit; } return []; }
[ "public", "function", "get_bit", "(", "string", "$", "id", ",", "bool", "$", "with_config", "=", "true", ")", ":", "array", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", "&&", "(", "$", "bit", "=", "$", "this", "->", "db", "->", "rselect", "(", "$", "this", "->", "class_cfg", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "[", "]", ",", "[", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options_bits'", "]", "[", "'id'", "]", "=>", "$", "id", "]", ")", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "with_config", ")", ")", "{", "return", "$", "this", "->", "explode_bit_cfg", "(", "$", "bit", ")", ";", "}", "return", "$", "bit", ";", "}", "return", "[", "]", ";", "}" ]
Returns a single preference's bit @param string $id The bit's ID @return array
[ "Returns", "a", "single", "preference", "s", "bit" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1061-L1075
22,270
nabab/bbn
src/bbn/user/preferences.php
preferences.get_bits
public function get_bits(string $id_usr_opt, $id_parent = false, bool $with_config = true): array { $c = $this->class_cfg['arch']['user_options_bits']; $t = $this; $where = [ $c['id_user_option'] => $id_usr_opt ]; if ( is_null($id_parent) || \bbn\str::is_uid($id_parent) ){ $where[$c['id_parent']] = $id_parent; } if ( \bbn\str::is_uid($id_usr_opt) && ($bits = $this->db->rselect_all($this->class_cfg['tables']['user_options_bits'], [], $where, [$c['num'] => 'ASC'])) ){ if ( !empty($with_config) ){ return array_map(function($b) use($t){ return $t->explode_bit_cfg($b); }, $bits); } return $bits; } return []; }
php
public function get_bits(string $id_usr_opt, $id_parent = false, bool $with_config = true): array { $c = $this->class_cfg['arch']['user_options_bits']; $t = $this; $where = [ $c['id_user_option'] => $id_usr_opt ]; if ( is_null($id_parent) || \bbn\str::is_uid($id_parent) ){ $where[$c['id_parent']] = $id_parent; } if ( \bbn\str::is_uid($id_usr_opt) && ($bits = $this->db->rselect_all($this->class_cfg['tables']['user_options_bits'], [], $where, [$c['num'] => 'ASC'])) ){ if ( !empty($with_config) ){ return array_map(function($b) use($t){ return $t->explode_bit_cfg($b); }, $bits); } return $bits; } return []; }
[ "public", "function", "get_bits", "(", "string", "$", "id_usr_opt", ",", "$", "id_parent", "=", "false", ",", "bool", "$", "with_config", "=", "true", ")", ":", "array", "{", "$", "c", "=", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options_bits'", "]", ";", "$", "t", "=", "$", "this", ";", "$", "where", "=", "[", "$", "c", "[", "'id_user_option'", "]", "=>", "$", "id_usr_opt", "]", ";", "if", "(", "is_null", "(", "$", "id_parent", ")", "||", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id_parent", ")", ")", "{", "$", "where", "[", "$", "c", "[", "'id_parent'", "]", "]", "=", "$", "id_parent", ";", "}", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id_usr_opt", ")", "&&", "(", "$", "bits", "=", "$", "this", "->", "db", "->", "rselect_all", "(", "$", "this", "->", "class_cfg", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "[", "]", ",", "$", "where", ",", "[", "$", "c", "[", "'num'", "]", "=>", "'ASC'", "]", ")", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "with_config", ")", ")", "{", "return", "array_map", "(", "function", "(", "$", "b", ")", "use", "(", "$", "t", ")", "{", "return", "$", "t", "->", "explode_bit_cfg", "(", "$", "b", ")", ";", "}", ",", "$", "bits", ")", ";", "}", "return", "$", "bits", ";", "}", "return", "[", "]", ";", "}" ]
Returns the bits list of a preference @param string $id The preference's ID @param null|string $id_parent The bits'parent ID @return array
[ "Returns", "the", "bits", "list", "of", "a", "preference" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1084-L1106
22,271
nabab/bbn
src/bbn/user/preferences.php
preferences.get_full_bits
public function get_full_bits(string $id_usr_opt, string $id_parent = null, bool $with_config = true): array { if ( \bbn\str::is_uid($id_usr_opt) ){ $c = $this->class_cfg['arch']['user_options_bits']; $t = $this; return array_map(function($b) use($t, $c, $id_usr_opt, $with_config){ if ( !empty($with_config) ){ $b = $t->explode_bit_cfg($b); } $b['items'] = $t->get_full_bits($id_usr_opt, $b[$c['id']], $with_config); return $b; }, $this->db->rselect_all([ 'table' => $this->class_cfg['tables']['user_options_bits'], 'fields' => [], 'where' => [ 'conditions' => [[ 'field' => $c['id_user_option'], 'value' => $id_usr_opt ], [ 'field' => $c['id_parent'], empty($id_parent) ? 'operator' : 'value' => $id_parent ?: 'isnull' ]] ], 'order' => [$c['num'] => 'ASC'] ])); } return []; }
php
public function get_full_bits(string $id_usr_opt, string $id_parent = null, bool $with_config = true): array { if ( \bbn\str::is_uid($id_usr_opt) ){ $c = $this->class_cfg['arch']['user_options_bits']; $t = $this; return array_map(function($b) use($t, $c, $id_usr_opt, $with_config){ if ( !empty($with_config) ){ $b = $t->explode_bit_cfg($b); } $b['items'] = $t->get_full_bits($id_usr_opt, $b[$c['id']], $with_config); return $b; }, $this->db->rselect_all([ 'table' => $this->class_cfg['tables']['user_options_bits'], 'fields' => [], 'where' => [ 'conditions' => [[ 'field' => $c['id_user_option'], 'value' => $id_usr_opt ], [ 'field' => $c['id_parent'], empty($id_parent) ? 'operator' : 'value' => $id_parent ?: 'isnull' ]] ], 'order' => [$c['num'] => 'ASC'] ])); } return []; }
[ "public", "function", "get_full_bits", "(", "string", "$", "id_usr_opt", ",", "string", "$", "id_parent", "=", "null", ",", "bool", "$", "with_config", "=", "true", ")", ":", "array", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id_usr_opt", ")", ")", "{", "$", "c", "=", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options_bits'", "]", ";", "$", "t", "=", "$", "this", ";", "return", "array_map", "(", "function", "(", "$", "b", ")", "use", "(", "$", "t", ",", "$", "c", ",", "$", "id_usr_opt", ",", "$", "with_config", ")", "{", "if", "(", "!", "empty", "(", "$", "with_config", ")", ")", "{", "$", "b", "=", "$", "t", "->", "explode_bit_cfg", "(", "$", "b", ")", ";", "}", "$", "b", "[", "'items'", "]", "=", "$", "t", "->", "get_full_bits", "(", "$", "id_usr_opt", ",", "$", "b", "[", "$", "c", "[", "'id'", "]", "]", ",", "$", "with_config", ")", ";", "return", "$", "b", ";", "}", ",", "$", "this", "->", "db", "->", "rselect_all", "(", "[", "'table'", "=>", "$", "this", "->", "class_cfg", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "'fields'", "=>", "[", "]", ",", "'where'", "=>", "[", "'conditions'", "=>", "[", "[", "'field'", "=>", "$", "c", "[", "'id_user_option'", "]", ",", "'value'", "=>", "$", "id_usr_opt", "]", ",", "[", "'field'", "=>", "$", "c", "[", "'id_parent'", "]", ",", "empty", "(", "$", "id_parent", ")", "?", "'operator'", ":", "'value'", "=>", "$", "id_parent", "?", ":", "'isnull'", "]", "]", "]", ",", "'order'", "=>", "[", "$", "c", "[", "'num'", "]", "=>", "'ASC'", "]", "]", ")", ")", ";", "}", "return", "[", "]", ";", "}" ]
Returns the hierarchical bits list of a preference @param string $id_usr_opt The preference's ID @param string $id_parent The parent's ID of a bit. Default: null @param bool $with_config Set it to false if you don't want the preference's cfg field values on the results. @return array
[ "Returns", "the", "hierarchical", "bits", "list", "of", "a", "preference" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1116-L1143
22,272
nabab/bbn
src/bbn/user/preferences.php
preferences.get_tree
public function get_tree(string $id, bool $with_config = true): array { if ( \bbn\str::is_uid($id) && ($p = $this->get($id, $with_config)) ){ $p['items'] = $this->get_full_bits($id, null, $with_config); return $p; } return []; }
php
public function get_tree(string $id, bool $with_config = true): array { if ( \bbn\str::is_uid($id) && ($p = $this->get($id, $with_config)) ){ $p['items'] = $this->get_full_bits($id, null, $with_config); return $p; } return []; }
[ "public", "function", "get_tree", "(", "string", "$", "id", ",", "bool", "$", "with_config", "=", "true", ")", ":", "array", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", "&&", "(", "$", "p", "=", "$", "this", "->", "get", "(", "$", "id", ",", "$", "with_config", ")", ")", ")", "{", "$", "p", "[", "'items'", "]", "=", "$", "this", "->", "get_full_bits", "(", "$", "id", ",", "null", ",", "$", "with_config", ")", ";", "return", "$", "p", ";", "}", "return", "[", "]", ";", "}" ]
Returns a preference and its hierarchical bits list @param string $id The preference's ID @param bool $with_config Set it to false if you don't want the preference's cfg field values on the results.
[ "Returns", "a", "preference", "and", "its", "hierarchical", "bits", "list" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1151-L1161
22,273
nabab/bbn
src/bbn/user/preferences.php
preferences.order_bit
public function order_bit(string $id, int $pos): ?bool { if ( \bbn\str::is_uid($id) && ($cf = $this->get_class_cfg()) && ($cfg = $cf['arch']['user_options_bits']) && ($bit = $this->get_bit($id)) && ($old = (int)$bit[$cfg['num']]) && !empty($pos) && ($old !== $pos) && ($bits = $this->get_bits($bit[$cfg['id_user_option']], $bit[$cfg['id_parent']] ?: false)) ){ $past_new = false; $past_old = false; $p = 1; $changed = 0; foreach ( $bits as $ele ){ $upd = []; if ( $past_old && !$past_new ){ $upd[$cfg['num']] = $p-1; } else if ( !$past_old && $past_new ){ $upd[$cfg['num']] = $p+1; } if ( $id === $ele['id'] ){ $upd[$cfg['num']] = $pos; $past_old = 1; } else if ( $p === $pos ){ $upd[$cfg['num']] = $p + ($pos > $old ? -1 : 1); $past_new = 1; } if ( !empty($upd) ){ $changed += $this->db->update($cf['tables']['user_options_bits'], $upd, [$cfg['id'] => $ele['id']]); } if ( $past_new && $past_old ){ break; } $p++; } return !!$changed; } return null; }
php
public function order_bit(string $id, int $pos): ?bool { if ( \bbn\str::is_uid($id) && ($cf = $this->get_class_cfg()) && ($cfg = $cf['arch']['user_options_bits']) && ($bit = $this->get_bit($id)) && ($old = (int)$bit[$cfg['num']]) && !empty($pos) && ($old !== $pos) && ($bits = $this->get_bits($bit[$cfg['id_user_option']], $bit[$cfg['id_parent']] ?: false)) ){ $past_new = false; $past_old = false; $p = 1; $changed = 0; foreach ( $bits as $ele ){ $upd = []; if ( $past_old && !$past_new ){ $upd[$cfg['num']] = $p-1; } else if ( !$past_old && $past_new ){ $upd[$cfg['num']] = $p+1; } if ( $id === $ele['id'] ){ $upd[$cfg['num']] = $pos; $past_old = 1; } else if ( $p === $pos ){ $upd[$cfg['num']] = $p + ($pos > $old ? -1 : 1); $past_new = 1; } if ( !empty($upd) ){ $changed += $this->db->update($cf['tables']['user_options_bits'], $upd, [$cfg['id'] => $ele['id']]); } if ( $past_new && $past_old ){ break; } $p++; } return !!$changed; } return null; }
[ "public", "function", "order_bit", "(", "string", "$", "id", ",", "int", "$", "pos", ")", ":", "?", "bool", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", "&&", "(", "$", "cf", "=", "$", "this", "->", "get_class_cfg", "(", ")", ")", "&&", "(", "$", "cfg", "=", "$", "cf", "[", "'arch'", "]", "[", "'user_options_bits'", "]", ")", "&&", "(", "$", "bit", "=", "$", "this", "->", "get_bit", "(", "$", "id", ")", ")", "&&", "(", "$", "old", "=", "(", "int", ")", "$", "bit", "[", "$", "cfg", "[", "'num'", "]", "]", ")", "&&", "!", "empty", "(", "$", "pos", ")", "&&", "(", "$", "old", "!==", "$", "pos", ")", "&&", "(", "$", "bits", "=", "$", "this", "->", "get_bits", "(", "$", "bit", "[", "$", "cfg", "[", "'id_user_option'", "]", "]", ",", "$", "bit", "[", "$", "cfg", "[", "'id_parent'", "]", "]", "?", ":", "false", ")", ")", ")", "{", "$", "past_new", "=", "false", ";", "$", "past_old", "=", "false", ";", "$", "p", "=", "1", ";", "$", "changed", "=", "0", ";", "foreach", "(", "$", "bits", "as", "$", "ele", ")", "{", "$", "upd", "=", "[", "]", ";", "if", "(", "$", "past_old", "&&", "!", "$", "past_new", ")", "{", "$", "upd", "[", "$", "cfg", "[", "'num'", "]", "]", "=", "$", "p", "-", "1", ";", "}", "else", "if", "(", "!", "$", "past_old", "&&", "$", "past_new", ")", "{", "$", "upd", "[", "$", "cfg", "[", "'num'", "]", "]", "=", "$", "p", "+", "1", ";", "}", "if", "(", "$", "id", "===", "$", "ele", "[", "'id'", "]", ")", "{", "$", "upd", "[", "$", "cfg", "[", "'num'", "]", "]", "=", "$", "pos", ";", "$", "past_old", "=", "1", ";", "}", "else", "if", "(", "$", "p", "===", "$", "pos", ")", "{", "$", "upd", "[", "$", "cfg", "[", "'num'", "]", "]", "=", "$", "p", "+", "(", "$", "pos", ">", "$", "old", "?", "-", "1", ":", "1", ")", ";", "$", "past_new", "=", "1", ";", "}", "if", "(", "!", "empty", "(", "$", "upd", ")", ")", "{", "$", "changed", "+=", "$", "this", "->", "db", "->", "update", "(", "$", "cf", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "$", "upd", ",", "[", "$", "cfg", "[", "'id'", "]", "=>", "$", "ele", "[", "'id'", "]", "]", ")", ";", "}", "if", "(", "$", "past_new", "&&", "$", "past_old", ")", "{", "break", ";", "}", "$", "p", "++", ";", "}", "return", "!", "!", "$", "changed", ";", "}", "return", "null", ";", "}" ]
Orders a bit. @param string $id The bit's ID @param int $pos The new position @return bool|null
[ "Orders", "a", "bit", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1237-L1280
22,274
nabab/bbn
src/bbn/user/preferences.php
preferences.move_bit
public function move_bit(string $id, string $id_parent = null): ?bool { if ( \bbn\str::is_uid($id) && ( (\bbn\str::is_uid($id_parent) && $this->get_bit($id_parent)) || \is_null($id_parent) ) && ($bit = $this->get_bit($id)) && ($cf = $this->get_class_cfg()) && ($cfg = $cf['arch']['user_options_bits']) ){ $upd = [ $cfg['id_parent'] => $id_parent, $cfg['num'] => $this->get_max_bit_num($bit[$cfg['id_user_option']], $id_parent, true) ]; return !!$this->db->update($cf['tables']['user_options_bits'], $upd, [$cfg['id'] => $id]); } return null; }
php
public function move_bit(string $id, string $id_parent = null): ?bool { if ( \bbn\str::is_uid($id) && ( (\bbn\str::is_uid($id_parent) && $this->get_bit($id_parent)) || \is_null($id_parent) ) && ($bit = $this->get_bit($id)) && ($cf = $this->get_class_cfg()) && ($cfg = $cf['arch']['user_options_bits']) ){ $upd = [ $cfg['id_parent'] => $id_parent, $cfg['num'] => $this->get_max_bit_num($bit[$cfg['id_user_option']], $id_parent, true) ]; return !!$this->db->update($cf['tables']['user_options_bits'], $upd, [$cfg['id'] => $id]); } return null; }
[ "public", "function", "move_bit", "(", "string", "$", "id", ",", "string", "$", "id_parent", "=", "null", ")", ":", "?", "bool", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", "&&", "(", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id_parent", ")", "&&", "$", "this", "->", "get_bit", "(", "$", "id_parent", ")", ")", "||", "\\", "is_null", "(", "$", "id_parent", ")", ")", "&&", "(", "$", "bit", "=", "$", "this", "->", "get_bit", "(", "$", "id", ")", ")", "&&", "(", "$", "cf", "=", "$", "this", "->", "get_class_cfg", "(", ")", ")", "&&", "(", "$", "cfg", "=", "$", "cf", "[", "'arch'", "]", "[", "'user_options_bits'", "]", ")", ")", "{", "$", "upd", "=", "[", "$", "cfg", "[", "'id_parent'", "]", "=>", "$", "id_parent", ",", "$", "cfg", "[", "'num'", "]", "=>", "$", "this", "->", "get_max_bit_num", "(", "$", "bit", "[", "$", "cfg", "[", "'id_user_option'", "]", "]", ",", "$", "id_parent", ",", "true", ")", "]", ";", "return", "!", "!", "$", "this", "->", "db", "->", "update", "(", "$", "cf", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "$", "upd", ",", "[", "$", "cfg", "[", "'id'", "]", "=>", "$", "id", "]", ")", ";", "}", "return", "null", ";", "}" ]
Moves a bit. @param string $id The bit's ID @param string|null The new parent's ID @return bool|null
[ "Moves", "a", "bit", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1289-L1308
22,275
nabab/bbn
src/bbn/user/preferences.php
preferences.get_max_bit_num
public function get_max_bit_num(string $id_user_option, string $id_parent = null, bool $incr = false): int { if ( \bbn\str::is_uid($id_user_option) && (\bbn\str::is_uid($id_parent) || is_null($id_parent)) && ($cf = $this->get_class_cfg()) && ($cfg = $cf['arch']['user_options_bits']) ){ if ( $max = $this->db->select_one([ 'table' => $cf['tables']['user_options_bits'], 'fields' => ["MAX($cfg[num])"], 'where' => [ 'conditions' => [[ 'field' => $cfg['id_user_option'], 'value' => $id_user_option ], [ 'field' => $cfg['id_parent'], empty($id_parent) ? 'operator' : 'value' => $id_parent ?: 'isnull' ]] ] ]) ){ $max = (int)$max; return $incr ? $max+1 : $max; } return 0; } }
php
public function get_max_bit_num(string $id_user_option, string $id_parent = null, bool $incr = false): int { if ( \bbn\str::is_uid($id_user_option) && (\bbn\str::is_uid($id_parent) || is_null($id_parent)) && ($cf = $this->get_class_cfg()) && ($cfg = $cf['arch']['user_options_bits']) ){ if ( $max = $this->db->select_one([ 'table' => $cf['tables']['user_options_bits'], 'fields' => ["MAX($cfg[num])"], 'where' => [ 'conditions' => [[ 'field' => $cfg['id_user_option'], 'value' => $id_user_option ], [ 'field' => $cfg['id_parent'], empty($id_parent) ? 'operator' : 'value' => $id_parent ?: 'isnull' ]] ] ]) ){ $max = (int)$max; return $incr ? $max+1 : $max; } return 0; } }
[ "public", "function", "get_max_bit_num", "(", "string", "$", "id_user_option", ",", "string", "$", "id_parent", "=", "null", ",", "bool", "$", "incr", "=", "false", ")", ":", "int", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id_user_option", ")", "&&", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id_parent", ")", "||", "is_null", "(", "$", "id_parent", ")", ")", "&&", "(", "$", "cf", "=", "$", "this", "->", "get_class_cfg", "(", ")", ")", "&&", "(", "$", "cfg", "=", "$", "cf", "[", "'arch'", "]", "[", "'user_options_bits'", "]", ")", ")", "{", "if", "(", "$", "max", "=", "$", "this", "->", "db", "->", "select_one", "(", "[", "'table'", "=>", "$", "cf", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "'fields'", "=>", "[", "\"MAX($cfg[num])\"", "]", ",", "'where'", "=>", "[", "'conditions'", "=>", "[", "[", "'field'", "=>", "$", "cfg", "[", "'id_user_option'", "]", ",", "'value'", "=>", "$", "id_user_option", "]", ",", "[", "'field'", "=>", "$", "cfg", "[", "'id_parent'", "]", ",", "empty", "(", "$", "id_parent", ")", "?", "'operator'", ":", "'value'", "=>", "$", "id_parent", "?", ":", "'isnull'", "]", "]", "]", "]", ")", ")", "{", "$", "max", "=", "(", "int", ")", "$", "max", ";", "return", "$", "incr", "?", "$", "max", "+", "1", ":", "$", "max", ";", "}", "return", "0", ";", "}", "}" ]
Gets the maximum num value of the user option's bits. @param string $id_user_option The user option's ID @param string|null $id_parent The parent's ID @param bool $incr Set it to true if you want the result increased by 1 @return int
[ "Gets", "the", "maximum", "num", "value", "of", "the", "user", "option", "s", "bits", "." ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1318-L1344
22,276
nabab/bbn
src/bbn/user/preferences.php
preferences.get_by_bit
public function get_by_bit(string $id): ?array { $t =& $this; if ( \bbn\str::is_uid($id) ){ return $this->db->rselect([ 'table' => $this->class_cfg['table'], 'fields' => array_map(function($v) use($t){ return $this->class_cfg['table'].'.'.$v; }, array_values($this->class_cfg['arch']['user_options'])), 'join' => [[ 'table' => $this->class_cfg['tables']['user_options_bits'], 'on' => [ 'conditions' => [[ 'field' => $this->class_cfg['arch']['user_options_bits']['id_user_option'], 'exp' => $this->class_cfg['table'].'.'.$this->fields['id'] ]] ] ]], 'where' => [ $this->class_cfg['tables']['user_options_bits'].'.'.$this->class_cfg['arch']['user_options_bits']['id'] => $id ] ]); } }
php
public function get_by_bit(string $id): ?array { $t =& $this; if ( \bbn\str::is_uid($id) ){ return $this->db->rselect([ 'table' => $this->class_cfg['table'], 'fields' => array_map(function($v) use($t){ return $this->class_cfg['table'].'.'.$v; }, array_values($this->class_cfg['arch']['user_options'])), 'join' => [[ 'table' => $this->class_cfg['tables']['user_options_bits'], 'on' => [ 'conditions' => [[ 'field' => $this->class_cfg['arch']['user_options_bits']['id_user_option'], 'exp' => $this->class_cfg['table'].'.'.$this->fields['id'] ]] ] ]], 'where' => [ $this->class_cfg['tables']['user_options_bits'].'.'.$this->class_cfg['arch']['user_options_bits']['id'] => $id ] ]); } }
[ "public", "function", "get_by_bit", "(", "string", "$", "id", ")", ":", "?", "array", "{", "$", "t", "=", "&", "$", "this", ";", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", ")", "{", "return", "$", "this", "->", "db", "->", "rselect", "(", "[", "'table'", "=>", "$", "this", "->", "class_cfg", "[", "'table'", "]", ",", "'fields'", "=>", "array_map", "(", "function", "(", "$", "v", ")", "use", "(", "$", "t", ")", "{", "return", "$", "this", "->", "class_cfg", "[", "'table'", "]", ".", "'.'", ".", "$", "v", ";", "}", ",", "array_values", "(", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options'", "]", ")", ")", ",", "'join'", "=>", "[", "[", "'table'", "=>", "$", "this", "->", "class_cfg", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ",", "'on'", "=>", "[", "'conditions'", "=>", "[", "[", "'field'", "=>", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options_bits'", "]", "[", "'id_user_option'", "]", ",", "'exp'", "=>", "$", "this", "->", "class_cfg", "[", "'table'", "]", ".", "'.'", ".", "$", "this", "->", "fields", "[", "'id'", "]", "]", "]", "]", "]", "]", ",", "'where'", "=>", "[", "$", "this", "->", "class_cfg", "[", "'tables'", "]", "[", "'user_options_bits'", "]", ".", "'.'", ".", "$", "this", "->", "class_cfg", "[", "'arch'", "]", "[", "'user_options_bits'", "]", "[", "'id'", "]", "=>", "$", "id", "]", "]", ")", ";", "}", "}" ]
Gets a preference row from a bit ID @param string $id The bit's ID @return array
[ "Gets", "a", "preference", "row", "from", "a", "bit", "ID" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1355-L1378
22,277
nabab/bbn
src/bbn/user/preferences.php
preferences.get_id_by_bit
public function get_id_by_bit(string $id): ?string { if ( \bbn\str::is_uid($id) && ($p = $this->get_by_bit($id)) ){ return $p[$this->fields['id']]; } return null; }
php
public function get_id_by_bit(string $id): ?string { if ( \bbn\str::is_uid($id) && ($p = $this->get_by_bit($id)) ){ return $p[$this->fields['id']]; } return null; }
[ "public", "function", "get_id_by_bit", "(", "string", "$", "id", ")", ":", "?", "string", "{", "if", "(", "\\", "bbn", "\\", "str", "::", "is_uid", "(", "$", "id", ")", "&&", "(", "$", "p", "=", "$", "this", "->", "get_by_bit", "(", "$", "id", ")", ")", ")", "{", "return", "$", "p", "[", "$", "this", "->", "fields", "[", "'id'", "]", "]", ";", "}", "return", "null", ";", "}" ]
Gets the preference's ID from a bit ID @param string $id The bit's ID @return string
[ "Gets", "the", "preference", "s", "ID", "from", "a", "bit", "ID" ]
439fea2faa0de22fdaae2611833bab8061f40c37
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/preferences.php#L1386-L1392
22,278
mothership-ec/composer
src/Composer/Repository/Pear/ChannelReader.php
ChannelReader.selectRestVersion
private function selectRestVersion($channelXml, $supportedVersions) { $channelXml->registerXPathNamespace('ns', self::CHANNEL_NS); foreach ($supportedVersions as $version) { $xpathTest = "ns:servers/ns:primary/ns:rest/ns:baseurl[@type='{$version}']"; $testResult = $channelXml->xpath($xpathTest); if (count($testResult) > 0) { return array('version' => $version, 'baseUrl' => (string) $testResult[0]); } } return null; }
php
private function selectRestVersion($channelXml, $supportedVersions) { $channelXml->registerXPathNamespace('ns', self::CHANNEL_NS); foreach ($supportedVersions as $version) { $xpathTest = "ns:servers/ns:primary/ns:rest/ns:baseurl[@type='{$version}']"; $testResult = $channelXml->xpath($xpathTest); if (count($testResult) > 0) { return array('version' => $version, 'baseUrl' => (string) $testResult[0]); } } return null; }
[ "private", "function", "selectRestVersion", "(", "$", "channelXml", ",", "$", "supportedVersions", ")", "{", "$", "channelXml", "->", "registerXPathNamespace", "(", "'ns'", ",", "self", "::", "CHANNEL_NS", ")", ";", "foreach", "(", "$", "supportedVersions", "as", "$", "version", ")", "{", "$", "xpathTest", "=", "\"ns:servers/ns:primary/ns:rest/ns:baseurl[@type='{$version}']\"", ";", "$", "testResult", "=", "$", "channelXml", "->", "xpath", "(", "$", "xpathTest", ")", ";", "if", "(", "count", "(", "$", "testResult", ")", ">", "0", ")", "{", "return", "array", "(", "'version'", "=>", "$", "version", ",", "'baseUrl'", "=>", "(", "string", ")", "$", "testResult", "[", "0", "]", ")", ";", "}", "}", "return", "null", ";", "}" ]
Reads channel supported REST interfaces and selects one of them @param $channelXml \SimpleXMLElement @param $supportedVersions string[] supported PEAR REST protocols @return array|null hash with selected version and baseUrl
[ "Reads", "channel", "supported", "REST", "interfaces", "and", "selects", "one", "of", "them" ]
fa6ad031a939d8d33b211e428fdbdd28cfce238c
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/Pear/ChannelReader.php#L78-L91
22,279
odiaseo/pagebuilder
src/PageBuilder/Controller/TemplateSectionController.php
TemplateSectionController.get
public function get($id) { return $this->_sendPayload( $this->_getService($this->_pageServiceKey)->getActiveTemplateSections($id) ); }
php
public function get($id) { return $this->_sendPayload( $this->_getService($this->_pageServiceKey)->getActiveTemplateSections($id) ); }
[ "public", "function", "get", "(", "$", "id", ")", "{", "return", "$", "this", "->", "_sendPayload", "(", "$", "this", "->", "_getService", "(", "$", "this", "->", "_pageServiceKey", ")", "->", "getActiveTemplateSections", "(", "$", "id", ")", ")", ";", "}" ]
Get template sections @param mixed $id @return mixed|\Zend\View\Model\ModelInterface
[ "Get", "template", "sections" ]
88ef7cccf305368561307efe4ca07fac8e5774f3
https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/Controller/TemplateSectionController.php#L18-L23
22,280
odiaseo/pagebuilder
src/PageBuilder/Controller/TemplateSectionController.php
TemplateSectionController.update
public function update($id, $data) { $sections = empty($data['sections']) ? [] : $data['sections']; return $this->_sendPayload( $this->_getService($this->_pageServiceKey)->updateTemplateSections($id, $sections) ); }
php
public function update($id, $data) { $sections = empty($data['sections']) ? [] : $data['sections']; return $this->_sendPayload( $this->_getService($this->_pageServiceKey)->updateTemplateSections($id, $sections) ); }
[ "public", "function", "update", "(", "$", "id", ",", "$", "data", ")", "{", "$", "sections", "=", "empty", "(", "$", "data", "[", "'sections'", "]", ")", "?", "[", "]", ":", "$", "data", "[", "'sections'", "]", ";", "return", "$", "this", "->", "_sendPayload", "(", "$", "this", "->", "_getService", "(", "$", "this", "->", "_pageServiceKey", ")", "->", "updateTemplateSections", "(", "$", "id", ",", "$", "sections", ")", ")", ";", "}" ]
Update section details @param mixed $id @param mixed $data @return mixed|\Zend\View\Model\ModelInterface
[ "Update", "section", "details" ]
88ef7cccf305368561307efe4ca07fac8e5774f3
https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/Controller/TemplateSectionController.php#L33-L40
22,281
AOEpeople/Aoe_Layout
app/code/local/Aoe/Layout/Block/Widget/Grid.php
Aoe_Layout_Block_Widget_Grid.getRowUrl
public function getRowUrl($item) { if (!$item instanceof Varien_Object) { return parent::getRowUrl($item); } $rowUrlRoute = trim($this->getRowUrlRoute()); if (empty($rowUrlRoute)) { return parent::getRowUrl($item); } $params = []; $rowUrlParams = $this->getRowUrlParams(); $rowUrlParams = (is_array($rowUrlParams) ? $rowUrlParams : explode(',', $rowUrlParams)); $rowUrlParams = array_filter(array_map('trim', $rowUrlParams)); foreach ($rowUrlParams as $key => $value) { if (strpos($value, '{{') === 0 && strrpos($value, '}}') === (strlen($value) - 2)) { $value = $item->getDataUsingMethod(substr($value, 2, -2)); } $params[$key] = $value; } $rowUrlQueryParams = $this->getRowUrlQueryParams(); $rowUrlQueryParams = (is_array($rowUrlQueryParams) ? $rowUrlQueryParams : explode(',', $rowUrlQueryParams)); $rowUrlQueryParams = array_filter(array_map('trim', $rowUrlQueryParams)); foreach ($rowUrlQueryParams as $key => $value) { if (strpos($value, '{{') === 0 && strrpos($value, '}}') === (strlen($value) - 2)) { $value = $item->getDataUsingMethod(substr($value, 1, -1)); } $params['_query'][$key] = $value; } return $this->getUrl($rowUrlRoute, $params); }
php
public function getRowUrl($item) { if (!$item instanceof Varien_Object) { return parent::getRowUrl($item); } $rowUrlRoute = trim($this->getRowUrlRoute()); if (empty($rowUrlRoute)) { return parent::getRowUrl($item); } $params = []; $rowUrlParams = $this->getRowUrlParams(); $rowUrlParams = (is_array($rowUrlParams) ? $rowUrlParams : explode(',', $rowUrlParams)); $rowUrlParams = array_filter(array_map('trim', $rowUrlParams)); foreach ($rowUrlParams as $key => $value) { if (strpos($value, '{{') === 0 && strrpos($value, '}}') === (strlen($value) - 2)) { $value = $item->getDataUsingMethod(substr($value, 2, -2)); } $params[$key] = $value; } $rowUrlQueryParams = $this->getRowUrlQueryParams(); $rowUrlQueryParams = (is_array($rowUrlQueryParams) ? $rowUrlQueryParams : explode(',', $rowUrlQueryParams)); $rowUrlQueryParams = array_filter(array_map('trim', $rowUrlQueryParams)); foreach ($rowUrlQueryParams as $key => $value) { if (strpos($value, '{{') === 0 && strrpos($value, '}}') === (strlen($value) - 2)) { $value = $item->getDataUsingMethod(substr($value, 1, -1)); } $params['_query'][$key] = $value; } return $this->getUrl($rowUrlRoute, $params); }
[ "public", "function", "getRowUrl", "(", "$", "item", ")", "{", "if", "(", "!", "$", "item", "instanceof", "Varien_Object", ")", "{", "return", "parent", "::", "getRowUrl", "(", "$", "item", ")", ";", "}", "$", "rowUrlRoute", "=", "trim", "(", "$", "this", "->", "getRowUrlRoute", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "rowUrlRoute", ")", ")", "{", "return", "parent", "::", "getRowUrl", "(", "$", "item", ")", ";", "}", "$", "params", "=", "[", "]", ";", "$", "rowUrlParams", "=", "$", "this", "->", "getRowUrlParams", "(", ")", ";", "$", "rowUrlParams", "=", "(", "is_array", "(", "$", "rowUrlParams", ")", "?", "$", "rowUrlParams", ":", "explode", "(", "','", ",", "$", "rowUrlParams", ")", ")", ";", "$", "rowUrlParams", "=", "array_filter", "(", "array_map", "(", "'trim'", ",", "$", "rowUrlParams", ")", ")", ";", "foreach", "(", "$", "rowUrlParams", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "value", ",", "'{{'", ")", "===", "0", "&&", "strrpos", "(", "$", "value", ",", "'}}'", ")", "===", "(", "strlen", "(", "$", "value", ")", "-", "2", ")", ")", "{", "$", "value", "=", "$", "item", "->", "getDataUsingMethod", "(", "substr", "(", "$", "value", ",", "2", ",", "-", "2", ")", ")", ";", "}", "$", "params", "[", "$", "key", "]", "=", "$", "value", ";", "}", "$", "rowUrlQueryParams", "=", "$", "this", "->", "getRowUrlQueryParams", "(", ")", ";", "$", "rowUrlQueryParams", "=", "(", "is_array", "(", "$", "rowUrlQueryParams", ")", "?", "$", "rowUrlQueryParams", ":", "explode", "(", "','", ",", "$", "rowUrlQueryParams", ")", ")", ";", "$", "rowUrlQueryParams", "=", "array_filter", "(", "array_map", "(", "'trim'", ",", "$", "rowUrlQueryParams", ")", ")", ";", "foreach", "(", "$", "rowUrlQueryParams", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "value", ",", "'{{'", ")", "===", "0", "&&", "strrpos", "(", "$", "value", ",", "'}}'", ")", "===", "(", "strlen", "(", "$", "value", ")", "-", "2", ")", ")", "{", "$", "value", "=", "$", "item", "->", "getDataUsingMethod", "(", "substr", "(", "$", "value", ",", "1", ",", "-", "1", ")", ")", ";", "}", "$", "params", "[", "'_query'", "]", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "this", "->", "getUrl", "(", "$", "rowUrlRoute", ",", "$", "params", ")", ";", "}" ]
Return row url for js event handlers @param Varien_Object @return string
[ "Return", "row", "url", "for", "js", "event", "handlers" ]
d88ba3406cf12dbaf09548477133c3cb27d155ed
https://github.com/AOEpeople/Aoe_Layout/blob/d88ba3406cf12dbaf09548477133c3cb27d155ed/app/code/local/Aoe/Layout/Block/Widget/Grid.php#L49-L84
22,282
AOEpeople/Aoe_Layout
app/code/local/Aoe/Layout/Block/Widget/Grid.php
Aoe_Layout_Block_Widget_Grid.sortColumnsByOrder
public function sortColumnsByOrder() { $columns = $this->_columns; foreach ($this->getColumnsOrder() as $columnId => $after) { if ($after[0] === '-') { $before = substr($after, 1); $after = null; } else { $before = null; } if ($after !== null && isset($columns[$after])) { $currentPosition = array_search($columnId, array_keys($columns)); $value = array_splice($columns, $currentPosition, 1); $destPosition = array_search($after, array_keys($columns)) + 1; $columns = array_slice($columns, 0, $destPosition) + $value + array_slice($columns, $destPosition); } elseif ($before !== null && $columns[$before]) { $currentPosition = array_search($columnId, array_keys($columns)); $value = array_splice($columns, $currentPosition, 1); $destPosition = array_search($before, array_keys($columns)); $columns = array_slice($columns, 0, $destPosition) + $value + array_slice($columns, $destPosition); } } $this->_columns = $columns; end($this->_columns); $this->_lastColumnId = key($this->_columns); return $this; }
php
public function sortColumnsByOrder() { $columns = $this->_columns; foreach ($this->getColumnsOrder() as $columnId => $after) { if ($after[0] === '-') { $before = substr($after, 1); $after = null; } else { $before = null; } if ($after !== null && isset($columns[$after])) { $currentPosition = array_search($columnId, array_keys($columns)); $value = array_splice($columns, $currentPosition, 1); $destPosition = array_search($after, array_keys($columns)) + 1; $columns = array_slice($columns, 0, $destPosition) + $value + array_slice($columns, $destPosition); } elseif ($before !== null && $columns[$before]) { $currentPosition = array_search($columnId, array_keys($columns)); $value = array_splice($columns, $currentPosition, 1); $destPosition = array_search($before, array_keys($columns)); $columns = array_slice($columns, 0, $destPosition) + $value + array_slice($columns, $destPosition); } } $this->_columns = $columns; end($this->_columns); $this->_lastColumnId = key($this->_columns); return $this; }
[ "public", "function", "sortColumnsByOrder", "(", ")", "{", "$", "columns", "=", "$", "this", "->", "_columns", ";", "foreach", "(", "$", "this", "->", "getColumnsOrder", "(", ")", "as", "$", "columnId", "=>", "$", "after", ")", "{", "if", "(", "$", "after", "[", "0", "]", "===", "'-'", ")", "{", "$", "before", "=", "substr", "(", "$", "after", ",", "1", ")", ";", "$", "after", "=", "null", ";", "}", "else", "{", "$", "before", "=", "null", ";", "}", "if", "(", "$", "after", "!==", "null", "&&", "isset", "(", "$", "columns", "[", "$", "after", "]", ")", ")", "{", "$", "currentPosition", "=", "array_search", "(", "$", "columnId", ",", "array_keys", "(", "$", "columns", ")", ")", ";", "$", "value", "=", "array_splice", "(", "$", "columns", ",", "$", "currentPosition", ",", "1", ")", ";", "$", "destPosition", "=", "array_search", "(", "$", "after", ",", "array_keys", "(", "$", "columns", ")", ")", "+", "1", ";", "$", "columns", "=", "array_slice", "(", "$", "columns", ",", "0", ",", "$", "destPosition", ")", "+", "$", "value", "+", "array_slice", "(", "$", "columns", ",", "$", "destPosition", ")", ";", "}", "elseif", "(", "$", "before", "!==", "null", "&&", "$", "columns", "[", "$", "before", "]", ")", "{", "$", "currentPosition", "=", "array_search", "(", "$", "columnId", ",", "array_keys", "(", "$", "columns", ")", ")", ";", "$", "value", "=", "array_splice", "(", "$", "columns", ",", "$", "currentPosition", ",", "1", ")", ";", "$", "destPosition", "=", "array_search", "(", "$", "before", ",", "array_keys", "(", "$", "columns", ")", ")", ";", "$", "columns", "=", "array_slice", "(", "$", "columns", ",", "0", ",", "$", "destPosition", ")", "+", "$", "value", "+", "array_slice", "(", "$", "columns", ",", "$", "destPosition", ")", ";", "}", "}", "$", "this", "->", "_columns", "=", "$", "columns", ";", "end", "(", "$", "this", "->", "_columns", ")", ";", "$", "this", "->", "_lastColumnId", "=", "key", "(", "$", "this", "->", "_columns", ")", ";", "return", "$", "this", ";", "}" ]
Sort columns by predefined order @return Mage_Adminhtml_Block_Widget_Grid
[ "Sort", "columns", "by", "predefined", "order" ]
d88ba3406cf12dbaf09548477133c3cb27d155ed
https://github.com/AOEpeople/Aoe_Layout/blob/d88ba3406cf12dbaf09548477133c3cb27d155ed/app/code/local/Aoe/Layout/Block/Widget/Grid.php#L97-L127
22,283
AOEpeople/Aoe_Layout
app/code/local/Aoe/Layout/Block/Widget/Grid.php
Aoe_Layout_Block_Widget_Grid.updateColumn
public function updateColumn($columnId, $key, $value) { if (isset($this->_columns[$columnId]) && $this->_columns[$columnId] instanceof Varien_Object) { $this->_columns[$columnId]->setData($key, $value); } return $this; }
php
public function updateColumn($columnId, $key, $value) { if (isset($this->_columns[$columnId]) && $this->_columns[$columnId] instanceof Varien_Object) { $this->_columns[$columnId]->setData($key, $value); } return $this; }
[ "public", "function", "updateColumn", "(", "$", "columnId", ",", "$", "key", ",", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_columns", "[", "$", "columnId", "]", ")", "&&", "$", "this", "->", "_columns", "[", "$", "columnId", "]", "instanceof", "Varien_Object", ")", "{", "$", "this", "->", "_columns", "[", "$", "columnId", "]", "->", "setData", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Modify grid column @param $columnId @param $key @param $value @return $this
[ "Modify", "grid", "column" ]
d88ba3406cf12dbaf09548477133c3cb27d155ed
https://github.com/AOEpeople/Aoe_Layout/blob/d88ba3406cf12dbaf09548477133c3cb27d155ed/app/code/local/Aoe/Layout/Block/Widget/Grid.php#L138-L145
22,284
HedronDev/hedron
src/ProjectTypeDictionary.php
ProjectTypeDictionary.getCurrentProject
public function getCurrentProject() { return $this->createInstance($this->environment->getProjectType(), $this->environment, $this->configuration, $this->fileSystem); }
php
public function getCurrentProject() { return $this->createInstance($this->environment->getProjectType(), $this->environment, $this->configuration, $this->fileSystem); }
[ "public", "function", "getCurrentProject", "(", ")", "{", "return", "$", "this", "->", "createInstance", "(", "$", "this", "->", "environment", "->", "getProjectType", "(", ")", ",", "$", "this", "->", "environment", ",", "$", "this", "->", "configuration", ",", "$", "this", "->", "fileSystem", ")", ";", "}" ]
Get a project plugin for the current environment settings. @return \Hedron\ProjectTypeInterface
[ "Get", "a", "project", "plugin", "for", "the", "current", "environment", "settings", "." ]
3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00
https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/ProjectTypeDictionary.php#L55-L57
22,285
Erdiko/core
src/Response.php
Response.getKeyValue
public function getKeyValue($key) { return empty($this->_data[$key]) ? null: $this->_data[$key]; }
php
public function getKeyValue($key) { return empty($this->_data[$key]) ? null: $this->_data[$key]; }
[ "public", "function", "getKeyValue", "(", "$", "key", ")", "{", "return", "empty", "(", "$", "this", "->", "_data", "[", "$", "key", "]", ")", "?", "null", ":", "$", "this", "->", "_data", "[", "$", "key", "]", ";", "}" ]
Get data value by key @param mixed $key @return mixed
[ "Get", "data", "value", "by", "key" ]
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Response.php#L55-L58
22,286
Erdiko/core
src/Response.php
Response.setThemeTemplate
public function setThemeTemplate($template) { $this->_themeTemplate = $template; if ($this->getTheme() != null) { $this->getTheme()->setTemplate($this->_themeTemplate); } }
php
public function setThemeTemplate($template) { $this->_themeTemplate = $template; if ($this->getTheme() != null) { $this->getTheme()->setTemplate($this->_themeTemplate); } }
[ "public", "function", "setThemeTemplate", "(", "$", "template", ")", "{", "$", "this", "->", "_themeTemplate", "=", "$", "template", ";", "if", "(", "$", "this", "->", "getTheme", "(", ")", "!=", "null", ")", "{", "$", "this", "->", "getTheme", "(", ")", "->", "setTemplate", "(", "$", "this", "->", "_themeTemplate", ")", ";", "}", "}" ]
Set Theme Template @param string $tamplate
[ "Set", "Theme", "Template" ]
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Response.php#L127-L133
22,287
GrupaZero/api
src/Gzero/Api/UrlParamsProcessor.php
UrlParamsProcessor.getProcessedFields
public function getProcessedFields() { return [ 'page' => $this->getPage(), 'perPage' => $this->getPerPage(), 'filter' => $this->filter, 'orderBy' => $this->orderBy, 'query' => $this->searchQuery ]; }
php
public function getProcessedFields() { return [ 'page' => $this->getPage(), 'perPage' => $this->getPerPage(), 'filter' => $this->filter, 'orderBy' => $this->orderBy, 'query' => $this->searchQuery ]; }
[ "public", "function", "getProcessedFields", "(", ")", "{", "return", "[", "'page'", "=>", "$", "this", "->", "getPage", "(", ")", ",", "'perPage'", "=>", "$", "this", "->", "getPerPage", "(", ")", ",", "'filter'", "=>", "$", "this", "->", "filter", ",", "'orderBy'", "=>", "$", "this", "->", "orderBy", ",", "'query'", "=>", "$", "this", "->", "searchQuery", "]", ";", "}" ]
Returns array with all processed fields @return array
[ "Returns", "array", "with", "all", "processed", "fields" ]
fc544bb6057274e9d5e7b617346c3f854ea5effd
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/UrlParamsProcessor.php#L100-L109
22,288
GrupaZero/api
src/Gzero/Api/UrlParamsProcessor.php
UrlParamsProcessor.processFilterParams
private function processFilterParams($key, $param) { $this->filter[] = [ $key, '=', (is_numeric($param)) ? (float) $param : $param ]; }
php
private function processFilterParams($key, $param) { $this->filter[] = [ $key, '=', (is_numeric($param)) ? (float) $param : $param ]; }
[ "private", "function", "processFilterParams", "(", "$", "key", ",", "$", "param", ")", "{", "$", "this", "->", "filter", "[", "]", "=", "[", "$", "key", ",", "'='", ",", "(", "is_numeric", "(", "$", "param", ")", ")", "?", "(", "float", ")", "$", "param", ":", "$", "param", "]", ";", "}" ]
Process filter params @param string $key Param name @param string $param Param value @return void
[ "Process", "filter", "params" ]
fc544bb6057274e9d5e7b617346c3f854ea5effd
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/UrlParamsProcessor.php#L180-L187
22,289
surebert/surebert-framework
src/sb/String/Image.php
Image.draw
public function draw($text, $size=12, $x=0, $y=0) { imagettftext($this->image, $size, $this->rotation, $x, $y, $this->text_color, $this->font, $text); return $this->image; }
php
public function draw($text, $size=12, $x=0, $y=0) { imagettftext($this->image, $size, $this->rotation, $x, $y, $this->text_color, $this->font, $text); return $this->image; }
[ "public", "function", "draw", "(", "$", "text", ",", "$", "size", "=", "12", ",", "$", "x", "=", "0", ",", "$", "y", "=", "0", ")", "{", "imagettftext", "(", "$", "this", "->", "image", ",", "$", "size", ",", "$", "this", "->", "rotation", ",", "$", "x", ",", "$", "y", ",", "$", "this", "->", "text_color", ",", "$", "this", "->", "font", ",", "$", "text", ")", ";", "return", "$", "this", "->", "image", ";", "}" ]
Draws the text onto the image @param string $text The text to write on the image @param integer $size The font size to use @param integer $x The x position to start draiwng on the image @param integer $y The y position to start drawing on the image @return resource A png image resource that can be used by imagepng, imagegif for output
[ "Draws", "the", "text", "onto", "the", "image" ]
f2f32eb693bd39385ceb93355efb5b2a429f27ce
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/String/Image.php#L84-L91
22,290
hametuha/wpametu
src/WPametu/Pattern/Singleton.php
Singleton.get_instance
final public static function get_instance( array $setting = [] ) { $class_name = get_called_class(); if ( ! isset( self::$instances[ $class_name ] ) ) { self::$instances[ $class_name ] = new $class_name( $setting ); } return self::$instances[ $class_name ]; }
php
final public static function get_instance( array $setting = [] ) { $class_name = get_called_class(); if ( ! isset( self::$instances[ $class_name ] ) ) { self::$instances[ $class_name ] = new $class_name( $setting ); } return self::$instances[ $class_name ]; }
[ "final", "public", "static", "function", "get_instance", "(", "array", "$", "setting", "=", "[", "]", ")", "{", "$", "class_name", "=", "get_called_class", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "class_name", "]", ")", ")", "{", "self", "::", "$", "instances", "[", "$", "class_name", "]", "=", "new", "$", "class_name", "(", "$", "setting", ")", ";", "}", "return", "self", "::", "$", "instances", "[", "$", "class_name", "]", ";", "}" ]
Singleton initialize method @param array $setting @return static
[ "Singleton", "initialize", "method" ]
0939373800815a8396291143d2a57967340da5aa
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Pattern/Singleton.php#L32-L39
22,291
ajant/SimpleArrayLibrary
src/Categories/Getters.php
Getters.getColumns
public static function getColumns(array $array, array $columns, $allRowsMustHaveAllColumns = false) { // validation foreach ($array as $key => $row) { if (!is_array($row)) { throw new UnexpectedValueException('Array element "' . $key . '" is not an array'); } } foreach ($columns as $key => $column) { if (!is_string($column) && !is_numeric($column)) { throw new InvalidArgumentException('Invalid column type in columns array, index "' . $key . '"'); } } if (!is_bool($allRowsMustHaveAllColumns)) { throw new InvalidArgumentException('allRowsMustHaveAllColumns flag must be boolean'); } $return = array_fill_keys($columns, array()); foreach ($array as $key => $row) { foreach ($columns as $column) { if (isset($row[$column]) || array_key_exists($column, $row)) { $return[$column][$key] = $row[$column]; } elseif ($allRowsMustHaveAllColumns) { throw new UnexpectedValueException('Row "' . $key . '" is missing column: "' . $column . '"'); } } } return $return; }
php
public static function getColumns(array $array, array $columns, $allRowsMustHaveAllColumns = false) { // validation foreach ($array as $key => $row) { if (!is_array($row)) { throw new UnexpectedValueException('Array element "' . $key . '" is not an array'); } } foreach ($columns as $key => $column) { if (!is_string($column) && !is_numeric($column)) { throw new InvalidArgumentException('Invalid column type in columns array, index "' . $key . '"'); } } if (!is_bool($allRowsMustHaveAllColumns)) { throw new InvalidArgumentException('allRowsMustHaveAllColumns flag must be boolean'); } $return = array_fill_keys($columns, array()); foreach ($array as $key => $row) { foreach ($columns as $column) { if (isset($row[$column]) || array_key_exists($column, $row)) { $return[$column][$key] = $row[$column]; } elseif ($allRowsMustHaveAllColumns) { throw new UnexpectedValueException('Row "' . $key . '" is missing column: "' . $column . '"'); } } } return $return; }
[ "public", "static", "function", "getColumns", "(", "array", "$", "array", ",", "array", "$", "columns", ",", "$", "allRowsMustHaveAllColumns", "=", "false", ")", "{", "// validation", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "row", ")", "{", "if", "(", "!", "is_array", "(", "$", "row", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'Array element \"'", ".", "$", "key", ".", "'\" is not an array'", ")", ";", "}", "}", "foreach", "(", "$", "columns", "as", "$", "key", "=>", "$", "column", ")", "{", "if", "(", "!", "is_string", "(", "$", "column", ")", "&&", "!", "is_numeric", "(", "$", "column", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid column type in columns array, index \"'", ".", "$", "key", ".", "'\"'", ")", ";", "}", "}", "if", "(", "!", "is_bool", "(", "$", "allRowsMustHaveAllColumns", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'allRowsMustHaveAllColumns flag must be boolean'", ")", ";", "}", "$", "return", "=", "array_fill_keys", "(", "$", "columns", ",", "array", "(", ")", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "row", ")", "{", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "if", "(", "isset", "(", "$", "row", "[", "$", "column", "]", ")", "||", "array_key_exists", "(", "$", "column", ",", "$", "row", ")", ")", "{", "$", "return", "[", "$", "column", "]", "[", "$", "key", "]", "=", "$", "row", "[", "$", "column", "]", ";", "}", "elseif", "(", "$", "allRowsMustHaveAllColumns", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'Row \"'", ".", "$", "key", ".", "'\" is missing column: \"'", ".", "$", "column", ".", "'\"'", ")", ";", "}", "}", "}", "return", "$", "return", ";", "}" ]
Extracts a column from an array @param array $array @param array $columns @param bool $allRowsMustHaveAllColumns @return array @throws UnexpectedValueException
[ "Extracts", "a", "column", "from", "an", "array" ]
374877c0f20a22a914eb3680eb1cf39e424071be
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Getters.php#L20-L49
22,292
ajant/SimpleArrayLibrary
src/Categories/Getters.php
Getters.getRectangularDimensions
public static function getRectangularDimensions(array $array) { $return = -1; $allArrays = array_map('is_array', $array); // all elements are arrays, iterate through them and call the static function recursively if (self::allElementsEqual($allArrays, true)) { $elementsPerArray = array(); foreach ($array as $row) { $noElements = self::getRectangularDimensions($row); if ($noElements == -1) { return $noElements; } $elementsPerArray[] = $noElements; } if (!self::allElementsEqual($elementsPerArray)) { return -1; } else { $return = reset($elementsPerArray); $return[] = count($elementsPerArray); } } // none of the elements are arrays, return number of elements of the "bottom" array elseif (self::allElementsEqual($allArrays, false)) { $return = array(0 => count($array)); } return $return; }
php
public static function getRectangularDimensions(array $array) { $return = -1; $allArrays = array_map('is_array', $array); // all elements are arrays, iterate through them and call the static function recursively if (self::allElementsEqual($allArrays, true)) { $elementsPerArray = array(); foreach ($array as $row) { $noElements = self::getRectangularDimensions($row); if ($noElements == -1) { return $noElements; } $elementsPerArray[] = $noElements; } if (!self::allElementsEqual($elementsPerArray)) { return -1; } else { $return = reset($elementsPerArray); $return[] = count($elementsPerArray); } } // none of the elements are arrays, return number of elements of the "bottom" array elseif (self::allElementsEqual($allArrays, false)) { $return = array(0 => count($array)); } return $return; }
[ "public", "static", "function", "getRectangularDimensions", "(", "array", "$", "array", ")", "{", "$", "return", "=", "-", "1", ";", "$", "allArrays", "=", "array_map", "(", "'is_array'", ",", "$", "array", ")", ";", "// all elements are arrays, iterate through them and call the static function recursively", "if", "(", "self", "::", "allElementsEqual", "(", "$", "allArrays", ",", "true", ")", ")", "{", "$", "elementsPerArray", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "row", ")", "{", "$", "noElements", "=", "self", "::", "getRectangularDimensions", "(", "$", "row", ")", ";", "if", "(", "$", "noElements", "==", "-", "1", ")", "{", "return", "$", "noElements", ";", "}", "$", "elementsPerArray", "[", "]", "=", "$", "noElements", ";", "}", "if", "(", "!", "self", "::", "allElementsEqual", "(", "$", "elementsPerArray", ")", ")", "{", "return", "-", "1", ";", "}", "else", "{", "$", "return", "=", "reset", "(", "$", "elementsPerArray", ")", ";", "$", "return", "[", "]", "=", "count", "(", "$", "elementsPerArray", ")", ";", "}", "}", "// none of the elements are arrays, return number of elements of the \"bottom\" array", "elseif", "(", "self", "::", "allElementsEqual", "(", "$", "allArrays", ",", "false", ")", ")", "{", "$", "return", "=", "array", "(", "0", "=>", "count", "(", "$", "array", ")", ")", ";", "}", "return", "$", "return", ";", "}" ]
Checks if an array is rectangular array and returns dimensions or -1 if it's not rectangular @param array $array @return int|array
[ "Checks", "if", "an", "array", "is", "rectangular", "array", "and", "returns", "dimensions", "or", "-", "1", "if", "it", "s", "not", "rectangular" ]
374877c0f20a22a914eb3680eb1cf39e424071be
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Getters.php#L58-L84
22,293
ajant/SimpleArrayLibrary
src/Categories/Getters.php
Getters.selectRandomArrayElements
public static function selectRandomArrayElements(array $array, $numberOfRequiredElements) { // validation, must be positive int or 0 if (!self::isLogicallyCastableToInt($numberOfRequiredElements)) { throw new InvalidArgumentException('Number of requested elements parameter must be a positive integer'); } if ($numberOfRequiredElements <= 0) { throw new InvalidArgumentException('Number of requested elements parameter must be a positive integer'); } $selected = $array; if (count($array) > $numberOfRequiredElements) { // select required number of random keys $selectedKeys = array_rand($array, $numberOfRequiredElements); $selectedKeys = $numberOfRequiredElements == 1 ? [$selectedKeys] : $selectedKeys; // select only array members with selected random keys $selected = array_intersect_key($array, array_fill_keys($selectedKeys, null)); } return $selected; }
php
public static function selectRandomArrayElements(array $array, $numberOfRequiredElements) { // validation, must be positive int or 0 if (!self::isLogicallyCastableToInt($numberOfRequiredElements)) { throw new InvalidArgumentException('Number of requested elements parameter must be a positive integer'); } if ($numberOfRequiredElements <= 0) { throw new InvalidArgumentException('Number of requested elements parameter must be a positive integer'); } $selected = $array; if (count($array) > $numberOfRequiredElements) { // select required number of random keys $selectedKeys = array_rand($array, $numberOfRequiredElements); $selectedKeys = $numberOfRequiredElements == 1 ? [$selectedKeys] : $selectedKeys; // select only array members with selected random keys $selected = array_intersect_key($array, array_fill_keys($selectedKeys, null)); } return $selected; }
[ "public", "static", "function", "selectRandomArrayElements", "(", "array", "$", "array", ",", "$", "numberOfRequiredElements", ")", "{", "// validation, must be positive int or 0", "if", "(", "!", "self", "::", "isLogicallyCastableToInt", "(", "$", "numberOfRequiredElements", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Number of requested elements parameter must be a positive integer'", ")", ";", "}", "if", "(", "$", "numberOfRequiredElements", "<=", "0", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Number of requested elements parameter must be a positive integer'", ")", ";", "}", "$", "selected", "=", "$", "array", ";", "if", "(", "count", "(", "$", "array", ")", ">", "$", "numberOfRequiredElements", ")", "{", "// select required number of random keys", "$", "selectedKeys", "=", "array_rand", "(", "$", "array", ",", "$", "numberOfRequiredElements", ")", ";", "$", "selectedKeys", "=", "$", "numberOfRequiredElements", "==", "1", "?", "[", "$", "selectedKeys", "]", ":", "$", "selectedKeys", ";", "// select only array members with selected random keys", "$", "selected", "=", "array_intersect_key", "(", "$", "array", ",", "array_fill_keys", "(", "$", "selectedKeys", ",", "null", ")", ")", ";", "}", "return", "$", "selected", ";", "}" ]
Selects random sub array @param array $array @param int $numberOfRequiredElements @return array @throws InvalidArgumentException
[ "Selects", "random", "sub", "array" ]
374877c0f20a22a914eb3680eb1cf39e424071be
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Getters.php#L95-L115
22,294
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Helper/Uri.php
Uri.parseUri
protected function parseUri($uriString = '') { $status = @preg_match("~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~", $uriString, $matches); if($status === FALSE) { throw new Exception("URI scheme-specific decomposition failed"); } if(!$status) return; $this->path = (isset($matches[4])) ? $matches[4] : ''; $this->query = (isset($matches[6])) ? $matches[6] : ''; $this->fragment = (isset($matches[8])) ? $matches[8] : ''; $status = @preg_match("~^(([^:@]*)(:([^@]*))?@)?((?(?=[[])[[][^]]+[]]|[^:]+))(:(.*))?$~", (isset($matches[3])) ? $matches[3] : "", $matches); if($status === FALSE) { throw new Exception("URI scheme-specific authority decomposition failed"); } if(!$status) return; $this->user = isset($matches[2]) ? $matches[2] : ""; $this->pass = isset($matches[4]) ? $matches[4] : ""; $this->host = isset($matches[5]) === TRUE ? preg_replace('~^\[([^]]+)\]$~', '\1', $matches[5]) : ""; $this->port = isset($matches[7]) ? $matches[7] : ""; }
php
protected function parseUri($uriString = '') { $status = @preg_match("~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~", $uriString, $matches); if($status === FALSE) { throw new Exception("URI scheme-specific decomposition failed"); } if(!$status) return; $this->path = (isset($matches[4])) ? $matches[4] : ''; $this->query = (isset($matches[6])) ? $matches[6] : ''; $this->fragment = (isset($matches[8])) ? $matches[8] : ''; $status = @preg_match("~^(([^:@]*)(:([^@]*))?@)?((?(?=[[])[[][^]]+[]]|[^:]+))(:(.*))?$~", (isset($matches[3])) ? $matches[3] : "", $matches); if($status === FALSE) { throw new Exception("URI scheme-specific authority decomposition failed"); } if(!$status) return; $this->user = isset($matches[2]) ? $matches[2] : ""; $this->pass = isset($matches[4]) ? $matches[4] : ""; $this->host = isset($matches[5]) === TRUE ? preg_replace('~^\[([^]]+)\]$~', '\1', $matches[5]) : ""; $this->port = isset($matches[7]) ? $matches[7] : ""; }
[ "protected", "function", "parseUri", "(", "$", "uriString", "=", "''", ")", "{", "$", "status", "=", "@", "preg_match", "(", "\"~^((//)([^/?#]*))([^?#]*)(\\?([^#]*))?(#(.*))?$~\"", ",", "$", "uriString", ",", "$", "matches", ")", ";", "if", "(", "$", "status", "===", "FALSE", ")", "{", "throw", "new", "Exception", "(", "\"URI scheme-specific decomposition failed\"", ")", ";", "}", "if", "(", "!", "$", "status", ")", "return", ";", "$", "this", "->", "path", "=", "(", "isset", "(", "$", "matches", "[", "4", "]", ")", ")", "?", "$", "matches", "[", "4", "]", ":", "''", ";", "$", "this", "->", "query", "=", "(", "isset", "(", "$", "matches", "[", "6", "]", ")", ")", "?", "$", "matches", "[", "6", "]", ":", "''", ";", "$", "this", "->", "fragment", "=", "(", "isset", "(", "$", "matches", "[", "8", "]", ")", ")", "?", "$", "matches", "[", "8", "]", ":", "''", ";", "$", "status", "=", "@", "preg_match", "(", "\"~^(([^:@]*)(:([^@]*))?@)?((?(?=[[])[[][^]]+[]]|[^:]+))(:(.*))?$~\"", ",", "(", "isset", "(", "$", "matches", "[", "3", "]", ")", ")", "?", "$", "matches", "[", "3", "]", ":", "\"\"", ",", "$", "matches", ")", ";", "if", "(", "$", "status", "===", "FALSE", ")", "{", "throw", "new", "Exception", "(", "\"URI scheme-specific authority decomposition failed\"", ")", ";", "}", "if", "(", "!", "$", "status", ")", "return", ";", "$", "this", "->", "user", "=", "isset", "(", "$", "matches", "[", "2", "]", ")", "?", "$", "matches", "[", "2", "]", ":", "\"\"", ";", "$", "this", "->", "pass", "=", "isset", "(", "$", "matches", "[", "4", "]", ")", "?", "$", "matches", "[", "4", "]", ":", "\"\"", ";", "$", "this", "->", "host", "=", "isset", "(", "$", "matches", "[", "5", "]", ")", "===", "TRUE", "?", "preg_replace", "(", "'~^\\[([^]]+)\\]$~'", ",", "'\\1'", ",", "$", "matches", "[", "5", "]", ")", ":", "\"\"", ";", "$", "this", "->", "port", "=", "isset", "(", "$", "matches", "[", "7", "]", ")", "?", "$", "matches", "[", "7", "]", ":", "\"\"", ";", "}" ]
Parses the scheme-specific portion of the URI and place its parts into instance variables. @throws Exception @return void
[ "Parses", "the", "scheme", "-", "specific", "portion", "of", "the", "URI", "and", "place", "its", "parts", "into", "instance", "variables", "." ]
39a56eca608da6b56b6aa386a7b5b31dc576c41a
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Helper/Uri.php#L145-L173
22,295
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Helper/Uri.php
Uri.check
public static function check($uri) { try { $uri = new self(strval($uri)); } catch(\Exception $e) { return FALSE; } return $uri->valid(); }
php
public static function check($uri) { try { $uri = new self(strval($uri)); } catch(\Exception $e) { return FALSE; } return $uri->valid(); }
[ "public", "static", "function", "check", "(", "$", "uri", ")", "{", "try", "{", "$", "uri", "=", "new", "self", "(", "strval", "(", "$", "uri", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "FALSE", ";", "}", "return", "$", "uri", "->", "valid", "(", ")", ";", "}" ]
Returns TRUE if a given URI is valid. @param string $uri @return boolean
[ "Returns", "TRUE", "if", "a", "given", "URI", "is", "valid", "." ]
39a56eca608da6b56b6aa386a7b5b31dc576c41a
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Helper/Uri.php#L191-L203
22,296
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Helper/Uri.php
Uri.checkPath
public function checkPath($path = null) { if($path === null) { $path = $this->path; } if(strlen($path) == 0) { return TRUE; } $pattern = "/^" . $this->regex["path"] . "$/"; $status = @preg_match($pattern, $path); if($status === FALSE) { throw new Exception("URI path validation failed"); } return ($status == 1); }
php
public function checkPath($path = null) { if($path === null) { $path = $this->path; } if(strlen($path) == 0) { return TRUE; } $pattern = "/^" . $this->regex["path"] . "$/"; $status = @preg_match($pattern, $path); if($status === FALSE) { throw new Exception("URI path validation failed"); } return ($status == 1); }
[ "public", "function", "checkPath", "(", "$", "path", "=", "null", ")", "{", "if", "(", "$", "path", "===", "null", ")", "{", "$", "path", "=", "$", "this", "->", "path", ";", "}", "if", "(", "strlen", "(", "$", "path", ")", "==", "0", ")", "{", "return", "TRUE", ";", "}", "$", "pattern", "=", "\"/^\"", ".", "$", "this", "->", "regex", "[", "\"path\"", "]", ".", "\"$/\"", ";", "$", "status", "=", "@", "preg_match", "(", "$", "pattern", ",", "$", "path", ")", ";", "if", "(", "$", "status", "===", "FALSE", ")", "{", "throw", "new", "Exception", "(", "\"URI path validation failed\"", ")", ";", "}", "return", "(", "$", "status", "==", "1", ")", ";", "}" ]
Returns TRUE if the path is valid. @param string $path @throws Exception @return boolean
[ "Returns", "TRUE", "if", "the", "path", "is", "valid", "." ]
39a56eca608da6b56b6aa386a7b5b31dc576c41a
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Helper/Uri.php#L414-L435
22,297
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Helper/Uri.php
Uri.getHostUri
public static function getHostUri() { $sheme = (self::getHostParam("HTTPS") == "on") ? "https" : "http"; $serverName = new Str(self::getHostParam("HTTP_HOST")); $serverPort = self::getHostParam("SERVER_PORT"); $serverPort = ($serverPort != 80 && $serverPort != 443) ? ":" . $serverPort : ""; if($serverName->endsWith($serverPort)) { $serverName = $serverName->replace($serverPort, ""); } return new Str($sheme . "://" . $serverName . $serverPort); }
php
public static function getHostUri() { $sheme = (self::getHostParam("HTTPS") == "on") ? "https" : "http"; $serverName = new Str(self::getHostParam("HTTP_HOST")); $serverPort = self::getHostParam("SERVER_PORT"); $serverPort = ($serverPort != 80 && $serverPort != 443) ? ":" . $serverPort : ""; if($serverName->endsWith($serverPort)) { $serverName = $serverName->replace($serverPort, ""); } return new Str($sheme . "://" . $serverName . $serverPort); }
[ "public", "static", "function", "getHostUri", "(", ")", "{", "$", "sheme", "=", "(", "self", "::", "getHostParam", "(", "\"HTTPS\"", ")", "==", "\"on\"", ")", "?", "\"https\"", ":", "\"http\"", ";", "$", "serverName", "=", "new", "Str", "(", "self", "::", "getHostParam", "(", "\"HTTP_HOST\"", ")", ")", ";", "$", "serverPort", "=", "self", "::", "getHostParam", "(", "\"SERVER_PORT\"", ")", ";", "$", "serverPort", "=", "(", "$", "serverPort", "!=", "80", "&&", "$", "serverPort", "!=", "443", ")", "?", "\":\"", ".", "$", "serverPort", ":", "\"\"", ";", "if", "(", "$", "serverName", "->", "endsWith", "(", "$", "serverPort", ")", ")", "{", "$", "serverName", "=", "$", "serverName", "->", "replace", "(", "$", "serverPort", ",", "\"\"", ")", ";", "}", "return", "new", "Str", "(", "$", "sheme", ".", "\"://\"", ".", "$", "serverName", ".", "$", "serverPort", ")", ";", "}" ]
Returns the applications host address. @return Str
[ "Returns", "the", "applications", "host", "address", "." ]
39a56eca608da6b56b6aa386a7b5b31dc576c41a
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Helper/Uri.php#L677-L691
22,298
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/text_parser.php
ezcMailTextParser.parseBody
public function parseBody( $line ) { $line = rtrim( $line, "\r\n" ); if ( $this->text === null ) { $this->text = $line; } else { $this->text .= "\n" . $line; } }
php
public function parseBody( $line ) { $line = rtrim( $line, "\r\n" ); if ( $this->text === null ) { $this->text = $line; } else { $this->text .= "\n" . $line; } }
[ "public", "function", "parseBody", "(", "$", "line", ")", "{", "$", "line", "=", "rtrim", "(", "$", "line", ",", "\"\\r\\n\"", ")", ";", "if", "(", "$", "this", "->", "text", "===", "null", ")", "{", "$", "this", "->", "text", "=", "$", "line", ";", "}", "else", "{", "$", "this", "->", "text", ".=", "\"\\n\"", ".", "$", "line", ";", "}", "}" ]
Adds each line to the body of the text part. @param string $line
[ "Adds", "each", "line", "to", "the", "body", "of", "the", "text", "part", "." ]
b0afc661105f0a2f65d49abac13956cc93c5188d
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/text_parser.php#L59-L70
22,299
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/text_parser.php
ezcMailTextParser.finish
public function finish() { $charset = "us-ascii"; // RFC 2822 default if ( isset( $this->headers['Content-Type'] ) ) { preg_match( '/\s*charset\s?=\s?"?([^;"\s]*);?/', $this->headers['Content-Type'], $parameters ); if ( count( $parameters ) > 0 ) { $charset = strtolower( trim( $parameters[1], '"' ) ); } } $encoding = strtolower( $this->headers['Content-Transfer-Encoding'] ); if ( $encoding == ezcMail::QUOTED_PRINTABLE ) { $this->text = quoted_printable_decode( $this->text ); } else if ( $encoding == ezcMail::BASE64 ) { $this->text = base64_decode( $this->text ); } $this->text = ezcMailCharsetConverter::convertToUTF8( $this->text, $charset ); $part = new ezcMailText( $this->text, 'utf-8', ezcMail::EIGHT_BIT, $charset ); $part->subType = $this->subType; $part->setHeaders( $this->headers->getCaseSensitiveArray() ); ezcMailPartParser::parsePartHeaders( $this->headers, $part ); $part->size = strlen( $this->text ); return $part; }
php
public function finish() { $charset = "us-ascii"; // RFC 2822 default if ( isset( $this->headers['Content-Type'] ) ) { preg_match( '/\s*charset\s?=\s?"?([^;"\s]*);?/', $this->headers['Content-Type'], $parameters ); if ( count( $parameters ) > 0 ) { $charset = strtolower( trim( $parameters[1], '"' ) ); } } $encoding = strtolower( $this->headers['Content-Transfer-Encoding'] ); if ( $encoding == ezcMail::QUOTED_PRINTABLE ) { $this->text = quoted_printable_decode( $this->text ); } else if ( $encoding == ezcMail::BASE64 ) { $this->text = base64_decode( $this->text ); } $this->text = ezcMailCharsetConverter::convertToUTF8( $this->text, $charset ); $part = new ezcMailText( $this->text, 'utf-8', ezcMail::EIGHT_BIT, $charset ); $part->subType = $this->subType; $part->setHeaders( $this->headers->getCaseSensitiveArray() ); ezcMailPartParser::parsePartHeaders( $this->headers, $part ); $part->size = strlen( $this->text ); return $part; }
[ "public", "function", "finish", "(", ")", "{", "$", "charset", "=", "\"us-ascii\"", ";", "// RFC 2822 default", "if", "(", "isset", "(", "$", "this", "->", "headers", "[", "'Content-Type'", "]", ")", ")", "{", "preg_match", "(", "'/\\s*charset\\s?=\\s?\"?([^;\"\\s]*);?/'", ",", "$", "this", "->", "headers", "[", "'Content-Type'", "]", ",", "$", "parameters", ")", ";", "if", "(", "count", "(", "$", "parameters", ")", ">", "0", ")", "{", "$", "charset", "=", "strtolower", "(", "trim", "(", "$", "parameters", "[", "1", "]", ",", "'\"'", ")", ")", ";", "}", "}", "$", "encoding", "=", "strtolower", "(", "$", "this", "->", "headers", "[", "'Content-Transfer-Encoding'", "]", ")", ";", "if", "(", "$", "encoding", "==", "ezcMail", "::", "QUOTED_PRINTABLE", ")", "{", "$", "this", "->", "text", "=", "quoted_printable_decode", "(", "$", "this", "->", "text", ")", ";", "}", "else", "if", "(", "$", "encoding", "==", "ezcMail", "::", "BASE64", ")", "{", "$", "this", "->", "text", "=", "base64_decode", "(", "$", "this", "->", "text", ")", ";", "}", "$", "this", "->", "text", "=", "ezcMailCharsetConverter", "::", "convertToUTF8", "(", "$", "this", "->", "text", ",", "$", "charset", ")", ";", "$", "part", "=", "new", "ezcMailText", "(", "$", "this", "->", "text", ",", "'utf-8'", ",", "ezcMail", "::", "EIGHT_BIT", ",", "$", "charset", ")", ";", "$", "part", "->", "subType", "=", "$", "this", "->", "subType", ";", "$", "part", "->", "setHeaders", "(", "$", "this", "->", "headers", "->", "getCaseSensitiveArray", "(", ")", ")", ";", "ezcMailPartParser", "::", "parsePartHeaders", "(", "$", "this", "->", "headers", ",", "$", "part", ")", ";", "$", "part", "->", "size", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "return", "$", "part", ";", "}" ]
Returns the ezcMailText part corresponding to the parsed message. @return ezcMailText
[ "Returns", "the", "ezcMailText", "part", "corresponding", "to", "the", "parsed", "message", "." ]
b0afc661105f0a2f65d49abac13956cc93c5188d
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/text_parser.php#L77-L109