repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
FuzeWorks/Core
src/FuzeWorks/Models.php
Models.loadModel
protected function loadModel($modelName, $directories): ModelAbstract { if (empty($directories)) { throw new ModelException("Could not load model. No directories provided", 1); } // Now figure out the className and subdir $class = trim($modelName, '/'); if (($last_slash = strrpos($class, '/')) !== FALSE) { // Extract the path $subdir = substr($class, 0, ++$last_slash); // Get the filename from the path $class = substr($class, $last_slash); } else { $subdir = ''; } $class = ucfirst($class); // Search for the model file foreach ($directories as $directory) { // Determine the file $file = $directory . DS . $subdir . "model." . strtolower($class) . '.php'; $className = '\Application\Model\\'.$class; // If the class already exists, return a new instance directly if (class_exists($className, false)) { return new $className(); } // If it doesn't, try and load the file if (file_exists($file)) { include_once($file); return new $className(); } } // Maybe it's in a subdirectory with the same name as the class if ($subdir === '') { return $this->loadModel($class."/".$class, $directories); } throw new ModelException("Could not load model. Model was not found", 1); }
php
protected function loadModel($modelName, $directories): ModelAbstract { if (empty($directories)) { throw new ModelException("Could not load model. No directories provided", 1); } // Now figure out the className and subdir $class = trim($modelName, '/'); if (($last_slash = strrpos($class, '/')) !== FALSE) { // Extract the path $subdir = substr($class, 0, ++$last_slash); // Get the filename from the path $class = substr($class, $last_slash); } else { $subdir = ''; } $class = ucfirst($class); // Search for the model file foreach ($directories as $directory) { // Determine the file $file = $directory . DS . $subdir . "model." . strtolower($class) . '.php'; $className = '\Application\Model\\'.$class; // If the class already exists, return a new instance directly if (class_exists($className, false)) { return new $className(); } // If it doesn't, try and load the file if (file_exists($file)) { include_once($file); return new $className(); } } // Maybe it's in a subdirectory with the same name as the class if ($subdir === '') { return $this->loadModel($class."/".$class, $directories); } throw new ModelException("Could not load model. Model was not found", 1); }
[ "protected", "function", "loadModel", "(", "$", "modelName", ",", "$", "directories", ")", ":", "ModelAbstract", "{", "if", "(", "empty", "(", "$", "directories", ")", ")", "{", "throw", "new", "ModelException", "(", "\"Could not load model. No directories provided\"", ",", "1", ")", ";", "}", "// Now figure out the className and subdir", "$", "class", "=", "trim", "(", "$", "modelName", ",", "'/'", ")", ";", "if", "(", "(", "$", "last_slash", "=", "strrpos", "(", "$", "class", ",", "'/'", ")", ")", "!==", "FALSE", ")", "{", "// Extract the path", "$", "subdir", "=", "substr", "(", "$", "class", ",", "0", ",", "++", "$", "last_slash", ")", ";", "// Get the filename from the path", "$", "class", "=", "substr", "(", "$", "class", ",", "$", "last_slash", ")", ";", "}", "else", "{", "$", "subdir", "=", "''", ";", "}", "$", "class", "=", "ucfirst", "(", "$", "class", ")", ";", "// Search for the model file", "foreach", "(", "$", "directories", "as", "$", "directory", ")", "{", "// Determine the file", "$", "file", "=", "$", "directory", ".", "DS", ".", "$", "subdir", ".", "\"model.\"", ".", "strtolower", "(", "$", "class", ")", ".", "'.php'", ";", "$", "className", "=", "'\\Application\\Model\\\\'", ".", "$", "class", ";", "// If the class already exists, return a new instance directly", "if", "(", "class_exists", "(", "$", "className", ",", "false", ")", ")", "{", "return", "new", "$", "className", "(", ")", ";", "}", "// If it doesn't, try and load the file", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "include_once", "(", "$", "file", ")", ";", "return", "new", "$", "className", "(", ")", ";", "}", "}", "// Maybe it's in a subdirectory with the same name as the class", "if", "(", "$", "subdir", "===", "''", ")", "{", "return", "$", "this", "->", "loadModel", "(", "$", "class", ".", "\"/\"", ".", "$", "class", ",", "$", "directories", ")", ";", "}", "throw", "new", "ModelException", "(", "\"Could not load model. Model was not found\"", ",", "1", ")", ";", "}" ]
Load and return a model. Supply the name and the model will be loaded from one of the supplied directories @param string $modelName Name of the model @param array $directories Directories to try and load the model from @return ModelAbstract The Model object
[ "Load", "and", "return", "a", "model", "." ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Models.php#L109-L161
train
FuzeWorks/Core
src/FuzeWorks/Models.php
Models.removeModelPath
public function removeModelPath($directory) { if (($key = array_search($directory, $this->modelPaths)) !== false) { unset($this->modelPaths[$key]); } }
php
public function removeModelPath($directory) { if (($key = array_search($directory, $this->modelPaths)) !== false) { unset($this->modelPaths[$key]); } }
[ "public", "function", "removeModelPath", "(", "$", "directory", ")", "{", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "directory", ",", "$", "this", "->", "modelPaths", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "modelPaths", "[", "$", "key", "]", ")", ";", "}", "}" ]
Remove a path where models can be found @param string $directory The directory @return void
[ "Remove", "a", "path", "where", "models", "can", "be", "found" ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Models.php#L183-L189
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.setDefaultEncoding
public static function setDefaultEncoding($encoding=null) { if(!is_null($encoding) && is_string($encoding) && !empty($encoding)) { self::$defaultencoding = $encoding; } else { self::$defaultencoding = null; } }
php
public static function setDefaultEncoding($encoding=null) { if(!is_null($encoding) && is_string($encoding) && !empty($encoding)) { self::$defaultencoding = $encoding; } else { self::$defaultencoding = null; } }
[ "public", "static", "function", "setDefaultEncoding", "(", "$", "encoding", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "encoding", ")", "&&", "is_string", "(", "$", "encoding", ")", "&&", "!", "empty", "(", "$", "encoding", ")", ")", "{", "self", "::", "$", "defaultencoding", "=", "$", "encoding", ";", "}", "else", "{", "self", "::", "$", "defaultencoding", "=", "null", ";", "}", "}" ]
Set global default encoding @param string $encoding
[ "Set", "global", "default", "encoding" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L17-L27
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.newInstance
public function newInstance($value = null) { $class = $this->getClassName(); $o = new $class($value, $this->encoding); return $o; }
php
public function newInstance($value = null) { $class = $this->getClassName(); $o = new $class($value, $this->encoding); return $o; }
[ "public", "function", "newInstance", "(", "$", "value", "=", "null", ")", "{", "$", "class", "=", "$", "this", "->", "getClassName", "(", ")", ";", "$", "o", "=", "new", "$", "class", "(", "$", "value", ",", "$", "this", "->", "encoding", ")", ";", "return", "$", "o", ";", "}" ]
Creates new instance of current class type @return \PerrysLambda\StringProperty
[ "Creates", "new", "instance", "of", "current", "class", "type" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L57-L62
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.getEncoding
protected function getEncoding($encoding=null) { if(is_null($encoding)) { if(!is_null($this->encoding)) { return $this->encoding; } return self::getDefaultEncoding(); } return $encoding; }
php
protected function getEncoding($encoding=null) { if(is_null($encoding)) { if(!is_null($this->encoding)) { return $this->encoding; } return self::getDefaultEncoding(); } return $encoding; }
[ "protected", "function", "getEncoding", "(", "$", "encoding", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "encoding", ")", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "encoding", ")", ")", "{", "return", "$", "this", "->", "encoding", ";", "}", "return", "self", "::", "getDefaultEncoding", "(", ")", ";", "}", "return", "$", "encoding", ";", "}" ]
Helper function to set default encoding @param string $encoding @return string
[ "Helper", "function", "to", "set", "default", "encoding" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L97-L108
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.substr
public function substr($start, $length=null) { return $this->newInstance(mb_substr($this->toString(), $start, $length, $this->getEncoding())); }
php
public function substr($start, $length=null) { return $this->newInstance(mb_substr($this->toString(), $start, $length, $this->getEncoding())); }
[ "public", "function", "substr", "(", "$", "start", ",", "$", "length", "=", "null", ")", "{", "return", "$", "this", "->", "newInstance", "(", "mb_substr", "(", "$", "this", "->", "toString", "(", ")", ",", "$", "start", ",", "$", "length", ",", "$", "this", "->", "getEncoding", "(", ")", ")", ")", ";", "}" ]
Return a substring of value @param int $start @param int $length @return \PerrysLambda\StringProperty
[ "Return", "a", "substring", "of", "value" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L221-L224
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.split
public function split($separator) { $temp = explode($separator, $this->toString()); $list = ArrayList::asType($this->getClassName(), $temp); return $list; }
php
public function split($separator) { $temp = explode($separator, $this->toString()); $list = ArrayList::asType($this->getClassName(), $temp); return $list; }
[ "public", "function", "split", "(", "$", "separator", ")", "{", "$", "temp", "=", "explode", "(", "$", "separator", ",", "$", "this", "->", "toString", "(", ")", ")", ";", "$", "list", "=", "ArrayList", "::", "asType", "(", "$", "this", "->", "getClassName", "(", ")", ",", "$", "temp", ")", ";", "return", "$", "list", ";", "}" ]
Split string by separator @param string $separator @return \PerrysLambda\ArrayList
[ "Split", "string", "by", "separator" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L231-L236
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.padDynamic
protected function padDynamic($padstr, $length, $type) { return $this->newInstance(str_pad($this->toString(), $length, $padstr, $type)); }
php
protected function padDynamic($padstr, $length, $type) { return $this->newInstance(str_pad($this->toString(), $length, $padstr, $type)); }
[ "protected", "function", "padDynamic", "(", "$", "padstr", ",", "$", "length", ",", "$", "type", ")", "{", "return", "$", "this", "->", "newInstance", "(", "str_pad", "(", "$", "this", "->", "toString", "(", ")", ",", "$", "length", ",", "$", "padstr", ",", "$", "type", ")", ")", ";", "}" ]
Helper function for string padding @param string $padstr @param int $length @param int $type @return \PerrysLambda\StringProperty
[ "Helper", "function", "for", "string", "padding" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L245-L248
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.indexOfDyamic
protected function indexOfDyamic($function, $needle, $offset) { $r = $function($this->toString(), $needle, $offset, $this->getEncoding()); return ($r===false ? -1 : $r); }
php
protected function indexOfDyamic($function, $needle, $offset) { $r = $function($this->toString(), $needle, $offset, $this->getEncoding()); return ($r===false ? -1 : $r); }
[ "protected", "function", "indexOfDyamic", "(", "$", "function", ",", "$", "needle", ",", "$", "offset", ")", "{", "$", "r", "=", "$", "function", "(", "$", "this", "->", "toString", "(", ")", ",", "$", "needle", ",", "$", "offset", ",", "$", "this", "->", "getEncoding", "(", ")", ")", ";", "return", "(", "$", "r", "===", "false", "?", "-", "1", ":", "$", "r", ")", ";", "}" ]
Helper function for strpos @param string $function @param string $needle @param int $offset @return int
[ "Helper", "function", "for", "strpos" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L290-L294
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.lastIndexOfDynamic
protected function lastIndexOfDynamic($function, $needle, $offset=0) { $r = $function($this->toString(), $needle, $offset, $this->getEncoding()); return ($r===false ? -1 : $r); }
php
protected function lastIndexOfDynamic($function, $needle, $offset=0) { $r = $function($this->toString(), $needle, $offset, $this->getEncoding()); return ($r===false ? -1 : $r); }
[ "protected", "function", "lastIndexOfDynamic", "(", "$", "function", ",", "$", "needle", ",", "$", "offset", "=", "0", ")", "{", "$", "r", "=", "$", "function", "(", "$", "this", "->", "toString", "(", ")", ",", "$", "needle", ",", "$", "offset", ",", "$", "this", "->", "getEncoding", "(", ")", ")", ";", "return", "(", "$", "r", "===", "false", "?", "-", "1", ":", "$", "r", ")", ";", "}" ]
Helper function for strrpos @param string $function @param string $needle @param int $offset @return int
[ "Helper", "function", "for", "strrpos" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L327-L331
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.endsWithDynamic
protected function endsWithDynamic($function, $needle) { $enc = $this->getEncoding(); $strlen = $this->length($enc); $testlen = mb_strlen($needle, $enc); if ($testlen <= $strlen) { return ($function($this->toString(), $needle, ($strlen-$testlen), $enc)!==false); } return false; }
php
protected function endsWithDynamic($function, $needle) { $enc = $this->getEncoding(); $strlen = $this->length($enc); $testlen = mb_strlen($needle, $enc); if ($testlen <= $strlen) { return ($function($this->toString(), $needle, ($strlen-$testlen), $enc)!==false); } return false; }
[ "protected", "function", "endsWithDynamic", "(", "$", "function", ",", "$", "needle", ")", "{", "$", "enc", "=", "$", "this", "->", "getEncoding", "(", ")", ";", "$", "strlen", "=", "$", "this", "->", "length", "(", "$", "enc", ")", ";", "$", "testlen", "=", "mb_strlen", "(", "$", "needle", ",", "$", "enc", ")", ";", "if", "(", "$", "testlen", "<=", "$", "strlen", ")", "{", "return", "(", "$", "function", "(", "$", "this", "->", "toString", "(", ")", ",", "$", "needle", ",", "(", "$", "strlen", "-", "$", "testlen", ")", ",", "$", "enc", ")", "!==", "false", ")", ";", "}", "return", "false", ";", "}" ]
Helper function for endsWith @param string $function @param string $needle @return boolean
[ "Helper", "function", "for", "endsWith" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L403-L414
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.match
public function match($regex) { $match = array(); if($this->isValidRegex($regex) && preg_match($regex, $this->toString(), $match)===1) { return new ObjectArray($match); } return null; }
php
public function match($regex) { $match = array(); if($this->isValidRegex($regex) && preg_match($regex, $this->toString(), $match)===1) { return new ObjectArray($match); } return null; }
[ "public", "function", "match", "(", "$", "regex", ")", "{", "$", "match", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "isValidRegex", "(", "$", "regex", ")", "&&", "preg_match", "(", "$", "regex", ",", "$", "this", "->", "toString", "(", ")", ",", "$", "match", ")", "===", "1", ")", "{", "return", "new", "ObjectArray", "(", "$", "match", ")", ";", "}", "return", "null", ";", "}" ]
Match value against regex @param string $regex @return \PerrysLambda\ObjectArray
[ "Match", "value", "against", "regex" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L461-L469
train
perryflynn/PerrysLambda
src/PerrysLambda/StringProperty.php
StringProperty.matchAll
public function matchAll($regex) { $matches = array(); $result = preg_match_all($regex, $this->toString(), $matches, PREG_SET_ORDER); if($this->isValidRegex($regex) && $result!==false && $result>0) { return ArrayList::asObjectArray($matches); } return null; }
php
public function matchAll($regex) { $matches = array(); $result = preg_match_all($regex, $this->toString(), $matches, PREG_SET_ORDER); if($this->isValidRegex($regex) && $result!==false && $result>0) { return ArrayList::asObjectArray($matches); } return null; }
[ "public", "function", "matchAll", "(", "$", "regex", ")", "{", "$", "matches", "=", "array", "(", ")", ";", "$", "result", "=", "preg_match_all", "(", "$", "regex", ",", "$", "this", "->", "toString", "(", ")", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ";", "if", "(", "$", "this", "->", "isValidRegex", "(", "$", "regex", ")", "&&", "$", "result", "!==", "false", "&&", "$", "result", ">", "0", ")", "{", "return", "ArrayList", "::", "asObjectArray", "(", "$", "matches", ")", ";", "}", "return", "null", ";", "}" ]
Get all matches by regex @param string $regex @return \PerrysLambda\ArrayList
[ "Get", "all", "matches", "by", "regex" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/StringProperty.php#L476-L485
train
lasallecms/lasallecms-l5-installedpackages-pkg
src/CreateInstalledPackagesArray.php
CreateInstalledPackagesArray.CreateArray
public function CreateArray() { $allPackages = $this->allLaSalleSoftwarePackages(); $installedPackages = []; foreach ($allPackages as $class) { if ( defined("\\".$class."\\Version::VERSION") ) { $installedPackages[] = [ 'class' => $class, 'version' => constant("\\".$class."\\Version::VERSION"), 'description' => constant("\\".$class."\\Version::PACKAGE"), ]; } } return $installedPackages; }
php
public function CreateArray() { $allPackages = $this->allLaSalleSoftwarePackages(); $installedPackages = []; foreach ($allPackages as $class) { if ( defined("\\".$class."\\Version::VERSION") ) { $installedPackages[] = [ 'class' => $class, 'version' => constant("\\".$class."\\Version::VERSION"), 'description' => constant("\\".$class."\\Version::PACKAGE"), ]; } } return $installedPackages; }
[ "public", "function", "CreateArray", "(", ")", "{", "$", "allPackages", "=", "$", "this", "->", "allLaSalleSoftwarePackages", "(", ")", ";", "$", "installedPackages", "=", "[", "]", ";", "foreach", "(", "$", "allPackages", "as", "$", "class", ")", "{", "if", "(", "defined", "(", "\"\\\\\"", ".", "$", "class", ".", "\"\\\\Version::VERSION\"", ")", ")", "{", "$", "installedPackages", "[", "]", "=", "[", "'class'", "=>", "$", "class", ",", "'version'", "=>", "constant", "(", "\"\\\\\"", ".", "$", "class", ".", "\"\\\\Version::VERSION\"", ")", ",", "'description'", "=>", "constant", "(", "\"\\\\\"", ".", "$", "class", ".", "\"\\\\Version::PACKAGE\"", ")", ",", "]", ";", "}", "}", "return", "$", "installedPackages", ";", "}" ]
What LaSalle Software packages are installed? @return array
[ "What", "LaSalle", "Software", "packages", "are", "installed?" ]
165fb63ab424fd716aaa43057ee6efc6d8929755
https://github.com/lasallecms/lasallecms-l5-installedpackages-pkg/blob/165fb63ab424fd716aaa43057ee6efc6d8929755/src/CreateInstalledPackagesArray.php#L45-L64
train
itcreator/custom-cmf
Module/View/src/Cmf/View/Helper/Style.php
Style.addStyle
public function addStyle($href, $path = null) { $key = $this->calculateKey($href, $path); $this->styles[$key] = 1; return $this; }
php
public function addStyle($href, $path = null) { $key = $this->calculateKey($href, $path); $this->styles[$key] = 1; return $this; }
[ "public", "function", "addStyle", "(", "$", "href", ",", "$", "path", "=", "null", ")", "{", "$", "key", "=", "$", "this", "->", "calculateKey", "(", "$", "href", ",", "$", "path", ")", ";", "$", "this", "->", "styles", "[", "$", "key", "]", "=", "1", ";", "return", "$", "this", ";", "}" ]
this method add css file @param string $href @param string $path @return Style
[ "this", "method", "add", "css", "file" ]
42fc0535dfa0f641856f06673f6ab596b2020c40
https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/View/src/Cmf/View/Helper/Style.php#L35-L41
train
itcreator/custom-cmf
Module/View/src/Cmf/View/Helper/Style.php
Style.deleteStyle
public function deleteStyle($href, $path = null) { $key = $this->calculateKey($href, $path); if (isset($this->styles[$key])) { unset($this->styles[$key]); } return $this; }
php
public function deleteStyle($href, $path = null) { $key = $this->calculateKey($href, $path); if (isset($this->styles[$key])) { unset($this->styles[$key]); } return $this; }
[ "public", "function", "deleteStyle", "(", "$", "href", ",", "$", "path", "=", "null", ")", "{", "$", "key", "=", "$", "this", "->", "calculateKey", "(", "$", "href", ",", "$", "path", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "styles", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "styles", "[", "$", "key", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
This method remove css file from list @param string $href @param string $path @return Style
[ "This", "method", "remove", "css", "file", "from", "list" ]
42fc0535dfa0f641856f06673f6ab596b2020c40
https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/View/src/Cmf/View/Helper/Style.php#L50-L58
train
itcreator/custom-cmf
Module/View/src/Cmf/View/Helper/Style.php
Style.buildCode
public function buildCode() { $res = ''; foreach ($this->styles as $href => $val) { $res .= '<link href="' . $href . '" rel="stylesheet" type="text/css" />' . "\r\n"; } return $res; }
php
public function buildCode() { $res = ''; foreach ($this->styles as $href => $val) { $res .= '<link href="' . $href . '" rel="stylesheet" type="text/css" />' . "\r\n"; } return $res; }
[ "public", "function", "buildCode", "(", ")", "{", "$", "res", "=", "''", ";", "foreach", "(", "$", "this", "->", "styles", "as", "$", "href", "=>", "$", "val", ")", "{", "$", "res", ".=", "'<link href=\"'", ".", "$", "href", ".", "'\" rel=\"stylesheet\" type=\"text/css\" />'", ".", "\"\\r\\n\"", ";", "}", "return", "$", "res", ";", "}" ]
This method generate code for include css files @return string
[ "This", "method", "generate", "code", "for", "include", "css", "files" ]
42fc0535dfa0f641856f06673f6ab596b2020c40
https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/View/src/Cmf/View/Helper/Style.php#L77-L85
train
bseddon/XPath20
Value/QNameValue.php
QNameValue.fromQName
public static function fromQName( $qn ) { $qname = new QNameValue(); $qname->LocalName = $qn->localName; $qname->Prefix = $qn->prefix; $qname->NamespaceUri = $qn->namespaceURI; if ( strlen( $qn->localName ) == 0 || ! preg_match( "/^" . NameValue::$ncName . "$/u", $qn->localName ) || ( strlen( $qn->prefix ) != 0 && ! preg_match( "/^" . NameValue::$ncName . "$/u", $qn->prefix ) ) ) { throw XPath2Exception::withErrorCodeAndParam( "FOCA0002", Resources::FOCA0002, $qn->__toString() ); } return $qname; }
php
public static function fromQName( $qn ) { $qname = new QNameValue(); $qname->LocalName = $qn->localName; $qname->Prefix = $qn->prefix; $qname->NamespaceUri = $qn->namespaceURI; if ( strlen( $qn->localName ) == 0 || ! preg_match( "/^" . NameValue::$ncName . "$/u", $qn->localName ) || ( strlen( $qn->prefix ) != 0 && ! preg_match( "/^" . NameValue::$ncName . "$/u", $qn->prefix ) ) ) { throw XPath2Exception::withErrorCodeAndParam( "FOCA0002", Resources::FOCA0002, $qn->__toString() ); } return $qname; }
[ "public", "static", "function", "fromQName", "(", "$", "qn", ")", "{", "$", "qname", "=", "new", "QNameValue", "(", ")", ";", "$", "qname", "->", "LocalName", "=", "$", "qn", "->", "localName", ";", "$", "qname", "->", "Prefix", "=", "$", "qn", "->", "prefix", ";", "$", "qname", "->", "NamespaceUri", "=", "$", "qn", "->", "namespaceURI", ";", "if", "(", "strlen", "(", "$", "qn", "->", "localName", ")", "==", "0", "||", "!", "preg_match", "(", "\"/^\"", ".", "NameValue", "::", "$", "ncName", ".", "\"$/u\"", ",", "$", "qn", "->", "localName", ")", "||", "(", "strlen", "(", "$", "qn", "->", "prefix", ")", "!=", "0", "&&", "!", "preg_match", "(", "\"/^\"", ".", "NameValue", "::", "$", "ncName", ".", "\"$/u\"", ",", "$", "qn", "->", "prefix", ")", ")", ")", "{", "throw", "XPath2Exception", "::", "withErrorCodeAndParam", "(", "\"FOCA0002\"", ",", "Resources", "::", "FOCA0002", ",", "$", "qn", "->", "__toString", "(", ")", ")", ";", "}", "return", "$", "qname", ";", "}" ]
Create a QNameValue from a QName @param QName $qn
[ "Create", "a", "QNameValue", "from", "a", "QName" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/QNameValue.php#L216-L232
train
bseddon/XPath20
Value/QNameValue.php
QNameValue.fromXPathNavigator
public static function fromXPathNavigator( $node ) { return QNameValue::fromQName( new \lyquidity\xml\qname( $node->getPrefix(), $node->getNamespaceURI(), $node->getLocalName() ) ); }
php
public static function fromXPathNavigator( $node ) { return QNameValue::fromQName( new \lyquidity\xml\qname( $node->getPrefix(), $node->getNamespaceURI(), $node->getLocalName() ) ); }
[ "public", "static", "function", "fromXPathNavigator", "(", "$", "node", ")", "{", "return", "QNameValue", "::", "fromQName", "(", "new", "\\", "lyquidity", "\\", "xml", "\\", "qname", "(", "$", "node", "->", "getPrefix", "(", ")", ",", "$", "node", "->", "getNamespaceURI", "(", ")", ",", "$", "node", "->", "getLocalName", "(", ")", ")", ")", ";", "}" ]
Create a QNameValue instance fron an XPathNavigator instance @param XPathNavigator $node @return QNameValue
[ "Create", "a", "QNameValue", "instance", "fron", "an", "XPathNavigator", "instance" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/QNameValue.php#L239-L242
train
pluf/discount
src/Discount/Engine.php
Discount_Engine.isValid
public function isValid($discount, $request) { $code = $this->validate($discount, $request); if ($code == Discount_Engine::VALIDATION_CODE_VALID) return true; return false; }
php
public function isValid($discount, $request) { $code = $this->validate($discount, $request); if ($code == Discount_Engine::VALIDATION_CODE_VALID) return true; return false; }
[ "public", "function", "isValid", "(", "$", "discount", ",", "$", "request", ")", "{", "$", "code", "=", "$", "this", "->", "validate", "(", "$", "discount", ",", "$", "request", ")", ";", "if", "(", "$", "code", "==", "Discount_Engine", "::", "VALIDATION_CODE_VALID", ")", "return", "true", ";", "return", "false", ";", "}" ]
Check if give discount is valid or not. @param Discount_Discount $discount @param Pluf_HTTP_Request $request
[ "Check", "if", "give", "discount", "is", "valid", "or", "not", "." ]
b0006d6b25dd61241f51b5b098d7d546b470de26
https://github.com/pluf/discount/blob/b0006d6b25dd61241f51b5b098d7d546b470de26/src/Discount/Engine.php#L109-L115
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.buildUrl
private function buildUrl($mode, $params = []) { $urlParams = array_merge(['mode' => $mode, 'apikey' => $this->apiKey, 'output' => 'json'], $params); return 'http://' . $this->url . ':' . $this->port . "/api?" . http_build_query($urlParams); }
php
private function buildUrl($mode, $params = []) { $urlParams = array_merge(['mode' => $mode, 'apikey' => $this->apiKey, 'output' => 'json'], $params); return 'http://' . $this->url . ':' . $this->port . "/api?" . http_build_query($urlParams); }
[ "private", "function", "buildUrl", "(", "$", "mode", ",", "$", "params", "=", "[", "]", ")", "{", "$", "urlParams", "=", "array_merge", "(", "[", "'mode'", "=>", "$", "mode", ",", "'apikey'", "=>", "$", "this", "->", "apiKey", ",", "'output'", "=>", "'json'", "]", ",", "$", "params", ")", ";", "return", "'http://'", ".", "$", "this", "->", "url", ".", "':'", ".", "$", "this", "->", "port", ".", "\"/api?\"", ".", "http_build_query", "(", "$", "urlParams", ")", ";", "}" ]
Url builder helper @param String $mode @param array $params @return string
[ "Url", "builder", "helper" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L52-L56
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.queue
public function queue($start = 0, $limit = 100) { $url = $this->buildUrl('queue', [ 'start' => $start, 'limit' => $limit ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['queue']; }
php
public function queue($start = 0, $limit = 100) { $url = $this->buildUrl('queue', [ 'start' => $start, 'limit' => $limit ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['queue']; }
[ "public", "function", "queue", "(", "$", "start", "=", "0", ",", "$", "limit", "=", "100", ")", "{", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'queue'", ",", "[", "'start'", "=>", "$", "start", ",", "'limit'", "=>", "$", "limit", "]", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", "[", "'queue'", "]", ";", "}" ]
Returns all items currently in the queue and some additional information @param int $start @param int $limit @return array
[ "Returns", "all", "items", "currently", "in", "the", "queue", "and", "some", "additional", "information" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L66-L75
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.history
public function history($category = '', $start = 0, $limit = 100, $failedOnly = false) { $url = $this->buildUrl('history', [ 'start' => $start, 'limit' => $limit, 'failed_only' => $failedOnly, 'category' => $category ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['history']; }
php
public function history($category = '', $start = 0, $limit = 100, $failedOnly = false) { $url = $this->buildUrl('history', [ 'start' => $start, 'limit' => $limit, 'failed_only' => $failedOnly, 'category' => $category ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['history']; }
[ "public", "function", "history", "(", "$", "category", "=", "''", ",", "$", "start", "=", "0", ",", "$", "limit", "=", "100", ",", "$", "failedOnly", "=", "false", ")", "{", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'history'", ",", "[", "'start'", "=>", "$", "start", ",", "'limit'", "=>", "$", "limit", ",", "'failed_only'", "=>", "$", "failedOnly", ",", "'category'", "=>", "$", "category", "]", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", "[", "'history'", "]", ";", "}" ]
Returns all items in the history and some additional information @param string $category @param int $start @param int $limit @param bool $failedOnly @return array
[ "Returns", "all", "items", "in", "the", "history", "and", "some", "additional", "information" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L87-L98
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.deleteQueueEntries
public function deleteQueueEntries($entries) { $url = $this->buildUrl('queue', [ 'name' => 'delete', 'value' => implode(',', $entries) ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
php
public function deleteQueueEntries($entries) { $url = $this->buildUrl('queue', [ 'name' => 'delete', 'value' => implode(',', $entries) ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
[ "public", "function", "deleteQueueEntries", "(", "$", "entries", ")", "{", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'queue'", ",", "[", "'name'", "=>", "'delete'", ",", "'value'", "=>", "implode", "(", "','", ",", "$", "entries", ")", "]", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", "[", "'status'", "]", ";", "}" ]
Deletes multiple entries with the given ids from the queue @param array $entries @return boolean
[ "Deletes", "multiple", "entries", "with", "the", "given", "ids", "from", "the", "queue" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L181-L190
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.switchQueueEntries
public function switchQueueEntries($first, $second) { $url = $this->buildUrl('switch', [ 'value' => $first, 'value2' => $second ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['result']; }
php
public function switchQueueEntries($first, $second) { $url = $this->buildUrl('switch', [ 'value' => $first, 'value2' => $second ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['result']; }
[ "public", "function", "switchQueueEntries", "(", "$", "first", ",", "$", "second", ")", "{", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'switch'", ",", "[", "'value'", "=>", "$", "first", ",", "'value2'", "=>", "$", "second", "]", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", "[", "'result'", "]", ";", "}" ]
Switches two entries in the queue @param string $first @param string $second @return boolean
[ "Switches", "two", "entries", "in", "the", "queue" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L216-L225
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.pauseQueue
public function pauseQueue() { $url = $this->buildUrl('set_pause'); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
php
public function pauseQueue() { $url = $this->buildUrl('set_pause'); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
[ "public", "function", "pauseQueue", "(", ")", "{", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'set_pause'", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", "[", "'status'", "]", ";", "}" ]
Pauses the whole queue @return boolean
[ "Pauses", "the", "whole", "queue" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L232-L238
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.pauseQueueTemporary
public function pauseQueueTemporary($time) { $url = $this->buildUrl('config', [ 'name' => 'set_pause', 'value' => $time ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
php
public function pauseQueueTemporary($time) { $url = $this->buildUrl('config', [ 'name' => 'set_pause', 'value' => $time ]); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
[ "public", "function", "pauseQueueTemporary", "(", "$", "time", ")", "{", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'config'", ",", "[", "'name'", "=>", "'set_pause'", ",", "'value'", "=>", "$", "time", "]", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", "[", "'status'", "]", ";", "}" ]
Pauses the queue temporarely for the given amount of time. $time is the number of minutes the queue ist paused @param integer $time @return boolean
[ "Pauses", "the", "queue", "temporarely", "for", "the", "given", "amount", "of", "time", "." ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L249-L259
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.addUrl
public function addUrl($url, $niceName = null, $priority = -100, $category = '', $postProcessing = 3, $script = '') { $params = [ 'name' => $url, 'priority' => $priority, 'category' => $category, 'pp' => $postProcessing, 'script' => $script ]; if ($niceName) { $params['nzbname'] = $niceName; } $url = $this->buildUrl('addurl', $params); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true); }
php
public function addUrl($url, $niceName = null, $priority = -100, $category = '', $postProcessing = 3, $script = '') { $params = [ 'name' => $url, 'priority' => $priority, 'category' => $category, 'pp' => $postProcessing, 'script' => $script ]; if ($niceName) { $params['nzbname'] = $niceName; } $url = $this->buildUrl('addurl', $params); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true); }
[ "public", "function", "addUrl", "(", "$", "url", ",", "$", "niceName", "=", "null", ",", "$", "priority", "=", "-", "100", ",", "$", "category", "=", "''", ",", "$", "postProcessing", "=", "3", ",", "$", "script", "=", "''", ")", "{", "$", "params", "=", "[", "'name'", "=>", "$", "url", ",", "'priority'", "=>", "$", "priority", ",", "'category'", "=>", "$", "category", ",", "'pp'", "=>", "$", "postProcessing", ",", "'script'", "=>", "$", "script", "]", ";", "if", "(", "$", "niceName", ")", "{", "$", "params", "[", "'nzbname'", "]", "=", "$", "niceName", ";", "}", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'addurl'", ",", "$", "params", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", ";", "}" ]
Adds a file to the queue via the given link to the file @param string $url @param string|null $niceName @param int $priority @param string $category @param int $postProcessing @param string $script @return array
[ "Adds", "a", "file", "to", "the", "queue", "via", "the", "given", "link", "to", "the", "file" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L286-L303
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.deleteHistoryEntries
public function deleteHistoryEntries($ids, $withFiles = true) { $params = [ 'name' => 'delete', 'del_files' => $withFiles, 'value' => implode(',', $ids) ]; $url = $this->buildUrl('history', $params); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
php
public function deleteHistoryEntries($ids, $withFiles = true) { $params = [ 'name' => 'delete', 'del_files' => $withFiles, 'value' => implode(',', $ids) ]; $url = $this->buildUrl('history', $params); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
[ "public", "function", "deleteHistoryEntries", "(", "$", "ids", ",", "$", "withFiles", "=", "true", ")", "{", "$", "params", "=", "[", "'name'", "=>", "'delete'", ",", "'del_files'", "=>", "$", "withFiles", ",", "'value'", "=>", "implode", "(", "','", ",", "$", "ids", ")", "]", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'history'", ",", "$", "params", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", "[", "'status'", "]", ";", "}" ]
Deletes the history entry with the given id @param string $ids @param bool $withFiles @return array
[ "Deletes", "the", "history", "entry", "with", "the", "given", "id" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L383-L395
train
effem/sabnzbd-api
Sabnzbd.php
Sabnzbd.deleteAllHistoryEntries
public function deleteAllHistoryEntries($withFiles = true) { $params = [ 'name' => 'delete', 'del_files' => $withFiles, 'value' => 'all' ]; $url = $this->buildUrl('history', $params); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
php
public function deleteAllHistoryEntries($withFiles = true) { $params = [ 'name' => 'delete', 'del_files' => $withFiles, 'value' => 'all' ]; $url = $this->buildUrl('history', $params); $request = $this->guzzle->request('GET', $url); return json_decode($request->getBody(), true)['status']; }
[ "public", "function", "deleteAllHistoryEntries", "(", "$", "withFiles", "=", "true", ")", "{", "$", "params", "=", "[", "'name'", "=>", "'delete'", ",", "'del_files'", "=>", "$", "withFiles", ",", "'value'", "=>", "'all'", "]", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "'history'", ",", "$", "params", ")", ";", "$", "request", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'GET'", ",", "$", "url", ")", ";", "return", "json_decode", "(", "$", "request", "->", "getBody", "(", ")", ",", "true", ")", "[", "'status'", "]", ";", "}" ]
Deletes all history entries @param bool $withFiles @return array
[ "Deletes", "all", "history", "entries" ]
fb173bd6a755f0fe88df23dd20af27e8ebde9f21
https://github.com/effem/sabnzbd-api/blob/fb173bd6a755f0fe88df23dd20af27e8ebde9f21/Sabnzbd.php#L404-L416
train
ARCANESOFT/Blog
src/Models/Presenters/PostPresenter.php
PostPresenter.getLocaleNativeAttribute
public function getLocaleNativeAttribute() { $locale = $this->getAttributeFromArray('locale'); try { return localization() ->getSupportedLocales() ->get($locale) ->native(); } catch (\Exception $e) { return strtoupper($locale); } }
php
public function getLocaleNativeAttribute() { $locale = $this->getAttributeFromArray('locale'); try { return localization() ->getSupportedLocales() ->get($locale) ->native(); } catch (\Exception $e) { return strtoupper($locale); } }
[ "public", "function", "getLocaleNativeAttribute", "(", ")", "{", "$", "locale", "=", "$", "this", "->", "getAttributeFromArray", "(", "'locale'", ")", ";", "try", "{", "return", "localization", "(", ")", "->", "getSupportedLocales", "(", ")", "->", "get", "(", "$", "locale", ")", "->", "native", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "strtoupper", "(", "$", "locale", ")", ";", "}", "}" ]
Get the locale's native name. @return string
[ "Get", "the", "locale", "s", "native", "name", "." ]
2078fdfdcbccda161c02899b9e1f344f011b2859
https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/src/Models/Presenters/PostPresenter.php#L29-L42
train
t3v/t3v_datamapper
Classes/Service/ExtensionService.php
ExtensionService.runningInStrictMode
public function runningInStrictMode(): bool { $strictMode = true; $settings = $this->getSettings(); if (is_array($settings) && !empty($settings)) { $mode = $settings['mode']; if ($mode != self::STRICT_MODE) { $strictMode = false; } } return $strictMode; }
php
public function runningInStrictMode(): bool { $strictMode = true; $settings = $this->getSettings(); if (is_array($settings) && !empty($settings)) { $mode = $settings['mode']; if ($mode != self::STRICT_MODE) { $strictMode = false; } } return $strictMode; }
[ "public", "function", "runningInStrictMode", "(", ")", ":", "bool", "{", "$", "strictMode", "=", "true", ";", "$", "settings", "=", "$", "this", "->", "getSettings", "(", ")", ";", "if", "(", "is_array", "(", "$", "settings", ")", "&&", "!", "empty", "(", "$", "settings", ")", ")", "{", "$", "mode", "=", "$", "settings", "[", "'mode'", "]", ";", "if", "(", "$", "mode", "!=", "self", "::", "STRICT_MODE", ")", "{", "$", "strictMode", "=", "false", ";", "}", "}", "return", "$", "strictMode", ";", "}" ]
Checks if T3v DataMapper is running in `strict` mode. @return bool If T3v DataMapper is running in `strict` mode
[ "Checks", "if", "T3v", "DataMapper", "is", "running", "in", "strict", "mode", "." ]
bab2de90f467936fbe4270cd133cb4109d1108eb
https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/Service/ExtensionService.php#L25-L38
train
t3v/t3v_datamapper
Classes/Service/ExtensionService.php
ExtensionService.runningInFallbackMode
public function runningInFallbackMode(): bool { $fallbackMode = false; $settings = $this->getSettings(); if (is_array($settings) && !empty($settings)) { $mode = $settings['mode']; if ($mode === self::FALLBACK_MODE) { $fallbackMode = true; } } return $fallbackMode; }
php
public function runningInFallbackMode(): bool { $fallbackMode = false; $settings = $this->getSettings(); if (is_array($settings) && !empty($settings)) { $mode = $settings['mode']; if ($mode === self::FALLBACK_MODE) { $fallbackMode = true; } } return $fallbackMode; }
[ "public", "function", "runningInFallbackMode", "(", ")", ":", "bool", "{", "$", "fallbackMode", "=", "false", ";", "$", "settings", "=", "$", "this", "->", "getSettings", "(", ")", ";", "if", "(", "is_array", "(", "$", "settings", ")", "&&", "!", "empty", "(", "$", "settings", ")", ")", "{", "$", "mode", "=", "$", "settings", "[", "'mode'", "]", ";", "if", "(", "$", "mode", "===", "self", "::", "FALLBACK_MODE", ")", "{", "$", "fallbackMode", "=", "true", ";", "}", "}", "return", "$", "fallbackMode", ";", "}" ]
Checks if T3v DataMapper is running in `fallback` mode. @return bool If T3v DataMapper is running in `fallback` mode
[ "Checks", "if", "T3v", "DataMapper", "is", "running", "in", "fallback", "mode", "." ]
bab2de90f467936fbe4270cd133cb4109d1108eb
https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/Service/ExtensionService.php#L45-L58
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.__initInputValidate
protected function __initInputValidate( array &$data ) { // $data must be a array if( !is_array( $data ) ) { throw \Exception( "Entity\Base expects a array for it's first argument" ); } // check to see if any keys exist in $this->data that don't in $data switch( static::$inputValidate ) { case self::VALIDATE_DISABLE: break; case self::VALIDATE_STRIP: $data = \array_intersect_key( $data, $this->data ); break; case self::VALIDATE_EXCEPTION: if( $extraKeys = array_diff_key( $data, $this->data ) ) { throw new UnexpectedPropertyException( sprintf( "Entity\Base via %s is not happy with undeclared keys in \$data input array.\nExtras keys not present in \$this->data: %s.\nPassed: %s", get_called_class(), implode( ', ', array_keys( $extraKeys ) ), print_r( $data, true ) )); } } return true; }
php
protected function __initInputValidate( array &$data ) { // $data must be a array if( !is_array( $data ) ) { throw \Exception( "Entity\Base expects a array for it's first argument" ); } // check to see if any keys exist in $this->data that don't in $data switch( static::$inputValidate ) { case self::VALIDATE_DISABLE: break; case self::VALIDATE_STRIP: $data = \array_intersect_key( $data, $this->data ); break; case self::VALIDATE_EXCEPTION: if( $extraKeys = array_diff_key( $data, $this->data ) ) { throw new UnexpectedPropertyException( sprintf( "Entity\Base via %s is not happy with undeclared keys in \$data input array.\nExtras keys not present in \$this->data: %s.\nPassed: %s", get_called_class(), implode( ', ', array_keys( $extraKeys ) ), print_r( $data, true ) )); } } return true; }
[ "protected", "function", "__initInputValidate", "(", "array", "&", "$", "data", ")", "{", "// $data must be a array", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "throw", "\\", "Exception", "(", "\"Entity\\Base expects a array for it's first argument\"", ")", ";", "}", "// check to see if any keys exist in $this->data that don't in $data", "switch", "(", "static", "::", "$", "inputValidate", ")", "{", "case", "self", "::", "VALIDATE_DISABLE", ":", "break", ";", "case", "self", "::", "VALIDATE_STRIP", ":", "$", "data", "=", "\\", "array_intersect_key", "(", "$", "data", ",", "$", "this", "->", "data", ")", ";", "break", ";", "case", "self", "::", "VALIDATE_EXCEPTION", ":", "if", "(", "$", "extraKeys", "=", "array_diff_key", "(", "$", "data", ",", "$", "this", "->", "data", ")", ")", "{", "throw", "new", "UnexpectedPropertyException", "(", "sprintf", "(", "\"Entity\\Base via %s is not happy with undeclared keys in \\$data input array.\\nExtras keys not present in \\$this->data: %s.\\nPassed: %s\"", ",", "get_called_class", "(", ")", ",", "implode", "(", "', '", ",", "array_keys", "(", "$", "extraKeys", ")", ")", ",", "print_r", "(", "$", "data", ",", "true", ")", ")", ")", ";", "}", "}", "return", "true", ";", "}" ]
Constructor input validation. External to the constructor so that the constructor may itself be overloaded more easily. Does base input validation for the constructor. Checks, that $data is a array. Performs input validation as per the entity constructs in static::$inputValidate @return bool Success
[ "Constructor", "input", "validation", ".", "External", "to", "the", "constructor", "so", "that", "the", "constructor", "may", "itself", "be", "overloaded", "more", "easily", "." ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L217-L251
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.copy
public function copy( $deep = false ) { $data = $this->data; foreach( static::$keyProperties as $key ) { $data[$key] = null; } foreach( $data as $key => $value ) { if( is_object( $value ) and !( $value instanceof self ) ) { $data[$key] = clone $value; } } // have repository? try { if( $repository = $this->r() ) { $entity = $repository->make( $data ); return $entity; } } catch ( EntityMissingEntityManagerException $e ) { } $entity = clone $this; $entity->data = $data; return $entity; }
php
public function copy( $deep = false ) { $data = $this->data; foreach( static::$keyProperties as $key ) { $data[$key] = null; } foreach( $data as $key => $value ) { if( is_object( $value ) and !( $value instanceof self ) ) { $data[$key] = clone $value; } } // have repository? try { if( $repository = $this->r() ) { $entity = $repository->make( $data ); return $entity; } } catch ( EntityMissingEntityManagerException $e ) { } $entity = clone $this; $entity->data = $data; return $entity; }
[ "public", "function", "copy", "(", "$", "deep", "=", "false", ")", "{", "$", "data", "=", "$", "this", "->", "data", ";", "foreach", "(", "static", "::", "$", "keyProperties", "as", "$", "key", ")", "{", "$", "data", "[", "$", "key", "]", "=", "null", ";", "}", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", "and", "!", "(", "$", "value", "instanceof", "self", ")", ")", "{", "$", "data", "[", "$", "key", "]", "=", "clone", "$", "value", ";", "}", "}", "// have repository?", "try", "{", "if", "(", "$", "repository", "=", "$", "this", "->", "r", "(", ")", ")", "{", "$", "entity", "=", "$", "repository", "->", "make", "(", "$", "data", ")", ";", "return", "$", "entity", ";", "}", "}", "catch", "(", "EntityMissingEntityManagerException", "$", "e", ")", "{", "}", "$", "entity", "=", "clone", "$", "this", ";", "$", "entity", "->", "data", "=", "$", "data", ";", "return", "$", "entity", ";", "}" ]
Make a shallow copy of a object clearing it's key fields @param bool # TODO. Pete/ This should probably be Bond\Schema property @return Base
[ "Make", "a", "shallow", "copy", "of", "a", "object", "clearing", "it", "s", "key", "fields" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L258-L284
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.markDeleted
public function markDeleted() { try { if( $repository = $this->r() ) { $repository->detach( $this ); } } catch ( EntityMissingEntityManagerException $e ) { } $this->checksum = null; return $this; }
php
public function markDeleted() { try { if( $repository = $this->r() ) { $repository->detach( $this ); } } catch ( EntityMissingEntityManagerException $e ) { } $this->checksum = null; return $this; }
[ "public", "function", "markDeleted", "(", ")", "{", "try", "{", "if", "(", "$", "repository", "=", "$", "this", "->", "r", "(", ")", ")", "{", "$", "repository", "->", "detach", "(", "$", "this", ")", ";", "}", "}", "catch", "(", "EntityMissingEntityManagerException", "$", "e", ")", "{", "}", "$", "this", "->", "checksum", "=", "null", ";", "return", "$", "this", ";", "}" ]
Mark a entity as deleted @return void
[ "Mark", "a", "entity", "as", "deleted" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L411-L421
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.markPersisted
public function markPersisted() { try { if( $repository = $this->r() ) { $repository->isNew( $this, false ); } } catch ( EntityMissingEntityManagerException $e ) { } $this->checksumReset(); $this->clearDataInitialStore(); return $this; }
php
public function markPersisted() { try { if( $repository = $this->r() ) { $repository->isNew( $this, false ); } } catch ( EntityMissingEntityManagerException $e ) { } $this->checksumReset(); $this->clearDataInitialStore(); return $this; }
[ "public", "function", "markPersisted", "(", ")", "{", "try", "{", "if", "(", "$", "repository", "=", "$", "this", "->", "r", "(", ")", ")", "{", "$", "repository", "->", "isNew", "(", "$", "this", ",", "false", ")", ";", "}", "}", "catch", "(", "EntityMissingEntityManagerException", "$", "e", ")", "{", "}", "$", "this", "->", "checksumReset", "(", ")", ";", "$", "this", "->", "clearDataInitialStore", "(", ")", ";", "return", "$", "this", ";", "}" ]
Mark a entity as persisted @return void
[ "Mark", "a", "entity", "as", "persisted" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L427-L438
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.uidGet
public function uidGet() { // got uid if( isset( $this->uid ) ) { return $this->uid->key; // got key } elseif( $key = $this->keyGet( $this ) ) { return $key; } $this->uid = new Uid( $this ); return $this->uid->key; }
php
public function uidGet() { // got uid if( isset( $this->uid ) ) { return $this->uid->key; // got key } elseif( $key = $this->keyGet( $this ) ) { return $key; } $this->uid = new Uid( $this ); return $this->uid->key; }
[ "public", "function", "uidGet", "(", ")", "{", "// got uid", "if", "(", "isset", "(", "$", "this", "->", "uid", ")", ")", "{", "return", "$", "this", "->", "uid", "->", "key", ";", "// got key", "}", "elseif", "(", "$", "key", "=", "$", "this", "->", "keyGet", "(", "$", "this", ")", ")", "{", "return", "$", "key", ";", "}", "$", "this", "->", "uid", "=", "new", "Uid", "(", "$", "this", ")", ";", "return", "$", "this", "->", "uid", "->", "key", ";", "}" ]
Get a uid for a object. This uid has the following properties. 1. Two different objects won't share the same uid simultaneously 2. In normal script usage a object's uid won't change in the script lifecycle. To fiddle this you'd need to diddling hard with setDirect and the only thing that should be doing that is the record manager. 3. A objects uid is only good for the lifetime of a script. 4. The uid is no good for looking up a object. This is a strictly one-way thing 5. The numbers are not deep and meaningfull. You can't infer anything from them. They are just, well, numbers.
[ "Get", "a", "uid", "for", "a", "object", ".", "This", "uid", "has", "the", "following", "properties", "." ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L501-L519
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.readOnlySafetyCheck
protected function readOnlySafetyCheck() { switch( static::$isReadOnly ) { case self::FULL_ACCESS: return false; case self::READONLY_DISABLE: return true; case self::READONLY_EXCEPTION: throw new ReadonlyException( "Entity is readonly" ); case self::READONLY_ON_PERSIST: if( $this->isNew() !== false ) { return false; } throw new ReadonlyException( "Entity has been persisted and is now readonly" ); default: throw new \InvalidArgumentException( "Entity self::\$isReadonly is has a invalid argument" ); } }
php
protected function readOnlySafetyCheck() { switch( static::$isReadOnly ) { case self::FULL_ACCESS: return false; case self::READONLY_DISABLE: return true; case self::READONLY_EXCEPTION: throw new ReadonlyException( "Entity is readonly" ); case self::READONLY_ON_PERSIST: if( $this->isNew() !== false ) { return false; } throw new ReadonlyException( "Entity has been persisted and is now readonly" ); default: throw new \InvalidArgumentException( "Entity self::\$isReadonly is has a invalid argument" ); } }
[ "protected", "function", "readOnlySafetyCheck", "(", ")", "{", "switch", "(", "static", "::", "$", "isReadOnly", ")", "{", "case", "self", "::", "FULL_ACCESS", ":", "return", "false", ";", "case", "self", "::", "READONLY_DISABLE", ":", "return", "true", ";", "case", "self", "::", "READONLY_EXCEPTION", ":", "throw", "new", "ReadonlyException", "(", "\"Entity is readonly\"", ")", ";", "case", "self", "::", "READONLY_ON_PERSIST", ":", "if", "(", "$", "this", "->", "isNew", "(", ")", "!==", "false", ")", "{", "return", "false", ";", "}", "throw", "new", "ReadonlyException", "(", "\"Entity has been persisted and is now readonly\"", ")", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Entity self::\\$isReadonly is has a invalid argument\"", ")", ";", "}", "}" ]
Is this object readonly? @return int|booly
[ "Is", "this", "object", "readonly?" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L652-L674
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.initalPropertySet
public function initalPropertySet( $key, $value) { // Is this one of our initialProperties // Is it different. Should we store it? if( is_array( $this->dataInitial ) and $repository = $this->r() and in_array( $key, $repository->initialProperties ) ) { $initialValue = $this->get( $key, self::READONLY_EXCEPTION, $source = self::DATA ); // only bother setting if the new value differs from the old and we don't have a dataInitial yet if( $initialValue !== $value and !array_key_exists( $key, $this->dataInitial ) ) { $this->dataInitial[$key] = $initialValue; return true; } } return false; }
php
public function initalPropertySet( $key, $value) { // Is this one of our initialProperties // Is it different. Should we store it? if( is_array( $this->dataInitial ) and $repository = $this->r() and in_array( $key, $repository->initialProperties ) ) { $initialValue = $this->get( $key, self::READONLY_EXCEPTION, $source = self::DATA ); // only bother setting if the new value differs from the old and we don't have a dataInitial yet if( $initialValue !== $value and !array_key_exists( $key, $this->dataInitial ) ) { $this->dataInitial[$key] = $initialValue; return true; } } return false; }
[ "public", "function", "initalPropertySet", "(", "$", "key", ",", "$", "value", ")", "{", "// Is this one of our initialProperties", "// Is it different. Should we store it?", "if", "(", "is_array", "(", "$", "this", "->", "dataInitial", ")", "and", "$", "repository", "=", "$", "this", "->", "r", "(", ")", "and", "in_array", "(", "$", "key", ",", "$", "repository", "->", "initialProperties", ")", ")", "{", "$", "initialValue", "=", "$", "this", "->", "get", "(", "$", "key", ",", "self", "::", "READONLY_EXCEPTION", ",", "$", "source", "=", "self", "::", "DATA", ")", ";", "// only bother setting if the new value differs from the old and we don't have a dataInitial yet", "if", "(", "$", "initialValue", "!==", "$", "value", "and", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "dataInitial", ")", ")", "{", "$", "this", "->", "dataInitial", "[", "$", "key", "]", "=", "$", "initialValue", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
InitialPropertiesSet helper method
[ "InitialPropertiesSet", "helper", "method" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L769-L788
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.keyGet
public static function keyGet( $data ) { // Is a Entity object ? $class = get_called_class(); if( $data instanceof $class ) { $keys = array(); foreach( static::$keyProperties as $property ) { $value = $data->get($property); // resolve entities back down to their key if( $value instanceof Base ) { $value = call_user_func( array( get_class($value), 'keyGet' ), $value ); } $keys[$property] = $value; } // is a data array } elseif( is_array( $data ) ) { $keys = array_intersect_key( $data, array_flip( static::$keyProperties ) ); } // build and return the key if( isset( $keys ) ) { $key = implode( self::KEY_SEPARATOR, $keys ); return strlen( trim( $key, self::KEY_SEPARATOR ) ) === 0 ? null : $key; } throw new BadKeyException("Cant determine a key from this"); }
php
public static function keyGet( $data ) { // Is a Entity object ? $class = get_called_class(); if( $data instanceof $class ) { $keys = array(); foreach( static::$keyProperties as $property ) { $value = $data->get($property); // resolve entities back down to their key if( $value instanceof Base ) { $value = call_user_func( array( get_class($value), 'keyGet' ), $value ); } $keys[$property] = $value; } // is a data array } elseif( is_array( $data ) ) { $keys = array_intersect_key( $data, array_flip( static::$keyProperties ) ); } // build and return the key if( isset( $keys ) ) { $key = implode( self::KEY_SEPARATOR, $keys ); return strlen( trim( $key, self::KEY_SEPARATOR ) ) === 0 ? null : $key; } throw new BadKeyException("Cant determine a key from this"); }
[ "public", "static", "function", "keyGet", "(", "$", "data", ")", "{", "// Is a Entity object ?", "$", "class", "=", "get_called_class", "(", ")", ";", "if", "(", "$", "data", "instanceof", "$", "class", ")", "{", "$", "keys", "=", "array", "(", ")", ";", "foreach", "(", "static", "::", "$", "keyProperties", "as", "$", "property", ")", "{", "$", "value", "=", "$", "data", "->", "get", "(", "$", "property", ")", ";", "// resolve entities back down to their key", "if", "(", "$", "value", "instanceof", "Base", ")", "{", "$", "value", "=", "call_user_func", "(", "array", "(", "get_class", "(", "$", "value", ")", ",", "'keyGet'", ")", ",", "$", "value", ")", ";", "}", "$", "keys", "[", "$", "property", "]", "=", "$", "value", ";", "}", "// is a data array", "}", "elseif", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "keys", "=", "array_intersect_key", "(", "$", "data", ",", "array_flip", "(", "static", "::", "$", "keyProperties", ")", ")", ";", "}", "// build and return the key", "if", "(", "isset", "(", "$", "keys", ")", ")", "{", "$", "key", "=", "implode", "(", "self", "::", "KEY_SEPARATOR", ",", "$", "keys", ")", ";", "return", "strlen", "(", "trim", "(", "$", "key", ",", "self", "::", "KEY_SEPARATOR", ")", ")", "===", "0", "?", "null", ":", "$", "key", ";", "}", "throw", "new", "BadKeyException", "(", "\"Cant determine a key from this\"", ")", ";", "}" ]
Key entity `key` @param array|Entity\Base $data @return array
[ "Key", "entity", "key" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L929-L973
train
squareproton/Bond
src/Bond/Entity/Base.php
Base.canValidateProperty
public function canValidateProperty( $key ) { return isset( $this->data[$key] ) and is_object( $this->data[$key] ) and $this->data[$key] instanceof Base; }
php
public function canValidateProperty( $key ) { return isset( $this->data[$key] ) and is_object( $this->data[$key] ) and $this->data[$key] instanceof Base; }
[ "public", "function", "canValidateProperty", "(", "$", "key", ")", "{", "return", "isset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", "and", "is_object", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", "and", "$", "this", "->", "data", "[", "$", "key", "]", "instanceof", "Base", ";", "}" ]
Has validation property?
[ "Has", "validation", "property?" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Base.php#L993-L996
train
jenskooij/cloudcontrol
src/search/CharacterFilter.php
CharacterFilter.filterSpecialCharacters
private function filterSpecialCharacters($string) { $string = str_replace('<', ' <', $string); // This is need, otherwise this: <h1>something</h1><h2>something</h2> will result in somethingsomething $string = strip_tags($string); $string = trim($string); $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters $string = str_replace(array('+', '=', '!', ',', '.', ';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space. $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space. $string = preg_replace("/[^a-zA-Z0-9 ]/", '', $string); // Filter out everything that is not alphanumeric or a space $string = preg_replace('!\s+!', ' ', $string); // Replace multiple spaces with a single space return $string; }
php
private function filterSpecialCharacters($string) { $string = str_replace('<', ' <', $string); // This is need, otherwise this: <h1>something</h1><h2>something</h2> will result in somethingsomething $string = strip_tags($string); $string = trim($string); $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters $string = str_replace(array('+', '=', '!', ',', '.', ';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space. $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space. $string = preg_replace("/[^a-zA-Z0-9 ]/", '', $string); // Filter out everything that is not alphanumeric or a space $string = preg_replace('!\s+!', ' ', $string); // Replace multiple spaces with a single space return $string; }
[ "private", "function", "filterSpecialCharacters", "(", "$", "string", ")", "{", "$", "string", "=", "str_replace", "(", "'<'", ",", "' <'", ",", "$", "string", ")", ";", "// This is need, otherwise this: <h1>something</h1><h2>something</h2> will result in somethingsomething", "$", "string", "=", "strip_tags", "(", "$", "string", ")", ";", "$", "string", "=", "trim", "(", "$", "string", ")", ";", "$", "string", "=", "iconv", "(", "'UTF-8'", ",", "'ASCII//TRANSLIT//IGNORE'", ",", "$", "string", ")", ";", "// Remove special alphanumeric characters", "$", "string", "=", "str_replace", "(", "array", "(", "'+'", ",", "'='", ",", "'!'", ",", "','", ",", "'.'", ",", "';'", ",", "':'", ",", "'?'", ")", ",", "' '", ",", "$", "string", ")", ";", "// Replace sentence breaking charaters with spaces", "$", "string", "=", "preg_replace", "(", "\"/[\\r\\n]+/\"", ",", "\" \"", ",", "$", "string", ")", ";", "// Replace multiple newlines with a single space.", "$", "string", "=", "preg_replace", "(", "\"/[\\t]+/\"", ",", "\" \"", ",", "$", "string", ")", ";", "// Replace multiple tabs with a single space.", "$", "string", "=", "preg_replace", "(", "\"/[^a-zA-Z0-9 ]/\"", ",", "''", ",", "$", "string", ")", ";", "// Filter out everything that is not alphanumeric or a space", "$", "string", "=", "preg_replace", "(", "'!\\s+!'", ",", "' '", ",", "$", "string", ")", ";", "// Replace multiple spaces with a single space", "return", "$", "string", ";", "}" ]
Filter out all special characters, like punctuation and characters with accents @param $string @return mixed|string
[ "Filter", "out", "all", "special", "characters", "like", "punctuation", "and", "characters", "with", "accents" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/search/CharacterFilter.php#L48-L63
train
zfegg/zfegg-admin
src/V1/Rest/UserRoles/UserRolesResource.php
UserRolesResource.fetchAll
public function fetchAll($params = []) { return $this->table->select( function (Select $select) { $select->columns([]); $select->join( $this->roleTableName, sprintf('%s.role_id=%s.role_id', $this->roleTableName, $this->table->getTable()) ); $select->where(['user_id' => $this->getUserId()]); } ); // $adapter = new DbSelect($select, $this->table->getAdapter()); // return new $this->collectionClass($adapter); }
php
public function fetchAll($params = []) { return $this->table->select( function (Select $select) { $select->columns([]); $select->join( $this->roleTableName, sprintf('%s.role_id=%s.role_id', $this->roleTableName, $this->table->getTable()) ); $select->where(['user_id' => $this->getUserId()]); } ); // $adapter = new DbSelect($select, $this->table->getAdapter()); // return new $this->collectionClass($adapter); }
[ "public", "function", "fetchAll", "(", "$", "params", "=", "[", "]", ")", "{", "return", "$", "this", "->", "table", "->", "select", "(", "function", "(", "Select", "$", "select", ")", "{", "$", "select", "->", "columns", "(", "[", "]", ")", ";", "$", "select", "->", "join", "(", "$", "this", "->", "roleTableName", ",", "sprintf", "(", "'%s.role_id=%s.role_id'", ",", "$", "this", "->", "roleTableName", ",", "$", "this", "->", "table", "->", "getTable", "(", ")", ")", ")", ";", "$", "select", "->", "where", "(", "[", "'user_id'", "=>", "$", "this", "->", "getUserId", "(", ")", "]", ")", ";", "}", ")", ";", "// $adapter = new DbSelect($select, $this->table->getAdapter());", "// return new $this->collectionClass($adapter);", "}" ]
Fetch all or a subset of resources @param array $params @return \Zend\Db\ResultSet\ResultSet
[ "Fetch", "all", "or", "a", "subset", "of", "resources" ]
4e8363eac54f090f84cf511be351f0cc46902b63
https://github.com/zfegg/zfegg-admin/blob/4e8363eac54f090f84cf511be351f0cc46902b63/src/V1/Rest/UserRoles/UserRolesResource.php#L45-L60
train
rollerworks/search-core
Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php
MoneyToLocalizedStringTransformer.addCurrencySymbol
private function addCurrencySymbol(string $value, ?string $currency = null): string { $currency = $currency ?? $this->defaultCurrency; $locale = \Locale::getDefault(); if (!isset(self::$patterns[$locale])) { self::$patterns[$locale] = []; } if (!isset(self::$patterns[$locale][$currency])) { $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); $pattern = $formatter->formatCurrency(123.00, $currency); // 1=left-position currency, 2=left-space, 3=right-space, 4=left-position currency. // With non latin number scripts. preg_match( '/^([^\s\xc2\xa0]*)([\s\xc2\xa0]*)\p{N}{3}(?:[,.]\p{N}+)?([\s\xc2\xa0]*)([^\s\xc2\xa0]*)$/iu', $pattern, $matches ); if (!empty($matches[1])) { self::$patterns[$locale][$currency] = ['%1$s'.$matches[2].'%2$s', $matches[1]]; } elseif (!empty($matches[4])) { self::$patterns[$locale][$currency] = ['%2$s'.$matches[3].'%1$s', $matches[4]]; } else { throw new \InvalidArgumentException( sprintf('Locale "%s" with currency "%s" does not provide a currency position.', $locale, $currency) ); } } return sprintf(self::$patterns[$locale][$currency][0], self::$patterns[$locale][$currency][1], $value); }
php
private function addCurrencySymbol(string $value, ?string $currency = null): string { $currency = $currency ?? $this->defaultCurrency; $locale = \Locale::getDefault(); if (!isset(self::$patterns[$locale])) { self::$patterns[$locale] = []; } if (!isset(self::$patterns[$locale][$currency])) { $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); $pattern = $formatter->formatCurrency(123.00, $currency); // 1=left-position currency, 2=left-space, 3=right-space, 4=left-position currency. // With non latin number scripts. preg_match( '/^([^\s\xc2\xa0]*)([\s\xc2\xa0]*)\p{N}{3}(?:[,.]\p{N}+)?([\s\xc2\xa0]*)([^\s\xc2\xa0]*)$/iu', $pattern, $matches ); if (!empty($matches[1])) { self::$patterns[$locale][$currency] = ['%1$s'.$matches[2].'%2$s', $matches[1]]; } elseif (!empty($matches[4])) { self::$patterns[$locale][$currency] = ['%2$s'.$matches[3].'%1$s', $matches[4]]; } else { throw new \InvalidArgumentException( sprintf('Locale "%s" with currency "%s" does not provide a currency position.', $locale, $currency) ); } } return sprintf(self::$patterns[$locale][$currency][0], self::$patterns[$locale][$currency][1], $value); }
[ "private", "function", "addCurrencySymbol", "(", "string", "$", "value", ",", "?", "string", "$", "currency", "=", "null", ")", ":", "string", "{", "$", "currency", "=", "$", "currency", "??", "$", "this", "->", "defaultCurrency", ";", "$", "locale", "=", "\\", "Locale", "::", "getDefault", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "patterns", "[", "$", "locale", "]", ")", ")", "{", "self", "::", "$", "patterns", "[", "$", "locale", "]", "=", "[", "]", ";", "}", "if", "(", "!", "isset", "(", "self", "::", "$", "patterns", "[", "$", "locale", "]", "[", "$", "currency", "]", ")", ")", "{", "$", "formatter", "=", "new", "\\", "NumberFormatter", "(", "$", "locale", ",", "\\", "NumberFormatter", "::", "CURRENCY", ")", ";", "$", "pattern", "=", "$", "formatter", "->", "formatCurrency", "(", "123.00", ",", "$", "currency", ")", ";", "// 1=left-position currency, 2=left-space, 3=right-space, 4=left-position currency.", "// With non latin number scripts.", "preg_match", "(", "'/^([^\\s\\xc2\\xa0]*)([\\s\\xc2\\xa0]*)\\p{N}{3}(?:[,.]\\p{N}+)?([\\s\\xc2\\xa0]*)([^\\s\\xc2\\xa0]*)$/iu'", ",", "$", "pattern", ",", "$", "matches", ")", ";", "if", "(", "!", "empty", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "self", "::", "$", "patterns", "[", "$", "locale", "]", "[", "$", "currency", "]", "=", "[", "'%1$s'", ".", "$", "matches", "[", "2", "]", ".", "'%2$s'", ",", "$", "matches", "[", "1", "]", "]", ";", "}", "elseif", "(", "!", "empty", "(", "$", "matches", "[", "4", "]", ")", ")", "{", "self", "::", "$", "patterns", "[", "$", "locale", "]", "[", "$", "currency", "]", "=", "[", "'%2$s'", ".", "$", "matches", "[", "3", "]", ".", "'%1$s'", ",", "$", "matches", "[", "4", "]", "]", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Locale \"%s\" with currency \"%s\" does not provide a currency position.'", ",", "$", "locale", ",", "$", "currency", ")", ")", ";", "}", "}", "return", "sprintf", "(", "self", "::", "$", "patterns", "[", "$", "locale", "]", "[", "$", "currency", "]", "[", "0", "]", ",", "self", "::", "$", "patterns", "[", "$", "locale", "]", "[", "$", "currency", "]", "[", "1", "]", ",", "$", "value", ")", ";", "}" ]
Adds the currency symbol when missing. ICU cannot parse() without a currency, and decimal doesn't include scale when 0.
[ "Adds", "the", "currency", "symbol", "when", "missing", "." ]
6b5671b8c4d6298906ded768261b0a59845140fb
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php#L149-L182
train
rollerworks/search-core
Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php
MoneyToLocalizedStringTransformer.removeCurrencySymbol
private function removeCurrencySymbol(string $value, string $currency): string { $locale = \Locale::getDefault(); if (!isset(self::$patterns[$locale][$currency])) { // Initialize the cache, ignore return. $this->addCurrencySymbol('123', $currency); } return preg_replace('#(\s?'.preg_quote(self::$patterns[$locale][$currency][1], '#').'\s?)#u', '', $value); }
php
private function removeCurrencySymbol(string $value, string $currency): string { $locale = \Locale::getDefault(); if (!isset(self::$patterns[$locale][$currency])) { // Initialize the cache, ignore return. $this->addCurrencySymbol('123', $currency); } return preg_replace('#(\s?'.preg_quote(self::$patterns[$locale][$currency][1], '#').'\s?)#u', '', $value); }
[ "private", "function", "removeCurrencySymbol", "(", "string", "$", "value", ",", "string", "$", "currency", ")", ":", "string", "{", "$", "locale", "=", "\\", "Locale", "::", "getDefault", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "patterns", "[", "$", "locale", "]", "[", "$", "currency", "]", ")", ")", "{", "// Initialize the cache, ignore return.", "$", "this", "->", "addCurrencySymbol", "(", "'123'", ",", "$", "currency", ")", ";", "}", "return", "preg_replace", "(", "'#(\\s?'", ".", "preg_quote", "(", "self", "::", "$", "patterns", "[", "$", "locale", "]", "[", "$", "currency", "]", "[", "1", "]", ",", "'#'", ")", ".", "'\\s?)#u'", ",", "''", ",", "$", "value", ")", ";", "}" ]
Removes the currency symbol. ICU cannot format() with currency, as this produces a number with the `¤` symbol. And, decimal doesn't include scale when 0.
[ "Removes", "the", "currency", "symbol", "." ]
6b5671b8c4d6298906ded768261b0a59845140fb
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php#L191-L201
train
judus/minimal-database
src/QueryBuilder.php
QueryBuilder.getFirst
public function getFirst($sql = null) { if ($sql) { $this->setLastQuery($sql); try { $result = $this->db->query($sql); } catch (\PDOException $e) { throw new DatabaseException($e->getMessage() . '<br>' . $this->getLastQuery()[0]); } $data = $this->fetchAssoc($result); if (isset($data[0])) { return $data[0]; } return null; } return $this->limit(1)->query()->fetchAssoc(); }
php
public function getFirst($sql = null) { if ($sql) { $this->setLastQuery($sql); try { $result = $this->db->query($sql); } catch (\PDOException $e) { throw new DatabaseException($e->getMessage() . '<br>' . $this->getLastQuery()[0]); } $data = $this->fetchAssoc($result); if (isset($data[0])) { return $data[0]; } return null; } return $this->limit(1)->query()->fetchAssoc(); }
[ "public", "function", "getFirst", "(", "$", "sql", "=", "null", ")", "{", "if", "(", "$", "sql", ")", "{", "$", "this", "->", "setLastQuery", "(", "$", "sql", ")", ";", "try", "{", "$", "result", "=", "$", "this", "->", "db", "->", "query", "(", "$", "sql", ")", ";", "}", "catch", "(", "\\", "PDOException", "$", "e", ")", "{", "throw", "new", "DatabaseException", "(", "$", "e", "->", "getMessage", "(", ")", ".", "'<br>'", ".", "$", "this", "->", "getLastQuery", "(", ")", "[", "0", "]", ")", ";", "}", "$", "data", "=", "$", "this", "->", "fetchAssoc", "(", "$", "result", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "0", "]", ")", ")", "{", "return", "$", "data", "[", "0", "]", ";", "}", "return", "null", ";", "}", "return", "$", "this", "->", "limit", "(", "1", ")", "->", "query", "(", ")", "->", "fetchAssoc", "(", ")", ";", "}" ]
Return the first the matching row @param null $sql Optional query string @return array|null @throws DatabaseException
[ "Return", "the", "first", "the", "matching", "row" ]
e6f8cb46eab41c3f1b6cabe0da5ccd0926727279
https://github.com/judus/minimal-database/blob/e6f8cb46eab41c3f1b6cabe0da5ccd0926727279/src/QueryBuilder.php#L740-L761
train
judus/minimal-database
src/QueryBuilder.php
QueryBuilder.getById
public function getById($id) { $sql = "SELECT * FROM " . $this->getTable() . " WHERE " . $this->getPrimaryKey() . " = " . intval($id) . ";"; try { $result = $this->db->query($sql); } catch (\PDOException $e) { throw new DatabaseException($e->getMessage() . '<br>' . $sql); } return $this->fetchAssoc($result); }
php
public function getById($id) { $sql = "SELECT * FROM " . $this->getTable() . " WHERE " . $this->getPrimaryKey() . " = " . intval($id) . ";"; try { $result = $this->db->query($sql); } catch (\PDOException $e) { throw new DatabaseException($e->getMessage() . '<br>' . $sql); } return $this->fetchAssoc($result); }
[ "public", "function", "getById", "(", "$", "id", ")", "{", "$", "sql", "=", "\"SELECT * FROM \"", ".", "$", "this", "->", "getTable", "(", ")", ".", "\" WHERE \"", ".", "$", "this", "->", "getPrimaryKey", "(", ")", ".", "\" = \"", ".", "intval", "(", "$", "id", ")", ".", "\";\"", ";", "try", "{", "$", "result", "=", "$", "this", "->", "db", "->", "query", "(", "$", "sql", ")", ";", "}", "catch", "(", "\\", "PDOException", "$", "e", ")", "{", "throw", "new", "DatabaseException", "(", "$", "e", "->", "getMessage", "(", ")", ".", "'<br>'", ".", "$", "sql", ")", ";", "}", "return", "$", "this", "->", "fetchAssoc", "(", "$", "result", ")", ";", "}" ]
Select a row by id from this table @param $id @return array|null @throws DatabaseException
[ "Select", "a", "row", "by", "id", "from", "this", "table" ]
e6f8cb46eab41c3f1b6cabe0da5ccd0926727279
https://github.com/judus/minimal-database/blob/e6f8cb46eab41c3f1b6cabe0da5ccd0926727279/src/QueryBuilder.php#L771-L782
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.setConnectionInfo
public function setConnectionInfo(array $connections) { foreach($connections as $connectionInfo) { if (empty($connectionInfo['hostname'])) $connectionInfo['hostname'] = 'localhost'; if (empty($connectionInfo['port'])) $connectionInfo['port'] = 3306; if (empty($connectionInfo['timeout'])) $connectionInfo['timeout'] = 30; if (empty($connectionInfo['database'])) throw new DatabaseException("Database name is empty."); if (empty($connectionInfo['username'])) throw new DatabaseException("Database username is empty."); } //if(empty($connectionInfo['password'])) // throw new DatabaseException("Database password is empty."); $this->connectionConfig = $connections; }
php
public function setConnectionInfo(array $connections) { foreach($connections as $connectionInfo) { if (empty($connectionInfo['hostname'])) $connectionInfo['hostname'] = 'localhost'; if (empty($connectionInfo['port'])) $connectionInfo['port'] = 3306; if (empty($connectionInfo['timeout'])) $connectionInfo['timeout'] = 30; if (empty($connectionInfo['database'])) throw new DatabaseException("Database name is empty."); if (empty($connectionInfo['username'])) throw new DatabaseException("Database username is empty."); } //if(empty($connectionInfo['password'])) // throw new DatabaseException("Database password is empty."); $this->connectionConfig = $connections; }
[ "public", "function", "setConnectionInfo", "(", "array", "$", "connections", ")", "{", "foreach", "(", "$", "connections", "as", "$", "connectionInfo", ")", "{", "if", "(", "empty", "(", "$", "connectionInfo", "[", "'hostname'", "]", ")", ")", "$", "connectionInfo", "[", "'hostname'", "]", "=", "'localhost'", ";", "if", "(", "empty", "(", "$", "connectionInfo", "[", "'port'", "]", ")", ")", "$", "connectionInfo", "[", "'port'", "]", "=", "3306", ";", "if", "(", "empty", "(", "$", "connectionInfo", "[", "'timeout'", "]", ")", ")", "$", "connectionInfo", "[", "'timeout'", "]", "=", "30", ";", "if", "(", "empty", "(", "$", "connectionInfo", "[", "'database'", "]", ")", ")", "throw", "new", "DatabaseException", "(", "\"Database name is empty.\"", ")", ";", "if", "(", "empty", "(", "$", "connectionInfo", "[", "'username'", "]", ")", ")", "throw", "new", "DatabaseException", "(", "\"Database username is empty.\"", ")", ";", "}", "//if(empty($connectionInfo['password']))", "// throw new DatabaseException(\"Database password is empty.\");", "$", "this", "->", "connectionConfig", "=", "$", "connections", ";", "}" ]
Validates required values are present for a database connection. @param array $connectionInfo Connection info. See {@link __construct(...)} for details on keys and values. @return void @throws Exception If the required parameters aren't passed
[ "Validates", "required", "values", "are", "present", "for", "a", "database", "connection", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L68-L94
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.getConnection
public function getConnection() { if (empty($this->connection)) { if (empty($this->connectionConfig) || !is_array($this->connectionConfig)) throw new DatabaseException("Connection config is empty or not an array."); $connCount = count($this->connectionConfig); for($i = 0; $i < $connCount; ++$i) { $connectionInfo = $this->connectionConfig[$i]; if (empty($connectionInfo['port'])) $connectionInfo['port'] = 3306; $dsn = "mysql:dbname={$connectionInfo['database']};host={$connectionInfo['host']};port={$connectionInfo['port']}"; if (!empty($connectionInfo['unix_socket'])) $dsn .= ';unix_socket='.$connectionInfo['unix_socket']; try { $trx_attempt = 0; while ($trx_attempt < $this->deadlockRetries) { try { $this->connection = new PDO($dsn, $connectionInfo['username'], $connectionInfo['password'], array( PDO::ATTR_PERSISTENT => (!empty($connectionInfo['persistent'])?StringUtils::strToBool($connectionInfo['persistent']):false), PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, PDO::MYSQL_ATTR_DIRECT_QUERY => true, PDO::ATTR_TIMEOUT => (!empty($connectionInfo['timeout'])?$connectionInfo['timeout']:30) )); $this->connDebugString = $connectionInfo['host'].':'.$connectionInfo['database']; $this->currentDBName = $connectionInfo['database']; $this->Logger->debug(array( 'SQL' => 'CONNECTION - DB: '.$this->connDebugString, )); return $this->connection; } catch (PDOException $pe) { if ((strpos($pe->getMessage(), 'Too many connections') !== FALSE) && ++$trx_attempt < $this->deadlockRetries) { usleep( pow(2,$trx_attempt) * 100000 ); continue; } throw $pe; } } } catch(PDOException $pe) { // if the last connection fails if($i == ($connCount-1)) throw new SQLConnectionException($pe->getMessage()); } } } return $this->connection; }
php
public function getConnection() { if (empty($this->connection)) { if (empty($this->connectionConfig) || !is_array($this->connectionConfig)) throw new DatabaseException("Connection config is empty or not an array."); $connCount = count($this->connectionConfig); for($i = 0; $i < $connCount; ++$i) { $connectionInfo = $this->connectionConfig[$i]; if (empty($connectionInfo['port'])) $connectionInfo['port'] = 3306; $dsn = "mysql:dbname={$connectionInfo['database']};host={$connectionInfo['host']};port={$connectionInfo['port']}"; if (!empty($connectionInfo['unix_socket'])) $dsn .= ';unix_socket='.$connectionInfo['unix_socket']; try { $trx_attempt = 0; while ($trx_attempt < $this->deadlockRetries) { try { $this->connection = new PDO($dsn, $connectionInfo['username'], $connectionInfo['password'], array( PDO::ATTR_PERSISTENT => (!empty($connectionInfo['persistent'])?StringUtils::strToBool($connectionInfo['persistent']):false), PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, PDO::MYSQL_ATTR_DIRECT_QUERY => true, PDO::ATTR_TIMEOUT => (!empty($connectionInfo['timeout'])?$connectionInfo['timeout']:30) )); $this->connDebugString = $connectionInfo['host'].':'.$connectionInfo['database']; $this->currentDBName = $connectionInfo['database']; $this->Logger->debug(array( 'SQL' => 'CONNECTION - DB: '.$this->connDebugString, )); return $this->connection; } catch (PDOException $pe) { if ((strpos($pe->getMessage(), 'Too many connections') !== FALSE) && ++$trx_attempt < $this->deadlockRetries) { usleep( pow(2,$trx_attempt) * 100000 ); continue; } throw $pe; } } } catch(PDOException $pe) { // if the last connection fails if($i == ($connCount-1)) throw new SQLConnectionException($pe->getMessage()); } } } return $this->connection; }
[ "public", "function", "getConnection", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "connection", ")", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "connectionConfig", ")", "||", "!", "is_array", "(", "$", "this", "->", "connectionConfig", ")", ")", "throw", "new", "DatabaseException", "(", "\"Connection config is empty or not an array.\"", ")", ";", "$", "connCount", "=", "count", "(", "$", "this", "->", "connectionConfig", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "connCount", ";", "++", "$", "i", ")", "{", "$", "connectionInfo", "=", "$", "this", "->", "connectionConfig", "[", "$", "i", "]", ";", "if", "(", "empty", "(", "$", "connectionInfo", "[", "'port'", "]", ")", ")", "$", "connectionInfo", "[", "'port'", "]", "=", "3306", ";", "$", "dsn", "=", "\"mysql:dbname={$connectionInfo['database']};host={$connectionInfo['host']};port={$connectionInfo['port']}\"", ";", "if", "(", "!", "empty", "(", "$", "connectionInfo", "[", "'unix_socket'", "]", ")", ")", "$", "dsn", ".=", "';unix_socket='", ".", "$", "connectionInfo", "[", "'unix_socket'", "]", ";", "try", "{", "$", "trx_attempt", "=", "0", ";", "while", "(", "$", "trx_attempt", "<", "$", "this", "->", "deadlockRetries", ")", "{", "try", "{", "$", "this", "->", "connection", "=", "new", "PDO", "(", "$", "dsn", ",", "$", "connectionInfo", "[", "'username'", "]", ",", "$", "connectionInfo", "[", "'password'", "]", ",", "array", "(", "PDO", "::", "ATTR_PERSISTENT", "=>", "(", "!", "empty", "(", "$", "connectionInfo", "[", "'persistent'", "]", ")", "?", "StringUtils", "::", "strToBool", "(", "$", "connectionInfo", "[", "'persistent'", "]", ")", ":", "false", ")", ",", "PDO", "::", "ATTR_ERRMODE", "=>", "PDO", "::", "ERRMODE_EXCEPTION", ",", "PDO", "::", "ATTR_CASE", "=>", "PDO", "::", "CASE_NATURAL", ",", "PDO", "::", "MYSQL_ATTR_USE_BUFFERED_QUERY", "=>", "true", ",", "PDO", "::", "MYSQL_ATTR_DIRECT_QUERY", "=>", "true", ",", "PDO", "::", "ATTR_TIMEOUT", "=>", "(", "!", "empty", "(", "$", "connectionInfo", "[", "'timeout'", "]", ")", "?", "$", "connectionInfo", "[", "'timeout'", "]", ":", "30", ")", ")", ")", ";", "$", "this", "->", "connDebugString", "=", "$", "connectionInfo", "[", "'host'", "]", ".", "':'", ".", "$", "connectionInfo", "[", "'database'", "]", ";", "$", "this", "->", "currentDBName", "=", "$", "connectionInfo", "[", "'database'", "]", ";", "$", "this", "->", "Logger", "->", "debug", "(", "array", "(", "'SQL'", "=>", "'CONNECTION - DB: '", ".", "$", "this", "->", "connDebugString", ",", ")", ")", ";", "return", "$", "this", "->", "connection", ";", "}", "catch", "(", "PDOException", "$", "pe", ")", "{", "if", "(", "(", "strpos", "(", "$", "pe", "->", "getMessage", "(", ")", ",", "'Too many connections'", ")", "!==", "FALSE", ")", "&&", "++", "$", "trx_attempt", "<", "$", "this", "->", "deadlockRetries", ")", "{", "usleep", "(", "pow", "(", "2", ",", "$", "trx_attempt", ")", "*", "100000", ")", ";", "continue", ";", "}", "throw", "$", "pe", ";", "}", "}", "}", "catch", "(", "PDOException", "$", "pe", ")", "{", "// if the last connection fails", "if", "(", "$", "i", "==", "(", "$", "connCount", "-", "1", ")", ")", "throw", "new", "SQLConnectionException", "(", "$", "pe", "->", "getMessage", "(", ")", ")", ";", "}", "}", "}", "return", "$", "this", "->", "connection", ";", "}" ]
Gets the current PDO connection object @return PDO MySQL PDO Connection
[ "Gets", "the", "current", "PDO", "connection", "object" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L101-L167
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.readField
public function readField($sql) { $result = $this->read($sql); $result->setFetchMode(PDO::FETCH_COLUMN, 0); $row = $result->fetch(); //$this->convertDatesInRows($result, $row); unset($result); return $row; }
php
public function readField($sql) { $result = $this->read($sql); $result->setFetchMode(PDO::FETCH_COLUMN, 0); $row = $result->fetch(); //$this->convertDatesInRows($result, $row); unset($result); return $row; }
[ "public", "function", "readField", "(", "$", "sql", ")", "{", "$", "result", "=", "$", "this", "->", "read", "(", "$", "sql", ")", ";", "$", "result", "->", "setFetchMode", "(", "PDO", "::", "FETCH_COLUMN", ",", "0", ")", ";", "$", "row", "=", "$", "result", "->", "fetch", "(", ")", ";", "//$this->convertDatesInRows($result, $row);", "unset", "(", "$", "result", ")", ";", "return", "$", "row", ";", "}" ]
Returns the first column of the first row of the result set NOTE: It is expected that all DATETIME or TIMESTAMP or other native date column types should automatically be converted to StorageDate. @param string $sql SELECT statement @return string|StorageDate
[ "Returns", "the", "first", "column", "of", "the", "first", "row", "of", "the", "result", "set" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L309-L317
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.readCol
public function readCol($sql) { $result = $this->read($sql); $row = $result->fetchAll(PDO::FETCH_COLUMN, 0); //$this->convertDatesInRows($result, $row); unset($result); return $row; }
php
public function readCol($sql) { $result = $this->read($sql); $row = $result->fetchAll(PDO::FETCH_COLUMN, 0); //$this->convertDatesInRows($result, $row); unset($result); return $row; }
[ "public", "function", "readCol", "(", "$", "sql", ")", "{", "$", "result", "=", "$", "this", "->", "read", "(", "$", "sql", ")", ";", "$", "row", "=", "$", "result", "->", "fetchAll", "(", "PDO", "::", "FETCH_COLUMN", ",", "0", ")", ";", "//$this->convertDatesInRows($result, $row);", "unset", "(", "$", "result", ")", ";", "return", "$", "row", ";", "}" ]
Returns an array of values for the first column of the result set <code> $result = $this->readCol('SELECT col FROM table'); ... array( 0 => 'value1', 1 => 'value2', 2 => 'value3' ) </code> @param string $sql SELECT statement @return array Single dimension array of values for the column
[ "Returns", "an", "array", "of", "values", "for", "the", "first", "column", "of", "the", "result", "set" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L338-L345
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.readOne
public function readOne($sql) { $result = $this->readAll($sql, false); if (count($result) > 0) { return $result[0]; } }
php
public function readOne($sql) { $result = $this->readAll($sql, false); if (count($result) > 0) { return $result[0]; } }
[ "public", "function", "readOne", "(", "$", "sql", ")", "{", "$", "result", "=", "$", "this", "->", "readAll", "(", "$", "sql", ",", "false", ")", ";", "if", "(", "count", "(", "$", "result", ")", ">", "0", ")", "{", "return", "$", "result", "[", "0", "]", ";", "}", "}" ]
Returns the first row of the result set as an associative array, regardless of the overall number of rows <code> $result = $this->readOne('SELECT col1, col2 FROM table'); ... array( 'col1' => 'value of col1', 'col2' => 'value of col2' ) </code> @param string $sql SELECT statement @return array Single dimension array of the first row returned by the SELECT query, regardless of overall result set count
[ "Returns", "the", "first", "row", "of", "the", "result", "set", "as", "an", "associative", "array", "regardless", "of", "the", "overall", "number", "of", "rows" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L368-L374
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.readAll
public function readAll($sql, $calcFoundRows = false) { $result = $this->read($calcFoundRows ? $this->insertPagingFlag($sql) : $sql); $rows = $result->fetchAll(PDO::FETCH_ASSOC); //$this->convertDatesInRows($result, $rows); unset($result); unset($sql); return $rows; }
php
public function readAll($sql, $calcFoundRows = false) { $result = $this->read($calcFoundRows ? $this->insertPagingFlag($sql) : $sql); $rows = $result->fetchAll(PDO::FETCH_ASSOC); //$this->convertDatesInRows($result, $rows); unset($result); unset($sql); return $rows; }
[ "public", "function", "readAll", "(", "$", "sql", ",", "$", "calcFoundRows", "=", "false", ")", "{", "$", "result", "=", "$", "this", "->", "read", "(", "$", "calcFoundRows", "?", "$", "this", "->", "insertPagingFlag", "(", "$", "sql", ")", ":", "$", "sql", ")", ";", "$", "rows", "=", "$", "result", "->", "fetchAll", "(", "PDO", "::", "FETCH_ASSOC", ")", ";", "//$this->convertDatesInRows($result, $rows);", "unset", "(", "$", "result", ")", ";", "unset", "(", "$", "sql", ")", ";", "return", "$", "rows", ";", "}" ]
Returns an associative array of rows and columns <code> $result = $this->readAll('SELECT id, col1 FROM table'); ... array( 0 => array( 'id' => '1', 'col1' => 'value'), 1 => array( 'id' => '2', 'col1' => 'value'), ... ) </code> @param string $sql SELECT statement @param boolean $calcFoundRows Flag to indicate to the underlying DB that the query should calculate the total number of rows matching the WHERE clause of the SELECT regardless of any LIMIT clause. In MySQL, this equates to injecting SQL_CALC_FOUND_ROWS into the SELECT. @return array Associative array of rows and columns
[ "Returns", "an", "associative", "array", "of", "rows", "and", "columns" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L399-L407
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.bulkInsertRecords
public function bulkInsertRecords($tablename, $parameters, $limit = 25) { if(empty($parameters)) throw new DatabaseException('bulkInsertRecords: no parameters.'); $count = 0; $tcount = 0; $totalcount = count($parameters); foreach ($parameters as $value) { if (!is_array($value)) throw new DatabaseException('bulkInsertRecords requires an array of arrays'); if ($count == 0) { $sql = "INSERT INTO ".$tablename." "; $sql .= " (".implode(",", array_keys($value)).")\n VALUES\n "; $first = false; } $sql .= "(".implode(",", array_map(array($this, 'quote'), (array)$value))."),\n"; ++$count; ++$tcount; if ($count == $limit || $tcount == $totalcount) { $sql = substr($sql, 0, -2); $this->write($sql); $count = 0; } } }
php
public function bulkInsertRecords($tablename, $parameters, $limit = 25) { if(empty($parameters)) throw new DatabaseException('bulkInsertRecords: no parameters.'); $count = 0; $tcount = 0; $totalcount = count($parameters); foreach ($parameters as $value) { if (!is_array($value)) throw new DatabaseException('bulkInsertRecords requires an array of arrays'); if ($count == 0) { $sql = "INSERT INTO ".$tablename." "; $sql .= " (".implode(",", array_keys($value)).")\n VALUES\n "; $first = false; } $sql .= "(".implode(",", array_map(array($this, 'quote'), (array)$value))."),\n"; ++$count; ++$tcount; if ($count == $limit || $tcount == $totalcount) { $sql = substr($sql, 0, -2); $this->write($sql); $count = 0; } } }
[ "public", "function", "bulkInsertRecords", "(", "$", "tablename", ",", "$", "parameters", ",", "$", "limit", "=", "25", ")", "{", "if", "(", "empty", "(", "$", "parameters", ")", ")", "throw", "new", "DatabaseException", "(", "'bulkInsertRecords: no parameters.'", ")", ";", "$", "count", "=", "0", ";", "$", "tcount", "=", "0", ";", "$", "totalcount", "=", "count", "(", "$", "parameters", ")", ";", "foreach", "(", "$", "parameters", "as", "$", "value", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "throw", "new", "DatabaseException", "(", "'bulkInsertRecords requires an array of arrays'", ")", ";", "if", "(", "$", "count", "==", "0", ")", "{", "$", "sql", "=", "\"INSERT INTO \"", ".", "$", "tablename", ".", "\" \"", ";", "$", "sql", ".=", "\" (\"", ".", "implode", "(", "\",\"", ",", "array_keys", "(", "$", "value", ")", ")", ".", "\")\\n VALUES\\n \"", ";", "$", "first", "=", "false", ";", "}", "$", "sql", ".=", "\"(\"", ".", "implode", "(", "\",\"", ",", "array_map", "(", "array", "(", "$", "this", ",", "'quote'", ")", ",", "(", "array", ")", "$", "value", ")", ")", ".", "\"),\\n\"", ";", "++", "$", "count", ";", "++", "$", "tcount", ";", "if", "(", "$", "count", "==", "$", "limit", "||", "$", "tcount", "==", "$", "totalcount", ")", "{", "$", "sql", "=", "substr", "(", "$", "sql", ",", "0", ",", "-", "2", ")", ";", "$", "this", "->", "write", "(", "$", "sql", ")", ";", "$", "count", "=", "0", ";", "}", "}", "}" ]
Inserts multiple records utilizing less INSERT statements. This function will execute as many statements as necessary to insert all the data supplied by the array {@link $parameters} inserting {@link $limit} records per statement. {@link $limit} is useful for preventing max query size errors. @param string $tablename Table to insert records @param string $parameters An associative array of rows and columns to insert similar to the results of {@link readAll()} <code> array( 0 => array( 'id' => '1', 'col1' => 'value'), 1 => array( 'id' => '2', 'col1' => 'value'), ... ) </code> @param int $limit The maximum number of records to insert on a single statement, defaults to 25 @return int Number of inserted rows @throws DatabaseException if tablename or parameters array is empty
[ "Inserts", "multiple", "records", "utilizing", "less", "INSERT", "statements", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L518-L549
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.insertRecord
public function insertRecord($tablename, $parameters, $ignore = false) { if (empty($parameters)) throw new DatabaseException('insertRecord: no parameters.'); $insert_fields = array(); $insert_values = array(); foreach ($parameters as $name => $value) { $insert_fields[] = $name; $insert_values[] = $this->quote($value); } $sql = "INSERT ".( $ignore ? "IGNORE " : "") . "INTO ". $tablename . " (" . implode(",", $insert_fields) . ") VALUES (". implode(",", $insert_values) . ")"; return $this->write($sql); }
php
public function insertRecord($tablename, $parameters, $ignore = false) { if (empty($parameters)) throw new DatabaseException('insertRecord: no parameters.'); $insert_fields = array(); $insert_values = array(); foreach ($parameters as $name => $value) { $insert_fields[] = $name; $insert_values[] = $this->quote($value); } $sql = "INSERT ".( $ignore ? "IGNORE " : "") . "INTO ". $tablename . " (" . implode(",", $insert_fields) . ") VALUES (". implode(",", $insert_values) . ")"; return $this->write($sql); }
[ "public", "function", "insertRecord", "(", "$", "tablename", ",", "$", "parameters", ",", "$", "ignore", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "parameters", ")", ")", "throw", "new", "DatabaseException", "(", "'insertRecord: no parameters.'", ")", ";", "$", "insert_fields", "=", "array", "(", ")", ";", "$", "insert_values", "=", "array", "(", ")", ";", "foreach", "(", "$", "parameters", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "insert_fields", "[", "]", "=", "$", "name", ";", "$", "insert_values", "[", "]", "=", "$", "this", "->", "quote", "(", "$", "value", ")", ";", "}", "$", "sql", "=", "\"INSERT \"", ".", "(", "$", "ignore", "?", "\"IGNORE \"", ":", "\"\"", ")", ".", "\"INTO \"", ".", "$", "tablename", ".", "\" (\"", ".", "implode", "(", "\",\"", ",", "$", "insert_fields", ")", ".", "\") VALUES (\"", ".", "implode", "(", "\",\"", ",", "$", "insert_values", ")", ".", "\")\"", ";", "return", "$", "this", "->", "write", "(", "$", "sql", ")", ";", "}" ]
Provides a convenience method for inserting an single row of columns and values into a database table @param string $tablename Table to insert record @param array $parameters Associative array of columns and values, ex. <code> array( 'col1' => 'value of col1', 'col2' => 'value of col2' ) </code> @param boolean $ignore If true, then we'll ignore key conflicts on insert. Default: false @return int Insert id of the record @throws DatabaseException if tablename or parameters array is empty
[ "Provides", "a", "convenience", "method", "for", "inserting", "an", "single", "row", "of", "columns", "and", "values", "into", "a", "database", "table" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L568-L587
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.updateRecord
public function updateRecord($tablename, $parameters, $where) { $update = array(); foreach ($parameters as $name => $value) { $update[] = "$name = " . $this->quote($value) . ""; } $sql = "UPDATE ". $tablename ." SET ". implode(",", $update) . " WHERE " . $where; return $this->write($sql, DatabaseInterface::AFFECTED_ROWS); }
php
public function updateRecord($tablename, $parameters, $where) { $update = array(); foreach ($parameters as $name => $value) { $update[] = "$name = " . $this->quote($value) . ""; } $sql = "UPDATE ". $tablename ." SET ". implode(",", $update) . " WHERE " . $where; return $this->write($sql, DatabaseInterface::AFFECTED_ROWS); }
[ "public", "function", "updateRecord", "(", "$", "tablename", ",", "$", "parameters", ",", "$", "where", ")", "{", "$", "update", "=", "array", "(", ")", ";", "foreach", "(", "$", "parameters", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "update", "[", "]", "=", "\"$name = \"", ".", "$", "this", "->", "quote", "(", "$", "value", ")", ".", "\"\"", ";", "}", "$", "sql", "=", "\"UPDATE \"", ".", "$", "tablename", ".", "\" SET \"", ".", "implode", "(", "\",\"", ",", "$", "update", ")", ".", "\" WHERE \"", ".", "$", "where", ";", "return", "$", "this", "->", "write", "(", "$", "sql", ",", "DatabaseInterface", "::", "AFFECTED_ROWS", ")", ";", "}" ]
Provides convenience method for updating columns on a table for 1 or many records matching a WHERE clause @param string $tablename Table to update @param array $parameters Associative array of columns and values, ex. <code> array( 'col1' => 'value of col1', 'col2' => 'value of col2' ) </code> @param string $where Where clause used to find the records to update, ex. "id = '2'", "title LIKE '%example%' AND status = '2'" @return int Number of affected rows @throws DatabaseException if tablename, parameters, or where clause is empty
[ "Provides", "convenience", "method", "for", "updating", "columns", "on", "a", "table", "for", "1", "or", "many", "records", "matching", "a", "WHERE", "clause" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L607-L618
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.deleteRecord
public function deleteRecord($tablename, $where) { if (!empty($tablename) && !empty($where)) { $sql = "DELETE FROM ".$tablename." WHERE ".$where; return $this->write($sql, DatabaseInterface::AFFECTED_ROWS); } }
php
public function deleteRecord($tablename, $where) { if (!empty($tablename) && !empty($where)) { $sql = "DELETE FROM ".$tablename." WHERE ".$where; return $this->write($sql, DatabaseInterface::AFFECTED_ROWS); } }
[ "public", "function", "deleteRecord", "(", "$", "tablename", ",", "$", "where", ")", "{", "if", "(", "!", "empty", "(", "$", "tablename", ")", "&&", "!", "empty", "(", "$", "where", ")", ")", "{", "$", "sql", "=", "\"DELETE FROM \"", ".", "$", "tablename", ".", "\" WHERE \"", ".", "$", "where", ";", "return", "$", "this", "->", "write", "(", "$", "sql", ",", "DatabaseInterface", "::", "AFFECTED_ROWS", ")", ";", "}", "}" ]
Provides convenience method for deleting records matching a WHERE clause @param string $tablename Table to delete from @param string $where Where clause used to find the records to delete, ex. "id = '2'", "title LIKE '%example%' AND status = '2'" @return int Number of affected rows @throws DatabaseException if tablename or where clause is empty
[ "Provides", "convenience", "method", "for", "deleting", "records", "matching", "a", "WHERE", "clause" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L630-L636
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.quote
public function quote($var) { if(is_null($var) || strtoupper($var) == 'NULL') return 'NULL'; if ($var instanceof Date) $var = $this->DateFactory->toStorageDate($var)->toMySQLDate(); return $this->getConnection()->quote($var); }
php
public function quote($var) { if(is_null($var) || strtoupper($var) == 'NULL') return 'NULL'; if ($var instanceof Date) $var = $this->DateFactory->toStorageDate($var)->toMySQLDate(); return $this->getConnection()->quote($var); }
[ "public", "function", "quote", "(", "$", "var", ")", "{", "if", "(", "is_null", "(", "$", "var", ")", "||", "strtoupper", "(", "$", "var", ")", "==", "'NULL'", ")", "return", "'NULL'", ";", "if", "(", "$", "var", "instanceof", "Date", ")", "$", "var", "=", "$", "this", "->", "DateFactory", "->", "toStorageDate", "(", "$", "var", ")", "->", "toMySQLDate", "(", ")", ";", "return", "$", "this", "->", "getConnection", "(", ")", "->", "quote", "(", "$", "var", ")", ";", "}" ]
Returns escaped value automatically wrapped in single quotes NOTE: Will convert Date types into strings for database entry @param mixed $var Value to escape and quote @return string Escaped and quoted string value ready for a SQL statement
[ "Returns", "escaped", "value", "automatically", "wrapped", "in", "single", "quotes" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L647-L656
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.read
public function read($sql) { $sql = (string)$sql; $conn = $this->getConnection(); $this->Benchmark->start('sql-query'); try { // if(!substr($sql, 0, 4) == 'SHOW') { // // $explain = $conn->query("EXPLAIN ".$sql); // // $explainresults = $explain->fetchAll(PDO::FETCH_ASSOC); // } // $start = microtime(TRUE); $result = $conn->query($sql); // $end = microtime(TRUE); // $totalms = ($end-$start)*1000; // if($totalms > 1 && !empty($explainresults)) { // // foreach($explainresults as $qline) // { // // if(strtolower($qline['select_type']) != 'union result' && strtolower($qline['type']) == 'all') // { // // table scan // $pr = ArrayUtils::arrayToStr($explainresults); // error_log("[SQL] BAD QUERY: TABLE SCAN {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"); // // }else if($qline['rows'] > 5000) { // // // poor index // $pr = ArrayUtils::arrayToStr($explainresults); // error_log("[SQL] BAD QUERY: SCANNED OVER 5000 ROWS {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"); // // } // } // // } // // if($totalms > 1000) { // // if(!empty($explainresults)) { // $pr = ArrayUtils::arrayToStr($explainresults); // $email = "SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"; // } else { // $email = "SQL:\n\n{$sql}\n\nTOTAL TIME:{$totalms}ms\n"; // } // error_log("[SQL] BAD QUERY: TOOK OVER 1 SECOND\n".$email); // // } } catch(PDOException $pe) { $errorMessage = $pe->getMessage(); $this->Logger->debug(array( 'Conn' => $this->connDebugString, 'SQL' => $sql, 'Execution Time (ms)' => $this->Benchmark->end('sql-query'), 'Error' => $errorMessage, )); throw new SQLException($sql, $errorMessage, intVal($pe->getCode())); } $this->Logger->debug(array( 'Conn' => $this->connDebugString, 'SQL' => $sql, 'Execution Time (ms)' => $this->Benchmark->end('sql-query'), 'Rows Returned' => $result->rowCount(), )); unset($sql); unset($conn); return $result; }
php
public function read($sql) { $sql = (string)$sql; $conn = $this->getConnection(); $this->Benchmark->start('sql-query'); try { // if(!substr($sql, 0, 4) == 'SHOW') { // // $explain = $conn->query("EXPLAIN ".$sql); // // $explainresults = $explain->fetchAll(PDO::FETCH_ASSOC); // } // $start = microtime(TRUE); $result = $conn->query($sql); // $end = microtime(TRUE); // $totalms = ($end-$start)*1000; // if($totalms > 1 && !empty($explainresults)) { // // foreach($explainresults as $qline) // { // // if(strtolower($qline['select_type']) != 'union result' && strtolower($qline['type']) == 'all') // { // // table scan // $pr = ArrayUtils::arrayToStr($explainresults); // error_log("[SQL] BAD QUERY: TABLE SCAN {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"); // // }else if($qline['rows'] > 5000) { // // // poor index // $pr = ArrayUtils::arrayToStr($explainresults); // error_log("[SQL] BAD QUERY: SCANNED OVER 5000 ROWS {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"); // // } // } // // } // // if($totalms > 1000) { // // if(!empty($explainresults)) { // $pr = ArrayUtils::arrayToStr($explainresults); // $email = "SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"; // } else { // $email = "SQL:\n\n{$sql}\n\nTOTAL TIME:{$totalms}ms\n"; // } // error_log("[SQL] BAD QUERY: TOOK OVER 1 SECOND\n".$email); // // } } catch(PDOException $pe) { $errorMessage = $pe->getMessage(); $this->Logger->debug(array( 'Conn' => $this->connDebugString, 'SQL' => $sql, 'Execution Time (ms)' => $this->Benchmark->end('sql-query'), 'Error' => $errorMessage, )); throw new SQLException($sql, $errorMessage, intVal($pe->getCode())); } $this->Logger->debug(array( 'Conn' => $this->connDebugString, 'SQL' => $sql, 'Execution Time (ms)' => $this->Benchmark->end('sql-query'), 'Rows Returned' => $result->rowCount(), )); unset($sql); unset($conn); return $result; }
[ "public", "function", "read", "(", "$", "sql", ")", "{", "$", "sql", "=", "(", "string", ")", "$", "sql", ";", "$", "conn", "=", "$", "this", "->", "getConnection", "(", ")", ";", "$", "this", "->", "Benchmark", "->", "start", "(", "'sql-query'", ")", ";", "try", "{", "// if(!substr($sql, 0, 4) == 'SHOW') {", "//", "// $explain = $conn->query(\"EXPLAIN \".$sql);", "//", "// $explainresults = $explain->fetchAll(PDO::FETCH_ASSOC);", "// }", "// $start = microtime(TRUE);", "$", "result", "=", "$", "conn", "->", "query", "(", "$", "sql", ")", ";", "// $end = microtime(TRUE);", "// $totalms = ($end-$start)*1000;", "// if($totalms > 1 && !empty($explainresults)) {", "//", "// foreach($explainresults as $qline)", "// {", "//", "// if(strtolower($qline['select_type']) != 'union result' && strtolower($qline['type']) == 'all')", "// {", "// // table scan", "// $pr = ArrayUtils::arrayToStr($explainresults);", "// error_log(\"[SQL] BAD QUERY: TABLE SCAN {$qline['key']}\\n\".\"SQL:\\n\\n{$sql}\\n\\nEXPLAIN:\\n\\n{$pr}\\n\\nTOTAL TIME:{$totalms}ms\\n\");", "//", "// }else if($qline['rows'] > 5000) {", "//", "// // poor index", "// $pr = ArrayUtils::arrayToStr($explainresults);", "// error_log(\"[SQL] BAD QUERY: SCANNED OVER 5000 ROWS {$qline['key']}\\n\".\"SQL:\\n\\n{$sql}\\n\\nEXPLAIN:\\n\\n{$pr}\\n\\nTOTAL TIME:{$totalms}ms\\n\");", "//", "// }", "// }", "//", "// }", "//", "// if($totalms > 1000) {", "//", "// if(!empty($explainresults)) {", "// $pr = ArrayUtils::arrayToStr($explainresults);", "// $email = \"SQL:\\n\\n{$sql}\\n\\nEXPLAIN:\\n\\n{$pr}\\n\\nTOTAL TIME:{$totalms}ms\\n\";", "// } else {", "// $email = \"SQL:\\n\\n{$sql}\\n\\nTOTAL TIME:{$totalms}ms\\n\";", "// }", "// error_log(\"[SQL] BAD QUERY: TOOK OVER 1 SECOND\\n\".$email);", "//", "// }", "}", "catch", "(", "PDOException", "$", "pe", ")", "{", "$", "errorMessage", "=", "$", "pe", "->", "getMessage", "(", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "array", "(", "'Conn'", "=>", "$", "this", "->", "connDebugString", ",", "'SQL'", "=>", "$", "sql", ",", "'Execution Time (ms)'", "=>", "$", "this", "->", "Benchmark", "->", "end", "(", "'sql-query'", ")", ",", "'Error'", "=>", "$", "errorMessage", ",", ")", ")", ";", "throw", "new", "SQLException", "(", "$", "sql", ",", "$", "errorMessage", ",", "intVal", "(", "$", "pe", "->", "getCode", "(", ")", ")", ")", ";", "}", "$", "this", "->", "Logger", "->", "debug", "(", "array", "(", "'Conn'", "=>", "$", "this", "->", "connDebugString", ",", "'SQL'", "=>", "$", "sql", ",", "'Execution Time (ms)'", "=>", "$", "this", "->", "Benchmark", "->", "end", "(", "'sql-query'", ")", ",", "'Rows Returned'", "=>", "$", "result", "->", "rowCount", "(", ")", ",", ")", ")", ";", "unset", "(", "$", "sql", ")", ";", "unset", "(", "$", "conn", ")", ";", "return", "$", "result", ";", "}" ]
Runs the SQL query in read-only mode from the database @param string $sql The SQL query to run @return PDOStatement The query result @see http://us.php.net/manual/en/pdo.query.php
[ "Runs", "the", "SQL", "query", "in", "read", "-", "only", "mode", "from", "the", "database" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L722-L807
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase.import
public function import($filename) { // TODO: Wrap this in a transaction! if (!file_exists($filename)) { throw new Exception("File not found: $filename"); } $sql_queries = file_get_contents($filename); $sql_queries = $this->_removeRemarks($sql_queries); $sql_queries = StringUtils::smartSplit($sql_queries, ";", "'", "\\'"); foreach ($sql_queries as $sql) { $sql = trim($sql); // Trim newlines so we don't have blank queries if (empty($sql)) continue; $this->write($sql); } }
php
public function import($filename) { // TODO: Wrap this in a transaction! if (!file_exists($filename)) { throw new Exception("File not found: $filename"); } $sql_queries = file_get_contents($filename); $sql_queries = $this->_removeRemarks($sql_queries); $sql_queries = StringUtils::smartSplit($sql_queries, ";", "'", "\\'"); foreach ($sql_queries as $sql) { $sql = trim($sql); // Trim newlines so we don't have blank queries if (empty($sql)) continue; $this->write($sql); } }
[ "public", "function", "import", "(", "$", "filename", ")", "{", "// TODO: Wrap this in a transaction!", "if", "(", "!", "file_exists", "(", "$", "filename", ")", ")", "{", "throw", "new", "Exception", "(", "\"File not found: $filename\"", ")", ";", "}", "$", "sql_queries", "=", "file_get_contents", "(", "$", "filename", ")", ";", "$", "sql_queries", "=", "$", "this", "->", "_removeRemarks", "(", "$", "sql_queries", ")", ";", "$", "sql_queries", "=", "StringUtils", "::", "smartSplit", "(", "$", "sql_queries", ",", "\";\"", ",", "\"'\"", ",", "\"\\\\'\"", ")", ";", "foreach", "(", "$", "sql_queries", "as", "$", "sql", ")", "{", "$", "sql", "=", "trim", "(", "$", "sql", ")", ";", "// Trim newlines so we don't have blank queries", "if", "(", "empty", "(", "$", "sql", ")", ")", "continue", ";", "$", "this", "->", "write", "(", "$", "sql", ")", ";", "}", "}" ]
Imports and runs sql contained in the specified file. The file must contain only valid sql. @param string $filename The filename to load @return void
[ "Imports", "and", "runs", "sql", "contained", "in", "the", "specified", "file", ".", "The", "file", "must", "contain", "only", "valid", "sql", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L867-L884
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/MySQLDatabase.php
MySQLDatabase._removeRemarks
private function _removeRemarks($sql) { $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql)); $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql)); return $sql; }
php
private function _removeRemarks($sql) { $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql)); $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql)); return $sql; }
[ "private", "function", "_removeRemarks", "(", "$", "sql", ")", "{", "$", "sql", "=", "preg_replace", "(", "'/\\n{2,}/'", ",", "\"\\n\"", ",", "preg_replace", "(", "'/^[-].*$/m'", ",", "\"\\n\"", ",", "$", "sql", ")", ")", ";", "$", "sql", "=", "preg_replace", "(", "'/\\n{2,}/'", ",", "\"\\n\"", ",", "preg_replace", "(", "'/^#.*$/m'", ",", "\"\\n\"", ",", "$", "sql", ")", ")", ";", "return", "$", "sql", ";", "}" ]
remove_remarks will strip the sql comment lines out of an uploaded sql file @param string $sql The sql to process @return string the SQL with the remarks removed
[ "remove_remarks", "will", "strip", "the", "sql", "comment", "lines", "out", "of", "an", "uploaded", "sql", "file" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/MySQLDatabase.php#L893-L898
train
mossphp/moss-storage
Moss/Storage/Query/Accessor/Accessor.php
Accessor.identifyEntity
public function identifyEntity(ModelInterface $model, &$entity, $identifier) { $primaryKeys = $model->primaryFields(); if (count($primaryKeys) !== 1) { return; } $field = reset($primaryKeys)->name(); $this->setPropertyValue($entity, $field, $identifier); }
php
public function identifyEntity(ModelInterface $model, &$entity, $identifier) { $primaryKeys = $model->primaryFields(); if (count($primaryKeys) !== 1) { return; } $field = reset($primaryKeys)->name(); $this->setPropertyValue($entity, $field, $identifier); }
[ "public", "function", "identifyEntity", "(", "ModelInterface", "$", "model", ",", "&", "$", "entity", ",", "$", "identifier", ")", "{", "$", "primaryKeys", "=", "$", "model", "->", "primaryFields", "(", ")", ";", "if", "(", "count", "(", "$", "primaryKeys", ")", "!==", "1", ")", "{", "return", ";", "}", "$", "field", "=", "reset", "(", "$", "primaryKeys", ")", "->", "name", "(", ")", ";", "$", "this", "->", "setPropertyValue", "(", "$", "entity", ",", "$", "field", ",", "$", "identifier", ")", ";", "}" ]
Assigns passed identifier to primary key Possible only when entity has one primary key @param ModelInterface $model @param mixed $entity @param int|string $identifier @return void
[ "Assigns", "passed", "identifier", "to", "primary", "key", "Possible", "only", "when", "entity", "has", "one", "primary", "key" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Accessor/Accessor.php#L36-L46
train
mossphp/moss-storage
Moss/Storage/Query/Accessor/Accessor.php
Accessor.getPropertyValue
public function getPropertyValue($entity, $field, $default = null) { $this->assertEntity($entity); if (is_array($entity) || $entity instanceof \ArrayAccess) { return isset($entity[$field]) ? $entity[$field] : $default; } $ref = $this->getReflection($entity); if (!$ref->hasProperty($field)) { return isset($entity->{$field}) ? $entity->{$field} : $default; } return $this->getProperty($ref, $field)->getValue($entity); }
php
public function getPropertyValue($entity, $field, $default = null) { $this->assertEntity($entity); if (is_array($entity) || $entity instanceof \ArrayAccess) { return isset($entity[$field]) ? $entity[$field] : $default; } $ref = $this->getReflection($entity); if (!$ref->hasProperty($field)) { return isset($entity->{$field}) ? $entity->{$field} : $default; } return $this->getProperty($ref, $field)->getValue($entity); }
[ "public", "function", "getPropertyValue", "(", "$", "entity", ",", "$", "field", ",", "$", "default", "=", "null", ")", "{", "$", "this", "->", "assertEntity", "(", "$", "entity", ")", ";", "if", "(", "is_array", "(", "$", "entity", ")", "||", "$", "entity", "instanceof", "\\", "ArrayAccess", ")", "{", "return", "isset", "(", "$", "entity", "[", "$", "field", "]", ")", "?", "$", "entity", "[", "$", "field", "]", ":", "$", "default", ";", "}", "$", "ref", "=", "$", "this", "->", "getReflection", "(", "$", "entity", ")", ";", "if", "(", "!", "$", "ref", "->", "hasProperty", "(", "$", "field", ")", ")", "{", "return", "isset", "(", "$", "entity", "->", "{", "$", "field", "}", ")", "?", "$", "entity", "->", "{", "$", "field", "}", ":", "$", "default", ";", "}", "return", "$", "this", "->", "getProperty", "(", "$", "ref", ",", "$", "field", ")", "->", "getValue", "(", "$", "entity", ")", ";", "}" ]
Returns property value @param array|object $entity @param string $field @param mixed $default @return mixed @throws AccessorException
[ "Returns", "property", "value" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Accessor/Accessor.php#L58-L72
train
mossphp/moss-storage
Moss/Storage/Query/Accessor/Accessor.php
Accessor.setPropertyValue
public function setPropertyValue(&$entity, $field, $value) { $this->assertEntity($entity); if (is_array($entity) || $entity instanceof \ArrayAccess) { $entity[$field] = $value; return; } $ref = $this->getReflection($entity); if (!$ref->hasProperty($field)) { $entity->{$field} = $value; return; } $this->getProperty($ref, $field)->setValue($entity, $value); }
php
public function setPropertyValue(&$entity, $field, $value) { $this->assertEntity($entity); if (is_array($entity) || $entity instanceof \ArrayAccess) { $entity[$field] = $value; return; } $ref = $this->getReflection($entity); if (!$ref->hasProperty($field)) { $entity->{$field} = $value; return; } $this->getProperty($ref, $field)->setValue($entity, $value); }
[ "public", "function", "setPropertyValue", "(", "&", "$", "entity", ",", "$", "field", ",", "$", "value", ")", "{", "$", "this", "->", "assertEntity", "(", "$", "entity", ")", ";", "if", "(", "is_array", "(", "$", "entity", ")", "||", "$", "entity", "instanceof", "\\", "ArrayAccess", ")", "{", "$", "entity", "[", "$", "field", "]", "=", "$", "value", ";", "return", ";", "}", "$", "ref", "=", "$", "this", "->", "getReflection", "(", "$", "entity", ")", ";", "if", "(", "!", "$", "ref", "->", "hasProperty", "(", "$", "field", ")", ")", "{", "$", "entity", "->", "{", "$", "field", "}", "=", "$", "value", ";", "return", ";", "}", "$", "this", "->", "getProperty", "(", "$", "ref", ",", "$", "field", ")", "->", "setValue", "(", "$", "entity", ",", "$", "value", ")", ";", "}" ]
Sets property value @param array|object $entity @param string $field @param mixed $value @throws AccessorException
[ "Sets", "property", "value" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Accessor/Accessor.php#L83-L101
train
mossphp/moss-storage
Moss/Storage/Query/Accessor/Accessor.php
Accessor.getReflection
private function getReflection($object) { $key = get_class($object); if (!array_key_exists($key, $this->buffer)) { $this->buffer[$key] = new \ReflectionClass($object); } return $this->buffer[$key]; }
php
private function getReflection($object) { $key = get_class($object); if (!array_key_exists($key, $this->buffer)) { $this->buffer[$key] = new \ReflectionClass($object); } return $this->buffer[$key]; }
[ "private", "function", "getReflection", "(", "$", "object", ")", "{", "$", "key", "=", "get_class", "(", "$", "object", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "buffer", ")", ")", "{", "$", "this", "->", "buffer", "[", "$", "key", "]", "=", "new", "\\", "ReflectionClass", "(", "$", "object", ")", ";", "}", "return", "$", "this", "->", "buffer", "[", "$", "key", "]", ";", "}" ]
Returns object reflection instance @param object $object @return \ReflectionClass
[ "Returns", "object", "reflection", "instance" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Accessor/Accessor.php#L124-L133
train
mossphp/moss-storage
Moss/Storage/Query/Accessor/Accessor.php
Accessor.getProperty
private function getProperty(\ReflectionClass $ref, $property) { $prop = $ref->getProperty($property); $prop->setAccessible(true); return $prop; }
php
private function getProperty(\ReflectionClass $ref, $property) { $prop = $ref->getProperty($property); $prop->setAccessible(true); return $prop; }
[ "private", "function", "getProperty", "(", "\\", "ReflectionClass", "$", "ref", ",", "$", "property", ")", "{", "$", "prop", "=", "$", "ref", "->", "getProperty", "(", "$", "property", ")", ";", "$", "prop", "->", "setAccessible", "(", "true", ")", ";", "return", "$", "prop", ";", "}" ]
Returns object property instance @param \ReflectionClass $ref @param string $property @return \ReflectionProperty
[ "Returns", "object", "property", "instance" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Accessor/Accessor.php#L143-L149
train
mossphp/moss-storage
Moss/Storage/Query/Accessor/Accessor.php
Accessor.addPropertyValue
public function addPropertyValue(&$entity, $field, $value) { $container = $this->getPropertyValue($entity, $field, $entity); if (!is_array($container)) { $container = empty($container) ? [] : [$container]; } $container[] = $value; $this->setPropertyValue($entity, $field, $container); }
php
public function addPropertyValue(&$entity, $field, $value) { $container = $this->getPropertyValue($entity, $field, $entity); if (!is_array($container)) { $container = empty($container) ? [] : [$container]; } $container[] = $value; $this->setPropertyValue($entity, $field, $container); }
[ "public", "function", "addPropertyValue", "(", "&", "$", "entity", ",", "$", "field", ",", "$", "value", ")", "{", "$", "container", "=", "$", "this", "->", "getPropertyValue", "(", "$", "entity", ",", "$", "field", ",", "$", "entity", ")", ";", "if", "(", "!", "is_array", "(", "$", "container", ")", ")", "{", "$", "container", "=", "empty", "(", "$", "container", ")", "?", "[", "]", ":", "[", "$", "container", "]", ";", "}", "$", "container", "[", "]", "=", "$", "value", ";", "$", "this", "->", "setPropertyValue", "(", "$", "entity", ",", "$", "field", ",", "$", "container", ")", ";", "}" ]
Adds value to array property If property is not an array - will be converted into one preserving existing value as first element @param mixed $entity @param string $field @param mixed $value @throws AccessorException
[ "Adds", "value", "to", "array", "property", "If", "property", "is", "not", "an", "array", "-", "will", "be", "converted", "into", "one", "preserving", "existing", "value", "as", "first", "element" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Accessor/Accessor.php#L161-L171
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.getTableAlias
public function getTableAlias($table_name = null) { if (!$table_name) { $table_name = $this->getTableName(); } $bits = explode("_", $table_name); $alias = ''; foreach ($bits as $bit) { $alias .= strtolower(substr($bit, 0, 1)); } return $alias; }
php
public function getTableAlias($table_name = null) { if (!$table_name) { $table_name = $this->getTableName(); } $bits = explode("_", $table_name); $alias = ''; foreach ($bits as $bit) { $alias .= strtolower(substr($bit, 0, 1)); } return $alias; }
[ "public", "function", "getTableAlias", "(", "$", "table_name", "=", "null", ")", "{", "if", "(", "!", "$", "table_name", ")", "{", "$", "table_name", "=", "$", "this", "->", "getTableName", "(", ")", ";", "}", "$", "bits", "=", "explode", "(", "\"_\"", ",", "$", "table_name", ")", ";", "$", "alias", "=", "''", ";", "foreach", "(", "$", "bits", "as", "$", "bit", ")", "{", "$", "alias", ".=", "strtolower", "(", "substr", "(", "$", "bit", ",", "0", ",", "1", ")", ")", ";", "}", "return", "$", "alias", ";", "}" ]
Get the short alias name of a table. @param string $table_name Optional table name @return string Table alias
[ "Get", "the", "short", "alias", "name", "of", "a", "table", "." ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L97-L108
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.getTablePrimaryKey
public function getTablePrimaryKey() { trigger_error('getTablePrimaryKey() is deprecated. Use getIDField() instead.', E_USER_DEPRECATED); $keys = $this->getPrimaryKeyIndex(); return isset($keys[0])?$keys[0]:false; }
php
public function getTablePrimaryKey() { trigger_error('getTablePrimaryKey() is deprecated. Use getIDField() instead.', E_USER_DEPRECATED); $keys = $this->getPrimaryKeyIndex(); return isset($keys[0])?$keys[0]:false; }
[ "public", "function", "getTablePrimaryKey", "(", ")", "{", "trigger_error", "(", "'getTablePrimaryKey() is deprecated. Use getIDField() instead.'", ",", "E_USER_DEPRECATED", ")", ";", "$", "keys", "=", "$", "this", "->", "getPrimaryKeyIndex", "(", ")", ";", "return", "isset", "(", "$", "keys", "[", "0", "]", ")", "?", "$", "keys", "[", "0", "]", ":", "false", ";", "}" ]
Get table primary key column name @deprecated @return string|false
[ "Get", "table", "primary", "key", "column", "name" ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L126-L132
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.getPrimaryKeyIndex
public function getPrimaryKeyIndex() { $database = DatabaseLayer::getInstance(); $columns = array(); if ($this instanceof VersionedActiveRecord) { $schema = $this->getClassSchema(); $firstColumn = reset($schema)['name']; $columns = [$firstColumn => $firstColumn, "sequence" => "sequence"]; } else { foreach ($database->getTableIndexes($this->_table) as $key) { $columns[$key->Column_name] = $key->Column_name; } } return array_values($columns); }
php
public function getPrimaryKeyIndex() { $database = DatabaseLayer::getInstance(); $columns = array(); if ($this instanceof VersionedActiveRecord) { $schema = $this->getClassSchema(); $firstColumn = reset($schema)['name']; $columns = [$firstColumn => $firstColumn, "sequence" => "sequence"]; } else { foreach ($database->getTableIndexes($this->_table) as $key) { $columns[$key->Column_name] = $key->Column_name; } } return array_values($columns); }
[ "public", "function", "getPrimaryKeyIndex", "(", ")", "{", "$", "database", "=", "DatabaseLayer", "::", "getInstance", "(", ")", ";", "$", "columns", "=", "array", "(", ")", ";", "if", "(", "$", "this", "instanceof", "VersionedActiveRecord", ")", "{", "$", "schema", "=", "$", "this", "->", "getClassSchema", "(", ")", ";", "$", "firstColumn", "=", "reset", "(", "$", "schema", ")", "[", "'name'", "]", ";", "$", "columns", "=", "[", "$", "firstColumn", "=>", "$", "firstColumn", ",", "\"sequence\"", "=>", "\"sequence\"", "]", ";", "}", "else", "{", "foreach", "(", "$", "database", "->", "getTableIndexes", "(", "$", "this", "->", "_table", ")", "as", "$", "key", ")", "{", "$", "columns", "[", "$", "key", "->", "Column_name", "]", "=", "$", "key", "->", "Column_name", ";", "}", "}", "return", "array_values", "(", "$", "columns", ")", ";", "}" ]
Get a unique key to use as an index @return string[]
[ "Get", "a", "unique", "key", "to", "use", "as", "an", "index" ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L139-L156
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.getId
public function getId() { $col = $this->getIDField(); if (property_exists($this, $col)) { $id = $this->$col; if ($id > 0) { return $id; } } return false; }
php
public function getId() { $col = $this->getIDField(); if (property_exists($this, $col)) { $id = $this->$col; if ($id > 0) { return $id; } } return false; }
[ "public", "function", "getId", "(", ")", "{", "$", "col", "=", "$", "this", "->", "getIDField", "(", ")", ";", "if", "(", "property_exists", "(", "$", "this", ",", "$", "col", ")", ")", "{", "$", "id", "=", "$", "this", "->", "$", "col", ";", "if", "(", "$", "id", ">", "0", ")", "{", "return", "$", "id", ";", "}", "}", "return", "false", ";", "}" ]
Get object ID @return integer
[ "Get", "object", "ID" ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L162-L173
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.getLabel
public function getLabel() { if (property_exists($this, '_label_column')) { if (property_exists($this, $this->_label_column)) { $label_column = $this->_label_column; return $this->$label_column; } } if (property_exists($this, 'name')) { return $this->name; } if (property_exists($this, 'description')) { return $this->description; } return "No label for " . get_called_class() . " ID " . $this->getId(); }
php
public function getLabel() { if (property_exists($this, '_label_column')) { if (property_exists($this, $this->_label_column)) { $label_column = $this->_label_column; return $this->$label_column; } } if (property_exists($this, 'name')) { return $this->name; } if (property_exists($this, 'description')) { return $this->description; } return "No label for " . get_called_class() . " ID " . $this->getId(); }
[ "public", "function", "getLabel", "(", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "'_label_column'", ")", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "$", "this", "->", "_label_column", ")", ")", "{", "$", "label_column", "=", "$", "this", "->", "_label_column", ";", "return", "$", "this", "->", "$", "label_column", ";", "}", "}", "if", "(", "property_exists", "(", "$", "this", ",", "'name'", ")", ")", "{", "return", "$", "this", "->", "name", ";", "}", "if", "(", "property_exists", "(", "$", "this", ",", "'description'", ")", ")", "{", "return", "$", "this", "->", "description", ";", "}", "return", "\"No label for \"", ".", "get_called_class", "(", ")", ".", "\" ID \"", ".", "$", "this", "->", "getId", "(", ")", ";", "}" ]
Get a label for the object. Perhaps a Name or Description field. @return string
[ "Get", "a", "label", "for", "the", "object", ".", "Perhaps", "a", "Name", "or", "Description", "field", "." ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L179-L194
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.__calculateSaveDownRows
public function __calculateSaveDownRows() { if (!$this->_columns) { foreach (get_object_vars($this) as $potential_column => $discard) { switch ($potential_column) { case 'table': case substr($potential_column, 0, 1) == "_": // Not a valid column break; default: $this->_columns[] = $potential_column; break; } } } // reorder the columns to match get_class_schema //TODO: Write test to verify that this works right. foreach ($this->getClassSchema() as $schemaKey => $dontCare) { if (in_array($schemaKey, $this->_columns)) { $sortedColumns[$schemaKey] = $schemaKey; } } foreach ($this->_columns as $column) { if (!isset($sortedColumns[$column])) { $class_name = get_called_class(); throw new Exception("No type hinting/docblock found for '{$column}' in '{$class_name}'.", E_USER_WARNING); } } $this->_columns = array_values($sortedColumns); // Return sorted columns. return $this->_columns; }
php
public function __calculateSaveDownRows() { if (!$this->_columns) { foreach (get_object_vars($this) as $potential_column => $discard) { switch ($potential_column) { case 'table': case substr($potential_column, 0, 1) == "_": // Not a valid column break; default: $this->_columns[] = $potential_column; break; } } } // reorder the columns to match get_class_schema //TODO: Write test to verify that this works right. foreach ($this->getClassSchema() as $schemaKey => $dontCare) { if (in_array($schemaKey, $this->_columns)) { $sortedColumns[$schemaKey] = $schemaKey; } } foreach ($this->_columns as $column) { if (!isset($sortedColumns[$column])) { $class_name = get_called_class(); throw new Exception("No type hinting/docblock found for '{$column}' in '{$class_name}'.", E_USER_WARNING); } } $this->_columns = array_values($sortedColumns); // Return sorted columns. return $this->_columns; }
[ "public", "function", "__calculateSaveDownRows", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_columns", ")", "{", "foreach", "(", "get_object_vars", "(", "$", "this", ")", "as", "$", "potential_column", "=>", "$", "discard", ")", "{", "switch", "(", "$", "potential_column", ")", "{", "case", "'table'", ":", "case", "substr", "(", "$", "potential_column", ",", "0", ",", "1", ")", "==", "\"_\"", ":", "// Not a valid column", "break", ";", "default", ":", "$", "this", "->", "_columns", "[", "]", "=", "$", "potential_column", ";", "break", ";", "}", "}", "}", "// reorder the columns to match get_class_schema", "//TODO: Write test to verify that this works right.", "foreach", "(", "$", "this", "->", "getClassSchema", "(", ")", "as", "$", "schemaKey", "=>", "$", "dontCare", ")", "{", "if", "(", "in_array", "(", "$", "schemaKey", ",", "$", "this", "->", "_columns", ")", ")", "{", "$", "sortedColumns", "[", "$", "schemaKey", "]", "=", "$", "schemaKey", ";", "}", "}", "foreach", "(", "$", "this", "->", "_columns", "as", "$", "column", ")", "{", "if", "(", "!", "isset", "(", "$", "sortedColumns", "[", "$", "column", "]", ")", ")", "{", "$", "class_name", "=", "get_called_class", "(", ")", ";", "throw", "new", "Exception", "(", "\"No type hinting/docblock found for '{$column}' in '{$class_name}'.\"", ",", "E_USER_WARNING", ")", ";", "}", "}", "$", "this", "->", "_columns", "=", "array_values", "(", "$", "sortedColumns", ")", ";", "// Return sorted columns.", "return", "$", "this", "->", "_columns", ";", "}" ]
Work out which columns should be saved down.
[ "Work", "out", "which", "columns", "should", "be", "saved", "down", "." ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L199-L233
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.save
public function save($automatic_reload = true) { // Run Pre-saver. $this->preSave(); // Run Field Fixer. $this->__fieldFix(); // Calculate row to save_down $this->__calculateSaveDownRows(); $primary_key_column = $this->getIDField(); // Make an array out of the objects columns. $data = array(); foreach ($this->_columns as $column) { // Never update the primary key. Bad bad bad. Except if we're versioned. if ($column != $primary_key_column || $this instanceof VersionedActiveRecord || $this->_force_insert ) { $data["`{$column}`"] = $this->$column; } } // If we already have an ID, this is an update. $database = DatabaseLayer::getInstance(); if (!$this->getId() || (property_exists($this, '_is_versioned') && $this->_is_versioned == true) || $this->_force_insert ) { $operation = $database->insert($this->getTableName(), $this->getTableAlias()); $this->_force_insert = false; } else { // Else, we're an insert. $operation = $database->update($this->getTableName(), $this->getTableAlias()); } $operation->setData($data); if ($this->getId() && $primary_key_column) { $operation->condition($primary_key_column, $this->$primary_key_column); $operation->execute(); } else { // Else, we're an insert. $new_id = $operation->execute($this->getClass()); if ($primary_key_column) { $this->$primary_key_column = $new_id; } } // Expire cache. if (DatabaseLayer::getInstance()->useCache()) { $cache = DatabaseLayer::getInstance()->getCache(); $cache->delete($this->getCacheIdentifier()); } // Expire any existing copy of this object. SearchIndex::getInstance()->expire(get_called_class() . "/" . $this->getTableName(), $this->getId()); if ($automatic_reload && $primary_key_column) { $this->reload(); } // Run Post Save. $this->postSave(); // Return object. Should this return true/false based on success instead? return $this; }
php
public function save($automatic_reload = true) { // Run Pre-saver. $this->preSave(); // Run Field Fixer. $this->__fieldFix(); // Calculate row to save_down $this->__calculateSaveDownRows(); $primary_key_column = $this->getIDField(); // Make an array out of the objects columns. $data = array(); foreach ($this->_columns as $column) { // Never update the primary key. Bad bad bad. Except if we're versioned. if ($column != $primary_key_column || $this instanceof VersionedActiveRecord || $this->_force_insert ) { $data["`{$column}`"] = $this->$column; } } // If we already have an ID, this is an update. $database = DatabaseLayer::getInstance(); if (!$this->getId() || (property_exists($this, '_is_versioned') && $this->_is_versioned == true) || $this->_force_insert ) { $operation = $database->insert($this->getTableName(), $this->getTableAlias()); $this->_force_insert = false; } else { // Else, we're an insert. $operation = $database->update($this->getTableName(), $this->getTableAlias()); } $operation->setData($data); if ($this->getId() && $primary_key_column) { $operation->condition($primary_key_column, $this->$primary_key_column); $operation->execute(); } else { // Else, we're an insert. $new_id = $operation->execute($this->getClass()); if ($primary_key_column) { $this->$primary_key_column = $new_id; } } // Expire cache. if (DatabaseLayer::getInstance()->useCache()) { $cache = DatabaseLayer::getInstance()->getCache(); $cache->delete($this->getCacheIdentifier()); } // Expire any existing copy of this object. SearchIndex::getInstance()->expire(get_called_class() . "/" . $this->getTableName(), $this->getId()); if ($automatic_reload && $primary_key_column) { $this->reload(); } // Run Post Save. $this->postSave(); // Return object. Should this return true/false based on success instead? return $this; }
[ "public", "function", "save", "(", "$", "automatic_reload", "=", "true", ")", "{", "// Run Pre-saver.", "$", "this", "->", "preSave", "(", ")", ";", "// Run Field Fixer.", "$", "this", "->", "__fieldFix", "(", ")", ";", "// Calculate row to save_down", "$", "this", "->", "__calculateSaveDownRows", "(", ")", ";", "$", "primary_key_column", "=", "$", "this", "->", "getIDField", "(", ")", ";", "// Make an array out of the objects columns.", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_columns", "as", "$", "column", ")", "{", "// Never update the primary key. Bad bad bad. Except if we're versioned.", "if", "(", "$", "column", "!=", "$", "primary_key_column", "||", "$", "this", "instanceof", "VersionedActiveRecord", "||", "$", "this", "->", "_force_insert", ")", "{", "$", "data", "[", "\"`{$column}`\"", "]", "=", "$", "this", "->", "$", "column", ";", "}", "}", "// If we already have an ID, this is an update.", "$", "database", "=", "DatabaseLayer", "::", "getInstance", "(", ")", ";", "if", "(", "!", "$", "this", "->", "getId", "(", ")", "||", "(", "property_exists", "(", "$", "this", ",", "'_is_versioned'", ")", "&&", "$", "this", "->", "_is_versioned", "==", "true", ")", "||", "$", "this", "->", "_force_insert", ")", "{", "$", "operation", "=", "$", "database", "->", "insert", "(", "$", "this", "->", "getTableName", "(", ")", ",", "$", "this", "->", "getTableAlias", "(", ")", ")", ";", "$", "this", "->", "_force_insert", "=", "false", ";", "}", "else", "{", "// Else, we're an insert.", "$", "operation", "=", "$", "database", "->", "update", "(", "$", "this", "->", "getTableName", "(", ")", ",", "$", "this", "->", "getTableAlias", "(", ")", ")", ";", "}", "$", "operation", "->", "setData", "(", "$", "data", ")", ";", "if", "(", "$", "this", "->", "getId", "(", ")", "&&", "$", "primary_key_column", ")", "{", "$", "operation", "->", "condition", "(", "$", "primary_key_column", ",", "$", "this", "->", "$", "primary_key_column", ")", ";", "$", "operation", "->", "execute", "(", ")", ";", "}", "else", "{", "// Else, we're an insert.", "$", "new_id", "=", "$", "operation", "->", "execute", "(", "$", "this", "->", "getClass", "(", ")", ")", ";", "if", "(", "$", "primary_key_column", ")", "{", "$", "this", "->", "$", "primary_key_column", "=", "$", "new_id", ";", "}", "}", "// Expire cache.", "if", "(", "DatabaseLayer", "::", "getInstance", "(", ")", "->", "useCache", "(", ")", ")", "{", "$", "cache", "=", "DatabaseLayer", "::", "getInstance", "(", ")", "->", "getCache", "(", ")", ";", "$", "cache", "->", "delete", "(", "$", "this", "->", "getCacheIdentifier", "(", ")", ")", ";", "}", "// Expire any existing copy of this object.", "SearchIndex", "::", "getInstance", "(", ")", "->", "expire", "(", "get_called_class", "(", ")", ".", "\"/\"", ".", "$", "this", "->", "getTableName", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "if", "(", "$", "automatic_reload", "&&", "$", "primary_key_column", ")", "{", "$", "this", "->", "reload", "(", ")", ";", "}", "// Run Post Save.", "$", "this", "->", "postSave", "(", ")", ";", "// Return object. Should this return true/false based on success instead?", "return", "$", "this", ";", "}" ]
Save the selected record. This will do an INSERT or UPDATE as appropriate @param boolean $automatic_reload Whether or not to automatically reload @return ActiveRecord
[ "Save", "the", "selected", "record", ".", "This", "will", "do", "an", "INSERT", "or", "UPDATE", "as", "appropriate" ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L283-L349
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.reload
public function reload() { $item = $this->getById($this->getId()); if ($item !== false) { $this->loadFromRow($item); return $this; } else { return false; } }
php
public function reload() { $item = $this->getById($this->getId()); if ($item !== false) { $this->loadFromRow($item); return $this; } else { return false; } }
[ "public", "function", "reload", "(", ")", "{", "$", "item", "=", "$", "this", "->", "getById", "(", "$", "this", "->", "getId", "(", ")", ")", ";", "if", "(", "$", "item", "!==", "false", ")", "{", "$", "this", "->", "loadFromRow", "(", "$", "item", ")", ";", "return", "$", "this", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Reload the selected record @return ActiveRecord|false
[ "Reload", "the", "selected", "record" ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L355-L364
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.delete
public function delete() { $database = DatabaseLayer::getInstance(); $delete = $database->delete($this->getTableName(), $this->getTableAlias()); $delete->setModel($this); $delete->condition($this->getIDField(), $this->getId()); $delete->execute($this->getClass()); // Invalidate cache. SearchIndex::getInstance()->expire($this->getTableName(), $this->getId()); return true; }
php
public function delete() { $database = DatabaseLayer::getInstance(); $delete = $database->delete($this->getTableName(), $this->getTableAlias()); $delete->setModel($this); $delete->condition($this->getIDField(), $this->getId()); $delete->execute($this->getClass()); // Invalidate cache. SearchIndex::getInstance()->expire($this->getTableName(), $this->getId()); return true; }
[ "public", "function", "delete", "(", ")", "{", "$", "database", "=", "DatabaseLayer", "::", "getInstance", "(", ")", ";", "$", "delete", "=", "$", "database", "->", "delete", "(", "$", "this", "->", "getTableName", "(", ")", ",", "$", "this", "->", "getTableAlias", "(", ")", ")", ";", "$", "delete", "->", "setModel", "(", "$", "this", ")", ";", "$", "delete", "->", "condition", "(", "$", "this", "->", "getIDField", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "$", "delete", "->", "execute", "(", "$", "this", "->", "getClass", "(", ")", ")", ";", "// Invalidate cache.", "SearchIndex", "::", "getInstance", "(", ")", "->", "expire", "(", "$", "this", "->", "getTableName", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "return", "true", ";", "}" ]
Delete the selected record @return boolean
[ "Delete", "the", "selected", "record" ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L369-L382
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.getBySlug
public static function getBySlug($slug) { $slug_parts = explode("-", $slug, 2); $class = get_called_class(); $temp_this = new $class(); $primary_key = $temp_this->getIDField(); return self::search()->where($primary_key, $slug_parts[0])->execOne(); }
php
public static function getBySlug($slug) { $slug_parts = explode("-", $slug, 2); $class = get_called_class(); $temp_this = new $class(); $primary_key = $temp_this->getIDField(); return self::search()->where($primary_key, $slug_parts[0])->execOne(); }
[ "public", "static", "function", "getBySlug", "(", "$", "slug", ")", "{", "$", "slug_parts", "=", "explode", "(", "\"-\"", ",", "$", "slug", ",", "2", ")", ";", "$", "class", "=", "get_called_class", "(", ")", ";", "$", "temp_this", "=", "new", "$", "class", "(", ")", ";", "$", "primary_key", "=", "$", "temp_this", "->", "getIDField", "(", ")", ";", "return", "self", "::", "search", "(", ")", "->", "where", "(", "$", "primary_key", ",", "$", "slug_parts", "[", "0", "]", ")", "->", "execOne", "(", ")", ";", "}" ]
Pull a database record by the slug we're given. @param $slug string Slug @return mixed
[ "Pull", "a", "database", "record", "by", "the", "slug", "we", "re", "given", "." ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L430-L437
train
Thruio/ActiveRecord
src/ActiveRecord.php
ActiveRecord.__fieldFix
public function __fieldFix() { $schema = $this->getClassSchema(); foreach ($this->__calculateSaveDownRows() as $column) { if (!isset($schema[$column]['type'])) { throw new Exception("No type hinting/docblock found for '{$column}' in '" . get_called_class() . "'.", E_USER_WARNING); } $type = $schema[$column]['type']; if ($type == "integer" && !is_int($this->$column)) { $this->$column = intval($this->$column); } } return true; }
php
public function __fieldFix() { $schema = $this->getClassSchema(); foreach ($this->__calculateSaveDownRows() as $column) { if (!isset($schema[$column]['type'])) { throw new Exception("No type hinting/docblock found for '{$column}' in '" . get_called_class() . "'.", E_USER_WARNING); } $type = $schema[$column]['type']; if ($type == "integer" && !is_int($this->$column)) { $this->$column = intval($this->$column); } } return true; }
[ "public", "function", "__fieldFix", "(", ")", "{", "$", "schema", "=", "$", "this", "->", "getClassSchema", "(", ")", ";", "foreach", "(", "$", "this", "->", "__calculateSaveDownRows", "(", ")", "as", "$", "column", ")", "{", "if", "(", "!", "isset", "(", "$", "schema", "[", "$", "column", "]", "[", "'type'", "]", ")", ")", "{", "throw", "new", "Exception", "(", "\"No type hinting/docblock found for '{$column}' in '\"", ".", "get_called_class", "(", ")", ".", "\"'.\"", ",", "E_USER_WARNING", ")", ";", "}", "$", "type", "=", "$", "schema", "[", "$", "column", "]", "[", "'type'", "]", ";", "if", "(", "$", "type", "==", "\"integer\"", "&&", "!", "is_int", "(", "$", "this", "->", "$", "column", ")", ")", "{", "$", "this", "->", "$", "column", "=", "intval", "(", "$", "this", "->", "$", "column", ")", ";", "}", "}", "return", "true", ";", "}" ]
Fix types of fields to match definition
[ "Fix", "types", "of", "fields", "to", "match", "definition" ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/ActiveRecord.php#L500-L514
train
ingro/Rest
src/Ingruz/Rest/Controllers/RestDingoController.php
RestDingoController.respondNotFound
protected function respondNotFound($message = '') { if (empty($message)) { $message = ucfirst($this->baseClass).' does not exist'; } return $this->respondWithError($message, 404); }
php
protected function respondNotFound($message = '') { if (empty($message)) { $message = ucfirst($this->baseClass).' does not exist'; } return $this->respondWithError($message, 404); }
[ "protected", "function", "respondNotFound", "(", "$", "message", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "message", ")", ")", "{", "$", "message", "=", "ucfirst", "(", "$", "this", "->", "baseClass", ")", ".", "' does not exist'", ";", "}", "return", "$", "this", "->", "respondWithError", "(", "$", "message", ",", "404", ")", ";", "}" ]
Respond with an error in case the resource request is not found @param string $message @return Response
[ "Respond", "with", "an", "error", "in", "case", "the", "resource", "request", "is", "not", "found" ]
922bed071b8ea41feb067d97a3e283f944a86cb8
https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Controllers/RestDingoController.php#L165-L173
train
phossa/phossa-shared
src/Phossa/Shared/Message/Loader/LanguageLoader.php
LanguageLoader.loadMessages
public function loadMessages(/*# string */ $className)/*# : array */ { $map = []; // reflect if (class_exists($className)) { $class = new \ReflectionClass($className); $file = $class->getFileName(); // language file 'Message.php' -> 'Message.zh_CN.php' $nfile = substr_replace($file, '.' . $this->language . '.php', -4); if (file_exists($nfile)) { $res = include $nfile; if (is_array($res)) { $map = $res; } } } return $map; }
php
public function loadMessages(/*# string */ $className)/*# : array */ { $map = []; // reflect if (class_exists($className)) { $class = new \ReflectionClass($className); $file = $class->getFileName(); // language file 'Message.php' -> 'Message.zh_CN.php' $nfile = substr_replace($file, '.' . $this->language . '.php', -4); if (file_exists($nfile)) { $res = include $nfile; if (is_array($res)) { $map = $res; } } } return $map; }
[ "public", "function", "loadMessages", "(", "/*# string */", "$", "className", ")", "/*# : array */", "{", "$", "map", "=", "[", "]", ";", "// reflect", "if", "(", "class_exists", "(", "$", "className", ")", ")", "{", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "className", ")", ";", "$", "file", "=", "$", "class", "->", "getFileName", "(", ")", ";", "// language file 'Message.php' -> 'Message.zh_CN.php'", "$", "nfile", "=", "substr_replace", "(", "$", "file", ",", "'.'", ".", "$", "this", "->", "language", ".", "'.php'", ",", "-", "4", ")", ";", "if", "(", "file_exists", "(", "$", "nfile", ")", ")", "{", "$", "res", "=", "include", "$", "nfile", ";", "if", "(", "is_array", "(", "$", "res", ")", ")", "{", "$", "map", "=", "$", "res", ";", "}", "}", "}", "return", "$", "map", ";", "}" ]
Load language file from the same directory of message class. language file name is something like 'Message.zh_CN.php' {@inheritDoc}
[ "Load", "language", "file", "from", "the", "same", "directory", "of", "message", "class", "." ]
fcf140c09e94c3a441ee4e285de0b4c18cb6504b
https://github.com/phossa/phossa-shared/blob/fcf140c09e94c3a441ee4e285de0b4c18cb6504b/src/Phossa/Shared/Message/Loader/LanguageLoader.php#L85-L104
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Event/PreUpdateEventArgs.php
PreUpdateEventArgs.setNewValue
public function setNewValue($attribute, $value) { $this->assertValidAttribute($attribute); $this->documentChangeSet[$attribute][1] = $value; $this->getDocumentManager()->getUnitOfWork()->setDocumentChangeSet($this->getDocument(), $this->documentChangeSet); }
php
public function setNewValue($attribute, $value) { $this->assertValidAttribute($attribute); $this->documentChangeSet[$attribute][1] = $value; $this->getDocumentManager()->getUnitOfWork()->setDocumentChangeSet($this->getDocument(), $this->documentChangeSet); }
[ "public", "function", "setNewValue", "(", "$", "attribute", ",", "$", "value", ")", "{", "$", "this", "->", "assertValidAttribute", "(", "$", "attribute", ")", ";", "$", "this", "->", "documentChangeSet", "[", "$", "attribute", "]", "[", "1", "]", "=", "$", "value", ";", "$", "this", "->", "getDocumentManager", "(", ")", "->", "getUnitOfWork", "(", ")", "->", "setDocumentChangeSet", "(", "$", "this", "->", "getDocument", "(", ")", ",", "$", "this", "->", "documentChangeSet", ")", ";", "}" ]
Sets the new value of this attribute. @param string $attribute @param mixed $value
[ "Sets", "the", "new", "value", "of", "this", "attribute", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Event/PreUpdateEventArgs.php#L84-L90
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Event/PreUpdateEventArgs.php
PreUpdateEventArgs.assertValidAttribute
private function assertValidAttribute($attribute) { if ( ! isset($this->documentChangeSet[$attribute])) { throw new \InvalidArgumentException(sprintf( 'Attribute "%s" is not a valid attribute of the document "%s" in PreUpdateEventArgs.', $attribute, get_class($this->getDocument()) )); } }
php
private function assertValidAttribute($attribute) { if ( ! isset($this->documentChangeSet[$attribute])) { throw new \InvalidArgumentException(sprintf( 'Attribute "%s" is not a valid attribute of the document "%s" in PreUpdateEventArgs.', $attribute, get_class($this->getDocument()) )); } }
[ "private", "function", "assertValidAttribute", "(", "$", "attribute", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "documentChangeSet", "[", "$", "attribute", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Attribute \"%s\" is not a valid attribute of the document \"%s\" in PreUpdateEventArgs.'", ",", "$", "attribute", ",", "get_class", "(", "$", "this", "->", "getDocument", "(", ")", ")", ")", ")", ";", "}", "}" ]
Asserts the attribute exists in changeset. @param string $attribute @throws \InvalidArgumentException if the attribute has no changeset
[ "Asserts", "the", "attribute", "exists", "in", "changeset", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Event/PreUpdateEventArgs.php#L98-L107
train
shgysk8zer0/core_api
traits/path_info.php
Path_Info.getPathInfo
final public function getPathInfo($path, $use_include_path = false) { if ($use_include_path) { $path = stream_resolve_include_path($path); } else { $path = realpath($path); } if (is_string($path)) { list( $this->dirname, $this->basename, $this->extension, $this->filename ) = array_values(pathinfo($path)); $this->absolute_path = $this->dirname . DIRECTORY_SEPARATOR . $this->basename; } }
php
final public function getPathInfo($path, $use_include_path = false) { if ($use_include_path) { $path = stream_resolve_include_path($path); } else { $path = realpath($path); } if (is_string($path)) { list( $this->dirname, $this->basename, $this->extension, $this->filename ) = array_values(pathinfo($path)); $this->absolute_path = $this->dirname . DIRECTORY_SEPARATOR . $this->basename; } }
[ "final", "public", "function", "getPathInfo", "(", "$", "path", ",", "$", "use_include_path", "=", "false", ")", "{", "if", "(", "$", "use_include_path", ")", "{", "$", "path", "=", "stream_resolve_include_path", "(", "$", "path", ")", ";", "}", "else", "{", "$", "path", "=", "realpath", "(", "$", "path", ")", ";", "}", "if", "(", "is_string", "(", "$", "path", ")", ")", "{", "list", "(", "$", "this", "->", "dirname", ",", "$", "this", "->", "basename", ",", "$", "this", "->", "extension", ",", "$", "this", "->", "filename", ")", "=", "array_values", "(", "pathinfo", "(", "$", "path", ")", ")", ";", "$", "this", "->", "absolute_path", "=", "$", "this", "->", "dirname", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "basename", ";", "}", "}" ]
Retrieves information about path components @param string $path The path to work with @param bool $use_include_path Whether or not to search inclde_path @return void
[ "Retrieves", "information", "about", "path", "components" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/path_info.php#L79-L97
train
fxpio/fxp-doctrine-extensions
Filter/Listener/AbstractFilterSubscriber.php
AbstractFilterSubscriber.onEvent
public function onEvent(Event $event): void { if (!$event instanceof GetResponseEvent || !$this->injected) { if (null !== ($filter = $this->getFilter())) { $this->injectParameters($filter); } } }
php
public function onEvent(Event $event): void { if (!$event instanceof GetResponseEvent || !$this->injected) { if (null !== ($filter = $this->getFilter())) { $this->injectParameters($filter); } } }
[ "public", "function", "onEvent", "(", "Event", "$", "event", ")", ":", "void", "{", "if", "(", "!", "$", "event", "instanceof", "GetResponseEvent", "||", "!", "$", "this", "->", "injected", ")", "{", "if", "(", "null", "!==", "(", "$", "filter", "=", "$", "this", "->", "getFilter", "(", ")", ")", ")", "{", "$", "this", "->", "injectParameters", "(", "$", "filter", ")", ";", "}", "}", "}" ]
Action on the event. @param Event $event The event
[ "Action", "on", "the", "event", "." ]
82942f51d47cdd79a20a5725ee1b3ecfc69e9d77
https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Filter/Listener/AbstractFilterSubscriber.php#L65-L72
train
fxpio/fxp-doctrine-extensions
Filter/Listener/AbstractFilterSubscriber.php
AbstractFilterSubscriber.getFilter
protected function getFilter() { $supports = $this->supports(); $filters = $this->entityManager->getFilters()->getEnabledFilters(); $fFilter = null; foreach ($filters as $name => $filter) { if ($filter instanceof $supports) { $fFilter = $filter; break; } } return $fFilter; }
php
protected function getFilter() { $supports = $this->supports(); $filters = $this->entityManager->getFilters()->getEnabledFilters(); $fFilter = null; foreach ($filters as $name => $filter) { if ($filter instanceof $supports) { $fFilter = $filter; break; } } return $fFilter; }
[ "protected", "function", "getFilter", "(", ")", "{", "$", "supports", "=", "$", "this", "->", "supports", "(", ")", ";", "$", "filters", "=", "$", "this", "->", "entityManager", "->", "getFilters", "(", ")", "->", "getEnabledFilters", "(", ")", ";", "$", "fFilter", "=", "null", ";", "foreach", "(", "$", "filters", "as", "$", "name", "=>", "$", "filter", ")", "{", "if", "(", "$", "filter", "instanceof", "$", "supports", ")", "{", "$", "fFilter", "=", "$", "filter", ";", "break", ";", "}", "}", "return", "$", "fFilter", ";", "}" ]
Get the supported filter. @return null|SQLFilter
[ "Get", "the", "supported", "filter", "." ]
82942f51d47cdd79a20a5725ee1b3ecfc69e9d77
https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Filter/Listener/AbstractFilterSubscriber.php#L79-L94
train
Bistro/Router
lib/Bistro/Router/Route.php
Route.isMatch
public function isMatch($method, $url) { $match = false; if (\in_array($method, $this->responds_to)) { \preg_match($this->compile(), $url, $matches); if ( ! empty($matches)) { $this->matched_params = \array_merge( $this->defaults, $this->method_defaults[$method], $this->cleanMatches($matches) ); $match = true; } } return $match; }
php
public function isMatch($method, $url) { $match = false; if (\in_array($method, $this->responds_to)) { \preg_match($this->compile(), $url, $matches); if ( ! empty($matches)) { $this->matched_params = \array_merge( $this->defaults, $this->method_defaults[$method], $this->cleanMatches($matches) ); $match = true; } } return $match; }
[ "public", "function", "isMatch", "(", "$", "method", ",", "$", "url", ")", "{", "$", "match", "=", "false", ";", "if", "(", "\\", "in_array", "(", "$", "method", ",", "$", "this", "->", "responds_to", ")", ")", "{", "\\", "preg_match", "(", "$", "this", "->", "compile", "(", ")", ",", "$", "url", ",", "$", "matches", ")", ";", "if", "(", "!", "empty", "(", "$", "matches", ")", ")", "{", "$", "this", "->", "matched_params", "=", "\\", "array_merge", "(", "$", "this", "->", "defaults", ",", "$", "this", "->", "method_defaults", "[", "$", "method", "]", ",", "$", "this", "->", "cleanMatches", "(", "$", "matches", ")", ")", ";", "$", "match", "=", "true", ";", "}", "}", "return", "$", "match", ";", "}" ]
Check to see if this route is a match. @param string $method The request method @param string $url The accessed url @return boolean [description]
[ "Check", "to", "see", "if", "this", "route", "is", "a", "match", "." ]
ab5c3fff119c0e6c43c05300122b236afabfff41
https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Route.php#L66-L87
train
Bistro/Router
lib/Bistro/Router/Route.php
Route.url
public function url($params = array()) { if ($this->isStatic()) { return $this->pattern; } $url = $this->pattern; foreach ($this->getSegments($url) as $segment) { $func = $segment['optional'] === true ? 'replaceOptional' : 'replaceRequired'; $url = $this->{$func}($url, $segment['name'], $segment['token'], $params); } return $url; }
php
public function url($params = array()) { if ($this->isStatic()) { return $this->pattern; } $url = $this->pattern; foreach ($this->getSegments($url) as $segment) { $func = $segment['optional'] === true ? 'replaceOptional' : 'replaceRequired'; $url = $this->{$func}($url, $segment['name'], $segment['token'], $params); } return $url; }
[ "public", "function", "url", "(", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "$", "this", "->", "isStatic", "(", ")", ")", "{", "return", "$", "this", "->", "pattern", ";", "}", "$", "url", "=", "$", "this", "->", "pattern", ";", "foreach", "(", "$", "this", "->", "getSegments", "(", "$", "url", ")", "as", "$", "segment", ")", "{", "$", "func", "=", "$", "segment", "[", "'optional'", "]", "===", "true", "?", "'replaceOptional'", ":", "'replaceRequired'", ";", "$", "url", "=", "$", "this", "->", "{", "$", "func", "}", "(", "$", "url", ",", "$", "segment", "[", "'name'", "]", ",", "$", "segment", "[", "'token'", "]", ",", "$", "params", ")", ";", "}", "return", "$", "url", ";", "}" ]
A reverse routing helper. @throws \UnexpectedValueException @param array $params Parameters to set named options to @return string
[ "A", "reverse", "routing", "helper", "." ]
ab5c3fff119c0e6c43c05300122b236afabfff41
https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Route.php#L145-L161
train
Bistro/Router
lib/Bistro/Router/Route.php
Route.compile
protected function compile() { if ($this->compiled !== false) { return $this->compiled; } if ($this->isStatic()) { $this->compiled = '~^'.$this->pattern.'$~'; return $this->compiled; } $compiled = $this->pattern; foreach ($this->getSegments($compiled) as $segment) { $compiled = \str_replace($segment['token'], $segment['regex'], $compiled); } $this->compiled = "~^{$compiled}$~"; return $this->compiled; }
php
protected function compile() { if ($this->compiled !== false) { return $this->compiled; } if ($this->isStatic()) { $this->compiled = '~^'.$this->pattern.'$~'; return $this->compiled; } $compiled = $this->pattern; foreach ($this->getSegments($compiled) as $segment) { $compiled = \str_replace($segment['token'], $segment['regex'], $compiled); } $this->compiled = "~^{$compiled}$~"; return $this->compiled; }
[ "protected", "function", "compile", "(", ")", "{", "if", "(", "$", "this", "->", "compiled", "!==", "false", ")", "{", "return", "$", "this", "->", "compiled", ";", "}", "if", "(", "$", "this", "->", "isStatic", "(", ")", ")", "{", "$", "this", "->", "compiled", "=", "'~^'", ".", "$", "this", "->", "pattern", ".", "'$~'", ";", "return", "$", "this", "->", "compiled", ";", "}", "$", "compiled", "=", "$", "this", "->", "pattern", ";", "foreach", "(", "$", "this", "->", "getSegments", "(", "$", "compiled", ")", "as", "$", "segment", ")", "{", "$", "compiled", "=", "\\", "str_replace", "(", "$", "segment", "[", "'token'", "]", ",", "$", "segment", "[", "'regex'", "]", ",", "$", "compiled", ")", ";", "}", "$", "this", "->", "compiled", "=", "\"~^{$compiled}$~\"", ";", "return", "$", "this", "->", "compiled", ";", "}" ]
Compiles the pattern into one suitable for regex. @return string The regex pattern
[ "Compiles", "the", "pattern", "into", "one", "suitable", "for", "regex", "." ]
ab5c3fff119c0e6c43c05300122b236afabfff41
https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Route.php#L168-L189
train
Bistro/Router
lib/Bistro/Router/Route.php
Route.getSegments
protected function getSegments($pattern) { $segments = array(); $parts = \explode("/", ltrim($pattern, "/")); foreach ($parts as $segment) { if (\strpos($segment, ":") !== false) { $segments[] = $this->parseSegment($segment); } } return $segments; }
php
protected function getSegments($pattern) { $segments = array(); $parts = \explode("/", ltrim($pattern, "/")); foreach ($parts as $segment) { if (\strpos($segment, ":") !== false) { $segments[] = $this->parseSegment($segment); } } return $segments; }
[ "protected", "function", "getSegments", "(", "$", "pattern", ")", "{", "$", "segments", "=", "array", "(", ")", ";", "$", "parts", "=", "\\", "explode", "(", "\"/\"", ",", "ltrim", "(", "$", "pattern", ",", "\"/\"", ")", ")", ";", "foreach", "(", "$", "parts", "as", "$", "segment", ")", "{", "if", "(", "\\", "strpos", "(", "$", "segment", ",", "\":\"", ")", "!==", "false", ")", "{", "$", "segments", "[", "]", "=", "$", "this", "->", "parseSegment", "(", "$", "segment", ")", ";", "}", "}", "return", "$", "segments", ";", "}" ]
Gets an array of url segments @param string $pattern The route pattern @return array An array containing url segments
[ "Gets", "an", "array", "of", "url", "segments" ]
ab5c3fff119c0e6c43c05300122b236afabfff41
https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Route.php#L197-L211
train
Bistro/Router
lib/Bistro/Router/Route.php
Route.parseSegment
protected function parseSegment($segment) { $optional = false; list($regex, $name) = \explode(":", $segment); if (\substr($name, -1) === "?") { $name = \substr($name, 0, -1); $optional = true; } if ($regex === "") { $regex = "[^\/]+"; } $regex = "/(?P<{$name}>{$regex})"; if ($optional) { $regex = "(?:{$regex})?"; } return array( 'segment' => $segment, 'token' => "/".$segment, 'name' => $name, 'regex' => $regex, 'optional' => $optional ); }
php
protected function parseSegment($segment) { $optional = false; list($regex, $name) = \explode(":", $segment); if (\substr($name, -1) === "?") { $name = \substr($name, 0, -1); $optional = true; } if ($regex === "") { $regex = "[^\/]+"; } $regex = "/(?P<{$name}>{$regex})"; if ($optional) { $regex = "(?:{$regex})?"; } return array( 'segment' => $segment, 'token' => "/".$segment, 'name' => $name, 'regex' => $regex, 'optional' => $optional ); }
[ "protected", "function", "parseSegment", "(", "$", "segment", ")", "{", "$", "optional", "=", "false", ";", "list", "(", "$", "regex", ",", "$", "name", ")", "=", "\\", "explode", "(", "\":\"", ",", "$", "segment", ")", ";", "if", "(", "\\", "substr", "(", "$", "name", ",", "-", "1", ")", "===", "\"?\"", ")", "{", "$", "name", "=", "\\", "substr", "(", "$", "name", ",", "0", ",", "-", "1", ")", ";", "$", "optional", "=", "true", ";", "}", "if", "(", "$", "regex", "===", "\"\"", ")", "{", "$", "regex", "=", "\"[^\\/]+\"", ";", "}", "$", "regex", "=", "\"/(?P<{$name}>{$regex})\"", ";", "if", "(", "$", "optional", ")", "{", "$", "regex", "=", "\"(?:{$regex})?\"", ";", "}", "return", "array", "(", "'segment'", "=>", "$", "segment", ",", "'token'", "=>", "\"/\"", ".", "$", "segment", ",", "'name'", "=>", "$", "name", ",", "'regex'", "=>", "$", "regex", ",", "'optional'", "=>", "$", "optional", ")", ";", "}" ]
Pulls out relevent information on a given segment. @param string $segment The segment @return array ['segment' => (string), name' => (string), 'regex' => (string), 'optional' => (boolean)]
[ "Pulls", "out", "relevent", "information", "on", "a", "given", "segment", "." ]
ab5c3fff119c0e6c43c05300122b236afabfff41
https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Route.php#L219-L250
train
Mandarin-Medien/MMCmfRoutingBundle
Controller/NodeRouteController.php
NodeRouteController.nodeRouteAction
public function nodeRouteAction(NodeRoute $nodeRoute) { if($node = $this->get('mm_cmf_routing.node_resolver')->resolve($nodeRoute)) { if ($nodeRoute instanceof RedirectNodeRoute) { return $this->redirectAction($nodeRoute); } else { if ($nodeRoute->getNode() instanceof TemplatableNodeInterface) { $response = $this->render( $this->get('mm_cmf_content.template_manager')->getTemplate($nodeRoute->getNode()), array( 'node' => $nodeRoute->getNode(), 'route' => $nodeRoute ) ); /** * should be configurable * cache for 1800 seconds */ $response->setSharedMaxAge(1800); // (optional) set a custom Cache-Control directive $response->headers->addCacheControlDirective('must-revalidate', true); return $response; } else { throw new NotFoundHttpException(); } } } else { throw new NotFoundHttpException(); } }
php
public function nodeRouteAction(NodeRoute $nodeRoute) { if($node = $this->get('mm_cmf_routing.node_resolver')->resolve($nodeRoute)) { if ($nodeRoute instanceof RedirectNodeRoute) { return $this->redirectAction($nodeRoute); } else { if ($nodeRoute->getNode() instanceof TemplatableNodeInterface) { $response = $this->render( $this->get('mm_cmf_content.template_manager')->getTemplate($nodeRoute->getNode()), array( 'node' => $nodeRoute->getNode(), 'route' => $nodeRoute ) ); /** * should be configurable * cache for 1800 seconds */ $response->setSharedMaxAge(1800); // (optional) set a custom Cache-Control directive $response->headers->addCacheControlDirective('must-revalidate', true); return $response; } else { throw new NotFoundHttpException(); } } } else { throw new NotFoundHttpException(); } }
[ "public", "function", "nodeRouteAction", "(", "NodeRoute", "$", "nodeRoute", ")", "{", "if", "(", "$", "node", "=", "$", "this", "->", "get", "(", "'mm_cmf_routing.node_resolver'", ")", "->", "resolve", "(", "$", "nodeRoute", ")", ")", "{", "if", "(", "$", "nodeRoute", "instanceof", "RedirectNodeRoute", ")", "{", "return", "$", "this", "->", "redirectAction", "(", "$", "nodeRoute", ")", ";", "}", "else", "{", "if", "(", "$", "nodeRoute", "->", "getNode", "(", ")", "instanceof", "TemplatableNodeInterface", ")", "{", "$", "response", "=", "$", "this", "->", "render", "(", "$", "this", "->", "get", "(", "'mm_cmf_content.template_manager'", ")", "->", "getTemplate", "(", "$", "nodeRoute", "->", "getNode", "(", ")", ")", ",", "array", "(", "'node'", "=>", "$", "nodeRoute", "->", "getNode", "(", ")", ",", "'route'", "=>", "$", "nodeRoute", ")", ")", ";", "/**\n * should be configurable\n * cache for 1800 seconds\n */", "$", "response", "->", "setSharedMaxAge", "(", "1800", ")", ";", "// (optional) set a custom Cache-Control directive", "$", "response", "->", "headers", "->", "addCacheControlDirective", "(", "'must-revalidate'", ",", "true", ")", ";", "return", "$", "response", ";", "}", "else", "{", "throw", "new", "NotFoundHttpException", "(", ")", ";", "}", "}", "}", "else", "{", "throw", "new", "NotFoundHttpException", "(", ")", ";", "}", "}" ]
process the the node route call @param NodeRoute $nodeRoute @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response @throws NotFoundHttpException
[ "process", "the", "the", "node", "route", "call" ]
7db1b03f5e120bd473486c0be6ab76c6146cd2d0
https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/Controller/NodeRouteController.php#L28-L65
train
pdyn/base
Utils.php
Utils.genRandomStr
public static function genRandomStr($l) { $p = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $s = ''; for ($i = 0; $i < $l; $i++) { $s .= $p[mt_rand(0, (mb_strlen($p) - 1))]; } return $s; }
php
public static function genRandomStr($l) { $p = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $s = ''; for ($i = 0; $i < $l; $i++) { $s .= $p[mt_rand(0, (mb_strlen($p) - 1))]; } return $s; }
[ "public", "static", "function", "genRandomStr", "(", "$", "l", ")", "{", "$", "p", "=", "'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'", ";", "$", "s", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "l", ";", "$", "i", "++", ")", "{", "$", "s", ".=", "$", "p", "[", "mt_rand", "(", "0", ",", "(", "mb_strlen", "(", "$", "p", ")", "-", "1", ")", ")", "]", ";", "}", "return", "$", "s", ";", "}" ]
Generate a random string of letters and numbers of a specific length. @param int $l The desired length of the string. @return string The generated string.
[ "Generate", "a", "random", "string", "of", "letters", "and", "numbers", "of", "a", "specific", "length", "." ]
0b93961693954a6b4e1c6df7e345e5cdf07f26ff
https://github.com/pdyn/base/blob/0b93961693954a6b4e1c6df7e345e5cdf07f26ff/Utils.php#L41-L48
train
pdyn/base
Utils.php
Utils.uniqid
public static function uniqid($length = false) { if ($length <= 13) { return uniqid(); } $uniq = strrev(str_replace('.', '', uniqid('', true))); $uniqlen = mb_strlen($uniq); if ($length === false || $length === $uniqlen) { return $uniq; } elseif ($length < $uniqlen) { return mb_substr($uniq, 0, $length); } else { return \pdyn\base\Utils::genRandomStr(($length - mb_strlen($uniq))).$uniq; } }
php
public static function uniqid($length = false) { if ($length <= 13) { return uniqid(); } $uniq = strrev(str_replace('.', '', uniqid('', true))); $uniqlen = mb_strlen($uniq); if ($length === false || $length === $uniqlen) { return $uniq; } elseif ($length < $uniqlen) { return mb_substr($uniq, 0, $length); } else { return \pdyn\base\Utils::genRandomStr(($length - mb_strlen($uniq))).$uniq; } }
[ "public", "static", "function", "uniqid", "(", "$", "length", "=", "false", ")", "{", "if", "(", "$", "length", "<=", "13", ")", "{", "return", "uniqid", "(", ")", ";", "}", "$", "uniq", "=", "strrev", "(", "str_replace", "(", "'.'", ",", "''", ",", "uniqid", "(", "''", ",", "true", ")", ")", ")", ";", "$", "uniqlen", "=", "mb_strlen", "(", "$", "uniq", ")", ";", "if", "(", "$", "length", "===", "false", "||", "$", "length", "===", "$", "uniqlen", ")", "{", "return", "$", "uniq", ";", "}", "elseif", "(", "$", "length", "<", "$", "uniqlen", ")", "{", "return", "mb_substr", "(", "$", "uniq", ",", "0", ",", "$", "length", ")", ";", "}", "else", "{", "return", "\\", "pdyn", "\\", "base", "\\", "Utils", "::", "genRandomStr", "(", "(", "$", "length", "-", "mb_strlen", "(", "$", "uniq", ")", ")", ")", ".", "$", "uniq", ";", "}", "}" ]
Generate a guaranteed unique value of a specified length. @param int|bool $length A desired length, or false to use uniqid length. @return string The unique string.
[ "Generate", "a", "guaranteed", "unique", "value", "of", "a", "specified", "length", "." ]
0b93961693954a6b4e1c6df7e345e5cdf07f26ff
https://github.com/pdyn/base/blob/0b93961693954a6b4e1c6df7e345e5cdf07f26ff/Utils.php#L55-L68
train
Vectrex/vxPHP
src/Autoload/Psr4.php
Psr4.addPrefix
public function addPrefix($prefix, $baseDirs, $prepend = FALSE) { $baseDirs = (array) $baseDirs; // normalize the namespace prefix $prefix = trim($prefix, '\\') . '\\'; // initialize the namespace prefix array if needed if (! isset($this->prefixes[$prefix])) { $this->prefixes[$prefix] = []; } // normalize each base dir with a trailing separator foreach ($baseDirs as $ndx => $dir) { $baseDirs[$ndx] = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } // prepend or append? $this->prefixes[$prefix] = $prepend ? array_merge($baseDirs, $this->prefixes[$prefix]) : $this->prefixes[$prefix] = array_merge($this->prefixes[$prefix], $baseDirs); }
php
public function addPrefix($prefix, $baseDirs, $prepend = FALSE) { $baseDirs = (array) $baseDirs; // normalize the namespace prefix $prefix = trim($prefix, '\\') . '\\'; // initialize the namespace prefix array if needed if (! isset($this->prefixes[$prefix])) { $this->prefixes[$prefix] = []; } // normalize each base dir with a trailing separator foreach ($baseDirs as $ndx => $dir) { $baseDirs[$ndx] = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } // prepend or append? $this->prefixes[$prefix] = $prepend ? array_merge($baseDirs, $this->prefixes[$prefix]) : $this->prefixes[$prefix] = array_merge($this->prefixes[$prefix], $baseDirs); }
[ "public", "function", "addPrefix", "(", "$", "prefix", ",", "$", "baseDirs", ",", "$", "prepend", "=", "FALSE", ")", "{", "$", "baseDirs", "=", "(", "array", ")", "$", "baseDirs", ";", "// normalize the namespace prefix", "$", "prefix", "=", "trim", "(", "$", "prefix", ",", "'\\\\'", ")", ".", "'\\\\'", ";", "// initialize the namespace prefix array if needed", "if", "(", "!", "isset", "(", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", ")", ")", "{", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", "=", "[", "]", ";", "}", "// normalize each base dir with a trailing separator", "foreach", "(", "$", "baseDirs", "as", "$", "ndx", "=>", "$", "dir", ")", "{", "$", "baseDirs", "[", "$", "ndx", "]", "=", "rtrim", "(", "$", "dir", ",", "DIRECTORY_SEPARATOR", ")", ".", "DIRECTORY_SEPARATOR", ";", "}", "// prepend or append?", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", "=", "$", "prepend", "?", "array_merge", "(", "$", "baseDirs", ",", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", ")", ":", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", "=", "array_merge", "(", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", ",", "$", "baseDirs", ")", ";", "}" ]
add a base directory for a namespace prefix @param string $prefix @param string|array $baseDirs: one or more base directories for the namespace prefix @param bool $prepend: if true, prepend base directories to prefix instead of appending them; this causes them to be searched first rather than last. @return void
[ "add", "a", "base", "directory", "for", "a", "namespace", "prefix" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Autoload/Psr4.php#L100-L124
train
Vectrex/vxPHP
src/Autoload/Psr4.php
Psr4.setPrefixes
public function setPrefixes(array $prefixes) { $this->prefixes = []; foreach ($prefixes as $prefix => $baseDir) { $this->addPrefix($prefix, $baseDir); } }
php
public function setPrefixes(array $prefixes) { $this->prefixes = []; foreach ($prefixes as $prefix => $baseDir) { $this->addPrefix($prefix, $baseDir); } }
[ "public", "function", "setPrefixes", "(", "array", "$", "prefixes", ")", "{", "$", "this", "->", "prefixes", "=", "[", "]", ";", "foreach", "(", "$", "prefixes", "as", "$", "prefix", "=>", "$", "baseDir", ")", "{", "$", "this", "->", "addPrefix", "(", "$", "prefix", ",", "$", "baseDir", ")", ";", "}", "}" ]
set all namespace prefixes and their base directories; overwrites existing prefixes @param array $prefixes: associative array of namespace prefixes and their base directories @return void
[ "set", "all", "namespace", "prefixes", "and", "their", "base", "directories", ";", "overwrites", "existing", "prefixes" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Autoload/Psr4.php#L134-L139
train
Vectrex/vxPHP
src/Autoload/Psr4.php
Psr4.loadFile
protected function loadFile($prefix, $relativeClass) { // any base directories for this namespace prefix? if (!isset($this->prefixes[$prefix])) { $this->debug[] = $prefix . ': no base dirs'; return FALSE; } // search base directories for this namespace prefix foreach($this->prefixes[$prefix] as $baseDir) { /* * replace the namespace prefix with the base directory, * replace namespace separators with directory separators * append ".php" */ $file = $baseDir . str_replace('\\', DIRECTORY_SEPARATOR, $relativeClass) . '.php'; // if mapped file exists, require it if ($this->requireFile($file)) { return $file; } // not in the base directory $this->debug[] = $prefix . ': ' . $file . ' not found'; } // not found return FALSE; }
php
protected function loadFile($prefix, $relativeClass) { // any base directories for this namespace prefix? if (!isset($this->prefixes[$prefix])) { $this->debug[] = $prefix . ': no base dirs'; return FALSE; } // search base directories for this namespace prefix foreach($this->prefixes[$prefix] as $baseDir) { /* * replace the namespace prefix with the base directory, * replace namespace separators with directory separators * append ".php" */ $file = $baseDir . str_replace('\\', DIRECTORY_SEPARATOR, $relativeClass) . '.php'; // if mapped file exists, require it if ($this->requireFile($file)) { return $file; } // not in the base directory $this->debug[] = $prefix . ': ' . $file . ' not found'; } // not found return FALSE; }
[ "protected", "function", "loadFile", "(", "$", "prefix", ",", "$", "relativeClass", ")", "{", "// any base directories for this namespace prefix?", "if", "(", "!", "isset", "(", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", ")", ")", "{", "$", "this", "->", "debug", "[", "]", "=", "$", "prefix", ".", "': no base dirs'", ";", "return", "FALSE", ";", "}", "// search base directories for this namespace prefix", "foreach", "(", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", "as", "$", "baseDir", ")", "{", "/*\n\t\t\t * replace the namespace prefix with the base directory,\n\t\t\t * replace namespace separators with directory separators\n\t\t\t * append \".php\"\n\t\t\t */", "$", "file", "=", "$", "baseDir", ".", "str_replace", "(", "'\\\\'", ",", "DIRECTORY_SEPARATOR", ",", "$", "relativeClass", ")", ".", "'.php'", ";", "// if mapped file exists, require it", "if", "(", "$", "this", "->", "requireFile", "(", "$", "file", ")", ")", "{", "return", "$", "file", ";", "}", "// not in the base directory", "$", "this", "->", "debug", "[", "]", "=", "$", "prefix", ".", "': '", ".", "$", "file", ".", "' not found'", ";", "}", "// not found", "return", "FALSE", ";", "}" ]
loads mapped file for a namespace prefix and relative class @param string $prefix @param string $relativeClass @return mixed name of mapped file that was loaded or FALSE if file could not be loaded
[ "loads", "mapped", "file", "for", "a", "namespace", "prefix", "and", "relative", "class" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Autoload/Psr4.php#L278-L316
train
Ydle/HubBundle
Controller/NodesController.php
NodesController.nodesFormAction
public function nodesFormAction(Request $request) { $node = new Node(); // Manage edition mode $this->currentNode = $request->get('node'); if ($this->currentNode) { $node = $this->get("ydle.node.manager")->find($request->get('node')); } $action = $this->get('router')->generate('submitNodeForm', array('node' => $this->currentNode)); $form = $this->createForm("node_form", $node); $form->handleRequest($request); return $this->render('YdleHubBundle:Nodes:form.html.twig', array( 'action' => $action, 'entry' => $node, 'form' => $form->createView() )); }
php
public function nodesFormAction(Request $request) { $node = new Node(); // Manage edition mode $this->currentNode = $request->get('node'); if ($this->currentNode) { $node = $this->get("ydle.node.manager")->find($request->get('node')); } $action = $this->get('router')->generate('submitNodeForm', array('node' => $this->currentNode)); $form = $this->createForm("node_form", $node); $form->handleRequest($request); return $this->render('YdleHubBundle:Nodes:form.html.twig', array( 'action' => $action, 'entry' => $node, 'form' => $form->createView() )); }
[ "public", "function", "nodesFormAction", "(", "Request", "$", "request", ")", "{", "$", "node", "=", "new", "Node", "(", ")", ";", "// Manage edition mode", "$", "this", "->", "currentNode", "=", "$", "request", "->", "get", "(", "'node'", ")", ";", "if", "(", "$", "this", "->", "currentNode", ")", "{", "$", "node", "=", "$", "this", "->", "get", "(", "\"ydle.node.manager\"", ")", "->", "find", "(", "$", "request", "->", "get", "(", "'node'", ")", ")", ";", "}", "$", "action", "=", "$", "this", "->", "get", "(", "'router'", ")", "->", "generate", "(", "'submitNodeForm'", ",", "array", "(", "'node'", "=>", "$", "this", "->", "currentNode", ")", ")", ";", "$", "form", "=", "$", "this", "->", "createForm", "(", "\"node_form\"", ",", "$", "node", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "return", "$", "this", "->", "render", "(", "'YdleHubBundle:Nodes:form.html.twig'", ",", "array", "(", "'action'", "=>", "$", "action", ",", "'entry'", "=>", "$", "node", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ")", ")", ";", "}" ]
Display a form to create or edit a node. @param Request $request
[ "Display", "a", "form", "to", "create", "or", "edit", "a", "node", "." ]
7fa423241246bcfd115f2ed3ad3997b4b63adb01
https://github.com/Ydle/HubBundle/blob/7fa423241246bcfd115f2ed3ad3997b4b63adb01/Controller/NodesController.php#L40-L58
train
squareproton/Bond
src/Bond/RecordManager/Task.php
Task.setObject
public function setObject( $object, $throwExceptionOnFailure = true ) { // tasks only work on objects if( !is_object($object) ) { throw new BadTaskException("A task must be object"); return false; } $error = null; if( $isCompatible = static::isCompatible( $object, $error ) ) { $this->object = $object; return true; } if( $throwExceptionOnFailure ) { throw new BadTaskException("{$error}"); } return false; }
php
public function setObject( $object, $throwExceptionOnFailure = true ) { // tasks only work on objects if( !is_object($object) ) { throw new BadTaskException("A task must be object"); return false; } $error = null; if( $isCompatible = static::isCompatible( $object, $error ) ) { $this->object = $object; return true; } if( $throwExceptionOnFailure ) { throw new BadTaskException("{$error}"); } return false; }
[ "public", "function", "setObject", "(", "$", "object", ",", "$", "throwExceptionOnFailure", "=", "true", ")", "{", "// tasks only work on objects", "if", "(", "!", "is_object", "(", "$", "object", ")", ")", "{", "throw", "new", "BadTaskException", "(", "\"A task must be object\"", ")", ";", "return", "false", ";", "}", "$", "error", "=", "null", ";", "if", "(", "$", "isCompatible", "=", "static", "::", "isCompatible", "(", "$", "object", ",", "$", "error", ")", ")", "{", "$", "this", "->", "object", "=", "$", "object", ";", "return", "true", ";", "}", "if", "(", "$", "throwExceptionOnFailure", ")", "{", "throw", "new", "BadTaskException", "(", "\"{$error}\"", ")", ";", "}", "return", "false", ";", "}" ]
Set a task's object property @param object $object @param booly Throw exception if the even we can't set the object @return Were we able to set this property
[ "Set", "a", "task", "s", "object", "property" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager/Task.php#L75-L96
train
ezra-obiwale/dSCore
src/Core/AInjector.php
AInjector.getConfigInject
protected function getConfigInject($type) { switch (strtolower($type)) { case 'all': case 'a': return engineGet('inject', 'all'); case 'controllers': case 'controller': case 'c': return array_merge(engineGet('inject', 'all'), engineGet('inject', 'controllers')); case 'services': case 'service': case 's': return array_merge(engineGet('inject', 'all'), engineGet('inject', 'services')); case 'views': case 'view': case 'v': return array_merge(engineGet('inject', 'all'), engineGet('inject', 'views')); } }
php
protected function getConfigInject($type) { switch (strtolower($type)) { case 'all': case 'a': return engineGet('inject', 'all'); case 'controllers': case 'controller': case 'c': return array_merge(engineGet('inject', 'all'), engineGet('inject', 'controllers')); case 'services': case 'service': case 's': return array_merge(engineGet('inject', 'all'), engineGet('inject', 'services')); case 'views': case 'view': case 'v': return array_merge(engineGet('inject', 'all'), engineGet('inject', 'views')); } }
[ "protected", "function", "getConfigInject", "(", "$", "type", ")", "{", "switch", "(", "strtolower", "(", "$", "type", ")", ")", "{", "case", "'all'", ":", "case", "'a'", ":", "return", "engineGet", "(", "'inject'", ",", "'all'", ")", ";", "case", "'controllers'", ":", "case", "'controller'", ":", "case", "'c'", ":", "return", "array_merge", "(", "engineGet", "(", "'inject'", ",", "'all'", ")", ",", "engineGet", "(", "'inject'", ",", "'controllers'", ")", ")", ";", "case", "'services'", ":", "case", "'service'", ":", "case", "'s'", ":", "return", "array_merge", "(", "engineGet", "(", "'inject'", ",", "'all'", ")", ",", "engineGet", "(", "'inject'", ",", "'services'", ")", ")", ";", "case", "'views'", ":", "case", "'view'", ":", "case", "'v'", ":", "return", "array_merge", "(", "engineGet", "(", "'inject'", ",", "'all'", ")", ",", "engineGet", "(", "'inject'", ",", "'views'", ")", ")", ";", "}", "}" ]
Fetches classes to inject from the config file. If given type is not "all", the required is merged with the "all" @param string $type all, controllers|controller|c,services|service|s, views|view|v @return array
[ "Fetches", "classes", "to", "inject", "from", "the", "config", "file", ".", "If", "given", "type", "is", "not", "all", "the", "required", "is", "merged", "with", "the", "all" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AInjector.php#L45-L63
train