repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
koolkode/view-express
src/Tree/TextNode.php
TextNode.compile
public function compile(ExpressCompiler $compiler, $flags = 0) { try { if($flags & self::FLAG_RAW) { $compiler->write(var_export($this->text, true)); } else { // Using ENT_COMPAT due to Knockout JS (and others) data binding, this is not risky // in Express-parsed attribute values due to the fact that all attribute values // are normalized to be quoted using double quotes. $compiler->out(htmlspecialchars($this->text, ENT_COMPAT | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8')); } } catch(ExpressViewException $e) { throw $e; } catch(\Exception $e) { throw new ExpressViewException('Unable to compile text node', $compiler->getResource(), $this->line, $e); } }
php
public function compile(ExpressCompiler $compiler, $flags = 0) { try { if($flags & self::FLAG_RAW) { $compiler->write(var_export($this->text, true)); } else { // Using ENT_COMPAT due to Knockout JS (and others) data binding, this is not risky // in Express-parsed attribute values due to the fact that all attribute values // are normalized to be quoted using double quotes. $compiler->out(htmlspecialchars($this->text, ENT_COMPAT | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8')); } } catch(ExpressViewException $e) { throw $e; } catch(\Exception $e) { throw new ExpressViewException('Unable to compile text node', $compiler->getResource(), $this->line, $e); } }
[ "public", "function", "compile", "(", "ExpressCompiler", "$", "compiler", ",", "$", "flags", "=", "0", ")", "{", "try", "{", "if", "(", "$", "flags", "&", "self", "::", "FLAG_RAW", ")", "{", "$", "compiler", "->", "write", "(", "var_export", "(", "$", "this", "->", "text", ",", "true", ")", ")", ";", "}", "else", "{", "// Using ENT_COMPAT due to Knockout JS (and others) data binding, this is not risky", "// in Express-parsed attribute values due to the fact that all attribute values", "// are normalized to be quoted using double quotes.", "$", "compiler", "->", "out", "(", "htmlspecialchars", "(", "$", "this", "->", "text", ",", "ENT_COMPAT", "|", "ENT_XML1", "|", "ENT_SUBSTITUTE", ",", "'UTF-8'", ")", ")", ";", "}", "}", "catch", "(", "ExpressViewException", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "ExpressViewException", "(", "'Unable to compile text node'", ",", "$", "compiler", "->", "getResource", "(", ")", ",", "$", "this", "->", "line", ",", "$", "e", ")", ";", "}", "}" ]
Compiles the text node into it's PHP code. @param ExpressCompiler $compiler @param integer $flags Raw mode is used when an element is morphed using a tag builder.
[ "Compiles", "the", "text", "node", "into", "it", "s", "PHP", "code", "." ]
a8ebe6f373b6bfe8b8818d6264535e8fe063a596
https://github.com/koolkode/view-express/blob/a8ebe6f373b6bfe8b8818d6264535e8fe063a596/src/Tree/TextNode.php#L58-L82
train
JoeBengalen/Assert
src/Assert.php
Assert.isBoolean
public static function isBoolean($value, $message = null) { if (!is_bool($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected boolean, but got %s', Helper::typeToString($value) )); } }
php
public static function isBoolean($value, $message = null) { if (!is_bool($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected boolean, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isBoolean", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_bool", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected boolean, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is boolean. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "boolean", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L32-L40
train
JoeBengalen/Assert
src/Assert.php
Assert.isInteger
public static function isInteger($value, $message = null) { if (!is_int($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected integer, but got %s', Helper::typeToString($value) )); } }
php
public static function isInteger($value, $message = null) { if (!is_int($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected integer, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isInteger", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_int", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected integer, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is integer. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "integer", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L52-L60
train
JoeBengalen/Assert
src/Assert.php
Assert.isNumeric
public static function isNumeric($value, $message = null) { if (!is_numeric($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected numeric, but got %s', Helper::typeToString($value) )); } }
php
public static function isNumeric($value, $message = null) { if (!is_numeric($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected numeric, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNumeric", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected numeric, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is numeric. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "numeric", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L72-L80
train
JoeBengalen/Assert
src/Assert.php
Assert.isFloat
public static function isFloat($value, $message = null) { if (!is_float($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected float, but got %s', Helper::typeToString($value) )); } }
php
public static function isFloat($value, $message = null) { if (!is_float($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected float, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isFloat", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_float", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected float, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is float. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "float", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L92-L100
train
JoeBengalen/Assert
src/Assert.php
Assert.isString
public static function isString($value, $message = null) { if (!is_string($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected string, but got %s', Helper::typeToString($value) )); } }
php
public static function isString($value, $message = null) { if (!is_string($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected string, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isString", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected string, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is string. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "string", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L112-L120
train
JoeBengalen/Assert
src/Assert.php
Assert.isScalar
public static function isScalar($value, $message = null) { if (!is_scalar($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected scalar, but got %s', Helper::typeToString($value) )); } }
php
public static function isScalar($value, $message = null) { if (!is_scalar($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected scalar, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isScalar", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected scalar, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is scalar. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "scalar", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L132-L140
train
JoeBengalen/Assert
src/Assert.php
Assert.isArray
public static function isArray($value, $message = null) { if (!is_array($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected array, but got %s', Helper::typeToString($value) )); } }
php
public static function isArray($value, $message = null) { if (!is_array($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected array, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isArray", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected array, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is array. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "array", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L152-L160
train
JoeBengalen/Assert
src/Assert.php
Assert.isInstanceOf
public static function isInstanceOf($value, $class, $message = null) { if (!$value instanceof $class) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected instance of %2$s, but got %s', Helper::typeToString($value), $class )); } }
php
public static function isInstanceOf($value, $class, $message = null) { if (!$value instanceof $class) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected instance of %2$s, but got %s', Helper::typeToString($value), $class )); } }
[ "public", "static", "function", "isInstanceOf", "(", "$", "value", ",", "$", "class", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "$", "value", "instanceof", "$", "class", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected instance of %2$s, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ",", "$", "class", ")", ")", ";", "}", "}" ]
Assert that the value is instance of class. @param mixed $value @param string $class @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "instance", "of", "class", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L193-L202
train
JoeBengalen/Assert
src/Assert.php
Assert.isResource
public static function isResource($value, $message = null) { if (!is_resource($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected resource, but got %s', Helper::typeToString($value) )); } }
php
public static function isResource($value, $message = null) { if (!is_resource($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected resource, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isResource", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_resource", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected resource, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is resource. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "resource", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L234-L242
train
JoeBengalen/Assert
src/Assert.php
Assert.isDirectory
public static function isDirectory($value, $message = null) { if (!is_string($value) || !is_dir($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected directory, but got %s', Helper::valueToString($value) )); } }
php
public static function isDirectory($value, $message = null) { if (!is_string($value) || !is_dir($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected directory, but got %s', Helper::valueToString($value) )); } }
[ "public", "static", "function", "isDirectory", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", "||", "!", "is_dir", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected directory, but got %s'", ",", "Helper", "::", "valueToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is directory. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "directory", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L254-L262
train
JoeBengalen/Assert
src/Assert.php
Assert.isFile
public static function isFile($value, $message = null) { if (!is_string($value) || !is_file($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected file, but got %s', Helper::valueToString($value) )); } }
php
public static function isFile($value, $message = null) { if (!is_string($value) || !is_file($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected file, but got %s', Helper::valueToString($value) )); } }
[ "public", "static", "function", "isFile", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", "||", "!", "is_file", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected file, but got %s'", ",", "Helper", "::", "valueToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is file. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "file", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L274-L282
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrBoolean
public static function isNullOrBoolean($value, $message = null) { if (!is_null($value) && !is_bool($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or boolean, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrBoolean($value, $message = null) { if (!is_null($value) && !is_bool($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or boolean, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrBoolean", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_bool", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or boolean, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or boolean. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "boolean", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L294-L302
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrInteger
public static function isNullOrInteger($value, $message = null) { if (!is_null($value) && !is_int($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or integer, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrInteger($value, $message = null) { if (!is_null($value) && !is_int($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or integer, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrInteger", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_int", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or integer, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or integer. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "integer", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L314-L322
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrNumeric
public static function isNullOrNumeric($value, $message = null) { if (!is_null($value) && !is_numeric($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or numeric, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrNumeric($value, $message = null) { if (!is_null($value) && !is_numeric($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or numeric, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrNumeric", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_numeric", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or numeric, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or numeric. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "numeric", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L334-L342
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrFloat
public static function isNullOrFloat($value, $message = null) { if (!is_null($value) && !is_float($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or float, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrFloat($value, $message = null) { if (!is_null($value) && !is_float($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or float, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrFloat", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_float", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or float, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or float. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "float", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L354-L362
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrString
public static function isNullOrString($value, $message = null) { if (!is_null($value) && !is_string($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or string, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrString($value, $message = null) { if (!is_null($value) && !is_string($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or string, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrString", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_string", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or string, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or string. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "string", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L374-L382
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrScalar
public static function isNullOrScalar($value, $message = null) { if (!is_null($value) && !is_scalar($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or scalar, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrScalar($value, $message = null) { if (!is_null($value) && !is_scalar($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or scalar, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrScalar", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_scalar", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or scalar, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or scalar. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "scalar", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L394-L402
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrArray
public static function isNullOrArray($value, $message = null) { if (!is_null($value) && !is_array($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or array, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrArray($value, $message = null) { if (!is_null($value) && !is_array($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or array, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrArray", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_array", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or array, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or array. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "array", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L414-L422
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrCallable
public static function isNullOrCallable($value, $message = null) { if (!is_null($value) && !is_callable($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or callable, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrCallable($value, $message = null) { if (!is_null($value) && !is_callable($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or callable, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrCallable", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_callable", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or callable, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or callable. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "callable", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L434-L442
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrInstanceOf
public static function isNullOrInstanceOf($value, $class, $message = null) { if (!is_null($value) && !$value instanceof $class) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or instance of %2$s, but got %s', Helper::typeToString($value), $class )); } }
php
public static function isNullOrInstanceOf($value, $class, $message = null) { if (!is_null($value) && !$value instanceof $class) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or instance of %2$s, but got %s', Helper::typeToString($value), $class )); } }
[ "public", "static", "function", "isNullOrInstanceOf", "(", "$", "value", ",", "$", "class", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "$", "value", "instanceof", "$", "class", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or instance of %2$s, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ",", "$", "class", ")", ")", ";", "}", "}" ]
Assert that the value is null or instance of class. @param mixed $value @param string $class @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "instance", "of", "class", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L455-L464
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrTraversable
public static function isNullOrTraversable($value, $message = null) { if (!is_null($value) && !is_array($value) && !$value instanceof Traversable) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or traversable, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrTraversable($value, $message = null) { if (!is_null($value) && !is_array($value) && !$value instanceof Traversable) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or traversable, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrTraversable", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_array", "(", "$", "value", ")", "&&", "!", "$", "value", "instanceof", "Traversable", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or traversable, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or traversable. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "traversable", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L476-L484
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrResource
public static function isNullOrResource($value, $message = null) { if (!is_null($value) && !is_resource($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or resource, but got %s', Helper::typeToString($value) )); } }
php
public static function isNullOrResource($value, $message = null) { if (!is_null($value) && !is_resource($value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or resource, but got %s', Helper::typeToString($value) )); } }
[ "public", "static", "function", "isNullOrResource", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "is_resource", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or resource, but got %s'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or resource. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "resource", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L496-L504
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrDirectory
public static function isNullOrDirectory($value, $message = null) { if (!is_null($value) && !(is_string($value) && is_dir($value))) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or directory, but got %s', Helper::valueToString($value) )); } }
php
public static function isNullOrDirectory($value, $message = null) { if (!is_null($value) && !(is_string($value) && is_dir($value))) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or directory, but got %s', Helper::valueToString($value) )); } }
[ "public", "static", "function", "isNullOrDirectory", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "(", "is_string", "(", "$", "value", ")", "&&", "is_dir", "(", "$", "value", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or directory, but got %s'", ",", "Helper", "::", "valueToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or directory. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "directory", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L516-L524
train
JoeBengalen/Assert
src/Assert.php
Assert.isNullOrFile
public static function isNullOrFile($value, $message = null) { if (!is_null($value) && !(is_string($value) && is_file($value))) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or file, but got %s', Helper::valueToString($value) )); } }
php
public static function isNullOrFile($value, $message = null) { if (!is_null($value) && !(is_string($value) && is_file($value))) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected null or file, but got %s', Helper::valueToString($value) )); } }
[ "public", "static", "function", "isNullOrFile", "(", "$", "value", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", "&&", "!", "(", "is_string", "(", "$", "value", ")", "&&", "is_file", "(", "$", "value", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected null or file, but got %s'", ",", "Helper", "::", "valueToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that the value is null or file. @param mixed $value @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "the", "value", "is", "null", "or", "file", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L536-L544
train
JoeBengalen/Assert
src/Assert.php
Assert.keyExists
public static function keyExists($value, $key, $message = null) { if (!array_key_exists($key, $value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected array key %2$s to exist', Helper::typeToString($value), Helper::valueToString($key) )); } }
php
public static function keyExists($value, $key, $message = null) { if (!array_key_exists($key, $value)) { throw new InvalidArgumentException(sprintf( $message ?: 'Expected array key %2$s to exist', Helper::typeToString($value), Helper::valueToString($key) )); } }
[ "public", "static", "function", "keyExists", "(", "$", "value", ",", "$", "key", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Expected array key %2$s to exist'", ",", "Helper", "::", "typeToString", "(", "$", "value", ")", ",", "Helper", "::", "valueToString", "(", "$", "key", ")", ")", ")", ";", "}", "}" ]
Assert that key exists in value. @param mixed $value @param string $key @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "key", "exists", "in", "value", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L557-L566
train
JoeBengalen/Assert
src/Assert.php
Assert.inArray
public static function inArray($value, array $array, $message = null) { if (!in_array($value, $array)) { throw new InvalidArgumentException(sprintf( $message ?: 'Value %s is not in array', Helper::valueToString($value) )); } }
php
public static function inArray($value, array $array, $message = null) { if (!in_array($value, $array)) { throw new InvalidArgumentException(sprintf( $message ?: 'Value %s is not in array', Helper::valueToString($value) )); } }
[ "public", "static", "function", "inArray", "(", "$", "value", ",", "array", "$", "array", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "in_array", "(", "$", "value", ",", "$", "array", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", "?", ":", "'Value %s is not in array'", ",", "Helper", "::", "valueToString", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Assert that value is in array. @param mixed $value @param array $array @param string $message @return void @throws InvalidArgumentException
[ "Assert", "that", "value", "is", "in", "array", "." ]
022b3f698d6bb94bda10a3e5f2f9f2219796c233
https://github.com/JoeBengalen/Assert/blob/022b3f698d6bb94bda10a3e5f2f9f2219796c233/src/Assert.php#L579-L587
train
vespolina/action
lib/Vespolina/Action/Manager/ActionManager.php
ActionManager.doExecute
protected function doExecute(ActionInterface $action, $reprocess = false) { // The first question is, are we even allowed to reprocess this action? $definition = $this->findActionDefinitionByName($action->getName()); if (null == $definition) { throw new \RuntimeException(sprintf('Could not load action definition for action %a', $action->getName())); } $handler = $this->handlers[$definition->getHandlerClass()]; if ($reprocess) { // Delegate to the action handler to see if the action is reprocessable $isReprocessable = $handler->isReprocessable($action, $definition); if (false == $isReprocessable) { throw new \RuntimeException(sprintf('Reprocessing is not allowed for action %a', $action->getName())); } } // Cool, we can process the action! $handler->process($action, $definition); // Save the state of the action $this->actionGateway->updateAction($action); }
php
protected function doExecute(ActionInterface $action, $reprocess = false) { // The first question is, are we even allowed to reprocess this action? $definition = $this->findActionDefinitionByName($action->getName()); if (null == $definition) { throw new \RuntimeException(sprintf('Could not load action definition for action %a', $action->getName())); } $handler = $this->handlers[$definition->getHandlerClass()]; if ($reprocess) { // Delegate to the action handler to see if the action is reprocessable $isReprocessable = $handler->isReprocessable($action, $definition); if (false == $isReprocessable) { throw new \RuntimeException(sprintf('Reprocessing is not allowed for action %a', $action->getName())); } } // Cool, we can process the action! $handler->process($action, $definition); // Save the state of the action $this->actionGateway->updateAction($action); }
[ "protected", "function", "doExecute", "(", "ActionInterface", "$", "action", ",", "$", "reprocess", "=", "false", ")", "{", "// The first question is, are we even allowed to reprocess this action?", "$", "definition", "=", "$", "this", "->", "findActionDefinitionByName", "(", "$", "action", "->", "getName", "(", ")", ")", ";", "if", "(", "null", "==", "$", "definition", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Could not load action definition for action %a'", ",", "$", "action", "->", "getName", "(", ")", ")", ")", ";", "}", "$", "handler", "=", "$", "this", "->", "handlers", "[", "$", "definition", "->", "getHandlerClass", "(", ")", "]", ";", "if", "(", "$", "reprocess", ")", "{", "// Delegate to the action handler to see if the action is reprocessable", "$", "isReprocessable", "=", "$", "handler", "->", "isReprocessable", "(", "$", "action", ",", "$", "definition", ")", ";", "if", "(", "false", "==", "$", "isReprocessable", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Reprocessing is not allowed for action %a'", ",", "$", "action", "->", "getName", "(", ")", ")", ")", ";", "}", "}", "// Cool, we can process the action!", "$", "handler", "->", "process", "(", "$", "action", ",", "$", "definition", ")", ";", "// Save the state of the action", "$", "this", "->", "actionGateway", "->", "updateAction", "(", "$", "action", ")", ";", "}" ]
Start the execution of an action or schedule the action for processing later on @param ActionInterface $action @param bool $reprocess
[ "Start", "the", "execution", "of", "an", "action", "or", "schedule", "the", "action", "for", "processing", "later", "on" ]
798baf0401c81cc507c51a54bf57fdd3505f5b92
https://github.com/vespolina/action/blob/798baf0401c81cc507c51a54bf57fdd3505f5b92/lib/Vespolina/Action/Manager/ActionManager.php#L138-L163
train
dubhunter/talon
src/Http.php
Http.getStatusMessage
public static function getStatusMessage($code) { if (!$code) { return ''; } return isset(self::$statusMessages[$code]) ? self::$statusMessages[$code] : ''; }
php
public static function getStatusMessage($code) { if (!$code) { return ''; } return isset(self::$statusMessages[$code]) ? self::$statusMessages[$code] : ''; }
[ "public", "static", "function", "getStatusMessage", "(", "$", "code", ")", "{", "if", "(", "!", "$", "code", ")", "{", "return", "''", ";", "}", "return", "isset", "(", "self", "::", "$", "statusMessages", "[", "$", "code", "]", ")", "?", "self", "::", "$", "statusMessages", "[", "$", "code", "]", ":", "''", ";", "}" ]
Returns a messages for a given code @param $code @return string
[ "Returns", "a", "messages", "for", "a", "given", "code" ]
308b7284556dfaff0d9ac4c7739dc6a46930ef36
https://github.com/dubhunter/talon/blob/308b7284556dfaff0d9ac4c7739dc6a46930ef36/src/Http.php#L85-L91
train
Aprila/Quick
src/Quick/Presenter/ListPresenter.php
ListPresenter.addOrEditObject
protected function addOrEditObject($data = [], $redirect = TRUE) { try { if ($this->detailObject) { // Edit object $this->canUser('edit'); $this->mainManager->edit($this->detailObject->id, $data); $this->flashMessage('Object saved'); } else { // Add object $this->canUser('add'); $this->mainManager->add($data); $this->flashMessage('Object added'); } } catch (\Exception $e) { $this->flashMessage('Upps.', 'error'); } if ($redirect) { $this->redirect('default'); } }
php
protected function addOrEditObject($data = [], $redirect = TRUE) { try { if ($this->detailObject) { // Edit object $this->canUser('edit'); $this->mainManager->edit($this->detailObject->id, $data); $this->flashMessage('Object saved'); } else { // Add object $this->canUser('add'); $this->mainManager->add($data); $this->flashMessage('Object added'); } } catch (\Exception $e) { $this->flashMessage('Upps.', 'error'); } if ($redirect) { $this->redirect('default'); } }
[ "protected", "function", "addOrEditObject", "(", "$", "data", "=", "[", "]", ",", "$", "redirect", "=", "TRUE", ")", "{", "try", "{", "if", "(", "$", "this", "->", "detailObject", ")", "{", "// Edit object", "$", "this", "->", "canUser", "(", "'edit'", ")", ";", "$", "this", "->", "mainManager", "->", "edit", "(", "$", "this", "->", "detailObject", "->", "id", ",", "$", "data", ")", ";", "$", "this", "->", "flashMessage", "(", "'Object saved'", ")", ";", "}", "else", "{", "// Add object", "$", "this", "->", "canUser", "(", "'add'", ")", ";", "$", "this", "->", "mainManager", "->", "add", "(", "$", "data", ")", ";", "$", "this", "->", "flashMessage", "(", "'Object added'", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "flashMessage", "(", "'Upps.'", ",", "'error'", ")", ";", "}", "if", "(", "$", "redirect", ")", "{", "$", "this", "->", "redirect", "(", "'default'", ")", ";", "}", "}" ]
Simple implementation add or edit object @param array $data @param bool $redirect
[ "Simple", "implementation", "add", "or", "edit", "object" ]
53c3830c7256d6f46f6bc352d7e0b022f0c81277
https://github.com/Aprila/Quick/blob/53c3830c7256d6f46f6bc352d7e0b022f0c81277/src/Quick/Presenter/ListPresenter.php#L168-L192
train
gplcart/backup
controllers/Backup.php
Backup.listBackup
public function listBackup() { $this->downloadListBackup(); $this->actionListBackup(); $this->setTitleListBackup(); $this->setBreadcrumbListBackup(); $this->setFilterListBackup(); $this->setPagerListBackup(); $this->setData('backups', $this->getListBackup()); $this->setData('handlers', $this->backup->getHandlers()); $this->outputListBackup(); }
php
public function listBackup() { $this->downloadListBackup(); $this->actionListBackup(); $this->setTitleListBackup(); $this->setBreadcrumbListBackup(); $this->setFilterListBackup(); $this->setPagerListBackup(); $this->setData('backups', $this->getListBackup()); $this->setData('handlers', $this->backup->getHandlers()); $this->outputListBackup(); }
[ "public", "function", "listBackup", "(", ")", "{", "$", "this", "->", "downloadListBackup", "(", ")", ";", "$", "this", "->", "actionListBackup", "(", ")", ";", "$", "this", "->", "setTitleListBackup", "(", ")", ";", "$", "this", "->", "setBreadcrumbListBackup", "(", ")", ";", "$", "this", "->", "setFilterListBackup", "(", ")", ";", "$", "this", "->", "setPagerListBackup", "(", ")", ";", "$", "this", "->", "setData", "(", "'backups'", ",", "$", "this", "->", "getListBackup", "(", ")", ")", ";", "$", "this", "->", "setData", "(", "'handlers'", ",", "$", "this", "->", "backup", "->", "getHandlers", "(", ")", ")", ";", "$", "this", "->", "outputListBackup", "(", ")", ";", "}" ]
Displays the backup overview page
[ "Displays", "the", "backup", "overview", "page" ]
5838e2f47f0bb8c2e18b6697e20bec5682b71393
https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/controllers/Backup.php#L46-L59
train
gplcart/backup
controllers/Backup.php
Backup.downloadListBackup
protected function downloadListBackup() { $backup_id = $this->getQuery('download'); if (empty($backup_id)) { return null; } $this->controlAccess('backup_download'); $backup = $this->backup->get($backup_id); if (!empty($backup['path'])) { $this->download(gplcart_file_absolute($backup['path'])); } }
php
protected function downloadListBackup() { $backup_id = $this->getQuery('download'); if (empty($backup_id)) { return null; } $this->controlAccess('backup_download'); $backup = $this->backup->get($backup_id); if (!empty($backup['path'])) { $this->download(gplcart_file_absolute($backup['path'])); } }
[ "protected", "function", "downloadListBackup", "(", ")", "{", "$", "backup_id", "=", "$", "this", "->", "getQuery", "(", "'download'", ")", ";", "if", "(", "empty", "(", "$", "backup_id", ")", ")", "{", "return", "null", ";", "}", "$", "this", "->", "controlAccess", "(", "'backup_download'", ")", ";", "$", "backup", "=", "$", "this", "->", "backup", "->", "get", "(", "$", "backup_id", ")", ";", "if", "(", "!", "empty", "(", "$", "backup", "[", "'path'", "]", ")", ")", "{", "$", "this", "->", "download", "(", "gplcart_file_absolute", "(", "$", "backup", "[", "'path'", "]", ")", ")", ";", "}", "}" ]
Downloads a backup
[ "Downloads", "a", "backup" ]
5838e2f47f0bb8c2e18b6697e20bec5682b71393
https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/controllers/Backup.php#L73-L88
train
gplcart/backup
controllers/Backup.php
Backup.actionListBackup
protected function actionListBackup() { list($selected, $action) = $this->getPostedAction(); $deleted = 0; foreach ($selected as $id) { if ($action === 'delete' && $this->access('backup_delete')) { $deleted += (int) $this->backup->delete($id); } } if ($deleted > 0) { $message = $this->text('Deleted %num item(s)', array('%num' => $deleted)); $this->setMessage($message, 'success'); } }
php
protected function actionListBackup() { list($selected, $action) = $this->getPostedAction(); $deleted = 0; foreach ($selected as $id) { if ($action === 'delete' && $this->access('backup_delete')) { $deleted += (int) $this->backup->delete($id); } } if ($deleted > 0) { $message = $this->text('Deleted %num item(s)', array('%num' => $deleted)); $this->setMessage($message, 'success'); } }
[ "protected", "function", "actionListBackup", "(", ")", "{", "list", "(", "$", "selected", ",", "$", "action", ")", "=", "$", "this", "->", "getPostedAction", "(", ")", ";", "$", "deleted", "=", "0", ";", "foreach", "(", "$", "selected", "as", "$", "id", ")", "{", "if", "(", "$", "action", "===", "'delete'", "&&", "$", "this", "->", "access", "(", "'backup_delete'", ")", ")", "{", "$", "deleted", "+=", "(", "int", ")", "$", "this", "->", "backup", "->", "delete", "(", "$", "id", ")", ";", "}", "}", "if", "(", "$", "deleted", ">", "0", ")", "{", "$", "message", "=", "$", "this", "->", "text", "(", "'Deleted %num item(s)'", ",", "array", "(", "'%num'", "=>", "$", "deleted", ")", ")", ";", "$", "this", "->", "setMessage", "(", "$", "message", ",", "'success'", ")", ";", "}", "}" ]
Applies an action to the selected backups
[ "Applies", "an", "action", "to", "the", "selected", "backups" ]
5838e2f47f0bb8c2e18b6697e20bec5682b71393
https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/controllers/Backup.php#L93-L109
train
gplcart/backup
controllers/Backup.php
Backup.getListBackup
protected function getListBackup() { $options = $this->query_filter; $options['limit'] = $this->data_limit; return $this->backup->getList($options); }
php
protected function getListBackup() { $options = $this->query_filter; $options['limit'] = $this->data_limit; return $this->backup->getList($options); }
[ "protected", "function", "getListBackup", "(", ")", "{", "$", "options", "=", "$", "this", "->", "query_filter", ";", "$", "options", "[", "'limit'", "]", "=", "$", "this", "->", "data_limit", ";", "return", "$", "this", "->", "backup", "->", "getList", "(", "$", "options", ")", ";", "}" ]
Returns an array of backups @return array
[ "Returns", "an", "array", "of", "backups" ]
5838e2f47f0bb8c2e18b6697e20bec5682b71393
https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/controllers/Backup.php#L144-L149
train
Kris-Kuiper/sFire-Framework
src/System/Captcha.php
Captcha.setImage
public function setImage($image) { if(false === is_string($image)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($image)), E_USER_ERROR); } $file = new File($image); if(false === $file -> exists()) { return trigger_error(sprintf('Argument 1 passed to %s() must be an existing image', __METHOD__), E_USER_ERROR); } if(false === in_array(exif_imagetype($image), [IMAGETYPE_JPEG, IMAGETYPE_PNG])) { return trigger_error(sprintf('Argument 1 passed to %s() must be an valid image (jpg, jpeg or png)', __METHOD__), E_USER_ERROR); } $this -> image = $file; return $this; }
php
public function setImage($image) { if(false === is_string($image)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($image)), E_USER_ERROR); } $file = new File($image); if(false === $file -> exists()) { return trigger_error(sprintf('Argument 1 passed to %s() must be an existing image', __METHOD__), E_USER_ERROR); } if(false === in_array(exif_imagetype($image), [IMAGETYPE_JPEG, IMAGETYPE_PNG])) { return trigger_error(sprintf('Argument 1 passed to %s() must be an valid image (jpg, jpeg or png)', __METHOD__), E_USER_ERROR); } $this -> image = $file; return $this; }
[ "public", "function", "setImage", "(", "$", "image", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "image", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "image", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "file", "=", "new", "File", "(", "$", "image", ")", ";", "if", "(", "false", "===", "$", "file", "->", "exists", "(", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be an existing image'", ",", "__METHOD__", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "in_array", "(", "exif_imagetype", "(", "$", "image", ")", ",", "[", "IMAGETYPE_JPEG", ",", "IMAGETYPE_PNG", "]", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be an valid image (jpg, jpeg or png)'", ",", "__METHOD__", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "image", "=", "$", "file", ";", "return", "$", "this", ";", "}" ]
Set image by giving a file path as image @param string $image @return sFire\Captcha\Captcha
[ "Set", "image", "by", "giving", "a", "file", "path", "as", "image" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Captcha.php#L72-L91
train
Kris-Kuiper/sFire-Framework
src/System/Captcha.php
Captcha.setFont
public function setFont($font) { if(false === is_string($font)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($font)), E_USER_ERROR); } $file = new File($font); if(false === $file -> exists()) { return trigger_error(sprintf('Argument 1 passed to %s() must be an existing font', __METHOD__), E_USER_ERROR); } $this -> font = $file; return $this; }
php
public function setFont($font) { if(false === is_string($font)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($font)), E_USER_ERROR); } $file = new File($font); if(false === $file -> exists()) { return trigger_error(sprintf('Argument 1 passed to %s() must be an existing font', __METHOD__), E_USER_ERROR); } $this -> font = $file; return $this; }
[ "public", "function", "setFont", "(", "$", "font", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "font", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "font", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "file", "=", "new", "File", "(", "$", "font", ")", ";", "if", "(", "false", "===", "$", "file", "->", "exists", "(", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be an existing font'", ",", "__METHOD__", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "font", "=", "$", "file", ";", "return", "$", "this", ";", "}" ]
Set the font by giving a file path as font @param string $font @return sFire\Captcha\Captcha
[ "Set", "the", "font", "by", "giving", "a", "file", "path", "as", "font" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Captcha.php#L99-L114
train
Kris-Kuiper/sFire-Framework
src/System/Captcha.php
Captcha.setFontSize
public function setFontSize($min, $max = null) { if(false === ('-' . intval($min) == '-' . $min)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($min)), E_USER_ERROR); } if(null !== $max && false === ('-' . intval($max) == '-' . $max)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($max)), E_USER_ERROR); } $this -> fontsize = ['min' => $min, 'max' => ($max !== null ? $max : $min)]; return $this; }
php
public function setFontSize($min, $max = null) { if(false === ('-' . intval($min) == '-' . $min)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($min)), E_USER_ERROR); } if(null !== $max && false === ('-' . intval($max) == '-' . $max)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($max)), E_USER_ERROR); } $this -> fontsize = ['min' => $min, 'max' => ($max !== null ? $max : $min)]; return $this; }
[ "public", "function", "setFontSize", "(", "$", "min", ",", "$", "max", "=", "null", ")", "{", "if", "(", "false", "===", "(", "'-'", ".", "intval", "(", "$", "min", ")", "==", "'-'", ".", "$", "min", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type integer, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "min", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "null", "!==", "$", "max", "&&", "false", "===", "(", "'-'", ".", "intval", "(", "$", "max", ")", "==", "'-'", ".", "$", "max", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 2 passed to %s() must be of the type integer, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "max", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "fontsize", "=", "[", "'min'", "=>", "$", "min", ",", "'max'", "=>", "(", "$", "max", "!==", "null", "?", "$", "max", ":", "$", "min", ")", "]", ";", "return", "$", "this", ";", "}" ]
Set the fontsize min. and max. If no max. is set, max. will be the same as min. @param int $min @param int $max @return sFire\Captcha\Captcha
[ "Set", "the", "fontsize", "min", ".", "and", "max", ".", "If", "no", "max", ".", "is", "set", "max", ".", "will", "be", "the", "same", "as", "min", "." ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Captcha.php#L152-L165
train
Kris-Kuiper/sFire-Framework
src/System/Captcha.php
Captcha.setAngle
public function setAngle($min, $max = null) { if(false === ('-' . intval($min) == '-' . $min)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($min)), E_USER_ERROR); } if(null !== $max && false === ('-' . intval($max) == '-' . $max)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($max)), E_USER_ERROR); } $this -> angle = ['min' => $min, 'max' => ($max !== null ? $max : $min)]; return $this; }
php
public function setAngle($min, $max = null) { if(false === ('-' . intval($min) == '-' . $min)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($min)), E_USER_ERROR); } if(null !== $max && false === ('-' . intval($max) == '-' . $max)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($max)), E_USER_ERROR); } $this -> angle = ['min' => $min, 'max' => ($max !== null ? $max : $min)]; return $this; }
[ "public", "function", "setAngle", "(", "$", "min", ",", "$", "max", "=", "null", ")", "{", "if", "(", "false", "===", "(", "'-'", ".", "intval", "(", "$", "min", ")", "==", "'-'", ".", "$", "min", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type integer, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "min", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "null", "!==", "$", "max", "&&", "false", "===", "(", "'-'", ".", "intval", "(", "$", "max", ")", "==", "'-'", ".", "$", "max", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 2 passed to %s() must be of the type integer, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "max", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "angle", "=", "[", "'min'", "=>", "$", "min", ",", "'max'", "=>", "(", "$", "max", "!==", "null", "?", "$", "max", ":", "$", "min", ")", "]", ";", "return", "$", "this", ";", "}" ]
Set the angle min. and max. If no max. is set, max. will be the same as min. @param int $min @param int $max @return sFire\Captcha\Captcha
[ "Set", "the", "angle", "min", ".", "and", "max", ".", "If", "no", "max", ".", "is", "set", "max", ".", "will", "be", "the", "same", "as", "min", "." ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Captcha.php#L174-L187
train
essence/dom
src/Tag.php
Tag.matches
public function matches($name, $pattern, &$matches = []) { return preg_match($pattern, $this->get($name), $matches); }
php
public function matches($name, $pattern, &$matches = []) { return preg_match($pattern, $this->get($name), $matches); }
[ "public", "function", "matches", "(", "$", "name", ",", "$", "pattern", ",", "&", "$", "matches", "=", "[", "]", ")", "{", "return", "preg_match", "(", "$", "pattern", ",", "$", "this", "->", "get", "(", "$", "name", ")", ",", "$", "matches", ")", ";", "}" ]
Tests if the value of an attribute matches the given pattern. @param string $name Attribute name. @param string $pattern Pattern. @param array $matches Search results. @return boolean If the attribute value matches the pattern.
[ "Tests", "if", "the", "value", "of", "an", "attribute", "matches", "the", "given", "pattern", "." ]
e5776d2286f4ccbd048d160c28ac77ccc6d68f3a
https://github.com/essence/dom/blob/e5776d2286f4ccbd048d160c28ac77ccc6d68f3a/src/Tag.php#L36-L38
train
dms-org/common.structure
src/Colour/TransparentColour.php
TransparentColour.fromRgba
public static function fromRgba(int $red, int $green, int $blue, float $alpha) : TransparentColour { return new self(new Colour($red, $green, $blue), $alpha); }
php
public static function fromRgba(int $red, int $green, int $blue, float $alpha) : TransparentColour { return new self(new Colour($red, $green, $blue), $alpha); }
[ "public", "static", "function", "fromRgba", "(", "int", "$", "red", ",", "int", "$", "green", ",", "int", "$", "blue", ",", "float", "$", "alpha", ")", ":", "TransparentColour", "{", "return", "new", "self", "(", "new", "Colour", "(", "$", "red", ",", "$", "green", ",", "$", "blue", ")", ",", "$", "alpha", ")", ";", "}" ]
Creates a new colour from the supplied rgba values @param int $red @param int $green @param int $blue @param float $alpha @return TransparentColour
[ "Creates", "a", "new", "colour", "from", "the", "supplied", "rgba", "values" ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/TransparentColour.php#L74-L77
train
dms-org/common.structure
src/Colour/TransparentColour.php
TransparentColour.fromRgbaString
public static function fromRgbaString(string $string) : TransparentColour { list($r, $g, $b, $a) = ColourStringParser::parseRgbaString($string); return new self(new Colour($r, $g, $b), $a); }
php
public static function fromRgbaString(string $string) : TransparentColour { list($r, $g, $b, $a) = ColourStringParser::parseRgbaString($string); return new self(new Colour($r, $g, $b), $a); }
[ "public", "static", "function", "fromRgbaString", "(", "string", "$", "string", ")", ":", "TransparentColour", "{", "list", "(", "$", "r", ",", "$", "g", ",", "$", "b", ",", "$", "a", ")", "=", "ColourStringParser", "::", "parseRgbaString", "(", "$", "string", ")", ";", "return", "new", "self", "(", "new", "Colour", "(", "$", "r", ",", "$", "g", ",", "$", "b", ")", ",", "$", "a", ")", ";", "}" ]
Creates a new colour from the supplied rgba string value @param string $string eg: "rgba(100, 100, 100, 0.5)" @return TransparentColour @throws InvalidArgumentException
[ "Creates", "a", "new", "colour", "from", "the", "supplied", "rgba", "string", "value" ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/TransparentColour.php#L87-L92
train
battis/configxml
src/ConfigXML.php
ConfigXML.toArray
public function toArray($query) { $nodes = $this->xpath->query((string) $query); if ($nodes->length) { $result = array(); foreach ($nodes as $node) { $result[] = json_decode( json_encode( simplexml_load_string( $this->dom->saveXML($node) ) ), true ); } return $result; } return null; }
php
public function toArray($query) { $nodes = $this->xpath->query((string) $query); if ($nodes->length) { $result = array(); foreach ($nodes as $node) { $result[] = json_decode( json_encode( simplexml_load_string( $this->dom->saveXML($node) ) ), true ); } return $result; } return null; }
[ "public", "function", "toArray", "(", "$", "query", ")", "{", "$", "nodes", "=", "$", "this", "->", "xpath", "->", "query", "(", "(", "string", ")", "$", "query", ")", ";", "if", "(", "$", "nodes", "->", "length", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "$", "result", "[", "]", "=", "json_decode", "(", "json_encode", "(", "simplexml_load_string", "(", "$", "this", "->", "dom", "->", "saveXML", "(", "$", "node", ")", ")", ")", ",", "true", ")", ";", "}", "return", "$", "result", ";", "}", "return", "null", ";", "}" ]
Extract an XPath query as an associative array @param string $query XPath query @return array An array of matches converted to associative arrays. `null` if no matches found.
[ "Extract", "an", "XPath", "query", "as", "an", "associative", "array" ]
7c6aeddce5c26bee553d7160bae47b30344ae122
https://github.com/battis/configxml/blob/7c6aeddce5c26bee553d7160bae47b30344ae122/src/ConfigXML.php#L74-L92
train
battis/configxml
src/ConfigXML.php
ConfigXML.recursiveImplode
private static function recursiveImplode($glue, $pieces) { if (is_array($pieces)) { $strings = array(); foreach ($pieces as $key => $piece) { if (is_int($key) || $key !== self::ATTRIBUTES) { if (is_array($piece)) { $strings[$key] = static::recursiveImplode($glue, $piece); } else { $strings[$key] = (string) $piece; } } } return implode($glue, $strings); } else { return (string) $pieces; } }
php
private static function recursiveImplode($glue, $pieces) { if (is_array($pieces)) { $strings = array(); foreach ($pieces as $key => $piece) { if (is_int($key) || $key !== self::ATTRIBUTES) { if (is_array($piece)) { $strings[$key] = static::recursiveImplode($glue, $piece); } else { $strings[$key] = (string) $piece; } } } return implode($glue, $strings); } else { return (string) $pieces; } }
[ "private", "static", "function", "recursiveImplode", "(", "$", "glue", ",", "$", "pieces", ")", "{", "if", "(", "is_array", "(", "$", "pieces", ")", ")", "{", "$", "strings", "=", "array", "(", ")", ";", "foreach", "(", "$", "pieces", "as", "$", "key", "=>", "$", "piece", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", "||", "$", "key", "!==", "self", "::", "ATTRIBUTES", ")", "{", "if", "(", "is_array", "(", "$", "piece", ")", ")", "{", "$", "strings", "[", "$", "key", "]", "=", "static", "::", "recursiveImplode", "(", "$", "glue", ",", "$", "piece", ")", ";", "}", "else", "{", "$", "strings", "[", "$", "key", "]", "=", "(", "string", ")", "$", "piece", ";", "}", "}", "}", "return", "implode", "(", "$", "glue", ",", "$", "strings", ")", ";", "}", "else", "{", "return", "(", "string", ")", "$", "pieces", ";", "}", "}" ]
Recursively implode nested ArrayAccess @param string $glue Glue to hold together imploded list of pieces @param array $pieces @return string
[ "Recursively", "implode", "nested", "ArrayAccess" ]
7c6aeddce5c26bee553d7160bae47b30344ae122
https://github.com/battis/configxml/blob/7c6aeddce5c26bee553d7160bae47b30344ae122/src/ConfigXML.php#L114-L131
train
battis/configxml
src/ConfigXML.php
ConfigXML.DOMtoArray
private static function DOMtoArray($node) { $occurence = array(); $result = null; if ($node->childNodes) { foreach ($node->childNodes as $child) { if (isset($occurence[$child->nodeName])) { $occurence[$child->nodeName]++; } else { $occurence[$child->nodeName] = 1; } } } if ($node->nodeType == XML_TEXT_NODE || $node->nodeType == XML_CDATA_SECTION_NODE) { $result = html_entity_decode( htmlentities( (string) $node->nodeValue, ENT_COMPAT, 'UTF-8' ), ENT_COMPAT, 'ISO-8859-15' ); } else { if ($node->hasChildNodes()) { $children = $node->childNodes; for ($i=0; $i<$children->length; $i++) { $child = $children->item($i); switch ($child->nodeName) { case '#cdata-section': case '#text': $text = static::DOMtoArray($child); if (trim($text) != '') { $result[self::VALUE] = static::DOMtoArray($child); }; break; default: if ($occurence[$child->nodeName] > 1) { $result[$child->nodeName][] = static::DOMtoArray($child); } else { $result[$child->nodeName] = static::DOMtoArray($child); } } } } if ($node->hasAttributes()) { $attributes = $node->attributes; if (!is_null($attributes)) { foreach ($attributes as $key => $attr) { $result[self::ATTRIBUTES][$attr->name] = $attr->value; } } } } return $result; }
php
private static function DOMtoArray($node) { $occurence = array(); $result = null; if ($node->childNodes) { foreach ($node->childNodes as $child) { if (isset($occurence[$child->nodeName])) { $occurence[$child->nodeName]++; } else { $occurence[$child->nodeName] = 1; } } } if ($node->nodeType == XML_TEXT_NODE || $node->nodeType == XML_CDATA_SECTION_NODE) { $result = html_entity_decode( htmlentities( (string) $node->nodeValue, ENT_COMPAT, 'UTF-8' ), ENT_COMPAT, 'ISO-8859-15' ); } else { if ($node->hasChildNodes()) { $children = $node->childNodes; for ($i=0; $i<$children->length; $i++) { $child = $children->item($i); switch ($child->nodeName) { case '#cdata-section': case '#text': $text = static::DOMtoArray($child); if (trim($text) != '') { $result[self::VALUE] = static::DOMtoArray($child); }; break; default: if ($occurence[$child->nodeName] > 1) { $result[$child->nodeName][] = static::DOMtoArray($child); } else { $result[$child->nodeName] = static::DOMtoArray($child); } } } } if ($node->hasAttributes()) { $attributes = $node->attributes; if (!is_null($attributes)) { foreach ($attributes as $key => $attr) { $result[self::ATTRIBUTES][$attr->name] = $attr->value; } } } } return $result; }
[ "private", "static", "function", "DOMtoArray", "(", "$", "node", ")", "{", "$", "occurence", "=", "array", "(", ")", ";", "$", "result", "=", "null", ";", "if", "(", "$", "node", "->", "childNodes", ")", "{", "foreach", "(", "$", "node", "->", "childNodes", "as", "$", "child", ")", "{", "if", "(", "isset", "(", "$", "occurence", "[", "$", "child", "->", "nodeName", "]", ")", ")", "{", "$", "occurence", "[", "$", "child", "->", "nodeName", "]", "++", ";", "}", "else", "{", "$", "occurence", "[", "$", "child", "->", "nodeName", "]", "=", "1", ";", "}", "}", "}", "if", "(", "$", "node", "->", "nodeType", "==", "XML_TEXT_NODE", "||", "$", "node", "->", "nodeType", "==", "XML_CDATA_SECTION_NODE", ")", "{", "$", "result", "=", "html_entity_decode", "(", "htmlentities", "(", "(", "string", ")", "$", "node", "->", "nodeValue", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ",", "ENT_COMPAT", ",", "'ISO-8859-15'", ")", ";", "}", "else", "{", "if", "(", "$", "node", "->", "hasChildNodes", "(", ")", ")", "{", "$", "children", "=", "$", "node", "->", "childNodes", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "children", "->", "length", ";", "$", "i", "++", ")", "{", "$", "child", "=", "$", "children", "->", "item", "(", "$", "i", ")", ";", "switch", "(", "$", "child", "->", "nodeName", ")", "{", "case", "'#cdata-section'", ":", "case", "'#text'", ":", "$", "text", "=", "static", "::", "DOMtoArray", "(", "$", "child", ")", ";", "if", "(", "trim", "(", "$", "text", ")", "!=", "''", ")", "{", "$", "result", "[", "self", "::", "VALUE", "]", "=", "static", "::", "DOMtoArray", "(", "$", "child", ")", ";", "}", ";", "break", ";", "default", ":", "if", "(", "$", "occurence", "[", "$", "child", "->", "nodeName", "]", ">", "1", ")", "{", "$", "result", "[", "$", "child", "->", "nodeName", "]", "[", "]", "=", "static", "::", "DOMtoArray", "(", "$", "child", ")", ";", "}", "else", "{", "$", "result", "[", "$", "child", "->", "nodeName", "]", "=", "static", "::", "DOMtoArray", "(", "$", "child", ")", ";", "}", "}", "}", "}", "if", "(", "$", "node", "->", "hasAttributes", "(", ")", ")", "{", "$", "attributes", "=", "$", "node", "->", "attributes", ";", "if", "(", "!", "is_null", "(", "$", "attributes", ")", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "attr", ")", "{", "$", "result", "[", "self", "::", "ATTRIBUTES", "]", "[", "$", "attr", "->", "name", "]", "=", "$", "attr", "->", "value", ";", "}", "}", "}", "}", "return", "$", "result", ";", "}" ]
Convert the XML DOM into a nested associative array @param DOMNode $node Root node of the array @return array
[ "Convert", "the", "XML", "DOM", "into", "a", "nested", "associative", "array" ]
7c6aeddce5c26bee553d7160bae47b30344ae122
https://github.com/battis/configxml/blob/7c6aeddce5c26bee553d7160bae47b30344ae122/src/ConfigXML.php#L139-L203
train
vaniocz/stdlib
src/Enum.php
Enum.box
final public static function box($plainValue): self { foreach (static::valueNames() as $name) { if (self::constant($name) === $plainValue) { return self::__callStatic($name, []); } } $message = sprintf('Value %s is not within %s enumeration.', $plainValue, static::class); throw new InvalidArgumentException($message); }
php
final public static function box($plainValue): self { foreach (static::valueNames() as $name) { if (self::constant($name) === $plainValue) { return self::__callStatic($name, []); } } $message = sprintf('Value %s is not within %s enumeration.', $plainValue, static::class); throw new InvalidArgumentException($message); }
[ "final", "public", "static", "function", "box", "(", "$", "plainValue", ")", ":", "self", "{", "foreach", "(", "static", "::", "valueNames", "(", ")", "as", "$", "name", ")", "{", "if", "(", "self", "::", "constant", "(", "$", "name", ")", "===", "$", "plainValue", ")", "{", "return", "self", "::", "__callStatic", "(", "$", "name", ",", "[", "]", ")", ";", "}", "}", "$", "message", "=", "sprintf", "(", "'Value %s is not within %s enumeration.'", ",", "$", "plainValue", ",", "static", "::", "class", ")", ";", "throw", "new", "InvalidArgumentException", "(", "$", "message", ")", ";", "}" ]
Box the given plain value. @param mixed $plainValue The plain value to be boxed. @return static The boxed value. @throws InvalidArgumentException If the given plain value is not within the enumeration.
[ "Box", "the", "given", "plain", "value", "." ]
06a8343c42829d8fdeecad2bb5c30946fbd73e74
https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/Enum.php#L52-L62
train
vaniocz/stdlib
src/Enum.php
Enum.valueNames
public static function valueNames(): array { static $valueNames = []; if (!isset($valueNames[static::class])) { $valueNames[static::class] = []; foreach ((new ReflectionClass(static::class))->getReflectionConstants() as $reflectionConstant) { if ($reflectionConstant->isPublic() && !$reflectionConstant->getDeclaringClass()->isInterface()) { $valueNames[static::class][] = $reflectionConstant->name; } } } return $valueNames[static::class]; }
php
public static function valueNames(): array { static $valueNames = []; if (!isset($valueNames[static::class])) { $valueNames[static::class] = []; foreach ((new ReflectionClass(static::class))->getReflectionConstants() as $reflectionConstant) { if ($reflectionConstant->isPublic() && !$reflectionConstant->getDeclaringClass()->isInterface()) { $valueNames[static::class][] = $reflectionConstant->name; } } } return $valueNames[static::class]; }
[ "public", "static", "function", "valueNames", "(", ")", ":", "array", "{", "static", "$", "valueNames", "=", "[", "]", ";", "if", "(", "!", "isset", "(", "$", "valueNames", "[", "static", "::", "class", "]", ")", ")", "{", "$", "valueNames", "[", "static", "::", "class", "]", "=", "[", "]", ";", "foreach", "(", "(", "new", "ReflectionClass", "(", "static", "::", "class", ")", ")", "->", "getReflectionConstants", "(", ")", "as", "$", "reflectionConstant", ")", "{", "if", "(", "$", "reflectionConstant", "->", "isPublic", "(", ")", "&&", "!", "$", "reflectionConstant", "->", "getDeclaringClass", "(", ")", "->", "isInterface", "(", ")", ")", "{", "$", "valueNames", "[", "static", "::", "class", "]", "[", "]", "=", "$", "reflectionConstant", "->", "name", ";", "}", "}", "}", "return", "$", "valueNames", "[", "static", "::", "class", "]", ";", "}" ]
Get names of all the values in this enumeration. @return string[] Names of all the values in this enumeration.
[ "Get", "names", "of", "all", "the", "values", "in", "this", "enumeration", "." ]
06a8343c42829d8fdeecad2bb5c30946fbd73e74
https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/Enum.php#L121-L136
train
vaniocz/stdlib
src/Enum.php
Enum.instantiate
private static function instantiate(string $valueName): self { $value = new static(...(array) self::constant($valueName)); $value->name = $valueName; return $value; }
php
private static function instantiate(string $valueName): self { $value = new static(...(array) self::constant($valueName)); $value->name = $valueName; return $value; }
[ "private", "static", "function", "instantiate", "(", "string", "$", "valueName", ")", ":", "self", "{", "$", "value", "=", "new", "static", "(", "...", "(", "array", ")", "self", "::", "constant", "(", "$", "valueName", ")", ")", ";", "$", "value", "->", "name", "=", "$", "valueName", ";", "return", "$", "value", ";", "}" ]
Instantiate value with the given name. @param string $valueName The name of the value. @return static The newly instantiated value.
[ "Instantiate", "value", "with", "the", "given", "name", "." ]
06a8343c42829d8fdeecad2bb5c30946fbd73e74
https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/Enum.php#L145-L151
train
vaniocz/stdlib
src/Enum.php
Enum.constant
private static function constant(string $name) { $constant = static::class . '::' . $name; if (!defined($constant)) { $message = sprintf('Enum %s does not contain value named %s.', static::class, $name); throw new InvalidArgumentException($message); } return constant($constant); }
php
private static function constant(string $name) { $constant = static::class . '::' . $name; if (!defined($constant)) { $message = sprintf('Enum %s does not contain value named %s.', static::class, $name); throw new InvalidArgumentException($message); } return constant($constant); }
[ "private", "static", "function", "constant", "(", "string", "$", "name", ")", "{", "$", "constant", "=", "static", "::", "class", ".", "'::'", ".", "$", "name", ";", "if", "(", "!", "defined", "(", "$", "constant", ")", ")", "{", "$", "message", "=", "sprintf", "(", "'Enum %s does not contain value named %s.'", ",", "static", "::", "class", ",", "$", "name", ")", ";", "throw", "new", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "return", "constant", "(", "$", "constant", ")", ";", "}" ]
Get the value of the given constant. @param string $name The name of the constant. @return mixed The value of the given constant. @throws InvalidArgumentException If no such constant exists.
[ "Get", "the", "value", "of", "the", "given", "constant", "." ]
06a8343c42829d8fdeecad2bb5c30946fbd73e74
https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/Enum.php#L162-L172
train
OxfordInfoLabs/kinikit-core
src/Validation/Validator.php
Validator.validateObject
public function validateObject($object) { if (!$object instanceof SerialisableObject) { throw new ClassNotSerialisableException(get_class($object)); } $classAnnotations = ClassAnnotationParser::instance()->parse($object); $validationFields = $classAnnotations->getFieldAnnotationsForMatchingTag("validation"); $validationErrors = array(); foreach ($validationFields as $field => $annotation) { $value = $object->__getSerialisablePropertyValue($field); foreach ($annotation[0]->getValues() as $validatorString) { $explodedValidator = explode("(", $validatorString); $validatorKey = trim($explodedValidator[0]); // Gather validator args if supplied. $validatorArgs = array(); if (sizeof($explodedValidator) > 1) { $argsCSV = explode(")", $explodedValidator[1]); $args = explode("|", $argsCSV[0]); foreach ($args as $arg) { $validatorArgs[] = trim($arg); } } $validator = isset($this->validators[$validatorKey]) ? $this->validators[$validatorKey] : null; if (isset($validator)) { $valid = $validator->validateObjectFieldValue($value, $field, $object, $validatorArgs, $validatorKey); if ($valid !== true) { if (!isset($validationErrors[$field])) $validationErrors[$field] = array(); $message = preg_replace_callback("/\\$([0-9])/", function ($matches) use ($validatorArgs) { return $validatorArgs[$matches[1] - 1]; }, $validator->getValidationMessage()); $validationErrors[$field][$validatorKey] = new FieldValidationError($field, $validatorKey, $message); } } else { throw new InvalidValidatorException($validatorKey, $field, $object); } } } return $validationErrors; }
php
public function validateObject($object) { if (!$object instanceof SerialisableObject) { throw new ClassNotSerialisableException(get_class($object)); } $classAnnotations = ClassAnnotationParser::instance()->parse($object); $validationFields = $classAnnotations->getFieldAnnotationsForMatchingTag("validation"); $validationErrors = array(); foreach ($validationFields as $field => $annotation) { $value = $object->__getSerialisablePropertyValue($field); foreach ($annotation[0]->getValues() as $validatorString) { $explodedValidator = explode("(", $validatorString); $validatorKey = trim($explodedValidator[0]); // Gather validator args if supplied. $validatorArgs = array(); if (sizeof($explodedValidator) > 1) { $argsCSV = explode(")", $explodedValidator[1]); $args = explode("|", $argsCSV[0]); foreach ($args as $arg) { $validatorArgs[] = trim($arg); } } $validator = isset($this->validators[$validatorKey]) ? $this->validators[$validatorKey] : null; if (isset($validator)) { $valid = $validator->validateObjectFieldValue($value, $field, $object, $validatorArgs, $validatorKey); if ($valid !== true) { if (!isset($validationErrors[$field])) $validationErrors[$field] = array(); $message = preg_replace_callback("/\\$([0-9])/", function ($matches) use ($validatorArgs) { return $validatorArgs[$matches[1] - 1]; }, $validator->getValidationMessage()); $validationErrors[$field][$validatorKey] = new FieldValidationError($field, $validatorKey, $message); } } else { throw new InvalidValidatorException($validatorKey, $field, $object); } } } return $validationErrors; }
[ "public", "function", "validateObject", "(", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "SerialisableObject", ")", "{", "throw", "new", "ClassNotSerialisableException", "(", "get_class", "(", "$", "object", ")", ")", ";", "}", "$", "classAnnotations", "=", "ClassAnnotationParser", "::", "instance", "(", ")", "->", "parse", "(", "$", "object", ")", ";", "$", "validationFields", "=", "$", "classAnnotations", "->", "getFieldAnnotationsForMatchingTag", "(", "\"validation\"", ")", ";", "$", "validationErrors", "=", "array", "(", ")", ";", "foreach", "(", "$", "validationFields", "as", "$", "field", "=>", "$", "annotation", ")", "{", "$", "value", "=", "$", "object", "->", "__getSerialisablePropertyValue", "(", "$", "field", ")", ";", "foreach", "(", "$", "annotation", "[", "0", "]", "->", "getValues", "(", ")", "as", "$", "validatorString", ")", "{", "$", "explodedValidator", "=", "explode", "(", "\"(\"", ",", "$", "validatorString", ")", ";", "$", "validatorKey", "=", "trim", "(", "$", "explodedValidator", "[", "0", "]", ")", ";", "// Gather validator args if supplied.", "$", "validatorArgs", "=", "array", "(", ")", ";", "if", "(", "sizeof", "(", "$", "explodedValidator", ")", ">", "1", ")", "{", "$", "argsCSV", "=", "explode", "(", "\")\"", ",", "$", "explodedValidator", "[", "1", "]", ")", ";", "$", "args", "=", "explode", "(", "\"|\"", ",", "$", "argsCSV", "[", "0", "]", ")", ";", "foreach", "(", "$", "args", "as", "$", "arg", ")", "{", "$", "validatorArgs", "[", "]", "=", "trim", "(", "$", "arg", ")", ";", "}", "}", "$", "validator", "=", "isset", "(", "$", "this", "->", "validators", "[", "$", "validatorKey", "]", ")", "?", "$", "this", "->", "validators", "[", "$", "validatorKey", "]", ":", "null", ";", "if", "(", "isset", "(", "$", "validator", ")", ")", "{", "$", "valid", "=", "$", "validator", "->", "validateObjectFieldValue", "(", "$", "value", ",", "$", "field", ",", "$", "object", ",", "$", "validatorArgs", ",", "$", "validatorKey", ")", ";", "if", "(", "$", "valid", "!==", "true", ")", "{", "if", "(", "!", "isset", "(", "$", "validationErrors", "[", "$", "field", "]", ")", ")", "$", "validationErrors", "[", "$", "field", "]", "=", "array", "(", ")", ";", "$", "message", "=", "preg_replace_callback", "(", "\"/\\\\$([0-9])/\"", ",", "function", "(", "$", "matches", ")", "use", "(", "$", "validatorArgs", ")", "{", "return", "$", "validatorArgs", "[", "$", "matches", "[", "1", "]", "-", "1", "]", ";", "}", ",", "$", "validator", "->", "getValidationMessage", "(", ")", ")", ";", "$", "validationErrors", "[", "$", "field", "]", "[", "$", "validatorKey", "]", "=", "new", "FieldValidationError", "(", "$", "field", ",", "$", "validatorKey", ",", "$", "message", ")", ";", "}", "}", "else", "{", "throw", "new", "InvalidValidatorException", "(", "$", "validatorKey", ",", "$", "field", ",", "$", "object", ")", ";", "}", "}", "}", "return", "$", "validationErrors", ";", "}" ]
Validate a serialisable object @param SerialisableObject $object
[ "Validate", "a", "serialisable", "object" ]
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Validation/Validator.php#L60-L115
train
Wedeto/Util
src/Cache/Manager.php
Manager.setCachePath
public function setCachePath(string $path) { $rpath = substr($path, 0, 6) === "vfs://" ? $path : realpath($path); if (empty($rpath) || !file_exists($path)) throw new InvalidArgumentException("Path does not exist: " . $rpath); $this->cache_path = $rpath; }
php
public function setCachePath(string $path) { $rpath = substr($path, 0, 6) === "vfs://" ? $path : realpath($path); if (empty($rpath) || !file_exists($path)) throw new InvalidArgumentException("Path does not exist: " . $rpath); $this->cache_path = $rpath; }
[ "public", "function", "setCachePath", "(", "string", "$", "path", ")", "{", "$", "rpath", "=", "substr", "(", "$", "path", ",", "0", ",", "6", ")", "===", "\"vfs://\"", "?", "$", "path", ":", "realpath", "(", "$", "path", ")", ";", "if", "(", "empty", "(", "$", "rpath", ")", "||", "!", "file_exists", "(", "$", "path", ")", ")", "throw", "new", "InvalidArgumentException", "(", "\"Path does not exist: \"", ".", "$", "rpath", ")", ";", "$", "this", "->", "cache_path", "=", "$", "rpath", ";", "}" ]
Set the base directory for the cache files @param string $path The cache directory
[ "Set", "the", "base", "directory", "for", "the", "cache", "files" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Manager.php#L90-L96
train
Wedeto/Util
src/Cache/Manager.php
Manager.setHook
public function setHook() { Hook::subscribe(Hook::SHUTDOWN_HOOK, [$this, 'saveCacheHook'], 10); foreach ($this->repository as $name => $cache) $this->checkExpiry($name); }
php
public function setHook() { Hook::subscribe(Hook::SHUTDOWN_HOOK, [$this, 'saveCacheHook'], 10); foreach ($this->repository as $name => $cache) $this->checkExpiry($name); }
[ "public", "function", "setHook", "(", ")", "{", "Hook", "::", "subscribe", "(", "Hook", "::", "SHUTDOWN_HOOK", ",", "[", "$", "this", ",", "'saveCacheHook'", "]", ",", "10", ")", ";", "foreach", "(", "$", "this", "->", "repository", "as", "$", "name", "=>", "$", "cache", ")", "$", "this", "->", "checkExpiry", "(", "$", "name", ")", ";", "}" ]
Add the hook after the configuration has been loaded, and apply invalidation to the cache once it times out.
[ "Add", "the", "hook", "after", "the", "configuration", "has", "been", "loaded", "and", "apply", "invalidation", "to", "the", "cache", "once", "it", "times", "out", "." ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Manager.php#L110-L116
train
Wedeto/Util
src/Cache/Manager.php
Manager.unsetHook
public function unsetHook() { if ($this->hook_reference !== null) { Hook::unsubscribe(Hook::SHUTDOWN_HOOK, $this->hook_reference); } }
php
public function unsetHook() { if ($this->hook_reference !== null) { Hook::unsubscribe(Hook::SHUTDOWN_HOOK, $this->hook_reference); } }
[ "public", "function", "unsetHook", "(", ")", "{", "if", "(", "$", "this", "->", "hook_reference", "!==", "null", ")", "{", "Hook", "::", "unsubscribe", "(", "Hook", "::", "SHUTDOWN_HOOK", ",", "$", "this", "->", "hook_reference", ")", ";", "}", "}" ]
Remove the hook - cancelling automatic save on termination
[ "Remove", "the", "hook", "-", "cancelling", "automatic", "save", "on", "termination" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Manager.php#L121-L127
train
Wedeto/Util
src/Cache/Manager.php
Manager.loadCache
protected function loadCache(string $name) { $path = $this->cache_path; $cache_file = $path . '/' . $name . '.cache'; if (file_exists($cache_file)) { if (!is_readable($cache_file)) { self::getLogger()->error("Cannot read cache from {0}", [$cache_file]); } else { try { $contents = file_get_contents($cache_file); $data = unserialize($contents); if (!is_array($data)) $data = []; $this->repository[$name] = $data; $this->repository[$name]['_changed'] = false; $this->checkExpiry($name); return; } catch (\Throwable $t) { self::getLogger()->error("Failure loading cache {0} - removing", [$name]); self::getLogger()->error("Error: {0}", [$t]); if (is_writable($cache_file)) unlink($cache_file); } } } self::getLogger()->debug("Cache {0} does not exist - creating", [$cache_file]); $this->repository[$name] = []; }
php
protected function loadCache(string $name) { $path = $this->cache_path; $cache_file = $path . '/' . $name . '.cache'; if (file_exists($cache_file)) { if (!is_readable($cache_file)) { self::getLogger()->error("Cannot read cache from {0}", [$cache_file]); } else { try { $contents = file_get_contents($cache_file); $data = unserialize($contents); if (!is_array($data)) $data = []; $this->repository[$name] = $data; $this->repository[$name]['_changed'] = false; $this->checkExpiry($name); return; } catch (\Throwable $t) { self::getLogger()->error("Failure loading cache {0} - removing", [$name]); self::getLogger()->error("Error: {0}", [$t]); if (is_writable($cache_file)) unlink($cache_file); } } } self::getLogger()->debug("Cache {0} does not exist - creating", [$cache_file]); $this->repository[$name] = []; }
[ "protected", "function", "loadCache", "(", "string", "$", "name", ")", "{", "$", "path", "=", "$", "this", "->", "cache_path", ";", "$", "cache_file", "=", "$", "path", ".", "'/'", ".", "$", "name", ".", "'.cache'", ";", "if", "(", "file_exists", "(", "$", "cache_file", ")", ")", "{", "if", "(", "!", "is_readable", "(", "$", "cache_file", ")", ")", "{", "self", "::", "getLogger", "(", ")", "->", "error", "(", "\"Cannot read cache from {0}\"", ",", "[", "$", "cache_file", "]", ")", ";", "}", "else", "{", "try", "{", "$", "contents", "=", "file_get_contents", "(", "$", "cache_file", ")", ";", "$", "data", "=", "unserialize", "(", "$", "contents", ")", ";", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "$", "data", "=", "[", "]", ";", "$", "this", "->", "repository", "[", "$", "name", "]", "=", "$", "data", ";", "$", "this", "->", "repository", "[", "$", "name", "]", "[", "'_changed'", "]", "=", "false", ";", "$", "this", "->", "checkExpiry", "(", "$", "name", ")", ";", "return", ";", "}", "catch", "(", "\\", "Throwable", "$", "t", ")", "{", "self", "::", "getLogger", "(", ")", "->", "error", "(", "\"Failure loading cache {0} - removing\"", ",", "[", "$", "name", "]", ")", ";", "self", "::", "getLogger", "(", ")", "->", "error", "(", "\"Error: {0}\"", ",", "[", "$", "t", "]", ")", ";", "if", "(", "is_writable", "(", "$", "cache_file", ")", ")", "unlink", "(", "$", "cache_file", ")", ";", "}", "}", "}", "self", "::", "getLogger", "(", ")", "->", "debug", "(", "\"Cache {0} does not exist - creating\"", ",", "[", "$", "cache_file", "]", ")", ";", "$", "this", "->", "repository", "[", "$", "name", "]", "=", "[", "]", ";", "}" ]
Load the cache from the cache files. The data will be stored in the class-internal cache storage @param $name string The name of the cache to load
[ "Load", "the", "cache", "from", "the", "cache", "files", ".", "The", "data", "will", "be", "stored", "in", "the", "class", "-", "internal", "cache", "storage" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Manager.php#L158-L193
train
Wedeto/Util
src/Cache/Manager.php
Manager.getCache
public function getCache(string $name) { if (!isset($this->repository[$name])) $this->loadCache($name); return new Cache($name, $this->repository[$name]); }
php
public function getCache(string $name) { if (!isset($this->repository[$name])) $this->loadCache($name); return new Cache($name, $this->repository[$name]); }
[ "public", "function", "getCache", "(", "string", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "repository", "[", "$", "name", "]", ")", ")", "$", "this", "->", "loadCache", "(", "$", "name", ")", ";", "return", "new", "Cache", "(", "$", "name", ",", "$", "this", "->", "repository", "[", "$", "name", "]", ")", ";", "}" ]
Return a cache
[ "Return", "a", "cache" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Manager.php#L246-L252
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Generators/Generator.php
Generator.getStub
protected function getStub( $name ) { if ( stripos( $name, '.php' ) === false ) $name = $name . '.php'; $this->files->get( $this->getStubPath() . '/' . $name ); }
php
protected function getStub( $name ) { if ( stripos( $name, '.php' ) === false ) $name = $name . '.php'; $this->files->get( $this->getStubPath() . '/' . $name ); }
[ "protected", "function", "getStub", "(", "$", "name", ")", "{", "if", "(", "stripos", "(", "$", "name", ",", "'.php'", ")", "===", "false", ")", "$", "name", "=", "$", "name", ".", "'.php'", ";", "$", "this", "->", "files", "->", "get", "(", "$", "this", "->", "getStubPath", "(", ")", ".", "'/'", ".", "$", "name", ")", ";", "}" ]
Get the given stub by name. @param string $table
[ "Get", "the", "given", "stub", "by", "name", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Generators/Generator.php#L40-L46
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Generators/Generator.php
Generator.parseStub
protected function parseStub( $stub, $replacements = [] ) { $output = $stub; foreach ( $replacements as $key => $replacement ) { $search = '{{' . $key . '}}'; $output = str_replace( $search, $replacement, $output ); } return $output; }
php
protected function parseStub( $stub, $replacements = [] ) { $output = $stub; foreach ( $replacements as $key => $replacement ) { $search = '{{' . $key . '}}'; $output = str_replace( $search, $replacement, $output ); } return $output; }
[ "protected", "function", "parseStub", "(", "$", "stub", ",", "$", "replacements", "=", "[", "]", ")", "{", "$", "output", "=", "$", "stub", ";", "foreach", "(", "$", "replacements", "as", "$", "key", "=>", "$", "replacement", ")", "{", "$", "search", "=", "'{{'", ".", "$", "key", ".", "'}}'", ";", "$", "output", "=", "str_replace", "(", "$", "search", ",", "$", "replacement", ",", "$", "output", ")", ";", "}", "return", "$", "output", ";", "}" ]
Parse the provided stub and replace via the array given. @param string $stub @param string $replacements @return string
[ "Parse", "the", "provided", "stub", "and", "replace", "via", "the", "array", "given", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Generators/Generator.php#L65-L76
train
WellCommerce/DistributionBundle
Command/Package/AbstractPackageCommand.php
AbstractPackageCommand.getCommandArguments
protected function getCommandArguments(InputInterface $input) { $package = $this->getPackageInformation($input->getOption('package')); return [ $this->getComposer(), $this->composerOperation, $package, ]; }
php
protected function getCommandArguments(InputInterface $input) { $package = $this->getPackageInformation($input->getOption('package')); return [ $this->getComposer(), $this->composerOperation, $package, ]; }
[ "protected", "function", "getCommandArguments", "(", "InputInterface", "$", "input", ")", "{", "$", "package", "=", "$", "this", "->", "getPackageInformation", "(", "$", "input", "->", "getOption", "(", "'package'", ")", ")", ";", "return", "[", "$", "this", "->", "getComposer", "(", ")", ",", "$", "this", "->", "composerOperation", ",", "$", "package", ",", "]", ";", "}" ]
Returns command arguments used in ProcessBuilder @param InputInterface $input @return array
[ "Returns", "command", "arguments", "used", "in", "ProcessBuilder" ]
82b1b4c2c5a59536aaae22506b23ccd5d141cbb0
https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Command/Package/AbstractPackageCommand.php#L105-L114
train
WellCommerce/DistributionBundle
Command/Package/AbstractPackageCommand.php
AbstractPackageCommand.getPackageInformation
protected function getPackageInformation($id) { $package = $this->getContainer()->get('package.repository')->find($id); if (!$package instanceof PackageInterface) { throw new \InvalidArgumentException(sprintf('Package "%s" not found', $id)); } return $package->getFullName(); }
php
protected function getPackageInformation($id) { $package = $this->getContainer()->get('package.repository')->find($id); if (!$package instanceof PackageInterface) { throw new \InvalidArgumentException(sprintf('Package "%s" not found', $id)); } return $package->getFullName(); }
[ "protected", "function", "getPackageInformation", "(", "$", "id", ")", "{", "$", "package", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'package.repository'", ")", "->", "find", "(", "$", "id", ")", ";", "if", "(", "!", "$", "package", "instanceof", "PackageInterface", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Package \"%s\" not found'", ",", "$", "id", ")", ")", ";", "}", "return", "$", "package", "->", "getFullName", "(", ")", ";", "}" ]
Returns package information by identifier @param int $id Package identifier @return string
[ "Returns", "package", "information", "by", "identifier" ]
82b1b4c2c5a59536aaae22506b23ccd5d141cbb0
https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Command/Package/AbstractPackageCommand.php#L123-L131
train
WellCommerce/DistributionBundle
Command/Package/AbstractPackageCommand.php
AbstractPackageCommand.initializeServer
protected function initializeServer(LoopInterface $loop, $port) { $writer = new Stream("php://output"); $logger = new Logger(); $logger->addWriter($writer); return new WebSocketServer("tcp://0.0.0.0:{$port}", $loop, $logger); }
php
protected function initializeServer(LoopInterface $loop, $port) { $writer = new Stream("php://output"); $logger = new Logger(); $logger->addWriter($writer); return new WebSocketServer("tcp://0.0.0.0:{$port}", $loop, $logger); }
[ "protected", "function", "initializeServer", "(", "LoopInterface", "$", "loop", ",", "$", "port", ")", "{", "$", "writer", "=", "new", "Stream", "(", "\"php://output\"", ")", ";", "$", "logger", "=", "new", "Logger", "(", ")", ";", "$", "logger", "->", "addWriter", "(", "$", "writer", ")", ";", "return", "new", "WebSocketServer", "(", "\"tcp://0.0.0.0:{$port}\"", ",", "$", "loop", ",", "$", "logger", ")", ";", "}" ]
Initializes web-socket server @param LoopInterface $loop @param int $port @return WebSocketServer
[ "Initializes", "web", "-", "socket", "server" ]
82b1b4c2c5a59536aaae22506b23ccd5d141cbb0
https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Command/Package/AbstractPackageCommand.php#L159-L166
train
WellCommerce/DistributionBundle
Command/Package/AbstractPackageCommand.php
AbstractPackageCommand.addEnvironmentInfo
protected function addEnvironmentInfo($port, $command) { $translator = $this->getContainer()->get('translator'); $info = [ $translator->trans('environment.server.port') => $port, $translator->trans('environment.console.command') => $command, $translator->trans('environment.symfony.version') => Kernel::VERSION, $translator->trans('environment.php.version') => phpversion(), ]; foreach ($info as $phrase => $value) { $this->buffer .= sprintf('<strong>%s: </strong>%s%s', $phrase, $value, PHP_EOL); } }
php
protected function addEnvironmentInfo($port, $command) { $translator = $this->getContainer()->get('translator'); $info = [ $translator->trans('environment.server.port') => $port, $translator->trans('environment.console.command') => $command, $translator->trans('environment.symfony.version') => Kernel::VERSION, $translator->trans('environment.php.version') => phpversion(), ]; foreach ($info as $phrase => $value) { $this->buffer .= sprintf('<strong>%s: </strong>%s%s', $phrase, $value, PHP_EOL); } }
[ "protected", "function", "addEnvironmentInfo", "(", "$", "port", ",", "$", "command", ")", "{", "$", "translator", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'translator'", ")", ";", "$", "info", "=", "[", "$", "translator", "->", "trans", "(", "'environment.server.port'", ")", "=>", "$", "port", ",", "$", "translator", "->", "trans", "(", "'environment.console.command'", ")", "=>", "$", "command", ",", "$", "translator", "->", "trans", "(", "'environment.symfony.version'", ")", "=>", "Kernel", "::", "VERSION", ",", "$", "translator", "->", "trans", "(", "'environment.php.version'", ")", "=>", "phpversion", "(", ")", ",", "]", ";", "foreach", "(", "$", "info", "as", "$", "phrase", "=>", "$", "value", ")", "{", "$", "this", "->", "buffer", ".=", "sprintf", "(", "'<strong>%s: </strong>%s%s'", ",", "$", "phrase", ",", "$", "value", ",", "PHP_EOL", ")", ";", "}", "}" ]
Adds additional environment information to buffer @param int $port @param string $command
[ "Adds", "additional", "environment", "information", "to", "buffer" ]
82b1b4c2c5a59536aaae22506b23ccd5d141cbb0
https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Command/Package/AbstractPackageCommand.php#L174-L188
train
WellCommerce/DistributionBundle
Command/Package/AbstractPackageCommand.php
AbstractPackageCommand.broadcastToClients
protected function broadcastToClients(\SplObjectStorage $clients) { foreach ($clients as $client) { $client->sendString($this->processOutput()); } }
php
protected function broadcastToClients(\SplObjectStorage $clients) { foreach ($clients as $client) { $client->sendString($this->processOutput()); } }
[ "protected", "function", "broadcastToClients", "(", "\\", "SplObjectStorage", "$", "clients", ")", "{", "foreach", "(", "$", "clients", "as", "$", "client", ")", "{", "$", "client", "->", "sendString", "(", "$", "this", "->", "processOutput", "(", ")", ")", ";", "}", "}" ]
Sends processed output to all connected clients
[ "Sends", "processed", "output", "to", "all", "connected", "clients" ]
82b1b4c2c5a59536aaae22506b23ccd5d141cbb0
https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Command/Package/AbstractPackageCommand.php#L193-L198
train
fridge-project/dbal
src/Fridge/DBAL/Schema/View.php
View.setSQL
public function setSQL($sql) { if ((is_string($sql) && (strlen($sql) <= 0)) || (!is_string($sql) && ($sql !== null))) { throw SchemaException::invalidViewSQL($this->getName()); } $this->sql = $sql; }
php
public function setSQL($sql) { if ((is_string($sql) && (strlen($sql) <= 0)) || (!is_string($sql) && ($sql !== null))) { throw SchemaException::invalidViewSQL($this->getName()); } $this->sql = $sql; }
[ "public", "function", "setSQL", "(", "$", "sql", ")", "{", "if", "(", "(", "is_string", "(", "$", "sql", ")", "&&", "(", "strlen", "(", "$", "sql", ")", "<=", "0", ")", ")", "||", "(", "!", "is_string", "(", "$", "sql", ")", "&&", "(", "$", "sql", "!==", "null", ")", ")", ")", "{", "throw", "SchemaException", "::", "invalidViewSQL", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "sql", "=", "$", "sql", ";", "}" ]
Sets the SQL query. @param string $sql The SQL query. @throws \Fridge\DBAL\Exception\SchemaException If the sql is not a valid string.
[ "Sets", "the", "SQL", "query", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/View.php#L56-L63
train
nicmart/DomainSpecificQuery
src/Lucene/Compiler/LuceneCompiler.php
LuceneCompiler.notFieldExpression
public function notFieldExpression(FieldExpression $expr, self $compiler) { $not = new TreeExpression('not'); $not->addChild(new FieldExpression($expr->getField(), $expr->getValue())); return $this->notExpression($not, $compiler); }
php
public function notFieldExpression(FieldExpression $expr, self $compiler) { $not = new TreeExpression('not'); $not->addChild(new FieldExpression($expr->getField(), $expr->getValue())); return $this->notExpression($not, $compiler); }
[ "public", "function", "notFieldExpression", "(", "FieldExpression", "$", "expr", ",", "self", "$", "compiler", ")", "{", "$", "not", "=", "new", "TreeExpression", "(", "'not'", ")", ";", "$", "not", "->", "addChild", "(", "new", "FieldExpression", "(", "$", "expr", "->", "getField", "(", ")", ",", "$", "expr", "->", "getValue", "(", ")", ")", ")", ";", "return", "$", "this", "->", "notExpression", "(", "$", "not", ",", "$", "compiler", ")", ";", "}" ]
Delegate a "not equal" field expression to the previous map @param FieldExpression $expr @param LuceneCompiler $compiler @return BooleanExpression
[ "Delegate", "a", "not", "equal", "field", "expression", "to", "the", "previous", "map" ]
7c01fe94337afdfae5884809e8b5487127a63ac3
https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Lucene/Compiler/LuceneCompiler.php#L116-L122
train
nicmart/DomainSpecificQuery
src/Lucene/Compiler/LuceneCompiler.php
LuceneCompiler.phrasizeOrTermize
public function phrasizeOrTermize($value, $phrase = true, $escape = true) { if (!$phrase && !$escape) return $value; if (!is_array($value)) return $phrase ? new PhraseExpression($value) : new TermExpression($value) ; $ary = array(); foreach ($value as $key => $v) { $ary[$key] = $this->phrasizeOrTermize($v, $phrase, $escape); } return $ary; }
php
public function phrasizeOrTermize($value, $phrase = true, $escape = true) { if (!$phrase && !$escape) return $value; if (!is_array($value)) return $phrase ? new PhraseExpression($value) : new TermExpression($value) ; $ary = array(); foreach ($value as $key => $v) { $ary[$key] = $this->phrasizeOrTermize($v, $phrase, $escape); } return $ary; }
[ "public", "function", "phrasizeOrTermize", "(", "$", "value", ",", "$", "phrase", "=", "true", ",", "$", "escape", "=", "true", ")", "{", "if", "(", "!", "$", "phrase", "&&", "!", "$", "escape", ")", "return", "$", "value", ";", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "return", "$", "phrase", "?", "new", "PhraseExpression", "(", "$", "value", ")", ":", "new", "TermExpression", "(", "$", "value", ")", ";", "$", "ary", "=", "array", "(", ")", ";", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "v", ")", "{", "$", "ary", "[", "$", "key", "]", "=", "$", "this", "->", "phrasizeOrTermize", "(", "$", "v", ",", "$", "phrase", ",", "$", "escape", ")", ";", "}", "return", "$", "ary", ";", "}" ]
Helper function that wraps an expression value with a phrase expression or a term expression Phrasing wins on termizing @param mixed $value @param bool $phrase @param bool $escape @return PhraseExpression|TermExpression|string
[ "Helper", "function", "that", "wraps", "an", "expression", "value", "with", "a", "phrase", "expression", "or", "a", "term", "expression", "Phrasing", "wins", "on", "termizing" ]
7c01fe94337afdfae5884809e8b5487127a63ac3
https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Lucene/Compiler/LuceneCompiler.php#L196-L213
train
ekyna/RequireJsBundle
Configuration/Provider.php
Provider.getMainConfig
public function getMainConfig() { $config = null; if ($this->cache) { $config = $this->cache->fetch(self::CONFIG_CACHE_KEY); } if (empty($config)) { $config = $this->generateMainConfig(); if ($this->cache) { $this->cache->save(self::CONFIG_CACHE_KEY, $config); } } return $config; }
php
public function getMainConfig() { $config = null; if ($this->cache) { $config = $this->cache->fetch(self::CONFIG_CACHE_KEY); } if (empty($config)) { $config = $this->generateMainConfig(); if ($this->cache) { $this->cache->save(self::CONFIG_CACHE_KEY, $config); } } return $config; }
[ "public", "function", "getMainConfig", "(", ")", "{", "$", "config", "=", "null", ";", "if", "(", "$", "this", "->", "cache", ")", "{", "$", "config", "=", "$", "this", "->", "cache", "->", "fetch", "(", "self", "::", "CONFIG_CACHE_KEY", ")", ";", "}", "if", "(", "empty", "(", "$", "config", ")", ")", "{", "$", "config", "=", "$", "this", "->", "generateMainConfig", "(", ")", ";", "if", "(", "$", "this", "->", "cache", ")", "{", "$", "this", "->", "cache", "->", "save", "(", "self", "::", "CONFIG_CACHE_KEY", ",", "$", "config", ")", ";", "}", "}", "return", "$", "config", ";", "}" ]
Fetches piece of JS-code with require.js main config from cache or if it was not there - generates and put into a cache @return string
[ "Fetches", "piece", "of", "JS", "-", "code", "with", "require", ".", "js", "main", "config", "from", "cache", "or", "if", "it", "was", "not", "there", "-", "generates", "and", "put", "into", "a", "cache" ]
2b746d25c17487838447d72a03d1050819bcf66a
https://github.com/ekyna/RequireJsBundle/blob/2b746d25c17487838447d72a03d1050819bcf66a/Configuration/Provider.php#L74-L87
train
ekyna/RequireJsBundle
Configuration/Provider.php
Provider.generateMainConfig
public function generateMainConfig() { $requirejs = $this->collectConfigs(); $config = $requirejs['config']; if (!empty($config['paths']) && is_array($config['paths'])) { foreach ($config['paths'] as &$path) { if (is_array($path)) { $path = $this->generator->generate( $path['route'], array_key_exists('params', $path) ? $path['params'] : [], UrlGeneratorInterface::ABSOLUTE_URL ); } if (substr($path, -3) === '.js') { $path = substr($path, 0, -3); } } } $config['baseUrl'] = '/'; return $config; }
php
public function generateMainConfig() { $requirejs = $this->collectConfigs(); $config = $requirejs['config']; if (!empty($config['paths']) && is_array($config['paths'])) { foreach ($config['paths'] as &$path) { if (is_array($path)) { $path = $this->generator->generate( $path['route'], array_key_exists('params', $path) ? $path['params'] : [], UrlGeneratorInterface::ABSOLUTE_URL ); } if (substr($path, -3) === '.js') { $path = substr($path, 0, -3); } } } $config['baseUrl'] = '/'; return $config; }
[ "public", "function", "generateMainConfig", "(", ")", "{", "$", "requirejs", "=", "$", "this", "->", "collectConfigs", "(", ")", ";", "$", "config", "=", "$", "requirejs", "[", "'config'", "]", ";", "if", "(", "!", "empty", "(", "$", "config", "[", "'paths'", "]", ")", "&&", "is_array", "(", "$", "config", "[", "'paths'", "]", ")", ")", "{", "foreach", "(", "$", "config", "[", "'paths'", "]", "as", "&", "$", "path", ")", "{", "if", "(", "is_array", "(", "$", "path", ")", ")", "{", "$", "path", "=", "$", "this", "->", "generator", "->", "generate", "(", "$", "path", "[", "'route'", "]", ",", "array_key_exists", "(", "'params'", ",", "$", "path", ")", "?", "$", "path", "[", "'params'", "]", ":", "[", "]", ",", "UrlGeneratorInterface", "::", "ABSOLUTE_URL", ")", ";", "}", "if", "(", "substr", "(", "$", "path", ",", "-", "3", ")", "===", "'.js'", ")", "{", "$", "path", "=", "substr", "(", "$", "path", ",", "0", ",", "-", "3", ")", ";", "}", "}", "}", "$", "config", "[", "'baseUrl'", "]", "=", "'/'", ";", "return", "$", "config", ";", "}" ]
Generates main config for require.js @return array
[ "Generates", "main", "config", "for", "require", ".", "js" ]
2b746d25c17487838447d72a03d1050819bcf66a
https://github.com/ekyna/RequireJsBundle/blob/2b746d25c17487838447d72a03d1050819bcf66a/Configuration/Provider.php#L94-L114
train
ekyna/RequireJsBundle
Configuration/Provider.php
Provider.generateBuildConfig
public function generateBuildConfig($configPath) { $config = $this->collectConfigs(); $config['build']['baseUrl'] = './'; $config['build']['out'] = './' . $config['build_path']; $config['build']['mainConfigFile'] = './' . $configPath; $paths = [ // build-in configuration 'require-config' => './' . substr($configPath, 0, -3), // build-in require.js lib 'require-lib' => 'bundles/ekynarequirejs/require', ]; $config['build']['paths'] = array_merge($config['build']['paths'], $paths); $config['build']['include'] = array_merge( array_keys($paths), //array_keys($config['config']['paths']) $config['build']['include'] ); return $config['build']; }
php
public function generateBuildConfig($configPath) { $config = $this->collectConfigs(); $config['build']['baseUrl'] = './'; $config['build']['out'] = './' . $config['build_path']; $config['build']['mainConfigFile'] = './' . $configPath; $paths = [ // build-in configuration 'require-config' => './' . substr($configPath, 0, -3), // build-in require.js lib 'require-lib' => 'bundles/ekynarequirejs/require', ]; $config['build']['paths'] = array_merge($config['build']['paths'], $paths); $config['build']['include'] = array_merge( array_keys($paths), //array_keys($config['config']['paths']) $config['build']['include'] ); return $config['build']; }
[ "public", "function", "generateBuildConfig", "(", "$", "configPath", ")", "{", "$", "config", "=", "$", "this", "->", "collectConfigs", "(", ")", ";", "$", "config", "[", "'build'", "]", "[", "'baseUrl'", "]", "=", "'./'", ";", "$", "config", "[", "'build'", "]", "[", "'out'", "]", "=", "'./'", ".", "$", "config", "[", "'build_path'", "]", ";", "$", "config", "[", "'build'", "]", "[", "'mainConfigFile'", "]", "=", "'./'", ".", "$", "configPath", ";", "$", "paths", "=", "[", "// build-in configuration", "'require-config'", "=>", "'./'", ".", "substr", "(", "$", "configPath", ",", "0", ",", "-", "3", ")", ",", "// build-in require.js lib", "'require-lib'", "=>", "'bundles/ekynarequirejs/require'", ",", "]", ";", "$", "config", "[", "'build'", "]", "[", "'paths'", "]", "=", "array_merge", "(", "$", "config", "[", "'build'", "]", "[", "'paths'", "]", ",", "$", "paths", ")", ";", "$", "config", "[", "'build'", "]", "[", "'include'", "]", "=", "array_merge", "(", "array_keys", "(", "$", "paths", ")", ",", "//array_keys($config['config']['paths'])", "$", "config", "[", "'build'", "]", "[", "'include'", "]", ")", ";", "return", "$", "config", "[", "'build'", "]", ";", "}" ]
Generates build config for require.js @param string $configPath path to require.js main config @return array
[ "Generates", "build", "config", "for", "require", ".", "js" ]
2b746d25c17487838447d72a03d1050819bcf66a
https://github.com/ekyna/RequireJsBundle/blob/2b746d25c17487838447d72a03d1050819bcf66a/Configuration/Provider.php#L122-L141
train
ekyna/RequireJsBundle
Configuration/Provider.php
Provider.collectConfigs
public function collectConfigs() { if (!$this->collectedConfig) { $config = $this->config; foreach ($this->bundles as $bundle) { $reflection = new \ReflectionClass($bundle); if (is_file($file = dirname($reflection->getFileName()) . '/Resources/config/requirejs.yml')) { $bundleConfig = Yaml::parse(file_get_contents(realpath($file))); $config = array_merge_recursive($config, $bundleConfig); } } $this->collectedConfig = $config; } return $this->collectedConfig; }
php
public function collectConfigs() { if (!$this->collectedConfig) { $config = $this->config; foreach ($this->bundles as $bundle) { $reflection = new \ReflectionClass($bundle); if (is_file($file = dirname($reflection->getFileName()) . '/Resources/config/requirejs.yml')) { $bundleConfig = Yaml::parse(file_get_contents(realpath($file))); $config = array_merge_recursive($config, $bundleConfig); } } $this->collectedConfig = $config; } return $this->collectedConfig; }
[ "public", "function", "collectConfigs", "(", ")", "{", "if", "(", "!", "$", "this", "->", "collectedConfig", ")", "{", "$", "config", "=", "$", "this", "->", "config", ";", "foreach", "(", "$", "this", "->", "bundles", "as", "$", "bundle", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "bundle", ")", ";", "if", "(", "is_file", "(", "$", "file", "=", "dirname", "(", "$", "reflection", "->", "getFileName", "(", ")", ")", ".", "'/Resources/config/requirejs.yml'", ")", ")", "{", "$", "bundleConfig", "=", "Yaml", "::", "parse", "(", "file_get_contents", "(", "realpath", "(", "$", "file", ")", ")", ")", ";", "$", "config", "=", "array_merge_recursive", "(", "$", "config", ",", "$", "bundleConfig", ")", ";", "}", "}", "$", "this", "->", "collectedConfig", "=", "$", "config", ";", "}", "return", "$", "this", "->", "collectedConfig", ";", "}" ]
Goes across bundles and collects configurations @return array
[ "Goes", "across", "bundles", "and", "collects", "configurations" ]
2b746d25c17487838447d72a03d1050819bcf66a
https://github.com/ekyna/RequireJsBundle/blob/2b746d25c17487838447d72a03d1050819bcf66a/Configuration/Provider.php#L148-L162
train
miBadger/miBadger.Mvc
src/View.php
View.get
public static function get($path, $data = []) { ob_start(); extract($data); try { $basePath = static::getInstance()->basePath; if ($basePath !== null) { if (mb_substr($path, 0, 1) === static::DIRECTORY_SEPARATOR) { $path = mb_substr($path, 1); } if (mb_substr($basePath, -1) === static::DIRECTORY_SEPARATOR) { $basePath = mb_substr($basePath, 0, -1); } $path = $basePath . static::DIRECTORY_SEPARATOR . $path; } include $path; } catch (\Exception $e) { ob_get_clean(); throw $e; } return ob_get_clean(); }
php
public static function get($path, $data = []) { ob_start(); extract($data); try { $basePath = static::getInstance()->basePath; if ($basePath !== null) { if (mb_substr($path, 0, 1) === static::DIRECTORY_SEPARATOR) { $path = mb_substr($path, 1); } if (mb_substr($basePath, -1) === static::DIRECTORY_SEPARATOR) { $basePath = mb_substr($basePath, 0, -1); } $path = $basePath . static::DIRECTORY_SEPARATOR . $path; } include $path; } catch (\Exception $e) { ob_get_clean(); throw $e; } return ob_get_clean(); }
[ "public", "static", "function", "get", "(", "$", "path", ",", "$", "data", "=", "[", "]", ")", "{", "ob_start", "(", ")", ";", "extract", "(", "$", "data", ")", ";", "try", "{", "$", "basePath", "=", "static", "::", "getInstance", "(", ")", "->", "basePath", ";", "if", "(", "$", "basePath", "!==", "null", ")", "{", "if", "(", "mb_substr", "(", "$", "path", ",", "0", ",", "1", ")", "===", "static", "::", "DIRECTORY_SEPARATOR", ")", "{", "$", "path", "=", "mb_substr", "(", "$", "path", ",", "1", ")", ";", "}", "if", "(", "mb_substr", "(", "$", "basePath", ",", "-", "1", ")", "===", "static", "::", "DIRECTORY_SEPARATOR", ")", "{", "$", "basePath", "=", "mb_substr", "(", "$", "basePath", ",", "0", ",", "-", "1", ")", ";", "}", "$", "path", "=", "$", "basePath", ".", "static", "::", "DIRECTORY_SEPARATOR", ".", "$", "path", ";", "}", "include", "$", "path", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "ob_get_clean", "(", ")", ";", "throw", "$", "e", ";", "}", "return", "ob_get_clean", "(", ")", ";", "}" ]
Returns the view at the given path with the given data. @param string $path @param string[] $data = [] @return string a string representation of the view.
[ "Returns", "the", "view", "at", "the", "given", "path", "with", "the", "given", "data", "." ]
d6725938a7c7c198deacb907c0db03e5db110d77
https://github.com/miBadger/miBadger.Mvc/blob/d6725938a7c7c198deacb907c0db03e5db110d77/src/View.php#L64-L92
train
bytic/orm
src/Navigator/Pagination/AbstractPaginator.php
AbstractPaginator.doCount
protected function doCount() { $query = $this->getCountQuery(); $result = $query->execute()->fetchResult(); $this->count = intval($result['count']); $this->pages = intval($this->count / $this->itemsPerPage); if ($this->count % $this->itemsPerPage != 0) { $this->pages++; } if ($this->pages == 0) { $this->pages = 1; } }
php
protected function doCount() { $query = $this->getCountQuery(); $result = $query->execute()->fetchResult(); $this->count = intval($result['count']); $this->pages = intval($this->count / $this->itemsPerPage); if ($this->count % $this->itemsPerPage != 0) { $this->pages++; } if ($this->pages == 0) { $this->pages = 1; } }
[ "protected", "function", "doCount", "(", ")", "{", "$", "query", "=", "$", "this", "->", "getCountQuery", "(", ")", ";", "$", "result", "=", "$", "query", "->", "execute", "(", ")", "->", "fetchResult", "(", ")", ";", "$", "this", "->", "count", "=", "intval", "(", "$", "result", "[", "'count'", "]", ")", ";", "$", "this", "->", "pages", "=", "intval", "(", "$", "this", "->", "count", "/", "$", "this", "->", "itemsPerPage", ")", ";", "if", "(", "$", "this", "->", "count", "%", "$", "this", "->", "itemsPerPage", "!=", "0", ")", "{", "$", "this", "->", "pages", "++", ";", "}", "if", "(", "$", "this", "->", "pages", "==", "0", ")", "{", "$", "this", "->", "pages", "=", "1", ";", "}", "}" ]
Does the count for all records
[ "Does", "the", "count", "for", "all", "records" ]
8d9a79b47761af0bfd9b8d1d28c83221dcac0de0
https://github.com/bytic/orm/blob/8d9a79b47761af0bfd9b8d1d28c83221dcac0de0/src/Navigator/Pagination/AbstractPaginator.php#L79-L94
train
brightnucleus/options-store
src/OptionRepository/IdentityMap.php
IdentityMap.getOption
public function getOption(string $key): Option { if (! $this->has($key)) { throw UnknownOptionKey::fromKey($key); } return $this->map[$key][self::SUBKEY_OPTION]; }
php
public function getOption(string $key): Option { if (! $this->has($key)) { throw UnknownOptionKey::fromKey($key); } return $this->map[$key][self::SUBKEY_OPTION]; }
[ "public", "function", "getOption", "(", "string", "$", "key", ")", ":", "Option", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "throw", "UnknownOptionKey", "::", "fromKey", "(", "$", "key", ")", ";", "}", "return", "$", "this", "->", "map", "[", "$", "key", "]", "[", "self", "::", "SUBKEY_OPTION", "]", ";", "}" ]
Get the associated option for a specific key. @since 0.1.0 @param string $key Key to fetch the option for. @return Option The option that is associated with the requested key.
[ "Get", "the", "associated", "option", "for", "a", "specific", "key", "." ]
9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1
https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/OptionRepository/IdentityMap.php#L90-L97
train
brightnucleus/options-store
src/OptionRepository/IdentityMap.php
IdentityMap.getRepository
public function getRepository(string $key): OptionRepository { if (! $this->has($key)) { throw UnknownOptionKey::fromKey($key); } return $this->map[$key][self::SUBKEY_REPOSITORY]; }
php
public function getRepository(string $key): OptionRepository { if (! $this->has($key)) { throw UnknownOptionKey::fromKey($key); } return $this->map[$key][self::SUBKEY_REPOSITORY]; }
[ "public", "function", "getRepository", "(", "string", "$", "key", ")", ":", "OptionRepository", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "throw", "UnknownOptionKey", "::", "fromKey", "(", "$", "key", ")", ";", "}", "return", "$", "this", "->", "map", "[", "$", "key", "]", "[", "self", "::", "SUBKEY_REPOSITORY", "]", ";", "}" ]
Get the associated repository for a specific key. @since 0.1.0 @param string $key Key to fetch the repository for. @return OptionRepository The repository that is associated with the requested key.
[ "Get", "the", "associated", "repository", "for", "a", "specific", "key", "." ]
9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1
https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/OptionRepository/IdentityMap.php#L108-L115
train
brightnucleus/options-store
src/OptionRepository/IdentityMap.php
IdentityMap.put
public function put(Option $option, OptionRepository $repository): Option { $this->map[$option->getKey()] = [ self::SUBKEY_OPTION => $option, self::SUBKEY_REPOSITORY => $repository, ]; return $option; }
php
public function put(Option $option, OptionRepository $repository): Option { $this->map[$option->getKey()] = [ self::SUBKEY_OPTION => $option, self::SUBKEY_REPOSITORY => $repository, ]; return $option; }
[ "public", "function", "put", "(", "Option", "$", "option", ",", "OptionRepository", "$", "repository", ")", ":", "Option", "{", "$", "this", "->", "map", "[", "$", "option", "->", "getKey", "(", ")", "]", "=", "[", "self", "::", "SUBKEY_OPTION", "=>", "$", "option", ",", "self", "::", "SUBKEY_REPOSITORY", "=>", "$", "repository", ",", "]", ";", "return", "$", "option", ";", "}" ]
Put a new association into the identity map. @since 0.1.0 @param Option $option Option to store for the given key. @param OptionRepository $repository Repository to store for the given key. @return Option $option Option that was stored in the identity map. This might differ from the passed-in $option.
[ "Put", "a", "new", "association", "into", "the", "identity", "map", "." ]
9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1
https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/OptionRepository/IdentityMap.php#L127-L135
train
dmitrya2e/filtration-bundle
Form/Creator/FormCreator.php
FormCreator.createForm
protected function createForm( CollectionInterface $filterCollection, $name = null, array $rootFormBuilderOptions = [], array $filterFormBuilderOptions = [] ) { // Create the root form builder, which is used as the container for all filter forms. $rootFormBuilder = $this->createFormBuilder($name, 'form', null, $rootFormBuilderOptions); if ($filterCollection->hasFilters()) { foreach ($filterCollection as $filter) { if (!($filter instanceof FilterHasFormInterface) || $filter->hasForm() !== true) { // Create a form for only filters, which have a form representation. continue; } // Create the filter form builder itself. $filterFormBuilder = $this->createFormBuilder( $filter->getName(), $this->createFilterFormType(), $filter, array_merge($filterFormBuilderOptions, ['data_class' => get_class($filter)]) ); // Append the filter to the filter form. $this->appendFormField($filter, $filterFormBuilder); // Finally, add the filter form builder to the root form builder. $rootFormBuilder->add($filterFormBuilder); } } return $rootFormBuilder->getForm(); }
php
protected function createForm( CollectionInterface $filterCollection, $name = null, array $rootFormBuilderOptions = [], array $filterFormBuilderOptions = [] ) { // Create the root form builder, which is used as the container for all filter forms. $rootFormBuilder = $this->createFormBuilder($name, 'form', null, $rootFormBuilderOptions); if ($filterCollection->hasFilters()) { foreach ($filterCollection as $filter) { if (!($filter instanceof FilterHasFormInterface) || $filter->hasForm() !== true) { // Create a form for only filters, which have a form representation. continue; } // Create the filter form builder itself. $filterFormBuilder = $this->createFormBuilder( $filter->getName(), $this->createFilterFormType(), $filter, array_merge($filterFormBuilderOptions, ['data_class' => get_class($filter)]) ); // Append the filter to the filter form. $this->appendFormField($filter, $filterFormBuilder); // Finally, add the filter form builder to the root form builder. $rootFormBuilder->add($filterFormBuilder); } } return $rootFormBuilder->getForm(); }
[ "protected", "function", "createForm", "(", "CollectionInterface", "$", "filterCollection", ",", "$", "name", "=", "null", ",", "array", "$", "rootFormBuilderOptions", "=", "[", "]", ",", "array", "$", "filterFormBuilderOptions", "=", "[", "]", ")", "{", "// Create the root form builder, which is used as the container for all filter forms.\r", "$", "rootFormBuilder", "=", "$", "this", "->", "createFormBuilder", "(", "$", "name", ",", "'form'", ",", "null", ",", "$", "rootFormBuilderOptions", ")", ";", "if", "(", "$", "filterCollection", "->", "hasFilters", "(", ")", ")", "{", "foreach", "(", "$", "filterCollection", "as", "$", "filter", ")", "{", "if", "(", "!", "(", "$", "filter", "instanceof", "FilterHasFormInterface", ")", "||", "$", "filter", "->", "hasForm", "(", ")", "!==", "true", ")", "{", "// Create a form for only filters, which have a form representation.\r", "continue", ";", "}", "// Create the filter form builder itself.\r", "$", "filterFormBuilder", "=", "$", "this", "->", "createFormBuilder", "(", "$", "filter", "->", "getName", "(", ")", ",", "$", "this", "->", "createFilterFormType", "(", ")", ",", "$", "filter", ",", "array_merge", "(", "$", "filterFormBuilderOptions", ",", "[", "'data_class'", "=>", "get_class", "(", "$", "filter", ")", "]", ")", ")", ";", "// Append the filter to the filter form.\r", "$", "this", "->", "appendFormField", "(", "$", "filter", ",", "$", "filterFormBuilder", ")", ";", "// Finally, add the filter form builder to the root form builder.\r", "$", "rootFormBuilder", "->", "add", "(", "$", "filterFormBuilder", ")", ";", "}", "}", "return", "$", "rootFormBuilder", "->", "getForm", "(", ")", ";", "}" ]
Creates the filtration form. @param CollectionInterface $filterCollection The collection of the filters @param null|string $name (Optional) The name of the root form @param array $rootFormBuilderOptions (Optional) The options for the root form @param array $filterFormBuilderOptions (Optional) The options for each filter form @return FormInterface The form with one root element, which contains as many sub-forms, as many filters there are in the collection (only considering filters, which have a form representations).
[ "Creates", "the", "filtration", "form", "." ]
fed5764af4e43871835744fb84957b2a76e9a215
https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Form/Creator/FormCreator.php#L95-L129
train
dmitrya2e/filtration-bundle
Form/Creator/FormCreator.php
FormCreator.appendFormField
protected function appendFormField(FilterHasFormInterface $filter, FormBuilderInterface $filterFormBuilder) { if (!($filter instanceof CustomAppendFormFieldsInterface)) { $filter->appendFormFieldsToForm($filterFormBuilder); return $filter; } $callableFunction = $filter->getAppendFormFieldsFunction(); if (!is_callable($callableFunction)) { /** @var FilterHasFormInterface $filter */ $filter->appendFormFieldsToForm($filterFormBuilder); return $filter; } call_user_func($callableFunction, $filter, $filterFormBuilder); return $filter; }
php
protected function appendFormField(FilterHasFormInterface $filter, FormBuilderInterface $filterFormBuilder) { if (!($filter instanceof CustomAppendFormFieldsInterface)) { $filter->appendFormFieldsToForm($filterFormBuilder); return $filter; } $callableFunction = $filter->getAppendFormFieldsFunction(); if (!is_callable($callableFunction)) { /** @var FilterHasFormInterface $filter */ $filter->appendFormFieldsToForm($filterFormBuilder); return $filter; } call_user_func($callableFunction, $filter, $filterFormBuilder); return $filter; }
[ "protected", "function", "appendFormField", "(", "FilterHasFormInterface", "$", "filter", ",", "FormBuilderInterface", "$", "filterFormBuilder", ")", "{", "if", "(", "!", "(", "$", "filter", "instanceof", "CustomAppendFormFieldsInterface", ")", ")", "{", "$", "filter", "->", "appendFormFieldsToForm", "(", "$", "filterFormBuilder", ")", ";", "return", "$", "filter", ";", "}", "$", "callableFunction", "=", "$", "filter", "->", "getAppendFormFieldsFunction", "(", ")", ";", "if", "(", "!", "is_callable", "(", "$", "callableFunction", ")", ")", "{", "/** @var FilterHasFormInterface $filter */", "$", "filter", "->", "appendFormFieldsToForm", "(", "$", "filterFormBuilder", ")", ";", "return", "$", "filter", ";", "}", "call_user_func", "(", "$", "callableFunction", ",", "$", "filter", ",", "$", "filterFormBuilder", ")", ";", "return", "$", "filter", ";", "}" ]
The main "actor" here. Appends a filter to the representation form. If the filter has defined a custom function for form appending, than it will be used. @param FilterHasFormInterface $filter The filter @param FormBuilderInterface $filterFormBuilder A form builder for a specific filter @return FilterHasFormInterface|CustomAppendFormFieldsInterface
[ "The", "main", "actor", "here", ".", "Appends", "a", "filter", "to", "the", "representation", "form", ".", "If", "the", "filter", "has", "defined", "a", "custom", "function", "for", "form", "appending", "than", "it", "will", "be", "used", "." ]
fed5764af4e43871835744fb84957b2a76e9a215
https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Form/Creator/FormCreator.php#L141-L161
train
dmitrya2e/filtration-bundle
Form/Creator/FormCreator.php
FormCreator.createFormBuilder
protected function createFormBuilder($name = null, $type = 'form', $data = null, array $options = []) { if ($name !== null) { return $this->formFactory->createNamedBuilder($name, $type, $data, $options); } return $this->formFactory->createBuilder($type, $data, $options); }
php
protected function createFormBuilder($name = null, $type = 'form', $data = null, array $options = []) { if ($name !== null) { return $this->formFactory->createNamedBuilder($name, $type, $data, $options); } return $this->formFactory->createBuilder($type, $data, $options); }
[ "protected", "function", "createFormBuilder", "(", "$", "name", "=", "null", ",", "$", "type", "=", "'form'", ",", "$", "data", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "name", "!==", "null", ")", "{", "return", "$", "this", "->", "formFactory", "->", "createNamedBuilder", "(", "$", "name", ",", "$", "type", ",", "$", "data", ",", "$", "options", ")", ";", "}", "return", "$", "this", "->", "formFactory", "->", "createBuilder", "(", "$", "type", ",", "$", "data", ",", "$", "options", ")", ";", "}" ]
Creates and returns a form builder. @param null|string $name For named form builder must not be null @param string|object $type Form type @param mixed|null $data Form data @param array $options Form builder options @return FormBuilderInterface
[ "Creates", "and", "returns", "a", "form", "builder", "." ]
fed5764af4e43871835744fb84957b2a76e9a215
https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Form/Creator/FormCreator.php#L173-L180
train
dmitrya2e/filtration-bundle
Form/Creator/FormCreator.php
FormCreator.validateConfig
protected function validateConfig(array $config) { // For now it's only required to pass a filter form type class. // If you don't want to use a defined form type class, // you can override the FormCreator object, implement FormCreatorInterface and customize it. $requiredKeys = ['form_filter_type_class']; foreach ($requiredKeys as $key) { if (!array_key_exists($key, $config)) { throw new FormCreatorException(sprintf( 'Key "%s" must be presented in the filters configuration.', $key )); } if (!class_exists($config[$key])) { throw new FormCreatorException(sprintf('Class "%s" is not found.', $config[$key])); } } }
php
protected function validateConfig(array $config) { // For now it's only required to pass a filter form type class. // If you don't want to use a defined form type class, // you can override the FormCreator object, implement FormCreatorInterface and customize it. $requiredKeys = ['form_filter_type_class']; foreach ($requiredKeys as $key) { if (!array_key_exists($key, $config)) { throw new FormCreatorException(sprintf( 'Key "%s" must be presented in the filters configuration.', $key )); } if (!class_exists($config[$key])) { throw new FormCreatorException(sprintf('Class "%s" is not found.', $config[$key])); } } }
[ "protected", "function", "validateConfig", "(", "array", "$", "config", ")", "{", "// For now it's only required to pass a filter form type class.\r", "// If you don't want to use a defined form type class,\r", "// you can override the FormCreator object, implement FormCreatorInterface and customize it.\r", "$", "requiredKeys", "=", "[", "'form_filter_type_class'", "]", ";", "foreach", "(", "$", "requiredKeys", "as", "$", "key", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "config", ")", ")", "{", "throw", "new", "FormCreatorException", "(", "sprintf", "(", "'Key \"%s\" must be presented in the filters configuration.'", ",", "$", "key", ")", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "config", "[", "$", "key", "]", ")", ")", "{", "throw", "new", "FormCreatorException", "(", "sprintf", "(", "'Class \"%s\" is not found.'", ",", "$", "config", "[", "$", "key", "]", ")", ")", ";", "}", "}", "}" ]
Validates configuration. @param array $config @throws FormCreatorException
[ "Validates", "configuration", "." ]
fed5764af4e43871835744fb84957b2a76e9a215
https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Form/Creator/FormCreator.php#L199-L217
train
gplcart/cli
controllers/commands/CategoryGroup.php
CategoryGroup.cmdGetCategoryGroup
public function cmdGetCategoryGroup() { $result = $this->getListCategoryGroup(); $this->outputFormat($result); $this->outputFormatTableCategoryGroup($result); $this->output(); }
php
public function cmdGetCategoryGroup() { $result = $this->getListCategoryGroup(); $this->outputFormat($result); $this->outputFormatTableCategoryGroup($result); $this->output(); }
[ "public", "function", "cmdGetCategoryGroup", "(", ")", "{", "$", "result", "=", "$", "this", "->", "getListCategoryGroup", "(", ")", ";", "$", "this", "->", "outputFormat", "(", "$", "result", ")", ";", "$", "this", "->", "outputFormatTableCategoryGroup", "(", "$", "result", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "category-group-get" command
[ "Callback", "for", "category", "-", "group", "-", "get", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CategoryGroup.php#L40-L46
train
gplcart/cli
controllers/commands/CategoryGroup.php
CategoryGroup.cmdUpdateCategoryGroup
public function cmdUpdateCategoryGroup() { $params = $this->getParam(); if (empty($params[0]) || count($params) < 2) { $this->errorAndExit($this->text('Invalid command')); } if (!is_numeric($params[0])) { $this->errorAndExit($this->text('Invalid argument')); } $this->setSubmitted(null, $params); $this->setSubmitted('update', $params[0]); $this->validateComponent('category_group'); $this->updateCategoryGroup($params[0]); $this->output(); }
php
public function cmdUpdateCategoryGroup() { $params = $this->getParam(); if (empty($params[0]) || count($params) < 2) { $this->errorAndExit($this->text('Invalid command')); } if (!is_numeric($params[0])) { $this->errorAndExit($this->text('Invalid argument')); } $this->setSubmitted(null, $params); $this->setSubmitted('update', $params[0]); $this->validateComponent('category_group'); $this->updateCategoryGroup($params[0]); $this->output(); }
[ "public", "function", "cmdUpdateCategoryGroup", "(", ")", "{", "$", "params", "=", "$", "this", "->", "getParam", "(", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "0", "]", ")", "||", "count", "(", "$", "params", ")", "<", "2", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid command'", ")", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "params", "[", "0", "]", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "params", ")", ";", "$", "this", "->", "setSubmitted", "(", "'update'", ",", "$", "params", "[", "0", "]", ")", ";", "$", "this", "->", "validateComponent", "(", "'category_group'", ")", ";", "$", "this", "->", "updateCategoryGroup", "(", "$", "params", "[", "0", "]", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "category-group-update" command
[ "Callback", "for", "category", "-", "group", "-", "update", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CategoryGroup.php#L110-L128
train
gplcart/cli
controllers/commands/CategoryGroup.php
CategoryGroup.addCategoryGroup
protected function addCategoryGroup() { if (!$this->isError()) { $id = $this->category_group->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
php
protected function addCategoryGroup() { if (!$this->isError()) { $id = $this->category_group->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
[ "protected", "function", "addCategoryGroup", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isError", "(", ")", ")", "{", "$", "id", "=", "$", "this", "->", "category_group", "->", "add", "(", "$", "this", "->", "getSubmitted", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "$", "this", "->", "line", "(", "$", "id", ")", ";", "}", "}" ]
Add a new category group
[ "Add", "a", "new", "category", "group" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CategoryGroup.php#L193-L202
train
gplcart/cli
controllers/commands/CategoryGroup.php
CategoryGroup.submitAddCategoryGroup
protected function submitAddCategoryGroup() { $this->setSubmitted(null, $this->getParam()); $this->validateComponent('category_group'); $this->addCategoryGroup(); }
php
protected function submitAddCategoryGroup() { $this->setSubmitted(null, $this->getParam()); $this->validateComponent('category_group'); $this->addCategoryGroup(); }
[ "protected", "function", "submitAddCategoryGroup", "(", ")", "{", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "this", "->", "getParam", "(", ")", ")", ";", "$", "this", "->", "validateComponent", "(", "'category_group'", ")", ";", "$", "this", "->", "addCategoryGroup", "(", ")", ";", "}" ]
Add a new category group at once
[ "Add", "a", "new", "category", "group", "at", "once" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CategoryGroup.php#L218-L223
train
gplcart/cli
controllers/commands/CategoryGroup.php
CategoryGroup.wizardAddCategoryGroup
protected function wizardAddCategoryGroup() { $this->validatePrompt('title', $this->text('Name'), 'category_group'); $this->validatePrompt('store_id', $this->text('Store ID'), 'category_group'); $this->validateMenu('type', $this->text('Type'), 'category_group', $this->category_group->getTypes()); $this->validateComponent('category_group'); $this->addCategoryGroup(); }
php
protected function wizardAddCategoryGroup() { $this->validatePrompt('title', $this->text('Name'), 'category_group'); $this->validatePrompt('store_id', $this->text('Store ID'), 'category_group'); $this->validateMenu('type', $this->text('Type'), 'category_group', $this->category_group->getTypes()); $this->validateComponent('category_group'); $this->addCategoryGroup(); }
[ "protected", "function", "wizardAddCategoryGroup", "(", ")", "{", "$", "this", "->", "validatePrompt", "(", "'title'", ",", "$", "this", "->", "text", "(", "'Name'", ")", ",", "'category_group'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'store_id'", ",", "$", "this", "->", "text", "(", "'Store ID'", ")", ",", "'category_group'", ")", ";", "$", "this", "->", "validateMenu", "(", "'type'", ",", "$", "this", "->", "text", "(", "'Type'", ")", ",", "'category_group'", ",", "$", "this", "->", "category_group", "->", "getTypes", "(", ")", ")", ";", "$", "this", "->", "validateComponent", "(", "'category_group'", ")", ";", "$", "this", "->", "addCategoryGroup", "(", ")", ";", "}" ]
Add a new category group step by step
[ "Add", "a", "new", "category", "group", "step", "by", "step" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CategoryGroup.php#L228-L236
train
agentmedia/phine-core
src/Core/Snippets/BackendRights/Base/RightsCheckboxes.php
RightsCheckboxes.RenderCheckbox
protected function RenderCheckbox($name) { $checkbox = new Checkbox($this->namePrefix . $name); $class = new \ReflectionClass($this); $checkbox->SetLabel(Trans('Core.' . $class->getShortName() . '.' . $name)); if ($this->Value($name)) { $checkbox->SetChecked(); } $field = new CheckboxField($checkbox); return $field->Render(); }
php
protected function RenderCheckbox($name) { $checkbox = new Checkbox($this->namePrefix . $name); $class = new \ReflectionClass($this); $checkbox->SetLabel(Trans('Core.' . $class->getShortName() . '.' . $name)); if ($this->Value($name)) { $checkbox->SetChecked(); } $field = new CheckboxField($checkbox); return $field->Render(); }
[ "protected", "function", "RenderCheckbox", "(", "$", "name", ")", "{", "$", "checkbox", "=", "new", "Checkbox", "(", "$", "this", "->", "namePrefix", ".", "$", "name", ")", ";", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "this", ")", ";", "$", "checkbox", "->", "SetLabel", "(", "Trans", "(", "'Core.'", ".", "$", "class", "->", "getShortName", "(", ")", ".", "'.'", ".", "$", "name", ")", ")", ";", "if", "(", "$", "this", "->", "Value", "(", "$", "name", ")", ")", "{", "$", "checkbox", "->", "SetChecked", "(", ")", ";", "}", "$", "field", "=", "new", "CheckboxField", "(", "$", "checkbox", ")", ";", "return", "$", "field", "->", "Render", "(", ")", ";", "}" ]
Renders a specific checkbox @param string $name @return string
[ "Renders", "a", "specific", "checkbox" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Snippets/BackendRights/Base/RightsCheckboxes.php#L51-L62
train
agentmedia/phine-core
src/Core/Snippets/BackendRights/Base/RightsCheckboxes.php
RightsCheckboxes.Value
protected function Value($name) { if (Request::IsPost()) { return (bool)trim(Request::PostData($this->namePrefix . $name)); } if ($this->Rights()) { return $this->Rights()->$name; } if ($this->ParentRights()) { return $this->ParentRights()->$name; } return false; }
php
protected function Value($name) { if (Request::IsPost()) { return (bool)trim(Request::PostData($this->namePrefix . $name)); } if ($this->Rights()) { return $this->Rights()->$name; } if ($this->ParentRights()) { return $this->ParentRights()->$name; } return false; }
[ "protected", "function", "Value", "(", "$", "name", ")", "{", "if", "(", "Request", "::", "IsPost", "(", ")", ")", "{", "return", "(", "bool", ")", "trim", "(", "Request", "::", "PostData", "(", "$", "this", "->", "namePrefix", ".", "$", "name", ")", ")", ";", "}", "if", "(", "$", "this", "->", "Rights", "(", ")", ")", "{", "return", "$", "this", "->", "Rights", "(", ")", "->", "$", "name", ";", "}", "if", "(", "$", "this", "->", "ParentRights", "(", ")", ")", "{", "return", "$", "this", "->", "ParentRights", "(", ")", "->", "$", "name", ";", "}", "return", "false", ";", "}" ]
Gets the posted value of the name, optional name prefix automatically attached @param string $name The checkbox name without prefix
[ "Gets", "the", "posted", "value", "of", "the", "name", "optional", "name", "prefix", "automatically", "attached" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Snippets/BackendRights/Base/RightsCheckboxes.php#L67-L82
train
leogitpro/php-network
src/Client.php
Client.reset
public function reset() { $this->_headers->clearHeaders(); $this->params = []; $this->postRawData = null; $this->httpClient->reset(); return $this; }
php
public function reset() { $this->_headers->clearHeaders(); $this->params = []; $this->postRawData = null; $this->httpClient->reset(); return $this; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "_headers", "->", "clearHeaders", "(", ")", ";", "$", "this", "->", "params", "=", "[", "]", ";", "$", "this", "->", "postRawData", "=", "null", ";", "$", "this", "->", "httpClient", "->", "reset", "(", ")", ";", "return", "$", "this", ";", "}" ]
Reset request information @return Client
[ "Reset", "request", "information" ]
6428e5081dce336ef36edcca28d8ea2b45bd2fce
https://github.com/leogitpro/php-network/blob/6428e5081dce336ef36edcca28d8ea2b45bd2fce/src/Client.php#L172-L179
train
leogitpro/php-network
src/Client.php
Client.send
public function send() { if (empty($this->uri)) { throw new InvalidArgumentException('Invalid url for request.'); } $customRequest = new Request(); $customRequest->setHeaders($this->_headers); $this->httpClient->setRequest($customRequest); $this->httpClient->setMethod($this->method); $this->httpClient->setUri($this->uri); if ($this->method == Request::METHOD_GET) { if (!empty($this->params)) { $this->httpClient->setParameterGet($this->params); } } if ($this->method == Request::METHOD_POST) { if (!empty($this->params)) { $this->httpClient->setParameterPost($this->params); } } if ($this->postRawData !== null) { $this->httpClient->setRawBody($this->postRawData); } try { $this->response = $this->httpClient->send(); if (!$this->response->isSuccess()) { throw new RuntimeException('Http request failure!'); } $this->request = $this->httpClient->getRequest(); return $this->response; } catch (HttpClientRuntimeException $exception) { throw new RuntimeException($exception->getMessage()); } catch (HttpRuntimeException $exception) { throw new RuntimeException($exception->getMessage()); } }
php
public function send() { if (empty($this->uri)) { throw new InvalidArgumentException('Invalid url for request.'); } $customRequest = new Request(); $customRequest->setHeaders($this->_headers); $this->httpClient->setRequest($customRequest); $this->httpClient->setMethod($this->method); $this->httpClient->setUri($this->uri); if ($this->method == Request::METHOD_GET) { if (!empty($this->params)) { $this->httpClient->setParameterGet($this->params); } } if ($this->method == Request::METHOD_POST) { if (!empty($this->params)) { $this->httpClient->setParameterPost($this->params); } } if ($this->postRawData !== null) { $this->httpClient->setRawBody($this->postRawData); } try { $this->response = $this->httpClient->send(); if (!$this->response->isSuccess()) { throw new RuntimeException('Http request failure!'); } $this->request = $this->httpClient->getRequest(); return $this->response; } catch (HttpClientRuntimeException $exception) { throw new RuntimeException($exception->getMessage()); } catch (HttpRuntimeException $exception) { throw new RuntimeException($exception->getMessage()); } }
[ "public", "function", "send", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "uri", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid url for request.'", ")", ";", "}", "$", "customRequest", "=", "new", "Request", "(", ")", ";", "$", "customRequest", "->", "setHeaders", "(", "$", "this", "->", "_headers", ")", ";", "$", "this", "->", "httpClient", "->", "setRequest", "(", "$", "customRequest", ")", ";", "$", "this", "->", "httpClient", "->", "setMethod", "(", "$", "this", "->", "method", ")", ";", "$", "this", "->", "httpClient", "->", "setUri", "(", "$", "this", "->", "uri", ")", ";", "if", "(", "$", "this", "->", "method", "==", "Request", "::", "METHOD_GET", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "params", ")", ")", "{", "$", "this", "->", "httpClient", "->", "setParameterGet", "(", "$", "this", "->", "params", ")", ";", "}", "}", "if", "(", "$", "this", "->", "method", "==", "Request", "::", "METHOD_POST", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "params", ")", ")", "{", "$", "this", "->", "httpClient", "->", "setParameterPost", "(", "$", "this", "->", "params", ")", ";", "}", "}", "if", "(", "$", "this", "->", "postRawData", "!==", "null", ")", "{", "$", "this", "->", "httpClient", "->", "setRawBody", "(", "$", "this", "->", "postRawData", ")", ";", "}", "try", "{", "$", "this", "->", "response", "=", "$", "this", "->", "httpClient", "->", "send", "(", ")", ";", "if", "(", "!", "$", "this", "->", "response", "->", "isSuccess", "(", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Http request failure!'", ")", ";", "}", "$", "this", "->", "request", "=", "$", "this", "->", "httpClient", "->", "getRequest", "(", ")", ";", "return", "$", "this", "->", "response", ";", "}", "catch", "(", "HttpClientRuntimeException", "$", "exception", ")", "{", "throw", "new", "RuntimeException", "(", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "HttpRuntimeException", "$", "exception", ")", "{", "throw", "new", "RuntimeException", "(", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Send http request @throws InvalidArgumentException @throws RuntimeException @return Response
[ "Send", "http", "request" ]
6428e5081dce336ef36edcca28d8ea2b45bd2fce
https://github.com/leogitpro/php-network/blob/6428e5081dce336ef36edcca28d8ea2b45bd2fce/src/Client.php#L291-L334
train
leogitpro/php-network
src/Client.php
Client.genericDefaultHeaders
private function genericDefaultHeaders() { //Cache-Control: no-cache $this->addRawHeaderLine('Cache-Control', 'no-cache'); //Pragma: no-cache $this->addRawHeaderLine('Pragma', 'no-cache'); //Connection: keep-alive $this->addRawHeaderLine('Connection', 'keep-alive'); //Upgrade-Insecure-Requests: 1 $this->addRawHeaderLine('Upgrade-Insecure-Requests', '1'); //User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 $this->addRawHeaderLine('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'); //Accept-Encoding: gzip, deflate Only support the 2 types $this->addRawHeaderLine('Accept-Encoding', ['gzip', 'deflate']); //Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 $this->addRawHeaderLine('Accept-Language', ['zh-CN', 'zh;q=0.8', 'zh-TW;q=0.7', 'zh-HK;q=0.5', 'en-US;q=0.3', 'en;q=0.2']); }
php
private function genericDefaultHeaders() { //Cache-Control: no-cache $this->addRawHeaderLine('Cache-Control', 'no-cache'); //Pragma: no-cache $this->addRawHeaderLine('Pragma', 'no-cache'); //Connection: keep-alive $this->addRawHeaderLine('Connection', 'keep-alive'); //Upgrade-Insecure-Requests: 1 $this->addRawHeaderLine('Upgrade-Insecure-Requests', '1'); //User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 $this->addRawHeaderLine('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'); //Accept-Encoding: gzip, deflate Only support the 2 types $this->addRawHeaderLine('Accept-Encoding', ['gzip', 'deflate']); //Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 $this->addRawHeaderLine('Accept-Language', ['zh-CN', 'zh;q=0.8', 'zh-TW;q=0.7', 'zh-HK;q=0.5', 'en-US;q=0.3', 'en;q=0.2']); }
[ "private", "function", "genericDefaultHeaders", "(", ")", "{", "//Cache-Control: no-cache", "$", "this", "->", "addRawHeaderLine", "(", "'Cache-Control'", ",", "'no-cache'", ")", ";", "//Pragma: no-cache", "$", "this", "->", "addRawHeaderLine", "(", "'Pragma'", ",", "'no-cache'", ")", ";", "//Connection: keep-alive", "$", "this", "->", "addRawHeaderLine", "(", "'Connection'", ",", "'keep-alive'", ")", ";", "//Upgrade-Insecure-Requests: 1", "$", "this", "->", "addRawHeaderLine", "(", "'Upgrade-Insecure-Requests'", ",", "'1'", ")", ";", "//User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36", "$", "this", "->", "addRawHeaderLine", "(", "'User-Agent'", ",", "'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'", ")", ";", "//Accept-Encoding: gzip, deflate Only support the 2 types", "$", "this", "->", "addRawHeaderLine", "(", "'Accept-Encoding'", ",", "[", "'gzip'", ",", "'deflate'", "]", ")", ";", "//Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "$", "this", "->", "addRawHeaderLine", "(", "'Accept-Language'", ",", "[", "'zh-CN'", ",", "'zh;q=0.8'", ",", "'zh-TW;q=0.7'", ",", "'zh-HK;q=0.5'", ",", "'en-US;q=0.3'", ",", "'en;q=0.2'", "]", ")", ";", "}" ]
Default request headers
[ "Default", "request", "headers" ]
6428e5081dce336ef36edcca28d8ea2b45bd2fce
https://github.com/leogitpro/php-network/blob/6428e5081dce336ef36edcca28d8ea2b45bd2fce/src/Client.php#L339-L363
train
koolkode/k2
src/Log/LoggerManager.php
LoggerManager.getLogger
public function getLogger(ExposedContainerInterface $container, InjectionPointInterface $point = NULL) { $channel = ($point === NULL) ? 'app' : str_replace('\\', '.', $point->getTypeName()); if(isset($this->loggers[$channel])) { return $this->loggers[$channel]; } $logger = new Logger($channel); $logger->pushProcessor(new PsrLogMessageProcessor()); $handled = false; foreach($this->matchers as $handlerName => $patterns) { foreach($patterns as $pattern) { if(preg_match($pattern, $channel)) { $logger->pushHandler($this->getHandler($handlerName, $container)); $handled = true; break; } } } if(!$handled) { $logger->pushHandler(new NullHandler()); } return $this->loggers[$channel] = $logger; }
php
public function getLogger(ExposedContainerInterface $container, InjectionPointInterface $point = NULL) { $channel = ($point === NULL) ? 'app' : str_replace('\\', '.', $point->getTypeName()); if(isset($this->loggers[$channel])) { return $this->loggers[$channel]; } $logger = new Logger($channel); $logger->pushProcessor(new PsrLogMessageProcessor()); $handled = false; foreach($this->matchers as $handlerName => $patterns) { foreach($patterns as $pattern) { if(preg_match($pattern, $channel)) { $logger->pushHandler($this->getHandler($handlerName, $container)); $handled = true; break; } } } if(!$handled) { $logger->pushHandler(new NullHandler()); } return $this->loggers[$channel] = $logger; }
[ "public", "function", "getLogger", "(", "ExposedContainerInterface", "$", "container", ",", "InjectionPointInterface", "$", "point", "=", "NULL", ")", "{", "$", "channel", "=", "(", "$", "point", "===", "NULL", ")", "?", "'app'", ":", "str_replace", "(", "'\\\\'", ",", "'.'", ",", "$", "point", "->", "getTypeName", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "loggers", "[", "$", "channel", "]", ")", ")", "{", "return", "$", "this", "->", "loggers", "[", "$", "channel", "]", ";", "}", "$", "logger", "=", "new", "Logger", "(", "$", "channel", ")", ";", "$", "logger", "->", "pushProcessor", "(", "new", "PsrLogMessageProcessor", "(", ")", ")", ";", "$", "handled", "=", "false", ";", "foreach", "(", "$", "this", "->", "matchers", "as", "$", "handlerName", "=>", "$", "patterns", ")", "{", "foreach", "(", "$", "patterns", "as", "$", "pattern", ")", "{", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "channel", ")", ")", "{", "$", "logger", "->", "pushHandler", "(", "$", "this", "->", "getHandler", "(", "$", "handlerName", ",", "$", "container", ")", ")", ";", "$", "handled", "=", "true", ";", "break", ";", "}", "}", "}", "if", "(", "!", "$", "handled", ")", "{", "$", "logger", "->", "pushHandler", "(", "new", "NullHandler", "(", ")", ")", ";", "}", "return", "$", "this", "->", "loggers", "[", "$", "channel", "]", "=", "$", "logger", ";", "}" ]
Obtain a logger instance, the log channel will consist of the type name provided by the injection point where all namespace separators will be replaced by periods. @param ExposedContainerInterface $container DI container being used for log handler creation. @param InjectionPointInterface $point The target of the injection. @return LoggerInterface Created (or cached) logger instance.
[ "Obtain", "a", "logger", "instance", "the", "log", "channel", "will", "consist", "of", "the", "type", "name", "provided", "by", "the", "injection", "point", "where", "all", "namespace", "separators", "will", "be", "replaced", "by", "periods", "." ]
c425a1bc7d2f8c567b1b0cc724ca9e8be7087397
https://github.com/koolkode/k2/blob/c425a1bc7d2f8c567b1b0cc724ca9e8be7087397/src/Log/LoggerManager.php#L69-L103
train
koolkode/k2
src/Log/LoggerManager.php
LoggerManager.replaceSpecialChars
protected function replaceSpecialChars($input) { if(is_array($input)) { $result = []; foreach($input as $k => $v) { $result[$k] = $this->replaceSpecialChars($v); } return $result; } return strtr($input, [ '\n' => "\n", '\t' => "\t" ]); }
php
protected function replaceSpecialChars($input) { if(is_array($input)) { $result = []; foreach($input as $k => $v) { $result[$k] = $this->replaceSpecialChars($v); } return $result; } return strtr($input, [ '\n' => "\n", '\t' => "\t" ]); }
[ "protected", "function", "replaceSpecialChars", "(", "$", "input", ")", "{", "if", "(", "is_array", "(", "$", "input", ")", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "input", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "result", "[", "$", "k", "]", "=", "$", "this", "->", "replaceSpecialChars", "(", "$", "v", ")", ";", "}", "return", "$", "result", ";", "}", "return", "strtr", "(", "$", "input", ",", "[", "'\\n'", "=>", "\"\\n\"", ",", "'\\t'", "=>", "\"\\t\"", "]", ")", ";", "}" ]
Recursively replaces special escape characters for line breaks and tabs with according characters. @param mixed $input @return mixed
[ "Recursively", "replaces", "special", "escape", "characters", "for", "line", "breaks", "and", "tabs", "with", "according", "characters", "." ]
c425a1bc7d2f8c567b1b0cc724ca9e8be7087397
https://github.com/koolkode/k2/blob/c425a1bc7d2f8c567b1b0cc724ca9e8be7087397/src/Log/LoggerManager.php#L158-L176
train
ekyna/Table
Bridge/Doctrine/ORM/Source/EntityAdapter.php
EntityAdapter.getQueryBuilderPath
public function getQueryBuilderPath($propertyPath) { if (false === strpos($propertyPath, '.')) { return $this->alias . '.' . $propertyPath; } if (isset($this->paths[$propertyPath])) { return $this->paths[$propertyPath]; } $paths = explode('.', $propertyPath); $property = array_pop($paths); $path = implode('.', array_slice($paths, 0, $i = count($paths))); if (!isset($this->aliases[$path])) { // Skip already defined aliases do { $i--; $path = implode('.', array_slice($paths, 0, $i)); if (isset($this->aliases[$path])) { break; } } while ($i > 0); do { // TODO Join may have been made by the source's query builder initializer : retrieve the configured alias //$this->queryBuilder->getDQLPart('join'); $alias = chr(98 + count($this->aliases)); $this->queryBuilder->leftJoin(($i == 0 ? $this->alias : $this->aliases[$path]) . '.' . $paths[$i], $alias); // Add select if manyToOne and lvl = 1 (ex: product.brand => b) if ($i == 0 && $this->getClassMetadata()->isSingleValuedAssociation($paths[$i])) { $this->queryBuilder->addSelect($alias); } $i++; $path = implode('.', array_slice($paths, 0, $i)); $this->aliases[$path] = $alias; } while ($i < count($paths)); } return $this->paths[$propertyPath] = $this->aliases[$path] . '.' . $property; }
php
public function getQueryBuilderPath($propertyPath) { if (false === strpos($propertyPath, '.')) { return $this->alias . '.' . $propertyPath; } if (isset($this->paths[$propertyPath])) { return $this->paths[$propertyPath]; } $paths = explode('.', $propertyPath); $property = array_pop($paths); $path = implode('.', array_slice($paths, 0, $i = count($paths))); if (!isset($this->aliases[$path])) { // Skip already defined aliases do { $i--; $path = implode('.', array_slice($paths, 0, $i)); if (isset($this->aliases[$path])) { break; } } while ($i > 0); do { // TODO Join may have been made by the source's query builder initializer : retrieve the configured alias //$this->queryBuilder->getDQLPart('join'); $alias = chr(98 + count($this->aliases)); $this->queryBuilder->leftJoin(($i == 0 ? $this->alias : $this->aliases[$path]) . '.' . $paths[$i], $alias); // Add select if manyToOne and lvl = 1 (ex: product.brand => b) if ($i == 0 && $this->getClassMetadata()->isSingleValuedAssociation($paths[$i])) { $this->queryBuilder->addSelect($alias); } $i++; $path = implode('.', array_slice($paths, 0, $i)); $this->aliases[$path] = $alias; } while ($i < count($paths)); } return $this->paths[$propertyPath] = $this->aliases[$path] . '.' . $property; }
[ "public", "function", "getQueryBuilderPath", "(", "$", "propertyPath", ")", "{", "if", "(", "false", "===", "strpos", "(", "$", "propertyPath", ",", "'.'", ")", ")", "{", "return", "$", "this", "->", "alias", ".", "'.'", ".", "$", "propertyPath", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "paths", "[", "$", "propertyPath", "]", ")", ")", "{", "return", "$", "this", "->", "paths", "[", "$", "propertyPath", "]", ";", "}", "$", "paths", "=", "explode", "(", "'.'", ",", "$", "propertyPath", ")", ";", "$", "property", "=", "array_pop", "(", "$", "paths", ")", ";", "$", "path", "=", "implode", "(", "'.'", ",", "array_slice", "(", "$", "paths", ",", "0", ",", "$", "i", "=", "count", "(", "$", "paths", ")", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "aliases", "[", "$", "path", "]", ")", ")", "{", "// Skip already defined aliases", "do", "{", "$", "i", "--", ";", "$", "path", "=", "implode", "(", "'.'", ",", "array_slice", "(", "$", "paths", ",", "0", ",", "$", "i", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "path", "]", ")", ")", "{", "break", ";", "}", "}", "while", "(", "$", "i", ">", "0", ")", ";", "do", "{", "// TODO Join may have been made by the source's query builder initializer : retrieve the configured alias", "//$this->queryBuilder->getDQLPart('join');", "$", "alias", "=", "chr", "(", "98", "+", "count", "(", "$", "this", "->", "aliases", ")", ")", ";", "$", "this", "->", "queryBuilder", "->", "leftJoin", "(", "(", "$", "i", "==", "0", "?", "$", "this", "->", "alias", ":", "$", "this", "->", "aliases", "[", "$", "path", "]", ")", ".", "'.'", ".", "$", "paths", "[", "$", "i", "]", ",", "$", "alias", ")", ";", "// Add select if manyToOne and lvl = 1 (ex: product.brand => b)", "if", "(", "$", "i", "==", "0", "&&", "$", "this", "->", "getClassMetadata", "(", ")", "->", "isSingleValuedAssociation", "(", "$", "paths", "[", "$", "i", "]", ")", ")", "{", "$", "this", "->", "queryBuilder", "->", "addSelect", "(", "$", "alias", ")", ";", "}", "$", "i", "++", ";", "$", "path", "=", "implode", "(", "'.'", ",", "array_slice", "(", "$", "paths", ",", "0", ",", "$", "i", ")", ")", ";", "$", "this", "->", "aliases", "[", "$", "path", "]", "=", "$", "alias", ";", "}", "while", "(", "$", "i", "<", "count", "(", "$", "paths", ")", ")", ";", "}", "return", "$", "this", "->", "paths", "[", "$", "propertyPath", "]", "=", "$", "this", "->", "aliases", "[", "$", "path", "]", ".", "'.'", ".", "$", "property", ";", "}" ]
Converts the property path to a query builder path and configures the necessary joins. @param string $propertyPath @return string
[ "Converts", "the", "property", "path", "to", "a", "query", "builder", "path", "and", "configures", "the", "necessary", "joins", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Bridge/Doctrine/ORM/Source/EntityAdapter.php#L94-L139
train
ekyna/Table
Bridge/Doctrine/ORM/Source/EntityAdapter.php
EntityAdapter.getClassMetadata
private function getClassMetadata() { if (null !== $this->metadata) { return $this->metadata; } return $this->metadata = $this->manager->getClassMetadata($this->getSource()->getClass()); }
php
private function getClassMetadata() { if (null !== $this->metadata) { return $this->metadata; } return $this->metadata = $this->manager->getClassMetadata($this->getSource()->getClass()); }
[ "private", "function", "getClassMetadata", "(", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "metadata", ")", "{", "return", "$", "this", "->", "metadata", ";", "}", "return", "$", "this", "->", "metadata", "=", "$", "this", "->", "manager", "->", "getClassMetadata", "(", "$", "this", "->", "getSource", "(", ")", "->", "getClass", "(", ")", ")", ";", "}" ]
Returns the class metadata. @return ClassMetadata
[ "Returns", "the", "class", "metadata", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Bridge/Doctrine/ORM/Source/EntityAdapter.php#L242-L249
train
OpenConext-Attic/OpenConext-engineblock-metadata
src/AttributeReleasePolicy.php
AttributeReleasePolicy.getRulesWithSourceSpecification
public function getRulesWithSourceSpecification() { $rulesWithSource = []; foreach ($this->attributeRules as $name => $rules) { $rulesWithSource[$name] = array_filter( $rules, function ($rule) { return isset($rule['source']); } ); } return array_filter($rulesWithSource); }
php
public function getRulesWithSourceSpecification() { $rulesWithSource = []; foreach ($this->attributeRules as $name => $rules) { $rulesWithSource[$name] = array_filter( $rules, function ($rule) { return isset($rule['source']); } ); } return array_filter($rulesWithSource); }
[ "public", "function", "getRulesWithSourceSpecification", "(", ")", "{", "$", "rulesWithSource", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "attributeRules", "as", "$", "name", "=>", "$", "rules", ")", "{", "$", "rulesWithSource", "[", "$", "name", "]", "=", "array_filter", "(", "$", "rules", ",", "function", "(", "$", "rule", ")", "{", "return", "isset", "(", "$", "rule", "[", "'source'", "]", ")", ";", "}", ")", ";", "}", "return", "array_filter", "(", "$", "rulesWithSource", ")", ";", "}" ]
Return all attribute rules eligible for attribute aggregation. A rule is eligible for attribute aggregation if it contains a source. @return array
[ "Return", "all", "attribute", "rules", "eligible", "for", "attribute", "aggregation", "." ]
236e2f52ef9cf28e71404544a1c4388f63ee535d
https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/AttributeReleasePolicy.php#L87-L101
train
OpenConext-Attic/OpenConext-engineblock-metadata
src/AttributeReleasePolicy.php
AttributeReleasePolicy.getSource
public function getSource($attributeName) { if ($this->hasAttribute($attributeName) && isset($this->attributeRules[$attributeName][0]['source'])) { return $this->attributeRules[$attributeName][0]['source']; } return 'idp'; }
php
public function getSource($attributeName) { if ($this->hasAttribute($attributeName) && isset($this->attributeRules[$attributeName][0]['source'])) { return $this->attributeRules[$attributeName][0]['source']; } return 'idp'; }
[ "public", "function", "getSource", "(", "$", "attributeName", ")", "{", "if", "(", "$", "this", "->", "hasAttribute", "(", "$", "attributeName", ")", "&&", "isset", "(", "$", "this", "->", "attributeRules", "[", "$", "attributeName", "]", "[", "0", "]", "[", "'source'", "]", ")", ")", "{", "return", "$", "this", "->", "attributeRules", "[", "$", "attributeName", "]", "[", "0", "]", "[", "'source'", "]", ";", "}", "return", "'idp'", ";", "}" ]
Loads the first source it finds in the list of attribute rules for the given attributeName. @param $attributeName @return string
[ "Loads", "the", "first", "source", "it", "finds", "in", "the", "list", "of", "attribute", "rules", "for", "the", "given", "attributeName", "." ]
236e2f52ef9cf28e71404544a1c4388f63ee535d
https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/AttributeReleasePolicy.php#L182-L188
train
phpffcms/ffcms-core
src/Managers/EventManager.php
EventManager.on
public function on($event, \Closure $callback): void { // check if event is a single string and parse it to array single item if (!Any::isArray($event)) { $event = [$event]; } foreach ($event as $item) { $this->events[$item][] = $callback; } }
php
public function on($event, \Closure $callback): void { // check if event is a single string and parse it to array single item if (!Any::isArray($event)) { $event = [$event]; } foreach ($event as $item) { $this->events[$item][] = $callback; } }
[ "public", "function", "on", "(", "$", "event", ",", "\\", "Closure", "$", "callback", ")", ":", "void", "{", "// check if event is a single string and parse it to array single item", "if", "(", "!", "Any", "::", "isArray", "(", "$", "event", ")", ")", "{", "$", "event", "=", "[", "$", "event", "]", ";", "}", "foreach", "(", "$", "event", "as", "$", "item", ")", "{", "$", "this", "->", "events", "[", "$", "item", "]", "[", "]", "=", "$", "callback", ";", "}", "}" ]
Catch the event if it occurred after this initiation of interception @param string|array $event @param \Closure $callback
[ "Catch", "the", "event", "if", "it", "occurred", "after", "this", "initiation", "of", "interception" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Managers/EventManager.php#L34-L44
train
phpffcms/ffcms-core
src/Managers/EventManager.php
EventManager.listen
public function listen($event, \Closure $callback): void { // check if $event is a single string and set it as array with one item if (!Any::isArray($event)) { $event = [$event]; } // each every one event in array foreach ($event as $item) { if (Any::isArray($this->runned) && array_key_exists($item, $this->runned)) { call_user_func_array($callback, $this->runned[$item]); } } }
php
public function listen($event, \Closure $callback): void { // check if $event is a single string and set it as array with one item if (!Any::isArray($event)) { $event = [$event]; } // each every one event in array foreach ($event as $item) { if (Any::isArray($this->runned) && array_key_exists($item, $this->runned)) { call_user_func_array($callback, $this->runned[$item]); } } }
[ "public", "function", "listen", "(", "$", "event", ",", "\\", "Closure", "$", "callback", ")", ":", "void", "{", "// check if $event is a single string and set it as array with one item", "if", "(", "!", "Any", "::", "isArray", "(", "$", "event", ")", ")", "{", "$", "event", "=", "[", "$", "event", "]", ";", "}", "// each every one event in array", "foreach", "(", "$", "event", "as", "$", "item", ")", "{", "if", "(", "Any", "::", "isArray", "(", "$", "this", "->", "runned", ")", "&&", "array_key_exists", "(", "$", "item", ",", "$", "this", "->", "runned", ")", ")", "{", "call_user_func_array", "(", "$", "callback", ",", "$", "this", "->", "runned", "[", "$", "item", "]", ")", ";", "}", "}", "}" ]
Catch the event if it occurred before the initiation of interception @param string|array $event @param \Closure $callback @return void
[ "Catch", "the", "event", "if", "it", "occurred", "before", "the", "initiation", "of", "interception" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Managers/EventManager.php#L52-L65
train
phpffcms/ffcms-core
src/Managers/EventManager.php
EventManager.run
public function run(): void { // dynamicly parse input params $args = func_get_args(); if (count($args) < 1) { return; } // get event name $eventName = array_shift($args); // get event args as array if passed $eventArgs = @array_shift($args); // if event is registered if (isset($this->events[$eventName]) && Any::isArray($this->events[$eventName])) { foreach ($this->events[$eventName] as $callback) { // call anonymous function with args if passed call_user_func_array($callback, $eventArgs); } } // set to post runned actions $this->runned[$eventName] = $eventArgs; }
php
public function run(): void { // dynamicly parse input params $args = func_get_args(); if (count($args) < 1) { return; } // get event name $eventName = array_shift($args); // get event args as array if passed $eventArgs = @array_shift($args); // if event is registered if (isset($this->events[$eventName]) && Any::isArray($this->events[$eventName])) { foreach ($this->events[$eventName] as $callback) { // call anonymous function with args if passed call_user_func_array($callback, $eventArgs); } } // set to post runned actions $this->runned[$eventName] = $eventArgs; }
[ "public", "function", "run", "(", ")", ":", "void", "{", "// dynamicly parse input params", "$", "args", "=", "func_get_args", "(", ")", ";", "if", "(", "count", "(", "$", "args", ")", "<", "1", ")", "{", "return", ";", "}", "// get event name", "$", "eventName", "=", "array_shift", "(", "$", "args", ")", ";", "// get event args as array if passed", "$", "eventArgs", "=", "@", "array_shift", "(", "$", "args", ")", ";", "// if event is registered", "if", "(", "isset", "(", "$", "this", "->", "events", "[", "$", "eventName", "]", ")", "&&", "Any", "::", "isArray", "(", "$", "this", "->", "events", "[", "$", "eventName", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "events", "[", "$", "eventName", "]", "as", "$", "callback", ")", "{", "// call anonymous function with args if passed", "call_user_func_array", "(", "$", "callback", ",", "$", "eventArgs", ")", ";", "}", "}", "// set to post runned actions", "$", "this", "->", "runned", "[", "$", "eventName", "]", "=", "$", "eventArgs", ";", "}" ]
Process event on happens @return void
[ "Process", "event", "on", "happens" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Managers/EventManager.php#L71-L95
train
miguelibero/meinhof
src/Meinhof/DependencyInjection/Compiler/EventListenerPass.php
EventListenerPass.getMethodFromAttributes
protected function getMethodFromAttributes($attrs) { if (!is_array($attrs) || !isset($attrs['method'])) { return $this->getEventFromAttributes($attrs); } return $attrs['method']; }
php
protected function getMethodFromAttributes($attrs) { if (!is_array($attrs) || !isset($attrs['method'])) { return $this->getEventFromAttributes($attrs); } return $attrs['method']; }
[ "protected", "function", "getMethodFromAttributes", "(", "$", "attrs", ")", "{", "if", "(", "!", "is_array", "(", "$", "attrs", ")", "||", "!", "isset", "(", "$", "attrs", "[", "'method'", "]", ")", ")", "{", "return", "$", "this", "->", "getEventFromAttributes", "(", "$", "attrs", ")", ";", "}", "return", "$", "attrs", "[", "'method'", "]", ";", "}" ]
Returns the event method from the tag attributes. @param mixed $attrs tag attributes @return string event method
[ "Returns", "the", "event", "method", "from", "the", "tag", "attributes", "." ]
3a090f08485dc0da3e27463cf349dba374201072
https://github.com/miguelibero/meinhof/blob/3a090f08485dc0da3e27463cf349dba374201072/src/Meinhof/DependencyInjection/Compiler/EventListenerPass.php#L56-L63
train
miguelibero/meinhof
src/Meinhof/DependencyInjection/Compiler/EventListenerPass.php
EventListenerPass.getPriorityFromAttributes
protected function getPriorityFromAttributes($attrs) { if (!is_array($attrs) || !isset($attrs['priority'])) { return 0; } $p = intval($attrs['priority']); return $p < 0 ? 0 : $p; }
php
protected function getPriorityFromAttributes($attrs) { if (!is_array($attrs) || !isset($attrs['priority'])) { return 0; } $p = intval($attrs['priority']); return $p < 0 ? 0 : $p; }
[ "protected", "function", "getPriorityFromAttributes", "(", "$", "attrs", ")", "{", "if", "(", "!", "is_array", "(", "$", "attrs", ")", "||", "!", "isset", "(", "$", "attrs", "[", "'priority'", "]", ")", ")", "{", "return", "0", ";", "}", "$", "p", "=", "intval", "(", "$", "attrs", "[", "'priority'", "]", ")", ";", "return", "$", "p", "<", "0", "?", "0", ":", "$", "p", ";", "}" ]
Returns the event priority from the tag attributes. If no priority specified returns priority 0. @param mixed $attrs tag attributes @return string event priotity
[ "Returns", "the", "event", "priority", "from", "the", "tag", "attributes", ".", "If", "no", "priority", "specified", "returns", "priority", "0", "." ]
3a090f08485dc0da3e27463cf349dba374201072
https://github.com/miguelibero/meinhof/blob/3a090f08485dc0da3e27463cf349dba374201072/src/Meinhof/DependencyInjection/Compiler/EventListenerPass.php#L73-L81
train
alexlcdee/colorcli
src/Logger.php
Logger.checkLevel
public function checkLevel($level) { if (static::$levels === null) { // Psr\Log does not provide Enum, so we need to load levels from LogLevel constants $reflection = new \ReflectionClass(LogLevel::class); static::$levels = $reflection->getConstants(); } if (!in_array($level, static::$levels)) { $levels = implode(', ', static::$levels); throw new InvalidArgumentException("Level must be one of [$levels]."); } }
php
public function checkLevel($level) { if (static::$levels === null) { // Psr\Log does not provide Enum, so we need to load levels from LogLevel constants $reflection = new \ReflectionClass(LogLevel::class); static::$levels = $reflection->getConstants(); } if (!in_array($level, static::$levels)) { $levels = implode(', ', static::$levels); throw new InvalidArgumentException("Level must be one of [$levels]."); } }
[ "public", "function", "checkLevel", "(", "$", "level", ")", "{", "if", "(", "static", "::", "$", "levels", "===", "null", ")", "{", "// Psr\\Log does not provide Enum, so we need to load levels from LogLevel constants", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "LogLevel", "::", "class", ")", ";", "static", "::", "$", "levels", "=", "$", "reflection", "->", "getConstants", "(", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "level", ",", "static", "::", "$", "levels", ")", ")", "{", "$", "levels", "=", "implode", "(", "', '", ",", "static", "::", "$", "levels", ")", ";", "throw", "new", "InvalidArgumentException", "(", "\"Level must be one of [$levels].\"", ")", ";", "}", "}" ]
Check if level exists in list of possible levels Psr\Log suggests to throw Psr\Log\InvalidArgumentException if incompatible log level passed @param mixed $level @throws InvalidArgumentException
[ "Check", "if", "level", "exists", "in", "list", "of", "possible", "levels", "Psr", "\\", "Log", "suggests", "to", "throw", "Psr", "\\", "Log", "\\", "InvalidArgumentException", "if", "incompatible", "log", "level", "passed" ]
2107917987f6c300ac5ce4a26102c9bf8e6b3d95
https://github.com/alexlcdee/colorcli/blob/2107917987f6c300ac5ce4a26102c9bf8e6b3d95/src/Logger.php#L61-L73
train
alexlcdee/colorcli
src/Logger.php
Logger.resetFGColors
public function resetFGColors() { static::$foregroundColorMap = [ LogLevel::EMERGENCY => ForegroundColors::YELLOW(), LogLevel::ALERT => ForegroundColors::WHITE(), LogLevel::CRITICAL => ForegroundColors::RED(), LogLevel::ERROR => ForegroundColors::LIGHT_RED(), LogLevel::WARNING => ForegroundColors::YELLOW(), LogLevel::NOTICE => ForegroundColors::LIGHT_BLUE(), LogLevel::INFO => ForegroundColors::LIGHT_GREEN(), LogLevel::DEBUG => null ]; }
php
public function resetFGColors() { static::$foregroundColorMap = [ LogLevel::EMERGENCY => ForegroundColors::YELLOW(), LogLevel::ALERT => ForegroundColors::WHITE(), LogLevel::CRITICAL => ForegroundColors::RED(), LogLevel::ERROR => ForegroundColors::LIGHT_RED(), LogLevel::WARNING => ForegroundColors::YELLOW(), LogLevel::NOTICE => ForegroundColors::LIGHT_BLUE(), LogLevel::INFO => ForegroundColors::LIGHT_GREEN(), LogLevel::DEBUG => null ]; }
[ "public", "function", "resetFGColors", "(", ")", "{", "static", "::", "$", "foregroundColorMap", "=", "[", "LogLevel", "::", "EMERGENCY", "=>", "ForegroundColors", "::", "YELLOW", "(", ")", ",", "LogLevel", "::", "ALERT", "=>", "ForegroundColors", "::", "WHITE", "(", ")", ",", "LogLevel", "::", "CRITICAL", "=>", "ForegroundColors", "::", "RED", "(", ")", ",", "LogLevel", "::", "ERROR", "=>", "ForegroundColors", "::", "LIGHT_RED", "(", ")", ",", "LogLevel", "::", "WARNING", "=>", "ForegroundColors", "::", "YELLOW", "(", ")", ",", "LogLevel", "::", "NOTICE", "=>", "ForegroundColors", "::", "LIGHT_BLUE", "(", ")", ",", "LogLevel", "::", "INFO", "=>", "ForegroundColors", "::", "LIGHT_GREEN", "(", ")", ",", "LogLevel", "::", "DEBUG", "=>", "null", "]", ";", "}" ]
Set foreground colors map to default ones
[ "Set", "foreground", "colors", "map", "to", "default", "ones" ]
2107917987f6c300ac5ce4a26102c9bf8e6b3d95
https://github.com/alexlcdee/colorcli/blob/2107917987f6c300ac5ce4a26102c9bf8e6b3d95/src/Logger.php#L91-L103
train