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
|
---|---|---|---|---|---|---|---|---|---|---|---|
300 | webriq/core | module/Menu/src/Grid/Menu/Model/Menu/Structure/ProxyAbstract.php | ProxyAbstract.isActive | public function isActive( $requestUri = null )
{
$uri = rawurldecode( preg_replace( '/[\\?#].*$/', '', (string) $this->getUri() ) );
if ( empty( $uri ) || '/' !== $uri[0] )
{
return false;
}
if ( null === $requestUri )
{
if ( null === $this->requestUri )
{
$this->requestUri = $this->getServiceLocator()
->get( 'Request' )
->getRequestUri();
$this->requestUri = preg_replace(
'/\\?.*$/', '',
$this->requestUri
);
}
$requestUri = $this->requestUri;
}
else
{
$requestUri = preg_replace(
'/[\\?#].*$/', '',
(string) $requestUri
);
}
$requestUri = rawurldecode( $requestUri );
return $requestUri === $uri || (
mb_strlen( $requestUri ) > mb_strlen( $uri ) &&
mb_substr( $requestUri, 0, mb_strlen( $uri ) + 1 ) === ( $uri . '/' )
);
} | php | public function isActive( $requestUri = null )
{
$uri = rawurldecode( preg_replace( '/[\\?#].*$/', '', (string) $this->getUri() ) );
if ( empty( $uri ) || '/' !== $uri[0] )
{
return false;
}
if ( null === $requestUri )
{
if ( null === $this->requestUri )
{
$this->requestUri = $this->getServiceLocator()
->get( 'Request' )
->getRequestUri();
$this->requestUri = preg_replace(
'/\\?.*$/', '',
$this->requestUri
);
}
$requestUri = $this->requestUri;
}
else
{
$requestUri = preg_replace(
'/[\\?#].*$/', '',
(string) $requestUri
);
}
$requestUri = rawurldecode( $requestUri );
return $requestUri === $uri || (
mb_strlen( $requestUri ) > mb_strlen( $uri ) &&
mb_substr( $requestUri, 0, mb_strlen( $uri ) + 1 ) === ( $uri . '/' )
);
} | [
"public",
"function",
"isActive",
"(",
"$",
"requestUri",
"=",
"null",
")",
"{",
"$",
"uri",
"=",
"rawurldecode",
"(",
"preg_replace",
"(",
"'/[\\\\?#].*$/'",
",",
"''",
",",
"(",
"string",
")",
"$",
"this",
"->",
"getUri",
"(",
")",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"uri",
")",
"||",
"'/'",
"!==",
"$",
"uri",
"[",
"0",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"requestUri",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"requestUri",
")",
"{",
"$",
"this",
"->",
"requestUri",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'Request'",
")",
"->",
"getRequestUri",
"(",
")",
";",
"$",
"this",
"->",
"requestUri",
"=",
"preg_replace",
"(",
"'/\\\\?.*$/'",
",",
"''",
",",
"$",
"this",
"->",
"requestUri",
")",
";",
"}",
"$",
"requestUri",
"=",
"$",
"this",
"->",
"requestUri",
";",
"}",
"else",
"{",
"$",
"requestUri",
"=",
"preg_replace",
"(",
"'/[\\\\?#].*$/'",
",",
"''",
",",
"(",
"string",
")",
"$",
"requestUri",
")",
";",
"}",
"$",
"requestUri",
"=",
"rawurldecode",
"(",
"$",
"requestUri",
")",
";",
"return",
"$",
"requestUri",
"===",
"$",
"uri",
"||",
"(",
"mb_strlen",
"(",
"$",
"requestUri",
")",
">",
"mb_strlen",
"(",
"$",
"uri",
")",
"&&",
"mb_substr",
"(",
"$",
"requestUri",
",",
"0",
",",
"mb_strlen",
"(",
"$",
"uri",
")",
"+",
"1",
")",
"===",
"(",
"$",
"uri",
".",
"'/'",
")",
")",
";",
"}"
] | Is this menu-item is active?
@param string $requestUri [optional]
@return bool | [
"Is",
"this",
"menu",
"-",
"item",
"is",
"active?"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Menu/src/Grid/Menu/Model/Menu/Structure/ProxyAbstract.php#L359-L398 |
301 | fortifi/sdk | src/OAuth/TokenStorage/TmpFileTokenStorage.php | TmpFileTokenStorage.retrieveToken | public function retrieveToken($key)
{
$location = $this->_createFileName($key);
if(file_exists($location))
{
return file_get_contents($location);
}
return null;
} | php | public function retrieveToken($key)
{
$location = $this->_createFileName($key);
if(file_exists($location))
{
return file_get_contents($location);
}
return null;
} | [
"public",
"function",
"retrieveToken",
"(",
"$",
"key",
")",
"{",
"$",
"location",
"=",
"$",
"this",
"->",
"_createFileName",
"(",
"$",
"key",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"location",
")",
")",
"{",
"return",
"file_get_contents",
"(",
"$",
"location",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Retrieve a token from storage
@param string $key location key for token
@return string|null | [
"Retrieve",
"a",
"token",
"from",
"storage"
] | 4d0471c72c7954271c692d32265fd42f698392e4 | https://github.com/fortifi/sdk/blob/4d0471c72c7954271c692d32265fd42f698392e4/src/OAuth/TokenStorage/TmpFileTokenStorage.php#L29-L37 |
302 | slickframework/orm | src/Mapper/AbstractEntityMapper.php | AbstractEntityMapper.getDescriptor | public function getDescriptor()
{
if (null == $this->descriptor) {
$this->setDescriptor(
EntityDescriptorRegistry::getInstance()
->getDescriptorFor($this->getEntityClassName())
);
}
return $this->descriptor;
} | php | public function getDescriptor()
{
if (null == $this->descriptor) {
$this->setDescriptor(
EntityDescriptorRegistry::getInstance()
->getDescriptorFor($this->getEntityClassName())
);
}
return $this->descriptor;
} | [
"public",
"function",
"getDescriptor",
"(",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"this",
"->",
"descriptor",
")",
"{",
"$",
"this",
"->",
"setDescriptor",
"(",
"EntityDescriptorRegistry",
"::",
"getInstance",
"(",
")",
"->",
"getDescriptorFor",
"(",
"$",
"this",
"->",
"getEntityClassName",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"descriptor",
";",
"}"
] | Get entity descriptor
@return EntityDescriptorInterface | [
"Get",
"entity",
"descriptor"
] | c5c782f5e3a46cdc6c934eda4411cb9edc48f969 | https://github.com/slickframework/orm/blob/c5c782f5e3a46cdc6c934eda4411cb9edc48f969/src/Mapper/AbstractEntityMapper.php#L52-L61 |
303 | slickframework/orm | src/Mapper/AbstractEntityMapper.php | AbstractEntityMapper.getEntityClassName | public function getEntityClassName()
{
if (null == $this->entityClassName) {
$this->setEntityClassName(get_class($this->entity));
}
return $this->entityClassName;
} | php | public function getEntityClassName()
{
if (null == $this->entityClassName) {
$this->setEntityClassName(get_class($this->entity));
}
return $this->entityClassName;
} | [
"public",
"function",
"getEntityClassName",
"(",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"this",
"->",
"entityClassName",
")",
"{",
"$",
"this",
"->",
"setEntityClassName",
"(",
"get_class",
"(",
"$",
"this",
"->",
"entity",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"entityClassName",
";",
"}"
] | Gets entity class name for this mapper
@return string | [
"Gets",
"entity",
"class",
"name",
"for",
"this",
"mapper"
] | c5c782f5e3a46cdc6c934eda4411cb9edc48f969 | https://github.com/slickframework/orm/blob/c5c782f5e3a46cdc6c934eda4411cb9edc48f969/src/Mapper/AbstractEntityMapper.php#L104-L110 |
304 | marando/phpSOFA | src/Marando/IAU/iauTr.php | iauTr.Tr | public static function Tr(array $r, array &$rt) {
$wm = [];
$i;
$j;
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j < 3; $j++) {
$wm[$i][$j] = $r[$j][$i];
}
}
IAU::Cr($wm, $rt);
return;
} | php | public static function Tr(array $r, array &$rt) {
$wm = [];
$i;
$j;
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j < 3; $j++) {
$wm[$i][$j] = $r[$j][$i];
}
}
IAU::Cr($wm, $rt);
return;
} | [
"public",
"static",
"function",
"Tr",
"(",
"array",
"$",
"r",
",",
"array",
"&",
"$",
"rt",
")",
"{",
"$",
"wm",
"=",
"[",
"]",
";",
"$",
"i",
";",
"$",
"j",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"3",
";",
"$",
"i",
"++",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"3",
";",
"$",
"j",
"++",
")",
"{",
"$",
"wm",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
"=",
"$",
"r",
"[",
"$",
"j",
"]",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"IAU",
"::",
"Cr",
"(",
"$",
"wm",
",",
"$",
"rt",
")",
";",
"return",
";",
"}"
] | - - - - - -
i a u T r
- - - - - -
Transpose an r-matrix.
This function is part of the International Astronomical Union's
SOFA (Standards Of Fundamental Astronomy) software collection.
Status: vector/matrix support function.
Given:
r double[3][3] r-matrix
Returned:
rt double[3][3] transpose
Note:
It is permissible for r and rt to be the same array.
Called:
iauCr copy r-matrix
This revision: 2013 June 18
SOFA release 2015-02-09
Copyright (C) 2015 IAU SOFA Board. See notes at end. | [
"-",
"-",
"-",
"-",
"-",
"-",
"i",
"a",
"u",
"T",
"r",
"-",
"-",
"-",
"-",
"-",
"-"
] | 757fa49fe335ae1210eaa7735473fd4388b13f07 | https://github.com/marando/phpSOFA/blob/757fa49fe335ae1210eaa7735473fd4388b13f07/src/Marando/IAU/iauTr.php#L37-L50 |
305 | samurai-fw/samurai | src/Samurai/Component/Utility/ArrayUtility.php | ArrayUtility.merge | public function merge()
{
$marged = NULL;
foreach (func_get_args() as $arg) {
// first is override.
if ($marged === null) {
$marged = $arg;
// when mismatch variable type, then override.
} elseif (gettype($marged) !== gettype($arg)) {
$marged = $arg;
// when not array, then override.
} elseif (! is_array($arg)) {
$marged = $arg;
// when both array, then merge recursive.
} else {
foreach ($arg as $_key => $_val) {
// when int key, then push.
if(is_int($_key)) {
$marged[] = $_val;
// when not exists key, then override.
} elseif(! isset($marged[$_key])) {
$marged[$_key] = $_val;
// merge.
} else {
$marged[$_key] = $this->merge($marged[$_key], $_val);
}
}
}
}
return $marged;
} | php | public function merge()
{
$marged = NULL;
foreach (func_get_args() as $arg) {
// first is override.
if ($marged === null) {
$marged = $arg;
// when mismatch variable type, then override.
} elseif (gettype($marged) !== gettype($arg)) {
$marged = $arg;
// when not array, then override.
} elseif (! is_array($arg)) {
$marged = $arg;
// when both array, then merge recursive.
} else {
foreach ($arg as $_key => $_val) {
// when int key, then push.
if(is_int($_key)) {
$marged[] = $_val;
// when not exists key, then override.
} elseif(! isset($marged[$_key])) {
$marged[$_key] = $_val;
// merge.
} else {
$marged[$_key] = $this->merge($marged[$_key], $_val);
}
}
}
}
return $marged;
} | [
"public",
"function",
"merge",
"(",
")",
"{",
"$",
"marged",
"=",
"NULL",
";",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"arg",
")",
"{",
"// first is override.",
"if",
"(",
"$",
"marged",
"===",
"null",
")",
"{",
"$",
"marged",
"=",
"$",
"arg",
";",
"// when mismatch variable type, then override.",
"}",
"elseif",
"(",
"gettype",
"(",
"$",
"marged",
")",
"!==",
"gettype",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"marged",
"=",
"$",
"arg",
";",
"// when not array, then override.",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"marged",
"=",
"$",
"arg",
";",
"// when both array, then merge recursive.",
"}",
"else",
"{",
"foreach",
"(",
"$",
"arg",
"as",
"$",
"_key",
"=>",
"$",
"_val",
")",
"{",
"// when int key, then push.",
"if",
"(",
"is_int",
"(",
"$",
"_key",
")",
")",
"{",
"$",
"marged",
"[",
"]",
"=",
"$",
"_val",
";",
"// when not exists key, then override.",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"marged",
"[",
"$",
"_key",
"]",
")",
")",
"{",
"$",
"marged",
"[",
"$",
"_key",
"]",
"=",
"$",
"_val",
";",
"// merge.",
"}",
"else",
"{",
"$",
"marged",
"[",
"$",
"_key",
"]",
"=",
"$",
"this",
"->",
"merge",
"(",
"$",
"marged",
"[",
"$",
"_key",
"]",
",",
"$",
"_val",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"marged",
";",
"}"
] | merge recursive.
@access public
@param array $array1
@param array $array2 | [
"merge",
"recursive",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Utility/ArrayUtility.php#L51-L84 |
306 | devLopez/Presenter | src/Generators/Generator.php | Generator.createClass | protected function createClass()
{
$file = $this->getPath();
if($this->files->exists($file)) {
throw new PresenterExistsException();
} else {
return $this->files->put(
$file,
$this->stub->populateStub($this->getPopulatedData())
);
}
} | php | protected function createClass()
{
$file = $this->getPath();
if($this->files->exists($file)) {
throw new PresenterExistsException();
} else {
return $this->files->put(
$file,
$this->stub->populateStub($this->getPopulatedData())
);
}
} | [
"protected",
"function",
"createClass",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"PresenterExistsException",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"files",
"->",
"put",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"stub",
"->",
"populateStub",
"(",
"$",
"this",
"->",
"getPopulatedData",
"(",
")",
")",
")",
";",
"}",
"}"
] | Create the Presenter file
@return bool
@throws PresenterExistsException | [
"Create",
"the",
"Presenter",
"file"
] | 25200f417f04cfddb555a16c8741aa7c7abbefc1 | https://github.com/devLopez/Presenter/blob/25200f417f04cfddb555a16c8741aa7c7abbefc1/src/Generators/Generator.php#L41-L53 |
307 | devLopez/Presenter | src/Generators/Generator.php | Generator.createDirectory | protected function createDirectory()
{
$dir = $this->getDirectory();
if (!$this->files->isDirectory($dir)) {
$this->files->makeDirectory($dir, 0755, true);
}
return $this;
} | php | protected function createDirectory()
{
$dir = $this->getDirectory();
if (!$this->files->isDirectory($dir)) {
$this->files->makeDirectory($dir, 0755, true);
}
return $this;
} | [
"protected",
"function",
"createDirectory",
"(",
")",
"{",
"$",
"dir",
"=",
"$",
"this",
"->",
"getDirectory",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"isDirectory",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"this",
"->",
"files",
"->",
"makeDirectory",
"(",
"$",
"dir",
",",
"0755",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Create the directory that will be used to receive the Presenters
@return $this | [
"Create",
"the",
"directory",
"that",
"will",
"be",
"used",
"to",
"receive",
"the",
"Presenters"
] | 25200f417f04cfddb555a16c8741aa7c7abbefc1 | https://github.com/devLopez/Presenter/blob/25200f417f04cfddb555a16c8741aa7c7abbefc1/src/Generators/Generator.php#L60-L69 |
308 | phplegends/routes | src/Route.php | Route.setAction | public function setAction ($action)
{
if ($action instanceof \Closure) {
$this->action = $action;
return $this;
}
$parts = explode('::', $action);
if (count($parts) != 2) {
throw new \LengthException('Malformed action string');
}
$this->validateRoutable($parts[0], $parts[1]);
$this->action = $parts;
return $this;
} | php | public function setAction ($action)
{
if ($action instanceof \Closure) {
$this->action = $action;
return $this;
}
$parts = explode('::', $action);
if (count($parts) != 2) {
throw new \LengthException('Malformed action string');
}
$this->validateRoutable($parts[0], $parts[1]);
$this->action = $parts;
return $this;
} | [
"public",
"function",
"setAction",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"action",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"this",
"->",
"action",
"=",
"$",
"action",
";",
"return",
"$",
"this",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'::'",
",",
"$",
"action",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"!=",
"2",
")",
"{",
"throw",
"new",
"\\",
"LengthException",
"(",
"'Malformed action string'",
")",
";",
"}",
"$",
"this",
"->",
"validateRoutable",
"(",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"$",
"this",
"->",
"action",
"=",
"$",
"parts",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the action
@param string $action
@throws \LengthException
@return self | [
"Sets",
"the",
"action"
] | 7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec | https://github.com/phplegends/routes/blob/7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec/src/Route.php#L97-L119 |
309 | phplegends/routes | src/Route.php | Route.acceptedVerb | public function acceptedVerb($verb)
{
if (isset($this->verbs[0]) && $this->verbs[0] == static::ANY_METHOD_WILDCARD) {
return true;
}
return in_array(strtoupper($verb), $this->getVerbs(), true);
} | php | public function acceptedVerb($verb)
{
if (isset($this->verbs[0]) && $this->verbs[0] == static::ANY_METHOD_WILDCARD) {
return true;
}
return in_array(strtoupper($verb), $this->getVerbs(), true);
} | [
"public",
"function",
"acceptedVerb",
"(",
"$",
"verb",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"verbs",
"[",
"0",
"]",
")",
"&&",
"$",
"this",
"->",
"verbs",
"[",
"0",
"]",
"==",
"static",
"::",
"ANY_METHOD_WILDCARD",
")",
"{",
"return",
"true",
";",
"}",
"return",
"in_array",
"(",
"strtoupper",
"(",
"$",
"verb",
")",
",",
"$",
"this",
"->",
"getVerbs",
"(",
")",
",",
"true",
")",
";",
"}"
] | Asserts if http verb is accepted
@param string $method | [
"Asserts",
"if",
"http",
"verb",
"is",
"accepted"
] | 7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec | https://github.com/phplegends/routes/blob/7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec/src/Route.php#L168-L177 |
310 | phplegends/routes | src/Route.php | Route.getActionAsClosure | public function getActionAsClosure()
{
if ($this->action instanceof \Closure)
{
return $this->action;
}
return function () {
$action = $this->getActionAsCallable();
return call_user_func_array($action, func_get_args());
};
} | php | public function getActionAsClosure()
{
if ($this->action instanceof \Closure)
{
return $this->action;
}
return function () {
$action = $this->getActionAsCallable();
return call_user_func_array($action, func_get_args());
};
} | [
"public",
"function",
"getActionAsClosure",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"action",
"instanceof",
"\\",
"Closure",
")",
"{",
"return",
"$",
"this",
"->",
"action",
";",
"}",
"return",
"function",
"(",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"getActionAsCallable",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"$",
"action",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
";",
"}"
] | Forces the action to be returns Closure
@todo isso está funcionando?
@return \Closure | [
"Forces",
"the",
"action",
"to",
"be",
"returns",
"Closure"
] | 7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec | https://github.com/phplegends/routes/blob/7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec/src/Route.php#L207-L220 |
311 | phplegends/routes | src/Route.php | Route.match | public function match($uri)
{
if (preg_match($this->getParsedPattern(), trim($uri), $matches) > 0) {
$this->parameters = array_slice($matches, 1);
return true;
}
return false;
} | php | public function match($uri)
{
if (preg_match($this->getParsedPattern(), trim($uri), $matches) > 0) {
$this->parameters = array_slice($matches, 1);
return true;
}
return false;
} | [
"public",
"function",
"match",
"(",
"$",
"uri",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"this",
"->",
"getParsedPattern",
"(",
")",
",",
"trim",
"(",
"$",
"uri",
")",
",",
"$",
"matches",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"parameters",
"=",
"array_slice",
"(",
"$",
"matches",
",",
"1",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Determines if uri matches with regex. If match, return params of uri
@param string $uri
@return boolean | [
"Determines",
"if",
"uri",
"matches",
"with",
"regex",
".",
"If",
"match",
"return",
"params",
"of",
"uri"
] | 7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec | https://github.com/phplegends/routes/blob/7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec/src/Route.php#L282-L292 |
312 | phplegends/routes | src/Route.php | Route.toUri | public function toUri(array $parameters = [])
{
$pattern = $this->getPattern();
$wildcardsRegexes = $this->wildcardsToRegexGroups(
$matches = $this->getPatternWildcards()
);
$parameters = array_slice($parameters, 0, count($wildcardsRegexes));
$this->validateParametersByWildcards($matches, $parameters);
$uri = preg_replace($wildcardsRegexes, $parameters, $pattern, 1);
return '/' . rtrim($uri, '/');
} | php | public function toUri(array $parameters = [])
{
$pattern = $this->getPattern();
$wildcardsRegexes = $this->wildcardsToRegexGroups(
$matches = $this->getPatternWildcards()
);
$parameters = array_slice($parameters, 0, count($wildcardsRegexes));
$this->validateParametersByWildcards($matches, $parameters);
$uri = preg_replace($wildcardsRegexes, $parameters, $pattern, 1);
return '/' . rtrim($uri, '/');
} | [
"public",
"function",
"toUri",
"(",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"getPattern",
"(",
")",
";",
"$",
"wildcardsRegexes",
"=",
"$",
"this",
"->",
"wildcardsToRegexGroups",
"(",
"$",
"matches",
"=",
"$",
"this",
"->",
"getPatternWildcards",
"(",
")",
")",
";",
"$",
"parameters",
"=",
"array_slice",
"(",
"$",
"parameters",
",",
"0",
",",
"count",
"(",
"$",
"wildcardsRegexes",
")",
")",
";",
"$",
"this",
"->",
"validateParametersByWildcards",
"(",
"$",
"matches",
",",
"$",
"parameters",
")",
";",
"$",
"uri",
"=",
"preg_replace",
"(",
"$",
"wildcardsRegexes",
",",
"$",
"parameters",
",",
"$",
"pattern",
",",
"1",
")",
";",
"return",
"'/'",
".",
"rtrim",
"(",
"$",
"uri",
",",
"'/'",
")",
";",
"}"
] | Generates the uri from current route
@param array $parameters
@return string | [
"Generates",
"the",
"uri",
"from",
"current",
"route"
] | 7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec | https://github.com/phplegends/routes/blob/7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec/src/Route.php#L300-L317 |
313 | phplegends/routes | src/Route.php | Route.getPatternWildcards | protected function getPatternWildcards()
{
preg_match_all($this->wildcardsToRegex(), $this->getPattern(), $matches);
return empty($matches[0]) ? [] : $matches[0];
} | php | protected function getPatternWildcards()
{
preg_match_all($this->wildcardsToRegex(), $this->getPattern(), $matches);
return empty($matches[0]) ? [] : $matches[0];
} | [
"protected",
"function",
"getPatternWildcards",
"(",
")",
"{",
"preg_match_all",
"(",
"$",
"this",
"->",
"wildcardsToRegex",
"(",
")",
",",
"$",
"this",
"->",
"getPattern",
"(",
")",
",",
"$",
"matches",
")",
";",
"return",
"empty",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
"?",
"[",
"]",
":",
"$",
"matches",
"[",
"0",
"]",
";",
"}"
] | Gets the wildcards of route pattern
@return array | [
"Gets",
"the",
"wildcards",
"of",
"route",
"pattern"
] | 7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec | https://github.com/phplegends/routes/blob/7b571362c4d9b190ad51bc5e8c4d96bfd03f31ec/src/Route.php#L496-L501 |
314 | wasabi-cms/core | src/Model/Behavior/KeyValueBehavior.php | KeyValueBehavior.getAllKeyValues | public function getAllKeyValues()
{
$query = $this->_table->query();
$query->formatResults(function (ResultSet $results) {
return $results->map(function ($row) {
if ($row['serialized'] === true) {
$row['value'] = unserialize($row['value']);
}
return $row;
});
});
$settings = [];
foreach ($query->all() as $row) {
$key = $row['scope'] . '__' . $row[$this->config('fields.key')];
$value = $row[$this->config('fields.value')];
$settings[$key] = $value;
}
return Hash::expand($settings, '__');
} | php | public function getAllKeyValues()
{
$query = $this->_table->query();
$query->formatResults(function (ResultSet $results) {
return $results->map(function ($row) {
if ($row['serialized'] === true) {
$row['value'] = unserialize($row['value']);
}
return $row;
});
});
$settings = [];
foreach ($query->all() as $row) {
$key = $row['scope'] . '__' . $row[$this->config('fields.key')];
$value = $row[$this->config('fields.value')];
$settings[$key] = $value;
}
return Hash::expand($settings, '__');
} | [
"public",
"function",
"getAllKeyValues",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"_table",
"->",
"query",
"(",
")",
";",
"$",
"query",
"->",
"formatResults",
"(",
"function",
"(",
"ResultSet",
"$",
"results",
")",
"{",
"return",
"$",
"results",
"->",
"map",
"(",
"function",
"(",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"'serialized'",
"]",
"===",
"true",
")",
"{",
"$",
"row",
"[",
"'value'",
"]",
"=",
"unserialize",
"(",
"$",
"row",
"[",
"'value'",
"]",
")",
";",
"}",
"return",
"$",
"row",
";",
"}",
")",
";",
"}",
")",
";",
"$",
"settings",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"all",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"key",
"=",
"$",
"row",
"[",
"'scope'",
"]",
".",
"'__'",
".",
"$",
"row",
"[",
"$",
"this",
"->",
"config",
"(",
"'fields.key'",
")",
"]",
";",
"$",
"value",
"=",
"$",
"row",
"[",
"$",
"this",
"->",
"config",
"(",
"'fields.value'",
")",
"]",
";",
"$",
"settings",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"Hash",
"::",
"expand",
"(",
"$",
"settings",
",",
"'__'",
")",
";",
"}"
] | Returns all keys and their values for all scopes.
@return array | [
"Returns",
"all",
"keys",
"and",
"their",
"values",
"for",
"all",
"scopes",
"."
] | 0eadbb64d2fc201bacc63c93814adeca70e08f90 | https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Model/Behavior/KeyValueBehavior.php#L52-L74 |
315 | wasabi-cms/core | src/Model/Behavior/KeyValueBehavior.php | KeyValueBehavior.getKeyValues | public function getKeyValues(Entity $entity, array $keys)
{
$scope = $this->config('scope');
$query = $this->_table->query();
$query
->where([
'scope' => $scope,
$this->config('fields.key') . ' IN' => $keys
])
->hydrate(false);
// unserialize serialized fields
$query->formatResults(function (ResultSet $results) {
return $results->map(function ($row) {
if ($row['serialized'] === true) {
$row['value'] = unserialize($row['value']);
}
return $row;
});
});
foreach ($query->all() as $row) {
$entity->{$row[$this->config('fields.key')]} = $row[$this->config('fields.value')];
}
return $entity;
} | php | public function getKeyValues(Entity $entity, array $keys)
{
$scope = $this->config('scope');
$query = $this->_table->query();
$query
->where([
'scope' => $scope,
$this->config('fields.key') . ' IN' => $keys
])
->hydrate(false);
// unserialize serialized fields
$query->formatResults(function (ResultSet $results) {
return $results->map(function ($row) {
if ($row['serialized'] === true) {
$row['value'] = unserialize($row['value']);
}
return $row;
});
});
foreach ($query->all() as $row) {
$entity->{$row[$this->config('fields.key')]} = $row[$this->config('fields.value')];
}
return $entity;
} | [
"public",
"function",
"getKeyValues",
"(",
"Entity",
"$",
"entity",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"scope",
"=",
"$",
"this",
"->",
"config",
"(",
"'scope'",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"_table",
"->",
"query",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"[",
"'scope'",
"=>",
"$",
"scope",
",",
"$",
"this",
"->",
"config",
"(",
"'fields.key'",
")",
".",
"' IN'",
"=>",
"$",
"keys",
"]",
")",
"->",
"hydrate",
"(",
"false",
")",
";",
"// unserialize serialized fields",
"$",
"query",
"->",
"formatResults",
"(",
"function",
"(",
"ResultSet",
"$",
"results",
")",
"{",
"return",
"$",
"results",
"->",
"map",
"(",
"function",
"(",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"'serialized'",
"]",
"===",
"true",
")",
"{",
"$",
"row",
"[",
"'value'",
"]",
"=",
"unserialize",
"(",
"$",
"row",
"[",
"'value'",
"]",
")",
";",
"}",
"return",
"$",
"row",
";",
"}",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"query",
"->",
"all",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"entity",
"->",
"{",
"$",
"row",
"[",
"$",
"this",
"->",
"config",
"(",
"'fields.key'",
")",
"]",
"}",
"=",
"$",
"row",
"[",
"$",
"this",
"->",
"config",
"(",
"'fields.value'",
")",
"]",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Generate a custom entity with all keys as properties and
their corresponding values
Returns a computed entity that can be used by FormHelper.
@param Entity $entity The base entity to customize.
@param array $keys The keys to set on the entity.
@return Entity | [
"Generate",
"a",
"custom",
"entity",
"with",
"all",
"keys",
"as",
"properties",
"and",
"their",
"corresponding",
"values"
] | 0eadbb64d2fc201bacc63c93814adeca70e08f90 | https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Model/Behavior/KeyValueBehavior.php#L87-L114 |
316 | wasabi-cms/core | src/Model/Behavior/KeyValueBehavior.php | KeyValueBehavior.saveKeyValues | public function saveKeyValues(Entity $entity, array $keys)
{
$event = $this->_table->dispatchEvent('Model.beforeSaveKeyValues', compact('entity'));
if ($event->isStopped()) {
return $event->result;
}
if (!empty($event->result)) {
$entity = $event->result;
}
$fields = $this->config('fields');
if ($entity->has($fields['key']) && $entity->has($fields['value'])) {
return true;
}
$mappedIds = $this->_getFieldToIdMapping($keys);
$entities = [];
foreach ($entity->toArray() as $key => $value) {
if ($this->_table->hasField($key)) {
continue;
}
$serialized = false;
if (in_array($key, $this->config('serializeFields'))) {
$value = serialize($value);
$serialized = true;
}
/** @var Setting $kvEntity */
$kvEntity = $this->_table->newEntity([
'scope' => $this->config('scope'),
$this->config('fields.key') => $key,
$this->config('fields.value') => $value,
'serialized' => $serialized
]);
if (($existingId = Hash::get($mappedIds, $key)) !== null) {
$kvEntity->id = $existingId;
}
$entities[] = $kvEntity;
}
$result = $this->_table->connection()->transactional(function () use ($entities) {
foreach ($entities as $e) {
$this->_table->save($e);
}
});
return ($result !== false);
} | php | public function saveKeyValues(Entity $entity, array $keys)
{
$event = $this->_table->dispatchEvent('Model.beforeSaveKeyValues', compact('entity'));
if ($event->isStopped()) {
return $event->result;
}
if (!empty($event->result)) {
$entity = $event->result;
}
$fields = $this->config('fields');
if ($entity->has($fields['key']) && $entity->has($fields['value'])) {
return true;
}
$mappedIds = $this->_getFieldToIdMapping($keys);
$entities = [];
foreach ($entity->toArray() as $key => $value) {
if ($this->_table->hasField($key)) {
continue;
}
$serialized = false;
if (in_array($key, $this->config('serializeFields'))) {
$value = serialize($value);
$serialized = true;
}
/** @var Setting $kvEntity */
$kvEntity = $this->_table->newEntity([
'scope' => $this->config('scope'),
$this->config('fields.key') => $key,
$this->config('fields.value') => $value,
'serialized' => $serialized
]);
if (($existingId = Hash::get($mappedIds, $key)) !== null) {
$kvEntity->id = $existingId;
}
$entities[] = $kvEntity;
}
$result = $this->_table->connection()->transactional(function () use ($entities) {
foreach ($entities as $e) {
$this->_table->save($e);
}
});
return ($result !== false);
} | [
"public",
"function",
"saveKeyValues",
"(",
"Entity",
"$",
"entity",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"_table",
"->",
"dispatchEvent",
"(",
"'Model.beforeSaveKeyValues'",
",",
"compact",
"(",
"'entity'",
")",
")",
";",
"if",
"(",
"$",
"event",
"->",
"isStopped",
"(",
")",
")",
"{",
"return",
"$",
"event",
"->",
"result",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
"->",
"result",
")",
")",
"{",
"$",
"entity",
"=",
"$",
"event",
"->",
"result",
";",
"}",
"$",
"fields",
"=",
"$",
"this",
"->",
"config",
"(",
"'fields'",
")",
";",
"if",
"(",
"$",
"entity",
"->",
"has",
"(",
"$",
"fields",
"[",
"'key'",
"]",
")",
"&&",
"$",
"entity",
"->",
"has",
"(",
"$",
"fields",
"[",
"'value'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"mappedIds",
"=",
"$",
"this",
"->",
"_getFieldToIdMapping",
"(",
"$",
"keys",
")",
";",
"$",
"entities",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"entity",
"->",
"toArray",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_table",
"->",
"hasField",
"(",
"$",
"key",
")",
")",
"{",
"continue",
";",
"}",
"$",
"serialized",
"=",
"false",
";",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"config",
"(",
"'serializeFields'",
")",
")",
")",
"{",
"$",
"value",
"=",
"serialize",
"(",
"$",
"value",
")",
";",
"$",
"serialized",
"=",
"true",
";",
"}",
"/** @var Setting $kvEntity */",
"$",
"kvEntity",
"=",
"$",
"this",
"->",
"_table",
"->",
"newEntity",
"(",
"[",
"'scope'",
"=>",
"$",
"this",
"->",
"config",
"(",
"'scope'",
")",
",",
"$",
"this",
"->",
"config",
"(",
"'fields.key'",
")",
"=>",
"$",
"key",
",",
"$",
"this",
"->",
"config",
"(",
"'fields.value'",
")",
"=>",
"$",
"value",
",",
"'serialized'",
"=>",
"$",
"serialized",
"]",
")",
";",
"if",
"(",
"(",
"$",
"existingId",
"=",
"Hash",
"::",
"get",
"(",
"$",
"mappedIds",
",",
"$",
"key",
")",
")",
"!==",
"null",
")",
"{",
"$",
"kvEntity",
"->",
"id",
"=",
"$",
"existingId",
";",
"}",
"$",
"entities",
"[",
"]",
"=",
"$",
"kvEntity",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"_table",
"->",
"connection",
"(",
")",
"->",
"transactional",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"entities",
")",
"{",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"_table",
"->",
"save",
"(",
"$",
"e",
")",
";",
"}",
"}",
")",
";",
"return",
"(",
"$",
"result",
"!==",
"false",
")",
";",
"}"
] | Save key value pairs.
@param Entity $entity The entity to save key values on.
@param array $keys The keys to apply.
@return bool|mixed | [
"Save",
"key",
"value",
"pairs",
"."
] | 0eadbb64d2fc201bacc63c93814adeca70e08f90 | https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Model/Behavior/KeyValueBehavior.php#L123-L177 |
317 | wasabi-cms/core | src/Model/Behavior/KeyValueBehavior.php | KeyValueBehavior._getFieldToIdMapping | protected function _getFieldToIdMapping(array $keys)
{
return $this->_table
->find('list', [
'keyField' => $this->config('fields.key'),
'valueField' => 'id'
])
->where([
'scope' => $this->config('scope'),
$this->config('fields.key') . ' IN' => $keys
])
->toArray();
} | php | protected function _getFieldToIdMapping(array $keys)
{
return $this->_table
->find('list', [
'keyField' => $this->config('fields.key'),
'valueField' => 'id'
])
->where([
'scope' => $this->config('scope'),
$this->config('fields.key') . ' IN' => $keys
])
->toArray();
} | [
"protected",
"function",
"_getFieldToIdMapping",
"(",
"array",
"$",
"keys",
")",
"{",
"return",
"$",
"this",
"->",
"_table",
"->",
"find",
"(",
"'list'",
",",
"[",
"'keyField'",
"=>",
"$",
"this",
"->",
"config",
"(",
"'fields.key'",
")",
",",
"'valueField'",
"=>",
"'id'",
"]",
")",
"->",
"where",
"(",
"[",
"'scope'",
"=>",
"$",
"this",
"->",
"config",
"(",
"'scope'",
")",
",",
"$",
"this",
"->",
"config",
"(",
"'fields.key'",
")",
".",
"' IN'",
"=>",
"$",
"keys",
"]",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] | Returns an array of existing keys and
their corresponding ids
@param array $keys The keys to map.
@return array | [
"Returns",
"an",
"array",
"of",
"existing",
"keys",
"and",
"their",
"corresponding",
"ids"
] | 0eadbb64d2fc201bacc63c93814adeca70e08f90 | https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Model/Behavior/KeyValueBehavior.php#L186-L198 |
318 | nirix/radium | src/Database/Model.php | Model.loadSchema | protected static function loadSchema()
{
// Make sure there's a place to store the schema
if (!array_key_exists(static::table(), static::$_schema)) {
static::$_schema[static::table()] = null;
}
// Make sure we haven't already fetched
// the tables schema.
if (static::$_schema[static::table()] === null) {
$result = static::connection()->prepare("DESCRIBE `" . static::table() . "`")->exec();
foreach ($result->fetchAll(\PDO::FETCH_COLUMN) as $column) {
static::$_schema[static::table()][$column['Field']] = array(
'type' => $column['Type'],
'default' => $column['Default'],
'null' => $column['Null'] == 'NO' ? false : true,
'key' => $column['Key'],
'extra' => $column['Extra']
);
}
}
} | php | protected static function loadSchema()
{
// Make sure there's a place to store the schema
if (!array_key_exists(static::table(), static::$_schema)) {
static::$_schema[static::table()] = null;
}
// Make sure we haven't already fetched
// the tables schema.
if (static::$_schema[static::table()] === null) {
$result = static::connection()->prepare("DESCRIBE `" . static::table() . "`")->exec();
foreach ($result->fetchAll(\PDO::FETCH_COLUMN) as $column) {
static::$_schema[static::table()][$column['Field']] = array(
'type' => $column['Type'],
'default' => $column['Default'],
'null' => $column['Null'] == 'NO' ? false : true,
'key' => $column['Key'],
'extra' => $column['Extra']
);
}
}
} | [
"protected",
"static",
"function",
"loadSchema",
"(",
")",
"{",
"// Make sure there's a place to store the schema",
"if",
"(",
"!",
"array_key_exists",
"(",
"static",
"::",
"table",
"(",
")",
",",
"static",
"::",
"$",
"_schema",
")",
")",
"{",
"static",
"::",
"$",
"_schema",
"[",
"static",
"::",
"table",
"(",
")",
"]",
"=",
"null",
";",
"}",
"// Make sure we haven't already fetched",
"// the tables schema.",
"if",
"(",
"static",
"::",
"$",
"_schema",
"[",
"static",
"::",
"table",
"(",
")",
"]",
"===",
"null",
")",
"{",
"$",
"result",
"=",
"static",
"::",
"connection",
"(",
")",
"->",
"prepare",
"(",
"\"DESCRIBE `\"",
".",
"static",
"::",
"table",
"(",
")",
".",
"\"`\"",
")",
"->",
"exec",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
")",
"as",
"$",
"column",
")",
"{",
"static",
"::",
"$",
"_schema",
"[",
"static",
"::",
"table",
"(",
")",
"]",
"[",
"$",
"column",
"[",
"'Field'",
"]",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"column",
"[",
"'Type'",
"]",
",",
"'default'",
"=>",
"$",
"column",
"[",
"'Default'",
"]",
",",
"'null'",
"=>",
"$",
"column",
"[",
"'Null'",
"]",
"==",
"'NO'",
"?",
"false",
":",
"true",
",",
"'key'",
"=>",
"$",
"column",
"[",
"'Key'",
"]",
",",
"'extra'",
"=>",
"$",
"column",
"[",
"'Extra'",
"]",
")",
";",
"}",
"}",
"}"
] | Used to fetch the tables schema.
@access protected | [
"Used",
"to",
"fetch",
"the",
"tables",
"schema",
"."
] | cc6907bfee296b64a7630b0b188e233d7cdb86fd | https://github.com/nirix/radium/blob/cc6907bfee296b64a7630b0b188e233d7cdb86fd/src/Database/Model.php#L86-L107 |
319 | nirix/radium | src/Database/Model.php | Model.find | public static function find($find, $value = null)
{
if ($value === null) {
$value = $find;
$find = static::$_primaryKey;
}
return static::select()->where("{$find} = ?", $value)->fetch();
} | php | public static function find($find, $value = null)
{
if ($value === null) {
$value = $find;
$find = static::$_primaryKey;
}
return static::select()->where("{$find} = ?", $value)->fetch();
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"find",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"find",
";",
"$",
"find",
"=",
"static",
"::",
"$",
"_primaryKey",
";",
"}",
"return",
"static",
"::",
"select",
"(",
")",
"->",
"where",
"(",
"\"{$find} = ?\"",
",",
"$",
"value",
")",
"->",
"fetch",
"(",
")",
";",
"}"
] | Returns the first found row.
@return object | [
"Returns",
"the",
"first",
"found",
"row",
"."
] | cc6907bfee296b64a7630b0b188e233d7cdb86fd | https://github.com/nirix/radium/blob/cc6907bfee296b64a7630b0b188e233d7cdb86fd/src/Database/Model.php#L136-L144 |
320 | nirix/radium | src/Database/Model.php | Model.data | public function data()
{
$data = array();
foreach (array_keys(static::schema()) as $column) {
if (isset($this->{$column})) {
$data[$column] = $this->{$column};
}
}
return $data;
} | php | public function data()
{
$data = array();
foreach (array_keys(static::schema()) as $column) {
if (isset($this->{$column})) {
$data[$column] = $this->{$column};
}
}
return $data;
} | [
"public",
"function",
"data",
"(",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"static",
"::",
"schema",
"(",
")",
")",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"column",
"}",
")",
")",
"{",
"$",
"data",
"[",
"$",
"column",
"]",
"=",
"$",
"this",
"->",
"{",
"$",
"column",
"}",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Gets the models data.
@return array | [
"Gets",
"the",
"models",
"data",
"."
] | cc6907bfee296b64a7630b0b188e233d7cdb86fd | https://github.com/nirix/radium/blob/cc6907bfee296b64a7630b0b188e233d7cdb86fd/src/Database/Model.php#L185-L194 |
321 | nirix/radium | src/Database/Model.php | Model.save | public function save()
{
// Validate
if (!$this->validates()) {
return false;
}
// Run filter
$this->runFilters('before', $this->_isNew ? 'create' : 'save');
// Get data
$data = static::data();
// Create
if ($this->_isNew) {
$result = static::connection()
->insert($data)
->into(static::table())
->exec();
$this->id = static::connection()->lastInsertId();
}
// Update
else {
$result = static::connection()
->update(static::table())
->set($data)
->where(static::$_primaryKey . ' = ?', $data[static::$_primaryKey])
->exec();
}
// Run filters
$this->runFilters('after', $this->_isNew ? 'create' : 'save');
return $result;
} | php | public function save()
{
// Validate
if (!$this->validates()) {
return false;
}
// Run filter
$this->runFilters('before', $this->_isNew ? 'create' : 'save');
// Get data
$data = static::data();
// Create
if ($this->_isNew) {
$result = static::connection()
->insert($data)
->into(static::table())
->exec();
$this->id = static::connection()->lastInsertId();
}
// Update
else {
$result = static::connection()
->update(static::table())
->set($data)
->where(static::$_primaryKey . ' = ?', $data[static::$_primaryKey])
->exec();
}
// Run filters
$this->runFilters('after', $this->_isNew ? 'create' : 'save');
return $result;
} | [
"public",
"function",
"save",
"(",
")",
"{",
"// Validate",
"if",
"(",
"!",
"$",
"this",
"->",
"validates",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Run filter",
"$",
"this",
"->",
"runFilters",
"(",
"'before'",
",",
"$",
"this",
"->",
"_isNew",
"?",
"'create'",
":",
"'save'",
")",
";",
"// Get data",
"$",
"data",
"=",
"static",
"::",
"data",
"(",
")",
";",
"// Create",
"if",
"(",
"$",
"this",
"->",
"_isNew",
")",
"{",
"$",
"result",
"=",
"static",
"::",
"connection",
"(",
")",
"->",
"insert",
"(",
"$",
"data",
")",
"->",
"into",
"(",
"static",
"::",
"table",
"(",
")",
")",
"->",
"exec",
"(",
")",
";",
"$",
"this",
"->",
"id",
"=",
"static",
"::",
"connection",
"(",
")",
"->",
"lastInsertId",
"(",
")",
";",
"}",
"// Update",
"else",
"{",
"$",
"result",
"=",
"static",
"::",
"connection",
"(",
")",
"->",
"update",
"(",
"static",
"::",
"table",
"(",
")",
")",
"->",
"set",
"(",
"$",
"data",
")",
"->",
"where",
"(",
"static",
"::",
"$",
"_primaryKey",
".",
"' = ?'",
",",
"$",
"data",
"[",
"static",
"::",
"$",
"_primaryKey",
"]",
")",
"->",
"exec",
"(",
")",
";",
"}",
"// Run filters",
"$",
"this",
"->",
"runFilters",
"(",
"'after'",
",",
"$",
"this",
"->",
"_isNew",
"?",
"'create'",
":",
"'save'",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Saves the model to the database.
@return boolean | [
"Saves",
"the",
"model",
"to",
"the",
"database",
"."
] | cc6907bfee296b64a7630b0b188e233d7cdb86fd | https://github.com/nirix/radium/blob/cc6907bfee296b64a7630b0b188e233d7cdb86fd/src/Database/Model.php#L201-L236 |
322 | nirix/radium | src/Database/Model.php | Model.delete | public function delete()
{
// Delete row
$result = static::connection()
->delete()
->from(static::table())
->where(static::$_primaryKey . " = ?", $this->{static::$_primaryKey})
->limit(1)
->exec();
// Run filters
if ($result) {
$this->runFilters('after', 'delete');
}
return $result;
} | php | public function delete()
{
// Delete row
$result = static::connection()
->delete()
->from(static::table())
->where(static::$_primaryKey . " = ?", $this->{static::$_primaryKey})
->limit(1)
->exec();
// Run filters
if ($result) {
$this->runFilters('after', 'delete');
}
return $result;
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"// Delete row",
"$",
"result",
"=",
"static",
"::",
"connection",
"(",
")",
"->",
"delete",
"(",
")",
"->",
"from",
"(",
"static",
"::",
"table",
"(",
")",
")",
"->",
"where",
"(",
"static",
"::",
"$",
"_primaryKey",
".",
"\" = ?\"",
",",
"$",
"this",
"->",
"{",
"static",
"::",
"$",
"_primaryKey",
"}",
")",
"->",
"limit",
"(",
"1",
")",
"->",
"exec",
"(",
")",
";",
"// Run filters",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"runFilters",
"(",
"'after'",
",",
"'delete'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Deletes the row from the database.
@return boolean | [
"Deletes",
"the",
"row",
"from",
"the",
"database",
"."
] | cc6907bfee296b64a7630b0b188e233d7cdb86fd | https://github.com/nirix/radium/blob/cc6907bfee296b64a7630b0b188e233d7cdb86fd/src/Database/Model.php#L243-L259 |
323 | nirix/radium | src/Database/Model.php | Model.__toArray | public function __toArray()
{
$data = array();
foreach (static::schema() as $field => $options) {
$data[$field] = $this->{$field};
}
return $data;
} | php | public function __toArray()
{
$data = array();
foreach (static::schema() as $field => $options) {
$data[$field] = $this->{$field};
}
return $data;
} | [
"public",
"function",
"__toArray",
"(",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"schema",
"(",
")",
"as",
"$",
"field",
"=>",
"$",
"options",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"this",
"->",
"{",
"$",
"field",
"}",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Returns the models properties in a key => value array.
@return array | [
"Returns",
"the",
"models",
"properties",
"in",
"a",
"key",
"=",
">",
"value",
"array",
"."
] | cc6907bfee296b64a7630b0b188e233d7cdb86fd | https://github.com/nirix/radium/blob/cc6907bfee296b64a7630b0b188e233d7cdb86fd/src/Database/Model.php#L266-L275 |
324 | phn-io/syntax | spec/Phn/Syntax/Rule/NumberRuleSpec.php | NumberRuleSpec.it_matches_identifiers | function it_matches_identifiers()
{
$this->match('123')->shouldReturn('123');
$this->match('3.14')->shouldReturn('3.14');
$this->match('-123')->shouldReturn('-123');
} | php | function it_matches_identifiers()
{
$this->match('123')->shouldReturn('123');
$this->match('3.14')->shouldReturn('3.14');
$this->match('-123')->shouldReturn('-123');
} | [
"function",
"it_matches_identifiers",
"(",
")",
"{",
"$",
"this",
"->",
"match",
"(",
"'123'",
")",
"->",
"shouldReturn",
"(",
"'123'",
")",
";",
"$",
"this",
"->",
"match",
"(",
"'3.14'",
")",
"->",
"shouldReturn",
"(",
"'3.14'",
")",
";",
"$",
"this",
"->",
"match",
"(",
"'-123'",
")",
"->",
"shouldReturn",
"(",
"'-123'",
")",
";",
"}"
] | It matches identifiers. | [
"It",
"matches",
"identifiers",
"."
] | 80fa47415a5eb7d306cc0cc31588f95afbce7306 | https://github.com/phn-io/syntax/blob/80fa47415a5eb7d306cc0cc31588f95afbce7306/spec/Phn/Syntax/Rule/NumberRuleSpec.php#L34-L39 |
325 | marando/phpSOFA | src/Marando/IAU/iauGst06a.php | iauGst06a.Gst06a | public static function Gst06a($uta, $utb, $tta, $ttb) {
$rnpb = [];
$gst;
/* Classical nutation x precession x bias matrix, IAU 2000A. */
IAU::Pnm06a($tta, $ttb, $rnpb);
/* Greenwich apparent sidereal time. */
$gst = IAU::Gst06($uta, $utb, $tta, $ttb, $rnpb);
return $gst;
} | php | public static function Gst06a($uta, $utb, $tta, $ttb) {
$rnpb = [];
$gst;
/* Classical nutation x precession x bias matrix, IAU 2000A. */
IAU::Pnm06a($tta, $ttb, $rnpb);
/* Greenwich apparent sidereal time. */
$gst = IAU::Gst06($uta, $utb, $tta, $ttb, $rnpb);
return $gst;
} | [
"public",
"static",
"function",
"Gst06a",
"(",
"$",
"uta",
",",
"$",
"utb",
",",
"$",
"tta",
",",
"$",
"ttb",
")",
"{",
"$",
"rnpb",
"=",
"[",
"]",
";",
"$",
"gst",
";",
"/* Classical nutation x precession x bias matrix, IAU 2000A. */",
"IAU",
"::",
"Pnm06a",
"(",
"$",
"tta",
",",
"$",
"ttb",
",",
"$",
"rnpb",
")",
";",
"/* Greenwich apparent sidereal time. */",
"$",
"gst",
"=",
"IAU",
"::",
"Gst06",
"(",
"$",
"uta",
",",
"$",
"utb",
",",
"$",
"tta",
",",
"$",
"ttb",
",",
"$",
"rnpb",
")",
";",
"return",
"$",
"gst",
";",
"}"
] | - - - - - - - - - -
i a u G s t 0 6 a
- - - - - - - - - -
Greenwich apparent sidereal time (consistent with IAU 2000 and 2006
resolutions).
This function is part of the International Astronomical Union's
SOFA (Standards Of Fundamental Astronomy) software collection.
Status: canonical model.
Given:
uta,utb double UT1 as a 2-part Julian Date (Notes 1,2)
tta,ttb double TT as a 2-part Julian Date (Notes 1,2)
Returned (function value):
double Greenwich apparent sidereal time (radians)
Notes:
1) The UT1 and TT dates uta+utb and tta+ttb respectively, are both
Julian Dates, apportioned in any convenient way between the
argument pairs. For example, JD=2450123.7 could be expressed in
any of these ways, among others:
Part A Part B
2450123.7 0.0 (JD method)
2451545.0 -1421.3 (J2000 method)
2400000.5 50123.2 (MJD method)
2450123.5 0.2 (date & time method)
The JD method is the most natural and convenient to use in
cases where the loss of several decimal digits of resolution
is acceptable (in the case of UT; the TT is not at all critical
in this respect). The J2000 and MJD methods are good compromises
between resolution and convenience. For UT, the date & time
method is best matched to the algorithm that is used by the Earth
rotation angle function, called internally: maximum precision is
delivered when the uta argument is for 0hrs UT1 on the day in
question and the utb argument lies in the range 0 to 1, or vice
versa.
2) Both UT1 and TT are required, UT1 to predict the Earth rotation
and TT to predict the effects of precession-nutation. If UT1 is
used for both purposes, errors of order 100 microarcseconds
result.
3) This GAST is compatible with the IAU 2000/2006 resolutions and
must be used only in conjunction with IAU 2006 precession and
IAU 2000A nutation.
4) The result is returned in the range 0 to 2pi.
Called:
iauPnm06a classical NPB matrix, IAU 2006/2000A
iauGst06 Greenwich apparent ST, IAU 2006, given NPB matrix
Reference:
Wallace, P.T. & Capitaine, N., 2006, Astron.Astrophys. 459, 981
This revision: 2013 June 18
SOFA release 2015-02-09
Copyright (C) 2015 IAU SOFA Board. See notes at end. | [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"i",
"a",
"u",
"G",
"s",
"t",
"0",
"6",
"a",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
] | 757fa49fe335ae1210eaa7735473fd4388b13f07 | https://github.com/marando/phpSOFA/blob/757fa49fe335ae1210eaa7735473fd4388b13f07/src/Marando/IAU/iauGst06a.php#L77-L88 |
326 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.setExcludes | public function setExcludes(array $excludes): self
{
$this->excludes = \array_map(function ($value) {
return \trim($value, '/');
}, $excludes);
return $this;
} | php | public function setExcludes(array $excludes): self
{
$this->excludes = \array_map(function ($value) {
return \trim($value, '/');
}, $excludes);
return $this;
} | [
"public",
"function",
"setExcludes",
"(",
"array",
"$",
"excludes",
")",
":",
"self",
"{",
"$",
"this",
"->",
"excludes",
"=",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"\\",
"trim",
"(",
"$",
"value",
",",
"'/'",
")",
";",
"}",
",",
"$",
"excludes",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Exclude paths from finder.
@param array $excludes
@return \Narrowspark\Automatic\Common\ClassFinder | [
"Exclude",
"paths",
"from",
"finder",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L129-L136 |
327 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.setComposerAutoload | public function setComposerAutoload(string $packageName, array $autoload): self
{
$this->reset();
if (isset($autoload['psr-0'])) {
$this->addPsr0($packageName, (array) $autoload['psr-0']);
}
if (isset($autoload['psr-4'])) {
$this->addPsr4($packageName, (array) $autoload['psr-4']);
}
if (isset($autoload['classmap'])) {
$this->addClassmap($packageName, (array) $autoload['classmap']);
}
if (isset($autoload['exclude-from-classmap'])) {
$this->setExcludes((array) $autoload['exclude-from-classmap']);
}
return $this;
} | php | public function setComposerAutoload(string $packageName, array $autoload): self
{
$this->reset();
if (isset($autoload['psr-0'])) {
$this->addPsr0($packageName, (array) $autoload['psr-0']);
}
if (isset($autoload['psr-4'])) {
$this->addPsr4($packageName, (array) $autoload['psr-4']);
}
if (isset($autoload['classmap'])) {
$this->addClassmap($packageName, (array) $autoload['classmap']);
}
if (isset($autoload['exclude-from-classmap'])) {
$this->setExcludes((array) $autoload['exclude-from-classmap']);
}
return $this;
} | [
"public",
"function",
"setComposerAutoload",
"(",
"string",
"$",
"packageName",
",",
"array",
"$",
"autoload",
")",
":",
"self",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"autoload",
"[",
"'psr-0'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addPsr0",
"(",
"$",
"packageName",
",",
"(",
"array",
")",
"$",
"autoload",
"[",
"'psr-0'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"autoload",
"[",
"'psr-4'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addPsr4",
"(",
"$",
"packageName",
",",
"(",
"array",
")",
"$",
"autoload",
"[",
"'psr-4'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"autoload",
"[",
"'classmap'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addClassmap",
"(",
"$",
"packageName",
",",
"(",
"array",
")",
"$",
"autoload",
"[",
"'classmap'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"autoload",
"[",
"'exclude-from-classmap'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setExcludes",
"(",
"(",
"array",
")",
"$",
"autoload",
"[",
"'exclude-from-classmap'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the composer.json file autoload key values.
@param string $packageName
@param array $autoload
@return \Narrowspark\Automatic\Common\ClassFinder | [
"Set",
"the",
"composer",
".",
"json",
"file",
"autoload",
"key",
"values",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L160-L181 |
328 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.addPsr0 | public function addPsr0(string $packageName, array $paths): self
{
$this->paths['psr0'][$packageName] = $paths;
return $this;
} | php | public function addPsr0(string $packageName, array $paths): self
{
$this->paths['psr0'][$packageName] = $paths;
return $this;
} | [
"public",
"function",
"addPsr0",
"(",
"string",
"$",
"packageName",
",",
"array",
"$",
"paths",
")",
":",
"self",
"{",
"$",
"this",
"->",
"paths",
"[",
"'psr0'",
"]",
"[",
"$",
"packageName",
"]",
"=",
"$",
"paths",
";",
"return",
"$",
"this",
";",
"}"
] | Add composer psr0 paths.
@param string $packageName
@param array $paths
@return \Narrowspark\Automatic\Common\ClassFinder | [
"Add",
"composer",
"psr0",
"paths",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L191-L196 |
329 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.addPsr4 | public function addPsr4(string $packageName, array $paths): self
{
$this->paths['psr4'][$packageName] = $paths;
return $this;
} | php | public function addPsr4(string $packageName, array $paths): self
{
$this->paths['psr4'][$packageName] = $paths;
return $this;
} | [
"public",
"function",
"addPsr4",
"(",
"string",
"$",
"packageName",
",",
"array",
"$",
"paths",
")",
":",
"self",
"{",
"$",
"this",
"->",
"paths",
"[",
"'psr4'",
"]",
"[",
"$",
"packageName",
"]",
"=",
"$",
"paths",
";",
"return",
"$",
"this",
";",
"}"
] | Add composer psr4 paths.
@param string $packageName
@param array $paths
@return \Narrowspark\Automatic\Common\ClassFinder | [
"Add",
"composer",
"psr4",
"paths",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L206-L211 |
330 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.addClassmap | public function addClassmap(string $packageName, array $paths): self
{
$this->paths['classmap'][$packageName] = $paths;
return $this;
} | php | public function addClassmap(string $packageName, array $paths): self
{
$this->paths['classmap'][$packageName] = $paths;
return $this;
} | [
"public",
"function",
"addClassmap",
"(",
"string",
"$",
"packageName",
",",
"array",
"$",
"paths",
")",
":",
"self",
"{",
"$",
"this",
"->",
"paths",
"[",
"'classmap'",
"]",
"[",
"$",
"packageName",
"]",
"=",
"$",
"paths",
";",
"return",
"$",
"this",
";",
"}"
] | Add composer classmap paths.
@param string $packageName
@param array $paths
@return \Narrowspark\Automatic\Common\ClassFinder | [
"Add",
"composer",
"classmap",
"paths",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L221-L226 |
331 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.find | public function find(): self
{
$preparedPaths = \array_unique(
\array_merge(
$this->getPreparedPaths((array) $this->paths['psr0']),
$this->getPreparedPaths((array) $this->paths['psr4']),
$this->getPreparedPaths((array) $this->paths['classmap'])
),
\SORT_STRING
);
$finder = Finder::create()
->files()
->in($preparedPaths)
->exclude($this->excludes)
->name('*.php')
->sortByName();
if ($this->filter !== null) {
$finder->filter($this->filter);
}
/** @var \SplFileInfo $file */
foreach ($finder as $file) {
$realPath = (string) $file->getRealPath();
$namespace = null;
$tokens = \token_get_all((string) \file_get_contents($realPath));
foreach ($tokens as $key => $token) {
if (\is_array($token)) {
if ($token[0] === \T_NAMESPACE) {
$namespace = self::getNamespace($key + 2, $tokens);
} elseif ($token[0] === \T_INTERFACE) {
$name = self::getName($key + 2, $tokens);
if ($name === null) {
continue 2;
}
$this->interfaces[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
} elseif ($token[0] === \T_TRAIT) {
$name = self::getName($key + 2, $tokens);
if ($name === null) {
continue 2;
}
$this->traits[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
} elseif ($token[0] === \T_ABSTRACT) {
$name = self::getName($key + 4, $tokens);
if ($name === null) {
continue 2;
}
$this->abstractClasses[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
continue 2;
} elseif ($token[0] === \T_CLASS) {
$name = self::getName($key + 2, $tokens);
if ($name === null) {
continue 2;
}
$this->classes[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
}
}
}
unset($tokens);
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
\gc_mem_caches();
}
return $this;
} | php | public function find(): self
{
$preparedPaths = \array_unique(
\array_merge(
$this->getPreparedPaths((array) $this->paths['psr0']),
$this->getPreparedPaths((array) $this->paths['psr4']),
$this->getPreparedPaths((array) $this->paths['classmap'])
),
\SORT_STRING
);
$finder = Finder::create()
->files()
->in($preparedPaths)
->exclude($this->excludes)
->name('*.php')
->sortByName();
if ($this->filter !== null) {
$finder->filter($this->filter);
}
/** @var \SplFileInfo $file */
foreach ($finder as $file) {
$realPath = (string) $file->getRealPath();
$namespace = null;
$tokens = \token_get_all((string) \file_get_contents($realPath));
foreach ($tokens as $key => $token) {
if (\is_array($token)) {
if ($token[0] === \T_NAMESPACE) {
$namespace = self::getNamespace($key + 2, $tokens);
} elseif ($token[0] === \T_INTERFACE) {
$name = self::getName($key + 2, $tokens);
if ($name === null) {
continue 2;
}
$this->interfaces[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
} elseif ($token[0] === \T_TRAIT) {
$name = self::getName($key + 2, $tokens);
if ($name === null) {
continue 2;
}
$this->traits[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
} elseif ($token[0] === \T_ABSTRACT) {
$name = self::getName($key + 4, $tokens);
if ($name === null) {
continue 2;
}
$this->abstractClasses[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
continue 2;
} elseif ($token[0] === \T_CLASS) {
$name = self::getName($key + 2, $tokens);
if ($name === null) {
continue 2;
}
$this->classes[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
}
}
}
unset($tokens);
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
\gc_mem_caches();
}
return $this;
} | [
"public",
"function",
"find",
"(",
")",
":",
"self",
"{",
"$",
"preparedPaths",
"=",
"\\",
"array_unique",
"(",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"getPreparedPaths",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"paths",
"[",
"'psr0'",
"]",
")",
",",
"$",
"this",
"->",
"getPreparedPaths",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"paths",
"[",
"'psr4'",
"]",
")",
",",
"$",
"this",
"->",
"getPreparedPaths",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"paths",
"[",
"'classmap'",
"]",
")",
")",
",",
"\\",
"SORT_STRING",
")",
";",
"$",
"finder",
"=",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"in",
"(",
"$",
"preparedPaths",
")",
"->",
"exclude",
"(",
"$",
"this",
"->",
"excludes",
")",
"->",
"name",
"(",
"'*.php'",
")",
"->",
"sortByName",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"filter",
"!==",
"null",
")",
"{",
"$",
"finder",
"->",
"filter",
"(",
"$",
"this",
"->",
"filter",
")",
";",
"}",
"/** @var \\SplFileInfo $file */",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"realPath",
"=",
"(",
"string",
")",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"$",
"namespace",
"=",
"null",
";",
"$",
"tokens",
"=",
"\\",
"token_get_all",
"(",
"(",
"string",
")",
"\\",
"file_get_contents",
"(",
"$",
"realPath",
")",
")",
";",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"key",
"=>",
"$",
"token",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"token",
")",
")",
"{",
"if",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"\\",
"T_NAMESPACE",
")",
"{",
"$",
"namespace",
"=",
"self",
"::",
"getNamespace",
"(",
"$",
"key",
"+",
"2",
",",
"$",
"tokens",
")",
";",
"}",
"elseif",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"\\",
"T_INTERFACE",
")",
"{",
"$",
"name",
"=",
"self",
"::",
"getName",
"(",
"$",
"key",
"+",
"2",
",",
"$",
"tokens",
")",
";",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"continue",
"2",
";",
"}",
"$",
"this",
"->",
"interfaces",
"[",
"\\",
"ltrim",
"(",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"name",
",",
"'\\\\'",
")",
"]",
"=",
"$",
"realPath",
";",
"}",
"elseif",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"\\",
"T_TRAIT",
")",
"{",
"$",
"name",
"=",
"self",
"::",
"getName",
"(",
"$",
"key",
"+",
"2",
",",
"$",
"tokens",
")",
";",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"continue",
"2",
";",
"}",
"$",
"this",
"->",
"traits",
"[",
"\\",
"ltrim",
"(",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"name",
",",
"'\\\\'",
")",
"]",
"=",
"$",
"realPath",
";",
"}",
"elseif",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"\\",
"T_ABSTRACT",
")",
"{",
"$",
"name",
"=",
"self",
"::",
"getName",
"(",
"$",
"key",
"+",
"4",
",",
"$",
"tokens",
")",
";",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"continue",
"2",
";",
"}",
"$",
"this",
"->",
"abstractClasses",
"[",
"\\",
"ltrim",
"(",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"name",
",",
"'\\\\'",
")",
"]",
"=",
"$",
"realPath",
";",
"continue",
"2",
";",
"}",
"elseif",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"\\",
"T_CLASS",
")",
"{",
"$",
"name",
"=",
"self",
"::",
"getName",
"(",
"$",
"key",
"+",
"2",
",",
"$",
"tokens",
")",
";",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"continue",
"2",
";",
"}",
"$",
"this",
"->",
"classes",
"[",
"\\",
"ltrim",
"(",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"name",
",",
"'\\\\'",
")",
"]",
"=",
"$",
"realPath",
";",
"}",
"}",
"}",
"unset",
"(",
"$",
"tokens",
")",
";",
"// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098",
"\\",
"gc_mem_caches",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Find all the class, traits and interface names in a given directory.
@return \Narrowspark\Automatic\Common\ClassFinder | [
"Find",
"all",
"the",
"class",
"traits",
"and",
"interface",
"names",
"in",
"a",
"given",
"directory",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L233-L310 |
332 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.getAll | public function getAll(): array
{
return \array_merge(
$this->interfaces,
$this->traits,
$this->abstractClasses,
$this->classes
);
} | php | public function getAll(): array
{
return \array_merge(
$this->interfaces,
$this->traits,
$this->abstractClasses,
$this->classes
);
} | [
"public",
"function",
"getAll",
"(",
")",
":",
"array",
"{",
"return",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"interfaces",
",",
"$",
"this",
"->",
"traits",
",",
"$",
"this",
"->",
"abstractClasses",
",",
"$",
"this",
"->",
"classes",
")",
";",
"}"
] | Returns a array of all found classes, interface and traits.
@return array|array<string, string> | [
"Returns",
"a",
"array",
"of",
"all",
"found",
"classes",
"interface",
"and",
"traits",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L317-L325 |
333 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.getName | private static function getName($key, array $tokens): ?string
{
$class = null;
$tokenCount = \count($tokens);
for ($i = $key; $i < $tokenCount; $i++) {
if (\is_array($tokens[$i])) {
if ($tokens[$i][0] === \T_STRING) {
$class .= $tokens[$i][1];
} elseif ($tokens[$i][0] === \T_WHITESPACE) {
return $class;
}
}
}
return null;
} | php | private static function getName($key, array $tokens): ?string
{
$class = null;
$tokenCount = \count($tokens);
for ($i = $key; $i < $tokenCount; $i++) {
if (\is_array($tokens[$i])) {
if ($tokens[$i][0] === \T_STRING) {
$class .= $tokens[$i][1];
} elseif ($tokens[$i][0] === \T_WHITESPACE) {
return $class;
}
}
}
return null;
} | [
"private",
"static",
"function",
"getName",
"(",
"$",
"key",
",",
"array",
"$",
"tokens",
")",
":",
"?",
"string",
"{",
"$",
"class",
"=",
"null",
";",
"$",
"tokenCount",
"=",
"\\",
"count",
"(",
"$",
"tokens",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"key",
";",
"$",
"i",
"<",
"$",
"tokenCount",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
")",
")",
"{",
"if",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
"===",
"\\",
"T_STRING",
")",
"{",
"$",
"class",
".=",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
";",
"}",
"elseif",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
"===",
"\\",
"T_WHITESPACE",
")",
"{",
"return",
"$",
"class",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Find the name in the tokens starting at a given key.
@param int $key
@param array $tokens
@return null|string | [
"Find",
"the",
"name",
"in",
"the",
"tokens",
"starting",
"at",
"a",
"given",
"key",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L387-L403 |
334 | narrowspark/automatic-common | ClassFinder.php | ClassFinder.getPreparedPaths | private function getPreparedPaths(array $paths): array
{
$fullPaths = [];
foreach ($paths as $name => $path) {
if (\is_array($path)) {
foreach ($path as $p) {
$fullPaths[] = \rtrim($this->vendorDir . \DIRECTORY_SEPARATOR . $name . \DIRECTORY_SEPARATOR . $p, '/');
}
} else {
$fullPaths[] = \rtrim($this->vendorDir . \DIRECTORY_SEPARATOR . $name . \DIRECTORY_SEPARATOR . $path, '/');
}
}
return $fullPaths;
} | php | private function getPreparedPaths(array $paths): array
{
$fullPaths = [];
foreach ($paths as $name => $path) {
if (\is_array($path)) {
foreach ($path as $p) {
$fullPaths[] = \rtrim($this->vendorDir . \DIRECTORY_SEPARATOR . $name . \DIRECTORY_SEPARATOR . $p, '/');
}
} else {
$fullPaths[] = \rtrim($this->vendorDir . \DIRECTORY_SEPARATOR . $name . \DIRECTORY_SEPARATOR . $path, '/');
}
}
return $fullPaths;
} | [
"private",
"function",
"getPreparedPaths",
"(",
"array",
"$",
"paths",
")",
":",
"array",
"{",
"$",
"fullPaths",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"name",
"=>",
"$",
"path",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"$",
"path",
"as",
"$",
"p",
")",
"{",
"$",
"fullPaths",
"[",
"]",
"=",
"\\",
"rtrim",
"(",
"$",
"this",
"->",
"vendorDir",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"$",
"p",
",",
"'/'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"fullPaths",
"[",
"]",
"=",
"\\",
"rtrim",
"(",
"$",
"this",
"->",
"vendorDir",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
",",
"'/'",
")",
";",
"}",
"}",
"return",
"$",
"fullPaths",
";",
"}"
] | Prepare psr0 and psr4 to full vendor package paths.
@param array $paths
@return array | [
"Prepare",
"psr0",
"and",
"psr4",
"to",
"full",
"vendor",
"package",
"paths",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/ClassFinder.php#L412-L427 |
335 | phlexible/phlexible | src/Phlexible/Bundle/DashboardBundle/Controller/InfoController.php | InfoController.infoAction | public function infoAction(Request $request)
{
$securityContext = $this->get('security.context');
$lines = [];
if ($securityContext->isGranted('ROLE_SUPER_ADMIN')) {
$lines[] = [
'Project:',
$this->container->getParameter('phlexible_gui.project.title').' '
.$this->container->getParameter('phlexible_gui.project.version'),
];
$lines[] = [
'Env:',
$this->container->getParameter('kernel.environment').($this->container->getParameter(
'kernel.debug'
) ? ' [DEBUG]' : ''),
];
$lines[] = ['Host:', $request->server->get('SERVER_NAME').' ['.PHP_SAPI.']'];
$connection = $this->getDoctrine()->getConnection();
/* @var $connection \Doctrine\DBAL\Connection */
$lines[] = [
'Default Database:',
$connection->getHost().' / '.$connection->getDatabase().' ['.$connection->getDriver()->getName(
).']',
];
$lines[] = ['Session:', $request->getSession()->getId().' ['.$request->server->get('REMOTE_ADDR').']'];
$lines[] = [
'User:',
$this->getUser()->getUsername().' ['.implode(', ', $this->getUser()->getRoles()).']',
];
$lines[] = ['UserAgent:', $request->server->get('HTTP_USER_AGENT')];
} else {
$lines[] = [
'Project:',
$this->container->getParameter('phlexible_gui.project.title').' '
.$this->container->getParameter('phlexible_gui.project.version'),
];
}
$l1 = 0;
$l2 = 0;
foreach ($lines as $line) {
if (strlen($line[0]) > $l1) {
$l1 = strlen($line[0]);
}
if (isset($line[1]) && strlen($line[1]) > $l2) {
$l2 = strlen($line[1]);
}
}
$table = '';
foreach ($lines as $line) {
$table .= str_pad($line[0], $l1 + 2);
$table .= str_pad($line[1], $l2 + 2);
if (isset($line[2])) {
$table .= $line[2];
}
$table .= PHP_EOL;
}
$out = '<pre>'.$table.'</pre>';
return new Response($out);
} | php | public function infoAction(Request $request)
{
$securityContext = $this->get('security.context');
$lines = [];
if ($securityContext->isGranted('ROLE_SUPER_ADMIN')) {
$lines[] = [
'Project:',
$this->container->getParameter('phlexible_gui.project.title').' '
.$this->container->getParameter('phlexible_gui.project.version'),
];
$lines[] = [
'Env:',
$this->container->getParameter('kernel.environment').($this->container->getParameter(
'kernel.debug'
) ? ' [DEBUG]' : ''),
];
$lines[] = ['Host:', $request->server->get('SERVER_NAME').' ['.PHP_SAPI.']'];
$connection = $this->getDoctrine()->getConnection();
/* @var $connection \Doctrine\DBAL\Connection */
$lines[] = [
'Default Database:',
$connection->getHost().' / '.$connection->getDatabase().' ['.$connection->getDriver()->getName(
).']',
];
$lines[] = ['Session:', $request->getSession()->getId().' ['.$request->server->get('REMOTE_ADDR').']'];
$lines[] = [
'User:',
$this->getUser()->getUsername().' ['.implode(', ', $this->getUser()->getRoles()).']',
];
$lines[] = ['UserAgent:', $request->server->get('HTTP_USER_AGENT')];
} else {
$lines[] = [
'Project:',
$this->container->getParameter('phlexible_gui.project.title').' '
.$this->container->getParameter('phlexible_gui.project.version'),
];
}
$l1 = 0;
$l2 = 0;
foreach ($lines as $line) {
if (strlen($line[0]) > $l1) {
$l1 = strlen($line[0]);
}
if (isset($line[1]) && strlen($line[1]) > $l2) {
$l2 = strlen($line[1]);
}
}
$table = '';
foreach ($lines as $line) {
$table .= str_pad($line[0], $l1 + 2);
$table .= str_pad($line[1], $l2 + 2);
if (isset($line[2])) {
$table .= $line[2];
}
$table .= PHP_EOL;
}
$out = '<pre>'.$table.'</pre>';
return new Response($out);
} | [
"public",
"function",
"infoAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"securityContext",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
";",
"$",
"lines",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"securityContext",
"->",
"isGranted",
"(",
"'ROLE_SUPER_ADMIN'",
")",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"[",
"'Project:'",
",",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'phlexible_gui.project.title'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'phlexible_gui.project.version'",
")",
",",
"]",
";",
"$",
"lines",
"[",
"]",
"=",
"[",
"'Env:'",
",",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'kernel.environment'",
")",
".",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'kernel.debug'",
")",
"?",
"' [DEBUG]'",
":",
"''",
")",
",",
"]",
";",
"$",
"lines",
"[",
"]",
"=",
"[",
"'Host:'",
",",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'SERVER_NAME'",
")",
".",
"' ['",
".",
"PHP_SAPI",
".",
"']'",
"]",
";",
"$",
"connection",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getConnection",
"(",
")",
";",
"/* @var $connection \\Doctrine\\DBAL\\Connection */",
"$",
"lines",
"[",
"]",
"=",
"[",
"'Default Database:'",
",",
"$",
"connection",
"->",
"getHost",
"(",
")",
".",
"' / '",
".",
"$",
"connection",
"->",
"getDatabase",
"(",
")",
".",
"' ['",
".",
"$",
"connection",
"->",
"getDriver",
"(",
")",
"->",
"getName",
"(",
")",
".",
"']'",
",",
"]",
";",
"$",
"lines",
"[",
"]",
"=",
"[",
"'Session:'",
",",
"$",
"request",
"->",
"getSession",
"(",
")",
"->",
"getId",
"(",
")",
".",
"' ['",
".",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'REMOTE_ADDR'",
")",
".",
"']'",
"]",
";",
"$",
"lines",
"[",
"]",
"=",
"[",
"'User:'",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getUsername",
"(",
")",
".",
"' ['",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getRoles",
"(",
")",
")",
".",
"']'",
",",
"]",
";",
"$",
"lines",
"[",
"]",
"=",
"[",
"'UserAgent:'",
",",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'HTTP_USER_AGENT'",
")",
"]",
";",
"}",
"else",
"{",
"$",
"lines",
"[",
"]",
"=",
"[",
"'Project:'",
",",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'phlexible_gui.project.title'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'phlexible_gui.project.version'",
")",
",",
"]",
";",
"}",
"$",
"l1",
"=",
"0",
";",
"$",
"l2",
"=",
"0",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"line",
"[",
"0",
"]",
")",
">",
"$",
"l1",
")",
"{",
"$",
"l1",
"=",
"strlen",
"(",
"$",
"line",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"1",
"]",
")",
"&&",
"strlen",
"(",
"$",
"line",
"[",
"1",
"]",
")",
">",
"$",
"l2",
")",
"{",
"$",
"l2",
"=",
"strlen",
"(",
"$",
"line",
"[",
"1",
"]",
")",
";",
"}",
"}",
"$",
"table",
"=",
"''",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"table",
".=",
"str_pad",
"(",
"$",
"line",
"[",
"0",
"]",
",",
"$",
"l1",
"+",
"2",
")",
";",
"$",
"table",
".=",
"str_pad",
"(",
"$",
"line",
"[",
"1",
"]",
",",
"$",
"l2",
"+",
"2",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"2",
"]",
")",
")",
"{",
"$",
"table",
".=",
"$",
"line",
"[",
"2",
"]",
";",
"}",
"$",
"table",
".=",
"PHP_EOL",
";",
"}",
"$",
"out",
"=",
"'<pre>'",
".",
"$",
"table",
".",
"'</pre>'",
";",
"return",
"new",
"Response",
"(",
"$",
"out",
")",
";",
"}"
] | Return info.
@param Request $request
@return Response
@Route("", name="dashboard_info") | [
"Return",
"info",
"."
] | 132f24924c9bb0dbb6c1ea84db0a463f97fa3893 | https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/DashboardBundle/Controller/InfoController.php#L35-L102 |
336 | bmdevel/php-index | classes/iterator/IndexIterator.php | IndexIterator.setOffset | public function setOffset($offset, $parseHints = Parser::HINT_NONE)
{
$this->offset = $offset;
$this->parseHints = $parseHints;
} | php | public function setOffset($offset, $parseHints = Parser::HINT_NONE)
{
$this->offset = $offset;
$this->parseHints = $parseHints;
} | [
"public",
"function",
"setOffset",
"(",
"$",
"offset",
",",
"$",
"parseHints",
"=",
"Parser",
"::",
"HINT_NONE",
")",
"{",
"$",
"this",
"->",
"offset",
"=",
"$",
"offset",
";",
"$",
"this",
"->",
"parseHints",
"=",
"$",
"parseHints",
";",
"}"
] | Sets a offset
@param int $offset Offset
@param int $parseHints Parse hints | [
"Sets",
"a",
"offset"
] | 6a6b476f1706b9524bfb34f6ce0963b1aea91259 | https://github.com/bmdevel/php-index/blob/6a6b476f1706b9524bfb34f6ce0963b1aea91259/classes/iterator/IndexIterator.php#L67-L71 |
337 | bmdevel/php-index | classes/iterator/IndexIterator.php | IndexIterator.iterateKeyReader | private function iterateKeyReader()
{
$results = $this->index->getKeyReader()->readKeys(
$this->offset,
$this->direction,
$this->parseHints
);
if (empty($results)) {
return $results;
}
// reverse order if iterating backwards
if ($this->direction == KeyReader::DIRECTION_BACKWARD) {
// $results = array_reverse($results);
// trim results to the offset and reverse the order
$revertBackwardResults = array();
foreach ($results as $result) {
if ($result->getOffset() > $this->offset) {
break;
}
array_unshift($revertBackwardResults, $result);
}
$results = $revertBackwardResults;
}
// shift offset
$end = end($results);
switch ($this->direction) {
case KeyReader::DIRECTION_FORWARD:
$this->setOffset($end->getOffset() + strlen($end->getData()));
break;
case KeyReader::DIRECTION_BACKWARD:
$this->setOffset($end->getOffset() - 1);
break;
default:
throw new \LogicException("invalid direction");
}
// remove duplicates (BACKWARD only)
$this->avoidBackwardDuplicates($results);
reset($results);
return $results;
} | php | private function iterateKeyReader()
{
$results = $this->index->getKeyReader()->readKeys(
$this->offset,
$this->direction,
$this->parseHints
);
if (empty($results)) {
return $results;
}
// reverse order if iterating backwards
if ($this->direction == KeyReader::DIRECTION_BACKWARD) {
// $results = array_reverse($results);
// trim results to the offset and reverse the order
$revertBackwardResults = array();
foreach ($results as $result) {
if ($result->getOffset() > $this->offset) {
break;
}
array_unshift($revertBackwardResults, $result);
}
$results = $revertBackwardResults;
}
// shift offset
$end = end($results);
switch ($this->direction) {
case KeyReader::DIRECTION_FORWARD:
$this->setOffset($end->getOffset() + strlen($end->getData()));
break;
case KeyReader::DIRECTION_BACKWARD:
$this->setOffset($end->getOffset() - 1);
break;
default:
throw new \LogicException("invalid direction");
}
// remove duplicates (BACKWARD only)
$this->avoidBackwardDuplicates($results);
reset($results);
return $results;
} | [
"private",
"function",
"iterateKeyReader",
"(",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"index",
"->",
"getKeyReader",
"(",
")",
"->",
"readKeys",
"(",
"$",
"this",
"->",
"offset",
",",
"$",
"this",
"->",
"direction",
",",
"$",
"this",
"->",
"parseHints",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"results",
")",
")",
"{",
"return",
"$",
"results",
";",
"}",
"// reverse order if iterating backwards",
"if",
"(",
"$",
"this",
"->",
"direction",
"==",
"KeyReader",
"::",
"DIRECTION_BACKWARD",
")",
"{",
"// $results = array_reverse($results);",
"// trim results to the offset and reverse the order",
"$",
"revertBackwardResults",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"->",
"getOffset",
"(",
")",
">",
"$",
"this",
"->",
"offset",
")",
"{",
"break",
";",
"}",
"array_unshift",
"(",
"$",
"revertBackwardResults",
",",
"$",
"result",
")",
";",
"}",
"$",
"results",
"=",
"$",
"revertBackwardResults",
";",
"}",
"// shift offset",
"$",
"end",
"=",
"end",
"(",
"$",
"results",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"direction",
")",
"{",
"case",
"KeyReader",
"::",
"DIRECTION_FORWARD",
":",
"$",
"this",
"->",
"setOffset",
"(",
"$",
"end",
"->",
"getOffset",
"(",
")",
"+",
"strlen",
"(",
"$",
"end",
"->",
"getData",
"(",
")",
")",
")",
";",
"break",
";",
"case",
"KeyReader",
"::",
"DIRECTION_BACKWARD",
":",
"$",
"this",
"->",
"setOffset",
"(",
"$",
"end",
"->",
"getOffset",
"(",
")",
"-",
"1",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"invalid direction\"",
")",
";",
"}",
"// remove duplicates (BACKWARD only)",
"$",
"this",
"->",
"avoidBackwardDuplicates",
"(",
"$",
"results",
")",
";",
"reset",
"(",
"$",
"results",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Iterates in the index and shifts the offset
@return Array | [
"Iterates",
"in",
"the",
"index",
"and",
"shifts",
"the",
"offset"
] | 6a6b476f1706b9524bfb34f6ce0963b1aea91259 | https://github.com/bmdevel/php-index/blob/6a6b476f1706b9524bfb34f6ce0963b1aea91259/classes/iterator/IndexIterator.php#L124-L176 |
338 | bmdevel/php-index | classes/iterator/IndexIterator.php | IndexIterator.avoidBackwardDuplicates | private function avoidBackwardDuplicates(array &$results)
{
// applies only on the last step of backward iteration
if ($this->direction == KeyReader::DIRECTION_FORWARD || $this->offset >= 0) {
return;
}
// get the minimum of the last iteration
$lastResults = $this->iterator->getArrayCopy();
if (empty($lastResults)) {
return;
}
$lastMinimum = end($lastResults)->getKey();
// reduce the results
$reducedResults = array();
foreach ($results as $result) {
if ($result->getKey() >= $lastMinimum) {
continue;
}
$reducedResults[] = $result;
}
$results = $reducedResults;
} | php | private function avoidBackwardDuplicates(array &$results)
{
// applies only on the last step of backward iteration
if ($this->direction == KeyReader::DIRECTION_FORWARD || $this->offset >= 0) {
return;
}
// get the minimum of the last iteration
$lastResults = $this->iterator->getArrayCopy();
if (empty($lastResults)) {
return;
}
$lastMinimum = end($lastResults)->getKey();
// reduce the results
$reducedResults = array();
foreach ($results as $result) {
if ($result->getKey() >= $lastMinimum) {
continue;
}
$reducedResults[] = $result;
}
$results = $reducedResults;
} | [
"private",
"function",
"avoidBackwardDuplicates",
"(",
"array",
"&",
"$",
"results",
")",
"{",
"// applies only on the last step of backward iteration",
"if",
"(",
"$",
"this",
"->",
"direction",
"==",
"KeyReader",
"::",
"DIRECTION_FORWARD",
"||",
"$",
"this",
"->",
"offset",
">=",
"0",
")",
"{",
"return",
";",
"}",
"// get the minimum of the last iteration",
"$",
"lastResults",
"=",
"$",
"this",
"->",
"iterator",
"->",
"getArrayCopy",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"lastResults",
")",
")",
"{",
"return",
";",
"}",
"$",
"lastMinimum",
"=",
"end",
"(",
"$",
"lastResults",
")",
"->",
"getKey",
"(",
")",
";",
"// reduce the results",
"$",
"reducedResults",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"->",
"getKey",
"(",
")",
">=",
"$",
"lastMinimum",
")",
"{",
"continue",
";",
"}",
"$",
"reducedResults",
"[",
"]",
"=",
"$",
"result",
";",
"}",
"$",
"results",
"=",
"$",
"reducedResults",
";",
"}"
] | Removes results which were found in the previous iteration.
This applies to backward iteration only | [
"Removes",
"results",
"which",
"were",
"found",
"in",
"the",
"previous",
"iteration",
"."
] | 6a6b476f1706b9524bfb34f6ce0963b1aea91259 | https://github.com/bmdevel/php-index/blob/6a6b476f1706b9524bfb34f6ce0963b1aea91259/classes/iterator/IndexIterator.php#L183-L210 |
339 | WellCommerce/DataGrid | Column/Options/Filter.php | Filter.prepareSelectValues | private function prepareSelectValues(array $values) : array
{
$options = [];
foreach ($values as $key => $value) {
$options[] = [
'id' => $key,
'caption' => $value,
];
}
return $options;
} | php | private function prepareSelectValues(array $values) : array
{
$options = [];
foreach ($values as $key => $value) {
$options[] = [
'id' => $key,
'caption' => $value,
];
}
return $options;
} | [
"private",
"function",
"prepareSelectValues",
"(",
"array",
"$",
"values",
")",
":",
"array",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"key",
",",
"'caption'",
"=>",
"$",
"value",
",",
"]",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | Prepares values to use in filter
@param array $values
@return array | [
"Prepares",
"values",
"to",
"use",
"in",
"filter"
] | 5ce3cd47c7902aaeb07c343a76574399286f56ff | https://github.com/WellCommerce/DataGrid/blob/5ce3cd47c7902aaeb07c343a76574399286f56ff/Column/Options/Filter.php#L95-L106 |
340 | praxisnetau/silverware-countries | src/Forms/CountryDropdownField.php | CountryDropdownField.getDefaultSource | public function getDefaultSource()
{
$source = i18n::getData()->getCountries();
$invalid = $this->config()->invalid_countries;
return array_filter($source, function ($code) use ($invalid) {
return !in_array($code, $invalid);
}, ARRAY_FILTER_USE_KEY);
} | php | public function getDefaultSource()
{
$source = i18n::getData()->getCountries();
$invalid = $this->config()->invalid_countries;
return array_filter($source, function ($code) use ($invalid) {
return !in_array($code, $invalid);
}, ARRAY_FILTER_USE_KEY);
} | [
"public",
"function",
"getDefaultSource",
"(",
")",
"{",
"$",
"source",
"=",
"i18n",
"::",
"getData",
"(",
")",
"->",
"getCountries",
"(",
")",
";",
"$",
"invalid",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"invalid_countries",
";",
"return",
"array_filter",
"(",
"$",
"source",
",",
"function",
"(",
"$",
"code",
")",
"use",
"(",
"$",
"invalid",
")",
"{",
"return",
"!",
"in_array",
"(",
"$",
"code",
",",
"$",
"invalid",
")",
";",
"}",
",",
"ARRAY_FILTER_USE_KEY",
")",
";",
"}"
] | Answers the default source options for the receiver.
@return array | [
"Answers",
"the",
"default",
"source",
"options",
"for",
"the",
"receiver",
"."
] | f0029706cfc15c133be1f93dc26c28bb6af1cac0 | https://github.com/praxisnetau/silverware-countries/blob/f0029706cfc15c133be1f93dc26c28bb6af1cac0/src/Forms/CountryDropdownField.php#L105-L113 |
341 | vinala/kernel | src/Objects/DateTime.php | DateTime.create | public static function create($year = null, $month = null, $day = null, $hour = null, $min = null, $second = null)
{
return Carbon::create($year, $month, $day, $hour, $min, $second);
} | php | public static function create($year = null, $month = null, $day = null, $hour = null, $min = null, $second = null)
{
return Carbon::create($year, $month, $day, $hour, $min, $second);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"hour",
"=",
"null",
",",
"$",
"min",
"=",
"null",
",",
"$",
"second",
"=",
"null",
")",
"{",
"return",
"Carbon",
"::",
"create",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"$",
"hour",
",",
"$",
"min",
",",
"$",
"second",
")",
";",
"}"
] | create new date. | [
"create",
"new",
"date",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Objects/DateTime.php#L72-L75 |
342 | php-rest-server/core | src/Core/Router.php | Router.getResult | protected function getResult($data)
{
if (is_array($data)) {
header('content-type: application/json');
return $this->cypher->encode(json_encode($data));
}
return $data;
} | php | protected function getResult($data)
{
if (is_array($data)) {
header('content-type: application/json');
return $this->cypher->encode(json_encode($data));
}
return $data;
} | [
"protected",
"function",
"getResult",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"header",
"(",
"'content-type: application/json'",
")",
";",
"return",
"$",
"this",
"->",
"cypher",
"->",
"encode",
"(",
"json_encode",
"(",
"$",
"data",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Encoding and cypher result
@param array|string $data
@return string | [
"Encoding",
"and",
"cypher",
"result"
] | 4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888 | https://github.com/php-rest-server/core/blob/4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888/src/Core/Router.php#L171-L179 |
343 | php-rest-server/core | src/Core/Router.php | Router.getRequestDataByMethod | protected function getRequestDataByMethod($method = HttpMethods::GET)
{
switch ($method) {
// POST method
case HttpMethods::POST:
$postData = array_merge($_GET, $_POST);
return $postData ?: [];
break;
// PUT method
case HttpMethods::PUT:
// PATH method
case HttpMethods::PATCH:
$data = $this->cypher->decode(file_get_contents('php://input'));
parse_str($data, $patchData);
$patchData = array_merge($_GET, $patchData);
return $patchData ?: [];
break;
// methods with empty payload
case HttpMethods::DELETE:
case HttpMethods::HEAD:
case HttpMethods::OPTIONS:
return [];
break;
// GET method (default)
case HttpMethods::GET:
default:
return $_GET;
break;
}
} | php | protected function getRequestDataByMethod($method = HttpMethods::GET)
{
switch ($method) {
// POST method
case HttpMethods::POST:
$postData = array_merge($_GET, $_POST);
return $postData ?: [];
break;
// PUT method
case HttpMethods::PUT:
// PATH method
case HttpMethods::PATCH:
$data = $this->cypher->decode(file_get_contents('php://input'));
parse_str($data, $patchData);
$patchData = array_merge($_GET, $patchData);
return $patchData ?: [];
break;
// methods with empty payload
case HttpMethods::DELETE:
case HttpMethods::HEAD:
case HttpMethods::OPTIONS:
return [];
break;
// GET method (default)
case HttpMethods::GET:
default:
return $_GET;
break;
}
} | [
"protected",
"function",
"getRequestDataByMethod",
"(",
"$",
"method",
"=",
"HttpMethods",
"::",
"GET",
")",
"{",
"switch",
"(",
"$",
"method",
")",
"{",
"// POST method",
"case",
"HttpMethods",
"::",
"POST",
":",
"$",
"postData",
"=",
"array_merge",
"(",
"$",
"_GET",
",",
"$",
"_POST",
")",
";",
"return",
"$",
"postData",
"?",
":",
"[",
"]",
";",
"break",
";",
"// PUT method",
"case",
"HttpMethods",
"::",
"PUT",
":",
"// PATH method",
"case",
"HttpMethods",
"::",
"PATCH",
":",
"$",
"data",
"=",
"$",
"this",
"->",
"cypher",
"->",
"decode",
"(",
"file_get_contents",
"(",
"'php://input'",
")",
")",
";",
"parse_str",
"(",
"$",
"data",
",",
"$",
"patchData",
")",
";",
"$",
"patchData",
"=",
"array_merge",
"(",
"$",
"_GET",
",",
"$",
"patchData",
")",
";",
"return",
"$",
"patchData",
"?",
":",
"[",
"]",
";",
"break",
";",
"// methods with empty payload",
"case",
"HttpMethods",
"::",
"DELETE",
":",
"case",
"HttpMethods",
"::",
"HEAD",
":",
"case",
"HttpMethods",
"::",
"OPTIONS",
":",
"return",
"[",
"]",
";",
"break",
";",
"// GET method (default)",
"case",
"HttpMethods",
"::",
"GET",
":",
"default",
":",
"return",
"$",
"_GET",
";",
"break",
";",
"}",
"}"
] | Returns the incoming array of parameters based on the type of the request
@param string $method
@return array | [
"Returns",
"the",
"incoming",
"array",
"of",
"parameters",
"based",
"on",
"the",
"type",
"of",
"the",
"request"
] | 4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888 | https://github.com/php-rest-server/core/blob/4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888/src/Core/Router.php#L210-L241 |
344 | php-rest-server/core | src/Core/Router.php | Router.getActionArguments | protected function getActionArguments($class, $action)
{
$method = new \ReflectionMethod($class, $action);
$this->action = $method;
$parameters = $method->getParameters();
$result = [];
foreach ($parameters as $parameter) {
$attribute = new ActionAttribute();
$attribute->name = $parameter->getName();
$attribute->isRequired = !$parameter->isDefaultValueAvailable();
if (!$attribute->isRequired) {
$attribute->defaultValue = $parameter->getDefaultValue();
}
$result[] = $attribute;
}
return $result;
} | php | protected function getActionArguments($class, $action)
{
$method = new \ReflectionMethod($class, $action);
$this->action = $method;
$parameters = $method->getParameters();
$result = [];
foreach ($parameters as $parameter) {
$attribute = new ActionAttribute();
$attribute->name = $parameter->getName();
$attribute->isRequired = !$parameter->isDefaultValueAvailable();
if (!$attribute->isRequired) {
$attribute->defaultValue = $parameter->getDefaultValue();
}
$result[] = $attribute;
}
return $result;
} | [
"protected",
"function",
"getActionArguments",
"(",
"$",
"class",
",",
"$",
"action",
")",
"{",
"$",
"method",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"action",
")",
";",
"$",
"this",
"->",
"action",
"=",
"$",
"method",
";",
"$",
"parameters",
"=",
"$",
"method",
"->",
"getParameters",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"$",
"attribute",
"=",
"new",
"ActionAttribute",
"(",
")",
";",
"$",
"attribute",
"->",
"name",
"=",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"$",
"attribute",
"->",
"isRequired",
"=",
"!",
"$",
"parameter",
"->",
"isDefaultValueAvailable",
"(",
")",
";",
"if",
"(",
"!",
"$",
"attribute",
"->",
"isRequired",
")",
"{",
"$",
"attribute",
"->",
"defaultValue",
"=",
"$",
"parameter",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"$",
"result",
"[",
"]",
"=",
"$",
"attribute",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | It goes through the parameters of the method and checks for the default value and requirement
@param string $class
@param string $action
@return ActionAttribute[]
@throws \ReflectionException | [
"It",
"goes",
"through",
"the",
"parameters",
"of",
"the",
"method",
"and",
"checks",
"for",
"the",
"default",
"value",
"and",
"requirement"
] | 4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888 | https://github.com/php-rest-server/core/blob/4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888/src/Core/Router.php#L252-L272 |
345 | php-rest-server/core | src/Core/Router.php | Router.callAction | protected function callAction(ControllerInterface $class, $action, $arguments, array $data)
{
if (null !== $this->action || $this->action->getName() !== $this->action) {
$this->action = new \ReflectionMethod($class, $action);
}
$params = [];
$dataBox = new Param($data);
foreach ($arguments as $argument) {
$params[$argument->name] = $dataBox->get($argument->name, $argument->defaultValue);
}
return $this->action->invokeArgs($class, $params);
} | php | protected function callAction(ControllerInterface $class, $action, $arguments, array $data)
{
if (null !== $this->action || $this->action->getName() !== $this->action) {
$this->action = new \ReflectionMethod($class, $action);
}
$params = [];
$dataBox = new Param($data);
foreach ($arguments as $argument) {
$params[$argument->name] = $dataBox->get($argument->name, $argument->defaultValue);
}
return $this->action->invokeArgs($class, $params);
} | [
"protected",
"function",
"callAction",
"(",
"ControllerInterface",
"$",
"class",
",",
"$",
"action",
",",
"$",
"arguments",
",",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"action",
"||",
"$",
"this",
"->",
"action",
"->",
"getName",
"(",
")",
"!==",
"$",
"this",
"->",
"action",
")",
"{",
"$",
"this",
"->",
"action",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"action",
")",
";",
"}",
"$",
"params",
"=",
"[",
"]",
";",
"$",
"dataBox",
"=",
"new",
"Param",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"argument",
")",
"{",
"$",
"params",
"[",
"$",
"argument",
"->",
"name",
"]",
"=",
"$",
"dataBox",
"->",
"get",
"(",
"$",
"argument",
"->",
"name",
",",
"$",
"argument",
"->",
"defaultValue",
")",
";",
"}",
"return",
"$",
"this",
"->",
"action",
"->",
"invokeArgs",
"(",
"$",
"class",
",",
"$",
"params",
")",
";",
"}"
] | Calling action with request data in params
@param ControllerInterface $class
@param string $action
@param ActionAttribute[] $arguments
@param array $data
@return array|string
@throws \ReflectionException | [
"Calling",
"action",
"with",
"request",
"data",
"in",
"params"
] | 4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888 | https://github.com/php-rest-server/core/blob/4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888/src/Core/Router.php#L285-L300 |
346 | php-rest-server/core | src/Core/Router.php | Router.getAllowedMethodsForRoute | protected function getAllowedMethodsForRoute(ControllerInterface $class, $action)
{
$actionsInfo = $class->getMethods();
if (isset($actionsInfo[$action])) {
$methods = implode(', ', $actionsInfo[$action]->getAllowedMethods());
$methodInfo = ReflectionHelper::getMethodInfo($class, $action);
header('Access-Control-Allow-Origin : *');
header('Access-Control-Allow-Methods : ' . $methods);
header('Access-Control-Allow-Headers : *');
return $methodInfo;
}
return [];
} | php | protected function getAllowedMethodsForRoute(ControllerInterface $class, $action)
{
$actionsInfo = $class->getMethods();
if (isset($actionsInfo[$action])) {
$methods = implode(', ', $actionsInfo[$action]->getAllowedMethods());
$methodInfo = ReflectionHelper::getMethodInfo($class, $action);
header('Access-Control-Allow-Origin : *');
header('Access-Control-Allow-Methods : ' . $methods);
header('Access-Control-Allow-Headers : *');
return $methodInfo;
}
return [];
} | [
"protected",
"function",
"getAllowedMethodsForRoute",
"(",
"ControllerInterface",
"$",
"class",
",",
"$",
"action",
")",
"{",
"$",
"actionsInfo",
"=",
"$",
"class",
"->",
"getMethods",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"actionsInfo",
"[",
"$",
"action",
"]",
")",
")",
"{",
"$",
"methods",
"=",
"implode",
"(",
"', '",
",",
"$",
"actionsInfo",
"[",
"$",
"action",
"]",
"->",
"getAllowedMethods",
"(",
")",
")",
";",
"$",
"methodInfo",
"=",
"ReflectionHelper",
"::",
"getMethodInfo",
"(",
"$",
"class",
",",
"$",
"action",
")",
";",
"header",
"(",
"'Access-Control-Allow-Origin : *'",
")",
";",
"header",
"(",
"'Access-Control-Allow-Methods : '",
".",
"$",
"methods",
")",
";",
"header",
"(",
"'Access-Control-Allow-Headers : *'",
")",
";",
"return",
"$",
"methodInfo",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Return action description and set headers to output
@param ControllerInterface $class
@param string $action
@return array | [
"Return",
"action",
"description",
"and",
"set",
"headers",
"to",
"output"
] | 4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888 | https://github.com/php-rest-server/core/blob/4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888/src/Core/Router.php#L310-L326 |
347 | jmpantoja/planb-utils | src/DS/Queue/Queue.php | Queue.typed | public static function typed(string $type, iterable $input = []): Queue
{
$resolver = Resolver::typed($type);
return new static($input, $resolver);
} | php | public static function typed(string $type, iterable $input = []): Queue
{
$resolver = Resolver::typed($type);
return new static($input, $resolver);
} | [
"public",
"static",
"function",
"typed",
"(",
"string",
"$",
"type",
",",
"iterable",
"$",
"input",
"=",
"[",
"]",
")",
":",
"Queue",
"{",
"$",
"resolver",
"=",
"Resolver",
"::",
"typed",
"(",
"$",
"type",
")",
";",
"return",
"new",
"static",
"(",
"$",
"input",
",",
"$",
"resolver",
")",
";",
"}"
] | Queue named constructor.
@param string $type
@param mixed[] $input
@return \PlanB\DS\Queue\Queue | [
"Queue",
"named",
"constructor",
"."
] | d17fbced4a285275928f8428ee56e269eb851690 | https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/DS/Queue/Queue.php#L45-L50 |
348 | konservs/brilliant.framework | components/users/models/register.php | Model_users_register.getData | public function getData($segments) {
$data = new stdClass;
$data->errors = array();
$data->email = BRequest::getString('email');
$data->name = BRequest::getString('name');
$data->password = BRequest::getString('password');
$data->result = false;
$data->do = BRequest::getString('do');
if ($data->do == 'register') {
//Validation
if (empty($data->name)) {
$data->errors['name'] = 'Could not';
return $data;
}
//
if (strlen($data->password) < 6) {
$data->errors['password'] = 'Password length < 6 chars';
return $data;
}
$user = new BUser();
$user->name = $data->name;
$user->email = $data->email;
$user->setpassword($data->password);
$r = $user->saveToDB();
if (!empty($r)) {
$data->errors = $r;
}
if ($r === true) {
$data->result = true;
$data->errors = array();
}
}
return $data;
} | php | public function getData($segments) {
$data = new stdClass;
$data->errors = array();
$data->email = BRequest::getString('email');
$data->name = BRequest::getString('name');
$data->password = BRequest::getString('password');
$data->result = false;
$data->do = BRequest::getString('do');
if ($data->do == 'register') {
//Validation
if (empty($data->name)) {
$data->errors['name'] = 'Could not';
return $data;
}
//
if (strlen($data->password) < 6) {
$data->errors['password'] = 'Password length < 6 chars';
return $data;
}
$user = new BUser();
$user->name = $data->name;
$user->email = $data->email;
$user->setpassword($data->password);
$r = $user->saveToDB();
if (!empty($r)) {
$data->errors = $r;
}
if ($r === true) {
$data->result = true;
$data->errors = array();
}
}
return $data;
} | [
"public",
"function",
"getData",
"(",
"$",
"segments",
")",
"{",
"$",
"data",
"=",
"new",
"stdClass",
";",
"$",
"data",
"->",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"data",
"->",
"email",
"=",
"BRequest",
"::",
"getString",
"(",
"'email'",
")",
";",
"$",
"data",
"->",
"name",
"=",
"BRequest",
"::",
"getString",
"(",
"'name'",
")",
";",
"$",
"data",
"->",
"password",
"=",
"BRequest",
"::",
"getString",
"(",
"'password'",
")",
";",
"$",
"data",
"->",
"result",
"=",
"false",
";",
"$",
"data",
"->",
"do",
"=",
"BRequest",
"::",
"getString",
"(",
"'do'",
")",
";",
"if",
"(",
"$",
"data",
"->",
"do",
"==",
"'register'",
")",
"{",
"//Validation",
"if",
"(",
"empty",
"(",
"$",
"data",
"->",
"name",
")",
")",
"{",
"$",
"data",
"->",
"errors",
"[",
"'name'",
"]",
"=",
"'Could not'",
";",
"return",
"$",
"data",
";",
"}",
"//",
"if",
"(",
"strlen",
"(",
"$",
"data",
"->",
"password",
")",
"<",
"6",
")",
"{",
"$",
"data",
"->",
"errors",
"[",
"'password'",
"]",
"=",
"'Password length < 6 chars'",
";",
"return",
"$",
"data",
";",
"}",
"$",
"user",
"=",
"new",
"BUser",
"(",
")",
";",
"$",
"user",
"->",
"name",
"=",
"$",
"data",
"->",
"name",
";",
"$",
"user",
"->",
"email",
"=",
"$",
"data",
"->",
"email",
";",
"$",
"user",
"->",
"setpassword",
"(",
"$",
"data",
"->",
"password",
")",
";",
"$",
"r",
"=",
"$",
"user",
"->",
"saveToDB",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"r",
")",
")",
"{",
"$",
"data",
"->",
"errors",
"=",
"$",
"r",
";",
"}",
"if",
"(",
"$",
"r",
"===",
"true",
")",
"{",
"$",
"data",
"->",
"result",
"=",
"true",
";",
"$",
"data",
"->",
"errors",
"=",
"array",
"(",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Get Data and try to registar user, if need.
@param $segments
@return stdClass | [
"Get",
"Data",
"and",
"try",
"to",
"registar",
"user",
"if",
"need",
"."
] | 95f03f1917f746fee98bea8a906ba0588c87762d | https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/components/users/models/register.php#L20-L54 |
349 | wpplex/wp-notify | WP_Notify.php | WP_Notify.callback_dismiss_notification | public function callback_dismiss_notification() {
if ( isset( $_POST['namespace'] ) || isset( $_POST['id'] ) ) {
$namespace = $_POST['namespace'];
$id = $_POST['id'];
$n_class = get_class();
$notify = new $n_class( $namespace );
$notify->hide_notification( $id );
}
exit;
} | php | public function callback_dismiss_notification() {
if ( isset( $_POST['namespace'] ) || isset( $_POST['id'] ) ) {
$namespace = $_POST['namespace'];
$id = $_POST['id'];
$n_class = get_class();
$notify = new $n_class( $namespace );
$notify->hide_notification( $id );
}
exit;
} | [
"public",
"function",
"callback_dismiss_notification",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'namespace'",
"]",
")",
"||",
"isset",
"(",
"$",
"_POST",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"namespace",
"=",
"$",
"_POST",
"[",
"'namespace'",
"]",
";",
"$",
"id",
"=",
"$",
"_POST",
"[",
"'id'",
"]",
";",
"$",
"n_class",
"=",
"get_class",
"(",
")",
";",
"$",
"notify",
"=",
"new",
"$",
"n_class",
"(",
"$",
"namespace",
")",
";",
"$",
"notify",
"->",
"hide_notification",
"(",
"$",
"id",
")",
";",
"}",
"exit",
";",
"}"
] | Callback to handle dismiss button AJAX request
@return void | [
"Callback",
"to",
"handle",
"dismiss",
"button",
"AJAX",
"request"
] | 7bf235e7fe69b9bcda1591cc93559f081f6703a6 | https://github.com/wpplex/wp-notify/blob/7bf235e7fe69b9bcda1591cc93559f081f6703a6/WP_Notify.php#L75-L85 |
350 | wpplex/wp-notify | WP_Notify.php | WP_Notify.load_notices | private function load_notices() {
$notices = get_option( 'wp_easy_notify_' . $this->prefix, array() );
$this->notices = $notices;
$active = get_option( 'wp_easy_notify_active_' . $this->prefix, array() );
$this->active = $active;
} | php | private function load_notices() {
$notices = get_option( 'wp_easy_notify_' . $this->prefix, array() );
$this->notices = $notices;
$active = get_option( 'wp_easy_notify_active_' . $this->prefix, array() );
$this->active = $active;
} | [
"private",
"function",
"load_notices",
"(",
")",
"{",
"$",
"notices",
"=",
"get_option",
"(",
"'wp_easy_notify_'",
".",
"$",
"this",
"->",
"prefix",
",",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"notices",
"=",
"$",
"notices",
";",
"$",
"active",
"=",
"get_option",
"(",
"'wp_easy_notify_active_'",
".",
"$",
"this",
"->",
"prefix",
",",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"active",
"=",
"$",
"active",
";",
"}"
] | Load all notices into the class.
@return void | [
"Load",
"all",
"notices",
"into",
"the",
"class",
"."
] | 7bf235e7fe69b9bcda1591cc93559f081f6703a6 | https://github.com/wpplex/wp-notify/blob/7bf235e7fe69b9bcda1591cc93559f081f6703a6/WP_Notify.php#L92-L98 |
351 | wpplex/wp-notify | WP_Notify.php | WP_Notify.display_notices | public function display_notices() {
// Go through all notices
foreach( $this->active as $id=>$count ) {
// If there is a call-able function, execute it
if ( is_callable( $this->notices[$id]['cond_func'] ) ) {
$cond = call_user_func( $this->notices[$id]['cond_func'] );
} else {
$cond = true;
}
// Print the notification
if ( $cond ) {
$this->print_notification( $this->notices[$id] );
}
// If only 1 count is available, unset the notice
if ( $count === 1 ) {
unset( $this->active[$id] );
}
// Decrease the notice counts
if ( $count > 1 ) {
$this->active[$id] = $count - 1;
}
}
$this->save();
} | php | public function display_notices() {
// Go through all notices
foreach( $this->active as $id=>$count ) {
// If there is a call-able function, execute it
if ( is_callable( $this->notices[$id]['cond_func'] ) ) {
$cond = call_user_func( $this->notices[$id]['cond_func'] );
} else {
$cond = true;
}
// Print the notification
if ( $cond ) {
$this->print_notification( $this->notices[$id] );
}
// If only 1 count is available, unset the notice
if ( $count === 1 ) {
unset( $this->active[$id] );
}
// Decrease the notice counts
if ( $count > 1 ) {
$this->active[$id] = $count - 1;
}
}
$this->save();
} | [
"public",
"function",
"display_notices",
"(",
")",
"{",
"// Go through all notices",
"foreach",
"(",
"$",
"this",
"->",
"active",
"as",
"$",
"id",
"=>",
"$",
"count",
")",
"{",
"// If there is a call-able function, execute it",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
"[",
"'cond_func'",
"]",
")",
")",
"{",
"$",
"cond",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
"[",
"'cond_func'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"cond",
"=",
"true",
";",
"}",
"// Print the notification",
"if",
"(",
"$",
"cond",
")",
"{",
"$",
"this",
"->",
"print_notification",
"(",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
")",
";",
"}",
"// If only 1 count is available, unset the notice",
"if",
"(",
"$",
"count",
"===",
"1",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"active",
"[",
"$",
"id",
"]",
")",
";",
"}",
"// Decrease the notice counts",
"if",
"(",
"$",
"count",
">",
"1",
")",
"{",
"$",
"this",
"->",
"active",
"[",
"$",
"id",
"]",
"=",
"$",
"count",
"-",
"1",
";",
"}",
"}",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Display the notices.
@return void | [
"Display",
"the",
"notices",
"."
] | 7bf235e7fe69b9bcda1591cc93559f081f6703a6 | https://github.com/wpplex/wp-notify/blob/7bf235e7fe69b9bcda1591cc93559f081f6703a6/WP_Notify.php#L105-L133 |
352 | wpplex/wp-notify | WP_Notify.php | WP_Notify.print_notification | private function print_notification( $notice ) {
do_action( 'easy_notifications_before_notice', $notice );
echo '<div class="updated '.$notice['type'].'">
' . $notice['content'] . '
<a href="#" class="dismiss-notice"
data-namespace="' . $this->prefix . '"
data-noticeid="' . $notice['id'] . '"
>Dismiss Notification</a>
</div>';
do_action( 'easy_notifications_after_notice', $notice );
} | php | private function print_notification( $notice ) {
do_action( 'easy_notifications_before_notice', $notice );
echo '<div class="updated '.$notice['type'].'">
' . $notice['content'] . '
<a href="#" class="dismiss-notice"
data-namespace="' . $this->prefix . '"
data-noticeid="' . $notice['id'] . '"
>Dismiss Notification</a>
</div>';
do_action( 'easy_notifications_after_notice', $notice );
} | [
"private",
"function",
"print_notification",
"(",
"$",
"notice",
")",
"{",
"do_action",
"(",
"'easy_notifications_before_notice'",
",",
"$",
"notice",
")",
";",
"echo",
"'<div class=\"updated '",
".",
"$",
"notice",
"[",
"'type'",
"]",
".",
"'\">\n '",
".",
"$",
"notice",
"[",
"'content'",
"]",
".",
"' \n\n <a href=\"#\" class=\"dismiss-notice\" \n data-namespace=\"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'\" \n data-noticeid=\"'",
".",
"$",
"notice",
"[",
"'id'",
"]",
".",
"'\"\n >Dismiss Notification</a>\n </div>'",
";",
"do_action",
"(",
"'easy_notifications_after_notice'",
",",
"$",
"notice",
")",
";",
"}"
] | Print a notification to the current Page.
@param array $notice
@return void | [
"Print",
"a",
"notification",
"to",
"the",
"current",
"Page",
"."
] | 7bf235e7fe69b9bcda1591cc93559f081f6703a6 | https://github.com/wpplex/wp-notify/blob/7bf235e7fe69b9bcda1591cc93559f081f6703a6/WP_Notify.php#L141-L154 |
353 | wpplex/wp-notify | WP_Notify.php | WP_Notify.save | private function save() {
update_option( 'wp_easy_notify_' . $this->prefix, $this->notices );
update_option( 'wp_easy_notify_active_' . $this->prefix, $this->active );
} | php | private function save() {
update_option( 'wp_easy_notify_' . $this->prefix, $this->notices );
update_option( 'wp_easy_notify_active_' . $this->prefix, $this->active );
} | [
"private",
"function",
"save",
"(",
")",
"{",
"update_option",
"(",
"'wp_easy_notify_'",
".",
"$",
"this",
"->",
"prefix",
",",
"$",
"this",
"->",
"notices",
")",
";",
"update_option",
"(",
"'wp_easy_notify_active_'",
".",
"$",
"this",
"->",
"prefix",
",",
"$",
"this",
"->",
"active",
")",
";",
"}"
] | Save the class data to Database.
@return void | [
"Save",
"the",
"class",
"data",
"to",
"Database",
"."
] | 7bf235e7fe69b9bcda1591cc93559f081f6703a6 | https://github.com/wpplex/wp-notify/blob/7bf235e7fe69b9bcda1591cc93559f081f6703a6/WP_Notify.php#L161-L164 |
354 | wpplex/wp-notify | WP_Notify.php | WP_Notify.add_notification | public function add_notification( $id, $content, $type = null, $hide_button = null, $cond_func = null ) {
if ( isset( $this->notices[$id] ) ) {
return false;
}
if ( !$type ) {
$type = 'success';
}
if ( !$hide_button ) {
$hide_button = true;
}
if ( !$cond_func ) {
$cond_func = false;
}
$this->notices[$id] = array(
'id' => $id,
'content' => $content,
'type' => $type,
'hide_button' => $hide_button,
'cond_func' => $cond_func,
);
$this->save();
} | php | public function add_notification( $id, $content, $type = null, $hide_button = null, $cond_func = null ) {
if ( isset( $this->notices[$id] ) ) {
return false;
}
if ( !$type ) {
$type = 'success';
}
if ( !$hide_button ) {
$hide_button = true;
}
if ( !$cond_func ) {
$cond_func = false;
}
$this->notices[$id] = array(
'id' => $id,
'content' => $content,
'type' => $type,
'hide_button' => $hide_button,
'cond_func' => $cond_func,
);
$this->save();
} | [
"public",
"function",
"add_notification",
"(",
"$",
"id",
",",
"$",
"content",
",",
"$",
"type",
"=",
"null",
",",
"$",
"hide_button",
"=",
"null",
",",
"$",
"cond_func",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"'success'",
";",
"}",
"if",
"(",
"!",
"$",
"hide_button",
")",
"{",
"$",
"hide_button",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"cond_func",
")",
"{",
"$",
"cond_func",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'content'",
"=>",
"$",
"content",
",",
"'type'",
"=>",
"$",
"type",
",",
"'hide_button'",
"=>",
"$",
"hide_button",
",",
"'cond_func'",
"=>",
"$",
"cond_func",
",",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Add a notification to the notices namespace.
@param string $id
@param string $content
@param string $type
@param bool $hide_button
@return void|bool | [
"Add",
"a",
"notification",
"to",
"the",
"notices",
"namespace",
"."
] | 7bf235e7fe69b9bcda1591cc93559f081f6703a6 | https://github.com/wpplex/wp-notify/blob/7bf235e7fe69b9bcda1591cc93559f081f6703a6/WP_Notify.php#L176-L202 |
355 | wpplex/wp-notify | WP_Notify.php | WP_Notify.update_notification | public function update_notification( $id, $content = null, $type = null, $hide_button = null, $cond_func = null ) {
if ( ! isset( $this->notices[$id] ) ) {
$this->add_notification( $id, $content, $type, $hide_button, $cond_func );
}
if ( $content ) {
$this->notices[$id]['content'] = $content;
}
if ( $type ) {
$this->notices[$id]['type'] = $type;
}
if ( $hide_button ) {
$this->notices[$id]['hide_button'] = $hide_button;
}
if ( $cond_func ) {
$this->notices[$id]['cond_func'] = $cond_func;
}
$this->save();
} | php | public function update_notification( $id, $content = null, $type = null, $hide_button = null, $cond_func = null ) {
if ( ! isset( $this->notices[$id] ) ) {
$this->add_notification( $id, $content, $type, $hide_button, $cond_func );
}
if ( $content ) {
$this->notices[$id]['content'] = $content;
}
if ( $type ) {
$this->notices[$id]['type'] = $type;
}
if ( $hide_button ) {
$this->notices[$id]['hide_button'] = $hide_button;
}
if ( $cond_func ) {
$this->notices[$id]['cond_func'] = $cond_func;
}
$this->save();
} | [
"public",
"function",
"update_notification",
"(",
"$",
"id",
",",
"$",
"content",
"=",
"null",
",",
"$",
"type",
"=",
"null",
",",
"$",
"hide_button",
"=",
"null",
",",
"$",
"cond_func",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"add_notification",
"(",
"$",
"id",
",",
"$",
"content",
",",
"$",
"type",
",",
"$",
"hide_button",
",",
"$",
"cond_func",
")",
";",
"}",
"if",
"(",
"$",
"content",
")",
"{",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
"[",
"'content'",
"]",
"=",
"$",
"content",
";",
"}",
"if",
"(",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
"[",
"'type'",
"]",
"=",
"$",
"type",
";",
"}",
"if",
"(",
"$",
"hide_button",
")",
"{",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
"[",
"'hide_button'",
"]",
"=",
"$",
"hide_button",
";",
"}",
"if",
"(",
"$",
"cond_func",
")",
"{",
"$",
"this",
"->",
"notices",
"[",
"$",
"id",
"]",
"[",
"'cond_func'",
"]",
"=",
"$",
"cond_func",
";",
"}",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Update a notification configuration.
@param string $id
@param string $content
@param string $type
@param bool $hide_button
@return void | [
"Update",
"a",
"notification",
"configuration",
"."
] | 7bf235e7fe69b9bcda1591cc93559f081f6703a6 | https://github.com/wpplex/wp-notify/blob/7bf235e7fe69b9bcda1591cc93559f081f6703a6/WP_Notify.php#L214-L236 |
356 | samurai-fw/samurai | src/Console/Controller/Controller.php | Controller.send | public function send()
{
$args = func_get_args();
if (count($args) > 1) {
$message = call_user_func_array('sprintf', $args);
} else {
$message = $args[0];
}
$this->response->send($message);
} | php | public function send()
{
$args = func_get_args();
if (count($args) > 1) {
$message = call_user_func_array('sprintf', $args);
} else {
$message = $args[0];
}
$this->response->send($message);
} | [
"public",
"function",
"send",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"1",
")",
"{",
"$",
"message",
"=",
"call_user_func_array",
"(",
"'sprintf'",
",",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"$",
"message",
")",
";",
"}"
] | implements for task output.
@access public | [
"implements",
"for",
"task",
"output",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Console/Controller/Controller.php#L53-L62 |
357 | samurai-fw/samurai | src/Console/Controller/Controller.php | Controller.isUsage | public function isUsage()
{
$options = array('help', 'usage', 'option.h');
foreach ($options as $option) {
if ($this->request->get($option)) return true;
}
return false;
} | php | public function isUsage()
{
$options = array('help', 'usage', 'option.h');
foreach ($options as $option) {
if ($this->request->get($option)) return true;
}
return false;
} | [
"public",
"function",
"isUsage",
"(",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'help'",
",",
"'usage'",
",",
"'option.h'",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"get",
"(",
"$",
"option",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | is usage ?
usage options:
--help
--usage
--h
@access public
@return boolean | [
"is",
"usage",
"?"
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Console/Controller/Controller.php#L77-L84 |
358 | crisu83/yii-multilingual | behaviors/MlApplicationBehavior.php | MlApplicationBehavior.setLanguage | protected function setLanguage()
{
$matches = array();
if ($this->owner->user->hasState('__locale'))
$language = $this->owner->user->getState('__locale');
else if (preg_match('/^\/([a-z]{2}(?:_[a-z]{2})?)\//i',
substr($this->owner->request->url, strlen($this->owner->baseUrl)), $matches) !== false
&& isset($matches[1], $this->languages[$matches[1]]))
$language = $matches[1];
else
$language = $this->defaultLanguage;
$this->owner->language = $language;
} | php | protected function setLanguage()
{
$matches = array();
if ($this->owner->user->hasState('__locale'))
$language = $this->owner->user->getState('__locale');
else if (preg_match('/^\/([a-z]{2}(?:_[a-z]{2})?)\//i',
substr($this->owner->request->url, strlen($this->owner->baseUrl)), $matches) !== false
&& isset($matches[1], $this->languages[$matches[1]]))
$language = $matches[1];
else
$language = $this->defaultLanguage;
$this->owner->language = $language;
} | [
"protected",
"function",
"setLanguage",
"(",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"user",
"->",
"hasState",
"(",
"'__locale'",
")",
")",
"$",
"language",
"=",
"$",
"this",
"->",
"owner",
"->",
"user",
"->",
"getState",
"(",
"'__locale'",
")",
";",
"else",
"if",
"(",
"preg_match",
"(",
"'/^\\/([a-z]{2}(?:_[a-z]{2})?)\\//i'",
",",
"substr",
"(",
"$",
"this",
"->",
"owner",
"->",
"request",
"->",
"url",
",",
"strlen",
"(",
"$",
"this",
"->",
"owner",
"->",
"baseUrl",
")",
")",
",",
"$",
"matches",
")",
"!==",
"false",
"&&",
"isset",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"this",
"->",
"languages",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
")",
")",
"$",
"language",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"else",
"$",
"language",
"=",
"$",
"this",
"->",
"defaultLanguage",
";",
"$",
"this",
"->",
"owner",
"->",
"language",
"=",
"$",
"language",
";",
"}"
] | Sets the application language from a user state if applicable. | [
"Sets",
"the",
"application",
"language",
"from",
"a",
"user",
"state",
"if",
"applicable",
"."
] | 85f9bcf6c76718a8cbeb599a08010c1bd4494e66 | https://github.com/crisu83/yii-multilingual/blob/85f9bcf6c76718a8cbeb599a08010c1bd4494e66/behaviors/MlApplicationBehavior.php#L36-L49 |
359 | consigliere/components | src/Traits/ComponentCommandTrait.php | ComponentCommandTrait.getComponentName | public function getComponentName()
{
$component = $this->argument('component') ?: app('components')->getUsedNow();
$component = app('components')->findOrFail($component);
return $component->getStudlyName();
} | php | public function getComponentName()
{
$component = $this->argument('component') ?: app('components')->getUsedNow();
$component = app('components')->findOrFail($component);
return $component->getStudlyName();
} | [
"public",
"function",
"getComponentName",
"(",
")",
"{",
"$",
"component",
"=",
"$",
"this",
"->",
"argument",
"(",
"'component'",
")",
"?",
":",
"app",
"(",
"'components'",
")",
"->",
"getUsedNow",
"(",
")",
";",
"$",
"component",
"=",
"app",
"(",
"'components'",
")",
"->",
"findOrFail",
"(",
"$",
"component",
")",
";",
"return",
"$",
"component",
"->",
"getStudlyName",
"(",
")",
";",
"}"
] | Get the component name.
@return string | [
"Get",
"the",
"component",
"name",
"."
] | 9b08bb111f0b55b0a860ed9c3407eda0d9cc1252 | https://github.com/consigliere/components/blob/9b08bb111f0b55b0a860ed9c3407eda0d9cc1252/src/Traits/ComponentCommandTrait.php#L12-L19 |
360 | easy-system/es-debug | src/Debug.php | Debug.registerDump | protected static function registerDump($representation, $backtrace)
{
$dump = new Dump($representation, $backtrace[0]['file'], $backtrace[0]['line']);
static::$instances[] = $dump;
return $dump;
} | php | protected static function registerDump($representation, $backtrace)
{
$dump = new Dump($representation, $backtrace[0]['file'], $backtrace[0]['line']);
static::$instances[] = $dump;
return $dump;
} | [
"protected",
"static",
"function",
"registerDump",
"(",
"$",
"representation",
",",
"$",
"backtrace",
")",
"{",
"$",
"dump",
"=",
"new",
"Dump",
"(",
"$",
"representation",
",",
"$",
"backtrace",
"[",
"0",
"]",
"[",
"'file'",
"]",
",",
"$",
"backtrace",
"[",
"0",
"]",
"[",
"'line'",
"]",
")",
";",
"static",
"::",
"$",
"instances",
"[",
"]",
"=",
"$",
"dump",
";",
"return",
"$",
"dump",
";",
"}"
] | Registers a dump.
@param string $representation The string representation of dump
@param array $backtrace The backtrace
@return Dump The instance of dump | [
"Registers",
"a",
"dump",
"."
] | 30c6dfd4f062f435006905bcf1482af8f6c0c0ca | https://github.com/easy-system/es-debug/blob/30c6dfd4f062f435006905bcf1482af8f6c0c0ca/src/Debug.php#L60-L67 |
361 | WellCommerce/DataGrid | Configuration/EventHandler/AbstractEventHandler.php | AbstractEventHandler.get | public function get(string $option)
{
if (!isset($this->options[$option])) {
throw new \InvalidArgumentException(sprintf('Option "%s" does not exists.', $option));
}
return $this->options[$option];
} | php | public function get(string $option)
{
if (!isset($this->options[$option])) {
throw new \InvalidArgumentException(sprintf('Option "%s" does not exists.', $option));
}
return $this->options[$option];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Option \"%s\" does not exists.'",
",",
"$",
"option",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
";",
"}"
] | Returns options value by its name
@param string $option
@return mixed
@throws \InvalidArgumentException | [
"Returns",
"options",
"value",
"by",
"its",
"name"
] | 5ce3cd47c7902aaeb07c343a76574399286f56ff | https://github.com/WellCommerce/DataGrid/blob/5ce3cd47c7902aaeb07c343a76574399286f56ff/Configuration/EventHandler/AbstractEventHandler.php#L66-L73 |
362 | zepi/turbo-base | Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php | LayoutAbstract.validateFormData | public function validateFormData(WebRequest $request, Response $response, callable $callback = null)
{
$form = $this->searchSubmittedForm($request, $response);
if ($form === null) {
return Form::NOT_SUBMITTED;
}
// Validate the data
$errors = $form->validateFormData($this->framework);
// Execute the custom validation method
if (is_callable($callback)) {
$callbackErrors = call_user_func_array($callback, array($this->getFormValues()));
if (is_array($callbackErrors)) {
$errors = array_merge($errors, $callbackErrors);
}
}
if (is_array($errors) && count($errors) > 0) {
$this->updateErrorBox($form, $errors);
return Form::DATA_INVALID;
}
return Form::DATA_VALID;
} | php | public function validateFormData(WebRequest $request, Response $response, callable $callback = null)
{
$form = $this->searchSubmittedForm($request, $response);
if ($form === null) {
return Form::NOT_SUBMITTED;
}
// Validate the data
$errors = $form->validateFormData($this->framework);
// Execute the custom validation method
if (is_callable($callback)) {
$callbackErrors = call_user_func_array($callback, array($this->getFormValues()));
if (is_array($callbackErrors)) {
$errors = array_merge($errors, $callbackErrors);
}
}
if (is_array($errors) && count($errors) > 0) {
$this->updateErrorBox($form, $errors);
return Form::DATA_INVALID;
}
return Form::DATA_VALID;
} | [
"public",
"function",
"validateFormData",
"(",
"WebRequest",
"$",
"request",
",",
"Response",
"$",
"response",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"searchSubmittedForm",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"if",
"(",
"$",
"form",
"===",
"null",
")",
"{",
"return",
"Form",
"::",
"NOT_SUBMITTED",
";",
"}",
"// Validate the data",
"$",
"errors",
"=",
"$",
"form",
"->",
"validateFormData",
"(",
"$",
"this",
"->",
"framework",
")",
";",
"// Execute the custom validation method",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"callbackErrors",
"=",
"call_user_func_array",
"(",
"$",
"callback",
",",
"array",
"(",
"$",
"this",
"->",
"getFormValues",
"(",
")",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"callbackErrors",
")",
")",
"{",
"$",
"errors",
"=",
"array_merge",
"(",
"$",
"errors",
",",
"$",
"callbackErrors",
")",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"errors",
")",
"&&",
"count",
"(",
"$",
"errors",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"updateErrorBox",
"(",
"$",
"form",
",",
"$",
"errors",
")",
";",
"return",
"Form",
"::",
"DATA_INVALID",
";",
"}",
"return",
"Form",
"::",
"DATA_VALID",
";",
"}"
] | Searches the submitted Form object in the layout and validates the data
@param \Zepi\Turbo\Request\WebRequest $request
@param \Zepi\Turbo\Response\Response $response
@param callable $callback
@return string | [
"Searches",
"the",
"submitted",
"Form",
"object",
"in",
"the",
"layout",
"and",
"validates",
"the",
"data"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php#L119-L145 |
363 | zepi/turbo-base | Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php | LayoutAbstract.searchSubmittedForm | protected function searchSubmittedForm(WebRequest $request, Response $response)
{
$this->verifyLayout();
$form = null;
foreach ($this->layout->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Form', true) as $availableForm) {
$availableForm->processFormData($request, $response);
if ($availableForm->isSubmitted()) {
$form = $availableForm;
break;
}
}
return $form;
} | php | protected function searchSubmittedForm(WebRequest $request, Response $response)
{
$this->verifyLayout();
$form = null;
foreach ($this->layout->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Form', true) as $availableForm) {
$availableForm->processFormData($request, $response);
if ($availableForm->isSubmitted()) {
$form = $availableForm;
break;
}
}
return $form;
} | [
"protected",
"function",
"searchSubmittedForm",
"(",
"WebRequest",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"verifyLayout",
"(",
")",
";",
"$",
"form",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"layout",
"->",
"getChildrenByType",
"(",
"'\\\\Zepi\\\\Web\\\\UserInterface\\\\Form\\\\Form'",
",",
"true",
")",
"as",
"$",
"availableForm",
")",
"{",
"$",
"availableForm",
"->",
"processFormData",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"if",
"(",
"$",
"availableForm",
"->",
"isSubmitted",
"(",
")",
")",
"{",
"$",
"form",
"=",
"$",
"availableForm",
";",
"break",
";",
"}",
"}",
"return",
"$",
"form",
";",
"}"
] | Searches the submitted form object in the layout.
@param \Zepi\Turbo\Request\WebRequest $request
@param \Zepi\Turbo\Response\Response $response
@return null|\Zepi\Web\UserInterface\Form\Form | [
"Searches",
"the",
"submitted",
"form",
"object",
"in",
"the",
"layout",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php#L154-L169 |
364 | zepi/turbo-base | Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php | LayoutAbstract.updateErrorBox | protected function updateErrorBox(Form $form, $errors)
{
foreach ($form->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\ErrorBox', true) as $errorBox) {
$errorBox->updateErrorBox($form, false, $errors);
}
} | php | protected function updateErrorBox(Form $form, $errors)
{
foreach ($form->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\ErrorBox', true) as $errorBox) {
$errorBox->updateErrorBox($form, false, $errors);
}
} | [
"protected",
"function",
"updateErrorBox",
"(",
"Form",
"$",
"form",
",",
"$",
"errors",
")",
"{",
"foreach",
"(",
"$",
"form",
"->",
"getChildrenByType",
"(",
"'\\\\Zepi\\\\Web\\\\UserInterface\\\\Form\\\\ErrorBox'",
",",
"true",
")",
"as",
"$",
"errorBox",
")",
"{",
"$",
"errorBox",
"->",
"updateErrorBox",
"(",
"$",
"form",
",",
"false",
",",
"$",
"errors",
")",
";",
"}",
"}"
] | Updates all error boxes inside the given form
@param \Zepi\Web\UserInterface\Form\Form $form
@param array $errors | [
"Updates",
"all",
"error",
"boxes",
"inside",
"the",
"given",
"form"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php#L177-L182 |
365 | zepi/turbo-base | Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php | LayoutAbstract.getFormValues | public function getFormValues()
{
$this->verifyLayout();
$values = array();
foreach ($this->layout->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Form', true) as $form) {
$values = $this->extractFormValues($form);
}
return $values;
} | php | public function getFormValues()
{
$this->verifyLayout();
$values = array();
foreach ($this->layout->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Form', true) as $form) {
$values = $this->extractFormValues($form);
}
return $values;
} | [
"public",
"function",
"getFormValues",
"(",
")",
"{",
"$",
"this",
"->",
"verifyLayout",
"(",
")",
";",
"$",
"values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"layout",
"->",
"getChildrenByType",
"(",
"'\\\\Zepi\\\\Web\\\\UserInterface\\\\Form\\\\Form'",
",",
"true",
")",
"as",
"$",
"form",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"extractFormValues",
"(",
"$",
"form",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Returns all the values of the form fields
@return array | [
"Returns",
"all",
"the",
"values",
"of",
"the",
"form",
"fields"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php#L189-L200 |
366 | zepi/turbo-base | Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php | LayoutAbstract.extractFormValues | protected function extractFormValues(Form $form)
{
$values = array();
foreach ($form->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Field\\FieldAbstract', true) as $field) {
if ($field->getValue() === null) {
continue;
}
$values[$field->getPath($form)] = $field->getValue();
}
return $values;
} | php | protected function extractFormValues(Form $form)
{
$values = array();
foreach ($form->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Field\\FieldAbstract', true) as $field) {
if ($field->getValue() === null) {
continue;
}
$values[$field->getPath($form)] = $field->getValue();
}
return $values;
} | [
"protected",
"function",
"extractFormValues",
"(",
"Form",
"$",
"form",
")",
"{",
"$",
"values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"form",
"->",
"getChildrenByType",
"(",
"'\\\\Zepi\\\\Web\\\\UserInterface\\\\Form\\\\Field\\\\FieldAbstract'",
",",
"true",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"getValue",
"(",
")",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"$",
"values",
"[",
"$",
"field",
"->",
"getPath",
"(",
"$",
"form",
")",
"]",
"=",
"$",
"field",
"->",
"getValue",
"(",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Extracts all values from the given form and returns
an array with the field path and the field value.
@param \Zepi\Web\UserInterface\Form\Form $form
@return array | [
"Extracts",
"all",
"values",
"from",
"the",
"given",
"form",
"and",
"returns",
"an",
"array",
"with",
"the",
"field",
"path",
"and",
"the",
"field",
"value",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Layout/LayoutAbstract.php#L209-L222 |
367 | velkuns/eureka-package-adminlte | src/AdminLTE/Layout/Controller/ModalComponent.php | ModalComponent.error | public function error($message = '', $title = '')
{
$this->dataCollection->add('message', $message);
$this->dataCollection->add('title', $title);
return $this->render('Error');
} | php | public function error($message = '', $title = '')
{
$this->dataCollection->add('message', $message);
$this->dataCollection->add('title', $title);
return $this->render('Error');
} | [
"public",
"function",
"error",
"(",
"$",
"message",
"=",
"''",
",",
"$",
"title",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"dataCollection",
"->",
"add",
"(",
"'message'",
",",
"$",
"message",
")",
";",
"$",
"this",
"->",
"dataCollection",
"->",
"add",
"(",
"'title'",
",",
"$",
"title",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'Error'",
")",
";",
"}"
] | Modal error component
@param string $message
@param string $title
@return string | [
"Modal",
"error",
"component"
] | b5abd516fb30ed054e5ba351ada47acced7cb38e | https://github.com/velkuns/eureka-package-adminlte/blob/b5abd516fb30ed054e5ba351ada47acced7cb38e/src/AdminLTE/Layout/Controller/ModalComponent.php#L64-L70 |
368 | donbidon/core | src/Log/T_Logger.php | T_Logger.log | protected function log(
$message, $source = null, $level = E_NOTICE, $data = null
)
{
if (!($this->evtManager instanceof Manager)) {
$e = new ExceptionExtended(sprintf(
"%s::\$evtManager isn't instance of %s",
get_class($this), Manager::class
));
$e->setData($data);
throw $e;
}
if (is_null($source)) {
$source = ":missed:";
}
$args = new Args([
'message' => $message,
'source' => $source,
'level' => (int)$level,
]);
$this->evtManager->fire(':log:', $args);
} | php | protected function log(
$message, $source = null, $level = E_NOTICE, $data = null
)
{
if (!($this->evtManager instanceof Manager)) {
$e = new ExceptionExtended(sprintf(
"%s::\$evtManager isn't instance of %s",
get_class($this), Manager::class
));
$e->setData($data);
throw $e;
}
if (is_null($source)) {
$source = ":missed:";
}
$args = new Args([
'message' => $message,
'source' => $source,
'level' => (int)$level,
]);
$this->evtManager->fire(':log:', $args);
} | [
"protected",
"function",
"log",
"(",
"$",
"message",
",",
"$",
"source",
"=",
"null",
",",
"$",
"level",
"=",
"E_NOTICE",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"evtManager",
"instanceof",
"Manager",
")",
")",
"{",
"$",
"e",
"=",
"new",
"ExceptionExtended",
"(",
"sprintf",
"(",
"\"%s::\\$evtManager isn't instance of %s\"",
",",
"get_class",
"(",
"$",
"this",
")",
",",
"Manager",
"::",
"class",
")",
")",
";",
"$",
"e",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"source",
")",
")",
"{",
"$",
"source",
"=",
"\":missed:\"",
";",
"}",
"$",
"args",
"=",
"new",
"Args",
"(",
"[",
"'message'",
"=>",
"$",
"message",
",",
"'source'",
"=>",
"$",
"source",
",",
"'level'",
"=>",
"(",
"int",
")",
"$",
"level",
",",
"]",
")",
";",
"$",
"this",
"->",
"evtManager",
"->",
"fire",
"(",
"':log:'",
",",
"$",
"args",
")",
";",
"}"
] | Fires event to log message.
@param string $message
@param string $source
@param int $level
@param mixed $data Exception data
@return void
@throws ExceptionExtended If no event manager present. | [
"Fires",
"event",
"to",
"log",
"message",
"."
] | a22030c98ffb2dcbb8eb7a12f0498d88fb7531fe | https://github.com/donbidon/core/blob/a22030c98ffb2dcbb8eb7a12f0498d88fb7531fe/src/Log/T_Logger.php#L107-L128 |
369 | CampaignChain/activity-xing | Controller/XingHandler.php | XingHandler.processContent | public function processContent(Operation $operation, $data)
{
try {
if(is_array($data)) {
$message = $this->contentService->getMessageByOperation($operation);
$message->setMessage($data['message']);
} else {
$message = $data;
}
} catch (\Exception $e){
// message has not been created yet, so do it from the form data.
$message = $data;
}
return $message;
} | php | public function processContent(Operation $operation, $data)
{
try {
if(is_array($data)) {
$message = $this->contentService->getMessageByOperation($operation);
$message->setMessage($data['message']);
} else {
$message = $data;
}
} catch (\Exception $e){
// message has not been created yet, so do it from the form data.
$message = $data;
}
return $message;
} | [
"public",
"function",
"processContent",
"(",
"Operation",
"$",
"operation",
",",
"$",
"data",
")",
"{",
"try",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"contentService",
"->",
"getMessageByOperation",
"(",
"$",
"operation",
")",
";",
"$",
"message",
"->",
"setMessage",
"(",
"$",
"data",
"[",
"'message'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"$",
"data",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// message has not been created yet, so do it from the form data.",
"$",
"message",
"=",
"$",
"data",
";",
"}",
"return",
"$",
"message",
";",
"}"
] | Create or modify the Content object from the form data.
Called in these views:
- new
- editApi
@param Operation $operation
@param $data Form submit data of the Content.
@return mixed | [
"Create",
"or",
"modify",
"the",
"Content",
"object",
"from",
"the",
"form",
"data",
"."
] | f444f72352ce2f97e98fe4f3967343e80251bb58 | https://github.com/CampaignChain/activity-xing/blob/f444f72352ce2f97e98fe4f3967343e80251bb58/Controller/XingHandler.php#L159-L173 |
370 | CampaignChain/activity-xing | Controller/XingHandler.php | XingHandler.postPersistNewEvent | public function postPersistNewEvent(Operation $operation, $content = null)
{
$this->publishNow($operation);
$this->em->persist($content);
$this->em->flush();
} | php | public function postPersistNewEvent(Operation $operation, $content = null)
{
$this->publishNow($operation);
$this->em->persist($content);
$this->em->flush();
} | [
"public",
"function",
"postPersistNewEvent",
"(",
"Operation",
"$",
"operation",
",",
"$",
"content",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"publishNow",
"(",
"$",
"operation",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"}"
] | This event is being called after the new Activity and its related
content was persisted.
Called in these views:
- new
@param Operation $operation
@param Form $form
@param $content The Activity's content object.
@return null | [
"This",
"event",
"is",
"being",
"called",
"after",
"the",
"new",
"Activity",
"and",
"its",
"related",
"content",
"was",
"persisted",
"."
] | f444f72352ce2f97e98fe4f3967343e80251bb58 | https://github.com/CampaignChain/activity-xing/blob/f444f72352ce2f97e98fe4f3967343e80251bb58/Controller/XingHandler.php#L249-L254 |
371 | mtoolkit/mtoolkit-core | src/MLog.php | MLog.i | public function i($text, $context = array())
{
$this->log->info($text, $context);
$this->emit(self::SIGNAL_INFORMATION_ENTERED);
} | php | public function i($text, $context = array())
{
$this->log->info($text, $context);
$this->emit(self::SIGNAL_INFORMATION_ENTERED);
} | [
"public",
"function",
"i",
"(",
"$",
"text",
",",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"$",
"text",
",",
"$",
"context",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"self",
"::",
"SIGNAL_INFORMATION_ENTERED",
")",
";",
"}"
] | Add a information message.
@param $text
@param array $context | [
"Add",
"a",
"information",
"message",
"."
] | 66c53273288a8652ff38240e063bdcffdf7c30aa | https://github.com/mtoolkit/mtoolkit-core/blob/66c53273288a8652ff38240e063bdcffdf7c30aa/src/MLog.php#L62-L66 |
372 | mtoolkit/mtoolkit-core | src/MLog.php | MLog.w | public function w($text, $context = array())
{
$this->log->warn($text, $context);
$this->emit(self::SIGNAL_WARNING_ENTERED);
} | php | public function w($text, $context = array())
{
$this->log->warn($text, $context);
$this->emit(self::SIGNAL_WARNING_ENTERED);
} | [
"public",
"function",
"w",
"(",
"$",
"text",
",",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warn",
"(",
"$",
"text",
",",
"$",
"context",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"self",
"::",
"SIGNAL_WARNING_ENTERED",
")",
";",
"}"
] | Add a warning message.
@param $text
@param array $context | [
"Add",
"a",
"warning",
"message",
"."
] | 66c53273288a8652ff38240e063bdcffdf7c30aa | https://github.com/mtoolkit/mtoolkit-core/blob/66c53273288a8652ff38240e063bdcffdf7c30aa/src/MLog.php#L74-L78 |
373 | mtoolkit/mtoolkit-core | src/MLog.php | MLog.e | public function e($text, $context = array())
{
$this->log->error($text, $context);
$this->emit(self::SIGNAL_ERROR_ENTERED);
} | php | public function e($text, $context = array())
{
$this->log->error($text, $context);
$this->emit(self::SIGNAL_ERROR_ENTERED);
} | [
"public",
"function",
"e",
"(",
"$",
"text",
",",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"$",
"text",
",",
"$",
"context",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"self",
"::",
"SIGNAL_ERROR_ENTERED",
")",
";",
"}"
] | Add a error message.
@param $text
@param array $context | [
"Add",
"a",
"error",
"message",
"."
] | 66c53273288a8652ff38240e063bdcffdf7c30aa | https://github.com/mtoolkit/mtoolkit-core/blob/66c53273288a8652ff38240e063bdcffdf7c30aa/src/MLog.php#L86-L90 |
374 | LastCallMedia/Mannequin-Core | Config/ConfigLoader.php | ConfigLoader.load | public static function load(string $filename): ConfigInterface
{
if (!file_exists($filename)) {
throw new \RuntimeException(sprintf('Expected config in %s, but the file does not exist.', $filename), 1);
}
// Try to determine the realpath of the file, if possible.
$filename = realpath($filename) ?: $filename;
try {
$config = require $filename;
} catch (Exception $e) {
throw new \RuntimeException(sprintf('There was an error loading config from %s. Message: %s', $filename, $e->getMessage()), 1, $e);
}
if (1 === $config) {
throw new \RuntimeException(sprintf('No configuration was returned from %s.', $filename), 1);
}
if (!$config instanceof ConfigInterface) {
throw new \RuntimeException(sprintf('Configuration returned from %s is not an instance of %s.', $filename, ConfigInterface::class), 1);
}
if ('' === $config->getDocroot()) {
$config->setDocroot(dirname($filename));
}
if ('' === $config->getCachePrefix()) {
$config->setCachePrefix(md5($filename));
}
return $config;
} | php | public static function load(string $filename): ConfigInterface
{
if (!file_exists($filename)) {
throw new \RuntimeException(sprintf('Expected config in %s, but the file does not exist.', $filename), 1);
}
// Try to determine the realpath of the file, if possible.
$filename = realpath($filename) ?: $filename;
try {
$config = require $filename;
} catch (Exception $e) {
throw new \RuntimeException(sprintf('There was an error loading config from %s. Message: %s', $filename, $e->getMessage()), 1, $e);
}
if (1 === $config) {
throw new \RuntimeException(sprintf('No configuration was returned from %s.', $filename), 1);
}
if (!$config instanceof ConfigInterface) {
throw new \RuntimeException(sprintf('Configuration returned from %s is not an instance of %s.', $filename, ConfigInterface::class), 1);
}
if ('' === $config->getDocroot()) {
$config->setDocroot(dirname($filename));
}
if ('' === $config->getCachePrefix()) {
$config->setCachePrefix(md5($filename));
}
return $config;
} | [
"public",
"static",
"function",
"load",
"(",
"string",
"$",
"filename",
")",
":",
"ConfigInterface",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Expected config in %s, but the file does not exist.'",
",",
"$",
"filename",
")",
",",
"1",
")",
";",
"}",
"// Try to determine the realpath of the file, if possible.",
"$",
"filename",
"=",
"realpath",
"(",
"$",
"filename",
")",
"?",
":",
"$",
"filename",
";",
"try",
"{",
"$",
"config",
"=",
"require",
"$",
"filename",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'There was an error loading config from %s. Message: %s'",
",",
"$",
"filename",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"1",
",",
"$",
"e",
")",
";",
"}",
"if",
"(",
"1",
"===",
"$",
"config",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'No configuration was returned from %s.'",
",",
"$",
"filename",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"!",
"$",
"config",
"instanceof",
"ConfigInterface",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Configuration returned from %s is not an instance of %s.'",
",",
"$",
"filename",
",",
"ConfigInterface",
"::",
"class",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"''",
"===",
"$",
"config",
"->",
"getDocroot",
"(",
")",
")",
"{",
"$",
"config",
"->",
"setDocroot",
"(",
"dirname",
"(",
"$",
"filename",
")",
")",
";",
"}",
"if",
"(",
"''",
"===",
"$",
"config",
"->",
"getCachePrefix",
"(",
")",
")",
"{",
"$",
"config",
"->",
"setCachePrefix",
"(",
"md5",
"(",
"$",
"filename",
")",
")",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Loads a ConfigInterface from a PHP file.
@param string $filename .mannequin.php file.
@return \LastCall\Mannequin\Core\Config\ConfigInterface | [
"Loads",
"a",
"ConfigInterface",
"from",
"a",
"PHP",
"file",
"."
] | 1d5cacd54a5060b8fbfc0e2dfee035a1aacb9c81 | https://github.com/LastCallMedia/Mannequin-Core/blob/1d5cacd54a5060b8fbfc0e2dfee035a1aacb9c81/Config/ConfigLoader.php#L26-L52 |
375 | ibrows/IbrowsSimpleSeoBundle | Model/ContentManager.php | ContentManager.checkIsAliasExistsAlready | public function checkIsAliasExistsAlready($alias, $path, array $pathParameters = array(), $locale = null)
{
if ($alias === null) {
return false;
}
$already = $this->findByAlias($alias);
if ($already) {
$seo = $this->createNewAlias($alias, $path, $pathParameters, $locale);
if ($seo->getKeyword() == $already->getKeyword()) {
return false;
}
return true;
}
return false;
} | php | public function checkIsAliasExistsAlready($alias, $path, array $pathParameters = array(), $locale = null)
{
if ($alias === null) {
return false;
}
$already = $this->findByAlias($alias);
if ($already) {
$seo = $this->createNewAlias($alias, $path, $pathParameters, $locale);
if ($seo->getKeyword() == $already->getKeyword()) {
return false;
}
return true;
}
return false;
} | [
"public",
"function",
"checkIsAliasExistsAlready",
"(",
"$",
"alias",
",",
"$",
"path",
",",
"array",
"$",
"pathParameters",
"=",
"array",
"(",
")",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"alias",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"already",
"=",
"$",
"this",
"->",
"findByAlias",
"(",
"$",
"alias",
")",
";",
"if",
"(",
"$",
"already",
")",
"{",
"$",
"seo",
"=",
"$",
"this",
"->",
"createNewAlias",
"(",
"$",
"alias",
",",
"$",
"path",
",",
"$",
"pathParameters",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"seo",
"->",
"getKeyword",
"(",
")",
"==",
"$",
"already",
"->",
"getKeyword",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if there is already an alias of another path+pathParameters+locale.
@param $alias
@param $path
@param array $pathParameters
@param null $locale
@return ContentInterface | [
"Returns",
"true",
"if",
"there",
"is",
"already",
"an",
"alias",
"of",
"another",
"path",
"+",
"pathParameters",
"+",
"locale",
"."
] | ca3008a677a4895a7314f59609fa6d31c47c882e | https://github.com/ibrows/IbrowsSimpleSeoBundle/blob/ca3008a677a4895a7314f59609fa6d31c47c882e/Model/ContentManager.php#L140-L156 |
376 | Dhii/iterator-helper-base | src/MapIterableCapableTrait.php | MapIterableCapableTrait._mapIterable | protected function _mapIterable($iterable, $callback, $start = null, $count = null, array &$results = null)
{
$iterable = $this->_normalizeIterable($iterable);
$start = is_null($start)
? 0
: $this->_normalizeInt($start);
$count = is_null($count)
? 0
: $this->_normalizeInt($count);
$cStop = $count - 1;
$i = 0; // Current iteration
$c = 0; // Current count
foreach ($iterable as $_k => $_v) {
if ($i < $start) {
++$i;
continue;
}
$result = $this->_invokeCallable($callback, [$_v, $_k, $iterable]);
if (is_array($results)) {
$results[$_k] = $result;
}
if ($c === $cStop) {
break;
}
++$c;
++$i;
}
} | php | protected function _mapIterable($iterable, $callback, $start = null, $count = null, array &$results = null)
{
$iterable = $this->_normalizeIterable($iterable);
$start = is_null($start)
? 0
: $this->_normalizeInt($start);
$count = is_null($count)
? 0
: $this->_normalizeInt($count);
$cStop = $count - 1;
$i = 0; // Current iteration
$c = 0; // Current count
foreach ($iterable as $_k => $_v) {
if ($i < $start) {
++$i;
continue;
}
$result = $this->_invokeCallable($callback, [$_v, $_k, $iterable]);
if (is_array($results)) {
$results[$_k] = $result;
}
if ($c === $cStop) {
break;
}
++$c;
++$i;
}
} | [
"protected",
"function",
"_mapIterable",
"(",
"$",
"iterable",
",",
"$",
"callback",
",",
"$",
"start",
"=",
"null",
",",
"$",
"count",
"=",
"null",
",",
"array",
"&",
"$",
"results",
"=",
"null",
")",
"{",
"$",
"iterable",
"=",
"$",
"this",
"->",
"_normalizeIterable",
"(",
"$",
"iterable",
")",
";",
"$",
"start",
"=",
"is_null",
"(",
"$",
"start",
")",
"?",
"0",
":",
"$",
"this",
"->",
"_normalizeInt",
"(",
"$",
"start",
")",
";",
"$",
"count",
"=",
"is_null",
"(",
"$",
"count",
")",
"?",
"0",
":",
"$",
"this",
"->",
"_normalizeInt",
"(",
"$",
"count",
")",
";",
"$",
"cStop",
"=",
"$",
"count",
"-",
"1",
";",
"$",
"i",
"=",
"0",
";",
"// Current iteration",
"$",
"c",
"=",
"0",
";",
"// Current count",
"foreach",
"(",
"$",
"iterable",
"as",
"$",
"_k",
"=>",
"$",
"_v",
")",
"{",
"if",
"(",
"$",
"i",
"<",
"$",
"start",
")",
"{",
"++",
"$",
"i",
";",
"continue",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"_invokeCallable",
"(",
"$",
"callback",
",",
"[",
"$",
"_v",
",",
"$",
"_k",
",",
"$",
"iterable",
"]",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"results",
")",
")",
"{",
"$",
"results",
"[",
"$",
"_k",
"]",
"=",
"$",
"result",
";",
"}",
"if",
"(",
"$",
"c",
"===",
"$",
"cStop",
")",
"{",
"break",
";",
"}",
"++",
"$",
"c",
";",
"++",
"$",
"i",
";",
"}",
"}"
] | Invokes a callback for each element of the iterable.
@since [*next-version*]
@param array|stdClass|Traversable $iterable The iterable to map.
@param callable $callback The callback to apply to the elements of the iterable.
The callback return value will be stored in `$results`.
Signature:
`function ($value, $key, $iterable)`
@param Stringable|string|int|float|bool|null $start The offset of the iteration, at which to start applying the callback.
Iterations will still happen on all previous elements, but the callback will not be applied.
Default: 0.
@param Stringable|string|int|float|bool|null $count The number of invocations to make. Iteration will stop when this number is reached.
Pass 0 (zero) to iterate until end.
Default: 0.
@param array|null $results If array, this will be filled with the results of the callback, in the same order, preserving keys.
@throws InvalidArgumentException If the iterable, the callback, start, or end are invalid.
@throws InvocationExceptionInterface If problem during invocation of the callback. | [
"Invokes",
"a",
"callback",
"for",
"each",
"element",
"of",
"the",
"iterable",
"."
] | cf62fb9f8b658a82815f15a2d906d8d1ff5c52ce | https://github.com/Dhii/iterator-helper-base/blob/cf62fb9f8b658a82815f15a2d906d8d1ff5c52ce/src/MapIterableCapableTrait.php#L39-L72 |
377 | robertasproniu/tic-tac-toe-agent | src/Game.php | Game.getMove | protected function getMove($player = self::PLAYER_X)
{
$move = $this->calculateBestMove($player);
if (!empty($move)) {
$this->board->setValue($move, $player);
}
return $move;
} | php | protected function getMove($player = self::PLAYER_X)
{
$move = $this->calculateBestMove($player);
if (!empty($move)) {
$this->board->setValue($move, $player);
}
return $move;
} | [
"protected",
"function",
"getMove",
"(",
"$",
"player",
"=",
"self",
"::",
"PLAYER_X",
")",
"{",
"$",
"move",
"=",
"$",
"this",
"->",
"calculateBestMove",
"(",
"$",
"player",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"move",
")",
")",
"{",
"$",
"this",
"->",
"board",
"->",
"setValue",
"(",
"$",
"move",
",",
"$",
"player",
")",
";",
"}",
"return",
"$",
"move",
";",
"}"
] | return recommended value
@param string $player
@return array | [
"return",
"recommended",
"value"
] | 00bc8e31e3c9770f2ee24d97d82e40dff20e3e98 | https://github.com/robertasproniu/tic-tac-toe-agent/blob/00bc8e31e3c9770f2ee24d97d82e40dff20e3e98/src/Game.php#L107-L116 |
378 | robertasproniu/tic-tac-toe-agent | src/Game.php | Game.winningValues | private function winningValues()
{
return array_merge(
// rows
$this->board->getBoard(),
// columns
$this->transpose($this->board->getBoard()),
// diagonals
$this->diagonals()
);
} | php | private function winningValues()
{
return array_merge(
// rows
$this->board->getBoard(),
// columns
$this->transpose($this->board->getBoard()),
// diagonals
$this->diagonals()
);
} | [
"private",
"function",
"winningValues",
"(",
")",
"{",
"return",
"array_merge",
"(",
"// rows",
"$",
"this",
"->",
"board",
"->",
"getBoard",
"(",
")",
",",
"// columns",
"$",
"this",
"->",
"transpose",
"(",
"$",
"this",
"->",
"board",
"->",
"getBoard",
"(",
")",
")",
",",
"// diagonals",
"$",
"this",
"->",
"diagonals",
"(",
")",
")",
";",
"}"
] | Determine winning values
@return array | [
"Determine",
"winning",
"values"
] | 00bc8e31e3c9770f2ee24d97d82e40dff20e3e98 | https://github.com/robertasproniu/tic-tac-toe-agent/blob/00bc8e31e3c9770f2ee24d97d82e40dff20e3e98/src/Game.php#L158-L168 |
379 | robertasproniu/tic-tac-toe-agent | src/Game.php | Game.calculateBestMove | private function calculateBestMove($player, $stopOpponentPlayer = true, &$playerMoveScore = 0)
{
$winningMoves = []; // the best tile(s)
$opponentMoveScore = 0; // the higher moveScore of the opponent
$opponentMove = []; // keep opponent best move
if (!$this->checkPlayer($player) || $this->isFinished()) {
return $winningMoves;
}
// try to stop the opponent from winning
if ($stopOpponentPlayer) {
// get the opponent's best move
$opponentMove = $this->calculateBestMove($this->getOpponentPlayer($player), false, $opponentMoveScore);
}
foreach ($this->board->getBoard() as $positionX => $col) {
foreach ($col as $positionY => $tile) {
$moveScore = $this->calculateMoveScore($player, [$positionX, $positionY]);
if (!is_null($moveScore)) {
if ($moveScore > $playerMoveScore) {
$winningMoves = [[$positionX, $positionY]];
$playerMoveScore = $moveScore;
continue;
}
if ($moveScore == $playerMoveScore) {
array_push($winningMoves, [$positionX, $positionY]);
continue;
}
}
}
}
if ($stopOpponentPlayer && $opponentMoveScore >= 10 && $playerMoveScore < 10) {
return $opponentMove;
}
if (count($winningMoves)) {
return $winningMoves[array_rand($winningMoves)];
}
return $winningMoves;
} | php | private function calculateBestMove($player, $stopOpponentPlayer = true, &$playerMoveScore = 0)
{
$winningMoves = []; // the best tile(s)
$opponentMoveScore = 0; // the higher moveScore of the opponent
$opponentMove = []; // keep opponent best move
if (!$this->checkPlayer($player) || $this->isFinished()) {
return $winningMoves;
}
// try to stop the opponent from winning
if ($stopOpponentPlayer) {
// get the opponent's best move
$opponentMove = $this->calculateBestMove($this->getOpponentPlayer($player), false, $opponentMoveScore);
}
foreach ($this->board->getBoard() as $positionX => $col) {
foreach ($col as $positionY => $tile) {
$moveScore = $this->calculateMoveScore($player, [$positionX, $positionY]);
if (!is_null($moveScore)) {
if ($moveScore > $playerMoveScore) {
$winningMoves = [[$positionX, $positionY]];
$playerMoveScore = $moveScore;
continue;
}
if ($moveScore == $playerMoveScore) {
array_push($winningMoves, [$positionX, $positionY]);
continue;
}
}
}
}
if ($stopOpponentPlayer && $opponentMoveScore >= 10 && $playerMoveScore < 10) {
return $opponentMove;
}
if (count($winningMoves)) {
return $winningMoves[array_rand($winningMoves)];
}
return $winningMoves;
} | [
"private",
"function",
"calculateBestMove",
"(",
"$",
"player",
",",
"$",
"stopOpponentPlayer",
"=",
"true",
",",
"&",
"$",
"playerMoveScore",
"=",
"0",
")",
"{",
"$",
"winningMoves",
"=",
"[",
"]",
";",
"// the best tile(s)",
"$",
"opponentMoveScore",
"=",
"0",
";",
"// the higher moveScore of the opponent",
"$",
"opponentMove",
"=",
"[",
"]",
";",
"// keep opponent best move",
"if",
"(",
"!",
"$",
"this",
"->",
"checkPlayer",
"(",
"$",
"player",
")",
"||",
"$",
"this",
"->",
"isFinished",
"(",
")",
")",
"{",
"return",
"$",
"winningMoves",
";",
"}",
"// try to stop the opponent from winning",
"if",
"(",
"$",
"stopOpponentPlayer",
")",
"{",
"// get the opponent's best move",
"$",
"opponentMove",
"=",
"$",
"this",
"->",
"calculateBestMove",
"(",
"$",
"this",
"->",
"getOpponentPlayer",
"(",
"$",
"player",
")",
",",
"false",
",",
"$",
"opponentMoveScore",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"board",
"->",
"getBoard",
"(",
")",
"as",
"$",
"positionX",
"=>",
"$",
"col",
")",
"{",
"foreach",
"(",
"$",
"col",
"as",
"$",
"positionY",
"=>",
"$",
"tile",
")",
"{",
"$",
"moveScore",
"=",
"$",
"this",
"->",
"calculateMoveScore",
"(",
"$",
"player",
",",
"[",
"$",
"positionX",
",",
"$",
"positionY",
"]",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"moveScore",
")",
")",
"{",
"if",
"(",
"$",
"moveScore",
">",
"$",
"playerMoveScore",
")",
"{",
"$",
"winningMoves",
"=",
"[",
"[",
"$",
"positionX",
",",
"$",
"positionY",
"]",
"]",
";",
"$",
"playerMoveScore",
"=",
"$",
"moveScore",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"moveScore",
"==",
"$",
"playerMoveScore",
")",
"{",
"array_push",
"(",
"$",
"winningMoves",
",",
"[",
"$",
"positionX",
",",
"$",
"positionY",
"]",
")",
";",
"continue",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"stopOpponentPlayer",
"&&",
"$",
"opponentMoveScore",
">=",
"10",
"&&",
"$",
"playerMoveScore",
"<",
"10",
")",
"{",
"return",
"$",
"opponentMove",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"winningMoves",
")",
")",
"{",
"return",
"$",
"winningMoves",
"[",
"array_rand",
"(",
"$",
"winningMoves",
")",
"]",
";",
"}",
"return",
"$",
"winningMoves",
";",
"}"
] | Get the best move of a player
@param string $player
@param bool $stopOpponentPlayer Whether to try to stop the opponent from winning
@param int $playerMoveScore
@return array The position of the best tile | [
"Get",
"the",
"best",
"move",
"of",
"a",
"player"
] | 00bc8e31e3c9770f2ee24d97d82e40dff20e3e98 | https://github.com/robertasproniu/tic-tac-toe-agent/blob/00bc8e31e3c9770f2ee24d97d82e40dff20e3e98/src/Game.php#L259-L312 |
380 | robertasproniu/tic-tac-toe-agent | src/Game.php | Game.calculateMoveScore | private function calculateMoveScore($player, array $position)
{
if ($this->board->getValue($position)) {
return null;
}
$totalScore = 0;
foreach ($this->positions as $row) {
if (!in_array($position, $row)) {
continue;
}
$countOpponentMoves = 0;
$countPlayerMoves = 0;
foreach ($row as $positionTile) {
$positionValue = $this->board->getValue($positionTile);
if ($positionValue) {
$countOpponentMoves++;
if ($positionValue == $player) {
$countPlayerMoves++;
$countOpponentMoves--;
}
}
}
if (!$countOpponentMoves && $countPlayerMoves == 2) {
$totalScore += 10;
continue;
}
if (!$countOpponentMoves && $countPlayerMoves == 1) {
$totalScore += 2;
continue;
}
if (!$countOpponentMoves && !$countPlayerMoves) {
$totalScore++;
continue;
}
}
return $totalScore;
} | php | private function calculateMoveScore($player, array $position)
{
if ($this->board->getValue($position)) {
return null;
}
$totalScore = 0;
foreach ($this->positions as $row) {
if (!in_array($position, $row)) {
continue;
}
$countOpponentMoves = 0;
$countPlayerMoves = 0;
foreach ($row as $positionTile) {
$positionValue = $this->board->getValue($positionTile);
if ($positionValue) {
$countOpponentMoves++;
if ($positionValue == $player) {
$countPlayerMoves++;
$countOpponentMoves--;
}
}
}
if (!$countOpponentMoves && $countPlayerMoves == 2) {
$totalScore += 10;
continue;
}
if (!$countOpponentMoves && $countPlayerMoves == 1) {
$totalScore += 2;
continue;
}
if (!$countOpponentMoves && !$countPlayerMoves) {
$totalScore++;
continue;
}
}
return $totalScore;
} | [
"private",
"function",
"calculateMoveScore",
"(",
"$",
"player",
",",
"array",
"$",
"position",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"board",
"->",
"getValue",
"(",
"$",
"position",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"totalScore",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"positions",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"position",
",",
"$",
"row",
")",
")",
"{",
"continue",
";",
"}",
"$",
"countOpponentMoves",
"=",
"0",
";",
"$",
"countPlayerMoves",
"=",
"0",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"positionTile",
")",
"{",
"$",
"positionValue",
"=",
"$",
"this",
"->",
"board",
"->",
"getValue",
"(",
"$",
"positionTile",
")",
";",
"if",
"(",
"$",
"positionValue",
")",
"{",
"$",
"countOpponentMoves",
"++",
";",
"if",
"(",
"$",
"positionValue",
"==",
"$",
"player",
")",
"{",
"$",
"countPlayerMoves",
"++",
";",
"$",
"countOpponentMoves",
"--",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"countOpponentMoves",
"&&",
"$",
"countPlayerMoves",
"==",
"2",
")",
"{",
"$",
"totalScore",
"+=",
"10",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"countOpponentMoves",
"&&",
"$",
"countPlayerMoves",
"==",
"1",
")",
"{",
"$",
"totalScore",
"+=",
"2",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"countOpponentMoves",
"&&",
"!",
"$",
"countPlayerMoves",
")",
"{",
"$",
"totalScore",
"++",
";",
"continue",
";",
"}",
"}",
"return",
"$",
"totalScore",
";",
"}"
] | Get the score of a move
@param int $player The player
@param array $position
@return int The overall rating (the higher the better) | [
"Get",
"the",
"score",
"of",
"a",
"move"
] | 00bc8e31e3c9770f2ee24d97d82e40dff20e3e98 | https://github.com/robertasproniu/tic-tac-toe-agent/blob/00bc8e31e3c9770f2ee24d97d82e40dff20e3e98/src/Game.php#L355-L406 |
381 | b3rs3rk/steamfront | source/b3rs3rk/steamfront/Main.php | Main.get | public function get($root, $path)
{
$url = $root . $path;
$response = Http::get($url . $this->countryCode . $this->localLang);
if (is_array($response)) {
return $response;
} else {
return false;
}
} | php | public function get($root, $path)
{
$url = $root . $path;
$response = Http::get($url . $this->countryCode . $this->localLang);
if (is_array($response)) {
return $response;
} else {
return false;
}
} | [
"public",
"function",
"get",
"(",
"$",
"root",
",",
"$",
"path",
")",
"{",
"$",
"url",
"=",
"$",
"root",
".",
"$",
"path",
";",
"$",
"response",
"=",
"Http",
"::",
"get",
"(",
"$",
"url",
".",
"$",
"this",
"->",
"countryCode",
".",
"$",
"this",
"->",
"localLang",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"response",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Gets requested data using Http client and returns the json decoded response
@param string $root The root url of the request
@param string $path The path of the request
@return array|bool The JSON decoded response or false | [
"Gets",
"requested",
"data",
"using",
"Http",
"client",
"and",
"returns",
"the",
"json",
"decoded",
"response"
] | 286962ea793a8069729b4412a675c88a8d6c3ebd | https://github.com/b3rs3rk/steamfront/blob/286962ea793a8069729b4412a675c88a8d6c3ebd/source/b3rs3rk/steamfront/Main.php#L104-L117 |
382 | b3rs3rk/steamfront | source/b3rs3rk/steamfront/Main.php | Main.getAppDetails | public function getAppDetails($id, $filter = '')
{
if (!empty($filter)) {
$filter = '&filters=' . $filter;
}
$app = $this->get(self::STEAM_STORE_ROOT, self::APP_DETAILS_PATH . $id . $filter);
if ($app[$id]['success'] == true) {
return new App($app[$id]['data']);
} else {
return false;
}
} | php | public function getAppDetails($id, $filter = '')
{
if (!empty($filter)) {
$filter = '&filters=' . $filter;
}
$app = $this->get(self::STEAM_STORE_ROOT, self::APP_DETAILS_PATH . $id . $filter);
if ($app[$id]['success'] == true) {
return new App($app[$id]['data']);
} else {
return false;
}
} | [
"public",
"function",
"getAppDetails",
"(",
"$",
"id",
",",
"$",
"filter",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"filter",
"=",
"'&filters='",
".",
"$",
"filter",
";",
"}",
"$",
"app",
"=",
"$",
"this",
"->",
"get",
"(",
"self",
"::",
"STEAM_STORE_ROOT",
",",
"self",
"::",
"APP_DETAILS_PATH",
".",
"$",
"id",
".",
"$",
"filter",
")",
";",
"if",
"(",
"$",
"app",
"[",
"$",
"id",
"]",
"[",
"'success'",
"]",
"==",
"true",
")",
"{",
"return",
"new",
"App",
"(",
"$",
"app",
"[",
"$",
"id",
"]",
"[",
"'data'",
"]",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Retrieves App information for a specific AppID
@param int $id The id argument settings value for the API query
@param string $filter The filter argument settings value for the API query
@return false|App The normalized data return for the requested Steam Application ID | [
"Retrieves",
"App",
"information",
"for",
"a",
"specific",
"AppID"
] | 286962ea793a8069729b4412a675c88a8d6c3ebd | https://github.com/b3rs3rk/steamfront/blob/286962ea793a8069729b4412a675c88a8d6c3ebd/source/b3rs3rk/steamfront/Main.php#L157-L170 |
383 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.buildQuery | protected function buildQuery()
{
/** @var Search $search */
$search = $this->repository->createSearch();
$search->setSize($this->limit);
$search->addSort(new Sort('left', Sort::ORDER_ASC));
$search->addQuery(new TermQuery('active', true), 'must');
if (!$this->loadHiddenCategories) {
$search->addQuery(new TermQuery('is_hidden', 0), 'must');
}
return $search;
} | php | protected function buildQuery()
{
/** @var Search $search */
$search = $this->repository->createSearch();
$search->setSize($this->limit);
$search->addSort(new Sort('left', Sort::ORDER_ASC));
$search->addQuery(new TermQuery('active', true), 'must');
if (!$this->loadHiddenCategories) {
$search->addQuery(new TermQuery('is_hidden', 0), 'must');
}
return $search;
} | [
"protected",
"function",
"buildQuery",
"(",
")",
"{",
"/** @var Search $search */",
"$",
"search",
"=",
"$",
"this",
"->",
"repository",
"->",
"createSearch",
"(",
")",
";",
"$",
"search",
"->",
"setSize",
"(",
"$",
"this",
"->",
"limit",
")",
";",
"$",
"search",
"->",
"addSort",
"(",
"new",
"Sort",
"(",
"'left'",
",",
"Sort",
"::",
"ORDER_ASC",
")",
")",
";",
"$",
"search",
"->",
"addQuery",
"(",
"new",
"TermQuery",
"(",
"'active'",
",",
"true",
")",
",",
"'must'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"loadHiddenCategories",
")",
"{",
"$",
"search",
"->",
"addQuery",
"(",
"new",
"TermQuery",
"(",
"'is_hidden'",
",",
"0",
")",
",",
"'must'",
")",
";",
"}",
"return",
"$",
"search",
";",
"}"
] | Builds a search query.
@return Search | [
"Builds",
"a",
"search",
"query",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L77-L89 |
384 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.buildChildNode | private function buildChildNode($node, $references, $maxLevel)
{
if (isset($references[$node->getParentId()])) {
$level = $references[$node->getParentId()]->getLevel() + 1;
// Check if max level is not reached or not set at all.
if ($maxLevel == 0 || $level <= $maxLevel) {
$node->setLevel($level);
$node->setParent($references[$node->getParentId()]);
$references[$node->getParentId()]->setChild($node, $node->getId());
}
}
} | php | private function buildChildNode($node, $references, $maxLevel)
{
if (isset($references[$node->getParentId()])) {
$level = $references[$node->getParentId()]->getLevel() + 1;
// Check if max level is not reached or not set at all.
if ($maxLevel == 0 || $level <= $maxLevel) {
$node->setLevel($level);
$node->setParent($references[$node->getParentId()]);
$references[$node->getParentId()]->setChild($node, $node->getId());
}
}
} | [
"private",
"function",
"buildChildNode",
"(",
"$",
"node",
",",
"$",
"references",
",",
"$",
"maxLevel",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"references",
"[",
"$",
"node",
"->",
"getParentId",
"(",
")",
"]",
")",
")",
"{",
"$",
"level",
"=",
"$",
"references",
"[",
"$",
"node",
"->",
"getParentId",
"(",
")",
"]",
"->",
"getLevel",
"(",
")",
"+",
"1",
";",
"// Check if max level is not reached or not set at all.",
"if",
"(",
"$",
"maxLevel",
"==",
"0",
"||",
"$",
"level",
"<=",
"$",
"maxLevel",
")",
"{",
"$",
"node",
"->",
"setLevel",
"(",
"$",
"level",
")",
";",
"$",
"node",
"->",
"setParent",
"(",
"$",
"references",
"[",
"$",
"node",
"->",
"getParentId",
"(",
")",
"]",
")",
";",
"$",
"references",
"[",
"$",
"node",
"->",
"getParentId",
"(",
")",
"]",
"->",
"setChild",
"(",
"$",
"node",
",",
"$",
"node",
"->",
"getId",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Builds a child node.
@param AbstractCategoryDocument $node
@param \ArrayIterator $references
@param int $maxLevel | [
"Builds",
"a",
"child",
"node",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L98-L110 |
385 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.buildRootNode | private function buildRootNode($node, $tree, $level)
{
$node->setLevel($level);
$tree[$node->getId()] = $node;
} | php | private function buildRootNode($node, $tree, $level)
{
$node->setLevel($level);
$tree[$node->getId()] = $node;
} | [
"private",
"function",
"buildRootNode",
"(",
"$",
"node",
",",
"$",
"tree",
",",
"$",
"level",
")",
"{",
"$",
"node",
"->",
"setLevel",
"(",
"$",
"level",
")",
";",
"$",
"tree",
"[",
"$",
"node",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"node",
";",
"}"
] | Builds a root node.
@param AbstractCategoryDocument $node
@param \ArrayIterator $tree
@param int $level | [
"Builds",
"a",
"root",
"node",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L133-L137 |
386 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.buildNode | private function buildNode($node, $references, $tree, $maxLevel)
{
if ($node->getId() == $this->getCurrentCategoryId()) {
$node->setCurrent(true);
$this->currentLeaf = $node;
}
$references[$node->getId()] = $node;
if ($node->getParentId() == $this->rootId) {
$this->buildRootNode($node, $tree, 1);
} else {
$this->buildChildNode($node, $references, $maxLevel);
}
} | php | private function buildNode($node, $references, $tree, $maxLevel)
{
if ($node->getId() == $this->getCurrentCategoryId()) {
$node->setCurrent(true);
$this->currentLeaf = $node;
}
$references[$node->getId()] = $node;
if ($node->getParentId() == $this->rootId) {
$this->buildRootNode($node, $tree, 1);
} else {
$this->buildChildNode($node, $references, $maxLevel);
}
} | [
"private",
"function",
"buildNode",
"(",
"$",
"node",
",",
"$",
"references",
",",
"$",
"tree",
",",
"$",
"maxLevel",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"getId",
"(",
")",
"==",
"$",
"this",
"->",
"getCurrentCategoryId",
"(",
")",
")",
"{",
"$",
"node",
"->",
"setCurrent",
"(",
"true",
")",
";",
"$",
"this",
"->",
"currentLeaf",
"=",
"$",
"node",
";",
"}",
"$",
"references",
"[",
"$",
"node",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"node",
";",
"if",
"(",
"$",
"node",
"->",
"getParentId",
"(",
")",
"==",
"$",
"this",
"->",
"rootId",
")",
"{",
"$",
"this",
"->",
"buildRootNode",
"(",
"$",
"node",
",",
"$",
"tree",
",",
"1",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"buildChildNode",
"(",
"$",
"node",
",",
"$",
"references",
",",
"$",
"maxLevel",
")",
";",
"}",
"}"
] | Builds a node. Sets node parameters.
@param AbstractCategoryDocument $node
@param \ArrayIterator $references
@param \ArrayIterator $tree
@param int $maxLevel | [
"Builds",
"a",
"node",
".",
"Sets",
"node",
"parameters",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L147-L161 |
387 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.expandNodes | private function expandNodes($references)
{
$id = $this->getCurrentCategoryId();
if ($id) {
while (isset($references[$id])) {
$references[$id]->setExpanded(true);
$id = $references[$id]->getParentId();
}
}
} | php | private function expandNodes($references)
{
$id = $this->getCurrentCategoryId();
if ($id) {
while (isset($references[$id])) {
$references[$id]->setExpanded(true);
$id = $references[$id]->getParentId();
}
}
} | [
"private",
"function",
"expandNodes",
"(",
"$",
"references",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getCurrentCategoryId",
"(",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"while",
"(",
"isset",
"(",
"$",
"references",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"references",
"[",
"$",
"id",
"]",
"->",
"setExpanded",
"(",
"true",
")",
";",
"$",
"id",
"=",
"$",
"references",
"[",
"$",
"id",
"]",
"->",
"getParentId",
"(",
")",
";",
"}",
"}",
"}"
] | Expands nodes.
@param \ArrayIterator $references | [
"Expands",
"nodes",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L168-L178 |
388 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.buildTree | private function buildTree($dataSet, $maxLevel = 0)
{
$tree = new \ArrayIterator();
$references = new \ArrayIterator();
/** @var DocumentIterator $dataSet */
foreach ($dataSet as $node) {
if ($node->isActive()) {
$this->buildNode($node, $references, $tree, $maxLevel);
}
}
$this->expandNodes($references);
$this->sortChildTree($tree);
return $tree;
} | php | private function buildTree($dataSet, $maxLevel = 0)
{
$tree = new \ArrayIterator();
$references = new \ArrayIterator();
/** @var DocumentIterator $dataSet */
foreach ($dataSet as $node) {
if ($node->isActive()) {
$this->buildNode($node, $references, $tree, $maxLevel);
}
}
$this->expandNodes($references);
$this->sortChildTree($tree);
return $tree;
} | [
"private",
"function",
"buildTree",
"(",
"$",
"dataSet",
",",
"$",
"maxLevel",
"=",
"0",
")",
"{",
"$",
"tree",
"=",
"new",
"\\",
"ArrayIterator",
"(",
")",
";",
"$",
"references",
"=",
"new",
"\\",
"ArrayIterator",
"(",
")",
";",
"/** @var DocumentIterator $dataSet */",
"foreach",
"(",
"$",
"dataSet",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"isActive",
"(",
")",
")",
"{",
"$",
"this",
"->",
"buildNode",
"(",
"$",
"node",
",",
"$",
"references",
",",
"$",
"tree",
",",
"$",
"maxLevel",
")",
";",
"}",
"}",
"$",
"this",
"->",
"expandNodes",
"(",
"$",
"references",
")",
";",
"$",
"this",
"->",
"sortChildTree",
"(",
"$",
"tree",
")",
";",
"return",
"$",
"tree",
";",
"}"
] | Builds nested tree from single category list.
@param array $dataSet A set of nodes.
@param int $maxLevel Maximum levels deep of the tree to build.
@return array | [
"Builds",
"nested",
"tree",
"from",
"single",
"category",
"list",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L188-L205 |
389 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.sortChildTree | protected function sortChildTree(&$tree)
{
/** @var AbstractCategoryDocument $node */
if (is_array($tree)) {
uasort($tree, [$this, 'sortNodes']);
foreach ($tree as $node) {
$children = $node->getChildren();
if ($children) {
$this->sortChildTree($children);
$node->setChildren($children);
}
}
} else {
$tree->uasort([$this, 'sortNodes']);
$tree->rewind();
foreach ($tree as $node) {
$children = $node->getChildren();
if ($children) {
$this->sortChildTree($children);
$node->setChildren($children);
}
}
}
} | php | protected function sortChildTree(&$tree)
{
/** @var AbstractCategoryDocument $node */
if (is_array($tree)) {
uasort($tree, [$this, 'sortNodes']);
foreach ($tree as $node) {
$children = $node->getChildren();
if ($children) {
$this->sortChildTree($children);
$node->setChildren($children);
}
}
} else {
$tree->uasort([$this, 'sortNodes']);
$tree->rewind();
foreach ($tree as $node) {
$children = $node->getChildren();
if ($children) {
$this->sortChildTree($children);
$node->setChildren($children);
}
}
}
} | [
"protected",
"function",
"sortChildTree",
"(",
"&",
"$",
"tree",
")",
"{",
"/** @var AbstractCategoryDocument $node */",
"if",
"(",
"is_array",
"(",
"$",
"tree",
")",
")",
"{",
"uasort",
"(",
"$",
"tree",
",",
"[",
"$",
"this",
",",
"'sortNodes'",
"]",
")",
";",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"node",
")",
"{",
"$",
"children",
"=",
"$",
"node",
"->",
"getChildren",
"(",
")",
";",
"if",
"(",
"$",
"children",
")",
"{",
"$",
"this",
"->",
"sortChildTree",
"(",
"$",
"children",
")",
";",
"$",
"node",
"->",
"setChildren",
"(",
"$",
"children",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"tree",
"->",
"uasort",
"(",
"[",
"$",
"this",
",",
"'sortNodes'",
"]",
")",
";",
"$",
"tree",
"->",
"rewind",
"(",
")",
";",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"node",
")",
"{",
"$",
"children",
"=",
"$",
"node",
"->",
"getChildren",
"(",
")",
";",
"if",
"(",
"$",
"children",
")",
"{",
"$",
"this",
"->",
"sortChildTree",
"(",
"$",
"children",
")",
";",
"$",
"node",
"->",
"setChildren",
"(",
"$",
"children",
")",
";",
"}",
"}",
"}",
"}"
] | Sorts category tree by sort field.
@param array|\ArrayIterator $tree | [
"Sorts",
"category",
"tree",
"by",
"sort",
"field",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L212-L235 |
390 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.sortNodes | public function sortNodes($a, $b)
{
if ($a->getSort() < $b->getSort()) {
return -1;
} elseif ($a->getSort() > $b->getSort()) {
return 1;
} elseif ($a->getLeft() < $b->getLeft()) {
return -1;
} elseif ($a->getLeft() > $b->getLeft()) {
return 1;
}
return 0;
} | php | public function sortNodes($a, $b)
{
if ($a->getSort() < $b->getSort()) {
return -1;
} elseif ($a->getSort() > $b->getSort()) {
return 1;
} elseif ($a->getLeft() < $b->getLeft()) {
return -1;
} elseif ($a->getLeft() > $b->getLeft()) {
return 1;
}
return 0;
} | [
"public",
"function",
"sortNodes",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getSort",
"(",
")",
"<",
"$",
"b",
"->",
"getSort",
"(",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"elseif",
"(",
"$",
"a",
"->",
"getSort",
"(",
")",
">",
"$",
"b",
"->",
"getSort",
"(",
")",
")",
"{",
"return",
"1",
";",
"}",
"elseif",
"(",
"$",
"a",
"->",
"getLeft",
"(",
")",
"<",
"$",
"b",
"->",
"getLeft",
"(",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"elseif",
"(",
"$",
"a",
"->",
"getLeft",
"(",
")",
">",
"$",
"b",
"->",
"getLeft",
"(",
")",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | Sorts nodes by field sort if value equal then by field left.
@param AbstractCategoryDocument $a
@param AbstractCategoryDocument $b
@return int | [
"Sorts",
"nodes",
"by",
"field",
"sort",
"if",
"value",
"equal",
"then",
"by",
"field",
"left",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L245-L258 |
391 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.getTree | public function getTree($maxLevel = 0, $getHidden = false)
{
$hash = $maxLevel . $getHidden;
if (!isset($this->treeCache[$hash])) {
$this->setLoadHiddenCategories($getHidden);
$query = $this->buildQuery();
$results = $this->repository->execute($query, Repository::RESULTS_OBJECT);
$tree = $this->buildTree($results, $maxLevel);
$this->treeCache[$hash] = $tree;
}
return $this->treeCache[$hash];
} | php | public function getTree($maxLevel = 0, $getHidden = false)
{
$hash = $maxLevel . $getHidden;
if (!isset($this->treeCache[$hash])) {
$this->setLoadHiddenCategories($getHidden);
$query = $this->buildQuery();
$results = $this->repository->execute($query, Repository::RESULTS_OBJECT);
$tree = $this->buildTree($results, $maxLevel);
$this->treeCache[$hash] = $tree;
}
return $this->treeCache[$hash];
} | [
"public",
"function",
"getTree",
"(",
"$",
"maxLevel",
"=",
"0",
",",
"$",
"getHidden",
"=",
"false",
")",
"{",
"$",
"hash",
"=",
"$",
"maxLevel",
".",
"$",
"getHidden",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"treeCache",
"[",
"$",
"hash",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setLoadHiddenCategories",
"(",
"$",
"getHidden",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"buildQuery",
"(",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"repository",
"->",
"execute",
"(",
"$",
"query",
",",
"Repository",
"::",
"RESULTS_OBJECT",
")",
";",
"$",
"tree",
"=",
"$",
"this",
"->",
"buildTree",
"(",
"$",
"results",
",",
"$",
"maxLevel",
")",
";",
"$",
"this",
"->",
"treeCache",
"[",
"$",
"hash",
"]",
"=",
"$",
"tree",
";",
"}",
"return",
"$",
"this",
"->",
"treeCache",
"[",
"$",
"hash",
"]",
";",
"}"
] | Returns nested category tree.
@param int $maxLevel
@param bool $getHidden
@return \ArrayIterator | [
"Returns",
"nested",
"category",
"tree",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L268-L280 |
392 | ongr-archive/ContentBundle | Service/CategoryService.php | CategoryService.findPartialTree | protected function findPartialTree($tree, $categoryId)
{
/** @var AbstractCategoryDocument $node */
foreach ($tree as $node) {
if ($node->getId() == $categoryId) {
return [$node];
}
if ($node->getChildren()) {
$result = $this->findPartialTree($node->getChildren(), $categoryId);
if (!empty($result)) {
return $result;
}
}
}
return [];
} | php | protected function findPartialTree($tree, $categoryId)
{
/** @var AbstractCategoryDocument $node */
foreach ($tree as $node) {
if ($node->getId() == $categoryId) {
return [$node];
}
if ($node->getChildren()) {
$result = $this->findPartialTree($node->getChildren(), $categoryId);
if (!empty($result)) {
return $result;
}
}
}
return [];
} | [
"protected",
"function",
"findPartialTree",
"(",
"$",
"tree",
",",
"$",
"categoryId",
")",
"{",
"/** @var AbstractCategoryDocument $node */",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"getId",
"(",
")",
"==",
"$",
"categoryId",
")",
"{",
"return",
"[",
"$",
"node",
"]",
";",
"}",
"if",
"(",
"$",
"node",
"->",
"getChildren",
"(",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"findPartialTree",
"(",
"$",
"node",
"->",
"getChildren",
"(",
")",
",",
"$",
"categoryId",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] | Returns partial tree by category ID.
@param array|\ArrayIterator $tree
@param string $categoryId
@return array | [
"Returns",
"partial",
"tree",
"by",
"category",
"ID",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Service/CategoryService.php#L309-L325 |
393 | dlabas/DlcCategory | src/DlcCategory/Form/BaseForm.php | BaseForm.getCategoryInsertionPointValueOptions | public function getCategoryInsertionPointValueOptions()
{
$trees = $this->getCategoryService()->getAllCategoryTreesAsArray();
$valueOptions = array();
foreach ($trees as $rootId => $tree) {
$valueOptions[$rootId] = array(
'label' => 'Label of category ' . $rootId,
'options' => array()
);
foreach ($tree as $node) {
$category = $node->getNode();
if ($category->getId() == $rootId) {
$valueOptions[$rootId]['label'] = $category->getTitle();
} //else {
$valueOptions[$rootId]['options'][$category->getId()] = str_repeat('-', $node->getLevel()) . $category->getTitle();
//}
}
}
return $valueOptions;
} | php | public function getCategoryInsertionPointValueOptions()
{
$trees = $this->getCategoryService()->getAllCategoryTreesAsArray();
$valueOptions = array();
foreach ($trees as $rootId => $tree) {
$valueOptions[$rootId] = array(
'label' => 'Label of category ' . $rootId,
'options' => array()
);
foreach ($tree as $node) {
$category = $node->getNode();
if ($category->getId() == $rootId) {
$valueOptions[$rootId]['label'] = $category->getTitle();
} //else {
$valueOptions[$rootId]['options'][$category->getId()] = str_repeat('-', $node->getLevel()) . $category->getTitle();
//}
}
}
return $valueOptions;
} | [
"public",
"function",
"getCategoryInsertionPointValueOptions",
"(",
")",
"{",
"$",
"trees",
"=",
"$",
"this",
"->",
"getCategoryService",
"(",
")",
"->",
"getAllCategoryTreesAsArray",
"(",
")",
";",
"$",
"valueOptions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"trees",
"as",
"$",
"rootId",
"=>",
"$",
"tree",
")",
"{",
"$",
"valueOptions",
"[",
"$",
"rootId",
"]",
"=",
"array",
"(",
"'label'",
"=>",
"'Label of category '",
".",
"$",
"rootId",
",",
"'options'",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"node",
")",
"{",
"$",
"category",
"=",
"$",
"node",
"->",
"getNode",
"(",
")",
";",
"if",
"(",
"$",
"category",
"->",
"getId",
"(",
")",
"==",
"$",
"rootId",
")",
"{",
"$",
"valueOptions",
"[",
"$",
"rootId",
"]",
"[",
"'label'",
"]",
"=",
"$",
"category",
"->",
"getTitle",
"(",
")",
";",
"}",
"//else {",
"$",
"valueOptions",
"[",
"$",
"rootId",
"]",
"[",
"'options'",
"]",
"[",
"$",
"category",
"->",
"getId",
"(",
")",
"]",
"=",
"str_repeat",
"(",
"'-'",
",",
"$",
"node",
"->",
"getLevel",
"(",
")",
")",
".",
"$",
"category",
"->",
"getTitle",
"(",
")",
";",
"//}",
"}",
"}",
"return",
"$",
"valueOptions",
";",
"}"
] | Returns all categoies for the category position select box
@return array | [
"Returns",
"all",
"categoies",
"for",
"the",
"category",
"position",
"select",
"box"
] | cd4dbcae8c1c6a373f96fb0ad15ccebad383f256 | https://github.com/dlabas/DlcCategory/blob/cd4dbcae8c1c6a373f96fb0ad15ccebad383f256/src/DlcCategory/Form/BaseForm.php#L76-L99 |
394 | Arcavias/ext-zend | lib/custom/src/MW/Translation/Zend.php | MW_Translation_Zend._getTranslations | protected function _getTranslations( $domain )
{
if( !isset( $this->_translations[$domain] ) )
{
if ( !isset( $this->_translationSources[$domain] ) )
{
$msg = sprintf( 'No translation directory for domain "%1$s" available', $domain );
throw new MW_Translation_Exception( $msg );
}
// Reverse locations so the former gets not overwritten by the later
$locations = array_reverse( $this->_getTranslationFileLocations( $this->_translationSources[$domain], $this->getLocale() ) );
$options = $this->_options;
foreach( $locations as $location )
{
$options['content'] = $location;
$this->_translations[$domain][] = new Zend_Translate( $options );
}
}
return ( isset( $this->_translations[$domain] ) ? $this->_translations[$domain] : array() );
} | php | protected function _getTranslations( $domain )
{
if( !isset( $this->_translations[$domain] ) )
{
if ( !isset( $this->_translationSources[$domain] ) )
{
$msg = sprintf( 'No translation directory for domain "%1$s" available', $domain );
throw new MW_Translation_Exception( $msg );
}
// Reverse locations so the former gets not overwritten by the later
$locations = array_reverse( $this->_getTranslationFileLocations( $this->_translationSources[$domain], $this->getLocale() ) );
$options = $this->_options;
foreach( $locations as $location )
{
$options['content'] = $location;
$this->_translations[$domain][] = new Zend_Translate( $options );
}
}
return ( isset( $this->_translations[$domain] ) ? $this->_translations[$domain] : array() );
} | [
"protected",
"function",
"_getTranslations",
"(",
"$",
"domain",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"domain",
"]",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_translationSources",
"[",
"$",
"domain",
"]",
")",
")",
"{",
"$",
"msg",
"=",
"sprintf",
"(",
"'No translation directory for domain \"%1$s\" available'",
",",
"$",
"domain",
")",
";",
"throw",
"new",
"MW_Translation_Exception",
"(",
"$",
"msg",
")",
";",
"}",
"// Reverse locations so the former gets not overwritten by the later",
"$",
"locations",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"_getTranslationFileLocations",
"(",
"$",
"this",
"->",
"_translationSources",
"[",
"$",
"domain",
"]",
",",
"$",
"this",
"->",
"getLocale",
"(",
")",
")",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"_options",
";",
"foreach",
"(",
"$",
"locations",
"as",
"$",
"location",
")",
"{",
"$",
"options",
"[",
"'content'",
"]",
"=",
"$",
"location",
";",
"$",
"this",
"->",
"_translations",
"[",
"$",
"domain",
"]",
"[",
"]",
"=",
"new",
"Zend_Translate",
"(",
"$",
"options",
")",
";",
"}",
"}",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"domain",
"]",
")",
"?",
"$",
"this",
"->",
"_translations",
"[",
"$",
"domain",
"]",
":",
"array",
"(",
")",
")",
";",
"}"
] | Returns the initialized Zend translation object which contains the translations.
@param string $domain Translation domain
@return array List of translation objects implementing Zend_Translate
@throws MW_Translation_Exception If initialization fails | [
"Returns",
"the",
"initialized",
"Zend",
"translation",
"object",
"which",
"contains",
"the",
"translations",
"."
] | 1d2adc81ae0091a70f1053e0f095d55e656a3c96 | https://github.com/Arcavias/ext-zend/blob/1d2adc81ae0091a70f1053e0f095d55e656a3c96/lib/custom/src/MW/Translation/Zend.php#L133-L155 |
395 | albertvision/MRestFramework | src/Maleeby/MRest/Routing.php | Routing.dispatch | public static function dispatch() {
self::$_config = MRest::getConfig('routing');
$routeData = self::_callDispatcher(self::$_config['dispatcher']);
if (!class_exists($routeData['class']) || !(new \ReflectionClass($routeData['class']))->isInstantiable()) {
throw new \Exception('Application class [' . $routeData['class'] . '] was not found', 404);
}
$class = new $routeData['class']();
if (!is_callable([$class, $routeData['method']])) {
throw new \Exception('Method [' . $routeData['method'] . '] not allowed', 405);
}
return call_user_func_array([$class, $routeData['method']], $routeData['attributes']);
} | php | public static function dispatch() {
self::$_config = MRest::getConfig('routing');
$routeData = self::_callDispatcher(self::$_config['dispatcher']);
if (!class_exists($routeData['class']) || !(new \ReflectionClass($routeData['class']))->isInstantiable()) {
throw new \Exception('Application class [' . $routeData['class'] . '] was not found', 404);
}
$class = new $routeData['class']();
if (!is_callable([$class, $routeData['method']])) {
throw new \Exception('Method [' . $routeData['method'] . '] not allowed', 405);
}
return call_user_func_array([$class, $routeData['method']], $routeData['attributes']);
} | [
"public",
"static",
"function",
"dispatch",
"(",
")",
"{",
"self",
"::",
"$",
"_config",
"=",
"MRest",
"::",
"getConfig",
"(",
"'routing'",
")",
";",
"$",
"routeData",
"=",
"self",
"::",
"_callDispatcher",
"(",
"self",
"::",
"$",
"_config",
"[",
"'dispatcher'",
"]",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"routeData",
"[",
"'class'",
"]",
")",
"||",
"!",
"(",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"routeData",
"[",
"'class'",
"]",
")",
")",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Application class ['",
".",
"$",
"routeData",
"[",
"'class'",
"]",
".",
"'] was not found'",
",",
"404",
")",
";",
"}",
"$",
"class",
"=",
"new",
"$",
"routeData",
"[",
"'class'",
"]",
"(",
")",
";",
"if",
"(",
"!",
"is_callable",
"(",
"[",
"$",
"class",
",",
"$",
"routeData",
"[",
"'method'",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Method ['",
".",
"$",
"routeData",
"[",
"'method'",
"]",
".",
"'] not allowed'",
",",
"405",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"[",
"$",
"class",
",",
"$",
"routeData",
"[",
"'method'",
"]",
"]",
",",
"$",
"routeData",
"[",
"'attributes'",
"]",
")",
";",
"}"
] | Initialization of the Routing class
@return mixed
@throws \Exception | [
"Initialization",
"of",
"the",
"Routing",
"class"
] | 5cb07328f60887b551bf3d129439c6d05f6e4702 | https://github.com/albertvision/MRestFramework/blob/5cb07328f60887b551bf3d129439c6d05f6e4702/src/Maleeby/MRest/Routing.php#L25-L40 |
396 | albertvision/MRestFramework | src/Maleeby/MRest/Routing.php | Routing._callDispatcher | private static function _callDispatcher($dispatcherCallback) {
$dispatcherCallback = $dispatcherCallback[0] !== '\\' ? __NAMESPACE__ . '\\' . $dispatcherCallback : $dispatcherCallback;
if (!is_callable($dispatcherCallback)) {
throw new \Exception('Routing dispacher [' . $dispatcherCallback . '] cannot be called.', 500);
}
return call_user_func_array($dispatcherCallback, [
self::$_uri, self::$_config
]);
} | php | private static function _callDispatcher($dispatcherCallback) {
$dispatcherCallback = $dispatcherCallback[0] !== '\\' ? __NAMESPACE__ . '\\' . $dispatcherCallback : $dispatcherCallback;
if (!is_callable($dispatcherCallback)) {
throw new \Exception('Routing dispacher [' . $dispatcherCallback . '] cannot be called.', 500);
}
return call_user_func_array($dispatcherCallback, [
self::$_uri, self::$_config
]);
} | [
"private",
"static",
"function",
"_callDispatcher",
"(",
"$",
"dispatcherCallback",
")",
"{",
"$",
"dispatcherCallback",
"=",
"$",
"dispatcherCallback",
"[",
"0",
"]",
"!==",
"'\\\\'",
"?",
"__NAMESPACE__",
".",
"'\\\\'",
".",
"$",
"dispatcherCallback",
":",
"$",
"dispatcherCallback",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"dispatcherCallback",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Routing dispacher ['",
".",
"$",
"dispatcherCallback",
".",
"'] cannot be called.'",
",",
"500",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"$",
"dispatcherCallback",
",",
"[",
"self",
"::",
"$",
"_uri",
",",
"self",
"::",
"$",
"_config",
"]",
")",
";",
"}"
] | Calls the route dispatcher which is specified in the configuration.
@param string $dispatcherCallback Dispatcher Callback
@return object
@throws \Exception | [
"Calls",
"the",
"route",
"dispatcher",
"which",
"is",
"specified",
"in",
"the",
"configuration",
"."
] | 5cb07328f60887b551bf3d129439c6d05f6e4702 | https://github.com/albertvision/MRestFramework/blob/5cb07328f60887b551bf3d129439c6d05f6e4702/src/Maleeby/MRest/Routing.php#L50-L60 |
397 | albertvision/MRestFramework | src/Maleeby/MRest/Routing.php | Routing._mainDispatcher | private static function _mainDispatcher($uri, $config) {
$uriInfo = self::analizeUri();
$uri = $uriInfo['uri'];
$uriItems = explode('/', $uri);
$attributes = [];
foreach ($config['routes'] as $routePattern => $className) {
if (preg_match('#' . $routePattern . '#', $uri)) {
$class = $className;
$itemCount = count(explode('/', str_replace('\\/', '/', $routePattern)));
for ($i = 0; $i < $itemCount; $i++) {
unset($uriItems[$i]);
}
$attributes = array_values($uriItems);
break;
}
}
if (!$class) {
$class = self::_getController($uri, 'App\\');
$classUri = self::_getControllerBaseUri($class);
if(strpos($uri, $classUri) === 0 && strlen($uri) > strlen($classUri)) {
$attributesUri = substr($uri, strlen($classUri)+1);
$attributes = explode('/', $attributesUri);
}
}
return [
'class' => self::fixNamespace($class ? $class : self::_getController($uri, 'App\\')),
'method' => strtolower($_SERVER['REQUEST_METHOD']),
'attributes' => $attributes
];
} | php | private static function _mainDispatcher($uri, $config) {
$uriInfo = self::analizeUri();
$uri = $uriInfo['uri'];
$uriItems = explode('/', $uri);
$attributes = [];
foreach ($config['routes'] as $routePattern => $className) {
if (preg_match('#' . $routePattern . '#', $uri)) {
$class = $className;
$itemCount = count(explode('/', str_replace('\\/', '/', $routePattern)));
for ($i = 0; $i < $itemCount; $i++) {
unset($uriItems[$i]);
}
$attributes = array_values($uriItems);
break;
}
}
if (!$class) {
$class = self::_getController($uri, 'App\\');
$classUri = self::_getControllerBaseUri($class);
if(strpos($uri, $classUri) === 0 && strlen($uri) > strlen($classUri)) {
$attributesUri = substr($uri, strlen($classUri)+1);
$attributes = explode('/', $attributesUri);
}
}
return [
'class' => self::fixNamespace($class ? $class : self::_getController($uri, 'App\\')),
'method' => strtolower($_SERVER['REQUEST_METHOD']),
'attributes' => $attributes
];
} | [
"private",
"static",
"function",
"_mainDispatcher",
"(",
"$",
"uri",
",",
"$",
"config",
")",
"{",
"$",
"uriInfo",
"=",
"self",
"::",
"analizeUri",
"(",
")",
";",
"$",
"uri",
"=",
"$",
"uriInfo",
"[",
"'uri'",
"]",
";",
"$",
"uriItems",
"=",
"explode",
"(",
"'/'",
",",
"$",
"uri",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"config",
"[",
"'routes'",
"]",
"as",
"$",
"routePattern",
"=>",
"$",
"className",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#'",
".",
"$",
"routePattern",
".",
"'#'",
",",
"$",
"uri",
")",
")",
"{",
"$",
"class",
"=",
"$",
"className",
";",
"$",
"itemCount",
"=",
"count",
"(",
"explode",
"(",
"'/'",
",",
"str_replace",
"(",
"'\\\\/'",
",",
"'/'",
",",
"$",
"routePattern",
")",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"itemCount",
";",
"$",
"i",
"++",
")",
"{",
"unset",
"(",
"$",
"uriItems",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"attributes",
"=",
"array_values",
"(",
"$",
"uriItems",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"_getController",
"(",
"$",
"uri",
",",
"'App\\\\'",
")",
";",
"$",
"classUri",
"=",
"self",
"::",
"_getControllerBaseUri",
"(",
"$",
"class",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"uri",
",",
"$",
"classUri",
")",
"===",
"0",
"&&",
"strlen",
"(",
"$",
"uri",
")",
">",
"strlen",
"(",
"$",
"classUri",
")",
")",
"{",
"$",
"attributesUri",
"=",
"substr",
"(",
"$",
"uri",
",",
"strlen",
"(",
"$",
"classUri",
")",
"+",
"1",
")",
";",
"$",
"attributes",
"=",
"explode",
"(",
"'/'",
",",
"$",
"attributesUri",
")",
";",
"}",
"}",
"return",
"[",
"'class'",
"=>",
"self",
"::",
"fixNamespace",
"(",
"$",
"class",
"?",
"$",
"class",
":",
"self",
"::",
"_getController",
"(",
"$",
"uri",
",",
"'App\\\\'",
")",
")",
",",
"'method'",
"=>",
"strtolower",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
",",
"'attributes'",
"=>",
"$",
"attributes",
"]",
";",
"}"
] | Main dispatcher. Looks for patterns from the config.
@param string $uri Current URI
@param array $config Routing configuration
@return string Controller's callback | [
"Main",
"dispatcher",
".",
"Looks",
"for",
"patterns",
"from",
"the",
"config",
"."
] | 5cb07328f60887b551bf3d129439c6d05f6e4702 | https://github.com/albertvision/MRestFramework/blob/5cb07328f60887b551bf3d129439c6d05f6e4702/src/Maleeby/MRest/Routing.php#L70-L104 |
398 | albertvision/MRestFramework | src/Maleeby/MRest/Routing.php | Routing._getController | private static function _getController($uri, $namespace) {
$dir = realpath(APP_PATH . '/../' . $namespace) . DIRECTORY_SEPARATOR;
if (!is_dir($dir . $uri)) {
$uriParts = explode('/', $uri, 2);
if (is_dir($dir . $uriParts[0])) {
return self::_getController($uriParts[1], $namespace . $uriParts[0] . '\\');
} elseif (is_file($dir . $uriParts[0] . '.php')) {
$uri = $uriParts[0];
}
} else {
$namespace = $namespace . '\\' . str_replace('/', '\\', $uri);
$uri = '';
}
if (substr($namespace, -1) == '\\') {
$namespace = substr($namespace, 0, strlen($namespace) - 1);
}
if (!$uri) {
$uri = self::getNamespaceDefaultClass($namespace, 'App\\'); // Sets the default class
}
return self::fixNamespace($namespace . '\\' . $uri);
} | php | private static function _getController($uri, $namespace) {
$dir = realpath(APP_PATH . '/../' . $namespace) . DIRECTORY_SEPARATOR;
if (!is_dir($dir . $uri)) {
$uriParts = explode('/', $uri, 2);
if (is_dir($dir . $uriParts[0])) {
return self::_getController($uriParts[1], $namespace . $uriParts[0] . '\\');
} elseif (is_file($dir . $uriParts[0] . '.php')) {
$uri = $uriParts[0];
}
} else {
$namespace = $namespace . '\\' . str_replace('/', '\\', $uri);
$uri = '';
}
if (substr($namespace, -1) == '\\') {
$namespace = substr($namespace, 0, strlen($namespace) - 1);
}
if (!$uri) {
$uri = self::getNamespaceDefaultClass($namespace, 'App\\'); // Sets the default class
}
return self::fixNamespace($namespace . '\\' . $uri);
} | [
"private",
"static",
"function",
"_getController",
"(",
"$",
"uri",
",",
"$",
"namespace",
")",
"{",
"$",
"dir",
"=",
"realpath",
"(",
"APP_PATH",
".",
"'/../'",
".",
"$",
"namespace",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
".",
"$",
"uri",
")",
")",
"{",
"$",
"uriParts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"uri",
",",
"2",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
".",
"$",
"uriParts",
"[",
"0",
"]",
")",
")",
"{",
"return",
"self",
"::",
"_getController",
"(",
"$",
"uriParts",
"[",
"1",
"]",
",",
"$",
"namespace",
".",
"$",
"uriParts",
"[",
"0",
"]",
".",
"'\\\\'",
")",
";",
"}",
"elseif",
"(",
"is_file",
"(",
"$",
"dir",
".",
"$",
"uriParts",
"[",
"0",
"]",
".",
"'.php'",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"uriParts",
"[",
"0",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"namespace",
"=",
"$",
"namespace",
".",
"'\\\\'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"uri",
")",
";",
"$",
"uri",
"=",
"''",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"namespace",
",",
"-",
"1",
")",
"==",
"'\\\\'",
")",
"{",
"$",
"namespace",
"=",
"substr",
"(",
"$",
"namespace",
",",
"0",
",",
"strlen",
"(",
"$",
"namespace",
")",
"-",
"1",
")",
";",
"}",
"if",
"(",
"!",
"$",
"uri",
")",
"{",
"$",
"uri",
"=",
"self",
"::",
"getNamespaceDefaultClass",
"(",
"$",
"namespace",
",",
"'App\\\\'",
")",
";",
"// Sets the default class",
"}",
"return",
"self",
"::",
"fixNamespace",
"(",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"uri",
")",
";",
"}"
] | Returns the controller's data for an URI
@param string $uri URI
@param string $namespace URI namespace
@return array [string uri, string namespace, array defaults] | [
"Returns",
"the",
"controller",
"s",
"data",
"for",
"an",
"URI"
] | 5cb07328f60887b551bf3d129439c6d05f6e4702 | https://github.com/albertvision/MRestFramework/blob/5cb07328f60887b551bf3d129439c6d05f6e4702/src/Maleeby/MRest/Routing.php#L114-L137 |
399 | albertvision/MRestFramework | src/Maleeby/MRest/Routing.php | Routing.getUri | public static function getUri() {
if (self::$_uri === null) {
$uri = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
self::$_uri = self::fixUri(substr($uri, strlen(BASE_URI)));
}
return self::$_uri;
} | php | public static function getUri() {
if (self::$_uri === null) {
$uri = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
self::$_uri = self::fixUri(substr($uri, strlen(BASE_URI)));
}
return self::$_uri;
} | [
"public",
"static",
"function",
"getUri",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_uri",
"===",
"null",
")",
"{",
"$",
"uri",
"=",
"explode",
"(",
"'?'",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
",",
"2",
")",
"[",
"0",
"]",
";",
"self",
"::",
"$",
"_uri",
"=",
"self",
"::",
"fixUri",
"(",
"substr",
"(",
"$",
"uri",
",",
"strlen",
"(",
"BASE_URI",
")",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_uri",
";",
"}"
] | Get the current URI
@return string The current URI | [
"Get",
"the",
"current",
"URI"
] | 5cb07328f60887b551bf3d129439c6d05f6e4702 | https://github.com/albertvision/MRestFramework/blob/5cb07328f60887b551bf3d129439c6d05f6e4702/src/Maleeby/MRest/Routing.php#L174-L180 |