id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
1,800 | agalbourdin/agl-core | src/Data/File.php | File.write | public static function write($pFile, $pContent, $pAppend = false)
{
if (! is_writable($pFile)) {
self::create($pFile);
}
if ($pAppend) {
return (file_put_contents($pFile, $pContent, FILE_APPEND | LOCK_EX));
}
return (file_put_contents($pFile, $pContent, LOCK_EX));
} | php | public static function write($pFile, $pContent, $pAppend = false)
{
if (! is_writable($pFile)) {
self::create($pFile);
}
if ($pAppend) {
return (file_put_contents($pFile, $pContent, FILE_APPEND | LOCK_EX));
}
return (file_put_contents($pFile, $pContent, LOCK_EX));
} | [
"public",
"static",
"function",
"write",
"(",
"$",
"pFile",
",",
"$",
"pContent",
",",
"$",
"pAppend",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"pFile",
")",
")",
"{",
"self",
"::",
"create",
"(",
"$",
"pFile",
")",
";",
"}",
"if",
"(",
"$",
"pAppend",
")",
"{",
"return",
"(",
"file_put_contents",
"(",
"$",
"pFile",
",",
"$",
"pContent",
",",
"FILE_APPEND",
"|",
"LOCK_EX",
")",
")",
";",
"}",
"return",
"(",
"file_put_contents",
"(",
"$",
"pFile",
",",
"$",
"pContent",
",",
"LOCK_EX",
")",
")",
";",
"}"
] | Write content to a file.
@param string $pFile
@param string $pContent
@param bool $pAppend Append data to file (erase content before write by
default)
@return mixed | [
"Write",
"content",
"to",
"a",
"file",
"."
] | 1db556f9a49488aa9fab6887fefb7141a79ad97d | https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Data/File.php#L87-L98 |
1,801 | agalbourdin/agl-core | src/Data/File.php | File.chmod | public static function chmod($pFile, $pMode)
{
if (strpos($pMode, '0') !== 0) {
$mode = octdec('0' . $pMode);
} else {
$mode = octdec($pMode);
}
return chmod($pFile, $mode);
} | php | public static function chmod($pFile, $pMode)
{
if (strpos($pMode, '0') !== 0) {
$mode = octdec('0' . $pMode);
} else {
$mode = octdec($pMode);
}
return chmod($pFile, $mode);
} | [
"public",
"static",
"function",
"chmod",
"(",
"$",
"pFile",
",",
"$",
"pMode",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"pMode",
",",
"'0'",
")",
"!==",
"0",
")",
"{",
"$",
"mode",
"=",
"octdec",
"(",
"'0'",
".",
"$",
"pMode",
")",
";",
"}",
"else",
"{",
"$",
"mode",
"=",
"octdec",
"(",
"$",
"pMode",
")",
";",
"}",
"return",
"chmod",
"(",
"$",
"pFile",
",",
"$",
"mode",
")",
";",
"}"
] | CHMOD a file.
@param string $pFile
@param mixed $pMode
@return bool | [
"CHMOD",
"a",
"file",
"."
] | 1db556f9a49488aa9fab6887fefb7141a79ad97d | https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Data/File.php#L107-L116 |
1,802 | rafaelnajera/matcher | Matcher/Pattern.php | Pattern.withCallback | public function withCallback(callable $theCallback)
{
$copy = clone $this;
foreach ($this->states as $key => $s) {
foreach ($s->conditions as $c) {
if ($c->nextState === State::MATCH_FOUND) {
$copy->callbacks[$key][State::MATCH_FOUND] = $theCallback;
}
}
}
return $copy;
} | php | public function withCallback(callable $theCallback)
{
$copy = clone $this;
foreach ($this->states as $key => $s) {
foreach ($s->conditions as $c) {
if ($c->nextState === State::MATCH_FOUND) {
$copy->callbacks[$key][State::MATCH_FOUND] = $theCallback;
}
}
}
return $copy;
} | [
"public",
"function",
"withCallback",
"(",
"callable",
"$",
"theCallback",
")",
"{",
"$",
"copy",
"=",
"clone",
"$",
"this",
";",
"foreach",
"(",
"$",
"this",
"->",
"states",
"as",
"$",
"key",
"=>",
"$",
"s",
")",
"{",
"foreach",
"(",
"$",
"s",
"->",
"conditions",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"c",
"->",
"nextState",
"===",
"State",
"::",
"MATCH_FOUND",
")",
"{",
"$",
"copy",
"->",
"callbacks",
"[",
"$",
"key",
"]",
"[",
"State",
"::",
"MATCH_FOUND",
"]",
"=",
"$",
"theCallback",
";",
"}",
"}",
"}",
"return",
"$",
"copy",
";",
"}"
] | Set the pattern's match callback
@param \callable $theCallback | [
"Set",
"the",
"pattern",
"s",
"match",
"callback"
] | f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf | https://github.com/rafaelnajera/matcher/blob/f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf/Matcher/Pattern.php#L59-L70 |
1,803 | ViPErCZ/composer_slimORM | src/Reflexion/EntityReflexion.php | EntityReflexion.getParent | public static function getParent($className) {
$reflection = ClassType::from($className);
$parent = $reflection->getParentClass();
return $parent ? $parent->getName() : $parent;
} | php | public static function getParent($className) {
$reflection = ClassType::from($className);
$parent = $reflection->getParentClass();
return $parent ? $parent->getName() : $parent;
} | [
"public",
"static",
"function",
"getParent",
"(",
"$",
"className",
")",
"{",
"$",
"reflection",
"=",
"ClassType",
"::",
"from",
"(",
"$",
"className",
")",
";",
"$",
"parent",
"=",
"$",
"reflection",
"->",
"getParentClass",
"(",
")",
";",
"return",
"$",
"parent",
"?",
"$",
"parent",
"->",
"getName",
"(",
")",
":",
"$",
"parent",
";",
"}"
] | Get parent class
@param $className
@return null|string | [
"Get",
"parent",
"class"
] | 2206f4ab4557e2b21b2ae4e2ded7cb5ca3d829bf | https://github.com/ViPErCZ/composer_slimORM/blob/2206f4ab4557e2b21b2ae4e2ded7cb5ca3d829bf/src/Reflexion/EntityReflexion.php#L97-L101 |
1,804 | PowerOnSystem/WebFramework | src/Network/Request.php | Request.getData | public function getData() {
$values = array_filter(filter_input_array(INPUT_POST));
foreach ($values as $key => $value) {
if ( is_array($value) ) {
$values[$key] = array_filter($value);
}
}
return $values + $_FILES;
} | php | public function getData() {
$values = array_filter(filter_input_array(INPUT_POST));
foreach ($values as $key => $value) {
if ( is_array($value) ) {
$values[$key] = array_filter($value);
}
}
return $values + $_FILES;
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"$",
"values",
"=",
"array_filter",
"(",
"filter_input_array",
"(",
"INPUT_POST",
")",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"array_filter",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"values",
"+",
"$",
"_FILES",
";",
"}"
] | Devuelve todos losd atos enviados de un formulario
@return type | [
"Devuelve",
"todos",
"losd",
"atos",
"enviados",
"de",
"un",
"formulario"
] | 3b885a390adc42d6ad93d7900d33d97c66a6c2a9 | https://github.com/PowerOnSystem/WebFramework/blob/3b885a390adc42d6ad93d7900d33d97c66a6c2a9/src/Network/Request.php#L129-L138 |
1,805 | PowerOnSystem/WebFramework | src/Network/Request.php | Request.is | public function is($method) {
$m = strtolower($method);
if ( ($m == 'post' || $m == 'ajax') && $this->_method == 'ajax-post') {
return TRUE;
}
return $m == $this->_method;
} | php | public function is($method) {
$m = strtolower($method);
if ( ($m == 'post' || $m == 'ajax') && $this->_method == 'ajax-post') {
return TRUE;
}
return $m == $this->_method;
} | [
"public",
"function",
"is",
"(",
"$",
"method",
")",
"{",
"$",
"m",
"=",
"strtolower",
"(",
"$",
"method",
")",
";",
"if",
"(",
"(",
"$",
"m",
"==",
"'post'",
"||",
"$",
"m",
"==",
"'ajax'",
")",
"&&",
"$",
"this",
"->",
"_method",
"==",
"'ajax-post'",
")",
"{",
"return",
"TRUE",
";",
"}",
"return",
"$",
"m",
"==",
"$",
"this",
"->",
"_method",
";",
"}"
] | Verifica el tipo de request dado
@param string $method El metodo a verificar
@return boolean | [
"Verifica",
"el",
"tipo",
"de",
"request",
"dado"
] | 3b885a390adc42d6ad93d7900d33d97c66a6c2a9 | https://github.com/PowerOnSystem/WebFramework/blob/3b885a390adc42d6ad93d7900d33d97c66a6c2a9/src/Network/Request.php#L145-L151 |
1,806 | PowerOnSystem/WebFramework | src/Network/Request.php | Request.data | public function data($name, $filter = FILTER_DEFAULT, $flag = NULL) {
$data = $flag ? filter_input(INPUT_POST, $name, $filter, $flag) : filter_input(INPUT_POST, $name, $filter);
return $data;
} | php | public function data($name, $filter = FILTER_DEFAULT, $flag = NULL) {
$data = $flag ? filter_input(INPUT_POST, $name, $filter, $flag) : filter_input(INPUT_POST, $name, $filter);
return $data;
} | [
"public",
"function",
"data",
"(",
"$",
"name",
",",
"$",
"filter",
"=",
"FILTER_DEFAULT",
",",
"$",
"flag",
"=",
"NULL",
")",
"{",
"$",
"data",
"=",
"$",
"flag",
"?",
"filter_input",
"(",
"INPUT_POST",
",",
"$",
"name",
",",
"$",
"filter",
",",
"$",
"flag",
")",
":",
"filter_input",
"(",
"INPUT_POST",
",",
"$",
"name",
",",
"$",
"filter",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Devuelve el dato enviado por POST
@param mix $name El nombre del parametro
@param integer $filter El filtro a utilizar
@return mix | [
"Devuelve",
"el",
"dato",
"enviado",
"por",
"POST"
] | 3b885a390adc42d6ad93d7900d33d97c66a6c2a9 | https://github.com/PowerOnSystem/WebFramework/blob/3b885a390adc42d6ad93d7900d33d97c66a6c2a9/src/Network/Request.php#L159-L162 |
1,807 | PowerOnSystem/WebFramework | src/Network/Request.php | Request.url | public function url($name) {
if ( key_exists($name, $this->_url) ) {
return $this->_url[$name];
}
return htmlentities(utf8_decode(filter_input(INPUT_GET, $name, FILTER_SANITIZE_STRING)));
} | php | public function url($name) {
if ( key_exists($name, $this->_url) ) {
return $this->_url[$name];
}
return htmlentities(utf8_decode(filter_input(INPUT_GET, $name, FILTER_SANITIZE_STRING)));
} | [
"public",
"function",
"url",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"_url",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_url",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"htmlentities",
"(",
"utf8_decode",
"(",
"filter_input",
"(",
"INPUT_GET",
",",
"$",
"name",
",",
"FILTER_SANITIZE_STRING",
")",
")",
")",
";",
"}"
] | Devuelve el dato enviado por GET
@param mix $name El nombre del parametro
@return string | [
"Devuelve",
"el",
"dato",
"enviado",
"por",
"GET"
] | 3b885a390adc42d6ad93d7900d33d97c66a6c2a9 | https://github.com/PowerOnSystem/WebFramework/blob/3b885a390adc42d6ad93d7900d33d97c66a6c2a9/src/Network/Request.php#L178-L184 |
1,808 | PowerOnSystem/WebFramework | src/Network/Request.php | Request.cookie | public function cookie($name) {
if ( in_array($name, $this->cookies) ) {
return filter_input(INPUT_COOKIE, $name, FILTER_SANITIZE_STRING);
}
return NULL;
} | php | public function cookie($name) {
if ( in_array($name, $this->cookies) ) {
return filter_input(INPUT_COOKIE, $name, FILTER_SANITIZE_STRING);
}
return NULL;
} | [
"public",
"function",
"cookie",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"cookies",
")",
")",
"{",
"return",
"filter_input",
"(",
"INPUT_COOKIE",
",",
"$",
"name",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"}",
"return",
"NULL",
";",
"}"
] | Devuelve el dato de una COOKIE
@param string|integer $name El nombre del parametro
@param integer $mode El modo de desinfectacion
@return string | [
"Devuelve",
"el",
"dato",
"de",
"una",
"COOKIE"
] | 3b885a390adc42d6ad93d7900d33d97c66a6c2a9 | https://github.com/PowerOnSystem/WebFramework/blob/3b885a390adc42d6ad93d7900d33d97c66a6c2a9/src/Network/Request.php#L207-L212 |
1,809 | ifrpl/muyo | model/db/db.php | Lib_Model_Db.aliasSet | public function aliasSet( $value )
{
$columns = $this->getColumns();
$this->aliasGet( $oldValue );
foreach( $columns as &$column )
{
$tableAlias = $column[0];
if( $tableAlias === $oldValue )
{
$column[0] = $value;
}
}
$select = $this->getSelect();
$from = $select->getPart( Zend_Db_Select::FROM );
$select->reset( Zend_Db_Select::FROM );
foreach( $from as $tableAlias => $descriptor )
{
if( $tableAlias === $oldValue )
{
unset($from[$oldValue]);
$from[$value] = $descriptor;
}
}
$select->from( array( $value => $this->getTable() ), array() );
return $this
->setAlias( $value )
->resetColumns( $columns )
;
} | php | public function aliasSet( $value )
{
$columns = $this->getColumns();
$this->aliasGet( $oldValue );
foreach( $columns as &$column )
{
$tableAlias = $column[0];
if( $tableAlias === $oldValue )
{
$column[0] = $value;
}
}
$select = $this->getSelect();
$from = $select->getPart( Zend_Db_Select::FROM );
$select->reset( Zend_Db_Select::FROM );
foreach( $from as $tableAlias => $descriptor )
{
if( $tableAlias === $oldValue )
{
unset($from[$oldValue]);
$from[$value] = $descriptor;
}
}
$select->from( array( $value => $this->getTable() ), array() );
return $this
->setAlias( $value )
->resetColumns( $columns )
;
} | [
"public",
"function",
"aliasSet",
"(",
"$",
"value",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"getColumns",
"(",
")",
";",
"$",
"this",
"->",
"aliasGet",
"(",
"$",
"oldValue",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"&",
"$",
"column",
")",
"{",
"$",
"tableAlias",
"=",
"$",
"column",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"tableAlias",
"===",
"$",
"oldValue",
")",
"{",
"$",
"column",
"[",
"0",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"select",
"=",
"$",
"this",
"->",
"getSelect",
"(",
")",
";",
"$",
"from",
"=",
"$",
"select",
"->",
"getPart",
"(",
"Zend_Db_Select",
"::",
"FROM",
")",
";",
"$",
"select",
"->",
"reset",
"(",
"Zend_Db_Select",
"::",
"FROM",
")",
";",
"foreach",
"(",
"$",
"from",
"as",
"$",
"tableAlias",
"=>",
"$",
"descriptor",
")",
"{",
"if",
"(",
"$",
"tableAlias",
"===",
"$",
"oldValue",
")",
"{",
"unset",
"(",
"$",
"from",
"[",
"$",
"oldValue",
"]",
")",
";",
"$",
"from",
"[",
"$",
"value",
"]",
"=",
"$",
"descriptor",
";",
"}",
"}",
"$",
"select",
"->",
"from",
"(",
"array",
"(",
"$",
"value",
"=>",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
",",
"array",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"setAlias",
"(",
"$",
"value",
")",
"->",
"resetColumns",
"(",
"$",
"columns",
")",
";",
"}"
] | Replaces current alias with different one.
@param string $value
@return $this
@see setAlias version that do not replaces currently set columns | [
"Replaces",
"current",
"alias",
"with",
"different",
"one",
"."
] | 05e544d91bba8a59ccd38c74da84448ec94b2a17 | https://github.com/ifrpl/muyo/blob/05e544d91bba8a59ccd38c74da84448ec94b2a17/model/db/db.php#L222-L252 |
1,810 | ifrpl/muyo | model/db/db.php | Lib_Model_Db.deleteBy | public function deleteBy($condition = null)
{
if( !is_null($condition) )
{
$this->filterBy($condition);
}
$matched = $this->load();
array_each(
$matched,
function($model)
{ /** @var Lib_Model_Db $model */
$model->delete();
}
);
return !empty($matched);
} | php | public function deleteBy($condition = null)
{
if( !is_null($condition) )
{
$this->filterBy($condition);
}
$matched = $this->load();
array_each(
$matched,
function($model)
{ /** @var Lib_Model_Db $model */
$model->delete();
}
);
return !empty($matched);
} | [
"public",
"function",
"deleteBy",
"(",
"$",
"condition",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"condition",
")",
")",
"{",
"$",
"this",
"->",
"filterBy",
"(",
"$",
"condition",
")",
";",
"}",
"$",
"matched",
"=",
"$",
"this",
"->",
"load",
"(",
")",
";",
"array_each",
"(",
"$",
"matched",
",",
"function",
"(",
"$",
"model",
")",
"{",
"/** @var Lib_Model_Db $model */",
"$",
"model",
"->",
"delete",
"(",
")",
";",
"}",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"matched",
")",
";",
"}"
] | Delete records by specified conditions.
@param array $condition array of conditions
@return bool deleted?
@todo Update logging to handle batches, then we can implement this function properly | [
"Delete",
"records",
"by",
"specified",
"conditions",
"."
] | 05e544d91bba8a59ccd38c74da84448ec94b2a17 | https://github.com/ifrpl/muyo/blob/05e544d91bba8a59ccd38c74da84448ec94b2a17/model/db/db.php#L285-L300 |
1,811 | GovTribe/laravel-kinvey | src/GovTribe/LaravelKinvey/Client/Plugins/KinveyUserSoftDeletePlugin.php | KinveyUserSoftDeletePlugin.beforePrepare | public function beforePrepare(Event $event)
{
$command = $event['command'];
$operation = $command->getOperation();
$client = $command->getClient();
if ($command->getName() !== 'updateEntity') return;
if ($operation->getParam('collection')->getDefault() !== 'user') return;
// Attempt to get the model's deleted at value from the array of values passed
// to the command.
$statusValue = false;
if ($command->offsetExists(Model::DELETED_AT))
{
$statusValue = $command->offsetGet(Model::DELETED_AT);
}
elseif ($command->offsetExists('_kmd'))
{
$_kmd = array_dot($command->offsetGet('_kmd'));
$statusField = MODEL::DELETED_AT;
$statusField = str_replace('_kmd.', '', MODEL::DELETED_AT);
if (array_key_exists($statusField, $_kmd))
{
$statusValue = $_kmd[$statusField];
}
}
// Could not determine the status field.
if ($statusValue === false)
{
return;
}
// Suspend the user.
elseif (!is_null($statusValue))
{
$event->stopPropagation();
$suspendCommand = $client->getCommand('deleteEntity', array(
'collection' => 'user',
'_id' => $command->offsetGet('_id'),
));
$suspendCommand->execute();
}
// Restore.
else
{
$event->stopPropagation();
$restoreCommand = $client->getCommand('restore', array(
'_id' => $command->offsetGet('_id'),
));
$restoreCommand->execute();
}
} | php | public function beforePrepare(Event $event)
{
$command = $event['command'];
$operation = $command->getOperation();
$client = $command->getClient();
if ($command->getName() !== 'updateEntity') return;
if ($operation->getParam('collection')->getDefault() !== 'user') return;
// Attempt to get the model's deleted at value from the array of values passed
// to the command.
$statusValue = false;
if ($command->offsetExists(Model::DELETED_AT))
{
$statusValue = $command->offsetGet(Model::DELETED_AT);
}
elseif ($command->offsetExists('_kmd'))
{
$_kmd = array_dot($command->offsetGet('_kmd'));
$statusField = MODEL::DELETED_AT;
$statusField = str_replace('_kmd.', '', MODEL::DELETED_AT);
if (array_key_exists($statusField, $_kmd))
{
$statusValue = $_kmd[$statusField];
}
}
// Could not determine the status field.
if ($statusValue === false)
{
return;
}
// Suspend the user.
elseif (!is_null($statusValue))
{
$event->stopPropagation();
$suspendCommand = $client->getCommand('deleteEntity', array(
'collection' => 'user',
'_id' => $command->offsetGet('_id'),
));
$suspendCommand->execute();
}
// Restore.
else
{
$event->stopPropagation();
$restoreCommand = $client->getCommand('restore', array(
'_id' => $command->offsetGet('_id'),
));
$restoreCommand->execute();
}
} | [
"public",
"function",
"beforePrepare",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"command",
"=",
"$",
"event",
"[",
"'command'",
"]",
";",
"$",
"operation",
"=",
"$",
"command",
"->",
"getOperation",
"(",
")",
";",
"$",
"client",
"=",
"$",
"command",
"->",
"getClient",
"(",
")",
";",
"if",
"(",
"$",
"command",
"->",
"getName",
"(",
")",
"!==",
"'updateEntity'",
")",
"return",
";",
"if",
"(",
"$",
"operation",
"->",
"getParam",
"(",
"'collection'",
")",
"->",
"getDefault",
"(",
")",
"!==",
"'user'",
")",
"return",
";",
"// Attempt to get the model's deleted at value from the array of values passed",
"// to the command.",
"$",
"statusValue",
"=",
"false",
";",
"if",
"(",
"$",
"command",
"->",
"offsetExists",
"(",
"Model",
"::",
"DELETED_AT",
")",
")",
"{",
"$",
"statusValue",
"=",
"$",
"command",
"->",
"offsetGet",
"(",
"Model",
"::",
"DELETED_AT",
")",
";",
"}",
"elseif",
"(",
"$",
"command",
"->",
"offsetExists",
"(",
"'_kmd'",
")",
")",
"{",
"$",
"_kmd",
"=",
"array_dot",
"(",
"$",
"command",
"->",
"offsetGet",
"(",
"'_kmd'",
")",
")",
";",
"$",
"statusField",
"=",
"MODEL",
"::",
"DELETED_AT",
";",
"$",
"statusField",
"=",
"str_replace",
"(",
"'_kmd.'",
",",
"''",
",",
"MODEL",
"::",
"DELETED_AT",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"statusField",
",",
"$",
"_kmd",
")",
")",
"{",
"$",
"statusValue",
"=",
"$",
"_kmd",
"[",
"$",
"statusField",
"]",
";",
"}",
"}",
"// Could not determine the status field.",
"if",
"(",
"$",
"statusValue",
"===",
"false",
")",
"{",
"return",
";",
"}",
"// Suspend the user.",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"statusValue",
")",
")",
"{",
"$",
"event",
"->",
"stopPropagation",
"(",
")",
";",
"$",
"suspendCommand",
"=",
"$",
"client",
"->",
"getCommand",
"(",
"'deleteEntity'",
",",
"array",
"(",
"'collection'",
"=>",
"'user'",
",",
"'_id'",
"=>",
"$",
"command",
"->",
"offsetGet",
"(",
"'_id'",
")",
",",
")",
")",
";",
"$",
"suspendCommand",
"->",
"execute",
"(",
")",
";",
"}",
"// Restore.",
"else",
"{",
"$",
"event",
"->",
"stopPropagation",
"(",
")",
";",
"$",
"restoreCommand",
"=",
"$",
"client",
"->",
"getCommand",
"(",
"'restore'",
",",
"array",
"(",
"'_id'",
"=>",
"$",
"command",
"->",
"offsetGet",
"(",
"'_id'",
")",
",",
")",
")",
";",
"$",
"restoreCommand",
"->",
"execute",
"(",
")",
";",
"}",
"}"
] | Map Laravel's soft delete action to Kinvey's user suspend
endpoint.
@param Guzzle\Common\Event
@return void | [
"Map",
"Laravel",
"s",
"soft",
"delete",
"action",
"to",
"Kinvey",
"s",
"user",
"suspend",
"endpoint",
"."
] | 8a25dafdf80a933384dfcfe8b70b0a7663fe9289 | https://github.com/GovTribe/laravel-kinvey/blob/8a25dafdf80a933384dfcfe8b70b0a7663fe9289/src/GovTribe/LaravelKinvey/Client/Plugins/KinveyUserSoftDeletePlugin.php#L26-L82 |
1,812 | mozartk/process-finder | src/ProcessFinder.php | ProcessFinder.getProcess | public function getProcess($pid = null)
{
if (is_null($pid)) {
$pid = $this->pid;
}
if (is_null($pid)) {
throw new ProcessFinderException('Pid is required');
}
$process = $this->api->getProcessByPid($pid);
return count($process) ? $process[0] : false;
} | php | public function getProcess($pid = null)
{
if (is_null($pid)) {
$pid = $this->pid;
}
if (is_null($pid)) {
throw new ProcessFinderException('Pid is required');
}
$process = $this->api->getProcessByPid($pid);
return count($process) ? $process[0] : false;
} | [
"public",
"function",
"getProcess",
"(",
"$",
"pid",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"pid",
")",
")",
"{",
"$",
"pid",
"=",
"$",
"this",
"->",
"pid",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"pid",
")",
")",
"{",
"throw",
"new",
"ProcessFinderException",
"(",
"'Pid is required'",
")",
";",
"}",
"$",
"process",
"=",
"$",
"this",
"->",
"api",
"->",
"getProcessByPid",
"(",
"$",
"pid",
")",
";",
"return",
"count",
"(",
"$",
"process",
")",
"?",
"$",
"process",
"[",
"0",
"]",
":",
"false",
";",
"}"
] | If the process exists will return the array
else if not found will return false.
@param null $pid
@return \mozartk\ProcessFinder\Process|boolean
@throws \mozartk\ProcessFinder\Exception\ProcessFinderException | [
"If",
"the",
"process",
"exists",
"will",
"return",
"the",
"array",
"else",
"if",
"not",
"found",
"will",
"return",
"false",
"."
] | 8e45b1b81909646ccf6c0d4a66fbd5a6d00056bb | https://github.com/mozartk/process-finder/blob/8e45b1b81909646ccf6c0d4a66fbd5a6d00056bb/src/ProcessFinder.php#L81-L94 |
1,813 | rafflesargentina/l5-user-action | src/Traits/PackageSettings.php | PackageSettings.getRouteName | public function getRouteName($resourceName = null, $action)
{
$resourceName = $resourceName ?? $this->resourceName;
return $this->alias.$resourceName.'.'.$action;
} | php | public function getRouteName($resourceName = null, $action)
{
$resourceName = $resourceName ?? $this->resourceName;
return $this->alias.$resourceName.'.'.$action;
} | [
"public",
"function",
"getRouteName",
"(",
"$",
"resourceName",
"=",
"null",
",",
"$",
"action",
")",
"{",
"$",
"resourceName",
"=",
"$",
"resourceName",
"??",
"$",
"this",
"->",
"resourceName",
";",
"return",
"$",
"this",
"->",
"alias",
".",
"$",
"resourceName",
".",
"'.'",
".",
"$",
"action",
";",
"}"
] | Get route name for the specified resource and action.
@param string|null $resourceName The name of the resource.
@param string $action The action.
@return string | [
"Get",
"route",
"name",
"for",
"the",
"specified",
"resource",
"and",
"action",
"."
] | eb13dd46bf8b45e498104bd14527afa0625f7ee1 | https://github.com/rafflesargentina/l5-user-action/blob/eb13dd46bf8b45e498104bd14527afa0625f7ee1/src/Traits/PackageSettings.php#L57-L61 |
1,814 | rafflesargentina/l5-user-action | src/Traits/PackageSettings.php | PackageSettings.getViewsLocation | public function getViewsLocation($resourceName = null)
{
$resourceName = $resourceName ?? $this->resourceName;
return $this->module.$this->theme.$resourceName;
} | php | public function getViewsLocation($resourceName = null)
{
$resourceName = $resourceName ?? $this->resourceName;
return $this->module.$this->theme.$resourceName;
} | [
"public",
"function",
"getViewsLocation",
"(",
"$",
"resourceName",
"=",
"null",
")",
"{",
"$",
"resourceName",
"=",
"$",
"resourceName",
"??",
"$",
"this",
"->",
"resourceName",
";",
"return",
"$",
"this",
"->",
"module",
".",
"$",
"this",
"->",
"theme",
".",
"$",
"resourceName",
";",
"}"
] | Get views location for the specified resource.
@param string $resourceName The name of the resource
@return string | [
"Get",
"views",
"location",
"for",
"the",
"specified",
"resource",
"."
] | eb13dd46bf8b45e498104bd14527afa0625f7ee1 | https://github.com/rafflesargentina/l5-user-action/blob/eb13dd46bf8b45e498104bd14527afa0625f7ee1/src/Traits/PackageSettings.php#L70-L74 |
1,815 | rafflesargentina/l5-user-action | src/Traits/PackageSettings.php | PackageSettings.getVendorViewsLocation | public function getVendorViewsLocation($resourceName = null)
{
$resourceName = $resourceName ?? $this->resourceName;
if ($this->package) {
$package = str_finish($this->package, '.');
}
return 'vendor.'.$package.$this->theme.$resourceName;
} | php | public function getVendorViewsLocation($resourceName = null)
{
$resourceName = $resourceName ?? $this->resourceName;
if ($this->package) {
$package = str_finish($this->package, '.');
}
return 'vendor.'.$package.$this->theme.$resourceName;
} | [
"public",
"function",
"getVendorViewsLocation",
"(",
"$",
"resourceName",
"=",
"null",
")",
"{",
"$",
"resourceName",
"=",
"$",
"resourceName",
"??",
"$",
"this",
"->",
"resourceName",
";",
"if",
"(",
"$",
"this",
"->",
"package",
")",
"{",
"$",
"package",
"=",
"str_finish",
"(",
"$",
"this",
"->",
"package",
",",
"'.'",
")",
";",
"}",
"return",
"'vendor.'",
".",
"$",
"package",
".",
"$",
"this",
"->",
"theme",
".",
"$",
"resourceName",
";",
"}"
] | Get vendor views location for the specified resource.
@param string $resourceName The name of the resource
@return string | [
"Get",
"vendor",
"views",
"location",
"for",
"the",
"specified",
"resource",
"."
] | eb13dd46bf8b45e498104bd14527afa0625f7ee1 | https://github.com/rafflesargentina/l5-user-action/blob/eb13dd46bf8b45e498104bd14527afa0625f7ee1/src/Traits/PackageSettings.php#L83-L92 |
1,816 | cobonto/module | src/Classes/Translation/ModuleFileLoader.php | ModuleFileLoader.loadModulePath | protected function loadModulePath($path, $locale, $name,$author)
{
if ($this->files->exists($full = "{$path}/{$author}/{$name}/translate/{$locale}.php")) {
return $this->files->getRequire($full);
}
return [];
} | php | protected function loadModulePath($path, $locale, $name,$author)
{
if ($this->files->exists($full = "{$path}/{$author}/{$name}/translate/{$locale}.php")) {
return $this->files->getRequire($full);
}
return [];
} | [
"protected",
"function",
"loadModulePath",
"(",
"$",
"path",
",",
"$",
"locale",
",",
"$",
"name",
",",
"$",
"author",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"full",
"=",
"\"{$path}/{$author}/{$name}/translate/{$locale}.php\"",
")",
")",
"{",
"return",
"$",
"this",
"->",
"files",
"->",
"getRequire",
"(",
"$",
"full",
")",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | load module file translated
@param $path
@param $locale
@param $name
@param $author
@return array|mixed
@throws \Illuminate\Contracts\Filesystem\FileNotFoundException | [
"load",
"module",
"file",
"translated"
] | 0978b5305c3d6f13ef7e0e5297855bd09eee6b76 | https://github.com/cobonto/module/blob/0978b5305c3d6f13ef7e0e5297855bd09eee6b76/src/Classes/Translation/ModuleFileLoader.php#L15-L21 |
1,817 | cobonto/module | src/Classes/Translation/ModuleFileLoader.php | ModuleFileLoader.loadModule | public function loadModule($locale, $name,$author)
{
if (isset($this->hints['Modules'])) {
return $this->loadModulePath($this->hints['Modules'], $locale, $name,$author);
}
return [];
} | php | public function loadModule($locale, $name,$author)
{
if (isset($this->hints['Modules'])) {
return $this->loadModulePath($this->hints['Modules'], $locale, $name,$author);
}
return [];
} | [
"public",
"function",
"loadModule",
"(",
"$",
"locale",
",",
"$",
"name",
",",
"$",
"author",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hints",
"[",
"'Modules'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"loadModulePath",
"(",
"$",
"this",
"->",
"hints",
"[",
"'Modules'",
"]",
",",
"$",
"locale",
",",
"$",
"name",
",",
"$",
"author",
")",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | get file from modules
@param $locale
@param $name
@param $author
@return array | [
"get",
"file",
"from",
"modules"
] | 0978b5305c3d6f13ef7e0e5297855bd09eee6b76 | https://github.com/cobonto/module/blob/0978b5305c3d6f13ef7e0e5297855bd09eee6b76/src/Classes/Translation/ModuleFileLoader.php#L30-L37 |
1,818 | Jinxes/layton | Layton/Console/Command.php | Command.run | public function run($argv)
{
$args = $this->getArgs($argv);
if (array_key_exists($args[1], $this->commands)) {
$callback = $this->commands[$args[1]];
$args = array_slice($args, 2);
if (is_callable($callback)) {
return $this->injectionClosure($callback, $args);
}
if (is_string($callback)) {
if (strpos($callback, '>') !== false) {
list($controller, $method) = explode('>', $callback);
return $this->injectionClass($controller, $method, $args);
}
return $this->injectionClass($callback, '__invoke', $args);
}
}
throw new \Exception('command line callback not found.');
} | php | public function run($argv)
{
$args = $this->getArgs($argv);
if (array_key_exists($args[1], $this->commands)) {
$callback = $this->commands[$args[1]];
$args = array_slice($args, 2);
if (is_callable($callback)) {
return $this->injectionClosure($callback, $args);
}
if (is_string($callback)) {
if (strpos($callback, '>') !== false) {
list($controller, $method) = explode('>', $callback);
return $this->injectionClass($controller, $method, $args);
}
return $this->injectionClass($callback, '__invoke', $args);
}
}
throw new \Exception('command line callback not found.');
} | [
"public",
"function",
"run",
"(",
"$",
"argv",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"getArgs",
"(",
"$",
"argv",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"this",
"->",
"commands",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"commands",
"[",
"$",
"args",
"[",
"1",
"]",
"]",
";",
"$",
"args",
"=",
"array_slice",
"(",
"$",
"args",
",",
"2",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"$",
"this",
"->",
"injectionClosure",
"(",
"$",
"callback",
",",
"$",
"args",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"callback",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"callback",
",",
"'>'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"controller",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"'>'",
",",
"$",
"callback",
")",
";",
"return",
"$",
"this",
"->",
"injectionClass",
"(",
"$",
"controller",
",",
"$",
"method",
",",
"$",
"args",
")",
";",
"}",
"return",
"$",
"this",
"->",
"injectionClass",
"(",
"$",
"callback",
",",
"'__invoke'",
",",
"$",
"args",
")",
";",
"}",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'command line callback not found.'",
")",
";",
"}"
] | Match and run a command line.
@param array $argv The cli args | [
"Match",
"and",
"run",
"a",
"command",
"line",
"."
] | 27b8eab2c59b9887eb93e40a533eb77cc5690584 | https://github.com/Jinxes/layton/blob/27b8eab2c59b9887eb93e40a533eb77cc5690584/Layton/Console/Command.php#L37-L58 |
1,819 | YiMAproject/yimaJquery | src/yimaJquery/Deliveries/Cdn.php | Cdn.getLibSrc | public function getLibSrc($ver)
{
if (!$this->isValidVersion($ver)) {
throw new \Exception(
sprintf(
'Invalid library version provided "%s"',
$ver
)
);
}
$options = $this->options;
$cdnUrl = rtrim($options['cdn-base'], '/').'/'.
trim($options['cdn-subfolder'], '/').'/'.
$ver.'/'.
trim($options['cdn-file-path'], '/');
return $cdnUrl;
} | php | public function getLibSrc($ver)
{
if (!$this->isValidVersion($ver)) {
throw new \Exception(
sprintf(
'Invalid library version provided "%s"',
$ver
)
);
}
$options = $this->options;
$cdnUrl = rtrim($options['cdn-base'], '/').'/'.
trim($options['cdn-subfolder'], '/').'/'.
$ver.'/'.
trim($options['cdn-file-path'], '/');
return $cdnUrl;
} | [
"public",
"function",
"getLibSrc",
"(",
"$",
"ver",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidVersion",
"(",
"$",
"ver",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Invalid library version provided \"%s\"'",
",",
"$",
"ver",
")",
")",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"options",
";",
"$",
"cdnUrl",
"=",
"rtrim",
"(",
"$",
"options",
"[",
"'cdn-base'",
"]",
",",
"'/'",
")",
".",
"'/'",
".",
"trim",
"(",
"$",
"options",
"[",
"'cdn-subfolder'",
"]",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"ver",
".",
"'/'",
".",
"trim",
"(",
"$",
"options",
"[",
"'cdn-file-path'",
"]",
",",
"'/'",
")",
";",
"return",
"$",
"cdnUrl",
";",
"}"
] | Get src to library for specific version
@param string $ver Version of library | [
"Get",
"src",
"to",
"library",
"for",
"specific",
"version"
] | 5c19fc17397a57c74e3c9f5ff4ff067a3beaf2cc | https://github.com/YiMAproject/yimaJquery/blob/5c19fc17397a57c74e3c9f5ff4ff067a3beaf2cc/src/yimaJquery/Deliveries/Cdn.php#L25-L43 |
1,820 | samurai-fw/samurai | src/Samurai/Component/Migration/Phinx/CodeGenerator.php | CodeGenerator.generateTableOptions | public function generateTableOptions(Table $table)
{
$code = [];
$options = $table->getOptions();
$code = $this->valuetize($options);
return $code === '[]' ? '' : ', ' . $code;
} | php | public function generateTableOptions(Table $table)
{
$code = [];
$options = $table->getOptions();
$code = $this->valuetize($options);
return $code === '[]' ? '' : ', ' . $code;
} | [
"public",
"function",
"generateTableOptions",
"(",
"Table",
"$",
"table",
")",
"{",
"$",
"code",
"=",
"[",
"]",
";",
"$",
"options",
"=",
"$",
"table",
"->",
"getOptions",
"(",
")",
";",
"$",
"code",
"=",
"$",
"this",
"->",
"valuetize",
"(",
"$",
"options",
")",
";",
"return",
"$",
"code",
"===",
"'[]'",
"?",
"''",
":",
"', '",
".",
"$",
"code",
";",
"}"
] | generate table options
@param Table $table
@return string | [
"generate",
"table",
"options"
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Migration/Phinx/CodeGenerator.php#L53-L60 |
1,821 | samurai-fw/samurai | src/Samurai/Component/Migration/Phinx/CodeGenerator.php | CodeGenerator.generateColumnOptions | public function generateColumnOptions(Column $column)
{
$options = [];
$keys = ['length', 'default', 'collation', 'null', 'precision', 'scale', 'after', 'update', 'comment'];
foreach ($keys as $key) {
$method = "get{$key}";
if ($key === 'length') $method = 'getLimit';
$value = $column->$method();
if ($key === 'collation') {
if ($value === null) {
$key = 'charset';
$value = $column->getCharset();
}
}
if ($value === null) continue;
if ($key === 'null' && $value === false) continue;
$options[$key] = $value;
}
$code = $this->valuetize($options);
return $code === '[]' ? '' : ', ' . $code;
} | php | public function generateColumnOptions(Column $column)
{
$options = [];
$keys = ['length', 'default', 'collation', 'null', 'precision', 'scale', 'after', 'update', 'comment'];
foreach ($keys as $key) {
$method = "get{$key}";
if ($key === 'length') $method = 'getLimit';
$value = $column->$method();
if ($key === 'collation') {
if ($value === null) {
$key = 'charset';
$value = $column->getCharset();
}
}
if ($value === null) continue;
if ($key === 'null' && $value === false) continue;
$options[$key] = $value;
}
$code = $this->valuetize($options);
return $code === '[]' ? '' : ', ' . $code;
} | [
"public",
"function",
"generateColumnOptions",
"(",
"Column",
"$",
"column",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"$",
"keys",
"=",
"[",
"'length'",
",",
"'default'",
",",
"'collation'",
",",
"'null'",
",",
"'precision'",
",",
"'scale'",
",",
"'after'",
",",
"'update'",
",",
"'comment'",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"method",
"=",
"\"get{$key}\"",
";",
"if",
"(",
"$",
"key",
"===",
"'length'",
")",
"$",
"method",
"=",
"'getLimit'",
";",
"$",
"value",
"=",
"$",
"column",
"->",
"$",
"method",
"(",
")",
";",
"if",
"(",
"$",
"key",
"===",
"'collation'",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"key",
"=",
"'charset'",
";",
"$",
"value",
"=",
"$",
"column",
"->",
"getCharset",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"continue",
";",
"if",
"(",
"$",
"key",
"===",
"'null'",
"&&",
"$",
"value",
"===",
"false",
")",
"continue",
";",
"$",
"options",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"code",
"=",
"$",
"this",
"->",
"valuetize",
"(",
"$",
"options",
")",
";",
"return",
"$",
"code",
"===",
"'[]'",
"?",
"''",
":",
"', '",
".",
"$",
"code",
";",
"}"
] | generate column options
@param Column $column
@return string | [
"generate",
"column",
"options"
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Migration/Phinx/CodeGenerator.php#L69-L94 |
1,822 | samurai-fw/samurai | src/Samurai/Component/Migration/Phinx/CodeGenerator.php | CodeGenerator.isSinglePrimaryKeyColumn | public function isSinglePrimaryKeyColumn(Table $table, Column $column)
{
$options = $table->getOptions();
if (! $options && $column->getName() === 'id') return true;
if (isset($options['id']) && $options['id'] == $column->getName()) return true;
return false;
} | php | public function isSinglePrimaryKeyColumn(Table $table, Column $column)
{
$options = $table->getOptions();
if (! $options && $column->getName() === 'id') return true;
if (isset($options['id']) && $options['id'] == $column->getName()) return true;
return false;
} | [
"public",
"function",
"isSinglePrimaryKeyColumn",
"(",
"Table",
"$",
"table",
",",
"Column",
"$",
"column",
")",
"{",
"$",
"options",
"=",
"$",
"table",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"!",
"$",
"options",
"&&",
"$",
"column",
"->",
"getName",
"(",
")",
"===",
"'id'",
")",
"return",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'id'",
"]",
")",
"&&",
"$",
"options",
"[",
"'id'",
"]",
"==",
"$",
"column",
"->",
"getName",
"(",
")",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
] | is single primary key column ?
@param Table $table
@param Column $column
@return boolean | [
"is",
"single",
"primary",
"key",
"column",
"?"
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Migration/Phinx/CodeGenerator.php#L135-L143 |
1,823 | tux-rampage/rampage-php | library/rampage/core/services/LazyFactoryDelegate.php | LazyFactoryDelegate.createFactory | protected function createFactory()
{
if (!class_exists($this->factoryClass)) {
throw new RuntimeException(sprintf(
'Failed to create an instance of non-existing factory class "%s".',
$this->factoryClass
));
}
$class = $this->factoryClass;
switch (count($this->args)) {
case 0:
$factory = new $class();
break;
case 1:
$factory = new $class($this->args[0]);
break;
case 2:
$factory = new $class($this->args[0], $this->args[1]);
break;
case 3:
$factory = new $class($this->args[0], $this->args[1], $this->args[2]);
break;
case 4:
$factory = new $class($this->args[0], $this->args[1], $this->args[2], $this->args[3]);
break;
default:
$reflection = new ClassReflection($class);
$factory = $reflection->newInstanceArgs($this->args);
break;
}
if (!$factory instanceof FactoryInterface) {
throw new LogicException(sprintf(
'Invalid service factory. Factory is expected to be an instance of %s, %s given.',
'Zend\ServiceManager\FactoryInterface',
get_class($factory)
));
}
return $factory;
} | php | protected function createFactory()
{
if (!class_exists($this->factoryClass)) {
throw new RuntimeException(sprintf(
'Failed to create an instance of non-existing factory class "%s".',
$this->factoryClass
));
}
$class = $this->factoryClass;
switch (count($this->args)) {
case 0:
$factory = new $class();
break;
case 1:
$factory = new $class($this->args[0]);
break;
case 2:
$factory = new $class($this->args[0], $this->args[1]);
break;
case 3:
$factory = new $class($this->args[0], $this->args[1], $this->args[2]);
break;
case 4:
$factory = new $class($this->args[0], $this->args[1], $this->args[2], $this->args[3]);
break;
default:
$reflection = new ClassReflection($class);
$factory = $reflection->newInstanceArgs($this->args);
break;
}
if (!$factory instanceof FactoryInterface) {
throw new LogicException(sprintf(
'Invalid service factory. Factory is expected to be an instance of %s, %s given.',
'Zend\ServiceManager\FactoryInterface',
get_class($factory)
));
}
return $factory;
} | [
"protected",
"function",
"createFactory",
"(",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"this",
"->",
"factoryClass",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Failed to create an instance of non-existing factory class \"%s\".'",
",",
"$",
"this",
"->",
"factoryClass",
")",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"factoryClass",
";",
"switch",
"(",
"count",
"(",
"$",
"this",
"->",
"args",
")",
")",
"{",
"case",
"0",
":",
"$",
"factory",
"=",
"new",
"$",
"class",
"(",
")",
";",
"break",
";",
"case",
"1",
":",
"$",
"factory",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"args",
"[",
"0",
"]",
")",
";",
"break",
";",
"case",
"2",
":",
"$",
"factory",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"args",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"args",
"[",
"1",
"]",
")",
";",
"break",
";",
"case",
"3",
":",
"$",
"factory",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"args",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"args",
"[",
"1",
"]",
",",
"$",
"this",
"->",
"args",
"[",
"2",
"]",
")",
";",
"break",
";",
"case",
"4",
":",
"$",
"factory",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"args",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"args",
"[",
"1",
"]",
",",
"$",
"this",
"->",
"args",
"[",
"2",
"]",
",",
"$",
"this",
"->",
"args",
"[",
"3",
"]",
")",
";",
"break",
";",
"default",
":",
"$",
"reflection",
"=",
"new",
"ClassReflection",
"(",
"$",
"class",
")",
";",
"$",
"factory",
"=",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"this",
"->",
"args",
")",
";",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"factory",
"instanceof",
"FactoryInterface",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'Invalid service factory. Factory is expected to be an instance of %s, %s given.'",
",",
"'Zend\\ServiceManager\\FactoryInterface'",
",",
"get_class",
"(",
"$",
"factory",
")",
")",
")",
";",
"}",
"return",
"$",
"factory",
";",
"}"
] | Create the factory on demand
@throws RuntimeException
@throws LogicException
@return Ambigous <\Zend\ServiceManager\FactoryInterface, unknown> | [
"Create",
"the",
"factory",
"on",
"demand"
] | 1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf | https://github.com/tux-rampage/rampage-php/blob/1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf/library/rampage/core/services/LazyFactoryDelegate.php#L72-L119 |
1,824 | jivoo/http | src/Route/RouteBase.php | RouteBase.stripAttributes | public static function stripAttributes($routeString, &$route, $withParameters = true)
{
$route['query'] = [];
$route['fragment'] = '';
$route['parameters'] = [];
$regex = '/^(.*?)(?:\?([^?#]*))?(?:#([^#?]*))?$/';
preg_match($regex, $routeString, $matches);
if (isset($matches[2])) {
parse_str($matches[2], $query);
$route['query'] = $query;
}
if (isset($matches[3])) {
$route['fragment'] = $matches[3];
}
if ($withParameters) {
// TODO: implement
}
return $matches[1];
} | php | public static function stripAttributes($routeString, &$route, $withParameters = true)
{
$route['query'] = [];
$route['fragment'] = '';
$route['parameters'] = [];
$regex = '/^(.*?)(?:\?([^?#]*))?(?:#([^#?]*))?$/';
preg_match($regex, $routeString, $matches);
if (isset($matches[2])) {
parse_str($matches[2], $query);
$route['query'] = $query;
}
if (isset($matches[3])) {
$route['fragment'] = $matches[3];
}
if ($withParameters) {
// TODO: implement
}
return $matches[1];
} | [
"public",
"static",
"function",
"stripAttributes",
"(",
"$",
"routeString",
",",
"&",
"$",
"route",
",",
"$",
"withParameters",
"=",
"true",
")",
"{",
"$",
"route",
"[",
"'query'",
"]",
"=",
"[",
"]",
";",
"$",
"route",
"[",
"'fragment'",
"]",
"=",
"''",
";",
"$",
"route",
"[",
"'parameters'",
"]",
"=",
"[",
"]",
";",
"$",
"regex",
"=",
"'/^(.*?)(?:\\?([^?#]*))?(?:#([^#?]*))?$/'",
";",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"routeString",
",",
"$",
"matches",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
")",
"{",
"parse_str",
"(",
"$",
"matches",
"[",
"2",
"]",
",",
"$",
"query",
")",
";",
"$",
"route",
"[",
"'query'",
"]",
"=",
"$",
"query",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
")",
"{",
"$",
"route",
"[",
"'fragment'",
"]",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"if",
"(",
"$",
"withParameters",
")",
"{",
"// TODO: implement",
"}",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}"
] | Strip fragment, query and optionally parameters from a route string.
@param string $routeString The route string.
@param array $route A route array to insert attributes into.
@param bool $withParameters Whether to also read parameters from the
route string.
@return string The route string without attributes. | [
"Strip",
"fragment",
"query",
"and",
"optionally",
"parameters",
"from",
"a",
"route",
"string",
"."
] | 3c1d8dba66978bc91fc2b324dd941e5da3b253bc | https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Route/RouteBase.php#L110-L128 |
1,825 | Dhii/di-abstract | src/AssignDefinitionContainerCapableTrait.php | AssignDefinitionContainerCapableTrait._assignDefinitionContainer | protected function _assignDefinitionContainer(callable $definition, BaseContainerInterface $container)
{
return function (BaseContainerInterface $c) use ($definition, $container) {
$args = func_get_args();
$args[0] = $container;
return $this->_invokeCallable($definition, $args);
};
} | php | protected function _assignDefinitionContainer(callable $definition, BaseContainerInterface $container)
{
return function (BaseContainerInterface $c) use ($definition, $container) {
$args = func_get_args();
$args[0] = $container;
return $this->_invokeCallable($definition, $args);
};
} | [
"protected",
"function",
"_assignDefinitionContainer",
"(",
"callable",
"$",
"definition",
",",
"BaseContainerInterface",
"$",
"container",
")",
"{",
"return",
"function",
"(",
"BaseContainerInterface",
"$",
"c",
")",
"use",
"(",
"$",
"definition",
",",
"$",
"container",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"args",
"[",
"0",
"]",
"=",
"$",
"container",
";",
"return",
"$",
"this",
"->",
"_invokeCallable",
"(",
"$",
"definition",
",",
"$",
"args",
")",
";",
"}",
";",
"}"
] | Wraps the given definition such that it will receive the given container.
The definition will receive the `$container` no matter what container it is invoked with.
All other arguments to the definition will be preserved.
This is very useful in converting existing definitions to use a different container,
possibly a composite one.
@since [*next-version*]
@param callable $definition The definition to assign the container to.
@param BaseContainerInterface $container The container to assign.
@return callable A definition that will be invoked with the given container. | [
"Wraps",
"the",
"given",
"definition",
"such",
"that",
"it",
"will",
"receive",
"the",
"given",
"container",
"."
] | badfa20def27e5c6883f1c1078c98603b7bee319 | https://github.com/Dhii/di-abstract/blob/badfa20def27e5c6883f1c1078c98603b7bee319/src/AssignDefinitionContainerCapableTrait.php#L34-L42 |
1,826 | synapsestudios/synapse-base | src/Synapse/Work/AbstractConsoleWork.php | AbstractConsoleWork.perform | public function perform()
{
$app = $this->application();
$command = $this->getConsoleCommand($app);
$inputDefinition = $this->getInputDefinition($this->args);
// Create Input object with $this->args loaded as Input arguments
$input = new ArrayInput($this->args, $inputDefinition);
$output = new ConsoleOutput;
// Output error details to the console if available
try {
$command->run($input, $output);
} catch (\Exception $e) {
$output->writeln('Exception: '.$e->getMessage());
$output->writeln('Code: '.$e->getCode());
$output->writeln('Stack trace: '.$e->getTraceAsString());
throw $e;
}
} | php | public function perform()
{
$app = $this->application();
$command = $this->getConsoleCommand($app);
$inputDefinition = $this->getInputDefinition($this->args);
// Create Input object with $this->args loaded as Input arguments
$input = new ArrayInput($this->args, $inputDefinition);
$output = new ConsoleOutput;
// Output error details to the console if available
try {
$command->run($input, $output);
} catch (\Exception $e) {
$output->writeln('Exception: '.$e->getMessage());
$output->writeln('Code: '.$e->getCode());
$output->writeln('Stack trace: '.$e->getTraceAsString());
throw $e;
}
} | [
"public",
"function",
"perform",
"(",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"application",
"(",
")",
";",
"$",
"command",
"=",
"$",
"this",
"->",
"getConsoleCommand",
"(",
"$",
"app",
")",
";",
"$",
"inputDefinition",
"=",
"$",
"this",
"->",
"getInputDefinition",
"(",
"$",
"this",
"->",
"args",
")",
";",
"// Create Input object with $this->args loaded as Input arguments",
"$",
"input",
"=",
"new",
"ArrayInput",
"(",
"$",
"this",
"->",
"args",
",",
"$",
"inputDefinition",
")",
";",
"$",
"output",
"=",
"new",
"ConsoleOutput",
";",
"// Output error details to the console if available",
"try",
"{",
"$",
"command",
"->",
"run",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Exception: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'Code: '",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'Stack trace: '",
".",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] | Manually load, configure, and run the console command
Inject $this->args as Input object arguments | [
"Manually",
"load",
"configure",
"and",
"run",
"the",
"console",
"command"
] | 60c830550491742a077ab063f924e2f0b63825da | https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Work/AbstractConsoleWork.php#L25-L47 |
1,827 | synapsestudios/synapse-base | src/Synapse/Work/AbstractConsoleWork.php | AbstractConsoleWork.application | protected function application()
{
// Initialize the Silex Application
$applicationInitializer = new ApplicationInitializer;
$app = $applicationInitializer->initialize();
// Set the default services
$defaultServices = new \Synapse\Application\Services;
$defaultServices->register($app);
// Set the application-specific services
$appServices = new \Application\Services;
$appServices->register($app);
return $app;
} | php | protected function application()
{
// Initialize the Silex Application
$applicationInitializer = new ApplicationInitializer;
$app = $applicationInitializer->initialize();
// Set the default services
$defaultServices = new \Synapse\Application\Services;
$defaultServices->register($app);
// Set the application-specific services
$appServices = new \Application\Services;
$appServices->register($app);
return $app;
} | [
"protected",
"function",
"application",
"(",
")",
"{",
"// Initialize the Silex Application",
"$",
"applicationInitializer",
"=",
"new",
"ApplicationInitializer",
";",
"$",
"app",
"=",
"$",
"applicationInitializer",
"->",
"initialize",
"(",
")",
";",
"// Set the default services",
"$",
"defaultServices",
"=",
"new",
"\\",
"Synapse",
"\\",
"Application",
"\\",
"Services",
";",
"$",
"defaultServices",
"->",
"register",
"(",
"$",
"app",
")",
";",
"// Set the application-specific services",
"$",
"appServices",
"=",
"new",
"\\",
"Application",
"\\",
"Services",
";",
"$",
"appServices",
"->",
"register",
"(",
"$",
"app",
")",
";",
"return",
"$",
"app",
";",
"}"
] | Return the Silex application loaded with all routes and services
@return Application | [
"Return",
"the",
"Silex",
"application",
"loaded",
"with",
"all",
"routes",
"and",
"services"
] | 60c830550491742a077ab063f924e2f0b63825da | https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Work/AbstractConsoleWork.php#L54-L70 |
1,828 | synapsestudios/synapse-base | src/Synapse/Work/AbstractConsoleWork.php | AbstractConsoleWork.getInputDefinition | protected function getInputDefinition(array $args)
{
$definition = new InputDefinition();
foreach ($args as $field => $value) {
$definition->addArgument(new InputArgument($field));
}
return $definition;
} | php | protected function getInputDefinition(array $args)
{
$definition = new InputDefinition();
foreach ($args as $field => $value) {
$definition->addArgument(new InputArgument($field));
}
return $definition;
} | [
"protected",
"function",
"getInputDefinition",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"definition",
"=",
"new",
"InputDefinition",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"definition",
"->",
"addArgument",
"(",
"new",
"InputArgument",
"(",
"$",
"field",
")",
")",
";",
"}",
"return",
"$",
"definition",
";",
"}"
] | Get an InputDefinition formed by the arguments provided
Effectively provides a passthrough for any input arguments provided
@param array $args Arguments
@return InputDefinition | [
"Get",
"an",
"InputDefinition",
"formed",
"by",
"the",
"arguments",
"provided"
] | 60c830550491742a077ab063f924e2f0b63825da | https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Work/AbstractConsoleWork.php#L80-L89 |
1,829 | jfortunato/fortune | src/Configuration/ResourceConfiguration.php | ResourceConfiguration.initializeConfig | protected function initializeConfig(array $config = null)
{
$default = $this->defaultConfigurations();
$this->config = $config ? array_replace_recursive($default, $config) : $default;
} | php | protected function initializeConfig(array $config = null)
{
$default = $this->defaultConfigurations();
$this->config = $config ? array_replace_recursive($default, $config) : $default;
} | [
"protected",
"function",
"initializeConfig",
"(",
"array",
"$",
"config",
"=",
"null",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"defaultConfigurations",
"(",
")",
";",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
"?",
"array_replace_recursive",
"(",
"$",
"default",
",",
"$",
"config",
")",
":",
"$",
"default",
";",
"}"
] | Overrides default configurations with user supplied values.
@param array $config
@return void | [
"Overrides",
"default",
"configurations",
"with",
"user",
"supplied",
"values",
"."
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/Configuration/ResourceConfiguration.php#L181-L186 |
1,830 | medooch/symfony-components | Medooch/Components/Controller/AbstractController.php | AbstractController.getTotalOfRecordsString | protected function getTotalOfRecordsString(int $totalOfRecords, array $data)
{
$show = $data['show'];
$page = $data['page'];
$startRecord = 0;
if (intval($totalOfRecords) > 0) {
$startRecord = ($show * ($page - 1)) + 1;
}
$endRecord = $show * $page;
if ($endRecord > $totalOfRecords) {
$endRecord = $totalOfRecords;
}
return $this->trans('totalOfRecordsString', [
'%$startRecord%' => $startRecord,
'%$endRecord%' => $endRecord,
'%$totalOfRecords%' => $totalOfRecords,
], 'messages');
} | php | protected function getTotalOfRecordsString(int $totalOfRecords, array $data)
{
$show = $data['show'];
$page = $data['page'];
$startRecord = 0;
if (intval($totalOfRecords) > 0) {
$startRecord = ($show * ($page - 1)) + 1;
}
$endRecord = $show * $page;
if ($endRecord > $totalOfRecords) {
$endRecord = $totalOfRecords;
}
return $this->trans('totalOfRecordsString', [
'%$startRecord%' => $startRecord,
'%$endRecord%' => $endRecord,
'%$totalOfRecords%' => $totalOfRecords,
], 'messages');
} | [
"protected",
"function",
"getTotalOfRecordsString",
"(",
"int",
"$",
"totalOfRecords",
",",
"array",
"$",
"data",
")",
"{",
"$",
"show",
"=",
"$",
"data",
"[",
"'show'",
"]",
";",
"$",
"page",
"=",
"$",
"data",
"[",
"'page'",
"]",
";",
"$",
"startRecord",
"=",
"0",
";",
"if",
"(",
"intval",
"(",
"$",
"totalOfRecords",
")",
">",
"0",
")",
"{",
"$",
"startRecord",
"=",
"(",
"$",
"show",
"*",
"(",
"$",
"page",
"-",
"1",
")",
")",
"+",
"1",
";",
"}",
"$",
"endRecord",
"=",
"$",
"show",
"*",
"$",
"page",
";",
"if",
"(",
"$",
"endRecord",
">",
"$",
"totalOfRecords",
")",
"{",
"$",
"endRecord",
"=",
"$",
"totalOfRecords",
";",
"}",
"return",
"$",
"this",
"->",
"trans",
"(",
"'totalOfRecordsString'",
",",
"[",
"'%$startRecord%'",
"=>",
"$",
"startRecord",
",",
"'%$endRecord%'",
"=>",
"$",
"endRecord",
",",
"'%$totalOfRecords%'",
"=>",
"$",
"totalOfRecords",
",",
"]",
",",
"'messages'",
")",
";",
"}"
] | Calculates the total of records string
@param int $totalOfRecords
@param array $data
@return string | [
"Calculates",
"the",
"total",
"of",
"records",
"string"
] | 77020fadf8341f9c7b23dcaa9eca47330589d995 | https://github.com/medooch/symfony-components/blob/77020fadf8341f9c7b23dcaa9eca47330589d995/Medooch/Components/Controller/AbstractController.php#L169-L188 |
1,831 | ncuesta/pinocchio | src/Pinocchio/Pinocchio.php | Pinocchio.setPath | public function setPath($path)
{
if (!is_readable($path)) {
throw new \InvalidArgumentException('The passed path is not readable: ' . $path);
}
$this->path = $path;
$this->source = file_get_contents($path);
return $this;
} | php | public function setPath($path)
{
if (!is_readable($path)) {
throw new \InvalidArgumentException('The passed path is not readable: ' . $path);
}
$this->path = $path;
$this->source = file_get_contents($path);
return $this;
} | [
"public",
"function",
"setPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The passed path is not readable: '",
".",
"$",
"path",
")",
";",
"}",
"$",
"this",
"->",
"path",
"=",
"$",
"path",
";",
"$",
"this",
"->",
"source",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the path to the source file.
@param string $path The path to the source file.
@return \Pinocchio\Pinocchio
@throws \InvalidArgumentException If $path is not a readable file. | [
"Set",
"the",
"path",
"to",
"the",
"source",
"file",
"."
] | 01b119a003362fd3a50e843341c62c95374d87cf | https://github.com/ncuesta/pinocchio/blob/01b119a003362fd3a50e843341c62c95374d87cf/src/Pinocchio/Pinocchio.php#L73-L83 |
1,832 | ncuesta/pinocchio | src/Pinocchio/Pinocchio.php | Pinocchio.getOutputFilename | public function getOutputFilename($prefix = null)
{
$fileInfo = $this->getFileInformation();
$filename = str_replace('/', '_', $fileInfo->getPathname());
if (null !== $prefix) {
$filename = substr($filename, strlen($prefix));
}
return strtr(ltrim($filename, '_'), array('.' . $fileInfo->getExtension() => '.html'));
} | php | public function getOutputFilename($prefix = null)
{
$fileInfo = $this->getFileInformation();
$filename = str_replace('/', '_', $fileInfo->getPathname());
if (null !== $prefix) {
$filename = substr($filename, strlen($prefix));
}
return strtr(ltrim($filename, '_'), array('.' . $fileInfo->getExtension() => '.html'));
} | [
"public",
"function",
"getOutputFilename",
"(",
"$",
"prefix",
"=",
"null",
")",
"{",
"$",
"fileInfo",
"=",
"$",
"this",
"->",
"getFileInformation",
"(",
")",
";",
"$",
"filename",
"=",
"str_replace",
"(",
"'/'",
",",
"'_'",
",",
"$",
"fileInfo",
"->",
"getPathname",
"(",
")",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"prefix",
")",
"{",
"$",
"filename",
"=",
"substr",
"(",
"$",
"filename",
",",
"strlen",
"(",
"$",
"prefix",
")",
")",
";",
"}",
"return",
"strtr",
"(",
"ltrim",
"(",
"$",
"filename",
",",
"'_'",
")",
",",
"array",
"(",
"'.'",
".",
"$",
"fileInfo",
"->",
"getExtension",
"(",
")",
"=>",
"'.html'",
")",
")",
";",
"}"
] | Get the name for this Pinocchio's output file.
@param string $prefix Prefix to remove from the filename (optional).
@return string | [
"Get",
"the",
"name",
"for",
"this",
"Pinocchio",
"s",
"output",
"file",
"."
] | 01b119a003362fd3a50e843341c62c95374d87cf | https://github.com/ncuesta/pinocchio/blob/01b119a003362fd3a50e843341c62c95374d87cf/src/Pinocchio/Pinocchio.php#L222-L232 |
1,833 | jeromeklam/freefw | src/FreeFW/Tools/Icu.php | Icu.parseResourceBundle | protected static function parseResourceBundle($p_rb, $p_prefix = '')
{
$p_prefix = rtrim($p_prefix, '.');
$values = array();
if ($p_rb instanceof \ResourceBundle) {
foreach ($p_rb as $k => $v) {
if (is_object($v)) {
$temp = self::parseResourceBundle($v, ($p_prefix == '' ? '' : $p_prefix . '.') .
print_r($k, true) . '.');
$values = array_merge($values, $temp);
} else {
$values[$p_prefix . '.' . $k] = $v;
}
}
}
return $values;
} | php | protected static function parseResourceBundle($p_rb, $p_prefix = '')
{
$p_prefix = rtrim($p_prefix, '.');
$values = array();
if ($p_rb instanceof \ResourceBundle) {
foreach ($p_rb as $k => $v) {
if (is_object($v)) {
$temp = self::parseResourceBundle($v, ($p_prefix == '' ? '' : $p_prefix . '.') .
print_r($k, true) . '.');
$values = array_merge($values, $temp);
} else {
$values[$p_prefix . '.' . $k] = $v;
}
}
}
return $values;
} | [
"protected",
"static",
"function",
"parseResourceBundle",
"(",
"$",
"p_rb",
",",
"$",
"p_prefix",
"=",
"''",
")",
"{",
"$",
"p_prefix",
"=",
"rtrim",
"(",
"$",
"p_prefix",
",",
"'.'",
")",
";",
"$",
"values",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"p_rb",
"instanceof",
"\\",
"ResourceBundle",
")",
"{",
"foreach",
"(",
"$",
"p_rb",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"v",
")",
")",
"{",
"$",
"temp",
"=",
"self",
"::",
"parseResourceBundle",
"(",
"$",
"v",
",",
"(",
"$",
"p_prefix",
"==",
"''",
"?",
"''",
":",
"$",
"p_prefix",
".",
"'.'",
")",
".",
"print_r",
"(",
"$",
"k",
",",
"true",
")",
".",
"'.'",
")",
";",
"$",
"values",
"=",
"array_merge",
"(",
"$",
"values",
",",
"$",
"temp",
")",
";",
"}",
"else",
"{",
"$",
"values",
"[",
"$",
"p_prefix",
".",
"'.'",
".",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"}",
"return",
"$",
"values",
";",
"}"
] | Parse des ressources
@param mixed $p_rb
@param string $p_prefix
@return array | [
"Parse",
"des",
"ressources"
] | 16ecf24192375c920a070296f396b9d3fd994a1e | https://github.com/jeromeklam/freefw/blob/16ecf24192375c920a070296f396b9d3fd994a1e/src/FreeFW/Tools/Icu.php#L26-L43 |
1,834 | jeromeklam/freefw | src/FreeFW/Tools/Icu.php | Icu.getAsArray | public static function getAsArray($p_name, $p_path, $p_prefix = '')
{
$ressource = new \ResourceBundle($p_name, $p_path);
$arr = self::parseResourceBundle($ressource, $p_prefix);
return $arr;
} | php | public static function getAsArray($p_name, $p_path, $p_prefix = '')
{
$ressource = new \ResourceBundle($p_name, $p_path);
$arr = self::parseResourceBundle($ressource, $p_prefix);
return $arr;
} | [
"public",
"static",
"function",
"getAsArray",
"(",
"$",
"p_name",
",",
"$",
"p_path",
",",
"$",
"p_prefix",
"=",
"''",
")",
"{",
"$",
"ressource",
"=",
"new",
"\\",
"ResourceBundle",
"(",
"$",
"p_name",
",",
"$",
"p_path",
")",
";",
"$",
"arr",
"=",
"self",
"::",
"parseResourceBundle",
"(",
"$",
"ressource",
",",
"$",
"p_prefix",
")",
";",
"return",
"$",
"arr",
";",
"}"
] | Retourne les traductions sous forme de tableau
@param string $p_name
@param string $p_path
@param string $p_prefix
@return array | [
"Retourne",
"les",
"traductions",
"sous",
"forme",
"de",
"tableau"
] | 16ecf24192375c920a070296f396b9d3fd994a1e | https://github.com/jeromeklam/freefw/blob/16ecf24192375c920a070296f396b9d3fd994a1e/src/FreeFW/Tools/Icu.php#L54-L60 |
1,835 | extendsframework/extends-router | src/Framework/Http/Middleware/Router/RouterMiddleware.php | RouterMiddleware.getMethodNotAllowedResponse | protected function getMethodNotAllowedResponse(MethodNotAllowed $exception): ResponseInterface
{
return (new Response())
->withStatusCode(405)
->withHeader('Allow', implode(', ', $exception->getAllowedMethods()))
->withBody([
'type' => '',
'title' => 'Method not allowed.',
'method' => $exception->getMethod(),
'allowed_methods' => $exception->getAllowedMethods(),
]);
} | php | protected function getMethodNotAllowedResponse(MethodNotAllowed $exception): ResponseInterface
{
return (new Response())
->withStatusCode(405)
->withHeader('Allow', implode(', ', $exception->getAllowedMethods()))
->withBody([
'type' => '',
'title' => 'Method not allowed.',
'method' => $exception->getMethod(),
'allowed_methods' => $exception->getAllowedMethods(),
]);
} | [
"protected",
"function",
"getMethodNotAllowedResponse",
"(",
"MethodNotAllowed",
"$",
"exception",
")",
":",
"ResponseInterface",
"{",
"return",
"(",
"new",
"Response",
"(",
")",
")",
"->",
"withStatusCode",
"(",
"405",
")",
"->",
"withHeader",
"(",
"'Allow'",
",",
"implode",
"(",
"', '",
",",
"$",
"exception",
"->",
"getAllowedMethods",
"(",
")",
")",
")",
"->",
"withBody",
"(",
"[",
"'type'",
"=>",
"''",
",",
"'title'",
"=>",
"'Method not allowed.'",
",",
"'method'",
"=>",
"$",
"exception",
"->",
"getMethod",
"(",
")",
",",
"'allowed_methods'",
"=>",
"$",
"exception",
"->",
"getAllowedMethods",
"(",
")",
",",
"]",
")",
";",
"}"
] | Get response for MethodNotAllowed exception.
@param MethodNotAllowed $exception
@return ResponseInterface | [
"Get",
"response",
"for",
"MethodNotAllowed",
"exception",
"."
] | 7c142749635c6fb1c58508bf3c8f594529e136d9 | https://github.com/extendsframework/extends-router/blob/7c142749635c6fb1c58508bf3c8f594529e136d9/src/Framework/Http/Middleware/Router/RouterMiddleware.php#L67-L78 |
1,836 | extendsframework/extends-router | src/Framework/Http/Middleware/Router/RouterMiddleware.php | RouterMiddleware.getNotFoundResponse | protected function getNotFoundResponse(NotFound $exception): ResponseInterface
{
return (new Response())
->withStatusCode(404)
->withBody([
'type' => '',
'title' => 'Not found.',
'path' => $exception
->getRequest()
->getUri()
->toRelative(),
]);
} | php | protected function getNotFoundResponse(NotFound $exception): ResponseInterface
{
return (new Response())
->withStatusCode(404)
->withBody([
'type' => '',
'title' => 'Not found.',
'path' => $exception
->getRequest()
->getUri()
->toRelative(),
]);
} | [
"protected",
"function",
"getNotFoundResponse",
"(",
"NotFound",
"$",
"exception",
")",
":",
"ResponseInterface",
"{",
"return",
"(",
"new",
"Response",
"(",
")",
")",
"->",
"withStatusCode",
"(",
"404",
")",
"->",
"withBody",
"(",
"[",
"'type'",
"=>",
"''",
",",
"'title'",
"=>",
"'Not found.'",
",",
"'path'",
"=>",
"$",
"exception",
"->",
"getRequest",
"(",
")",
"->",
"getUri",
"(",
")",
"->",
"toRelative",
"(",
")",
",",
"]",
")",
";",
"}"
] | Get response for NotFound exception.
@param NotFound $exception
@return ResponseInterface | [
"Get",
"response",
"for",
"NotFound",
"exception",
"."
] | 7c142749635c6fb1c58508bf3c8f594529e136d9 | https://github.com/extendsframework/extends-router/blob/7c142749635c6fb1c58508bf3c8f594529e136d9/src/Framework/Http/Middleware/Router/RouterMiddleware.php#L86-L98 |
1,837 | extendsframework/extends-router | src/Framework/Http/Middleware/Router/RouterMiddleware.php | RouterMiddleware.getInvalidQueryStringResponse | protected function getInvalidQueryStringResponse(InvalidQueryString $exception): ResponseInterface
{
return (new Response())
->withStatusCode(400)
->withBody([
'type' => '',
'title' => 'Invalid query string.',
'parameter' => $exception->getParameter(),
'reason' => $exception->getResult(),
]);
} | php | protected function getInvalidQueryStringResponse(InvalidQueryString $exception): ResponseInterface
{
return (new Response())
->withStatusCode(400)
->withBody([
'type' => '',
'title' => 'Invalid query string.',
'parameter' => $exception->getParameter(),
'reason' => $exception->getResult(),
]);
} | [
"protected",
"function",
"getInvalidQueryStringResponse",
"(",
"InvalidQueryString",
"$",
"exception",
")",
":",
"ResponseInterface",
"{",
"return",
"(",
"new",
"Response",
"(",
")",
")",
"->",
"withStatusCode",
"(",
"400",
")",
"->",
"withBody",
"(",
"[",
"'type'",
"=>",
"''",
",",
"'title'",
"=>",
"'Invalid query string.'",
",",
"'parameter'",
"=>",
"$",
"exception",
"->",
"getParameter",
"(",
")",
",",
"'reason'",
"=>",
"$",
"exception",
"->",
"getResult",
"(",
")",
",",
"]",
")",
";",
"}"
] | Get response for InvalidQueryString exception.
@param InvalidQueryString $exception
@return ResponseInterface | [
"Get",
"response",
"for",
"InvalidQueryString",
"exception",
"."
] | 7c142749635c6fb1c58508bf3c8f594529e136d9 | https://github.com/extendsframework/extends-router/blob/7c142749635c6fb1c58508bf3c8f594529e136d9/src/Framework/Http/Middleware/Router/RouterMiddleware.php#L106-L116 |
1,838 | tekkla/core-language | Core/Language/LanguageStorage.php | LanguageStorage.getText | public function getText($key)
{
if (isset($this->data[$key])) {
return $this->data[$key];
}
return $key;
} | php | public function getText($key)
{
if (isset($this->data[$key])) {
return $this->data[$key];
}
return $key;
} | [
"public",
"function",
"getText",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"key",
";",
"}"
] | Returns a language string by looking for a matching key
Will return the key when no machting entry is found.
@param string $key
The key to get text for
@return string | [
"Returns",
"a",
"language",
"string",
"by",
"looking",
"for",
"a",
"matching",
"key"
] | 42d4a2e9fd5f9a01bfc9427bbcdfaf9fc869ab58 | https://github.com/tekkla/core-language/blob/42d4a2e9fd5f9a01bfc9427bbcdfaf9fc869ab58/Core/Language/LanguageStorage.php#L26-L33 |
1,839 | n0m4dz/laracasa | Zend/Gdata/App/Entry.php | Zend_Gdata_App_Entry.save | public function save($uri = null, $className = null, $extraHeaders = array())
{
return $this->getService()->updateEntry($this,
$uri,
$className,
$extraHeaders);
} | php | public function save($uri = null, $className = null, $extraHeaders = array())
{
return $this->getService()->updateEntry($this,
$uri,
$className,
$extraHeaders);
} | [
"public",
"function",
"save",
"(",
"$",
"uri",
"=",
"null",
",",
"$",
"className",
"=",
"null",
",",
"$",
"extraHeaders",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getService",
"(",
")",
"->",
"updateEntry",
"(",
"$",
"this",
",",
"$",
"uri",
",",
"$",
"className",
",",
"$",
"extraHeaders",
")",
";",
"}"
] | Uploads changes in this entry to the server using Zend_Gdata_App
@param string|null $uri The URI to send requests to, or null if $data
contains the URI.
@param string|null $className The name of the class that should we
deserializing the server response. If null, then
'Zend_Gdata_App_Entry' will be used.
@param array $extraHeaders Extra headers to add to the request, as an
array of string-based key/value pairs.
@return Zend_Gdata_App_Entry The updated entry.
@throws Zend_Gdata_App_Exception | [
"Uploads",
"changes",
"in",
"this",
"entry",
"to",
"the",
"server",
"using",
"Zend_Gdata_App"
] | 6141f0c16c7d4453275e3b74be5041f336085c91 | https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/App/Entry.php#L204-L210 |
1,840 | n0m4dz/laracasa | Zend/Gdata/App/Entry.php | Zend_Gdata_App_Entry.reload | public function reload($uri = null, $className = null, $extraHeaders = array())
{
// Get URI
$editLink = $this->getEditLink();
if (($uri === null) && $editLink != null) {
$uri = $editLink->getHref();
}
// Set classname to current class, if not otherwise set
if ($className === null) {
$className = get_class($this);
}
// Append ETag, if present (Gdata v2 and above, only) and doesn't
// conflict with existing headers
if ($this->_etag != null
&& !array_key_exists('If-Match', $extraHeaders)
&& !array_key_exists('If-None-Match', $extraHeaders)) {
$extraHeaders['If-None-Match'] = $this->_etag;
}
// If an HTTP 304 status (Not Modified)is returned, then we return
// null.
$result = null;
try {
$result = $this->service->importUrl($uri, $className, $extraHeaders);
} catch (Zend_Gdata_App_HttpException $e) {
if ($e->getResponse()->getStatus() != '304')
throw $e;
}
return $result;
} | php | public function reload($uri = null, $className = null, $extraHeaders = array())
{
// Get URI
$editLink = $this->getEditLink();
if (($uri === null) && $editLink != null) {
$uri = $editLink->getHref();
}
// Set classname to current class, if not otherwise set
if ($className === null) {
$className = get_class($this);
}
// Append ETag, if present (Gdata v2 and above, only) and doesn't
// conflict with existing headers
if ($this->_etag != null
&& !array_key_exists('If-Match', $extraHeaders)
&& !array_key_exists('If-None-Match', $extraHeaders)) {
$extraHeaders['If-None-Match'] = $this->_etag;
}
// If an HTTP 304 status (Not Modified)is returned, then we return
// null.
$result = null;
try {
$result = $this->service->importUrl($uri, $className, $extraHeaders);
} catch (Zend_Gdata_App_HttpException $e) {
if ($e->getResponse()->getStatus() != '304')
throw $e;
}
return $result;
} | [
"public",
"function",
"reload",
"(",
"$",
"uri",
"=",
"null",
",",
"$",
"className",
"=",
"null",
",",
"$",
"extraHeaders",
"=",
"array",
"(",
")",
")",
"{",
"// Get URI",
"$",
"editLink",
"=",
"$",
"this",
"->",
"getEditLink",
"(",
")",
";",
"if",
"(",
"(",
"$",
"uri",
"===",
"null",
")",
"&&",
"$",
"editLink",
"!=",
"null",
")",
"{",
"$",
"uri",
"=",
"$",
"editLink",
"->",
"getHref",
"(",
")",
";",
"}",
"// Set classname to current class, if not otherwise set",
"if",
"(",
"$",
"className",
"===",
"null",
")",
"{",
"$",
"className",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"}",
"// Append ETag, if present (Gdata v2 and above, only) and doesn't",
"// conflict with existing headers",
"if",
"(",
"$",
"this",
"->",
"_etag",
"!=",
"null",
"&&",
"!",
"array_key_exists",
"(",
"'If-Match'",
",",
"$",
"extraHeaders",
")",
"&&",
"!",
"array_key_exists",
"(",
"'If-None-Match'",
",",
"$",
"extraHeaders",
")",
")",
"{",
"$",
"extraHeaders",
"[",
"'If-None-Match'",
"]",
"=",
"$",
"this",
"->",
"_etag",
";",
"}",
"// If an HTTP 304 status (Not Modified)is returned, then we return",
"// null.",
"$",
"result",
"=",
"null",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"service",
"->",
"importUrl",
"(",
"$",
"uri",
",",
"$",
"className",
",",
"$",
"extraHeaders",
")",
";",
"}",
"catch",
"(",
"Zend_Gdata_App_HttpException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getStatus",
"(",
")",
"!=",
"'304'",
")",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Reload the current entry. Returns a new copy of the entry as returned
by the server, or null if no changes exist. This does not
modify the current entry instance.
@param string|null The URI to send requests to, or null if $data
contains the URI.
@param string|null The name of the class that should we deserializing
the server response. If null, then 'Zend_Gdata_App_Entry' will
be used.
@param array $extraHeaders Extra headers to add to the request, as an
array of string-based key/value pairs.
@return mixed A new instance of the current entry with updated data, or
null if the server reports that no changes have been made.
@throws Zend_Gdata_App_Exception | [
"Reload",
"the",
"current",
"entry",
".",
"Returns",
"a",
"new",
"copy",
"of",
"the",
"entry",
"as",
"returned",
"by",
"the",
"server",
"or",
"null",
"if",
"no",
"changes",
"exist",
".",
"This",
"does",
"not",
"modify",
"the",
"current",
"entry",
"instance",
"."
] | 6141f0c16c7d4453275e3b74be5041f336085c91 | https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/App/Entry.php#L241-L273 |
1,841 | dreamfactorysoftware/df-couchbase | src/Resources/Table.php | Table.cleanFields | protected static function cleanFields($fields)
{
$new = [];
$fieldList = explode(',', $fields);
foreach ($fieldList as $f) {
if (static::ID_FIELD !== trim(strtolower($f))) {
$new[] = $f;
}
}
return implode(',', $new);
} | php | protected static function cleanFields($fields)
{
$new = [];
$fieldList = explode(',', $fields);
foreach ($fieldList as $f) {
if (static::ID_FIELD !== trim(strtolower($f))) {
$new[] = $f;
}
}
return implode(',', $new);
} | [
"protected",
"static",
"function",
"cleanFields",
"(",
"$",
"fields",
")",
"{",
"$",
"new",
"=",
"[",
"]",
";",
"$",
"fieldList",
"=",
"explode",
"(",
"','",
",",
"$",
"fields",
")",
";",
"foreach",
"(",
"$",
"fieldList",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"static",
"::",
"ID_FIELD",
"!==",
"trim",
"(",
"strtolower",
"(",
"$",
"f",
")",
")",
")",
"{",
"$",
"new",
"[",
"]",
"=",
"$",
"f",
";",
"}",
"}",
"return",
"implode",
"(",
"','",
",",
"$",
"new",
")",
";",
"}"
] | Excluding _id field from field list
@param string $fields
@return string | [
"Excluding",
"_id",
"field",
"from",
"field",
"list"
] | 29a4dd7fc248ef3848fe9476545837c68c0e28be | https://github.com/dreamfactorysoftware/df-couchbase/blob/29a4dd7fc248ef3848fe9476545837c68c0e28be/src/Resources/Table.php#L152-L163 |
1,842 | dreamfactorysoftware/df-couchbase | src/Resources/Table.php | Table.preCleanRecords | protected function preCleanRecords($records)
{
$new = [];
foreach ($records as $record) {
if (property_exists($record, $this->transactionTable)) {
$cleaned = (array)$record->{$this->transactionTable};
unset($cleaned[static::ID_FIELD]);
if (property_exists($record, '_id')) {
$cleaned = array_merge([static::ID_FIELD => $record->_id], $cleaned);
}
} else {
$cleaned = (array)$record;
}
$new[] = $cleaned;
}
return $new;
} | php | protected function preCleanRecords($records)
{
$new = [];
foreach ($records as $record) {
if (property_exists($record, $this->transactionTable)) {
$cleaned = (array)$record->{$this->transactionTable};
unset($cleaned[static::ID_FIELD]);
if (property_exists($record, '_id')) {
$cleaned = array_merge([static::ID_FIELD => $record->_id], $cleaned);
}
} else {
$cleaned = (array)$record;
}
$new[] = $cleaned;
}
return $new;
} | [
"protected",
"function",
"preCleanRecords",
"(",
"$",
"records",
")",
"{",
"$",
"new",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"record",
",",
"$",
"this",
"->",
"transactionTable",
")",
")",
"{",
"$",
"cleaned",
"=",
"(",
"array",
")",
"$",
"record",
"->",
"{",
"$",
"this",
"->",
"transactionTable",
"}",
";",
"unset",
"(",
"$",
"cleaned",
"[",
"static",
"::",
"ID_FIELD",
"]",
")",
";",
"if",
"(",
"property_exists",
"(",
"$",
"record",
",",
"'_id'",
")",
")",
"{",
"$",
"cleaned",
"=",
"array_merge",
"(",
"[",
"static",
"::",
"ID_FIELD",
"=>",
"$",
"record",
"->",
"_id",
"]",
",",
"$",
"cleaned",
")",
";",
"}",
"}",
"else",
"{",
"$",
"cleaned",
"=",
"(",
"array",
")",
"$",
"record",
";",
"}",
"$",
"new",
"[",
"]",
"=",
"$",
"cleaned",
";",
"}",
"return",
"$",
"new",
";",
"}"
] | Cleaning Couchbase rows.
@param array $records
@return array | [
"Cleaning",
"Couchbase",
"rows",
"."
] | 29a4dd7fc248ef3848fe9476545837c68c0e28be | https://github.com/dreamfactorysoftware/df-couchbase/blob/29a4dd7fc248ef3848fe9476545837c68c0e28be/src/Resources/Table.php#L172-L189 |
1,843 | dreamfactorysoftware/df-couchbase | src/Resources/Table.php | Table.isExpression | protected static function isExpression($field)
{
$alias = explode(' as ', $field);
$field = trim($alias[0]);
if (preg_match('/\S+\(\S*\)/', $field) === 1) {
if (isset($alias[1])) {
return trim($alias[1]);
}
return true;
}
return false;
} | php | protected static function isExpression($field)
{
$alias = explode(' as ', $field);
$field = trim($alias[0]);
if (preg_match('/\S+\(\S*\)/', $field) === 1) {
if (isset($alias[1])) {
return trim($alias[1]);
}
return true;
}
return false;
} | [
"protected",
"static",
"function",
"isExpression",
"(",
"$",
"field",
")",
"{",
"$",
"alias",
"=",
"explode",
"(",
"' as '",
",",
"$",
"field",
")",
";",
"$",
"field",
"=",
"trim",
"(",
"$",
"alias",
"[",
"0",
"]",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/\\S+\\(\\S*\\)/'",
",",
"$",
"field",
")",
"===",
"1",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"alias",
"[",
"1",
"]",
")",
")",
"{",
"return",
"trim",
"(",
"$",
"alias",
"[",
"1",
"]",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks to see if field is an expression
@param string $field
@return bool|string | [
"Checks",
"to",
"see",
"if",
"field",
"is",
"an",
"expression"
] | 29a4dd7fc248ef3848fe9476545837c68c0e28be | https://github.com/dreamfactorysoftware/df-couchbase/blob/29a4dd7fc248ef3848fe9476545837c68c0e28be/src/Resources/Table.php#L244-L257 |
1,844 | mizmoz/container | src/Container.php | Container.find | private function find($id)
{
if (! isset($this->registry[$id])) {
throw new NotFoundException("Entry id '" . $id . "' not found in container");
}
return $this->registry[$id];
} | php | private function find($id)
{
if (! isset($this->registry[$id])) {
throw new NotFoundException("Entry id '" . $id . "' not found in container");
}
return $this->registry[$id];
} | [
"private",
"function",
"find",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"Entry id '\"",
".",
"$",
"id",
".",
"\"' not found in container\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"registry",
"[",
"$",
"id",
"]",
";",
"}"
] | Find the item in the registry
@param $id
@return mixed | [
"Find",
"the",
"item",
"in",
"the",
"registry"
] | 7ae194189595fbcd392445bb41ac8ddb118b5b7c | https://github.com/mizmoz/container/blob/7ae194189595fbcd392445bb41ac8ddb118b5b7c/src/Container.php#L42-L49 |
1,845 | gourmet/common | Controller/Component/OpauthComponent.php | OpauthComponent.enabled | public function enabled($name = null) {
if (empty($this->_providers)) {
$this->_providers = (array) Configure::read('Opauth.Strategy');
}
if (empty($this->_providers)) {
return false;
}
if (!empty($name)) {
return isset($this->_providers[$name]);
}
return $this->_providers;
} | php | public function enabled($name = null) {
if (empty($this->_providers)) {
$this->_providers = (array) Configure::read('Opauth.Strategy');
}
if (empty($this->_providers)) {
return false;
}
if (!empty($name)) {
return isset($this->_providers[$name]);
}
return $this->_providers;
} | [
"public",
"function",
"enabled",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_providers",
")",
")",
"{",
"$",
"this",
"->",
"_providers",
"=",
"(",
"array",
")",
"Configure",
"::",
"read",
"(",
"'Opauth.Strategy'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_providers",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_providers",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_providers",
";",
"}"
] | Check if a given provider's strategy is enabled.
@param string $name Optional. Provider's name (i.e. linkedin, facebook, etc.).
@return mixed True if given name is enabled, false if not and the list of enabled providers if no name provided. | [
"Check",
"if",
"a",
"given",
"provider",
"s",
"strategy",
"is",
"enabled",
"."
] | 53ad4e919c51606dc81f2c716267d01ee768ade5 | https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/Controller/Component/OpauthComponent.php#L246-L260 |
1,846 | gourmet/common | Controller/Component/OpauthComponent.php | OpauthComponent.isAuthenticated | public function isAuthenticated($authData) {
// Case where user is locally logged in.
if (!empty($this->_user)) {
$this->updateData($this->mapData($authData));
return $this->_user;
}
$Model = ClassRegistry::init($this->_authenticateObject->settings['userModel']);
$conditions = array($Model->alias . '.' . Inflector::underscore($authData['provider']) . '_id' => $authData['uid']);
if (isset($authData['info']['email'])) {
$conditions = array('OR' => array_merge($conditions, array($Model->alias . '.' . 'email' => $authData['info']['email'])));
}
if (!empty($this->_authenticateObject->settings['scope'])) {
$conditions += $this->_authenticateObject->settings['scope'];
}
$result = $Model->find('first', array(
'conditions' => $conditions,
'contain' => $this->_authenticateObject->settings['contain'],
'recursive' => $this->_authenticateObject->settings['recursive']
));
// Case where no local user matches OAuth's provider UID and/or email.
if (empty($result) || empty($result[$Model->alias])) {
return false;
}
// Automatically log OAuth user by writing the local user's data to the session to by-pass the
// `BaseAuthenticate::_findUser()` auto-hashing of password.
$user = $result[$Model->alias];
if (array_key_exists($this->_authenticateObject->settings['fields']['password'], $user)) {
unset($user[$this->_authenticateObject->settings['fields']['password']]);
}
unset($result[$Model->alias]);
$this->_user = array_merge($user, $result);
$this->updateData($this->mapData($authData));
return $this->_user;
} | php | public function isAuthenticated($authData) {
// Case where user is locally logged in.
if (!empty($this->_user)) {
$this->updateData($this->mapData($authData));
return $this->_user;
}
$Model = ClassRegistry::init($this->_authenticateObject->settings['userModel']);
$conditions = array($Model->alias . '.' . Inflector::underscore($authData['provider']) . '_id' => $authData['uid']);
if (isset($authData['info']['email'])) {
$conditions = array('OR' => array_merge($conditions, array($Model->alias . '.' . 'email' => $authData['info']['email'])));
}
if (!empty($this->_authenticateObject->settings['scope'])) {
$conditions += $this->_authenticateObject->settings['scope'];
}
$result = $Model->find('first', array(
'conditions' => $conditions,
'contain' => $this->_authenticateObject->settings['contain'],
'recursive' => $this->_authenticateObject->settings['recursive']
));
// Case where no local user matches OAuth's provider UID and/or email.
if (empty($result) || empty($result[$Model->alias])) {
return false;
}
// Automatically log OAuth user by writing the local user's data to the session to by-pass the
// `BaseAuthenticate::_findUser()` auto-hashing of password.
$user = $result[$Model->alias];
if (array_key_exists($this->_authenticateObject->settings['fields']['password'], $user)) {
unset($user[$this->_authenticateObject->settings['fields']['password']]);
}
unset($result[$Model->alias]);
$this->_user = array_merge($user, $result);
$this->updateData($this->mapData($authData));
return $this->_user;
} | [
"public",
"function",
"isAuthenticated",
"(",
"$",
"authData",
")",
"{",
"// Case where user is locally logged in.",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_user",
")",
")",
"{",
"$",
"this",
"->",
"updateData",
"(",
"$",
"this",
"->",
"mapData",
"(",
"$",
"authData",
")",
")",
";",
"return",
"$",
"this",
"->",
"_user",
";",
"}",
"$",
"Model",
"=",
"ClassRegistry",
"::",
"init",
"(",
"$",
"this",
"->",
"_authenticateObject",
"->",
"settings",
"[",
"'userModel'",
"]",
")",
";",
"$",
"conditions",
"=",
"array",
"(",
"$",
"Model",
"->",
"alias",
".",
"'.'",
".",
"Inflector",
"::",
"underscore",
"(",
"$",
"authData",
"[",
"'provider'",
"]",
")",
".",
"'_id'",
"=>",
"$",
"authData",
"[",
"'uid'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"authData",
"[",
"'info'",
"]",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"conditions",
"=",
"array",
"(",
"'OR'",
"=>",
"array_merge",
"(",
"$",
"conditions",
",",
"array",
"(",
"$",
"Model",
"->",
"alias",
".",
"'.'",
".",
"'email'",
"=>",
"$",
"authData",
"[",
"'info'",
"]",
"[",
"'email'",
"]",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_authenticateObject",
"->",
"settings",
"[",
"'scope'",
"]",
")",
")",
"{",
"$",
"conditions",
"+=",
"$",
"this",
"->",
"_authenticateObject",
"->",
"settings",
"[",
"'scope'",
"]",
";",
"}",
"$",
"result",
"=",
"$",
"Model",
"->",
"find",
"(",
"'first'",
",",
"array",
"(",
"'conditions'",
"=>",
"$",
"conditions",
",",
"'contain'",
"=>",
"$",
"this",
"->",
"_authenticateObject",
"->",
"settings",
"[",
"'contain'",
"]",
",",
"'recursive'",
"=>",
"$",
"this",
"->",
"_authenticateObject",
"->",
"settings",
"[",
"'recursive'",
"]",
")",
")",
";",
"// Case where no local user matches OAuth's provider UID and/or email.",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
"||",
"empty",
"(",
"$",
"result",
"[",
"$",
"Model",
"->",
"alias",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Automatically log OAuth user by writing the local user's data to the session to by-pass the",
"// `BaseAuthenticate::_findUser()` auto-hashing of password.",
"$",
"user",
"=",
"$",
"result",
"[",
"$",
"Model",
"->",
"alias",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"_authenticateObject",
"->",
"settings",
"[",
"'fields'",
"]",
"[",
"'password'",
"]",
",",
"$",
"user",
")",
")",
"{",
"unset",
"(",
"$",
"user",
"[",
"$",
"this",
"->",
"_authenticateObject",
"->",
"settings",
"[",
"'fields'",
"]",
"[",
"'password'",
"]",
"]",
")",
";",
"}",
"unset",
"(",
"$",
"result",
"[",
"$",
"Model",
"->",
"alias",
"]",
")",
";",
"$",
"this",
"->",
"_user",
"=",
"array_merge",
"(",
"$",
"user",
",",
"$",
"result",
")",
";",
"$",
"this",
"->",
"updateData",
"(",
"$",
"this",
"->",
"mapData",
"(",
"$",
"authData",
")",
")",
";",
"return",
"$",
"this",
"->",
"_user",
";",
"}"
] | Checks if OAuth2 user authenticates to local user base.
@param array $authData Opauth's data.
@return boolean The local user's data if already logged in or when the provider's UID
and/or email match a local user record. False otherwise. | [
"Checks",
"if",
"OAuth2",
"user",
"authenticates",
"to",
"local",
"user",
"base",
"."
] | 53ad4e919c51606dc81f2c716267d01ee768ade5 | https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/Controller/Component/OpauthComponent.php#L269-L307 |
1,847 | gourmet/common | Controller/Component/OpauthComponent.php | OpauthComponent.mapData | public function mapData($authData) {
$map = $this->mapKeysToFields;
list(, $model) = pluginSplit($this->_authenticateObject->settings['userModel']);
$provider = Inflector::underscore($authData['provider']);
$data = array($model => array($provider . '_credentials' => serialize($authData['credentials'])));
foreach ($this->mapKeysToFields as $key => $path) {
$map[$key] = String::insert($path, compact('model', 'provider'), array('after' => ':'));
$value = Hash::get($authData, $key);
$mappedKey = explode('.', $map[$key]);
if (!empty($this->_user[array_pop($mappedKey)]) || empty($value)) {
continue;
}
$data = Hash::insert($data, $map[$key], Hash::get($authData, $key));
}
return $data;
} | php | public function mapData($authData) {
$map = $this->mapKeysToFields;
list(, $model) = pluginSplit($this->_authenticateObject->settings['userModel']);
$provider = Inflector::underscore($authData['provider']);
$data = array($model => array($provider . '_credentials' => serialize($authData['credentials'])));
foreach ($this->mapKeysToFields as $key => $path) {
$map[$key] = String::insert($path, compact('model', 'provider'), array('after' => ':'));
$value = Hash::get($authData, $key);
$mappedKey = explode('.', $map[$key]);
if (!empty($this->_user[array_pop($mappedKey)]) || empty($value)) {
continue;
}
$data = Hash::insert($data, $map[$key], Hash::get($authData, $key));
}
return $data;
} | [
"public",
"function",
"mapData",
"(",
"$",
"authData",
")",
"{",
"$",
"map",
"=",
"$",
"this",
"->",
"mapKeysToFields",
";",
"list",
"(",
",",
"$",
"model",
")",
"=",
"pluginSplit",
"(",
"$",
"this",
"->",
"_authenticateObject",
"->",
"settings",
"[",
"'userModel'",
"]",
")",
";",
"$",
"provider",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"authData",
"[",
"'provider'",
"]",
")",
";",
"$",
"data",
"=",
"array",
"(",
"$",
"model",
"=>",
"array",
"(",
"$",
"provider",
".",
"'_credentials'",
"=>",
"serialize",
"(",
"$",
"authData",
"[",
"'credentials'",
"]",
")",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"mapKeysToFields",
"as",
"$",
"key",
"=>",
"$",
"path",
")",
"{",
"$",
"map",
"[",
"$",
"key",
"]",
"=",
"String",
"::",
"insert",
"(",
"$",
"path",
",",
"compact",
"(",
"'model'",
",",
"'provider'",
")",
",",
"array",
"(",
"'after'",
"=>",
"':'",
")",
")",
";",
"$",
"value",
"=",
"Hash",
"::",
"get",
"(",
"$",
"authData",
",",
"$",
"key",
")",
";",
"$",
"mappedKey",
"=",
"explode",
"(",
"'.'",
",",
"$",
"map",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_user",
"[",
"array_pop",
"(",
"$",
"mappedKey",
")",
"]",
")",
"||",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"$",
"data",
"=",
"Hash",
"::",
"insert",
"(",
"$",
"data",
",",
"$",
"map",
"[",
"$",
"key",
"]",
",",
"Hash",
"::",
"get",
"(",
"$",
"authData",
",",
"$",
"key",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Maps Opauth's data for use in models.
@param array $authData Opauth's data.
@return array Mapped data. | [
"Maps",
"Opauth",
"s",
"data",
"for",
"use",
"in",
"models",
"."
] | 53ad4e919c51606dc81f2c716267d01ee768ade5 | https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/Controller/Component/OpauthComponent.php#L333-L351 |
1,848 | PSESD/chms-common | lib/Http/Controllers/Base/ObjectActions/PatchObjectTrait.php | PatchObjectTrait.patch | public function patch(Request $request, Fractal $fractal, InputGateContract $inputGate)
{
$this->beforeRequest($request, func_get_args());
$id = $this->parseObjectId($request);
$model = $this->loadAuthorizeObject($id, 'update');
$input = $request->json()->all();
if (!is_array($input) || empty($input)) {
throw new UnprocessableEntityHttpException("Invalid request body");
}
$attributes = $originalAttributes = array_get($input, 'data.attributes', []);
$context = app('context');
foreach ($context as $key => $value) {
unset($attributes[$key]);
}
$relationships = array_get($input, 'data.relationships', []);
$attributes = $inputGate->process($model, $attributes, 'update');
$validatedRelationshipData = $this->validateRelationshipData($model, $relationships, 'update');
// do update logic
if ($model->update($attributes) && $this->saveRelationshipData($validatedRelationshipData)) {
return $this->respondWithUpdated(
$fractal->createData(new FractalItem($this->loadAuthorizeObject($id, 'update'), $this->getTransformer(), $this->getResourceKey()))
);
}
throw new ServerErrorHttpException("Unable to save object. Try again later.");
} | php | public function patch(Request $request, Fractal $fractal, InputGateContract $inputGate)
{
$this->beforeRequest($request, func_get_args());
$id = $this->parseObjectId($request);
$model = $this->loadAuthorizeObject($id, 'update');
$input = $request->json()->all();
if (!is_array($input) || empty($input)) {
throw new UnprocessableEntityHttpException("Invalid request body");
}
$attributes = $originalAttributes = array_get($input, 'data.attributes', []);
$context = app('context');
foreach ($context as $key => $value) {
unset($attributes[$key]);
}
$relationships = array_get($input, 'data.relationships', []);
$attributes = $inputGate->process($model, $attributes, 'update');
$validatedRelationshipData = $this->validateRelationshipData($model, $relationships, 'update');
// do update logic
if ($model->update($attributes) && $this->saveRelationshipData($validatedRelationshipData)) {
return $this->respondWithUpdated(
$fractal->createData(new FractalItem($this->loadAuthorizeObject($id, 'update'), $this->getTransformer(), $this->getResourceKey()))
);
}
throw new ServerErrorHttpException("Unable to save object. Try again later.");
} | [
"public",
"function",
"patch",
"(",
"Request",
"$",
"request",
",",
"Fractal",
"$",
"fractal",
",",
"InputGateContract",
"$",
"inputGate",
")",
"{",
"$",
"this",
"->",
"beforeRequest",
"(",
"$",
"request",
",",
"func_get_args",
"(",
")",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"parseObjectId",
"(",
"$",
"request",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"loadAuthorizeObject",
"(",
"$",
"id",
",",
"'update'",
")",
";",
"$",
"input",
"=",
"$",
"request",
"->",
"json",
"(",
")",
"->",
"all",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"input",
")",
"||",
"empty",
"(",
"$",
"input",
")",
")",
"{",
"throw",
"new",
"UnprocessableEntityHttpException",
"(",
"\"Invalid request body\"",
")",
";",
"}",
"$",
"attributes",
"=",
"$",
"originalAttributes",
"=",
"array_get",
"(",
"$",
"input",
",",
"'data.attributes'",
",",
"[",
"]",
")",
";",
"$",
"context",
"=",
"app",
"(",
"'context'",
")",
";",
"foreach",
"(",
"$",
"context",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"$",
"relationships",
"=",
"array_get",
"(",
"$",
"input",
",",
"'data.relationships'",
",",
"[",
"]",
")",
";",
"$",
"attributes",
"=",
"$",
"inputGate",
"->",
"process",
"(",
"$",
"model",
",",
"$",
"attributes",
",",
"'update'",
")",
";",
"$",
"validatedRelationshipData",
"=",
"$",
"this",
"->",
"validateRelationshipData",
"(",
"$",
"model",
",",
"$",
"relationships",
",",
"'update'",
")",
";",
"// do update logic",
"if",
"(",
"$",
"model",
"->",
"update",
"(",
"$",
"attributes",
")",
"&&",
"$",
"this",
"->",
"saveRelationshipData",
"(",
"$",
"validatedRelationshipData",
")",
")",
"{",
"return",
"$",
"this",
"->",
"respondWithUpdated",
"(",
"$",
"fractal",
"->",
"createData",
"(",
"new",
"FractalItem",
"(",
"$",
"this",
"->",
"loadAuthorizeObject",
"(",
"$",
"id",
",",
"'update'",
")",
",",
"$",
"this",
"->",
"getTransformer",
"(",
")",
",",
"$",
"this",
"->",
"getResourceKey",
"(",
")",
")",
")",
")",
";",
"}",
"throw",
"new",
"ServerErrorHttpException",
"(",
"\"Unable to save object. Try again later.\"",
")",
";",
"}"
] | Update the object
@param Request $request Request object
@param string $id Unique identifier for the object
@return ResponseInterface Response for object | [
"Update",
"the",
"object"
] | dba29f95de57cb6b1113c169ccb911152b18e288 | https://github.com/PSESD/chms-common/blob/dba29f95de57cb6b1113c169ccb911152b18e288/lib/Http/Controllers/Base/ObjectActions/PatchObjectTrait.php#L26-L51 |
1,849 | UTipdMe/MysqlModel | src/Utipd/MysqlModel/BaseMysqlDirectory.php | BaseMysqlDirectory.createAndSave | public function createAndSave($create_vars=[]) {
// build new object
$new_model = $this->create($create_vars);
// save it to the database
$model = $this->save($new_model);
return $model;
} | php | public function createAndSave($create_vars=[]) {
// build new object
$new_model = $this->create($create_vars);
// save it to the database
$model = $this->save($new_model);
return $model;
} | [
"public",
"function",
"createAndSave",
"(",
"$",
"create_vars",
"=",
"[",
"]",
")",
"{",
"// build new object",
"$",
"new_model",
"=",
"$",
"this",
"->",
"create",
"(",
"$",
"create_vars",
")",
";",
"// save it to the database",
"$",
"model",
"=",
"$",
"this",
"->",
"save",
"(",
"$",
"new_model",
")",
";",
"return",
"$",
"model",
";",
"}"
] | creates a new model
@param array $create_vars
@return BaseMysqlModel a new model | [
"creates",
"a",
"new",
"model"
] | f011ba996b3b73a0405100379f177ce76dd95118 | https://github.com/UTipdMe/MysqlModel/blob/f011ba996b3b73a0405100379f177ce76dd95118/src/Utipd/MysqlModel/BaseMysqlDirectory.php#L56-L64 |
1,850 | UTipdMe/MysqlModel | src/Utipd/MysqlModel/BaseMysqlDirectory.php | BaseMysqlDirectory.create | public function create($create_vars=[]) {
// add
$new_model_doc_vars = array_merge($this->newModelDefaults(), $create_vars);
$new_model_doc_vars = $this->onCreate_pre($new_model_doc_vars);
return $this->newModel($new_model_doc_vars);
} | php | public function create($create_vars=[]) {
// add
$new_model_doc_vars = array_merge($this->newModelDefaults(), $create_vars);
$new_model_doc_vars = $this->onCreate_pre($new_model_doc_vars);
return $this->newModel($new_model_doc_vars);
} | [
"public",
"function",
"create",
"(",
"$",
"create_vars",
"=",
"[",
"]",
")",
"{",
"// add",
"$",
"new_model_doc_vars",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"newModelDefaults",
"(",
")",
",",
"$",
"create_vars",
")",
";",
"$",
"new_model_doc_vars",
"=",
"$",
"this",
"->",
"onCreate_pre",
"(",
"$",
"new_model_doc_vars",
")",
";",
"return",
"$",
"this",
"->",
"newModel",
"(",
"$",
"new_model_doc_vars",
")",
";",
"}"
] | creates a model without saving to the database
@param array $create_vars
@return BaseMysqlModel a new model | [
"creates",
"a",
"model",
"without",
"saving",
"to",
"the",
"database"
] | f011ba996b3b73a0405100379f177ce76dd95118 | https://github.com/UTipdMe/MysqlModel/blob/f011ba996b3b73a0405100379f177ce76dd95118/src/Utipd/MysqlModel/BaseMysqlDirectory.php#L71-L77 |
1,851 | UTipdMe/MysqlModel | src/Utipd/MysqlModel/BaseMysqlDirectory.php | BaseMysqlDirectory.save | public function save(BaseMysqlModel $model) {
$create_vars = $this->onSave_pre((array)$model);
$sql = $this->buildInsertStatement($create_vars);
$id = $this->connection_manager->executeWithReconnect(function($mysql_dbh) use ($sql, $create_vars) {
$sth = $mysql_dbh->prepare($sql);
$result = $sth->execute(array_values($create_vars));
return $mysql_dbh->lastInsertId();
});
$model['id'] = $id;
return $model;
} | php | public function save(BaseMysqlModel $model) {
$create_vars = $this->onSave_pre((array)$model);
$sql = $this->buildInsertStatement($create_vars);
$id = $this->connection_manager->executeWithReconnect(function($mysql_dbh) use ($sql, $create_vars) {
$sth = $mysql_dbh->prepare($sql);
$result = $sth->execute(array_values($create_vars));
return $mysql_dbh->lastInsertId();
});
$model['id'] = $id;
return $model;
} | [
"public",
"function",
"save",
"(",
"BaseMysqlModel",
"$",
"model",
")",
"{",
"$",
"create_vars",
"=",
"$",
"this",
"->",
"onSave_pre",
"(",
"(",
"array",
")",
"$",
"model",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"buildInsertStatement",
"(",
"$",
"create_vars",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"connection_manager",
"->",
"executeWithReconnect",
"(",
"function",
"(",
"$",
"mysql_dbh",
")",
"use",
"(",
"$",
"sql",
",",
"$",
"create_vars",
")",
"{",
"$",
"sth",
"=",
"$",
"mysql_dbh",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"$",
"sth",
"->",
"execute",
"(",
"array_values",
"(",
"$",
"create_vars",
")",
")",
";",
"return",
"$",
"mysql_dbh",
"->",
"lastInsertId",
"(",
")",
";",
"}",
")",
";",
"$",
"model",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"return",
"$",
"model",
";",
"}"
] | saves a new model to the database
@param array $create_vars
@return BaseMysqlModel a new model | [
"saves",
"a",
"new",
"model",
"to",
"the",
"database"
] | f011ba996b3b73a0405100379f177ce76dd95118 | https://github.com/UTipdMe/MysqlModel/blob/f011ba996b3b73a0405100379f177ce76dd95118/src/Utipd/MysqlModel/BaseMysqlDirectory.php#L84-L97 |
1,852 | UTipdMe/MysqlModel | src/Utipd/MysqlModel/BaseMysqlDirectory.php | BaseMysqlDirectory.findByID | public function findByID($model_or_id, $options=null) {
$id = $this->extractID($model_or_id);
return $this->findOne(['id' => $id], null, $options);
} | php | public function findByID($model_or_id, $options=null) {
$id = $this->extractID($model_or_id);
return $this->findOne(['id' => $id], null, $options);
} | [
"public",
"function",
"findByID",
"(",
"$",
"model_or_id",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"extractID",
"(",
"$",
"model_or_id",
")",
";",
"return",
"$",
"this",
"->",
"findOne",
"(",
"[",
"'id'",
"=>",
"$",
"id",
"]",
",",
"null",
",",
"$",
"options",
")",
";",
"}"
] | finds a model by ID
@param BaseMysqlModel|MongoID|string $model_or_id
@return BaseMysqlModel|null | [
"finds",
"a",
"model",
"by",
"ID"
] | f011ba996b3b73a0405100379f177ce76dd95118 | https://github.com/UTipdMe/MysqlModel/blob/f011ba996b3b73a0405100379f177ce76dd95118/src/Utipd/MysqlModel/BaseMysqlDirectory.php#L105-L108 |
1,853 | UTipdMe/MysqlModel | src/Utipd/MysqlModel/BaseMysqlDirectory.php | BaseMysqlDirectory.findOne | public function findOne($vars, $order_by_keys=null, $options=null) {
foreach ($this->find($vars, $order_by_keys, 1, $options) as $model) {
return $model;
}
return null;
} | php | public function findOne($vars, $order_by_keys=null, $options=null) {
foreach ($this->find($vars, $order_by_keys, 1, $options) as $model) {
return $model;
}
return null;
} | [
"public",
"function",
"findOne",
"(",
"$",
"vars",
",",
"$",
"order_by_keys",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"find",
"(",
"$",
"vars",
",",
"$",
"order_by_keys",
",",
"1",
",",
"$",
"options",
")",
"as",
"$",
"model",
")",
"{",
"return",
"$",
"model",
";",
"}",
"return",
"null",
";",
"}"
] | queries the database for a single object
@param array $query
@return BaseMysqlModel or null | [
"queries",
"the",
"database",
"for",
"a",
"single",
"object"
] | f011ba996b3b73a0405100379f177ce76dd95118 | https://github.com/UTipdMe/MysqlModel/blob/f011ba996b3b73a0405100379f177ce76dd95118/src/Utipd/MysqlModel/BaseMysqlDirectory.php#L145-L150 |
1,854 | UTipdMe/MysqlModel | src/Utipd/MysqlModel/BaseMysqlDirectory.php | BaseMysqlDirectory.update | public function update($model_or_id, $update_vars, $mongo_options=[]) {
$id = $this->extractID($model_or_id);
$update_vars = $this->onUpdate_pre($update_vars, $model_or_id);
$sql = $this->buildUpdateStatement($update_vars, ['id']);
$sth = $this->connection_manager->executeWithReconnect(function($mysql_dbh) use ($sql, $update_vars, $id) {
$sth = $mysql_dbh->prepare($sql);
$vars = $this->removeMysqlLiterals(array_values($update_vars));
$vars[] = $id;
$result = $sth->execute($vars);
return $sth;
});
return $sth->rowCount();
} | php | public function update($model_or_id, $update_vars, $mongo_options=[]) {
$id = $this->extractID($model_or_id);
$update_vars = $this->onUpdate_pre($update_vars, $model_or_id);
$sql = $this->buildUpdateStatement($update_vars, ['id']);
$sth = $this->connection_manager->executeWithReconnect(function($mysql_dbh) use ($sql, $update_vars, $id) {
$sth = $mysql_dbh->prepare($sql);
$vars = $this->removeMysqlLiterals(array_values($update_vars));
$vars[] = $id;
$result = $sth->execute($vars);
return $sth;
});
return $sth->rowCount();
} | [
"public",
"function",
"update",
"(",
"$",
"model_or_id",
",",
"$",
"update_vars",
",",
"$",
"mongo_options",
"=",
"[",
"]",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"extractID",
"(",
"$",
"model_or_id",
")",
";",
"$",
"update_vars",
"=",
"$",
"this",
"->",
"onUpdate_pre",
"(",
"$",
"update_vars",
",",
"$",
"model_or_id",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"buildUpdateStatement",
"(",
"$",
"update_vars",
",",
"[",
"'id'",
"]",
")",
";",
"$",
"sth",
"=",
"$",
"this",
"->",
"connection_manager",
"->",
"executeWithReconnect",
"(",
"function",
"(",
"$",
"mysql_dbh",
")",
"use",
"(",
"$",
"sql",
",",
"$",
"update_vars",
",",
"$",
"id",
")",
"{",
"$",
"sth",
"=",
"$",
"mysql_dbh",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"vars",
"=",
"$",
"this",
"->",
"removeMysqlLiterals",
"(",
"array_values",
"(",
"$",
"update_vars",
")",
")",
";",
"$",
"vars",
"[",
"]",
"=",
"$",
"id",
";",
"$",
"result",
"=",
"$",
"sth",
"->",
"execute",
"(",
"$",
"vars",
")",
";",
"return",
"$",
"sth",
";",
"}",
")",
";",
"return",
"$",
"sth",
"->",
"rowCount",
"(",
")",
";",
"}"
] | updates a model in the database
@param BaseMysqlModel|MongoID|string $model_or_id
@param array $update_vars
@param array $mongo_options
@return BaseMysqlModel | [
"updates",
"a",
"model",
"in",
"the",
"database"
] | f011ba996b3b73a0405100379f177ce76dd95118 | https://github.com/UTipdMe/MysqlModel/blob/f011ba996b3b73a0405100379f177ce76dd95118/src/Utipd/MysqlModel/BaseMysqlDirectory.php#L217-L233 |
1,855 | pletfix/core | src/Services/DateTime.php | DateTime.createFromParts | public static function createFromParts(array $parts, $timezone = null)
{
$year = isset($parts[0]) ? $parts[0] : date('Y');
$month = isset($parts[1]) ? $parts[1] : date('m');
$day = isset($parts[2]) ? $parts[2] : date('d');
$hour = isset($parts[3]) ? $parts[3] : 0; //date('H');
$minute = isset($parts[4]) ? $parts[4] : 0; //date('i');
$second = isset($parts[5]) ? $parts[5] : 0; //date('s');
$micro = isset($parts[6]) ? $parts[6] : 0; //date('u');
$dateTimeString = sprintf('%04s-%02s-%02s %02s:%02s:%02s.%06s', $year, $month, $day, $hour, $minute, $second, $micro);
return new static($dateTimeString, $timezone);
} | php | public static function createFromParts(array $parts, $timezone = null)
{
$year = isset($parts[0]) ? $parts[0] : date('Y');
$month = isset($parts[1]) ? $parts[1] : date('m');
$day = isset($parts[2]) ? $parts[2] : date('d');
$hour = isset($parts[3]) ? $parts[3] : 0; //date('H');
$minute = isset($parts[4]) ? $parts[4] : 0; //date('i');
$second = isset($parts[5]) ? $parts[5] : 0; //date('s');
$micro = isset($parts[6]) ? $parts[6] : 0; //date('u');
$dateTimeString = sprintf('%04s-%02s-%02s %02s:%02s:%02s.%06s', $year, $month, $day, $hour, $minute, $second, $micro);
return new static($dateTimeString, $timezone);
} | [
"public",
"static",
"function",
"createFromParts",
"(",
"array",
"$",
"parts",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"year",
"=",
"isset",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
"?",
"$",
"parts",
"[",
"0",
"]",
":",
"date",
"(",
"'Y'",
")",
";",
"$",
"month",
"=",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"$",
"parts",
"[",
"1",
"]",
":",
"date",
"(",
"'m'",
")",
";",
"$",
"day",
"=",
"isset",
"(",
"$",
"parts",
"[",
"2",
"]",
")",
"?",
"$",
"parts",
"[",
"2",
"]",
":",
"date",
"(",
"'d'",
")",
";",
"$",
"hour",
"=",
"isset",
"(",
"$",
"parts",
"[",
"3",
"]",
")",
"?",
"$",
"parts",
"[",
"3",
"]",
":",
"0",
";",
"//date('H');",
"$",
"minute",
"=",
"isset",
"(",
"$",
"parts",
"[",
"4",
"]",
")",
"?",
"$",
"parts",
"[",
"4",
"]",
":",
"0",
";",
"//date('i');",
"$",
"second",
"=",
"isset",
"(",
"$",
"parts",
"[",
"5",
"]",
")",
"?",
"$",
"parts",
"[",
"5",
"]",
":",
"0",
";",
"//date('s');",
"$",
"micro",
"=",
"isset",
"(",
"$",
"parts",
"[",
"6",
"]",
")",
"?",
"$",
"parts",
"[",
"6",
"]",
":",
"0",
";",
"//date('u');",
"$",
"dateTimeString",
"=",
"sprintf",
"(",
"'%04s-%02s-%02s %02s:%02s:%02s.%06s'",
",",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"second",
",",
"$",
"micro",
")",
";",
"return",
"new",
"static",
"(",
"$",
"dateTimeString",
",",
"$",
"timezone",
")",
";",
"}"
] | Create a new DateTime instance from a specific parts of date and time.
The default of any part of date (year, month or day) is today.
The default of any part of time (hour, minute, second or microsecond) is 0.
@param array $parts [$year, $month, $day, $hour, $minute, $second, $micro] All parts are optional.
@param DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"new",
"DateTime",
"instance",
"from",
"a",
"specific",
"parts",
"of",
"date",
"and",
"time",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/DateTime.php#L132-L144 |
1,856 | pletfix/core | src/Services/DateTime.php | DateTime.next | private function next($dayOfWeek)
{
$days = [
self::SUNDAY => 'Sunday',
self::MONDAY => 'Monday',
self::TUESDAY => 'Tuesday',
self::WEDNESDAY => 'Wednesday',
self::THURSDAY => 'Thursday',
self::FRIDAY => 'Friday',
self::SATURDAY => 'Saturday',
];
$dow = $days[$dayOfWeek];
return $this->startOfDay()->modify("next $dow");
} | php | private function next($dayOfWeek)
{
$days = [
self::SUNDAY => 'Sunday',
self::MONDAY => 'Monday',
self::TUESDAY => 'Tuesday',
self::WEDNESDAY => 'Wednesday',
self::THURSDAY => 'Thursday',
self::FRIDAY => 'Friday',
self::SATURDAY => 'Saturday',
];
$dow = $days[$dayOfWeek];
return $this->startOfDay()->modify("next $dow");
} | [
"private",
"function",
"next",
"(",
"$",
"dayOfWeek",
")",
"{",
"$",
"days",
"=",
"[",
"self",
"::",
"SUNDAY",
"=>",
"'Sunday'",
",",
"self",
"::",
"MONDAY",
"=>",
"'Monday'",
",",
"self",
"::",
"TUESDAY",
"=>",
"'Tuesday'",
",",
"self",
"::",
"WEDNESDAY",
"=>",
"'Wednesday'",
",",
"self",
"::",
"THURSDAY",
"=>",
"'Thursday'",
",",
"self",
"::",
"FRIDAY",
"=>",
"'Friday'",
",",
"self",
"::",
"SATURDAY",
"=>",
"'Saturday'",
",",
"]",
";",
"$",
"dow",
"=",
"$",
"days",
"[",
"$",
"dayOfWeek",
"]",
";",
"return",
"$",
"this",
"->",
"startOfDay",
"(",
")",
"->",
"modify",
"(",
"\"next $dow\"",
")",
";",
"}"
] | Modify to the next occurrence of a given day of the week.
If no dayOfWeek is provided, modify to the next occurrence of the current day of the week.
Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
@param int $dayOfWeek
@return static | [
"Modify",
"to",
"the",
"next",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/DateTime.php#L982-L997 |
1,857 | pletfix/core | src/Services/DateTime.php | DateTime.localeFormat | private static function localeFormat($part = 'datetime')
{
if (self::$localeFormat === null) {
$locale = self::getLocale();
$file = resource_path('lang/' . $locale . '/datetime.php');
if (file_exists($file)) {
/** @noinspection PhpIncludeInspection */
self::$localeFormat = include $file;
}
else {
$file = resource_path('lang/' . config('locale.fallback') . '/datetime.php');
/** @noinspection PhpIncludeInspection */
self::$localeFormat = file_exists($file) ? include $file : ['datetime' => 'Y-m-d H:i', 'date' => 'Y-m-d', 'time' => 'H:i'];
}
}
return self::$localeFormat[$part];
} | php | private static function localeFormat($part = 'datetime')
{
if (self::$localeFormat === null) {
$locale = self::getLocale();
$file = resource_path('lang/' . $locale . '/datetime.php');
if (file_exists($file)) {
/** @noinspection PhpIncludeInspection */
self::$localeFormat = include $file;
}
else {
$file = resource_path('lang/' . config('locale.fallback') . '/datetime.php');
/** @noinspection PhpIncludeInspection */
self::$localeFormat = file_exists($file) ? include $file : ['datetime' => 'Y-m-d H:i', 'date' => 'Y-m-d', 'time' => 'H:i'];
}
}
return self::$localeFormat[$part];
} | [
"private",
"static",
"function",
"localeFormat",
"(",
"$",
"part",
"=",
"'datetime'",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"localeFormat",
"===",
"null",
")",
"{",
"$",
"locale",
"=",
"self",
"::",
"getLocale",
"(",
")",
";",
"$",
"file",
"=",
"resource_path",
"(",
"'lang/'",
".",
"$",
"locale",
".",
"'/datetime.php'",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"/** @noinspection PhpIncludeInspection */",
"self",
"::",
"$",
"localeFormat",
"=",
"include",
"$",
"file",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"resource_path",
"(",
"'lang/'",
".",
"config",
"(",
"'locale.fallback'",
")",
".",
"'/datetime.php'",
")",
";",
"/** @noinspection PhpIncludeInspection */",
"self",
"::",
"$",
"localeFormat",
"=",
"file_exists",
"(",
"$",
"file",
")",
"?",
"include",
"$",
"file",
":",
"[",
"'datetime'",
"=>",
"'Y-m-d H:i'",
",",
"'date'",
"=>",
"'Y-m-d'",
",",
"'time'",
"=>",
"'H:i'",
"]",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"localeFormat",
"[",
"$",
"part",
"]",
";",
"}"
] | Returns the locale date time format.
@param string $part
@return string | [
"Returns",
"the",
"locale",
"date",
"time",
"format",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/DateTime.php#L1129-L1146 |
1,858 | Briareos/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php | YamlDriver.parseDiscriminatorField | private function parseDiscriminatorField($discriminatorField)
{
if (is_string($discriminatorField)) {
return $discriminatorField;
}
if ( ! is_array($discriminatorField)) {
throw new \InvalidArgumentException('Expected array or string for discriminatorField; found: ' . gettype($discriminatorField));
}
if (isset($discriminatorField['name'])) {
return (string) $discriminatorField['name'];
}
if (isset($discriminatorField['fieldName'])) {
return (string) $discriminatorField['fieldName'];
}
throw new \InvalidArgumentException('Expected "name" or "fieldName" key in discriminatorField array; found neither.');
} | php | private function parseDiscriminatorField($discriminatorField)
{
if (is_string($discriminatorField)) {
return $discriminatorField;
}
if ( ! is_array($discriminatorField)) {
throw new \InvalidArgumentException('Expected array or string for discriminatorField; found: ' . gettype($discriminatorField));
}
if (isset($discriminatorField['name'])) {
return (string) $discriminatorField['name'];
}
if (isset($discriminatorField['fieldName'])) {
return (string) $discriminatorField['fieldName'];
}
throw new \InvalidArgumentException('Expected "name" or "fieldName" key in discriminatorField array; found neither.');
} | [
"private",
"function",
"parseDiscriminatorField",
"(",
"$",
"discriminatorField",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"discriminatorField",
")",
")",
"{",
"return",
"$",
"discriminatorField",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"discriminatorField",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Expected array or string for discriminatorField; found: '",
".",
"gettype",
"(",
"$",
"discriminatorField",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"discriminatorField",
"[",
"'name'",
"]",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"discriminatorField",
"[",
"'name'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"discriminatorField",
"[",
"'fieldName'",
"]",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"discriminatorField",
"[",
"'fieldName'",
"]",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Expected \"name\" or \"fieldName\" key in discriminatorField array; found neither.'",
")",
";",
"}"
] | Parses the class or field-level "discriminatorField" option.
If the value is an array, check the "name" option before falling back to
the deprecated "fieldName" option (for BC). Otherwise, the value must be
a string.
@param array|string $discriminatorField
@return string
@throws \InvalidArgumentException if the value is neither a string nor an
array with a "name" or "fieldName" key. | [
"Parses",
"the",
"class",
"or",
"field",
"-",
"level",
"discriminatorField",
"option",
"."
] | 29e28bed9a265efd7d05473b0a909fb7c83f76e0 | https://github.com/Briareos/mongodb-odm/blob/29e28bed9a265efd7d05473b0a909fb7c83f76e0/lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php#L268-L287 |
1,859 | mijohansen/php-gae-util | src/Defaulter.php | Defaulter.gaeutilJson | static function gaeutilJson($project_directory, $app_engine_project, $gaeutil_defaults = []) {
$config_dir_location = Conf::getConfFolderPath($project_directory);
$gaeutil_json_location = Conf::getGaeUtilJsonPath($project_directory);
Files::ensureDirectory($config_dir_location);
$gaeutil_json_content = Files::getJson($gaeutil_json_location, []);
foreach ($gaeutil_defaults as $key => $val) {
$gaeutil_json_content[$key] = $val;
}
/**
* Just create a new key.
*/
$project_key_name = $gaeutil_json_content[Secrets::CONF_PROJECT_KEY_NAME];
$project_key_parts = Secrets::reverseKmsKey($project_key_name);
list($project, $location, $keyRing) = array_values($project_key_parts);
$gaeutil_json_content[Secrets::CONF_PROJECT_KEY_NAME] = Secrets::getKeyName($project, $location, $keyRing, $app_engine_project);
// Write to disk
if (Files::putJson($gaeutil_json_location, $gaeutil_json_content)) {
Util::cmdline("Updated gaeutil.json $project_directory");
}
} | php | static function gaeutilJson($project_directory, $app_engine_project, $gaeutil_defaults = []) {
$config_dir_location = Conf::getConfFolderPath($project_directory);
$gaeutil_json_location = Conf::getGaeUtilJsonPath($project_directory);
Files::ensureDirectory($config_dir_location);
$gaeutil_json_content = Files::getJson($gaeutil_json_location, []);
foreach ($gaeutil_defaults as $key => $val) {
$gaeutil_json_content[$key] = $val;
}
/**
* Just create a new key.
*/
$project_key_name = $gaeutil_json_content[Secrets::CONF_PROJECT_KEY_NAME];
$project_key_parts = Secrets::reverseKmsKey($project_key_name);
list($project, $location, $keyRing) = array_values($project_key_parts);
$gaeutil_json_content[Secrets::CONF_PROJECT_KEY_NAME] = Secrets::getKeyName($project, $location, $keyRing, $app_engine_project);
// Write to disk
if (Files::putJson($gaeutil_json_location, $gaeutil_json_content)) {
Util::cmdline("Updated gaeutil.json $project_directory");
}
} | [
"static",
"function",
"gaeutilJson",
"(",
"$",
"project_directory",
",",
"$",
"app_engine_project",
",",
"$",
"gaeutil_defaults",
"=",
"[",
"]",
")",
"{",
"$",
"config_dir_location",
"=",
"Conf",
"::",
"getConfFolderPath",
"(",
"$",
"project_directory",
")",
";",
"$",
"gaeutil_json_location",
"=",
"Conf",
"::",
"getGaeUtilJsonPath",
"(",
"$",
"project_directory",
")",
";",
"Files",
"::",
"ensureDirectory",
"(",
"$",
"config_dir_location",
")",
";",
"$",
"gaeutil_json_content",
"=",
"Files",
"::",
"getJson",
"(",
"$",
"gaeutil_json_location",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"gaeutil_defaults",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"gaeutil_json_content",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"/**\n * Just create a new key.\n */",
"$",
"project_key_name",
"=",
"$",
"gaeutil_json_content",
"[",
"Secrets",
"::",
"CONF_PROJECT_KEY_NAME",
"]",
";",
"$",
"project_key_parts",
"=",
"Secrets",
"::",
"reverseKmsKey",
"(",
"$",
"project_key_name",
")",
";",
"list",
"(",
"$",
"project",
",",
"$",
"location",
",",
"$",
"keyRing",
")",
"=",
"array_values",
"(",
"$",
"project_key_parts",
")",
";",
"$",
"gaeutil_json_content",
"[",
"Secrets",
"::",
"CONF_PROJECT_KEY_NAME",
"]",
"=",
"Secrets",
"::",
"getKeyName",
"(",
"$",
"project",
",",
"$",
"location",
",",
"$",
"keyRing",
",",
"$",
"app_engine_project",
")",
";",
"// Write to disk",
"if",
"(",
"Files",
"::",
"putJson",
"(",
"$",
"gaeutil_json_location",
",",
"$",
"gaeutil_json_content",
")",
")",
"{",
"Util",
"::",
"cmdline",
"(",
"\"Updated gaeutil.json $project_directory\"",
")",
";",
"}",
"}"
] | Fixing gaeutil.json | [
"Fixing",
"gaeutil",
".",
"json"
] | dfa7a1a4d61aa435351d6a5b1b120c0e23d81dde | https://github.com/mijohansen/php-gae-util/blob/dfa7a1a4d61aa435351d6a5b1b120c0e23d81dde/src/Defaulter.php#L31-L50 |
1,860 | mijohansen/php-gae-util | src/Defaulter.php | Defaulter.packageJson | static function packageJson($project_directory, $app_engine_project, $app_engine_service, $package_json_defaults = []) {
$package_json_location = $project_directory . DIRECTORY_SEPARATOR . "package.json";
$package_json_content = Files::getJson($package_json_location, []);
$package_json_content = array_merge([
"name" => null,
"project" => null,
"private" => null,
], $package_json_content);
$project_name = $app_engine_project . '-' . $app_engine_service;
$package_json_defaults["private"] = true;
$package_json_content["name"] = $project_name;
$package_json_content["project"] = $app_engine_project;
foreach ($package_json_defaults as $key => $val) {
$package_json_content[$key] = $val;
}
if ($app_engine_service == "default") {
$package_json_content["scripts"]["deploy"] = 'gcloud app deploy app.yaml queue.yaml --project $npm_package_project --promote --quiet';
} else {
$package_json_content["scripts"]["deploy"] = 'gcloud app deploy app.yaml --project $npm_package_project --promote --quiet';
}
$gaeutil_json = Files::getJson(Conf::getGaeUtilJsonPath($project_directory), []);
$project_key_name = $gaeutil_json[Secrets::CONF_PROJECT_KEY_NAME];
$project_key = Secrets::reverseKmsKey($project_key_name);
$crypt_params = [
"ciphertext-file" => "config/secrets.cipher",
"plaintext-file" => "secrets.json",
"project" => $project_key["project"],
"location" => $project_key["location"],
"keyring" => $project_key["keyRing"],
"key" => $project_key["cryptoKey"]
];
$package_json_content["scripts"]["encrypt"] = self::commandMaker("gcloud kms encrypt", $crypt_params);
$package_json_content["scripts"]["decrypt"] = self::commandMaker("gcloud kms decrypt", $crypt_params);
$package_json_content["scripts"]["devserve"] = 'dev_appserver.py --port=5000 . -A $npm_package_project';
if (Files::putJson($package_json_location, $package_json_content)) {
Util::cmdline("Updated package.json in $project_name");
}
} | php | static function packageJson($project_directory, $app_engine_project, $app_engine_service, $package_json_defaults = []) {
$package_json_location = $project_directory . DIRECTORY_SEPARATOR . "package.json";
$package_json_content = Files::getJson($package_json_location, []);
$package_json_content = array_merge([
"name" => null,
"project" => null,
"private" => null,
], $package_json_content);
$project_name = $app_engine_project . '-' . $app_engine_service;
$package_json_defaults["private"] = true;
$package_json_content["name"] = $project_name;
$package_json_content["project"] = $app_engine_project;
foreach ($package_json_defaults as $key => $val) {
$package_json_content[$key] = $val;
}
if ($app_engine_service == "default") {
$package_json_content["scripts"]["deploy"] = 'gcloud app deploy app.yaml queue.yaml --project $npm_package_project --promote --quiet';
} else {
$package_json_content["scripts"]["deploy"] = 'gcloud app deploy app.yaml --project $npm_package_project --promote --quiet';
}
$gaeutil_json = Files::getJson(Conf::getGaeUtilJsonPath($project_directory), []);
$project_key_name = $gaeutil_json[Secrets::CONF_PROJECT_KEY_NAME];
$project_key = Secrets::reverseKmsKey($project_key_name);
$crypt_params = [
"ciphertext-file" => "config/secrets.cipher",
"plaintext-file" => "secrets.json",
"project" => $project_key["project"],
"location" => $project_key["location"],
"keyring" => $project_key["keyRing"],
"key" => $project_key["cryptoKey"]
];
$package_json_content["scripts"]["encrypt"] = self::commandMaker("gcloud kms encrypt", $crypt_params);
$package_json_content["scripts"]["decrypt"] = self::commandMaker("gcloud kms decrypt", $crypt_params);
$package_json_content["scripts"]["devserve"] = 'dev_appserver.py --port=5000 . -A $npm_package_project';
if (Files::putJson($package_json_location, $package_json_content)) {
Util::cmdline("Updated package.json in $project_name");
}
} | [
"static",
"function",
"packageJson",
"(",
"$",
"project_directory",
",",
"$",
"app_engine_project",
",",
"$",
"app_engine_service",
",",
"$",
"package_json_defaults",
"=",
"[",
"]",
")",
"{",
"$",
"package_json_location",
"=",
"$",
"project_directory",
".",
"DIRECTORY_SEPARATOR",
".",
"\"package.json\"",
";",
"$",
"package_json_content",
"=",
"Files",
"::",
"getJson",
"(",
"$",
"package_json_location",
",",
"[",
"]",
")",
";",
"$",
"package_json_content",
"=",
"array_merge",
"(",
"[",
"\"name\"",
"=>",
"null",
",",
"\"project\"",
"=>",
"null",
",",
"\"private\"",
"=>",
"null",
",",
"]",
",",
"$",
"package_json_content",
")",
";",
"$",
"project_name",
"=",
"$",
"app_engine_project",
".",
"'-'",
".",
"$",
"app_engine_service",
";",
"$",
"package_json_defaults",
"[",
"\"private\"",
"]",
"=",
"true",
";",
"$",
"package_json_content",
"[",
"\"name\"",
"]",
"=",
"$",
"project_name",
";",
"$",
"package_json_content",
"[",
"\"project\"",
"]",
"=",
"$",
"app_engine_project",
";",
"foreach",
"(",
"$",
"package_json_defaults",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"package_json_content",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"if",
"(",
"$",
"app_engine_service",
"==",
"\"default\"",
")",
"{",
"$",
"package_json_content",
"[",
"\"scripts\"",
"]",
"[",
"\"deploy\"",
"]",
"=",
"'gcloud app deploy app.yaml queue.yaml --project $npm_package_project --promote --quiet'",
";",
"}",
"else",
"{",
"$",
"package_json_content",
"[",
"\"scripts\"",
"]",
"[",
"\"deploy\"",
"]",
"=",
"'gcloud app deploy app.yaml --project $npm_package_project --promote --quiet'",
";",
"}",
"$",
"gaeutil_json",
"=",
"Files",
"::",
"getJson",
"(",
"Conf",
"::",
"getGaeUtilJsonPath",
"(",
"$",
"project_directory",
")",
",",
"[",
"]",
")",
";",
"$",
"project_key_name",
"=",
"$",
"gaeutil_json",
"[",
"Secrets",
"::",
"CONF_PROJECT_KEY_NAME",
"]",
";",
"$",
"project_key",
"=",
"Secrets",
"::",
"reverseKmsKey",
"(",
"$",
"project_key_name",
")",
";",
"$",
"crypt_params",
"=",
"[",
"\"ciphertext-file\"",
"=>",
"\"config/secrets.cipher\"",
",",
"\"plaintext-file\"",
"=>",
"\"secrets.json\"",
",",
"\"project\"",
"=>",
"$",
"project_key",
"[",
"\"project\"",
"]",
",",
"\"location\"",
"=>",
"$",
"project_key",
"[",
"\"location\"",
"]",
",",
"\"keyring\"",
"=>",
"$",
"project_key",
"[",
"\"keyRing\"",
"]",
",",
"\"key\"",
"=>",
"$",
"project_key",
"[",
"\"cryptoKey\"",
"]",
"]",
";",
"$",
"package_json_content",
"[",
"\"scripts\"",
"]",
"[",
"\"encrypt\"",
"]",
"=",
"self",
"::",
"commandMaker",
"(",
"\"gcloud kms encrypt\"",
",",
"$",
"crypt_params",
")",
";",
"$",
"package_json_content",
"[",
"\"scripts\"",
"]",
"[",
"\"decrypt\"",
"]",
"=",
"self",
"::",
"commandMaker",
"(",
"\"gcloud kms decrypt\"",
",",
"$",
"crypt_params",
")",
";",
"$",
"package_json_content",
"[",
"\"scripts\"",
"]",
"[",
"\"devserve\"",
"]",
"=",
"'dev_appserver.py --port=5000 . -A $npm_package_project'",
";",
"if",
"(",
"Files",
"::",
"putJson",
"(",
"$",
"package_json_location",
",",
"$",
"package_json_content",
")",
")",
"{",
"Util",
"::",
"cmdline",
"(",
"\"Updated package.json in $project_name\"",
")",
";",
"}",
"}"
] | Fixing package.json | [
"Fixing",
"package",
".",
"json"
] | dfa7a1a4d61aa435351d6a5b1b120c0e23d81dde | https://github.com/mijohansen/php-gae-util/blob/dfa7a1a4d61aa435351d6a5b1b120c0e23d81dde/src/Defaulter.php#L55-L94 |
1,861 | plinker-rpc/core | src/Server.php | Server.info | private function info()
{
$response = [
'class' => []
];
foreach ($this->config["classes"] as $key => $val) {
// addtional config
$response["class"][$key]["config"] = !empty($val[1]) ? $val[1] : [];
// check class file exists
if (!file_exists($val[0])) {
$response["class"][$key]["methods"] = [];
continue;
}
//
require($val[0]);
$reflection = new \ReflectionClass($key);
foreach ($reflection->getMethods() as $method) {
if (!in_array($method->getName(), ["__construct"])) {
$param = [];
foreach ($method->getParameters() as $parameter) {
$param[] = $parameter->getName();
}
$response["class"][$key]["methods"][$method->getName()] = $param;
}
}
}
return $response;
} | php | private function info()
{
$response = [
'class' => []
];
foreach ($this->config["classes"] as $key => $val) {
// addtional config
$response["class"][$key]["config"] = !empty($val[1]) ? $val[1] : [];
// check class file exists
if (!file_exists($val[0])) {
$response["class"][$key]["methods"] = [];
continue;
}
//
require($val[0]);
$reflection = new \ReflectionClass($key);
foreach ($reflection->getMethods() as $method) {
if (!in_array($method->getName(), ["__construct"])) {
$param = [];
foreach ($method->getParameters() as $parameter) {
$param[] = $parameter->getName();
}
$response["class"][$key]["methods"][$method->getName()] = $param;
}
}
}
return $response;
} | [
"private",
"function",
"info",
"(",
")",
"{",
"$",
"response",
"=",
"[",
"'class'",
"=>",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"config",
"[",
"\"classes\"",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"// addtional config",
"$",
"response",
"[",
"\"class\"",
"]",
"[",
"$",
"key",
"]",
"[",
"\"config\"",
"]",
"=",
"!",
"empty",
"(",
"$",
"val",
"[",
"1",
"]",
")",
"?",
"$",
"val",
"[",
"1",
"]",
":",
"[",
"]",
";",
"// check class file exists",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"val",
"[",
"0",
"]",
")",
")",
"{",
"$",
"response",
"[",
"\"class\"",
"]",
"[",
"$",
"key",
"]",
"[",
"\"methods\"",
"]",
"=",
"[",
"]",
";",
"continue",
";",
"}",
"//",
"require",
"(",
"$",
"val",
"[",
"0",
"]",
")",
";",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"key",
")",
";",
"foreach",
"(",
"$",
"reflection",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"[",
"\"__construct\"",
"]",
")",
")",
"{",
"$",
"param",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"method",
"->",
"getParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"$",
"param",
"[",
"]",
"=",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"response",
"[",
"\"class\"",
"]",
"[",
"$",
"key",
"]",
"[",
"\"methods\"",
"]",
"[",
"$",
"method",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"param",
";",
"}",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] | Return info about available classes
<code>
$client->info();
</code>
@return array | [
"Return",
"info",
"about",
"available",
"classes"
] | c9039cfa840cfe2d6377455e6668364d910626fd | https://github.com/plinker-rpc/core/blob/c9039cfa840cfe2d6377455e6668364d910626fd/src/Server.php#L148-L182 |
1,862 | plinker-rpc/core | src/Server.php | Server.setInput | private function setInput()
{
$this->input = file_get_contents("php://input");
if (!empty($this->input)) {
$this->input = gzinflate($this->input);
$this->input = json_decode($this->input, true);
}
} | php | private function setInput()
{
$this->input = file_get_contents("php://input");
if (!empty($this->input)) {
$this->input = gzinflate($this->input);
$this->input = json_decode($this->input, true);
}
} | [
"private",
"function",
"setInput",
"(",
")",
"{",
"$",
"this",
"->",
"input",
"=",
"file_get_contents",
"(",
"\"php://input\"",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"input",
")",
")",
"{",
"$",
"this",
"->",
"input",
"=",
"gzinflate",
"(",
"$",
"this",
"->",
"input",
")",
";",
"$",
"this",
"->",
"input",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"input",
",",
"true",
")",
";",
"}",
"}"
] | Sets inbound input value into scope
@return void | [
"Sets",
"inbound",
"input",
"value",
"into",
"scope"
] | c9039cfa840cfe2d6377455e6668364d910626fd | https://github.com/plinker-rpc/core/blob/c9039cfa840cfe2d6377455e6668364d910626fd/src/Server.php#L189-L196 |
1,863 | plinker-rpc/core | src/Server.php | Server.executeCoreComponent | private function executeCoreComponent($component, $action)
{
// define component namespace
$ns = "\\Plinker\\".ucfirst($component);
if (class_exists($ns)) {
//
$response = $this->execute($ns, $action);
} elseif (class_exists($ns."\\".ucfirst($component))) {
//
$ns = "\\Plinker\\".ucfirst($component)."\\".ucfirst($component);
$response = $this->execute($ns, $action);
} else {
if (empty($component) && $action === "info") {
$response = $this->info();
} else {
$response = sprintf(Server::ERROR_EXT_COMPONENT, $component);
}
}
return $response;
} | php | private function executeCoreComponent($component, $action)
{
// define component namespace
$ns = "\\Plinker\\".ucfirst($component);
if (class_exists($ns)) {
//
$response = $this->execute($ns, $action);
} elseif (class_exists($ns."\\".ucfirst($component))) {
//
$ns = "\\Plinker\\".ucfirst($component)."\\".ucfirst($component);
$response = $this->execute($ns, $action);
} else {
if (empty($component) && $action === "info") {
$response = $this->info();
} else {
$response = sprintf(Server::ERROR_EXT_COMPONENT, $component);
}
}
return $response;
} | [
"private",
"function",
"executeCoreComponent",
"(",
"$",
"component",
",",
"$",
"action",
")",
"{",
"// define component namespace",
"$",
"ns",
"=",
"\"\\\\Plinker\\\\\"",
".",
"ucfirst",
"(",
"$",
"component",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"ns",
")",
")",
"{",
"//",
"$",
"response",
"=",
"$",
"this",
"->",
"execute",
"(",
"$",
"ns",
",",
"$",
"action",
")",
";",
"}",
"elseif",
"(",
"class_exists",
"(",
"$",
"ns",
".",
"\"\\\\\"",
".",
"ucfirst",
"(",
"$",
"component",
")",
")",
")",
"{",
"//",
"$",
"ns",
"=",
"\"\\\\Plinker\\\\\"",
".",
"ucfirst",
"(",
"$",
"component",
")",
".",
"\"\\\\\"",
".",
"ucfirst",
"(",
"$",
"component",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"execute",
"(",
"$",
"ns",
",",
"$",
"action",
")",
";",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"component",
")",
"&&",
"$",
"action",
"===",
"\"info\"",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"info",
"(",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"sprintf",
"(",
"Server",
"::",
"ERROR_EXT_COMPONENT",
",",
"$",
"component",
")",
";",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] | Execute core component | [
"Execute",
"core",
"component"
] | c9039cfa840cfe2d6377455e6668364d910626fd | https://github.com/plinker-rpc/core/blob/c9039cfa840cfe2d6377455e6668364d910626fd/src/Server.php#L211-L232 |
1,864 | plinker-rpc/core | src/Server.php | Server.executeUserComponent | private function executeUserComponent($component, $action)
{
$ns = null;
//
if (!empty($this->config["classes"][$component][0])) {
$ns = $this->config["classes"][$component][0];
}
//
if (!empty($this->config["classes"][$component][1])) {
$this->config['config'] = array_merge(
$this->config['config'],
$this->config["classes"][$component][1]
);
}
//
if (!empty($ns) && !file_exists($ns)) {
$this->response = serialize([
"error" => sprintf(Server::ERROR_USR_COMPONENT, $component),
"code" => 422
]);
return;
}
//
require($ns);
//
if (!class_exists($component)) {
$this->response = serialize([
"error" => sprintf(Server::ERROR_USR_COMPONENT, $component),
"code" => 422
]);
return;
}
//
return $this->execute($component, $action);
} | php | private function executeUserComponent($component, $action)
{
$ns = null;
//
if (!empty($this->config["classes"][$component][0])) {
$ns = $this->config["classes"][$component][0];
}
//
if (!empty($this->config["classes"][$component][1])) {
$this->config['config'] = array_merge(
$this->config['config'],
$this->config["classes"][$component][1]
);
}
//
if (!empty($ns) && !file_exists($ns)) {
$this->response = serialize([
"error" => sprintf(Server::ERROR_USR_COMPONENT, $component),
"code" => 422
]);
return;
}
//
require($ns);
//
if (!class_exists($component)) {
$this->response = serialize([
"error" => sprintf(Server::ERROR_USR_COMPONENT, $component),
"code" => 422
]);
return;
}
//
return $this->execute($component, $action);
} | [
"private",
"function",
"executeUserComponent",
"(",
"$",
"component",
",",
"$",
"action",
")",
"{",
"$",
"ns",
"=",
"null",
";",
"//",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"\"classes\"",
"]",
"[",
"$",
"component",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"ns",
"=",
"$",
"this",
"->",
"config",
"[",
"\"classes\"",
"]",
"[",
"$",
"component",
"]",
"[",
"0",
"]",
";",
"}",
"//",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"\"classes\"",
"]",
"[",
"$",
"component",
"]",
"[",
"1",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'config'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
"[",
"'config'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"\"classes\"",
"]",
"[",
"$",
"component",
"]",
"[",
"1",
"]",
")",
";",
"}",
"//",
"if",
"(",
"!",
"empty",
"(",
"$",
"ns",
")",
"&&",
"!",
"file_exists",
"(",
"$",
"ns",
")",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"serialize",
"(",
"[",
"\"error\"",
"=>",
"sprintf",
"(",
"Server",
"::",
"ERROR_USR_COMPONENT",
",",
"$",
"component",
")",
",",
"\"code\"",
"=>",
"422",
"]",
")",
";",
"return",
";",
"}",
"//",
"require",
"(",
"$",
"ns",
")",
";",
"//",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"component",
")",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"serialize",
"(",
"[",
"\"error\"",
"=>",
"sprintf",
"(",
"Server",
"::",
"ERROR_USR_COMPONENT",
",",
"$",
"component",
")",
",",
"\"code\"",
"=>",
"422",
"]",
")",
";",
"return",
";",
"}",
"//",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"component",
",",
"$",
"action",
")",
";",
"}"
] | Execute user component | [
"Execute",
"user",
"component"
] | c9039cfa840cfe2d6377455e6668364d910626fd | https://github.com/plinker-rpc/core/blob/c9039cfa840cfe2d6377455e6668364d910626fd/src/Server.php#L237-L277 |
1,865 | razielsd/webdriverlib | WebDriver/WebDriver/Exception/FailedCommand.php | WebDriver_Exception_FailedCommand.factory | final public static function factory(
WebDriver_Command $command,
array $infoList = [],
$rawResponse = null,
$responseJson = null
) {
if (!isset($responseJson['status'])) {
$errorMessage = "Unknown error";
} elseif (static::isOk($responseJson['status'])) {
$errorMessage = "Unexpected Ok status {$responseJson['status']}";
} elseif (static::isKnownError($responseJson['status'])) {
$errorMessage = static::getErrorMessage($responseJson['status']);
} else {
$errorMessage = "Unknown error status: {$responseJson['status']}";
}
$messageList = [$errorMessage];
if (isset($responseJson['value']['message'])) {
$messageList[] = $responseJson['value']['message'];
}
$messageList[] = static::getCommandDescription($command);
$messageList[] = "HTTP Status Code: {$infoList['http_code']}";
switch ($responseJson['status']) {
case self::STALE_ELEMENT_REFERENCE:
$e = new WebDriver_Exception_StaleElementReference(
implode("\n", $messageList),
$responseJson['status']
);
$e->responseList = $responseJson;
return $e;
default:
$e = new WebDriver_Exception_FailedCommand(implode("\n", $messageList), $responseJson['status']);
$e->responseList = $responseJson;
return $e;
}
} | php | final public static function factory(
WebDriver_Command $command,
array $infoList = [],
$rawResponse = null,
$responseJson = null
) {
if (!isset($responseJson['status'])) {
$errorMessage = "Unknown error";
} elseif (static::isOk($responseJson['status'])) {
$errorMessage = "Unexpected Ok status {$responseJson['status']}";
} elseif (static::isKnownError($responseJson['status'])) {
$errorMessage = static::getErrorMessage($responseJson['status']);
} else {
$errorMessage = "Unknown error status: {$responseJson['status']}";
}
$messageList = [$errorMessage];
if (isset($responseJson['value']['message'])) {
$messageList[] = $responseJson['value']['message'];
}
$messageList[] = static::getCommandDescription($command);
$messageList[] = "HTTP Status Code: {$infoList['http_code']}";
switch ($responseJson['status']) {
case self::STALE_ELEMENT_REFERENCE:
$e = new WebDriver_Exception_StaleElementReference(
implode("\n", $messageList),
$responseJson['status']
);
$e->responseList = $responseJson;
return $e;
default:
$e = new WebDriver_Exception_FailedCommand(implode("\n", $messageList), $responseJson['status']);
$e->responseList = $responseJson;
return $e;
}
} | [
"final",
"public",
"static",
"function",
"factory",
"(",
"WebDriver_Command",
"$",
"command",
",",
"array",
"$",
"infoList",
"=",
"[",
"]",
",",
"$",
"rawResponse",
"=",
"null",
",",
"$",
"responseJson",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"responseJson",
"[",
"'status'",
"]",
")",
")",
"{",
"$",
"errorMessage",
"=",
"\"Unknown error\"",
";",
"}",
"elseif",
"(",
"static",
"::",
"isOk",
"(",
"$",
"responseJson",
"[",
"'status'",
"]",
")",
")",
"{",
"$",
"errorMessage",
"=",
"\"Unexpected Ok status {$responseJson['status']}\"",
";",
"}",
"elseif",
"(",
"static",
"::",
"isKnownError",
"(",
"$",
"responseJson",
"[",
"'status'",
"]",
")",
")",
"{",
"$",
"errorMessage",
"=",
"static",
"::",
"getErrorMessage",
"(",
"$",
"responseJson",
"[",
"'status'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"errorMessage",
"=",
"\"Unknown error status: {$responseJson['status']}\"",
";",
"}",
"$",
"messageList",
"=",
"[",
"$",
"errorMessage",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"responseJson",
"[",
"'value'",
"]",
"[",
"'message'",
"]",
")",
")",
"{",
"$",
"messageList",
"[",
"]",
"=",
"$",
"responseJson",
"[",
"'value'",
"]",
"[",
"'message'",
"]",
";",
"}",
"$",
"messageList",
"[",
"]",
"=",
"static",
"::",
"getCommandDescription",
"(",
"$",
"command",
")",
";",
"$",
"messageList",
"[",
"]",
"=",
"\"HTTP Status Code: {$infoList['http_code']}\"",
";",
"switch",
"(",
"$",
"responseJson",
"[",
"'status'",
"]",
")",
"{",
"case",
"self",
"::",
"STALE_ELEMENT_REFERENCE",
":",
"$",
"e",
"=",
"new",
"WebDriver_Exception_StaleElementReference",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"messageList",
")",
",",
"$",
"responseJson",
"[",
"'status'",
"]",
")",
";",
"$",
"e",
"->",
"responseList",
"=",
"$",
"responseJson",
";",
"return",
"$",
"e",
";",
"default",
":",
"$",
"e",
"=",
"new",
"WebDriver_Exception_FailedCommand",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"messageList",
")",
",",
"$",
"responseJson",
"[",
"'status'",
"]",
")",
";",
"$",
"e",
"->",
"responseList",
"=",
"$",
"responseJson",
";",
"return",
"$",
"e",
";",
"}",
"}"
] | Factory for all failed command exceptions.
@param WebDriver_Command $command
@param array $infoList
@param null|string $rawResponse
@param null|array $responseJson
@return WebDriver_Exception_FailedCommand | [
"Factory",
"for",
"all",
"failed",
"command",
"exceptions",
"."
] | e498afc36a8cdeab5b6ca95016420557baf32f36 | https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Exception/FailedCommand.php#L146-L181 |
1,866 | lrc-se/bth-anax-repository | src/Repository/ManagedRepositoryTrait.php | ManagedRepositoryTrait.fetchReferences | public function fetchReferences($refs = true, $soft = false)
{
$this->fetchRefs = $refs;
$this->softRefs = $soft;
return $this;
} | php | public function fetchReferences($refs = true, $soft = false)
{
$this->fetchRefs = $refs;
$this->softRefs = $soft;
return $this;
} | [
"public",
"function",
"fetchReferences",
"(",
"$",
"refs",
"=",
"true",
",",
"$",
"soft",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"fetchRefs",
"=",
"$",
"refs",
";",
"$",
"this",
"->",
"softRefs",
"=",
"$",
"soft",
";",
"return",
"$",
"this",
";",
"}"
] | Change reference fetching behavior.
@param array|boolean $refs Array of references to include in fetch operations (pass true to fetch all or false to fetch none).
@param boolean $soft Whether to take soft-deletion into account when fetching references.
@return self | [
"Change",
"reference",
"fetching",
"behavior",
"."
] | 344a0795fbfadf34ea768719dc5cf2f1d90154df | https://github.com/lrc-se/bth-anax-repository/blob/344a0795fbfadf34ea768719dc5cf2f1d90154df/src/Repository/ManagedRepositoryTrait.php#L50-L55 |
1,867 | mszewcz/php-json-schema-validator | src/Validators/MiscValidators/OneOfValidator.php | OneOfValidator.validate | public function validate($subject): bool
{
$validatedCount = 0;
foreach ($this->schema['oneOf'] as $schema) {
$nodeValidator = new NodeValidator($schema, $this->rootSchema);
if ($nodeValidator->validate($subject)) {
$validatedCount++;
}
}
return $validatedCount === 1;
} | php | public function validate($subject): bool
{
$validatedCount = 0;
foreach ($this->schema['oneOf'] as $schema) {
$nodeValidator = new NodeValidator($schema, $this->rootSchema);
if ($nodeValidator->validate($subject)) {
$validatedCount++;
}
}
return $validatedCount === 1;
} | [
"public",
"function",
"validate",
"(",
"$",
"subject",
")",
":",
"bool",
"{",
"$",
"validatedCount",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"[",
"'oneOf'",
"]",
"as",
"$",
"schema",
")",
"{",
"$",
"nodeValidator",
"=",
"new",
"NodeValidator",
"(",
"$",
"schema",
",",
"$",
"this",
"->",
"rootSchema",
")",
";",
"if",
"(",
"$",
"nodeValidator",
"->",
"validate",
"(",
"$",
"subject",
")",
")",
"{",
"$",
"validatedCount",
"++",
";",
"}",
"}",
"return",
"$",
"validatedCount",
"===",
"1",
";",
"}"
] | Validates subject against oneOf
@param $subject
@return bool | [
"Validates",
"subject",
"against",
"oneOf"
] | f7768bfe07ce6508bb1ff36163560a5e5791de7d | https://github.com/mszewcz/php-json-schema-validator/blob/f7768bfe07ce6508bb1ff36163560a5e5791de7d/src/Validators/MiscValidators/OneOfValidator.php#L48-L58 |
1,868 | eix/core | src/php/main/Eix/Core/Application.php | Application.run | public function run()
{
$this->requestId = uniqid();
$this->startTime = microtime();
try {
// Generate a Request object from the data available in the
// current running environment.
try {
$requestFactory = new Requests\Factories\Http;
$request = $requestFactory->get($this);
// Set the application locale from the request.
// TODO: Move into the Request constructor?
$this->setLocale($request->getLocale());
// Run the process of responding to the request.
$this->issueResponse($request);
} catch (\Throwable $throwable) {
// There was an error somewhere during the request
// creation, or somewhere during the response building
// process.
$errorRequest = new Requests\Http\Error;
$errorRequest->setThrowable($throwable);
$this->issueResponse($errorRequest, $throwable);
}
} catch (\Exception $exception) {
// There was an error while trying to fail gracefully.
// Little else can be done now.
$this->fail($exception);
}
Logger::get()->info($this->getStats());
// Since the application is being run in an HTTP context, and
// PHP is the scripting language it is, the application cycle
// just finishes after the response is done with its tasks.
} | php | public function run()
{
$this->requestId = uniqid();
$this->startTime = microtime();
try {
// Generate a Request object from the data available in the
// current running environment.
try {
$requestFactory = new Requests\Factories\Http;
$request = $requestFactory->get($this);
// Set the application locale from the request.
// TODO: Move into the Request constructor?
$this->setLocale($request->getLocale());
// Run the process of responding to the request.
$this->issueResponse($request);
} catch (\Throwable $throwable) {
// There was an error somewhere during the request
// creation, or somewhere during the response building
// process.
$errorRequest = new Requests\Http\Error;
$errorRequest->setThrowable($throwable);
$this->issueResponse($errorRequest, $throwable);
}
} catch (\Exception $exception) {
// There was an error while trying to fail gracefully.
// Little else can be done now.
$this->fail($exception);
}
Logger::get()->info($this->getStats());
// Since the application is being run in an HTTP context, and
// PHP is the scripting language it is, the application cycle
// just finishes after the response is done with its tasks.
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"this",
"->",
"requestId",
"=",
"uniqid",
"(",
")",
";",
"$",
"this",
"->",
"startTime",
"=",
"microtime",
"(",
")",
";",
"try",
"{",
"// Generate a Request object from the data available in the",
"// current running environment.",
"try",
"{",
"$",
"requestFactory",
"=",
"new",
"Requests",
"\\",
"Factories",
"\\",
"Http",
";",
"$",
"request",
"=",
"$",
"requestFactory",
"->",
"get",
"(",
"$",
"this",
")",
";",
"// Set the application locale from the request.",
"// TODO: Move into the Request constructor?",
"$",
"this",
"->",
"setLocale",
"(",
"$",
"request",
"->",
"getLocale",
"(",
")",
")",
";",
"// Run the process of responding to the request.",
"$",
"this",
"->",
"issueResponse",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"throwable",
")",
"{",
"// There was an error somewhere during the request",
"// creation, or somewhere during the response building",
"// process.",
"$",
"errorRequest",
"=",
"new",
"Requests",
"\\",
"Http",
"\\",
"Error",
";",
"$",
"errorRequest",
"->",
"setThrowable",
"(",
"$",
"throwable",
")",
";",
"$",
"this",
"->",
"issueResponse",
"(",
"$",
"errorRequest",
",",
"$",
"throwable",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"// There was an error while trying to fail gracefully.",
"// Little else can be done now.",
"$",
"this",
"->",
"fail",
"(",
"$",
"exception",
")",
";",
"}",
"Logger",
"::",
"get",
"(",
")",
"->",
"info",
"(",
"$",
"this",
"->",
"getStats",
"(",
")",
")",
";",
"// Since the application is being run in an HTTP context, and",
"// PHP is the scripting language it is, the application cycle",
"// just finishes after the response is done with its tasks.",
"}"
] | Starts the application's cycle. | [
"Starts",
"the",
"application",
"s",
"cycle",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L103-L138 |
1,869 | eix/core | src/php/main/Eix/Core/Application.php | Application.issueResponse | private function issueResponse(Request $request, \Exception $exception = null)
{
$responder = null;
if ($exception === null) {
// No exception, just return a normal responder.
$responder = ResponderFactory::getResponder($request);
} else {
// Any type of exception, just find an error responder.
$responder = ResponderFactory::getErrorResponder($request, $exception);
}
// The responder is asked to produce a Response object, which is then
// asked to perform whatever actions it takes to issue the response.
try {
$response = $responder->getResponse();
} catch (NotAuthenticatedException $exception) {
// A resource that needs authentication was hit.
// Store the current locator, to be able to return to it after
// signing in.
$this->keepCurrentLocator($request);
// Request identification from the user.
// Set the method to GET for the identity request. POST is reserved
// for the actual posting of the identity data by the user.
$request->setMethod(HttpRequest::HTTP_METHOD_GET);
$responder = new IdentityResponder($request);
$response = $responder->getResponse();
}
if ($response instanceof Response) {
// Provide a hook for last-minute response work.
$this->alterResponse($response);
// Issue the response.
$response->issue();
} else {
throw new HttpException('No response available.');
}
} | php | private function issueResponse(Request $request, \Exception $exception = null)
{
$responder = null;
if ($exception === null) {
// No exception, just return a normal responder.
$responder = ResponderFactory::getResponder($request);
} else {
// Any type of exception, just find an error responder.
$responder = ResponderFactory::getErrorResponder($request, $exception);
}
// The responder is asked to produce a Response object, which is then
// asked to perform whatever actions it takes to issue the response.
try {
$response = $responder->getResponse();
} catch (NotAuthenticatedException $exception) {
// A resource that needs authentication was hit.
// Store the current locator, to be able to return to it after
// signing in.
$this->keepCurrentLocator($request);
// Request identification from the user.
// Set the method to GET for the identity request. POST is reserved
// for the actual posting of the identity data by the user.
$request->setMethod(HttpRequest::HTTP_METHOD_GET);
$responder = new IdentityResponder($request);
$response = $responder->getResponse();
}
if ($response instanceof Response) {
// Provide a hook for last-minute response work.
$this->alterResponse($response);
// Issue the response.
$response->issue();
} else {
throw new HttpException('No response available.');
}
} | [
"private",
"function",
"issueResponse",
"(",
"Request",
"$",
"request",
",",
"\\",
"Exception",
"$",
"exception",
"=",
"null",
")",
"{",
"$",
"responder",
"=",
"null",
";",
"if",
"(",
"$",
"exception",
"===",
"null",
")",
"{",
"// No exception, just return a normal responder.",
"$",
"responder",
"=",
"ResponderFactory",
"::",
"getResponder",
"(",
"$",
"request",
")",
";",
"}",
"else",
"{",
"// Any type of exception, just find an error responder.",
"$",
"responder",
"=",
"ResponderFactory",
"::",
"getErrorResponder",
"(",
"$",
"request",
",",
"$",
"exception",
")",
";",
"}",
"// The responder is asked to produce a Response object, which is then",
"// asked to perform whatever actions it takes to issue the response.",
"try",
"{",
"$",
"response",
"=",
"$",
"responder",
"->",
"getResponse",
"(",
")",
";",
"}",
"catch",
"(",
"NotAuthenticatedException",
"$",
"exception",
")",
"{",
"// A resource that needs authentication was hit.",
"// Store the current locator, to be able to return to it after",
"// signing in.",
"$",
"this",
"->",
"keepCurrentLocator",
"(",
"$",
"request",
")",
";",
"// Request identification from the user.",
"// Set the method to GET for the identity request. POST is reserved",
"// for the actual posting of the identity data by the user.",
"$",
"request",
"->",
"setMethod",
"(",
"HttpRequest",
"::",
"HTTP_METHOD_GET",
")",
";",
"$",
"responder",
"=",
"new",
"IdentityResponder",
"(",
"$",
"request",
")",
";",
"$",
"response",
"=",
"$",
"responder",
"->",
"getResponse",
"(",
")",
";",
"}",
"if",
"(",
"$",
"response",
"instanceof",
"Response",
")",
"{",
"// Provide a hook for last-minute response work.",
"$",
"this",
"->",
"alterResponse",
"(",
"$",
"response",
")",
";",
"// Issue the response.",
"$",
"response",
"->",
"issue",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"HttpException",
"(",
"'No response available.'",
")",
";",
"}",
"}"
] | Obtains a Response to a Request and actions it.
@param Request $request the request that a response is needed for. | [
"Obtains",
"a",
"Response",
"to",
"a",
"Request",
"and",
"actions",
"it",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L145-L182 |
1,870 | eix/core | src/php/main/Eix/Core/Application.php | Application.fail | public function fail(\Throwable $throwable)
{
Logger::get()->exception($throwable);
header('Server error', true, 500);
echo '<h1>Eix</h1>';
echo 'The application cannot continue.';
echo '<blockquote>' . $throwable->getMessage() . '</blockquote>';
if (defined('DEBUG') && DEBUG) {
echo '<pre>' . $throwable->getTraceAsString() . '</pre>';
}
die(-1);
} | php | public function fail(\Throwable $throwable)
{
Logger::get()->exception($throwable);
header('Server error', true, 500);
echo '<h1>Eix</h1>';
echo 'The application cannot continue.';
echo '<blockquote>' . $throwable->getMessage() . '</blockquote>';
if (defined('DEBUG') && DEBUG) {
echo '<pre>' . $throwable->getTraceAsString() . '</pre>';
}
die(-1);
} | [
"public",
"function",
"fail",
"(",
"\\",
"Throwable",
"$",
"throwable",
")",
"{",
"Logger",
"::",
"get",
"(",
")",
"->",
"exception",
"(",
"$",
"throwable",
")",
";",
"header",
"(",
"'Server error'",
",",
"true",
",",
"500",
")",
";",
"echo",
"'<h1>Eix</h1>'",
";",
"echo",
"'The application cannot continue.'",
";",
"echo",
"'<blockquote>'",
".",
"$",
"throwable",
"->",
"getMessage",
"(",
")",
".",
"'</blockquote>'",
";",
"if",
"(",
"defined",
"(",
"'DEBUG'",
")",
"&&",
"DEBUG",
")",
"{",
"echo",
"'<pre>'",
".",
"$",
"throwable",
"->",
"getTraceAsString",
"(",
")",
".",
"'</pre>'",
";",
"}",
"die",
"(",
"-",
"1",
")",
";",
"}"
] | Stops the application and outputs an error.
@param Throwable $throwable the error that caused the application to
stop. | [
"Stops",
"the",
"application",
"and",
"outputs",
"an",
"error",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L198-L211 |
1,871 | eix/core | src/php/main/Eix/Core/Application.php | Application.getSettings | public static function getSettings()
{
try {
return self::getCurrent()->settings;
} catch (Exception $exception) {
// No application running.
throw new SettingsException(
$exception->getMessage(),
$exception->getCode(),
$exception
);
}
} | php | public static function getSettings()
{
try {
return self::getCurrent()->settings;
} catch (Exception $exception) {
// No application running.
throw new SettingsException(
$exception->getMessage(),
$exception->getCode(),
$exception
);
}
} | [
"public",
"static",
"function",
"getSettings",
"(",
")",
"{",
"try",
"{",
"return",
"self",
"::",
"getCurrent",
"(",
")",
"->",
"settings",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"// No application running.",
"throw",
"new",
"SettingsException",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"$",
"exception",
"->",
"getCode",
"(",
")",
",",
"$",
"exception",
")",
";",
"}",
"}"
] | Provides access to the current application's settings.
@return \Eix\Core\Settings the current application's settings; | [
"Provides",
"access",
"to",
"the",
"current",
"application",
"s",
"settings",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L218-L230 |
1,872 | eix/core | src/php/main/Eix/Core/Application.php | Application.handleError | public function handleError($number, $message, $file, $line, array $context)
{
// This avoids silenced (@'ed) errors from being reported.
if (error_reporting()) {
$message = "PHP error $number: $message\n\tat $file:$line";
Logger::get()->error($message);
$this->handleException(new \RuntimeException($message));
}
} | php | public function handleError($number, $message, $file, $line, array $context)
{
// This avoids silenced (@'ed) errors from being reported.
if (error_reporting()) {
$message = "PHP error $number: $message\n\tat $file:$line";
Logger::get()->error($message);
$this->handleException(new \RuntimeException($message));
}
} | [
"public",
"function",
"handleError",
"(",
"$",
"number",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
",",
"array",
"$",
"context",
")",
"{",
"// This avoids silenced (@'ed) errors from being reported.",
"if",
"(",
"error_reporting",
"(",
")",
")",
"{",
"$",
"message",
"=",
"\"PHP error $number: $message\\n\\tat $file:$line\"",
";",
"Logger",
"::",
"get",
"(",
")",
"->",
"error",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"handleException",
"(",
"new",
"\\",
"RuntimeException",
"(",
"$",
"message",
")",
")",
";",
"}",
"}"
] | Eix's way of handling a PHP error is to wrap it in a runtime exception
and throw it, so that the standard exception handler can catch it. | [
"Eix",
"s",
"way",
"of",
"handling",
"a",
"PHP",
"error",
"is",
"to",
"wrap",
"it",
"in",
"a",
"runtime",
"exception",
"and",
"throw",
"it",
"so",
"that",
"the",
"standard",
"exception",
"handler",
"can",
"catch",
"it",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L236-L244 |
1,873 | eix/core | src/php/main/Eix/Core/Application.php | Application.setLocale | public function setLocale($locale = null)
{
if (class_exists('\Locale')) {
$this->locale = \Locale::lookup(
$this->getAvailableLocales(),
$locale,
true,
$this->getSettings()->locale->default
);
}
if (empty($this->locale)) {
$this->locale = $this->getSettings()->locale->default;
}
// Set up locale environment for gettext.
bindtextdomain(self::TEXT_DOMAIN_NAME, self::TEXT_DOMAIN_LOCATION);
bind_textdomain_codeset(self::TEXT_DOMAIN_NAME, 'UTF-8');
textdomain(self::TEXT_DOMAIN_NAME);
putenv('LANG=' . $this->locale);
putenv('LC_MESSAGES=' . $this->locale);
$locale = setlocale(LC_MESSAGES, $this->locale);
Logger::get()->info(sprintf('Locale is now %s [%s] (domain "%s" at %s)',
$locale,
$this->locale,
self::TEXT_DOMAIN_NAME,
realpath(self::TEXT_DOMAIN_LOCATION)
));
} | php | public function setLocale($locale = null)
{
if (class_exists('\Locale')) {
$this->locale = \Locale::lookup(
$this->getAvailableLocales(),
$locale,
true,
$this->getSettings()->locale->default
);
}
if (empty($this->locale)) {
$this->locale = $this->getSettings()->locale->default;
}
// Set up locale environment for gettext.
bindtextdomain(self::TEXT_DOMAIN_NAME, self::TEXT_DOMAIN_LOCATION);
bind_textdomain_codeset(self::TEXT_DOMAIN_NAME, 'UTF-8');
textdomain(self::TEXT_DOMAIN_NAME);
putenv('LANG=' . $this->locale);
putenv('LC_MESSAGES=' . $this->locale);
$locale = setlocale(LC_MESSAGES, $this->locale);
Logger::get()->info(sprintf('Locale is now %s [%s] (domain "%s" at %s)',
$locale,
$this->locale,
self::TEXT_DOMAIN_NAME,
realpath(self::TEXT_DOMAIN_LOCATION)
));
} | [
"public",
"function",
"setLocale",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\Locale'",
")",
")",
"{",
"$",
"this",
"->",
"locale",
"=",
"\\",
"Locale",
"::",
"lookup",
"(",
"$",
"this",
"->",
"getAvailableLocales",
"(",
")",
",",
"$",
"locale",
",",
"true",
",",
"$",
"this",
"->",
"getSettings",
"(",
")",
"->",
"locale",
"->",
"default",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"locale",
")",
")",
"{",
"$",
"this",
"->",
"locale",
"=",
"$",
"this",
"->",
"getSettings",
"(",
")",
"->",
"locale",
"->",
"default",
";",
"}",
"// Set up locale environment for gettext.",
"bindtextdomain",
"(",
"self",
"::",
"TEXT_DOMAIN_NAME",
",",
"self",
"::",
"TEXT_DOMAIN_LOCATION",
")",
";",
"bind_textdomain_codeset",
"(",
"self",
"::",
"TEXT_DOMAIN_NAME",
",",
"'UTF-8'",
")",
";",
"textdomain",
"(",
"self",
"::",
"TEXT_DOMAIN_NAME",
")",
";",
"putenv",
"(",
"'LANG='",
".",
"$",
"this",
"->",
"locale",
")",
";",
"putenv",
"(",
"'LC_MESSAGES='",
".",
"$",
"this",
"->",
"locale",
")",
";",
"$",
"locale",
"=",
"setlocale",
"(",
"LC_MESSAGES",
",",
"$",
"this",
"->",
"locale",
")",
";",
"Logger",
"::",
"get",
"(",
")",
"->",
"info",
"(",
"sprintf",
"(",
"'Locale is now %s [%s] (domain \"%s\" at %s)'",
",",
"$",
"locale",
",",
"$",
"this",
"->",
"locale",
",",
"self",
"::",
"TEXT_DOMAIN_NAME",
",",
"realpath",
"(",
"self",
"::",
"TEXT_DOMAIN_LOCATION",
")",
")",
")",
";",
"}"
] | Sets the locale of the application, if this locale is available.
@param string $locale the new locale. | [
"Sets",
"the",
"locale",
"of",
"the",
"application",
"if",
"this",
"locale",
"is",
"available",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L326-L355 |
1,874 | eix/core | src/php/main/Eix/Core/Application.php | Application.keepCurrentLocator | private function keepCurrentLocator(Request $request)
{
// Ensure a location is not already set, to avoid overwriting it.
if (!@$_COOKIE[self::LOCATOR_COOKIE_NAME]) {
$currentUrl = $request->getCurrentUrl();
// Do not keep identity URLs.
if (!preg_match('#/identity.+#', $currentUrl)) {
setcookie(
self::LOCATOR_COOKIE_NAME,
$currentUrl,
time() + 300 // Keep it for 5 minutes.
);
Logger::get()->debug('Current locator stored: ' . $currentUrl);
}
}
} | php | private function keepCurrentLocator(Request $request)
{
// Ensure a location is not already set, to avoid overwriting it.
if (!@$_COOKIE[self::LOCATOR_COOKIE_NAME]) {
$currentUrl = $request->getCurrentUrl();
// Do not keep identity URLs.
if (!preg_match('#/identity.+#', $currentUrl)) {
setcookie(
self::LOCATOR_COOKIE_NAME,
$currentUrl,
time() + 300 // Keep it for 5 minutes.
);
Logger::get()->debug('Current locator stored: ' . $currentUrl);
}
}
} | [
"private",
"function",
"keepCurrentLocator",
"(",
"Request",
"$",
"request",
")",
"{",
"// Ensure a location is not already set, to avoid overwriting it.",
"if",
"(",
"!",
"@",
"$",
"_COOKIE",
"[",
"self",
"::",
"LOCATOR_COOKIE_NAME",
"]",
")",
"{",
"$",
"currentUrl",
"=",
"$",
"request",
"->",
"getCurrentUrl",
"(",
")",
";",
"// Do not keep identity URLs.",
"if",
"(",
"!",
"preg_match",
"(",
"'#/identity.+#'",
",",
"$",
"currentUrl",
")",
")",
"{",
"setcookie",
"(",
"self",
"::",
"LOCATOR_COOKIE_NAME",
",",
"$",
"currentUrl",
",",
"time",
"(",
")",
"+",
"300",
"// Keep it for 5 minutes.",
")",
";",
"Logger",
"::",
"get",
"(",
")",
"->",
"debug",
"(",
"'Current locator stored: '",
".",
"$",
"currentUrl",
")",
";",
"}",
"}",
"}"
] | Keeps the currently requested URL, to be able to retrieve it at a later
point. | [
"Keeps",
"the",
"currently",
"requested",
"URL",
"to",
"be",
"able",
"to",
"retrieve",
"it",
"at",
"a",
"later",
"point",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L361-L376 |
1,875 | eix/core | src/php/main/Eix/Core/Application.php | Application.popLastLocator | public function popLastLocator()
{
$lastLocator = @$_COOKIE[self::LOCATOR_COOKIE_NAME];
// Check whether a locator is set.
if ($lastLocator) {
// There is a locator. Clear its cookie.
setcookie(
self::LOCATOR_COOKIE_NAME,
null,
time() - 1 // Expire the cookie.
);
}
return $lastLocator;
} | php | public function popLastLocator()
{
$lastLocator = @$_COOKIE[self::LOCATOR_COOKIE_NAME];
// Check whether a locator is set.
if ($lastLocator) {
// There is a locator. Clear its cookie.
setcookie(
self::LOCATOR_COOKIE_NAME,
null,
time() - 1 // Expire the cookie.
);
}
return $lastLocator;
} | [
"public",
"function",
"popLastLocator",
"(",
")",
"{",
"$",
"lastLocator",
"=",
"@",
"$",
"_COOKIE",
"[",
"self",
"::",
"LOCATOR_COOKIE_NAME",
"]",
";",
"// Check whether a locator is set.",
"if",
"(",
"$",
"lastLocator",
")",
"{",
"// There is a locator. Clear its cookie.",
"setcookie",
"(",
"self",
"::",
"LOCATOR_COOKIE_NAME",
",",
"null",
",",
"time",
"(",
")",
"-",
"1",
"// Expire the cookie.",
")",
";",
"}",
"return",
"$",
"lastLocator",
";",
"}"
] | Returns the latest stored URL, and clears the record. | [
"Returns",
"the",
"latest",
"stored",
"URL",
"and",
"clears",
"the",
"record",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L381-L395 |
1,876 | eix/core | src/php/main/Eix/Core/Application.php | Application.getAvailableLocales | private function getAvailableLocales()
{
if (empty($this->availableLocales)) {
// Open the pages directory.
$pagesDirectory = opendir('../data/pages/');
while ($directory = readdir($pagesDirectory)) {
if (($directory != '.') && ($directory != '..')) {
$this->availableLocales[] = $directory;
}
}
closedir($pagesDirectory);
}
return $this->availableLocales;
} | php | private function getAvailableLocales()
{
if (empty($this->availableLocales)) {
// Open the pages directory.
$pagesDirectory = opendir('../data/pages/');
while ($directory = readdir($pagesDirectory)) {
if (($directory != '.') && ($directory != '..')) {
$this->availableLocales[] = $directory;
}
}
closedir($pagesDirectory);
}
return $this->availableLocales;
} | [
"private",
"function",
"getAvailableLocales",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"availableLocales",
")",
")",
"{",
"// Open the pages directory.",
"$",
"pagesDirectory",
"=",
"opendir",
"(",
"'../data/pages/'",
")",
";",
"while",
"(",
"$",
"directory",
"=",
"readdir",
"(",
"$",
"pagesDirectory",
")",
")",
"{",
"if",
"(",
"(",
"$",
"directory",
"!=",
"'.'",
")",
"&&",
"(",
"$",
"directory",
"!=",
"'..'",
")",
")",
"{",
"$",
"this",
"->",
"availableLocales",
"[",
"]",
"=",
"$",
"directory",
";",
"}",
"}",
"closedir",
"(",
"$",
"pagesDirectory",
")",
";",
"}",
"return",
"$",
"this",
"->",
"availableLocales",
";",
"}"
] | Gathers all the locales the application can serve. | [
"Gathers",
"all",
"the",
"locales",
"the",
"application",
"can",
"serve",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L400-L414 |
1,877 | eix/core | src/php/main/Eix/Core/Application.php | Application.getStats | protected function getStats()
{
$endTime = microtime() - $this->startTime;
$stats = sprintf(
'Request-response cycle finished: %1.3fs'
. ' - Memory usage: %1.2fMB (peak: %1.2fMB)'
,
$endTime,
memory_get_usage(true) / 1048576,
memory_get_peak_usage(true) / 1048576
);
return $stats;
} | php | protected function getStats()
{
$endTime = microtime() - $this->startTime;
$stats = sprintf(
'Request-response cycle finished: %1.3fs'
. ' - Memory usage: %1.2fMB (peak: %1.2fMB)'
,
$endTime,
memory_get_usage(true) / 1048576,
memory_get_peak_usage(true) / 1048576
);
return $stats;
} | [
"protected",
"function",
"getStats",
"(",
")",
"{",
"$",
"endTime",
"=",
"microtime",
"(",
")",
"-",
"$",
"this",
"->",
"startTime",
";",
"$",
"stats",
"=",
"sprintf",
"(",
"'Request-response cycle finished: %1.3fs'",
".",
"' - Memory usage: %1.2fMB (peak: %1.2fMB)'",
",",
"$",
"endTime",
",",
"memory_get_usage",
"(",
"true",
")",
"/",
"1048576",
",",
"memory_get_peak_usage",
"(",
"true",
")",
"/",
"1048576",
")",
";",
"return",
"$",
"stats",
";",
"}"
] | Gather some runtime statistics. | [
"Gather",
"some",
"runtime",
"statistics",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L419-L432 |
1,878 | eix/core | src/php/main/Eix/Core/Application.php | Application.getLocale | public function getLocale()
{
if (empty($this->locale)) {
$this->locale = $this->getSettings()->locale->default;
}
return $this->locale;
} | php | public function getLocale()
{
if (empty($this->locale)) {
$this->locale = $this->getSettings()->locale->default;
}
return $this->locale;
} | [
"public",
"function",
"getLocale",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"locale",
")",
")",
"{",
"$",
"this",
"->",
"locale",
"=",
"$",
"this",
"->",
"getSettings",
"(",
")",
"->",
"locale",
"->",
"default",
";",
"}",
"return",
"$",
"this",
"->",
"locale",
";",
"}"
] | This should probably go in Http\Request. | [
"This",
"should",
"probably",
"go",
"in",
"Http",
"\\",
"Request",
"."
] | a5b4c09cc168221e85804fdfeb78e519a0415466 | https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Application.php#L437-L444 |
1,879 | popy-dev/popy-calendar | src/Parser/FormatToken.php | FormatToken.isOne | public function isOne($symbols)
{
if ($this->type !== self::TYPE_SYMBOL) {
return false;
}
if (!is_array($symbols)) {
$symbols = func_get_args();
}
return in_array($this->value, $symbols);
} | php | public function isOne($symbols)
{
if ($this->type !== self::TYPE_SYMBOL) {
return false;
}
if (!is_array($symbols)) {
$symbols = func_get_args();
}
return in_array($this->value, $symbols);
} | [
"public",
"function",
"isOne",
"(",
"$",
"symbols",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"!==",
"self",
"::",
"TYPE_SYMBOL",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"symbols",
")",
")",
"{",
"$",
"symbols",
"=",
"func_get_args",
"(",
")",
";",
"}",
"return",
"in_array",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"symbols",
")",
";",
"}"
] | Checks if token is a TYPE_SYMBOL matching one of the arguments,
or one of the symbol contained in the first argument if it is an array
@param array|string $symbols
@param string ...$symbols
@return boolean | [
"Checks",
"if",
"token",
"is",
"a",
"TYPE_SYMBOL",
"matching",
"one",
"of",
"the",
"arguments",
"or",
"one",
"of",
"the",
"symbol",
"contained",
"in",
"the",
"first",
"argument",
"if",
"it",
"is",
"an",
"array"
] | 989048be18451c813cfce926229c6aaddd1b0639 | https://github.com/popy-dev/popy-calendar/blob/989048be18451c813cfce926229c6aaddd1b0639/src/Parser/FormatToken.php#L104-L115 |
1,880 | fenghuilee/phalbee-core | src/Base/View/Engine/Smarty.php | Smarty.setOptions | public function setOptions(array $options)
{
foreach ($options as $k => $v) {
$this->smarty->$k = $v;
}
} | php | public function setOptions(array $options)
{
foreach ($options as $k => $v) {
$this->smarty->$k = $v;
}
} | [
"public",
"function",
"setOptions",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"smarty",
"->",
"$",
"k",
"=",
"$",
"v",
";",
"}",
"}"
] | Set Smarty's options
@param array $options | [
"Set",
"Smarty",
"s",
"options"
] | d38ca89cbd1731fed51826ff38255086b8894eb0 | https://github.com/fenghuilee/phalbee-core/blob/d38ca89cbd1731fed51826ff38255086b8894eb0/src/Base/View/Engine/Smarty.php#L64-L69 |
1,881 | benkle-libs/feed-parser | src/Traits/WithEnclosuresTrait.php | WithEnclosuresTrait.removeEnclosure | public function removeEnclosure(EnclosureInterface $enclosure)
{
foreach ($this->enclosures as $i => $itemEnclosure) {
if ($itemEnclosure == $enclosure) {
unset($this->enclosures[$i]);
}
}
$this->enclosures = array_values($this->enclosures);
return $this;
} | php | public function removeEnclosure(EnclosureInterface $enclosure)
{
foreach ($this->enclosures as $i => $itemEnclosure) {
if ($itemEnclosure == $enclosure) {
unset($this->enclosures[$i]);
}
}
$this->enclosures = array_values($this->enclosures);
return $this;
} | [
"public",
"function",
"removeEnclosure",
"(",
"EnclosureInterface",
"$",
"enclosure",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"enclosures",
"as",
"$",
"i",
"=>",
"$",
"itemEnclosure",
")",
"{",
"if",
"(",
"$",
"itemEnclosure",
"==",
"$",
"enclosure",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"enclosures",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"enclosures",
"=",
"array_values",
"(",
"$",
"this",
"->",
"enclosures",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Remove an enclosure from the feed.
@param EnclosureInterface $enclosure
@return $this | [
"Remove",
"an",
"enclosure",
"from",
"the",
"feed",
"."
] | 8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f | https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Traits/WithEnclosuresTrait.php#L45-L54 |
1,882 | AnonymPHP/Anonym-Library | src/Anonym/Application/Console/ConfigCacheCommand.php | ConfigCacheCommand.handle | public function handle(){
$cachedPath = SYSTEM.'cached_configs.php';
$configs = $this->loadAllConfigs();
$this->file->put($cachedPath, '<?php return '.var_export($configs, true).';'.PHP_EOL);
$this->info('Configuration cached successfully!');
} | php | public function handle(){
$cachedPath = SYSTEM.'cached_configs.php';
$configs = $this->loadAllConfigs();
$this->file->put($cachedPath, '<?php return '.var_export($configs, true).';'.PHP_EOL);
$this->info('Configuration cached successfully!');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"cachedPath",
"=",
"SYSTEM",
".",
"'cached_configs.php'",
";",
"$",
"configs",
"=",
"$",
"this",
"->",
"loadAllConfigs",
"(",
")",
";",
"$",
"this",
"->",
"file",
"->",
"put",
"(",
"$",
"cachedPath",
",",
"'<?php return '",
".",
"var_export",
"(",
"$",
"configs",
",",
"true",
")",
".",
"';'",
".",
"PHP_EOL",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Configuration cached successfully!'",
")",
";",
"}"
] | handle the command
@param InputInterface $input
@param OutputInterface $output
@return mixed | [
"handle",
"the",
"command"
] | c967ad804f84e8fb204593a0959cda2fed5ae075 | https://github.com/AnonymPHP/Anonym-Library/blob/c967ad804f84e8fb204593a0959cda2fed5ae075/src/Anonym/Application/Console/ConfigCacheCommand.php#L72-L79 |
1,883 | eosnewmedia/JSON-API-Server-Resource-Mappers | src/Mapper/ResourceMapperRegistry.php | ResourceMapperRegistry.supportsEntity | public function supportsEntity(EntityInterface $entity): bool
{
foreach ($this->mappers as $mapper) {
if ($mapper->supportsEntity($entity)) {
return true;
}
}
return false;
} | php | public function supportsEntity(EntityInterface $entity): bool
{
foreach ($this->mappers as $mapper) {
if ($mapper->supportsEntity($entity)) {
return true;
}
}
return false;
} | [
"public",
"function",
"supportsEntity",
"(",
"EntityInterface",
"$",
"entity",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"mappers",
"as",
"$",
"mapper",
")",
"{",
"if",
"(",
"$",
"mapper",
"->",
"supportsEntity",
"(",
"$",
"entity",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Indicates if this mapper can handle the given entity
@param EntityInterface $entity
@return bool | [
"Indicates",
"if",
"this",
"mapper",
"can",
"handle",
"the",
"given",
"entity"
] | 0fe9b45f7093e5be0d149fc5d888afdb092fa0dc | https://github.com/eosnewmedia/JSON-API-Server-Resource-Mappers/blob/0fe9b45f7093e5be0d149fc5d888afdb092fa0dc/src/Mapper/ResourceMapperRegistry.php#L41-L50 |
1,884 | eosnewmedia/JSON-API-Server-Resource-Mappers | src/Mapper/ResourceMapperRegistry.php | ResourceMapperRegistry.toEntityFull | public function toEntityFull(ResourceInterface $resource, EntityInterface $entity)
{
foreach ($this->mappers as $mapper) {
if ($mapper->supportsEntity($entity)) {
$this->configureResourceMapper($mapper);
$mapper->toEntityFull($resource, $entity);
return;
}
}
throw new UnsupportedTypeException($resource->type());
} | php | public function toEntityFull(ResourceInterface $resource, EntityInterface $entity)
{
foreach ($this->mappers as $mapper) {
if ($mapper->supportsEntity($entity)) {
$this->configureResourceMapper($mapper);
$mapper->toEntityFull($resource, $entity);
return;
}
}
throw new UnsupportedTypeException($resource->type());
} | [
"public",
"function",
"toEntityFull",
"(",
"ResourceInterface",
"$",
"resource",
",",
"EntityInterface",
"$",
"entity",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"mappers",
"as",
"$",
"mapper",
")",
"{",
"if",
"(",
"$",
"mapper",
"->",
"supportsEntity",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"this",
"->",
"configureResourceMapper",
"(",
"$",
"mapper",
")",
";",
"$",
"mapper",
"->",
"toEntityFull",
"(",
"$",
"resource",
",",
"$",
"entity",
")",
";",
"return",
";",
"}",
"}",
"throw",
"new",
"UnsupportedTypeException",
"(",
"$",
"resource",
"->",
"type",
"(",
")",
")",
";",
"}"
] | Maps all fields of the given api resource from post request to the given entity and throws an exception if required elements are missing
@param ResourceInterface $resource
@param EntityInterface $entity
@return void
@throws JsonApiException | [
"Maps",
"all",
"fields",
"of",
"the",
"given",
"api",
"resource",
"from",
"post",
"request",
"to",
"the",
"given",
"entity",
"and",
"throws",
"an",
"exception",
"if",
"required",
"elements",
"are",
"missing"
] | 0fe9b45f7093e5be0d149fc5d888afdb092fa0dc | https://github.com/eosnewmedia/JSON-API-Server-Resource-Mappers/blob/0fe9b45f7093e5be0d149fc5d888afdb092fa0dc/src/Mapper/ResourceMapperRegistry.php#L85-L97 |
1,885 | tjbp/tablelegs | src/lib/Table.php | Table.constructDatabase | private function constructDatabase($db)
{
if (is_null($this->dbClass)) {
if (is_array($db)) {
if (array_keys($db) !== range(0, count($db) - 1)) {
$this->db = new Databases\AssociativeArray($db);
} else {
$this->db = new Databases\NumericArray($db);
}
} elseif ($db instanceof \Illuminate\Support\Collection) {
$this->db = new Databases\LaravelCollection($db);
} elseif ($db instanceof \Illuminate\Database\Eloquent\Builder
|| $db instanceof \Illuminate\Database\Eloquent\Relations\Relation) {
$this->db = new Databases\LaravelEloquent($db);
} elseif (!is_object($db)) {
throw new InvalidArgumentException('Database must be an object or array');
} else {
$class_name = get_class($db);
throw new DomainException("Please add database class for handling $class_name objects");
}
} else {
$this->db = new $dbClass($db);
}
} | php | private function constructDatabase($db)
{
if (is_null($this->dbClass)) {
if (is_array($db)) {
if (array_keys($db) !== range(0, count($db) - 1)) {
$this->db = new Databases\AssociativeArray($db);
} else {
$this->db = new Databases\NumericArray($db);
}
} elseif ($db instanceof \Illuminate\Support\Collection) {
$this->db = new Databases\LaravelCollection($db);
} elseif ($db instanceof \Illuminate\Database\Eloquent\Builder
|| $db instanceof \Illuminate\Database\Eloquent\Relations\Relation) {
$this->db = new Databases\LaravelEloquent($db);
} elseif (!is_object($db)) {
throw new InvalidArgumentException('Database must be an object or array');
} else {
$class_name = get_class($db);
throw new DomainException("Please add database class for handling $class_name objects");
}
} else {
$this->db = new $dbClass($db);
}
} | [
"private",
"function",
"constructDatabase",
"(",
"$",
"db",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"dbClass",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"db",
")",
")",
"{",
"if",
"(",
"array_keys",
"(",
"$",
"db",
")",
"!==",
"range",
"(",
"0",
",",
"count",
"(",
"$",
"db",
")",
"-",
"1",
")",
")",
"{",
"$",
"this",
"->",
"db",
"=",
"new",
"Databases",
"\\",
"AssociativeArray",
"(",
"$",
"db",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"db",
"=",
"new",
"Databases",
"\\",
"NumericArray",
"(",
"$",
"db",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"db",
"instanceof",
"\\",
"Illuminate",
"\\",
"Support",
"\\",
"Collection",
")",
"{",
"$",
"this",
"->",
"db",
"=",
"new",
"Databases",
"\\",
"LaravelCollection",
"(",
"$",
"db",
")",
";",
"}",
"elseif",
"(",
"$",
"db",
"instanceof",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"Builder",
"||",
"$",
"db",
"instanceof",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"Relations",
"\\",
"Relation",
")",
"{",
"$",
"this",
"->",
"db",
"=",
"new",
"Databases",
"\\",
"LaravelEloquent",
"(",
"$",
"db",
")",
";",
"}",
"elseif",
"(",
"!",
"is_object",
"(",
"$",
"db",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Database must be an object or array'",
")",
";",
"}",
"else",
"{",
"$",
"class_name",
"=",
"get_class",
"(",
"$",
"db",
")",
";",
"throw",
"new",
"DomainException",
"(",
"\"Please add database class for handling $class_name objects\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"db",
"=",
"new",
"$",
"dbClass",
"(",
"$",
"db",
")",
";",
"}",
"}"
] | Instantiate the database.
@param mixed $db
@return void | [
"Instantiate",
"the",
"database",
"."
] | 89916f6662ab324a96c62672ed4bb9a6e9cb3360 | https://github.com/tjbp/tablelegs/blob/89916f6662ab324a96c62672ed4bb9a6e9cb3360/src/lib/Table.php#L159-L183 |
1,886 | tjbp/tablelegs | src/lib/Table.php | Table.constructColumnHeaders | private function constructColumnHeaders()
{
foreach ($this->columnHeaders as $column_name => $column_key) {
$this->columnHeaderObjects[] = new TableColumnHeader(
$this,
$this->request,
$column_key,
$column_name
);
}
} | php | private function constructColumnHeaders()
{
foreach ($this->columnHeaders as $column_name => $column_key) {
$this->columnHeaderObjects[] = new TableColumnHeader(
$this,
$this->request,
$column_key,
$column_name
);
}
} | [
"private",
"function",
"constructColumnHeaders",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"columnHeaders",
"as",
"$",
"column_name",
"=>",
"$",
"column_key",
")",
"{",
"$",
"this",
"->",
"columnHeaderObjects",
"[",
"]",
"=",
"new",
"TableColumnHeader",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"request",
",",
"$",
"column_key",
",",
"$",
"column_name",
")",
";",
"}",
"}"
] | Instantiate the column headers.
@return void | [
"Instantiate",
"the",
"column",
"headers",
"."
] | 89916f6662ab324a96c62672ed4bb9a6e9cb3360 | https://github.com/tjbp/tablelegs/blob/89916f6662ab324a96c62672ed4bb9a6e9cb3360/src/lib/Table.php#L190-L200 |
1,887 | tjbp/tablelegs | src/lib/Table.php | Table.constructFilters | private function constructFilters()
{
foreach ($this->filters as $filter_name => $filter_options) {
$this->filterObjects[] = new TableFilter(
$this->request,
$filter_name,
$filter_options
);
}
} | php | private function constructFilters()
{
foreach ($this->filters as $filter_name => $filter_options) {
$this->filterObjects[] = new TableFilter(
$this->request,
$filter_name,
$filter_options
);
}
} | [
"private",
"function",
"constructFilters",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"filter_name",
"=>",
"$",
"filter_options",
")",
"{",
"$",
"this",
"->",
"filterObjects",
"[",
"]",
"=",
"new",
"TableFilter",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"filter_name",
",",
"$",
"filter_options",
")",
";",
"}",
"}"
] | Instantiate the filters.
@return void | [
"Instantiate",
"the",
"filters",
"."
] | 89916f6662ab324a96c62672ed4bb9a6e9cb3360 | https://github.com/tjbp/tablelegs/blob/89916f6662ab324a96c62672ed4bb9a6e9cb3360/src/lib/Table.php#L207-L216 |
1,888 | tjbp/tablelegs | src/lib/Table.php | Table.runFilters | private function runFilters()
{
foreach ($this->filterObjects as $filter) {
$filter_key = $filter->getKey();
// Execute the filter method if enabled
if ($this->request->has($filter_key)) {
$filter_option = ucfirst(preg_replace('/[^a-z0-9]/i', ' ', $this->request->input($filter_key)));
$filter_key = ucfirst(preg_replace('/[^a-z0-9]/i', ' ', $filter_key));
if (!in_array($filter_option, $this->filters[$filter_key])) {
continue;
}
$filter_method = 'filter'.Str::studly($filter_key).Str::studly($filter_option);
if (method_exists($this, $filter_method)) {
$this->$filter_method();
}
}
}
} | php | private function runFilters()
{
foreach ($this->filterObjects as $filter) {
$filter_key = $filter->getKey();
// Execute the filter method if enabled
if ($this->request->has($filter_key)) {
$filter_option = ucfirst(preg_replace('/[^a-z0-9]/i', ' ', $this->request->input($filter_key)));
$filter_key = ucfirst(preg_replace('/[^a-z0-9]/i', ' ', $filter_key));
if (!in_array($filter_option, $this->filters[$filter_key])) {
continue;
}
$filter_method = 'filter'.Str::studly($filter_key).Str::studly($filter_option);
if (method_exists($this, $filter_method)) {
$this->$filter_method();
}
}
}
} | [
"private",
"function",
"runFilters",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filterObjects",
"as",
"$",
"filter",
")",
"{",
"$",
"filter_key",
"=",
"$",
"filter",
"->",
"getKey",
"(",
")",
";",
"// Execute the filter method if enabled",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"has",
"(",
"$",
"filter_key",
")",
")",
"{",
"$",
"filter_option",
"=",
"ucfirst",
"(",
"preg_replace",
"(",
"'/[^a-z0-9]/i'",
",",
"' '",
",",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"$",
"filter_key",
")",
")",
")",
";",
"$",
"filter_key",
"=",
"ucfirst",
"(",
"preg_replace",
"(",
"'/[^a-z0-9]/i'",
",",
"' '",
",",
"$",
"filter_key",
")",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"filter_option",
",",
"$",
"this",
"->",
"filters",
"[",
"$",
"filter_key",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"filter_method",
"=",
"'filter'",
".",
"Str",
"::",
"studly",
"(",
"$",
"filter_key",
")",
".",
"Str",
"::",
"studly",
"(",
"$",
"filter_option",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"filter_method",
")",
")",
"{",
"$",
"this",
"->",
"$",
"filter_method",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | Run the filters.
@return void | [
"Run",
"the",
"filters",
"."
] | 89916f6662ab324a96c62672ed4bb9a6e9cb3360 | https://github.com/tjbp/tablelegs/blob/89916f6662ab324a96c62672ed4bb9a6e9cb3360/src/lib/Table.php#L223-L245 |
1,889 | tjbp/tablelegs | src/lib/Table.php | Table.runSorting | private function runSorting()
{
$sort_method = 'sort'.studly_case($this->sortKey);
// Apply the sorting for the query
if (method_exists($this, $sort_method)) {
$this->$sort_method($this->sortOrder);
} else {
$this->db->sort($this->sortKey, $this->sortOrder);
}
} | php | private function runSorting()
{
$sort_method = 'sort'.studly_case($this->sortKey);
// Apply the sorting for the query
if (method_exists($this, $sort_method)) {
$this->$sort_method($this->sortOrder);
} else {
$this->db->sort($this->sortKey, $this->sortOrder);
}
} | [
"private",
"function",
"runSorting",
"(",
")",
"{",
"$",
"sort_method",
"=",
"'sort'",
".",
"studly_case",
"(",
"$",
"this",
"->",
"sortKey",
")",
";",
"// Apply the sorting for the query",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"sort_method",
")",
")",
"{",
"$",
"this",
"->",
"$",
"sort_method",
"(",
"$",
"this",
"->",
"sortOrder",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"db",
"->",
"sort",
"(",
"$",
"this",
"->",
"sortKey",
",",
"$",
"this",
"->",
"sortOrder",
")",
";",
"}",
"}"
] | Run the sorting.
@return void | [
"Run",
"the",
"sorting",
"."
] | 89916f6662ab324a96c62672ed4bb9a6e9cb3360 | https://github.com/tjbp/tablelegs/blob/89916f6662ab324a96c62672ed4bb9a6e9cb3360/src/lib/Table.php#L252-L262 |
1,890 | tjbp/tablelegs | src/lib/Table.php | Table.paginate | public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
$per_page = ($this->request->has('per_page'))
? $this->request->get('per_page')
: $perPage;
$paginator = $this->db->paginate($per_page, $columns, $pageName, $page);
$paginator->appends($this->request->all());
return $paginator;
} | php | public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
$per_page = ($this->request->has('per_page'))
? $this->request->get('per_page')
: $perPage;
$paginator = $this->db->paginate($per_page, $columns, $pageName, $page);
$paginator->appends($this->request->all());
return $paginator;
} | [
"public",
"function",
"paginate",
"(",
"$",
"perPage",
"=",
"15",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
",",
"$",
"pageName",
"=",
"'page'",
",",
"$",
"page",
"=",
"null",
")",
"{",
"$",
"per_page",
"=",
"(",
"$",
"this",
"->",
"request",
"->",
"has",
"(",
"'per_page'",
")",
")",
"?",
"$",
"this",
"->",
"request",
"->",
"get",
"(",
"'per_page'",
")",
":",
"$",
"perPage",
";",
"$",
"paginator",
"=",
"$",
"this",
"->",
"db",
"->",
"paginate",
"(",
"$",
"per_page",
",",
"$",
"columns",
",",
"$",
"pageName",
",",
"$",
"page",
")",
";",
"$",
"paginator",
"->",
"appends",
"(",
"$",
"this",
"->",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"$",
"paginator",
";",
"}"
] | Return paginated rows.
@return \Illuminate\Pagination\LengthAwarePaginator | [
"Return",
"paginated",
"rows",
"."
] | 89916f6662ab324a96c62672ed4bb9a6e9cb3360 | https://github.com/tjbp/tablelegs/blob/89916f6662ab324a96c62672ed4bb9a6e9cb3360/src/lib/Table.php#L309-L320 |
1,891 | tjbp/tablelegs | src/lib/Table.php | Table.paginator | public function paginator()
{
$paginator = $this->paginate();
if (!is_null($this->presenter)) {
return (new $this->presenter($paginator))->render();
}
return $paginator->render();
} | php | public function paginator()
{
$paginator = $this->paginate();
if (!is_null($this->presenter)) {
return (new $this->presenter($paginator))->render();
}
return $paginator->render();
} | [
"public",
"function",
"paginator",
"(",
")",
"{",
"$",
"paginator",
"=",
"$",
"this",
"->",
"paginate",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"presenter",
")",
")",
"{",
"return",
"(",
"new",
"$",
"this",
"->",
"presenter",
"(",
"$",
"paginator",
")",
")",
"->",
"render",
"(",
")",
";",
"}",
"return",
"$",
"paginator",
"->",
"render",
"(",
")",
";",
"}"
] | Return the paginator presenter markup.
@return string | [
"Return",
"the",
"paginator",
"presenter",
"markup",
"."
] | 89916f6662ab324a96c62672ed4bb9a6e9cb3360 | https://github.com/tjbp/tablelegs/blob/89916f6662ab324a96c62672ed4bb9a6e9cb3360/src/lib/Table.php#L327-L336 |
1,892 | mijohansen/php-gae-util | src/DataStore.php | DataStore.retriveTokensByScope | static function retriveTokensByScope($scope, $domain = null) {
$kind_schema = self::getGoogleAccessTokenKind();
$str_query = "SELECT * FROM $kind_schema WHERE scopes='$scope'";
if (!is_null($domain)) {
$str_query = $str_query . " AND domain='$domain'";
}
return self::fetchAll($kind_schema, $str_query);
} | php | static function retriveTokensByScope($scope, $domain = null) {
$kind_schema = self::getGoogleAccessTokenKind();
$str_query = "SELECT * FROM $kind_schema WHERE scopes='$scope'";
if (!is_null($domain)) {
$str_query = $str_query . " AND domain='$domain'";
}
return self::fetchAll($kind_schema, $str_query);
} | [
"static",
"function",
"retriveTokensByScope",
"(",
"$",
"scope",
",",
"$",
"domain",
"=",
"null",
")",
"{",
"$",
"kind_schema",
"=",
"self",
"::",
"getGoogleAccessTokenKind",
"(",
")",
";",
"$",
"str_query",
"=",
"\"SELECT * FROM $kind_schema WHERE scopes='$scope'\"",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"domain",
")",
")",
"{",
"$",
"str_query",
"=",
"$",
"str_query",
".",
"\" AND domain='$domain'\"",
";",
"}",
"return",
"self",
"::",
"fetchAll",
"(",
"$",
"kind_schema",
",",
"$",
"str_query",
")",
";",
"}"
] | Function that retrives users and tokens based on URL. used for background processing in bulk. | [
"Function",
"that",
"retrives",
"users",
"and",
"tokens",
"based",
"on",
"URL",
".",
"used",
"for",
"background",
"processing",
"in",
"bulk",
"."
] | dfa7a1a4d61aa435351d6a5b1b120c0e23d81dde | https://github.com/mijohansen/php-gae-util/blob/dfa7a1a4d61aa435351d6a5b1b120c0e23d81dde/src/DataStore.php#L105-L112 |
1,893 | mijohansen/php-gae-util | src/DataStore.php | DataStore.retrieveMostCurrentWorkflowJobByAgeAndStatus | static function retrieveMostCurrentWorkflowJobByAgeAndStatus($workflow_key, $status, $created_after) {
$kind_schema = self::getWorkflowJobKind();
$store = self::store($kind_schema);
$obsolete_time = new \DateTime($created_after);
$where = [
"workflow_key" => $workflow_key,
"status" => $status,
"obsolete_time" => $obsolete_time
];
syslog(LOG_INFO, __METHOD__ . " with vars " . json_encode($where));
$str_query = "SELECT * FROM $kind_schema
WHERE workflow_key = @workflow_key AND status = @status AND created > @obsolete_time ORDER BY created DESC";
$result = $store->fetchOne($str_query, $where);
if ($result) {
return $result->getData();
} else {
return false;
}
} | php | static function retrieveMostCurrentWorkflowJobByAgeAndStatus($workflow_key, $status, $created_after) {
$kind_schema = self::getWorkflowJobKind();
$store = self::store($kind_schema);
$obsolete_time = new \DateTime($created_after);
$where = [
"workflow_key" => $workflow_key,
"status" => $status,
"obsolete_time" => $obsolete_time
];
syslog(LOG_INFO, __METHOD__ . " with vars " . json_encode($where));
$str_query = "SELECT * FROM $kind_schema
WHERE workflow_key = @workflow_key AND status = @status AND created > @obsolete_time ORDER BY created DESC";
$result = $store->fetchOne($str_query, $where);
if ($result) {
return $result->getData();
} else {
return false;
}
} | [
"static",
"function",
"retrieveMostCurrentWorkflowJobByAgeAndStatus",
"(",
"$",
"workflow_key",
",",
"$",
"status",
",",
"$",
"created_after",
")",
"{",
"$",
"kind_schema",
"=",
"self",
"::",
"getWorkflowJobKind",
"(",
")",
";",
"$",
"store",
"=",
"self",
"::",
"store",
"(",
"$",
"kind_schema",
")",
";",
"$",
"obsolete_time",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"created_after",
")",
";",
"$",
"where",
"=",
"[",
"\"workflow_key\"",
"=>",
"$",
"workflow_key",
",",
"\"status\"",
"=>",
"$",
"status",
",",
"\"obsolete_time\"",
"=>",
"$",
"obsolete_time",
"]",
";",
"syslog",
"(",
"LOG_INFO",
",",
"__METHOD__",
".",
"\" with vars \"",
".",
"json_encode",
"(",
"$",
"where",
")",
")",
";",
"$",
"str_query",
"=",
"\"SELECT * FROM $kind_schema \n WHERE workflow_key = @workflow_key AND status = @status AND created > @obsolete_time ORDER BY created DESC\"",
";",
"$",
"result",
"=",
"$",
"store",
"->",
"fetchOne",
"(",
"$",
"str_query",
",",
"$",
"where",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"result",
"->",
"getData",
"(",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Used to check if job is running and getting last successful job run to retrieve state.
@param $workflow_key
@param $status
@param $created_after
@return array|bool
@throws \Exception | [
"Used",
"to",
"check",
"if",
"job",
"is",
"running",
"and",
"getting",
"last",
"successful",
"job",
"run",
"to",
"retrieve",
"state",
"."
] | dfa7a1a4d61aa435351d6a5b1b120c0e23d81dde | https://github.com/mijohansen/php-gae-util/blob/dfa7a1a4d61aa435351d6a5b1b120c0e23d81dde/src/DataStore.php#L248-L266 |
1,894 | jooorooo/embed | src/Bag.php | Bag.set | public function set($name, $value = null)
{
if (is_array($name)) {
$this->parameters = array_replace($this->parameters, $name);
} else {
$this->parameters[trim(strtolower($name))] = is_string($value) ? trim($value) : $value;
}
} | php | public function set($name, $value = null)
{
if (is_array($name)) {
$this->parameters = array_replace($this->parameters, $name);
} else {
$this->parameters[trim(strtolower($name))] = is_string($value) ? trim($value) : $value;
}
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"parameters",
"=",
"array_replace",
"(",
"$",
"this",
"->",
"parameters",
",",
"$",
"name",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"parameters",
"[",
"trim",
"(",
"strtolower",
"(",
"$",
"name",
")",
")",
"]",
"=",
"is_string",
"(",
"$",
"value",
")",
"?",
"trim",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"}",
"}"
] | Save a value
@param string|array $name Name of the value
@param mixed $value The value to save | [
"Save",
"a",
"value"
] | 078e70a093f246dc8e10b92f909f9166932c4106 | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Bag.php#L17-L24 |
1,895 | jooorooo/embed | src/Bag.php | Bag.add | public function add($name, $value = null)
{
$name = trim($name);
if (!isset($this->parameters[$name])) {
$this->parameters[$name] = [];
} elseif (!is_array($this->parameters[$name])) {
$this->parameters[$name] = (array) $this->parameters[$name];
}
$this->parameters[$name][] = $value;
} | php | public function add($name, $value = null)
{
$name = trim($name);
if (!isset($this->parameters[$name])) {
$this->parameters[$name] = [];
} elseif (!is_array($this->parameters[$name])) {
$this->parameters[$name] = (array) $this->parameters[$name];
}
$this->parameters[$name][] = $value;
} | [
"public",
"function",
"add",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
"=",
"[",
"]",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}"
] | Adds a subvalue
@param string $name Name of the value
@param mixed $value The value to add | [
"Adds",
"a",
"subvalue"
] | 078e70a093f246dc8e10b92f909f9166932c4106 | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Bag.php#L32-L43 |
1,896 | phramework/database | src/Operations/Update.php | Update.update | public static function update($id, $keysValues, $table, $idAttribute = 'id', $limit = 1)
{
//Work with arrays
if (is_object($keysValues)) {
$keysValues = (array)$keysValues;
}
$queryKeys = implode('" = ?,"', array_keys($keysValues));
$queryValues = array_values($keysValues);
//Push id to the end
$queryValues[] = $id;
$tableName = '';
//Work with array
if (is_object($table)) {
$table = (array)$table;
}
if (is_array($table)
&& isset($table['schema'])
&& isset($table['table'])
) {
$tableName = sprintf(
'"%s"."%s"',
$table['schema'],
$table['table']
);
} else {
$tableName = sprintf(
'"%s"',
$table
);
}
$query = sprintf(
'UPDATE %s SET "%s" = ?
WHERE "%s" = ?
%s',
$tableName,
$queryKeys,
$idAttribute,
(
$limit === null
? ''
: '' //'LIMIT ' . $limit
)
);
//Return number of rows affected
$result = Database::execute($query, $queryValues);
return $result;
} | php | public static function update($id, $keysValues, $table, $idAttribute = 'id', $limit = 1)
{
//Work with arrays
if (is_object($keysValues)) {
$keysValues = (array)$keysValues;
}
$queryKeys = implode('" = ?,"', array_keys($keysValues));
$queryValues = array_values($keysValues);
//Push id to the end
$queryValues[] = $id;
$tableName = '';
//Work with array
if (is_object($table)) {
$table = (array)$table;
}
if (is_array($table)
&& isset($table['schema'])
&& isset($table['table'])
) {
$tableName = sprintf(
'"%s"."%s"',
$table['schema'],
$table['table']
);
} else {
$tableName = sprintf(
'"%s"',
$table
);
}
$query = sprintf(
'UPDATE %s SET "%s" = ?
WHERE "%s" = ?
%s',
$tableName,
$queryKeys,
$idAttribute,
(
$limit === null
? ''
: '' //'LIMIT ' . $limit
)
);
//Return number of rows affected
$result = Database::execute($query, $queryValues);
return $result;
} | [
"public",
"static",
"function",
"update",
"(",
"$",
"id",
",",
"$",
"keysValues",
",",
"$",
"table",
",",
"$",
"idAttribute",
"=",
"'id'",
",",
"$",
"limit",
"=",
"1",
")",
"{",
"//Work with arrays",
"if",
"(",
"is_object",
"(",
"$",
"keysValues",
")",
")",
"{",
"$",
"keysValues",
"=",
"(",
"array",
")",
"$",
"keysValues",
";",
"}",
"$",
"queryKeys",
"=",
"implode",
"(",
"'\" = ?,\"'",
",",
"array_keys",
"(",
"$",
"keysValues",
")",
")",
";",
"$",
"queryValues",
"=",
"array_values",
"(",
"$",
"keysValues",
")",
";",
"//Push id to the end",
"$",
"queryValues",
"[",
"]",
"=",
"$",
"id",
";",
"$",
"tableName",
"=",
"''",
";",
"//Work with array",
"if",
"(",
"is_object",
"(",
"$",
"table",
")",
")",
"{",
"$",
"table",
"=",
"(",
"array",
")",
"$",
"table",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"table",
")",
"&&",
"isset",
"(",
"$",
"table",
"[",
"'schema'",
"]",
")",
"&&",
"isset",
"(",
"$",
"table",
"[",
"'table'",
"]",
")",
")",
"{",
"$",
"tableName",
"=",
"sprintf",
"(",
"'\"%s\".\"%s\"'",
",",
"$",
"table",
"[",
"'schema'",
"]",
",",
"$",
"table",
"[",
"'table'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"tableName",
"=",
"sprintf",
"(",
"'\"%s\"'",
",",
"$",
"table",
")",
";",
"}",
"$",
"query",
"=",
"sprintf",
"(",
"'UPDATE %s SET \"%s\" = ?\n WHERE \"%s\" = ?\n %s'",
",",
"$",
"tableName",
",",
"$",
"queryKeys",
",",
"$",
"idAttribute",
",",
"(",
"$",
"limit",
"===",
"null",
"?",
"''",
":",
"''",
"//'LIMIT ' . $limit",
")",
")",
";",
"//Return number of rows affected",
"$",
"result",
"=",
"Database",
"::",
"execute",
"(",
"$",
"query",
",",
"$",
"queryValues",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Update database records
@param string|integer $id
@param array|object $keysValues
@param string|array $table Table's name
@param string $idAttribute **[Optional]** Id attribute
@return integer Return number of affected records
@param null|integer $limit **[Optional]**
Limit clause, when null there is not limit.
@todo Add $additionalAttributes | [
"Update",
"database",
"records"
] | 12726d81917981aa447bb58b76e21762592aab8f | https://github.com/phramework/database/blob/12726d81917981aa447bb58b76e21762592aab8f/src/Operations/Update.php#L41-L96 |
1,897 | ghiencode/util | DateTime.php | DateTime.formatDate | public static function formatDate($time, $format = DATE_ISO8601, $timezone = 'UTC')
{
return static::create($time, $timezone)->format($format);
} | php | public static function formatDate($time, $format = DATE_ISO8601, $timezone = 'UTC')
{
return static::create($time, $timezone)->format($format);
} | [
"public",
"static",
"function",
"formatDate",
"(",
"$",
"time",
",",
"$",
"format",
"=",
"DATE_ISO8601",
",",
"$",
"timezone",
"=",
"'UTC'",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"$",
"time",
",",
"$",
"timezone",
")",
"->",
"format",
"(",
"$",
"format",
")",
";",
"}"
] | Returns date formatted according to the specified format and timezone
@param string $time A date/time string. Valid formats could be:
- 'now'
- '10 September 2000'
- '2016-12-30T10:01:33+0700'
- '1483067019' (Unix Timestamp)
@param string $format Format accepted by date(). [optional]
@param string $timezone String representing the desired time zone. [optional]
@return string | [
"Returns",
"date",
"formatted",
"according",
"to",
"the",
"specified",
"format",
"and",
"timezone"
] | c27ead3cde04cc682055318a0836862aa7cd9d35 | https://github.com/ghiencode/util/blob/c27ead3cde04cc682055318a0836862aa7cd9d35/DateTime.php#L42-L45 |
1,898 | ghiencode/util | DateTime.php | DateTime.compare | public static function compare($date1, $date2): int
{
$d1 = static::create($date1);
$d2 = static::create($date2);
return ($d1 > $d2) ? static::DATETIME_GREATER : (($d1 < $d2) ? static::DATETIME_LESS : static::DATETIME_EQUAL);
} | php | public static function compare($date1, $date2): int
{
$d1 = static::create($date1);
$d2 = static::create($date2);
return ($d1 > $d2) ? static::DATETIME_GREATER : (($d1 < $d2) ? static::DATETIME_LESS : static::DATETIME_EQUAL);
} | [
"public",
"static",
"function",
"compare",
"(",
"$",
"date1",
",",
"$",
"date2",
")",
":",
"int",
"{",
"$",
"d1",
"=",
"static",
"::",
"create",
"(",
"$",
"date1",
")",
";",
"$",
"d2",
"=",
"static",
"::",
"create",
"(",
"$",
"date2",
")",
";",
"return",
"(",
"$",
"d1",
">",
"$",
"d2",
")",
"?",
"static",
"::",
"DATETIME_GREATER",
":",
"(",
"(",
"$",
"d1",
"<",
"$",
"d2",
")",
"?",
"static",
"::",
"DATETIME_LESS",
":",
"static",
"::",
"DATETIME_EQUAL",
")",
";",
"}"
] | Return comparision result of 2 datetime object
@param $date1
@param $date2
@return integer
* 1 if Greater than
* 0 if Equal
* -1 if Less than | [
"Return",
"comparision",
"result",
"of",
"2",
"datetime",
"object"
] | c27ead3cde04cc682055318a0836862aa7cd9d35 | https://github.com/ghiencode/util/blob/c27ead3cde04cc682055318a0836862aa7cd9d35/DateTime.php#L57-L63 |
1,899 | bishopb/vanilla | applications/dashboard/models/class.updatemodel.php | UpdateModel.ParseCoreVersion | public static function ParseCoreVersion($Path) {
$fp = fopen($Path, 'rb');
$Application = FALSE;
$Version = FALSE;
while (($Line = fgets($fp)) !== FALSE) {
if (preg_match("`define\\('(.*?)', '(.*?)'\\);`", $Line, $Matches)) {
$Name = $Matches[1];
$Value = $Matches[2];
switch ($Name) {
case 'APPLICATION':
$Application = $Value;
break;
case 'APPLICATION_VERSION':
$Version = $Value;
}
}
if ($Application !== FALSE && $Version !== FALSE)
break;
}
fclose($fp);
return $Version;
} | php | public static function ParseCoreVersion($Path) {
$fp = fopen($Path, 'rb');
$Application = FALSE;
$Version = FALSE;
while (($Line = fgets($fp)) !== FALSE) {
if (preg_match("`define\\('(.*?)', '(.*?)'\\);`", $Line, $Matches)) {
$Name = $Matches[1];
$Value = $Matches[2];
switch ($Name) {
case 'APPLICATION':
$Application = $Value;
break;
case 'APPLICATION_VERSION':
$Version = $Value;
}
}
if ($Application !== FALSE && $Version !== FALSE)
break;
}
fclose($fp);
return $Version;
} | [
"public",
"static",
"function",
"ParseCoreVersion",
"(",
"$",
"Path",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"Path",
",",
"'rb'",
")",
";",
"$",
"Application",
"=",
"FALSE",
";",
"$",
"Version",
"=",
"FALSE",
";",
"while",
"(",
"(",
"$",
"Line",
"=",
"fgets",
"(",
"$",
"fp",
")",
")",
"!==",
"FALSE",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"`define\\\\('(.*?)', '(.*?)'\\\\);`\"",
",",
"$",
"Line",
",",
"$",
"Matches",
")",
")",
"{",
"$",
"Name",
"=",
"$",
"Matches",
"[",
"1",
"]",
";",
"$",
"Value",
"=",
"$",
"Matches",
"[",
"2",
"]",
";",
"switch",
"(",
"$",
"Name",
")",
"{",
"case",
"'APPLICATION'",
":",
"$",
"Application",
"=",
"$",
"Value",
";",
"break",
";",
"case",
"'APPLICATION_VERSION'",
":",
"$",
"Version",
"=",
"$",
"Value",
";",
"}",
"}",
"if",
"(",
"$",
"Application",
"!==",
"FALSE",
"&&",
"$",
"Version",
"!==",
"FALSE",
")",
"break",
";",
"}",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"Version",
";",
"}"
] | Parse the version out of the core's index.php file.
@param string $Path The path to the index.php file.
@return string|false A string containing the version or false if the file could not be parsed. | [
"Parse",
"the",
"version",
"out",
"of",
"the",
"core",
"s",
"index",
".",
"php",
"file",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.updatemodel.php#L562-L585 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.