id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
24,600
|
Kris-Kuiper/sFire-Framework
|
src/Permissions/ACL.php
|
ACL.getResources
|
public function getResources($match = null) {
if(null !== $match && false === is_string($match)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($match)), E_USER_ERROR);
}
$permissions = [];
$match = null === $match ? '.*?' : $match;
foreach($this -> permissions as $permission) {
foreach($permission as $type => $value) {
if(preg_match(sprintf('#%s#', str_replace('#', '\#', $match)), $type)) {
$permissions[] = $type;
}
}
}
return array_unique($permissions);
}
|
php
|
public function getResources($match = null) {
if(null !== $match && false === is_string($match)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($match)), E_USER_ERROR);
}
$permissions = [];
$match = null === $match ? '.*?' : $match;
foreach($this -> permissions as $permission) {
foreach($permission as $type => $value) {
if(preg_match(sprintf('#%s#', str_replace('#', '\#', $match)), $type)) {
$permissions[] = $type;
}
}
}
return array_unique($permissions);
}
|
[
"public",
"function",
"getResources",
"(",
"$",
"match",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"match",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"match",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"match",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"permissions",
"=",
"[",
"]",
";",
"$",
"match",
"=",
"null",
"===",
"$",
"match",
"?",
"'.*?'",
":",
"$",
"match",
";",
"foreach",
"(",
"$",
"this",
"->",
"permissions",
"as",
"$",
"permission",
")",
"{",
"foreach",
"(",
"$",
"permission",
"as",
"$",
"type",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"sprintf",
"(",
"'#%s#'",
",",
"str_replace",
"(",
"'#'",
",",
"'\\#'",
",",
"$",
"match",
")",
")",
",",
"$",
"type",
")",
")",
"{",
"$",
"permissions",
"[",
"]",
"=",
"$",
"type",
";",
"}",
"}",
"}",
"return",
"array_unique",
"(",
"$",
"permissions",
")",
";",
"}"
] |
Returns all the resourses in array
@param string|null $match
@return array
|
[
"Returns",
"all",
"the",
"resourses",
"in",
"array"
] |
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
|
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/ACL.php#L168-L188
|
24,601
|
Kris-Kuiper/sFire-Framework
|
src/Permissions/ACL.php
|
ACL.fill
|
private function fill($roles, $resources, $allow) {
if(true === is_string($roles)) {
$roles = [$roles];
}
if(true === is_string($resources)) {
$resources = [$resources];
}
if(false === is_array($roles)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($roles)), E_USER_ERROR);
}
if(false === is_array($resources)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($resources)), E_USER_ERROR);
}
if(false === is_bool($allow)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($allow)), E_USER_ERROR);
}
foreach($roles as $role) {
if(false === is_string($role)) {
return trigger_error(sprintf('Argument 1 passed to %s() must contain only strings, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR);
}
if(false === isset($this -> permissions[$role])) {
$this -> permissions[$role] = [];
}
foreach($resources as $resource) {
if(false === is_string($resource)) {
return trigger_error(sprintf('Argument 2 passed to %s() must contain only strings, "%s" given', __METHOD__, gettype($resource)), E_USER_ERROR);
}
$this -> permissions[$role][$resource] = $allow;
}
}
return $this;
}
|
php
|
private function fill($roles, $resources, $allow) {
if(true === is_string($roles)) {
$roles = [$roles];
}
if(true === is_string($resources)) {
$resources = [$resources];
}
if(false === is_array($roles)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($roles)), E_USER_ERROR);
}
if(false === is_array($resources)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($resources)), E_USER_ERROR);
}
if(false === is_bool($allow)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($allow)), E_USER_ERROR);
}
foreach($roles as $role) {
if(false === is_string($role)) {
return trigger_error(sprintf('Argument 1 passed to %s() must contain only strings, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR);
}
if(false === isset($this -> permissions[$role])) {
$this -> permissions[$role] = [];
}
foreach($resources as $resource) {
if(false === is_string($resource)) {
return trigger_error(sprintf('Argument 2 passed to %s() must contain only strings, "%s" given', __METHOD__, gettype($resource)), E_USER_ERROR);
}
$this -> permissions[$role][$resource] = $allow;
}
}
return $this;
}
|
[
"private",
"function",
"fill",
"(",
"$",
"roles",
",",
"$",
"resources",
",",
"$",
"allow",
")",
"{",
"if",
"(",
"true",
"===",
"is_string",
"(",
"$",
"roles",
")",
")",
"{",
"$",
"roles",
"=",
"[",
"$",
"roles",
"]",
";",
"}",
"if",
"(",
"true",
"===",
"is_string",
"(",
"$",
"resources",
")",
")",
"{",
"$",
"resources",
"=",
"[",
"$",
"resources",
"]",
";",
"}",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"roles",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string or array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"roles",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"resources",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string or array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"resources",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_bool",
"(",
"$",
"allow",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 3 passed to %s() must be of the type boolean, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"allow",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"role",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must contain only strings, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"role",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"permissions",
"[",
"$",
"role",
"]",
")",
")",
"{",
"$",
"this",
"->",
"permissions",
"[",
"$",
"role",
"]",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"resources",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"resource",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must contain only strings, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"resource",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"permissions",
"[",
"$",
"role",
"]",
"[",
"$",
"resource",
"]",
"=",
"$",
"allow",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add a new permission entry
@param string|array $roles
@param string|array $resources
@param boolean $allow
@return sFire\Permissions\ACL
|
[
"Add",
"a",
"new",
"permission",
"entry"
] |
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
|
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/ACL.php#L198-L241
|
24,602
|
Wedeto/IO
|
src/File.php
|
File.touch
|
public function touch()
{
// Check permissions
$path = $this->getFullPath();
if (file_exists($path))
{
if (!is_writable($path))
Path::makeWritable($path);
}
touch($path);
Path::setPermissions($path);
}
|
php
|
public function touch()
{
// Check permissions
$path = $this->getFullPath();
if (file_exists($path))
{
if (!is_writable($path))
Path::makeWritable($path);
}
touch($path);
Path::setPermissions($path);
}
|
[
"public",
"function",
"touch",
"(",
")",
"{",
"// Check permissions",
"$",
"path",
"=",
"$",
"this",
"->",
"getFullPath",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"path",
")",
")",
"Path",
"::",
"makeWritable",
"(",
"$",
"path",
")",
";",
"}",
"touch",
"(",
"$",
"path",
")",
";",
"Path",
"::",
"setPermissions",
"(",
"$",
"path",
")",
";",
"}"
] |
Touch the file, updating its permissions
|
[
"Touch",
"the",
"file",
"updating",
"its",
"permissions"
] |
4cfeaedd1bd9bda3097d18cb12233a4afecb2e85
|
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/File.php#L47-L59
|
24,603
|
Wedeto/IO
|
src/File.php
|
File.getMime
|
public function getMime()
{
if (!$this->mime)
{
$type = FileType::getFromFile($this->getFullPath());
$this->mime = $type->getMimeType();
}
return $this->mime;
}
|
php
|
public function getMime()
{
if (!$this->mime)
{
$type = FileType::getFromFile($this->getFullPath());
$this->mime = $type->getMimeType();
}
return $this->mime;
}
|
[
"public",
"function",
"getMime",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"mime",
")",
"{",
"$",
"type",
"=",
"FileType",
"::",
"getFromFile",
"(",
"$",
"this",
"->",
"getFullPath",
"(",
")",
")",
";",
"$",
"this",
"->",
"mime",
"=",
"$",
"type",
"->",
"getMimeType",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"mime",
";",
"}"
] |
Return the appropriate mime type for the file
|
[
"Return",
"the",
"appropriate",
"mime",
"type",
"for",
"the",
"file"
] |
4cfeaedd1bd9bda3097d18cb12233a4afecb2e85
|
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/File.php#L84-L92
|
24,604
|
Wedeto/IO
|
src/File.php
|
File.open
|
public function open(string $mode)
{
$read = strpbrk($mode, "r+") !== false;
$write = strpbrk($mode, "waxc+") !== false;
$x = strpbrk($mode, "x") !== false;
$path = $this->getFullPath();
$fh = @fopen($path, $mode);
if (is_resource($fh))
return $fh;
if ($x && file_exists($path))
throw new IOException("File already exists: " . $path);
if ($write && !is_writable($path))
throw new IOException("File is not writable: " . $path);
if ($read && !is_readable($path))
throw new IOException("File is not readable: " . $path);
throw new IOException("Invalid mode for opening file: " . $mode);
}
|
php
|
public function open(string $mode)
{
$read = strpbrk($mode, "r+") !== false;
$write = strpbrk($mode, "waxc+") !== false;
$x = strpbrk($mode, "x") !== false;
$path = $this->getFullPath();
$fh = @fopen($path, $mode);
if (is_resource($fh))
return $fh;
if ($x && file_exists($path))
throw new IOException("File already exists: " . $path);
if ($write && !is_writable($path))
throw new IOException("File is not writable: " . $path);
if ($read && !is_readable($path))
throw new IOException("File is not readable: " . $path);
throw new IOException("Invalid mode for opening file: " . $mode);
}
|
[
"public",
"function",
"open",
"(",
"string",
"$",
"mode",
")",
"{",
"$",
"read",
"=",
"strpbrk",
"(",
"$",
"mode",
",",
"\"r+\"",
")",
"!==",
"false",
";",
"$",
"write",
"=",
"strpbrk",
"(",
"$",
"mode",
",",
"\"waxc+\"",
")",
"!==",
"false",
";",
"$",
"x",
"=",
"strpbrk",
"(",
"$",
"mode",
",",
"\"x\"",
")",
"!==",
"false",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getFullPath",
"(",
")",
";",
"$",
"fh",
"=",
"@",
"fopen",
"(",
"$",
"path",
",",
"$",
"mode",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"fh",
")",
")",
"return",
"$",
"fh",
";",
"if",
"(",
"$",
"x",
"&&",
"file_exists",
"(",
"$",
"path",
")",
")",
"throw",
"new",
"IOException",
"(",
"\"File already exists: \"",
".",
"$",
"path",
")",
";",
"if",
"(",
"$",
"write",
"&&",
"!",
"is_writable",
"(",
"$",
"path",
")",
")",
"throw",
"new",
"IOException",
"(",
"\"File is not writable: \"",
".",
"$",
"path",
")",
";",
"if",
"(",
"$",
"read",
"&&",
"!",
"is_readable",
"(",
"$",
"path",
")",
")",
"throw",
"new",
"IOException",
"(",
"\"File is not readable: \"",
".",
"$",
"path",
")",
";",
"throw",
"new",
"IOException",
"(",
"\"Invalid mode for opening file: \"",
".",
"$",
"mode",
")",
";",
"}"
] |
Open the file for reading or writing, throwing informative
exceptions when it fails.
@param string $mode The file opening mode
@return resource The opened file resource
@throws IOException When opening the file failed.
@seealso fopen
|
[
"Open",
"the",
"file",
"for",
"reading",
"or",
"writing",
"throwing",
"informative",
"exceptions",
"when",
"it",
"fails",
"."
] |
4cfeaedd1bd9bda3097d18cb12233a4afecb2e85
|
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/File.php#L154-L173
|
24,605
|
lanfisis/deflection
|
src/Deflection/Transformer.php
|
Transformer.arrayToClassElement
|
public function arrayToClassElement($definition)
{
$class = new Classes();
if (isset($definition['docblock'])) {
$docblock = $this->arrayToDocblockElement($definition['docblock']);
$class->setDocbloc($docblock);
}
if (isset($definition['namespace'])) {
$class->setNamespace($definition['namespace']);
}
if (isset($definition['name'])) {
$class->setName($definition['name']);
}
if (isset($definition['extends'])) {
$class->setExtends($definition['extends']);
}
if (isset($definition['implements'])) {
foreach ($definition['implements'] as $interface) {
$class->addImplements($interface);
}
}
if (isset($definition['uses'])) {
foreach ($definition['uses'] as $alias => $use) {
$alias = is_string($alias) ? $alias : null;
$class->addUse($use, $alias);
}
}
if (isset($definition['functions'])) {
foreach ($definition['functions'] as $definition) {
$function = $this->arrayToFunctionElement($definition);
$class->addFunction($function);
}
}
return $class;
}
|
php
|
public function arrayToClassElement($definition)
{
$class = new Classes();
if (isset($definition['docblock'])) {
$docblock = $this->arrayToDocblockElement($definition['docblock']);
$class->setDocbloc($docblock);
}
if (isset($definition['namespace'])) {
$class->setNamespace($definition['namespace']);
}
if (isset($definition['name'])) {
$class->setName($definition['name']);
}
if (isset($definition['extends'])) {
$class->setExtends($definition['extends']);
}
if (isset($definition['implements'])) {
foreach ($definition['implements'] as $interface) {
$class->addImplements($interface);
}
}
if (isset($definition['uses'])) {
foreach ($definition['uses'] as $alias => $use) {
$alias = is_string($alias) ? $alias : null;
$class->addUse($use, $alias);
}
}
if (isset($definition['functions'])) {
foreach ($definition['functions'] as $definition) {
$function = $this->arrayToFunctionElement($definition);
$class->addFunction($function);
}
}
return $class;
}
|
[
"public",
"function",
"arrayToClassElement",
"(",
"$",
"definition",
")",
"{",
"$",
"class",
"=",
"new",
"Classes",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'docblock'",
"]",
")",
")",
"{",
"$",
"docblock",
"=",
"$",
"this",
"->",
"arrayToDocblockElement",
"(",
"$",
"definition",
"[",
"'docblock'",
"]",
")",
";",
"$",
"class",
"->",
"setDocbloc",
"(",
"$",
"docblock",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'namespace'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setNamespace",
"(",
"$",
"definition",
"[",
"'namespace'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setName",
"(",
"$",
"definition",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'extends'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setExtends",
"(",
"$",
"definition",
"[",
"'extends'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'implements'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"definition",
"[",
"'implements'",
"]",
"as",
"$",
"interface",
")",
"{",
"$",
"class",
"->",
"addImplements",
"(",
"$",
"interface",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'uses'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"definition",
"[",
"'uses'",
"]",
"as",
"$",
"alias",
"=>",
"$",
"use",
")",
"{",
"$",
"alias",
"=",
"is_string",
"(",
"$",
"alias",
")",
"?",
"$",
"alias",
":",
"null",
";",
"$",
"class",
"->",
"addUse",
"(",
"$",
"use",
",",
"$",
"alias",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'functions'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"definition",
"[",
"'functions'",
"]",
"as",
"$",
"definition",
")",
"{",
"$",
"function",
"=",
"$",
"this",
"->",
"arrayToFunctionElement",
"(",
"$",
"definition",
")",
";",
"$",
"class",
"->",
"addFunction",
"(",
"$",
"function",
")",
";",
"}",
"}",
"return",
"$",
"class",
";",
"}"
] |
Transform an array to a class element object
@param array $definition Class definitoion
@return Deflection\Element\Classes
|
[
"Transform",
"an",
"array",
"to",
"a",
"class",
"element",
"object"
] |
31deaf7f085d6456d8a323e7ac3cc9914fbe49a9
|
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Transformer.php#L26-L60
|
24,606
|
lanfisis/deflection
|
src/Deflection/Transformer.php
|
Transformer.arrayToDocblockElement
|
public function arrayToDocblockElement(array $definition)
{
$docblock = new Docblock();
if (isset($definition['description'])) {
$docblock->setDescription($definition['description']);
}
if (isset($definition['params'])) {
foreach ($definition['params'] as $param => $infos) {
$type = isset($infos['type']) ? $infos['type']: '';
$description = isset($infos['description']) ? $infos['description'] : '';
$docblock->addVar($param, $type, $description);
}
}
if (isset($definition['return'])) {
$docblock->addParam('return', $definition['return']);
}
if (isset($definition['infos'])) {
foreach ($definition['infos'] as $name => $value) {
$docblock->addParam($name, $value);
}
}
return $docblock;
}
|
php
|
public function arrayToDocblockElement(array $definition)
{
$docblock = new Docblock();
if (isset($definition['description'])) {
$docblock->setDescription($definition['description']);
}
if (isset($definition['params'])) {
foreach ($definition['params'] as $param => $infos) {
$type = isset($infos['type']) ? $infos['type']: '';
$description = isset($infos['description']) ? $infos['description'] : '';
$docblock->addVar($param, $type, $description);
}
}
if (isset($definition['return'])) {
$docblock->addParam('return', $definition['return']);
}
if (isset($definition['infos'])) {
foreach ($definition['infos'] as $name => $value) {
$docblock->addParam($name, $value);
}
}
return $docblock;
}
|
[
"public",
"function",
"arrayToDocblockElement",
"(",
"array",
"$",
"definition",
")",
"{",
"$",
"docblock",
"=",
"new",
"Docblock",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"docblock",
"->",
"setDescription",
"(",
"$",
"definition",
"[",
"'description'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'params'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"definition",
"[",
"'params'",
"]",
"as",
"$",
"param",
"=>",
"$",
"infos",
")",
"{",
"$",
"type",
"=",
"isset",
"(",
"$",
"infos",
"[",
"'type'",
"]",
")",
"?",
"$",
"infos",
"[",
"'type'",
"]",
":",
"''",
";",
"$",
"description",
"=",
"isset",
"(",
"$",
"infos",
"[",
"'description'",
"]",
")",
"?",
"$",
"infos",
"[",
"'description'",
"]",
":",
"''",
";",
"$",
"docblock",
"->",
"addVar",
"(",
"$",
"param",
",",
"$",
"type",
",",
"$",
"description",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'return'",
"]",
")",
")",
"{",
"$",
"docblock",
"->",
"addParam",
"(",
"'return'",
",",
"$",
"definition",
"[",
"'return'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'infos'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"definition",
"[",
"'infos'",
"]",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"docblock",
"->",
"addParam",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"docblock",
";",
"}"
] |
Returns well formated header with descriptions, param, return, ...
@param array $definition Header definition
@return Deflection\Element\Docblock
|
[
"Returns",
"well",
"formated",
"header",
"with",
"descriptions",
"param",
"return",
"..."
] |
31deaf7f085d6456d8a323e7ac3cc9914fbe49a9
|
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Transformer.php#L69-L91
|
24,607
|
lanfisis/deflection
|
src/Deflection/Transformer.php
|
Transformer.arrayToFunctionElement
|
public function arrayToFunctionElement(array $definition)
{
$function = new Functions;
if (isset($definition['docblock'])) {
$docblock = $this->arrayToDocblockElement($definition['docblock']);
$function->setDocbloc($docblock);
}
if (isset($definition['public'])) {
$function->isPublic(true);
}
if (isset($definition['name'])) {
$function->setName($definition['name']);
}
if (isset($definition['params'])) {
foreach ($definition['params'] as $name => $type) {
$function->addParam($name, $type);
}
}
if (isset($definition['content'])) {
$function->setContent($definition['content']);
}
return $function;
}
|
php
|
public function arrayToFunctionElement(array $definition)
{
$function = new Functions;
if (isset($definition['docblock'])) {
$docblock = $this->arrayToDocblockElement($definition['docblock']);
$function->setDocbloc($docblock);
}
if (isset($definition['public'])) {
$function->isPublic(true);
}
if (isset($definition['name'])) {
$function->setName($definition['name']);
}
if (isset($definition['params'])) {
foreach ($definition['params'] as $name => $type) {
$function->addParam($name, $type);
}
}
if (isset($definition['content'])) {
$function->setContent($definition['content']);
}
return $function;
}
|
[
"public",
"function",
"arrayToFunctionElement",
"(",
"array",
"$",
"definition",
")",
"{",
"$",
"function",
"=",
"new",
"Functions",
";",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'docblock'",
"]",
")",
")",
"{",
"$",
"docblock",
"=",
"$",
"this",
"->",
"arrayToDocblockElement",
"(",
"$",
"definition",
"[",
"'docblock'",
"]",
")",
";",
"$",
"function",
"->",
"setDocbloc",
"(",
"$",
"docblock",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'public'",
"]",
")",
")",
"{",
"$",
"function",
"->",
"isPublic",
"(",
"true",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"function",
"->",
"setName",
"(",
"$",
"definition",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'params'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"definition",
"[",
"'params'",
"]",
"as",
"$",
"name",
"=>",
"$",
"type",
")",
"{",
"$",
"function",
"->",
"addParam",
"(",
"$",
"name",
",",
"$",
"type",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"function",
"->",
"setContent",
"(",
"$",
"definition",
"[",
"'content'",
"]",
")",
";",
"}",
"return",
"$",
"function",
";",
"}"
] |
Returns well formated function declaration
@param array $definition Functions definition
@return Deflection\Element\Functions
|
[
"Returns",
"well",
"formated",
"function",
"declaration"
] |
31deaf7f085d6456d8a323e7ac3cc9914fbe49a9
|
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Transformer.php#L100-L122
|
24,608
|
rzajac/phptools
|
src/Helper/Err.php
|
Err.errToException
|
public static function errToException($turnOn = true)
{
if (!$turnOn) {
return set_error_handler(null);
}
/*
* Error handler
*
* @param int $errno
* @param string $errStr
* @param string $errFile
* @param int $errLine
*
* @throws ErrorException
*/
$handler = function ($errno, $errStr, $errFile, $errLine) {
// This error code is not included in error_reporting
if (!(error_reporting() & $errno)) {
return;
}
throw new ErrorException($errStr, 0, $errno, $errFile, $errLine);
};
return set_error_handler($handler);
}
|
php
|
public static function errToException($turnOn = true)
{
if (!$turnOn) {
return set_error_handler(null);
}
/*
* Error handler
*
* @param int $errno
* @param string $errStr
* @param string $errFile
* @param int $errLine
*
* @throws ErrorException
*/
$handler = function ($errno, $errStr, $errFile, $errLine) {
// This error code is not included in error_reporting
if (!(error_reporting() & $errno)) {
return;
}
throw new ErrorException($errStr, 0, $errno, $errFile, $errLine);
};
return set_error_handler($handler);
}
|
[
"public",
"static",
"function",
"errToException",
"(",
"$",
"turnOn",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"turnOn",
")",
"{",
"return",
"set_error_handler",
"(",
"null",
")",
";",
"}",
"/*\n * Error handler\n *\n * @param int $errno\n * @param string $errStr\n * @param string $errFile\n * @param int $errLine\n *\n * @throws ErrorException\n */",
"$",
"handler",
"=",
"function",
"(",
"$",
"errno",
",",
"$",
"errStr",
",",
"$",
"errFile",
",",
"$",
"errLine",
")",
"{",
"// This error code is not included in error_reporting",
"if",
"(",
"!",
"(",
"error_reporting",
"(",
")",
"&",
"$",
"errno",
")",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"ErrorException",
"(",
"$",
"errStr",
",",
"0",
",",
"$",
"errno",
",",
"$",
"errFile",
",",
"$",
"errLine",
")",
";",
"}",
";",
"return",
"set_error_handler",
"(",
"$",
"handler",
")",
";",
"}"
] |
Change errors to exceptions.
@see http://php.net/manual/en/class.errorexception.php
@param bool $turnOn Set to false to turn off user defined error exception handling and set the default one.
@return mixed
|
[
"Change",
"errors",
"to",
"exceptions",
"."
] |
3cbece7645942d244603c14ba897d8a676ee3088
|
https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Err.php#L38-L63
|
24,609
|
peridot-php/peridot-scope
|
src/Scope.php
|
Scope.&
|
public function &__get($name)
{
list($result, $found) = $this->peridotScanChildren($this, function ($childScope, &$accumulator) use ($name) {
if (property_exists($childScope, $name)) {
$accumulator = [$childScope->$name, true, $childScope];
}
});
if (!$found) {
throw new DomainException("Scope property $name not found");
}
return $result;
}
|
php
|
public function &__get($name)
{
list($result, $found) = $this->peridotScanChildren($this, function ($childScope, &$accumulator) use ($name) {
if (property_exists($childScope, $name)) {
$accumulator = [$childScope->$name, true, $childScope];
}
});
if (!$found) {
throw new DomainException("Scope property $name not found");
}
return $result;
}
|
[
"public",
"function",
"&",
"__get",
"(",
"$",
"name",
")",
"{",
"list",
"(",
"$",
"result",
",",
"$",
"found",
")",
"=",
"$",
"this",
"->",
"peridotScanChildren",
"(",
"$",
"this",
",",
"function",
"(",
"$",
"childScope",
",",
"&",
"$",
"accumulator",
")",
"use",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"childScope",
",",
"$",
"name",
")",
")",
"{",
"$",
"accumulator",
"=",
"[",
"$",
"childScope",
"->",
"$",
"name",
",",
"true",
",",
"$",
"childScope",
"]",
";",
"}",
"}",
")",
";",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"\"Scope property $name not found\"",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Lookup properties on child scopes.
@param $name
@return mixed
@throws DomainException
|
[
"Lookup",
"properties",
"on",
"child",
"scopes",
"."
] |
baabb128c805f84279c1506435120314ac09d9ff
|
https://github.com/peridot-php/peridot-scope/blob/baabb128c805f84279c1506435120314ac09d9ff/src/Scope.php#L106-L117
|
24,610
|
peridot-php/peridot-scope
|
src/Scope.php
|
Scope.peridotScanChildren
|
protected function peridotScanChildren(Scope $scope, callable $fn, &$accumulator = [])
{
if (! empty($accumulator)) {
return $accumulator;
}
$children = $scope->peridotGetChildScopes();
foreach ($children as $childScope) {
$fn($childScope, $accumulator);
$this->peridotScanChildren($childScope, $fn, $accumulator);
}
if (empty($accumulator)) {
return [null, false];
}
return $accumulator;
}
|
php
|
protected function peridotScanChildren(Scope $scope, callable $fn, &$accumulator = [])
{
if (! empty($accumulator)) {
return $accumulator;
}
$children = $scope->peridotGetChildScopes();
foreach ($children as $childScope) {
$fn($childScope, $accumulator);
$this->peridotScanChildren($childScope, $fn, $accumulator);
}
if (empty($accumulator)) {
return [null, false];
}
return $accumulator;
}
|
[
"protected",
"function",
"peridotScanChildren",
"(",
"Scope",
"$",
"scope",
",",
"callable",
"$",
"fn",
",",
"&",
"$",
"accumulator",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"accumulator",
")",
")",
"{",
"return",
"$",
"accumulator",
";",
"}",
"$",
"children",
"=",
"$",
"scope",
"->",
"peridotGetChildScopes",
"(",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"childScope",
")",
"{",
"$",
"fn",
"(",
"$",
"childScope",
",",
"$",
"accumulator",
")",
";",
"$",
"this",
"->",
"peridotScanChildren",
"(",
"$",
"childScope",
",",
"$",
"fn",
",",
"$",
"accumulator",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"accumulator",
")",
")",
"{",
"return",
"[",
"null",
",",
"false",
"]",
";",
"}",
"return",
"$",
"accumulator",
";",
"}"
] |
Scan child scopes and execute a function against each one passing an
accumulator reference along.
@param Scope $scope
@param callable $fn
@param array $accumulator
@return array
|
[
"Scan",
"child",
"scopes",
"and",
"execute",
"a",
"function",
"against",
"each",
"one",
"passing",
"an",
"accumulator",
"reference",
"along",
"."
] |
baabb128c805f84279c1506435120314ac09d9ff
|
https://github.com/peridot-php/peridot-scope/blob/baabb128c805f84279c1506435120314ac09d9ff/src/Scope.php#L128-L145
|
24,611
|
netzmacht-archive/subcolumns_bootstrap_customizable
|
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
|
ColumnSet.prepareContainer
|
public static function prepareContainer($id)
{
// use array key exists so non existing column will researched
if(array_key_exists('id', self::$container)) {
return static::$container[$id];
}
$model = ColumnsetModel::findByPk($id);
if($model === null)
{
static::$container[$id] = null;
return null;
}
$sizes = deserialize($model->sizes, true);
$container = array();
foreach($sizes as $size)
{
$key = 'columnset_' . $size;
$columns = deserialize($model->{$key}, true);
foreach($columns as $index => $column) {
if(isset($container[$index][0])) {
$container[$index][0] .= ' ' . self::prepareSize($size, deserialize($column, true));
}
else {
$container[$index][0] .= self::prepareSize($size, deserialize($column, true));
}
}
}
static::$container[$id] = $container;
return $container;
}
|
php
|
public static function prepareContainer($id)
{
// use array key exists so non existing column will researched
if(array_key_exists('id', self::$container)) {
return static::$container[$id];
}
$model = ColumnsetModel::findByPk($id);
if($model === null)
{
static::$container[$id] = null;
return null;
}
$sizes = deserialize($model->sizes, true);
$container = array();
foreach($sizes as $size)
{
$key = 'columnset_' . $size;
$columns = deserialize($model->{$key}, true);
foreach($columns as $index => $column) {
if(isset($container[$index][0])) {
$container[$index][0] .= ' ' . self::prepareSize($size, deserialize($column, true));
}
else {
$container[$index][0] .= self::prepareSize($size, deserialize($column, true));
}
}
}
static::$container[$id] = $container;
return $container;
}
|
[
"public",
"static",
"function",
"prepareContainer",
"(",
"$",
"id",
")",
"{",
"// use array key exists so non existing column will researched",
"if",
"(",
"array_key_exists",
"(",
"'id'",
",",
"self",
"::",
"$",
"container",
")",
")",
"{",
"return",
"static",
"::",
"$",
"container",
"[",
"$",
"id",
"]",
";",
"}",
"$",
"model",
"=",
"ColumnsetModel",
"::",
"findByPk",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"model",
"===",
"null",
")",
"{",
"static",
"::",
"$",
"container",
"[",
"$",
"id",
"]",
"=",
"null",
";",
"return",
"null",
";",
"}",
"$",
"sizes",
"=",
"deserialize",
"(",
"$",
"model",
"->",
"sizes",
",",
"true",
")",
";",
"$",
"container",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sizes",
"as",
"$",
"size",
")",
"{",
"$",
"key",
"=",
"'columnset_'",
".",
"$",
"size",
";",
"$",
"columns",
"=",
"deserialize",
"(",
"$",
"model",
"->",
"{",
"$",
"key",
"}",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"index",
"=>",
"$",
"column",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"container",
"[",
"$",
"index",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"container",
"[",
"$",
"index",
"]",
"[",
"0",
"]",
".=",
"' '",
".",
"self",
"::",
"prepareSize",
"(",
"$",
"size",
",",
"deserialize",
"(",
"$",
"column",
",",
"true",
")",
")",
";",
"}",
"else",
"{",
"$",
"container",
"[",
"$",
"index",
"]",
"[",
"0",
"]",
".=",
"self",
"::",
"prepareSize",
"(",
"$",
"size",
",",
"deserialize",
"(",
"$",
"column",
",",
"true",
")",
")",
";",
"}",
"}",
"}",
"static",
"::",
"$",
"container",
"[",
"$",
"id",
"]",
"=",
"$",
"container",
";",
"return",
"$",
"container",
";",
"}"
] |
prepare the container which sub columns expects
@param int $id id of the columnset
@return array
|
[
"prepare",
"the",
"container",
"which",
"sub",
"columns",
"expects"
] |
c0f63755282451fad670ceaa49b984bfabf9e4ee
|
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L39-L75
|
24,612
|
netzmacht-archive/subcolumns_bootstrap_customizable
|
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
|
ColumnSet.prepareSize
|
protected static function prepareSize($size, array $definition)
{
$css = sprintf('col-%s-%s', $size, $definition['width']);
if($definition['offset']) {
$css .= sprintf(' col-%s-offset-%s', $size, $definition['offset']);
}
if($definition['order']) {
$css .= sprintf(' col-%s-%s', $size, $definition['order']);
}
return $css;
}
|
php
|
protected static function prepareSize($size, array $definition)
{
$css = sprintf('col-%s-%s', $size, $definition['width']);
if($definition['offset']) {
$css .= sprintf(' col-%s-offset-%s', $size, $definition['offset']);
}
if($definition['order']) {
$css .= sprintf(' col-%s-%s', $size, $definition['order']);
}
return $css;
}
|
[
"protected",
"static",
"function",
"prepareSize",
"(",
"$",
"size",
",",
"array",
"$",
"definition",
")",
"{",
"$",
"css",
"=",
"sprintf",
"(",
"'col-%s-%s'",
",",
"$",
"size",
",",
"$",
"definition",
"[",
"'width'",
"]",
")",
";",
"if",
"(",
"$",
"definition",
"[",
"'offset'",
"]",
")",
"{",
"$",
"css",
".=",
"sprintf",
"(",
"' col-%s-offset-%s'",
",",
"$",
"size",
",",
"$",
"definition",
"[",
"'offset'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"definition",
"[",
"'order'",
"]",
")",
"{",
"$",
"css",
".=",
"sprintf",
"(",
"' col-%s-%s'",
",",
"$",
"size",
",",
"$",
"definition",
"[",
"'order'",
"]",
")",
";",
"}",
"return",
"$",
"css",
";",
"}"
] |
generates the css class defnition for one column
@param string $size the selected size
@param array $definition the column definition
@return string
|
[
"generates",
"the",
"css",
"class",
"defnition",
"for",
"one",
"column"
] |
c0f63755282451fad670ceaa49b984bfabf9e4ee
|
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L85-L98
|
24,613
|
netzmacht-archive/subcolumns_bootstrap_customizable
|
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
|
ColumnSet.appendColumnsetIdToPalette
|
public function appendColumnsetIdToPalette($dc)
{
if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') {
return;
}
if($dc->table == 'tl_content') {
$model = \ContentModel::findByPK($dc->id);
if($model->sc_type > 0) {
\MetaPalettes::appendFields($dc->table, 'colsetStart', 'colset', array('columnset_id'));
}
}
else {
$model = \ModuleModel::findByPk($dc->id);
if($model->sc_type > 0) {
if($model->sc_type > 0) {
$GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns'] = str_replace(
'sc_type,',
'sc_type,columnset_id,',
$GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns']
);
}
}
}
}
|
php
|
public function appendColumnsetIdToPalette($dc)
{
if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') {
return;
}
if($dc->table == 'tl_content') {
$model = \ContentModel::findByPK($dc->id);
if($model->sc_type > 0) {
\MetaPalettes::appendFields($dc->table, 'colsetStart', 'colset', array('columnset_id'));
}
}
else {
$model = \ModuleModel::findByPk($dc->id);
if($model->sc_type > 0) {
if($model->sc_type > 0) {
$GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns'] = str_replace(
'sc_type,',
'sc_type,columnset_id,',
$GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns']
);
}
}
}
}
|
[
"public",
"function",
"appendColumnsetIdToPalette",
"(",
"$",
"dc",
")",
"{",
"if",
"(",
"$",
"GLOBALS",
"[",
"'TL_CONFIG'",
"]",
"[",
"'subcolumns'",
"]",
"!=",
"'bootstrap_customizable'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"dc",
"->",
"table",
"==",
"'tl_content'",
")",
"{",
"$",
"model",
"=",
"\\",
"ContentModel",
"::",
"findByPK",
"(",
"$",
"dc",
"->",
"id",
")",
";",
"if",
"(",
"$",
"model",
"->",
"sc_type",
">",
"0",
")",
"{",
"\\",
"MetaPalettes",
"::",
"appendFields",
"(",
"$",
"dc",
"->",
"table",
",",
"'colsetStart'",
",",
"'colset'",
",",
"array",
"(",
"'columnset_id'",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"model",
"=",
"\\",
"ModuleModel",
"::",
"findByPk",
"(",
"$",
"dc",
"->",
"id",
")",
";",
"if",
"(",
"$",
"model",
"->",
"sc_type",
">",
"0",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"sc_type",
">",
"0",
")",
"{",
"$",
"GLOBALS",
"[",
"'TL_DCA'",
"]",
"[",
"'tl_module'",
"]",
"[",
"'palettes'",
"]",
"[",
"'subcolumns'",
"]",
"=",
"str_replace",
"(",
"'sc_type,'",
",",
"'sc_type,columnset_id,'",
",",
"$",
"GLOBALS",
"[",
"'TL_DCA'",
"]",
"[",
"'tl_module'",
"]",
"[",
"'palettes'",
"]",
"[",
"'subcolumns'",
"]",
")",
";",
"}",
"}",
"}",
"}"
] |
add column set field to the colsetStart content element. We need to do it dynamically because subcolumns
creates its palette dynamically
@param $dc
|
[
"add",
"column",
"set",
"field",
"to",
"the",
"colsetStart",
"content",
"element",
".",
"We",
"need",
"to",
"do",
"it",
"dynamically",
"because",
"subcolumns",
"creates",
"its",
"palette",
"dynamically"
] |
c0f63755282451fad670ceaa49b984bfabf9e4ee
|
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L107-L133
|
24,614
|
netzmacht-archive/subcolumns_bootstrap_customizable
|
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
|
ColumnSet.appendColumnSizesToPalette
|
public function appendColumnSizesToPalette($dc)
{
$model = ColumnsetModel::findByPk($dc->id);
$sizes = array_merge(deserialize($model->sizes, true));
foreach($sizes as $size)
{
$field = 'columnset_' . $size;
\MetaPalettes::appendFields('tl_columnset', 'columnset', array($field));
}
}
|
php
|
public function appendColumnSizesToPalette($dc)
{
$model = ColumnsetModel::findByPk($dc->id);
$sizes = array_merge(deserialize($model->sizes, true));
foreach($sizes as $size)
{
$field = 'columnset_' . $size;
\MetaPalettes::appendFields('tl_columnset', 'columnset', array($field));
}
}
|
[
"public",
"function",
"appendColumnSizesToPalette",
"(",
"$",
"dc",
")",
"{",
"$",
"model",
"=",
"ColumnsetModel",
"::",
"findByPk",
"(",
"$",
"dc",
"->",
"id",
")",
";",
"$",
"sizes",
"=",
"array_merge",
"(",
"deserialize",
"(",
"$",
"model",
"->",
"sizes",
",",
"true",
")",
")",
";",
"foreach",
"(",
"$",
"sizes",
"as",
"$",
"size",
")",
"{",
"$",
"field",
"=",
"'columnset_'",
".",
"$",
"size",
";",
"\\",
"MetaPalettes",
"::",
"appendFields",
"(",
"'tl_columnset'",
",",
"'columnset'",
",",
"array",
"(",
"$",
"field",
")",
")",
";",
"}",
"}"
] |
Append column sizes fields dynamically to the palettes. Not using
@param $dc
|
[
"Append",
"column",
"sizes",
"fields",
"dynamically",
"to",
"the",
"palettes",
".",
"Not",
"using"
] |
c0f63755282451fad670ceaa49b984bfabf9e4ee
|
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L140-L151
|
24,615
|
netzmacht-archive/subcolumns_bootstrap_customizable
|
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
|
ColumnSet.createColumns
|
public function createColumns($value, $mcw)
{
$columns = (int) $mcw->activeRecord->columns;
$value = deserialize($value, true);
$count = count($value);
// initialize columns
if($count == 0) {
for($i= 0; $i < $columns; $i++) {
$value[$i]['width'] = floor(12/$columns);
}
}
// reduce columns if necessary
elseif($count > $columns) {
$count = count($value) - $columns;
for($i=0; $i < $count; $i++) {
array_pop($value);
}
}
// make sure that column numbers has not changed
else {
for($i= 0; $i < ($columns - $count); $i++) {
$value[$i+$count]['width'] = floor(12/$columns);
}
}
return $value;
}
|
php
|
public function createColumns($value, $mcw)
{
$columns = (int) $mcw->activeRecord->columns;
$value = deserialize($value, true);
$count = count($value);
// initialize columns
if($count == 0) {
for($i= 0; $i < $columns; $i++) {
$value[$i]['width'] = floor(12/$columns);
}
}
// reduce columns if necessary
elseif($count > $columns) {
$count = count($value) - $columns;
for($i=0; $i < $count; $i++) {
array_pop($value);
}
}
// make sure that column numbers has not changed
else {
for($i= 0; $i < ($columns - $count); $i++) {
$value[$i+$count]['width'] = floor(12/$columns);
}
}
return $value;
}
|
[
"public",
"function",
"createColumns",
"(",
"$",
"value",
",",
"$",
"mcw",
")",
"{",
"$",
"columns",
"=",
"(",
"int",
")",
"$",
"mcw",
"->",
"activeRecord",
"->",
"columns",
";",
"$",
"value",
"=",
"deserialize",
"(",
"$",
"value",
",",
"true",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"value",
")",
";",
"// initialize columns",
"if",
"(",
"$",
"count",
"==",
"0",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"columns",
";",
"$",
"i",
"++",
")",
"{",
"$",
"value",
"[",
"$",
"i",
"]",
"[",
"'width'",
"]",
"=",
"floor",
"(",
"12",
"/",
"$",
"columns",
")",
";",
"}",
"}",
"// reduce columns if necessary",
"elseif",
"(",
"$",
"count",
">",
"$",
"columns",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"value",
")",
"-",
"$",
"columns",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"array_pop",
"(",
"$",
"value",
")",
";",
"}",
"}",
"// make sure that column numbers has not changed",
"else",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"(",
"$",
"columns",
"-",
"$",
"count",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"value",
"[",
"$",
"i",
"+",
"$",
"count",
"]",
"[",
"'width'",
"]",
"=",
"floor",
"(",
"12",
"/",
"$",
"columns",
")",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] |
create a MCW row for each column
@param string $value deseriazable value, for getting an array
@param $mcw multi column wizard or DC_Table
@return mixed
|
[
"create",
"a",
"MCW",
"row",
"for",
"each",
"column"
] |
c0f63755282451fad670ceaa49b984bfabf9e4ee
|
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L161-L190
|
24,616
|
netzmacht-archive/subcolumns_bootstrap_customizable
|
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
|
ColumnSet.getAllTypes
|
public function getAllTypes($dc)
{
if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') {
$sc = new \tl_content_sc();
return $sc->getAllTypes();
}
$this->import('Database');
$collection = $this->Database->execute('SELECT columns FROM tl_columnset GROUP BY columns ORDER BY columns');
$types = array();
while($collection->next()) {
$types[] = $collection->columns;
}
return $types;
}
|
php
|
public function getAllTypes($dc)
{
if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') {
$sc = new \tl_content_sc();
return $sc->getAllTypes();
}
$this->import('Database');
$collection = $this->Database->execute('SELECT columns FROM tl_columnset GROUP BY columns ORDER BY columns');
$types = array();
while($collection->next()) {
$types[] = $collection->columns;
}
return $types;
}
|
[
"public",
"function",
"getAllTypes",
"(",
"$",
"dc",
")",
"{",
"if",
"(",
"$",
"GLOBALS",
"[",
"'TL_CONFIG'",
"]",
"[",
"'subcolumns'",
"]",
"!=",
"'bootstrap_customizable'",
")",
"{",
"$",
"sc",
"=",
"new",
"\\",
"tl_content_sc",
"(",
")",
";",
"return",
"$",
"sc",
"->",
"getAllTypes",
"(",
")",
";",
"}",
"$",
"this",
"->",
"import",
"(",
"'Database'",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"Database",
"->",
"execute",
"(",
"'SELECT columns FROM tl_columnset GROUP BY columns ORDER BY columns'",
")",
";",
"$",
"types",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"collection",
"->",
"next",
"(",
")",
")",
"{",
"$",
"types",
"[",
"]",
"=",
"$",
"collection",
"->",
"columns",
";",
"}",
"return",
"$",
"types",
";",
"}"
] |
replace subcolumns getAllTypes method, to load all created columnsets. There is a fallback provided if not
bootstra_customizable is used
@param DC_Table $dc
@return array
|
[
"replace",
"subcolumns",
"getAllTypes",
"method",
"to",
"load",
"all",
"created",
"columnsets",
".",
"There",
"is",
"a",
"fallback",
"provided",
"if",
"not",
"bootstra_customizable",
"is",
"used"
] |
c0f63755282451fad670ceaa49b984bfabf9e4ee
|
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L200-L217
|
24,617
|
netzmacht-archive/subcolumns_bootstrap_customizable
|
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
|
ColumnSet.getAllColumnsets
|
public function getAllColumnsets($dc)
{
$collection = ColumnsetModel::findBy('published=1 AND columns', $dc->activeRecord->sc_type, array('order' => 'title'));
$set = array();
if($collection !== null)
{
while($collection->next()) {
$set[$collection->id] = $collection->title;
}
}
return $set;
}
|
php
|
public function getAllColumnsets($dc)
{
$collection = ColumnsetModel::findBy('published=1 AND columns', $dc->activeRecord->sc_type, array('order' => 'title'));
$set = array();
if($collection !== null)
{
while($collection->next()) {
$set[$collection->id] = $collection->title;
}
}
return $set;
}
|
[
"public",
"function",
"getAllColumnsets",
"(",
"$",
"dc",
")",
"{",
"$",
"collection",
"=",
"ColumnsetModel",
"::",
"findBy",
"(",
"'published=1 AND columns'",
",",
"$",
"dc",
"->",
"activeRecord",
"->",
"sc_type",
",",
"array",
"(",
"'order'",
"=>",
"'title'",
")",
")",
";",
"$",
"set",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"collection",
"!==",
"null",
")",
"{",
"while",
"(",
"$",
"collection",
"->",
"next",
"(",
")",
")",
"{",
"$",
"set",
"[",
"$",
"collection",
"->",
"id",
"]",
"=",
"$",
"collection",
"->",
"title",
";",
"}",
"}",
"return",
"$",
"set",
";",
"}"
] |
get all columnsets which fits to the selected type
@param $dc
@return array
|
[
"get",
"all",
"columnsets",
"which",
"fits",
"to",
"the",
"selected",
"type"
] |
c0f63755282451fad670ceaa49b984bfabf9e4ee
|
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L225-L238
|
24,618
|
leprephp/di
|
src/ExtensionQueue.php
|
ExtensionQueue.getService
|
public function getService($service)
{
foreach ($this->queue as $extension) {
$new = call_user_func($extension, $service, $this->container);
if ($new) {
$service = $new;
}
}
return $service;
}
|
php
|
public function getService($service)
{
foreach ($this->queue as $extension) {
$new = call_user_func($extension, $service, $this->container);
if ($new) {
$service = $new;
}
}
return $service;
}
|
[
"public",
"function",
"getService",
"(",
"$",
"service",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"queue",
"as",
"$",
"extension",
")",
"{",
"$",
"new",
"=",
"call_user_func",
"(",
"$",
"extension",
",",
"$",
"service",
",",
"$",
"this",
"->",
"container",
")",
";",
"if",
"(",
"$",
"new",
")",
"{",
"$",
"service",
"=",
"$",
"new",
";",
"}",
"}",
"return",
"$",
"service",
";",
"}"
] |
Gets the extended version of the service.
@param mixed $service
@return mixed
|
[
"Gets",
"the",
"extended",
"version",
"of",
"the",
"service",
"."
] |
d7de90c0d44714abd70c4f5bd5341a1a87203a7e
|
https://github.com/leprephp/di/blob/d7de90c0d44714abd70c4f5bd5341a1a87203a7e/src/ExtensionQueue.php#L60-L71
|
24,619
|
MichaelJ2324/PHP-REST-Client
|
src/Endpoint/Abstracts/AbstractCollectionEndpoint.php
|
AbstractCollectionEndpoint.update
|
public function update(array $collection){
foreach($collection as $key => $value){
$this->collection[$key] = $value;
}
return $this;
}
|
php
|
public function update(array $collection){
foreach($collection as $key => $value){
$this->collection[$key] = $value;
}
return $this;
}
|
[
"public",
"function",
"update",
"(",
"array",
"$",
"collection",
")",
"{",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"collection",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Update and append to Collection array
@param array $collection
@return self
|
[
"Update",
"and",
"append",
"to",
"Collection",
"array"
] |
b8a2caaf6456eccaa845ba5c5098608aa9645c92
|
https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractCollectionEndpoint.php#L112-L117
|
24,620
|
MichaelJ2324/PHP-REST-Client
|
src/Endpoint/Abstracts/AbstractCollectionEndpoint.php
|
AbstractCollectionEndpoint.at
|
public function at($index){
$return = NULL;
$index = intval($index);
$data = $this->asArray();
reset($data);
if ($index < 0){
$index += $this->length();
}
$c = 1;
while ($c <= $index){
next($data);
$c++;
}
$return = current($data);
$Model = $this->buildModel($return);
if ($Model !== NULL){
$return = $Model;
}
return $return;
}
|
php
|
public function at($index){
$return = NULL;
$index = intval($index);
$data = $this->asArray();
reset($data);
if ($index < 0){
$index += $this->length();
}
$c = 1;
while ($c <= $index){
next($data);
$c++;
}
$return = current($data);
$Model = $this->buildModel($return);
if ($Model !== NULL){
$return = $Model;
}
return $return;
}
|
[
"public",
"function",
"at",
"(",
"$",
"index",
")",
"{",
"$",
"return",
"=",
"NULL",
";",
"$",
"index",
"=",
"intval",
"(",
"$",
"index",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"asArray",
"(",
")",
";",
"reset",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"index",
"<",
"0",
")",
"{",
"$",
"index",
"+=",
"$",
"this",
"->",
"length",
"(",
")",
";",
"}",
"$",
"c",
"=",
"1",
";",
"while",
"(",
"$",
"c",
"<=",
"$",
"index",
")",
"{",
"next",
"(",
"$",
"data",
")",
";",
"$",
"c",
"++",
";",
"}",
"$",
"return",
"=",
"current",
"(",
"$",
"data",
")",
";",
"$",
"Model",
"=",
"$",
"this",
"->",
"buildModel",
"(",
"$",
"return",
")",
";",
"if",
"(",
"$",
"Model",
"!==",
"NULL",
")",
"{",
"$",
"return",
"=",
"$",
"Model",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Get a model based on numerical index
@param int $index
@return array|ModelInterface
|
[
"Get",
"a",
"model",
"based",
"on",
"numerical",
"index"
] |
b8a2caaf6456eccaa845ba5c5098608aa9645c92
|
https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractCollectionEndpoint.php#L149-L168
|
24,621
|
MichaelJ2324/PHP-REST-Client
|
src/Endpoint/Abstracts/AbstractCollectionEndpoint.php
|
AbstractCollectionEndpoint.updateCollection
|
protected function updateCollection(){
$responseBody = $this->Response->getBody();
if (is_array($responseBody)){
if (isset($this->model)){
$modelIdKey = $this->buildModel()->modelIdKey();
foreach($responseBody as $key => $model){
if (isset($model[$modelIdKey])){
$this->collection[$model[$modelIdKey]] = $model;
} else {
$this->collection[] = $model;
}
}
} else {
$this->collection = $responseBody;
}
}
}
|
php
|
protected function updateCollection(){
$responseBody = $this->Response->getBody();
if (is_array($responseBody)){
if (isset($this->model)){
$modelIdKey = $this->buildModel()->modelIdKey();
foreach($responseBody as $key => $model){
if (isset($model[$modelIdKey])){
$this->collection[$model[$modelIdKey]] = $model;
} else {
$this->collection[] = $model;
}
}
} else {
$this->collection = $responseBody;
}
}
}
|
[
"protected",
"function",
"updateCollection",
"(",
")",
"{",
"$",
"responseBody",
"=",
"$",
"this",
"->",
"Response",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"responseBody",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"model",
")",
")",
"{",
"$",
"modelIdKey",
"=",
"$",
"this",
"->",
"buildModel",
"(",
")",
"->",
"modelIdKey",
"(",
")",
";",
"foreach",
"(",
"$",
"responseBody",
"as",
"$",
"key",
"=>",
"$",
"model",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"model",
"[",
"$",
"modelIdKey",
"]",
")",
")",
"{",
"$",
"this",
"->",
"collection",
"[",
"$",
"model",
"[",
"$",
"modelIdKey",
"]",
"]",
"=",
"$",
"model",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collection",
"[",
"]",
"=",
"$",
"model",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"collection",
"=",
"$",
"responseBody",
";",
"}",
"}",
"}"
] |
Configures the collection based on the Response Body
|
[
"Configures",
"the",
"collection",
"based",
"on",
"the",
"Response",
"Body"
] |
b8a2caaf6456eccaa845ba5c5098608aa9645c92
|
https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractCollectionEndpoint.php#L229-L245
|
24,622
|
MichaelJ2324/PHP-REST-Client
|
src/Endpoint/Abstracts/AbstractCollectionEndpoint.php
|
AbstractCollectionEndpoint.buildModel
|
protected function buildModel(array $data = array()){
$Model = NULL;
if (isset($this->model)){
$Model = new $this->model();
$Model->setBaseUrl($this->getBaseUrl());
if ($this->getAuth() !== NULL) {
$Model->setAuth($this->getAuth());
}
if (!empty($data)){
foreach($data as $key => $value){
$Model->set($key,$value);
}
}
}
return $Model;
}
|
php
|
protected function buildModel(array $data = array()){
$Model = NULL;
if (isset($this->model)){
$Model = new $this->model();
$Model->setBaseUrl($this->getBaseUrl());
if ($this->getAuth() !== NULL) {
$Model->setAuth($this->getAuth());
}
if (!empty($data)){
foreach($data as $key => $value){
$Model->set($key,$value);
}
}
}
return $Model;
}
|
[
"protected",
"function",
"buildModel",
"(",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"$",
"Model",
"=",
"NULL",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"model",
")",
")",
"{",
"$",
"Model",
"=",
"new",
"$",
"this",
"->",
"model",
"(",
")",
";",
"$",
"Model",
"->",
"setBaseUrl",
"(",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getAuth",
"(",
")",
"!==",
"NULL",
")",
"{",
"$",
"Model",
"->",
"setAuth",
"(",
"$",
"this",
"->",
"getAuth",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"Model",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"return",
"$",
"Model",
";",
"}"
] |
Build the ModelEndpoint
@param array $data
@return AbstractModelEndpoint
|
[
"Build",
"the",
"ModelEndpoint"
] |
b8a2caaf6456eccaa845ba5c5098608aa9645c92
|
https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractCollectionEndpoint.php#L252-L267
|
24,623
|
Gendoria/command-queue
|
src/Gendoria/CommandQueue/QueueManager/MultipleQueueManager.php
|
MultipleQueueManager.detectPool
|
private function detectPool(CommandInterface $command)
{
$commandClass = get_class($command);
return $this->poolDetector->detect($commandClass);
}
|
php
|
private function detectPool(CommandInterface $command)
{
$commandClass = get_class($command);
return $this->poolDetector->detect($commandClass);
}
|
[
"private",
"function",
"detectPool",
"(",
"CommandInterface",
"$",
"command",
")",
"{",
"$",
"commandClass",
"=",
"get_class",
"(",
"$",
"command",
")",
";",
"return",
"$",
"this",
"->",
"poolDetector",
"->",
"detect",
"(",
"$",
"commandClass",
")",
";",
"}"
] |
Detect correct pool for given command.
@param CommandInterface $command
@return string
|
[
"Detect",
"correct",
"pool",
"for",
"given",
"command",
"."
] |
4e1094570705942f2ce3b2c976b5b251c3c84b40
|
https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/QueueManager/MultipleQueueManager.php#L117-L121
|
24,624
|
OxfordInfoLabs/kinikit-core
|
src/Util/ArrayUtils.php
|
ArrayUtils.prefixArrayKeys
|
public static function prefixArrayKeys($array, $prefix) {
$prefixedArray = array();
foreach ($array as $key => $value) {
$prefixedArray [$prefix . $key] = $value;
}
return $prefixedArray;
}
|
php
|
public static function prefixArrayKeys($array, $prefix) {
$prefixedArray = array();
foreach ($array as $key => $value) {
$prefixedArray [$prefix . $key] = $value;
}
return $prefixedArray;
}
|
[
"public",
"static",
"function",
"prefixArrayKeys",
"(",
"$",
"array",
",",
"$",
"prefix",
")",
"{",
"$",
"prefixedArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"prefixedArray",
"[",
"$",
"prefix",
".",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"prefixedArray",
";",
"}"
] |
Take an associative array as input and return a new array with all the original keys prefixed by the
passed prefix.
@param array $array
@param string $prefix
@return array
|
[
"Take",
"an",
"associative",
"array",
"as",
"input",
"and",
"return",
"a",
"new",
"array",
"with",
"all",
"the",
"original",
"keys",
"prefixed",
"by",
"the",
"passed",
"prefix",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L35-L44
|
24,625
|
OxfordInfoLabs/kinikit-core
|
src/Util/ArrayUtils.php
|
ArrayUtils.getAllArrayItemsByKeyPrefix
|
public static function getAllArrayItemsByKeyPrefix($array, $prefix, $stripPrefix = false) {
$returnValues = array();
foreach ($array as $key => $value) {
$positionOfPrefix = strpos($key, $prefix);
if (is_numeric($positionOfPrefix) && $positionOfPrefix == 0) {
if ($stripPrefix) $key = substr($key, strlen($prefix));
$returnValues [$key] = $value;
}
}
return $returnValues;
}
|
php
|
public static function getAllArrayItemsByKeyPrefix($array, $prefix, $stripPrefix = false) {
$returnValues = array();
foreach ($array as $key => $value) {
$positionOfPrefix = strpos($key, $prefix);
if (is_numeric($positionOfPrefix) && $positionOfPrefix == 0) {
if ($stripPrefix) $key = substr($key, strlen($prefix));
$returnValues [$key] = $value;
}
}
return $returnValues;
}
|
[
"public",
"static",
"function",
"getAllArrayItemsByKeyPrefix",
"(",
"$",
"array",
",",
"$",
"prefix",
",",
"$",
"stripPrefix",
"=",
"false",
")",
"{",
"$",
"returnValues",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"positionOfPrefix",
"=",
"strpos",
"(",
"$",
"key",
",",
"$",
"prefix",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"positionOfPrefix",
")",
"&&",
"$",
"positionOfPrefix",
"==",
"0",
")",
"{",
"if",
"(",
"$",
"stripPrefix",
")",
"$",
"key",
"=",
"substr",
"(",
"$",
"key",
",",
"strlen",
"(",
"$",
"prefix",
")",
")",
";",
"$",
"returnValues",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"returnValues",
";",
"}"
] |
Find all parameters in the passed array with a key starting with the supplied prefix.
Return them as an associative array by key.
@param array $array
@param string $prefix
@return array
|
[
"Find",
"all",
"parameters",
"in",
"the",
"passed",
"array",
"with",
"a",
"key",
"starting",
"with",
"the",
"supplied",
"prefix",
".",
"Return",
"them",
"as",
"an",
"associative",
"array",
"by",
"key",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L55-L66
|
24,626
|
OxfordInfoLabs/kinikit-core
|
src/Util/ArrayUtils.php
|
ArrayUtils.arrayDiff
|
public static function arrayDiff($array1, $array2) {
return array_udiff($array1, $array2,
function ($a, $b) {
if (is_object($a)) {
return strcmp(spl_object_hash($a), spl_object_hash($b));
} else if (is_array($a)) {
return ArrayUtils::arrayDiff($a, $b);
} else {
return strcmp($a, $b);
}
}
);
}
|
php
|
public static function arrayDiff($array1, $array2) {
return array_udiff($array1, $array2,
function ($a, $b) {
if (is_object($a)) {
return strcmp(spl_object_hash($a), spl_object_hash($b));
} else if (is_array($a)) {
return ArrayUtils::arrayDiff($a, $b);
} else {
return strcmp($a, $b);
}
}
);
}
|
[
"public",
"static",
"function",
"arrayDiff",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"return",
"array_udiff",
"(",
"$",
"array1",
",",
"$",
"array2",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"a",
")",
")",
"{",
"return",
"strcmp",
"(",
"spl_object_hash",
"(",
"$",
"a",
")",
",",
"spl_object_hash",
"(",
"$",
"b",
")",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"a",
")",
")",
"{",
"return",
"ArrayUtils",
"::",
"arrayDiff",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"}",
"else",
"{",
"return",
"strcmp",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Diff function for arrays which works with arrays of objects as well as string comparables.
@param $array1
@param $array2
|
[
"Diff",
"function",
"for",
"arrays",
"which",
"works",
"with",
"arrays",
"of",
"objects",
"as",
"well",
"as",
"string",
"comparables",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L87-L99
|
24,627
|
OxfordInfoLabs/kinikit-core
|
src/Util/ArrayUtils.php
|
ArrayUtils.recursiveMerge
|
public static function recursiveMerge($array1, $array2) {
if ($array1 instanceof AssociativeArray) {
$array1 = $array1->toArray();
}
if ($array2 instanceof AssociativeArray) {
$array2 = $array2->toArray();
}
if (ArrayUtils::isAssociative($array1) != ArrayUtils::isAssociative($array2)) {
if (ArrayUtils::isAssociative($array1)) {
$array1 = array($array1);
} else {
$array2 = array($array2);
}
}
$combinedKeys = array_unique(array_merge(array_keys($array1), array_keys($array2)));
$mergedArray = array();
foreach ($combinedKeys as $key) {
if (isset($array1[$key]) && isset($array2[$key])) {
if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
$mergedArray[$key] = ArrayUtils::recursiveMerge($array1[$key], $array2[$key]);
} else {
$mergedArray[$key] = $array1[$key];
}
} else {
$mergedArray[$key] = isset($array1[$key]) ? $array1[$key] : $array2[$key];
}
}
return $mergedArray;
}
|
php
|
public static function recursiveMerge($array1, $array2) {
if ($array1 instanceof AssociativeArray) {
$array1 = $array1->toArray();
}
if ($array2 instanceof AssociativeArray) {
$array2 = $array2->toArray();
}
if (ArrayUtils::isAssociative($array1) != ArrayUtils::isAssociative($array2)) {
if (ArrayUtils::isAssociative($array1)) {
$array1 = array($array1);
} else {
$array2 = array($array2);
}
}
$combinedKeys = array_unique(array_merge(array_keys($array1), array_keys($array2)));
$mergedArray = array();
foreach ($combinedKeys as $key) {
if (isset($array1[$key]) && isset($array2[$key])) {
if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
$mergedArray[$key] = ArrayUtils::recursiveMerge($array1[$key], $array2[$key]);
} else {
$mergedArray[$key] = $array1[$key];
}
} else {
$mergedArray[$key] = isset($array1[$key]) ? $array1[$key] : $array2[$key];
}
}
return $mergedArray;
}
|
[
"public",
"static",
"function",
"recursiveMerge",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"if",
"(",
"$",
"array1",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array1",
"=",
"$",
"array1",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"$",
"array2",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array2",
"=",
"$",
"array2",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"ArrayUtils",
"::",
"isAssociative",
"(",
"$",
"array1",
")",
"!=",
"ArrayUtils",
"::",
"isAssociative",
"(",
"$",
"array2",
")",
")",
"{",
"if",
"(",
"ArrayUtils",
"::",
"isAssociative",
"(",
"$",
"array1",
")",
")",
"{",
"$",
"array1",
"=",
"array",
"(",
"$",
"array1",
")",
";",
"}",
"else",
"{",
"$",
"array2",
"=",
"array",
"(",
"$",
"array2",
")",
";",
"}",
"}",
"$",
"combinedKeys",
"=",
"array_unique",
"(",
"array_merge",
"(",
"array_keys",
"(",
"$",
"array1",
")",
",",
"array_keys",
"(",
"$",
"array2",
")",
")",
")",
";",
"$",
"mergedArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"combinedKeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"&&",
"isset",
"(",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"array1",
"[",
"$",
"key",
"]",
"instanceof",
"AssociativeArray",
")",
"&&",
"(",
"is_array",
"(",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"array2",
"[",
"$",
"key",
"]",
"instanceof",
"AssociativeArray",
")",
")",
"{",
"$",
"mergedArray",
"[",
"$",
"key",
"]",
"=",
"ArrayUtils",
"::",
"recursiveMerge",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"mergedArray",
"[",
"$",
"key",
"]",
"=",
"$",
"array1",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"mergedArray",
"[",
"$",
"key",
"]",
"=",
"isset",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"array1",
"[",
"$",
"key",
"]",
":",
"$",
"array2",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"mergedArray",
";",
"}"
] |
Recursively merge array1 and array2. If keys exist in both arrays at any level, take the value from array1 in preference.
@param $array1
@param $array2
|
[
"Recursively",
"merge",
"array1",
"and",
"array2",
".",
"If",
"keys",
"exist",
"in",
"both",
"arrays",
"at",
"any",
"level",
"take",
"the",
"value",
"from",
"array1",
"in",
"preference",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L107-L148
|
24,628
|
OxfordInfoLabs/kinikit-core
|
src/Util/ArrayUtils.php
|
ArrayUtils.recursiveDiff
|
public static function recursiveDiff($array1, $array2, $caseInsensitive = true, $matchingKeysOnly = true) {
if ($array1 instanceof AssociativeArray) {
$array1 = $array1->toArray();
}
if ($array2 instanceof AssociativeArray) {
$array2 = $array2->toArray();
}
$sharedKeys = array_intersect(array_keys($array1), array_keys($array2));
$diffArray = array();
// Only care about shared keys
foreach ($sharedKeys as $key) {
if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
$diffArray[$key] = ArrayUtils::recursiveDiff($array1[$key], $array2[$key], $caseInsensitive, $matchingKeysOnly);
} else {
$value1 = $caseInsensitive ? strtolower($array1[$key]) : $array1[$key];
$value2 = $caseInsensitive ? strtolower($array2[$key]) : $array2[$key];
if ($value1 != $value2) {
$diffArray[$key] = array("value1" => $array1[$key], "value2" => $array2[$key]);
}
}
}
return $diffArray;
}
|
php
|
public static function recursiveDiff($array1, $array2, $caseInsensitive = true, $matchingKeysOnly = true) {
if ($array1 instanceof AssociativeArray) {
$array1 = $array1->toArray();
}
if ($array2 instanceof AssociativeArray) {
$array2 = $array2->toArray();
}
$sharedKeys = array_intersect(array_keys($array1), array_keys($array2));
$diffArray = array();
// Only care about shared keys
foreach ($sharedKeys as $key) {
if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
$diffArray[$key] = ArrayUtils::recursiveDiff($array1[$key], $array2[$key], $caseInsensitive, $matchingKeysOnly);
} else {
$value1 = $caseInsensitive ? strtolower($array1[$key]) : $array1[$key];
$value2 = $caseInsensitive ? strtolower($array2[$key]) : $array2[$key];
if ($value1 != $value2) {
$diffArray[$key] = array("value1" => $array1[$key], "value2" => $array2[$key]);
}
}
}
return $diffArray;
}
|
[
"public",
"static",
"function",
"recursiveDiff",
"(",
"$",
"array1",
",",
"$",
"array2",
",",
"$",
"caseInsensitive",
"=",
"true",
",",
"$",
"matchingKeysOnly",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"array1",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array1",
"=",
"$",
"array1",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"$",
"array2",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array2",
"=",
"$",
"array2",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"sharedKeys",
"=",
"array_intersect",
"(",
"array_keys",
"(",
"$",
"array1",
")",
",",
"array_keys",
"(",
"$",
"array2",
")",
")",
";",
"$",
"diffArray",
"=",
"array",
"(",
")",
";",
"// Only care about shared keys",
"foreach",
"(",
"$",
"sharedKeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"array1",
"[",
"$",
"key",
"]",
"instanceof",
"AssociativeArray",
")",
"&&",
"(",
"is_array",
"(",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"array2",
"[",
"$",
"key",
"]",
"instanceof",
"AssociativeArray",
")",
")",
"{",
"$",
"diffArray",
"[",
"$",
"key",
"]",
"=",
"ArrayUtils",
"::",
"recursiveDiff",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"$",
"array2",
"[",
"$",
"key",
"]",
",",
"$",
"caseInsensitive",
",",
"$",
"matchingKeysOnly",
")",
";",
"}",
"else",
"{",
"$",
"value1",
"=",
"$",
"caseInsensitive",
"?",
"strtolower",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
":",
"$",
"array1",
"[",
"$",
"key",
"]",
";",
"$",
"value2",
"=",
"$",
"caseInsensitive",
"?",
"strtolower",
"(",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
":",
"$",
"array2",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"value1",
"!=",
"$",
"value2",
")",
"{",
"$",
"diffArray",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"\"value1\"",
"=>",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"\"value2\"",
"=>",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"diffArray",
";",
"}"
] |
Return an array of different elements within the 2 arrays. If matching keys only is supplied, only elements which exist in both but which are different are included.
The returned array contains an associative array for each differing value with a "value1" and "value2" element.
@param $array1
@param $array2
@param bool $matchingKeysOnly
|
[
"Return",
"an",
"array",
"of",
"different",
"elements",
"within",
"the",
"2",
"arrays",
".",
"If",
"matching",
"keys",
"only",
"is",
"supplied",
"only",
"elements",
"which",
"exist",
"in",
"both",
"but",
"which",
"are",
"different",
"are",
"included",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L161-L194
|
24,629
|
OxfordInfoLabs/kinikit-core
|
src/Util/ArrayUtils.php
|
ArrayUtils.reduceToElementsWithKey
|
public static function reduceToElementsWithKey($array, $key) {
if ($array instanceof AssociativeArray) {
$array = $array->toArray();
}
$targetArray = array();
foreach ($array as $itemKey => $value) {
if ($itemKey == $key) {
$targetArray[$key] = $value;
} else if (is_array($value) || $value instanceof AssociativeArray) {
$subArray = ArrayUtils::reduceToElementsWithKey($value, $key);
if (sizeof($subArray) > 0) {
$targetArray[$itemKey] = $subArray;
}
}
}
return $targetArray;
}
|
php
|
public static function reduceToElementsWithKey($array, $key) {
if ($array instanceof AssociativeArray) {
$array = $array->toArray();
}
$targetArray = array();
foreach ($array as $itemKey => $value) {
if ($itemKey == $key) {
$targetArray[$key] = $value;
} else if (is_array($value) || $value instanceof AssociativeArray) {
$subArray = ArrayUtils::reduceToElementsWithKey($value, $key);
if (sizeof($subArray) > 0) {
$targetArray[$itemKey] = $subArray;
}
}
}
return $targetArray;
}
|
[
"public",
"static",
"function",
"reduceToElementsWithKey",
"(",
"$",
"array",
",",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"array",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array",
"=",
"$",
"array",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"targetArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"itemKey",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"itemKey",
"==",
"$",
"key",
")",
"{",
"$",
"targetArray",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"subArray",
"=",
"ArrayUtils",
"::",
"reduceToElementsWithKey",
"(",
"$",
"value",
",",
"$",
"key",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"subArray",
")",
">",
"0",
")",
"{",
"$",
"targetArray",
"[",
"$",
"itemKey",
"]",
"=",
"$",
"subArray",
";",
"}",
"}",
"}",
"return",
"$",
"targetArray",
";",
"}"
] |
Reduce the array to only elements with the passed key at any depth.
@param $array
@param $key
|
[
"Reduce",
"the",
"array",
"to",
"only",
"elements",
"with",
"the",
"passed",
"key",
"at",
"any",
"depth",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L203-L226
|
24,630
|
OxfordInfoLabs/kinikit-core
|
src/Util/ArrayUtils.php
|
ArrayUtils.findElementsByKey
|
public static function findElementsByKey($array, $key, &$targetArray = null, $prefix = "") {
if ($array instanceof AssociativeArray) {
$array = $array->toArray();
}
if (!$targetArray)
$targetArray = array();
foreach ($array as $itemKey => $value) {
if ($itemKey === $key) {
$targetArray[substr($prefix . "." . $key, 1)] = $value;
} else if (is_array($value) || $value instanceof AssociativeArray) {
if (is_numeric($itemKey)) {
$newPrefix = $prefix . "[" . $itemKey . "]";
} else {
$newPrefix = $prefix . "." . $itemKey;
}
ArrayUtils::findElementsByKey($value, $key, $targetArray, $newPrefix);
}
}
return $targetArray;
}
|
php
|
public static function findElementsByKey($array, $key, &$targetArray = null, $prefix = "") {
if ($array instanceof AssociativeArray) {
$array = $array->toArray();
}
if (!$targetArray)
$targetArray = array();
foreach ($array as $itemKey => $value) {
if ($itemKey === $key) {
$targetArray[substr($prefix . "." . $key, 1)] = $value;
} else if (is_array($value) || $value instanceof AssociativeArray) {
if (is_numeric($itemKey)) {
$newPrefix = $prefix . "[" . $itemKey . "]";
} else {
$newPrefix = $prefix . "." . $itemKey;
}
ArrayUtils::findElementsByKey($value, $key, $targetArray, $newPrefix);
}
}
return $targetArray;
}
|
[
"public",
"static",
"function",
"findElementsByKey",
"(",
"$",
"array",
",",
"$",
"key",
",",
"&",
"$",
"targetArray",
"=",
"null",
",",
"$",
"prefix",
"=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"array",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array",
"=",
"$",
"array",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"targetArray",
")",
"$",
"targetArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"itemKey",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"itemKey",
"===",
"$",
"key",
")",
"{",
"$",
"targetArray",
"[",
"substr",
"(",
"$",
"prefix",
".",
"\".\"",
".",
"$",
"key",
",",
"1",
")",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"instanceof",
"AssociativeArray",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"itemKey",
")",
")",
"{",
"$",
"newPrefix",
"=",
"$",
"prefix",
".",
"\"[\"",
".",
"$",
"itemKey",
".",
"\"]\"",
";",
"}",
"else",
"{",
"$",
"newPrefix",
"=",
"$",
"prefix",
".",
"\".\"",
".",
"$",
"itemKey",
";",
"}",
"ArrayUtils",
"::",
"findElementsByKey",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"targetArray",
",",
"$",
"newPrefix",
")",
";",
"}",
"}",
"return",
"$",
"targetArray",
";",
"}"
] |
Find elements by key.
@param $array
@param $key
|
[
"Find",
"elements",
"by",
"key",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L235-L262
|
24,631
|
OxfordInfoLabs/kinikit-core
|
src/Util/ArrayUtils.php
|
ArrayUtils.groupElementsByValueKeys
|
public static function groupElementsByValueKeys($array, $groupKeys) {
if (!is_array($groupKeys)) {
$groupKeys = array($groupKeys);
}
$newArray = new AssociativeArray();
foreach ($array as $element) {
$applyObject = $newArray;
foreach ($groupKeys as $index => $groupKey) {
if ($index < sizeof($groupKeys) - 1) {
$subArray = $applyObject[$element[$groupKeys[$index]]];
if (!$subArray) {
$subArray = new AssociativeArray();
$applyObject[$element[$groupKeys[$index]]] = $subArray;
}
$applyObject = $subArray;
} else {
if (!is_array($applyObject[$element[$groupKeys[$index]]])) {
$applyObject[$element[$groupKeys[$index]]] = array();
}
$applyObject[$element[$groupKeys[$index]]][] = $element;
}
}
}
return $newArray->toArray();
}
|
php
|
public static function groupElementsByValueKeys($array, $groupKeys) {
if (!is_array($groupKeys)) {
$groupKeys = array($groupKeys);
}
$newArray = new AssociativeArray();
foreach ($array as $element) {
$applyObject = $newArray;
foreach ($groupKeys as $index => $groupKey) {
if ($index < sizeof($groupKeys) - 1) {
$subArray = $applyObject[$element[$groupKeys[$index]]];
if (!$subArray) {
$subArray = new AssociativeArray();
$applyObject[$element[$groupKeys[$index]]] = $subArray;
}
$applyObject = $subArray;
} else {
if (!is_array($applyObject[$element[$groupKeys[$index]]])) {
$applyObject[$element[$groupKeys[$index]]] = array();
}
$applyObject[$element[$groupKeys[$index]]][] = $element;
}
}
}
return $newArray->toArray();
}
|
[
"public",
"static",
"function",
"groupElementsByValueKeys",
"(",
"$",
"array",
",",
"$",
"groupKeys",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"groupKeys",
")",
")",
"{",
"$",
"groupKeys",
"=",
"array",
"(",
"$",
"groupKeys",
")",
";",
"}",
"$",
"newArray",
"=",
"new",
"AssociativeArray",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"element",
")",
"{",
"$",
"applyObject",
"=",
"$",
"newArray",
";",
"foreach",
"(",
"$",
"groupKeys",
"as",
"$",
"index",
"=>",
"$",
"groupKey",
")",
"{",
"if",
"(",
"$",
"index",
"<",
"sizeof",
"(",
"$",
"groupKeys",
")",
"-",
"1",
")",
"{",
"$",
"subArray",
"=",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
";",
"if",
"(",
"!",
"$",
"subArray",
")",
"{",
"$",
"subArray",
"=",
"new",
"AssociativeArray",
"(",
")",
";",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
"=",
"$",
"subArray",
";",
"}",
"$",
"applyObject",
"=",
"$",
"subArray",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
")",
")",
"{",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
"[",
"]",
"=",
"$",
"element",
";",
"}",
"}",
"}",
"return",
"$",
"newArray",
"->",
"toArray",
"(",
")",
";",
"}"
] |
Group an array of elements by one or more of it's keys. Essentially convert into an indexed array for each key type.
@param $array
@param $groupKeys
|
[
"Group",
"an",
"array",
"of",
"elements",
"by",
"one",
"or",
"more",
"of",
"it",
"s",
"keys",
".",
"Essentially",
"convert",
"into",
"an",
"indexed",
"array",
"for",
"each",
"key",
"type",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L271-L302
|
24,632
|
phossa/phossa-config
|
src/Phossa/Config/Reference/TreeTrait.php
|
TreeTrait.&
|
protected function &searchTree(
/*# string */ $key,
/*# array */ &$tree,
/*# bool */ $create = false
) {
$found = &$tree;
$parts = explode($this->field_splitter, $key);
while (null !== ($part = array_shift($parts))) {
if (!isset($found[$part])) {
if ($create) {
$found[$part] = [];
} else {
$bad = null;
return $bad;
}
}
$found = &$found[$part];
}
return $found;
}
|
php
|
protected function &searchTree(
/*# string */ $key,
/*# array */ &$tree,
/*# bool */ $create = false
) {
$found = &$tree;
$parts = explode($this->field_splitter, $key);
while (null !== ($part = array_shift($parts))) {
if (!isset($found[$part])) {
if ($create) {
$found[$part] = [];
} else {
$bad = null;
return $bad;
}
}
$found = &$found[$part];
}
return $found;
}
|
[
"protected",
"function",
"&",
"searchTree",
"(",
"/*# string */",
"$",
"key",
",",
"/*# array */",
"&",
"$",
"tree",
",",
"/*# bool */",
"$",
"create",
"=",
"false",
")",
"{",
"$",
"found",
"=",
"&",
"$",
"tree",
";",
"$",
"parts",
"=",
"explode",
"(",
"$",
"this",
"->",
"field_splitter",
",",
"$",
"key",
")",
";",
"while",
"(",
"null",
"!==",
"(",
"$",
"part",
"=",
"array_shift",
"(",
"$",
"parts",
")",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"found",
"[",
"$",
"part",
"]",
")",
")",
"{",
"if",
"(",
"$",
"create",
")",
"{",
"$",
"found",
"[",
"$",
"part",
"]",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"bad",
"=",
"null",
";",
"return",
"$",
"bad",
";",
"}",
"}",
"$",
"found",
"=",
"&",
"$",
"found",
"[",
"$",
"part",
"]",
";",
"}",
"return",
"$",
"found",
";",
"}"
] |
Return a node in an array structure
@param string $key something like 'db.auth.host'
@param array &$tree the array tree
@param bool $create create the node if missing
@return null|array|string the matching node
@access protected
|
[
"Return",
"a",
"node",
"in",
"an",
"array",
"structure"
] |
fdb90831da06408bb674ab777754e67025604bed
|
https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Reference/TreeTrait.php#L57-L76
|
24,633
|
MetaModels/phpunit-contao-database
|
src/Contao/Database/FakeResult.php
|
FakeResult.addRow
|
public function addRow($data, $rowId = null)
{
if (($rowId === null) && isset($data['id'])) {
$rowId = $data['id'];
}
if ($rowId === null) {
$rowId = count($this->rows);
}
$this->rows[$rowId] = $data;
return $this;
}
|
php
|
public function addRow($data, $rowId = null)
{
if (($rowId === null) && isset($data['id'])) {
$rowId = $data['id'];
}
if ($rowId === null) {
$rowId = count($this->rows);
}
$this->rows[$rowId] = $data;
return $this;
}
|
[
"public",
"function",
"addRow",
"(",
"$",
"data",
",",
"$",
"rowId",
"=",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"rowId",
"===",
"null",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"rowId",
"=",
"$",
"data",
"[",
"'id'",
"]",
";",
"}",
"if",
"(",
"$",
"rowId",
"===",
"null",
")",
"{",
"$",
"rowId",
"=",
"count",
"(",
"$",
"this",
"->",
"rows",
")",
";",
"}",
"$",
"this",
"->",
"rows",
"[",
"$",
"rowId",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a row.
@param array $data The row data.
@param null|int $rowId The id for the row.
@return FakeResult
|
[
"Add",
"a",
"row",
"."
] |
aeb2ee10dac532fa73e2deb6457b6a167a1c01c7
|
https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeResult.php#L44-L57
|
24,634
|
MetaModels/phpunit-contao-database
|
src/Contao/Database/FakeResult.php
|
FakeResult.addRows
|
public function addRows($data)
{
foreach ($data as $key => $row) {
$this->addRow($row, isset($row['id']) ? $row['id'] : $key);
}
return $this;
}
|
php
|
public function addRows($data)
{
foreach ($data as $key => $row) {
$this->addRow($row, isset($row['id']) ? $row['id'] : $key);
}
return $this;
}
|
[
"public",
"function",
"addRows",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"addRow",
"(",
"$",
"row",
",",
"isset",
"(",
"$",
"row",
"[",
"'id'",
"]",
")",
"?",
"$",
"row",
"[",
"'id'",
"]",
":",
"$",
"key",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add rows.
@param array $data The row data.
@return FakeResult
|
[
"Add",
"rows",
"."
] |
aeb2ee10dac532fa73e2deb6457b6a167a1c01c7
|
https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeResult.php#L66-L73
|
24,635
|
MetaModels/phpunit-contao-database
|
src/Contao/Database/FakeResult.php
|
FakeResult.getRow
|
public function getRow($index)
{
$keys = array_keys($this->rows);
return isset($keys[$index]) ? $this->rows[$keys[$index]] : null;
}
|
php
|
public function getRow($index)
{
$keys = array_keys($this->rows);
return isset($keys[$index]) ? $this->rows[$keys[$index]] : null;
}
|
[
"public",
"function",
"getRow",
"(",
"$",
"index",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"rows",
")",
";",
"return",
"isset",
"(",
"$",
"keys",
"[",
"$",
"index",
"]",
")",
"?",
"$",
"this",
"->",
"rows",
"[",
"$",
"keys",
"[",
"$",
"index",
"]",
"]",
":",
"null",
";",
"}"
] |
Retrieve the row with the given index.
@param int $index The index.
@return array
|
[
"Retrieve",
"the",
"row",
"with",
"the",
"given",
"index",
"."
] |
aeb2ee10dac532fa73e2deb6457b6a167a1c01c7
|
https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeResult.php#L84-L89
|
24,636
|
perryflynn/PerrysLambda
|
src/PerrysLambda/ArrayList.php
|
ArrayList.asType
|
public static function asType($type, array $data)
{
$converter = new TypeStringListConverter($type);
$converter->setArraySource($data);
return new static($converter);
}
|
php
|
public static function asType($type, array $data)
{
$converter = new TypeStringListConverter($type);
$converter->setArraySource($data);
return new static($converter);
}
|
[
"public",
"static",
"function",
"asType",
"(",
"$",
"type",
",",
"array",
"$",
"data",
")",
"{",
"$",
"converter",
"=",
"new",
"TypeStringListConverter",
"(",
"$",
"type",
")",
";",
"$",
"converter",
"->",
"setArraySource",
"(",
"$",
"data",
")",
";",
"return",
"new",
"static",
"(",
"$",
"converter",
")",
";",
"}"
] |
Create arraylist of class
@param string $type
@param mixed[] $data
@return \PerrysLambda\ArrayList
|
[
"Create",
"arraylist",
"of",
"class"
] |
9f1734ae4689d73278b887f9354dfd31428e96de
|
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayList.php#L32-L37
|
24,637
|
perryflynn/PerrysLambda
|
src/PerrysLambda/ArrayList.php
|
ArrayList.serializeGenerator
|
public function serializeGenerator()
{
if($this->__converter instanceof IListConverter)
{
foreach($this->__converter->toGenerator($this) as $index => $row)
{
yield $index => $row;
}
}
else
{
foreach($this->toArray() as $index => $row)
{
yield $index => $row;
}
}
}
|
php
|
public function serializeGenerator()
{
if($this->__converter instanceof IListConverter)
{
foreach($this->__converter->toGenerator($this) as $index => $row)
{
yield $index => $row;
}
}
else
{
foreach($this->toArray() as $index => $row)
{
yield $index => $row;
}
}
}
|
[
"public",
"function",
"serializeGenerator",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"__converter",
"instanceof",
"IListConverter",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"__converter",
"->",
"toGenerator",
"(",
"$",
"this",
")",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"yield",
"$",
"index",
"=>",
"$",
"row",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"yield",
"$",
"index",
"=>",
"$",
"row",
";",
"}",
"}",
"}"
] |
Serialize via converter as generator
@return mixed[]
|
[
"Serialize",
"via",
"converter",
"as",
"generator"
] |
9f1734ae4689d73278b887f9354dfd31428e96de
|
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayList.php#L79-L95
|
24,638
|
locomotivemtl/charcoal-translator
|
src/Charcoal/Translator/TranslatorConfig.php
|
TranslatorConfig.setTranslations
|
public function setTranslations(array $translations)
{
$this->translations = [];
foreach ($translations as $domain => $data) {
if (!is_array($data)) {
throw new InvalidArgumentException(
'Translator translations must be a 3-level array'
);
}
foreach ($data as $locale => $messages) {
if (!is_array($messages)) {
throw new InvalidArgumentException(
'Translator translations must be a 3-level array'
);
}
}
}
$this->translations = $translations;
return $this;
}
|
php
|
public function setTranslations(array $translations)
{
$this->translations = [];
foreach ($translations as $domain => $data) {
if (!is_array($data)) {
throw new InvalidArgumentException(
'Translator translations must be a 3-level array'
);
}
foreach ($data as $locale => $messages) {
if (!is_array($messages)) {
throw new InvalidArgumentException(
'Translator translations must be a 3-level array'
);
}
}
}
$this->translations = $translations;
return $this;
}
|
[
"public",
"function",
"setTranslations",
"(",
"array",
"$",
"translations",
")",
"{",
"$",
"this",
"->",
"translations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"domain",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Translator translations must be a 3-level array'",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"locale",
"=>",
"$",
"messages",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"messages",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Translator translations must be a 3-level array'",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"translations",
"=",
"$",
"translations",
";",
"return",
"$",
"this",
";",
"}"
] |
Set mapping of additional translations.
Expects:
```json
{
"<domain>": {
"<locale>": {
"<translation-key>": "translation"
}
}
}
```
@param array $translations Mapping of domains/locales/messages.
@throws InvalidArgumentException If the path is not a string.
@return TranslatorConfig Chainable
|
[
"Set",
"mapping",
"of",
"additional",
"translations",
"."
] |
0a64432baef223dcccbfecf057015440dfa76e49
|
https://github.com/locomotivemtl/charcoal-translator/blob/0a64432baef223dcccbfecf057015440dfa76e49/src/Charcoal/Translator/TranslatorConfig.php#L144-L166
|
24,639
|
ZFrapid/zf2rapid-domain
|
src/ZF2rapidDomain/Entity/AbstractEntity.php
|
AbstractEntity.exchangeArray
|
public function exchangeArray(array $array)
{
foreach ($array as $key => $value) {
$setMethod = 'set' . StaticFilter::execute(
$key, 'WordUnderscoreToCamelCase'
);
if (method_exists($this, $setMethod)) {
$this->$setMethod($value);
}
}
}
|
php
|
public function exchangeArray(array $array)
{
foreach ($array as $key => $value) {
$setMethod = 'set' . StaticFilter::execute(
$key, 'WordUnderscoreToCamelCase'
);
if (method_exists($this, $setMethod)) {
$this->$setMethod($value);
}
}
}
|
[
"public",
"function",
"exchangeArray",
"(",
"array",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"setMethod",
"=",
"'set'",
".",
"StaticFilter",
"::",
"execute",
"(",
"$",
"key",
",",
"'WordUnderscoreToCamelCase'",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"setMethod",
")",
")",
"{",
"$",
"this",
"->",
"$",
"setMethod",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}"
] |
Exchange properties with values from array
@param array $array
|
[
"Exchange",
"properties",
"with",
"values",
"from",
"array"
] |
9455689cac06b42025c144878604d27c28b4bb04
|
https://github.com/ZFrapid/zf2rapid-domain/blob/9455689cac06b42025c144878604d27c28b4bb04/src/ZF2rapidDomain/Entity/AbstractEntity.php#L32-L43
|
24,640
|
ZFrapid/zf2rapid-domain
|
src/ZF2rapidDomain/Entity/AbstractEntity.php
|
AbstractEntity.getArrayCopy
|
public function getArrayCopy()
{
$data = [];
foreach (get_object_vars($this) as $key => $value) {
$getMethod = 'get' . ucfirst($key);
$arrayKey = StaticFilter::execute($key, 'WordCamelCaseToUnderscore');
$arrayKey = StaticFilter::execute($arrayKey, 'StringToLower');
if (method_exists($this, $getMethod)) {
$data[$arrayKey] = $this->$getMethod();
}
}
return $data;
}
|
php
|
public function getArrayCopy()
{
$data = [];
foreach (get_object_vars($this) as $key => $value) {
$getMethod = 'get' . ucfirst($key);
$arrayKey = StaticFilter::execute($key, 'WordCamelCaseToUnderscore');
$arrayKey = StaticFilter::execute($arrayKey, 'StringToLower');
if (method_exists($this, $getMethod)) {
$data[$arrayKey] = $this->$getMethod();
}
}
return $data;
}
|
[
"public",
"function",
"getArrayCopy",
"(",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"get_object_vars",
"(",
"$",
"this",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"getMethod",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"key",
")",
";",
"$",
"arrayKey",
"=",
"StaticFilter",
"::",
"execute",
"(",
"$",
"key",
",",
"'WordCamelCaseToUnderscore'",
")",
";",
"$",
"arrayKey",
"=",
"StaticFilter",
"::",
"execute",
"(",
"$",
"arrayKey",
",",
"'StringToLower'",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"getMethod",
")",
")",
"{",
"$",
"data",
"[",
"$",
"arrayKey",
"]",
"=",
"$",
"this",
"->",
"$",
"getMethod",
"(",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Generate an array copy from property values
|
[
"Generate",
"an",
"array",
"copy",
"from",
"property",
"values"
] |
9455689cac06b42025c144878604d27c28b4bb04
|
https://github.com/ZFrapid/zf2rapid-domain/blob/9455689cac06b42025c144878604d27c28b4bb04/src/ZF2rapidDomain/Entity/AbstractEntity.php#L48-L65
|
24,641
|
Fenzland/http-api-gluer
|
src/Gluer/THoldsSerializers_.php
|
THoldsSerializers_.registerSerializer_
|
static public function registerSerializer_( string$mime, $serializer ):string
{
static::checkSerializerNotRegistered_( $mime );
static::checkSerializer_( $serializer );
static::$serializers_[$mime]= $serializer;
return self::class;
}
|
php
|
static public function registerSerializer_( string$mime, $serializer ):string
{
static::checkSerializerNotRegistered_( $mime );
static::checkSerializer_( $serializer );
static::$serializers_[$mime]= $serializer;
return self::class;
}
|
[
"static",
"public",
"function",
"registerSerializer_",
"(",
"string",
"$",
"mime",
",",
"$",
"serializer",
")",
":",
"string",
"{",
"static",
"::",
"checkSerializerNotRegistered_",
"(",
"$",
"mime",
")",
";",
"static",
"::",
"checkSerializer_",
"(",
"$",
"serializer",
")",
";",
"static",
"::",
"$",
"serializers_",
"[",
"$",
"mime",
"]",
"=",
"$",
"serializer",
";",
"return",
"self",
"::",
"class",
";",
"}"
] |
Static method registerSerializer_
@static
@access public
@param string $mime
@param class|S\ASerializer $serializer
@return class
|
[
"Static",
"method",
"registerSerializer_"
] |
3488de28b7f54fb444ec47f84034473a7d86e17e
|
https://github.com/Fenzland/http-api-gluer/blob/3488de28b7f54fb444ec47f84034473a7d86e17e/src/Gluer/THoldsSerializers_.php#L26-L35
|
24,642
|
Fenzland/http-api-gluer
|
src/Gluer/THoldsSerializers_.php
|
THoldsSerializers_.checkSerializer_
|
static protected function checkSerializer_( $serializer ):void
{
if(!(
(
is_object( $serializer )
&&
$serializer instanceof S\ASerializer
)
or
(
is_string( $serializer )
&&
class_exists( $serializer )
&&
isset( class_parents( $serializer )[S\ASerializer::class] )
)
)){
$caller= debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )[1];
throw new \TypeError(
"Argument 2 passed to {$caller['class']}{$caller['type']}{$caller['function']}() must be an class extends ".S\ASerializer::class.' or it\'s instance'
);
}
}
|
php
|
static protected function checkSerializer_( $serializer ):void
{
if(!(
(
is_object( $serializer )
&&
$serializer instanceof S\ASerializer
)
or
(
is_string( $serializer )
&&
class_exists( $serializer )
&&
isset( class_parents( $serializer )[S\ASerializer::class] )
)
)){
$caller= debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )[1];
throw new \TypeError(
"Argument 2 passed to {$caller['class']}{$caller['type']}{$caller['function']}() must be an class extends ".S\ASerializer::class.' or it\'s instance'
);
}
}
|
[
"static",
"protected",
"function",
"checkSerializer_",
"(",
"$",
"serializer",
")",
":",
"void",
"{",
"if",
"(",
"!",
"(",
"(",
"is_object",
"(",
"$",
"serializer",
")",
"&&",
"$",
"serializer",
"instanceof",
"S",
"\\",
"ASerializer",
")",
"or",
"(",
"is_string",
"(",
"$",
"serializer",
")",
"&&",
"class_exists",
"(",
"$",
"serializer",
")",
"&&",
"isset",
"(",
"class_parents",
"(",
"$",
"serializer",
")",
"[",
"S",
"\\",
"ASerializer",
"::",
"class",
"]",
")",
")",
")",
")",
"{",
"$",
"caller",
"=",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
",",
"2",
")",
"[",
"1",
"]",
";",
"throw",
"new",
"\\",
"TypeError",
"(",
"\"Argument 2 passed to {$caller['class']}{$caller['type']}{$caller['function']}() must be an class extends \"",
".",
"S",
"\\",
"ASerializer",
"::",
"class",
".",
"' or it\\'s instance'",
")",
";",
"}",
"}"
] |
Static method checkSerializer_
@static
@access protected
@param mixed $serializer
@return void
|
[
"Static",
"method",
"checkSerializer_"
] |
3488de28b7f54fb444ec47f84034473a7d86e17e
|
https://github.com/Fenzland/http-api-gluer/blob/3488de28b7f54fb444ec47f84034473a7d86e17e/src/Gluer/THoldsSerializers_.php#L93-L116
|
24,643
|
Fenzland/http-api-gluer
|
src/Gluer/THoldsSerializers_.php
|
THoldsSerializers_.achieveSerializer_
|
static protected function achieveSerializer_( string$mime ):S\ASerializer
{
static::checkSerializerSupported_( $mime );
$serializer= static::getSerializer_( $mime );
return static::instantiateSerializer_( $serializer );
}
|
php
|
static protected function achieveSerializer_( string$mime ):S\ASerializer
{
static::checkSerializerSupported_( $mime );
$serializer= static::getSerializer_( $mime );
return static::instantiateSerializer_( $serializer );
}
|
[
"static",
"protected",
"function",
"achieveSerializer_",
"(",
"string",
"$",
"mime",
")",
":",
"S",
"\\",
"ASerializer",
"{",
"static",
"::",
"checkSerializerSupported_",
"(",
"$",
"mime",
")",
";",
"$",
"serializer",
"=",
"static",
"::",
"getSerializer_",
"(",
"$",
"mime",
")",
";",
"return",
"static",
"::",
"instantiateSerializer_",
"(",
"$",
"serializer",
")",
";",
"}"
] |
Static method achieveSerializer_
@static
@access protected
@param string $mime
@return S\ASerializer
|
[
"Static",
"method",
"achieveSerializer_"
] |
3488de28b7f54fb444ec47f84034473a7d86e17e
|
https://github.com/Fenzland/http-api-gluer/blob/3488de28b7f54fb444ec47f84034473a7d86e17e/src/Gluer/THoldsSerializers_.php#L171-L178
|
24,644
|
varunsridharan/wp-post
|
src/Post.php
|
Post.set_post
|
protected function set_post( $post ) {
$this->post = $post;
$this->id = ( isset( $post->ID ) ) ? $post->ID : false;
if ( ! empty( $this->taxonomies() ) ) {
foreach ( $this->taxonomies() as $taxonomy ) {
$this->{$taxonomy} = $this->get_terms( $taxonomy, array( 'fields' => 'all' ) );
}
}
}
|
php
|
protected function set_post( $post ) {
$this->post = $post;
$this->id = ( isset( $post->ID ) ) ? $post->ID : false;
if ( ! empty( $this->taxonomies() ) ) {
foreach ( $this->taxonomies() as $taxonomy ) {
$this->{$taxonomy} = $this->get_terms( $taxonomy, array( 'fields' => 'all' ) );
}
}
}
|
[
"protected",
"function",
"set_post",
"(",
"$",
"post",
")",
"{",
"$",
"this",
"->",
"post",
"=",
"$",
"post",
";",
"$",
"this",
"->",
"id",
"=",
"(",
"isset",
"(",
"$",
"post",
"->",
"ID",
")",
")",
"?",
"$",
"post",
"->",
"ID",
":",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taxonomies",
"(",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"taxonomies",
"(",
")",
"as",
"$",
"taxonomy",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"taxonomy",
"}",
"=",
"$",
"this",
"->",
"get_terms",
"(",
"$",
"taxonomy",
",",
"array",
"(",
"'fields'",
"=>",
"'all'",
")",
")",
";",
"}",
"}",
"}"
] |
Sets Post Data.
@param $post
|
[
"Sets",
"Post",
"Data",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L70-L79
|
24,645
|
varunsridharan/wp-post
|
src/Post.php
|
Post.featured_image_id
|
public function featured_image_id() {
if ( isset( $this->featured_image_id ) ) {
return $this->featured_image_id;
}
$this->featured_image_id = \get_post_thumbnail_id( $this->post );
return $this->featured_image_id;
}
|
php
|
public function featured_image_id() {
if ( isset( $this->featured_image_id ) ) {
return $this->featured_image_id;
}
$this->featured_image_id = \get_post_thumbnail_id( $this->post );
return $this->featured_image_id;
}
|
[
"public",
"function",
"featured_image_id",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"featured_image_id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"featured_image_id",
";",
"}",
"$",
"this",
"->",
"featured_image_id",
"=",
"\\",
"get_post_thumbnail_id",
"(",
"$",
"this",
"->",
"post",
")",
";",
"return",
"$",
"this",
"->",
"featured_image_id",
";",
"}"
] |
Returns Featured Image ID.
@return bool|int|mixed|string
|
[
"Returns",
"Featured",
"Image",
"ID",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L137-L143
|
24,646
|
varunsridharan/wp-post
|
src/Post.php
|
Post.featured_image_url
|
public function featured_image_url( $size = 'thumbnail', $default = '' ) {
$featured_image = \get_the_post_thumbnail_url( $this->id(), $size );
return ( false !== $featured_image ) ? $featured_image : $default;
}
|
php
|
public function featured_image_url( $size = 'thumbnail', $default = '' ) {
$featured_image = \get_the_post_thumbnail_url( $this->id(), $size );
return ( false !== $featured_image ) ? $featured_image : $default;
}
|
[
"public",
"function",
"featured_image_url",
"(",
"$",
"size",
"=",
"'thumbnail'",
",",
"$",
"default",
"=",
"''",
")",
"{",
"$",
"featured_image",
"=",
"\\",
"get_the_post_thumbnail_url",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"size",
")",
";",
"return",
"(",
"false",
"!==",
"$",
"featured_image",
")",
"?",
"$",
"featured_image",
":",
"$",
"default",
";",
"}"
] |
Returns Featured Image URL.
@param string $size
@param string $default
@return false|string
|
[
"Returns",
"Featured",
"Image",
"URL",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L153-L156
|
24,647
|
varunsridharan/wp-post
|
src/Post.php
|
Post.parent
|
public function parent( $only_id = true ) {
if ( $only_id ) {
return $this->post->post_parent;
}
$class = get_called_class();
return new $class( $this->post->post_parent );
}
|
php
|
public function parent( $only_id = true ) {
if ( $only_id ) {
return $this->post->post_parent;
}
$class = get_called_class();
return new $class( $this->post->post_parent );
}
|
[
"public",
"function",
"parent",
"(",
"$",
"only_id",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"only_id",
")",
"{",
"return",
"$",
"this",
"->",
"post",
"->",
"post_parent",
";",
"}",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"post",
"->",
"post_parent",
")",
";",
"}"
] |
Returns Post Parent.
@param boolean $only_id
@return int
|
[
"Returns",
"Post",
"Parent",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L224-L230
|
24,648
|
varunsridharan/wp-post
|
src/Post.php
|
Post.update_meta
|
public function update_meta( $meta_key = '', $values = '', $prev_values = '' ) {
return \update_post_meta( $this->id(), $meta_key, $values, $prev_values );
}
|
php
|
public function update_meta( $meta_key = '', $values = '', $prev_values = '' ) {
return \update_post_meta( $this->id(), $meta_key, $values, $prev_values );
}
|
[
"public",
"function",
"update_meta",
"(",
"$",
"meta_key",
"=",
"''",
",",
"$",
"values",
"=",
"''",
",",
"$",
"prev_values",
"=",
"''",
")",
"{",
"return",
"\\",
"update_post_meta",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"meta_key",
",",
"$",
"values",
",",
"$",
"prev_values",
")",
";",
"}"
] |
Updates Post Meta.
@param string $meta_key
@param string $values
@param string $prev_values
@return bool|int
|
[
"Updates",
"Post",
"Meta",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L313-L315
|
24,649
|
varunsridharan/wp-post
|
src/Post.php
|
Post.add_meta
|
public function add_meta( $meta_key = '', $values = '', $unique = false ) {
return \add_post_meta( $this->id(), $meta_key, $values, $unique );
}
|
php
|
public function add_meta( $meta_key = '', $values = '', $unique = false ) {
return \add_post_meta( $this->id(), $meta_key, $values, $unique );
}
|
[
"public",
"function",
"add_meta",
"(",
"$",
"meta_key",
"=",
"''",
",",
"$",
"values",
"=",
"''",
",",
"$",
"unique",
"=",
"false",
")",
"{",
"return",
"\\",
"add_post_meta",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"meta_key",
",",
"$",
"values",
",",
"$",
"unique",
")",
";",
"}"
] |
Adds Post Meta.
@param string $meta_key
@param string $values
@param boolean|bool $unique
@return bool|int
|
[
"Adds",
"Post",
"Meta",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L326-L328
|
24,650
|
varunsridharan/wp-post
|
src/Post.php
|
Post.taxonomies
|
public function taxonomies() {
if ( ! empty( $this->taxes ) ) {
return $this->taxes;
}
$taxes = \get_post_taxonomies( $this->post );
$this->taxes = $taxes;
return $this->taxes;
}
|
php
|
public function taxonomies() {
if ( ! empty( $this->taxes ) ) {
return $this->taxes;
}
$taxes = \get_post_taxonomies( $this->post );
$this->taxes = $taxes;
return $this->taxes;
}
|
[
"public",
"function",
"taxonomies",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taxes",
")",
")",
"{",
"return",
"$",
"this",
"->",
"taxes",
";",
"}",
"$",
"taxes",
"=",
"\\",
"get_post_taxonomies",
"(",
"$",
"this",
"->",
"post",
")",
";",
"$",
"this",
"->",
"taxes",
"=",
"$",
"taxes",
";",
"return",
"$",
"this",
"->",
"taxes",
";",
"}"
] |
Returns All Post Taxonomies.
@return array
|
[
"Returns",
"All",
"Post",
"Taxonomies",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L351-L358
|
24,651
|
varunsridharan/wp-post
|
src/Post.php
|
Post.get_terms
|
public function get_terms( $taxonomy = '', $args = array() ) {
if ( isset( $this->{$taxonomy} ) && empty( $args ) ) {
return $this->{$taxonomy};
} else {
$name = $taxonomy . '_' . md5( json_encode( $args ) );
if ( isset( $this->{$name} ) ) {
return $this->{$name};
}
$data = \wp_get_post_terms( $this->id(), $taxonomy, $args );
$this->{$name} = $data;
return $data;
}
}
|
php
|
public function get_terms( $taxonomy = '', $args = array() ) {
if ( isset( $this->{$taxonomy} ) && empty( $args ) ) {
return $this->{$taxonomy};
} else {
$name = $taxonomy . '_' . md5( json_encode( $args ) );
if ( isset( $this->{$name} ) ) {
return $this->{$name};
}
$data = \wp_get_post_terms( $this->id(), $taxonomy, $args );
$this->{$name} = $data;
return $data;
}
}
|
[
"public",
"function",
"get_terms",
"(",
"$",
"taxonomy",
"=",
"''",
",",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"taxonomy",
"}",
")",
"&&",
"empty",
"(",
"$",
"args",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"taxonomy",
"}",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"taxonomy",
".",
"'_'",
".",
"md5",
"(",
"json_encode",
"(",
"$",
"args",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"name",
"}",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"name",
"}",
";",
"}",
"$",
"data",
"=",
"\\",
"wp_get_post_terms",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"taxonomy",
",",
"$",
"args",
")",
";",
"$",
"this",
"->",
"{",
"$",
"name",
"}",
"=",
"$",
"data",
";",
"return",
"$",
"data",
";",
"}",
"}"
] |
Returns All Terms From Post.
@param string $taxonomy
@param array $args
@return array|\WP_Error
|
[
"Returns",
"All",
"Terms",
"From",
"Post",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L368-L380
|
24,652
|
varunsridharan/wp-post
|
src/Post.php
|
Post.set_terms
|
public function set_terms( $terms = array(), $taxonomy = '', $append = false ) {
return \wp_set_post_terms( $this->id(), $terms, $taxonomy, $append );
}
|
php
|
public function set_terms( $terms = array(), $taxonomy = '', $append = false ) {
return \wp_set_post_terms( $this->id(), $terms, $taxonomy, $append );
}
|
[
"public",
"function",
"set_terms",
"(",
"$",
"terms",
"=",
"array",
"(",
")",
",",
"$",
"taxonomy",
"=",
"''",
",",
"$",
"append",
"=",
"false",
")",
"{",
"return",
"\\",
"wp_set_post_terms",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"terms",
",",
"$",
"taxonomy",
",",
"$",
"append",
")",
";",
"}"
] |
Sets Given Terms With Tax To The Current Post.
@param array $terms
@param string $taxonomy
@param bool $append
@return array|false|\WP_Error
|
[
"Sets",
"Given",
"Terms",
"With",
"Tax",
"To",
"The",
"Current",
"Post",
"."
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L391-L393
|
24,653
|
varunsridharan/wp-post
|
src/Post.php
|
Post.in
|
public function in( $key = '', $data = '', $default = false ) {
if ( is_array( $data ) ) {
return ( in_array( $key, $data ) ) ? $key : $default;
}
if ( isset( $this->{$data} ) ) {
return ( in_array( $key, $this->{$data} ) ) ? $key : $default;
}
return $default;
}
|
php
|
public function in( $key = '', $data = '', $default = false ) {
if ( is_array( $data ) ) {
return ( in_array( $key, $data ) ) ? $key : $default;
}
if ( isset( $this->{$data} ) ) {
return ( in_array( $key, $this->{$data} ) ) ? $key : $default;
}
return $default;
}
|
[
"public",
"function",
"in",
"(",
"$",
"key",
"=",
"''",
",",
"$",
"data",
"=",
"''",
",",
"$",
"default",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"data",
")",
")",
"?",
"$",
"key",
":",
"$",
"default",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"data",
"}",
")",
")",
"{",
"return",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"{",
"$",
"data",
"}",
")",
")",
"?",
"$",
"key",
":",
"$",
"default",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Checks if given key is in array
@uses \in_array()
@uses \VS_WP_Post
@example in('somekey','post_category','no') post_category will be taken from post data.
@example in('somekey',array('somekey' => 'somekey'), will be used the given array.
@param string $key
@param string $data
@param bool $default
@return bool|string
|
[
"Checks",
"if",
"given",
"key",
"is",
"in",
"array"
] |
064bdc55c945b08480c841c1b99502eb8df148e1
|
https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L415-L423
|
24,654
|
linpax/microphp-framework
|
src/cli/CliApplication.php
|
CliApplication.doException
|
protected function doException(\Exception $e)
{
$command = new DefaultConsoleCommand();
$command->data = '"Error #' . $e->getCode() . ' - ' . $e->getMessage() . '"';
$command->execute();
$response = (new ResponseInjector)->build();
$response = $response->withHeader('status', (string)(int)$command->result); // TODO: hack for select cli stream
$stream = $response->getBody();
$stream->write($command->message);
return $response->withBody($stream);
}
|
php
|
protected function doException(\Exception $e)
{
$command = new DefaultConsoleCommand();
$command->data = '"Error #' . $e->getCode() . ' - ' . $e->getMessage() . '"';
$command->execute();
$response = (new ResponseInjector)->build();
$response = $response->withHeader('status', (string)(int)$command->result); // TODO: hack for select cli stream
$stream = $response->getBody();
$stream->write($command->message);
return $response->withBody($stream);
}
|
[
"protected",
"function",
"doException",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"command",
"=",
"new",
"DefaultConsoleCommand",
"(",
")",
";",
"$",
"command",
"->",
"data",
"=",
"'\"Error #'",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' - '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'\"'",
";",
"$",
"command",
"->",
"execute",
"(",
")",
";",
"$",
"response",
"=",
"(",
"new",
"ResponseInjector",
")",
"->",
"build",
"(",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"'status'",
",",
"(",
"string",
")",
"(",
"int",
")",
"$",
"command",
"->",
"result",
")",
";",
"// TODO: hack for select cli stream",
"$",
"stream",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"$",
"stream",
"->",
"write",
"(",
"$",
"command",
"->",
"message",
")",
";",
"return",
"$",
"response",
"->",
"withBody",
"(",
"$",
"stream",
")",
";",
"}"
] |
Run application with error
@param \Exception $e
@return ResponseInterface
@throws \InvalidArgumentException|\RuntimeException|Exception
|
[
"Run",
"application",
"with",
"error"
] |
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
|
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/cli/CliApplication.php#L30-L43
|
24,655
|
Wedeto/Util
|
src/DI/DI.php
|
DI.startNewContext
|
public static function startNewContext(string $name, bool $inherit = true)
{
if ($inherit)
{
$current = static::getInjector();
$new_injector = new Injector($current);
}
else
$new_injector = new Injector();
return static::$injectors[$name] = $new_injector;
}
|
php
|
public static function startNewContext(string $name, bool $inherit = true)
{
if ($inherit)
{
$current = static::getInjector();
$new_injector = new Injector($current);
}
else
$new_injector = new Injector();
return static::$injectors[$name] = $new_injector;
}
|
[
"public",
"static",
"function",
"startNewContext",
"(",
"string",
"$",
"name",
",",
"bool",
"$",
"inherit",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"inherit",
")",
"{",
"$",
"current",
"=",
"static",
"::",
"getInjector",
"(",
")",
";",
"$",
"new_injector",
"=",
"new",
"Injector",
"(",
"$",
"current",
")",
";",
"}",
"else",
"$",
"new_injector",
"=",
"new",
"Injector",
"(",
")",
";",
"return",
"static",
"::",
"$",
"injectors",
"[",
"$",
"name",
"]",
"=",
"$",
"new_injector",
";",
"}"
] |
Start a new injection context. Useful to be able to release
all static context to a certain run of the software, for example
in testing.
@param string $name A name for the injection context
@param bool $inherit True to inherit instances from the current injector,
false to start with an empty set.
|
[
"Start",
"a",
"new",
"injection",
"context",
".",
"Useful",
"to",
"be",
"able",
"to",
"release",
"all",
"static",
"context",
"to",
"a",
"certain",
"run",
"of",
"the",
"software",
"for",
"example",
"in",
"testing",
"."
] |
0e080251bbaa8e7d91ae8d02eb79c029c976744a
|
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/DI.php#L63-L74
|
24,656
|
Wedeto/Util
|
src/DI/DI.php
|
DI.destroyContext
|
public static function destroyContext(string $name)
{
end(static::$injectors);
if ($name !== key(static::$injectors))
throw new DIException("Injection context $name is not at top of the stack");
$injector = array_pop(static::$injectors);
}
|
php
|
public static function destroyContext(string $name)
{
end(static::$injectors);
if ($name !== key(static::$injectors))
throw new DIException("Injection context $name is not at top of the stack");
$injector = array_pop(static::$injectors);
}
|
[
"public",
"static",
"function",
"destroyContext",
"(",
"string",
"$",
"name",
")",
"{",
"end",
"(",
"static",
"::",
"$",
"injectors",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"key",
"(",
"static",
"::",
"$",
"injectors",
")",
")",
"throw",
"new",
"DIException",
"(",
"\"Injection context $name is not at top of the stack\"",
")",
";",
"$",
"injector",
"=",
"array_pop",
"(",
"static",
"::",
"$",
"injectors",
")",
";",
"}"
] |
Destroy a context - the injector at the top of the stack
is released.
@param string $name The name of the injection context
@throws DIException When the injection context is not at the top of the stack
|
[
"Destroy",
"a",
"context",
"-",
"the",
"injector",
"at",
"the",
"top",
"of",
"the",
"stack",
"is",
"released",
"."
] |
0e080251bbaa8e7d91ae8d02eb79c029c976744a
|
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/DI.php#L83-L90
|
24,657
|
g4code/utility
|
src/Cleaner.php
|
Cleaner.getHtml
|
public function getHtml($variable, $default = '', $allowed = "", $escape = true)
{
return (string) rawurldecode($this->get($variable, $default, $allowed, $escape));
}
|
php
|
public function getHtml($variable, $default = '', $allowed = "", $escape = true)
{
return (string) rawurldecode($this->get($variable, $default, $allowed, $escape));
}
|
[
"public",
"function",
"getHtml",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"''",
",",
"$",
"allowed",
"=",
"\"\"",
",",
"$",
"escape",
"=",
"true",
")",
"{",
"return",
"(",
"string",
")",
"rawurldecode",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"$",
"allowed",
",",
"$",
"escape",
")",
")",
";",
"}"
] |
Same as _get, but it rawurldecodes the string
@param mixed $variable - variable
@param mixed $default - default value if variable not set
@param mixed $allowed - array of allowed values
@param bool $escape - escape quotes
@return string
|
[
"Same",
"as",
"_get",
"but",
"it",
"rawurldecodes",
"the",
"string"
] |
e0c9138aab61a53d88f32bb66201b075f3f44f1d
|
https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L62-L65
|
24,658
|
g4code/utility
|
src/Cleaner.php
|
Cleaner.getString
|
public function getString($variable, $default = '', $allowed = "", $escape = true)
{
return (string) strip_tags($this->getHtml($variable, $default, $allowed, $escape));
}
|
php
|
public function getString($variable, $default = '', $allowed = "", $escape = true)
{
return (string) strip_tags($this->getHtml($variable, $default, $allowed, $escape));
}
|
[
"public",
"function",
"getString",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"''",
",",
"$",
"allowed",
"=",
"\"\"",
",",
"$",
"escape",
"=",
"true",
")",
"{",
"return",
"(",
"string",
")",
"strip_tags",
"(",
"$",
"this",
"->",
"getHtml",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"$",
"allowed",
",",
"$",
"escape",
")",
")",
";",
"}"
] |
Same as _getHtml, but it also strips tags
@param mixed $variable - variable
@param mixed $default - default value if variable not set
@param mixed $allowed - array of allowed values
@param bool $escape - escape quotes
@return string
|
[
"Same",
"as",
"_getHtml",
"but",
"it",
"also",
"strips",
"tags"
] |
e0c9138aab61a53d88f32bb66201b075f3f44f1d
|
https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L76-L79
|
24,659
|
g4code/utility
|
src/Cleaner.php
|
Cleaner.getBool
|
public function getBool($variable, $default = false)
{
return (bool) $this->get($variable, $default, array(false, true), false);
}
|
php
|
public function getBool($variable, $default = false)
{
return (bool) $this->get($variable, $default, array(false, true), false);
}
|
[
"public",
"function",
"getBool",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"false",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"get",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"array",
"(",
"false",
",",
"true",
")",
",",
"false",
")",
";",
"}"
] |
Same as _get but casts return value to bollean
@access public
@param mixed $variable - variable
@return bool
|
[
"Same",
"as",
"_get",
"but",
"casts",
"return",
"value",
"to",
"bollean"
] |
e0c9138aab61a53d88f32bb66201b075f3f44f1d
|
https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L116-L119
|
24,660
|
g4code/utility
|
src/Cleaner.php
|
Cleaner.htmlEncode
|
public function htmlEncode($string, $quoteStyle = ENT_QUOTES, $charset = 'UTF-8', $doubleEncode = false)
{
return htmlspecialchars((string) $string, $quoteStyle, $charset, $doubleEncode);
}
|
php
|
public function htmlEncode($string, $quoteStyle = ENT_QUOTES, $charset = 'UTF-8', $doubleEncode = false)
{
return htmlspecialchars((string) $string, $quoteStyle, $charset, $doubleEncode);
}
|
[
"public",
"function",
"htmlEncode",
"(",
"$",
"string",
",",
"$",
"quoteStyle",
"=",
"ENT_QUOTES",
",",
"$",
"charset",
"=",
"'UTF-8'",
",",
"$",
"doubleEncode",
"=",
"false",
")",
"{",
"return",
"htmlspecialchars",
"(",
"(",
"string",
")",
"$",
"string",
",",
"$",
"quoteStyle",
",",
"$",
"charset",
",",
"$",
"doubleEncode",
")",
";",
"}"
] |
Replacement for htmlspecialchars
@param string $string
@param int $quoteStyle default ENT_QUOTES
@param string $charset default UTF-8
@param bool $doubleEncode - when double_encode is turned off PHP will not encode existing html entities
@return string
|
[
"Replacement",
"for",
"htmlspecialchars"
] |
e0c9138aab61a53d88f32bb66201b075f3f44f1d
|
https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L184-L187
|
24,661
|
stubbles/stubbles-dbal
|
src/main/php/Database.php
|
Database.query
|
public function query(string $sql, array $values = []): int
{
return $this->dbConnection->prepare($sql)
->execute($values)
->count();
}
|
php
|
public function query(string $sql, array $values = []): int
{
return $this->dbConnection->prepare($sql)
->execute($values)
->count();
}
|
[
"public",
"function",
"query",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"dbConnection",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"values",
")",
"->",
"count",
"(",
")",
";",
"}"
] |
sends a query to the database and returns amount of affected records
@param string $sql
@param array $values
@return int
@since 3.1.0
|
[
"sends",
"a",
"query",
"to",
"the",
"database",
"and",
"returns",
"amount",
"of",
"affected",
"records"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L57-L62
|
24,662
|
stubbles/stubbles-dbal
|
src/main/php/Database.php
|
Database.fetchOne
|
public function fetchOne(string $sql, array $values = [], int $columnNumber = 0): string
{
return $this->dbConnection->prepare($sql)
->execute($values)
->fetchOne($columnNumber);
}
|
php
|
public function fetchOne(string $sql, array $values = [], int $columnNumber = 0): string
{
return $this->dbConnection->prepare($sql)
->execute($values)
->fetchOne($columnNumber);
}
|
[
"public",
"function",
"fetchOne",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"int",
"$",
"columnNumber",
"=",
"0",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"dbConnection",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"values",
")",
"->",
"fetchOne",
"(",
"$",
"columnNumber",
")",
";",
"}"
] |
fetch single value from a result set
@param string $sql sql query to fetch data with
@param array $values map of values in case $sql contains a prepared statement
@param int $columnNumber optional the column number to fetch, default is first column
@return string
@throws \stubbles\db\DatabaseException
@since 3.1.0
|
[
"fetch",
"single",
"value",
"from",
"a",
"result",
"set"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L74-L79
|
24,663
|
stubbles/stubbles-dbal
|
src/main/php/Database.php
|
Database.fetchAll
|
public function fetchAll(
string $sql,
array $values = [],
int $fetchMode = null,
array $driverOptions = []
): Sequence {
return Sequence::of(new QueryResultIterator(
$this->dbConnection->prepare($sql)->execute($values),
$fetchMode,
$driverOptions
));
}
|
php
|
public function fetchAll(
string $sql,
array $values = [],
int $fetchMode = null,
array $driverOptions = []
): Sequence {
return Sequence::of(new QueryResultIterator(
$this->dbConnection->prepare($sql)->execute($values),
$fetchMode,
$driverOptions
));
}
|
[
"public",
"function",
"fetchAll",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"int",
"$",
"fetchMode",
"=",
"null",
",",
"array",
"$",
"driverOptions",
"=",
"[",
"]",
")",
":",
"Sequence",
"{",
"return",
"Sequence",
"::",
"of",
"(",
"new",
"QueryResultIterator",
"(",
"$",
"this",
"->",
"dbConnection",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"values",
")",
",",
"$",
"fetchMode",
",",
"$",
"driverOptions",
")",
")",
";",
"}"
] |
return all result rows for given sql query
Allows to fetch all results for a query at once.
<code>
$blockedUsers = $database->fetchAll('SELECT * FROM users WHERE status = "blocked"');
</code>
Now $blockedUsers contains all rows from the query.
@param string $sql sql query to fetch data with
@param array $values map of values in case $sql contains a prepared statement
@param int $fetchMode optional the mode to use for fetching the data
@param array $driverOptions optional driver specific arguments
@return \stubbles\sequence\Sequence
|
[
"return",
"all",
"result",
"rows",
"for",
"given",
"sql",
"query"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L96-L107
|
24,664
|
stubbles/stubbles-dbal
|
src/main/php/Database.php
|
Database.fetchRow
|
public function fetchRow(
string $sql,
array $values = [],
int $fetchMode = null,
array $driverOptions = []
): array {
return $this->dbConnection->prepare($sql)
->execute($values)
->fetch($fetchMode, $driverOptions);
}
|
php
|
public function fetchRow(
string $sql,
array $values = [],
int $fetchMode = null,
array $driverOptions = []
): array {
return $this->dbConnection->prepare($sql)
->execute($values)
->fetch($fetchMode, $driverOptions);
}
|
[
"public",
"function",
"fetchRow",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"int",
"$",
"fetchMode",
"=",
"null",
",",
"array",
"$",
"driverOptions",
"=",
"[",
"]",
")",
":",
"array",
"{",
"return",
"$",
"this",
"->",
"dbConnection",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"values",
")",
"->",
"fetch",
"(",
"$",
"fetchMode",
",",
"$",
"driverOptions",
")",
";",
"}"
] |
returns first result row for given sql query
@param string $sql sql query to fetch data with
@param array $values map of values in case $sql contains a prepared statement
@param int $fetchMode optional the mode to use for fetching the data
@param array $driverOptions optional driver specific arguments
@return array
@since 2.4.0
|
[
"returns",
"first",
"result",
"row",
"for",
"given",
"sql",
"query"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L119-L128
|
24,665
|
stubbles/stubbles-dbal
|
src/main/php/Database.php
|
Database.fetchColumn
|
public function fetchColumn(
string $sql,
array $values = [],
int $columnIndex = 0
): Sequence {
return $this->fetchAll(
$sql,
$values,
\PDO::FETCH_COLUMN,
['columnIndex' => $columnIndex]
);
}
|
php
|
public function fetchColumn(
string $sql,
array $values = [],
int $columnIndex = 0
): Sequence {
return $this->fetchAll(
$sql,
$values,
\PDO::FETCH_COLUMN,
['columnIndex' => $columnIndex]
);
}
|
[
"public",
"function",
"fetchColumn",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"int",
"$",
"columnIndex",
"=",
"0",
")",
":",
"Sequence",
"{",
"return",
"$",
"this",
"->",
"fetchAll",
"(",
"$",
"sql",
",",
"$",
"values",
",",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
",",
"[",
"'columnIndex'",
"=>",
"$",
"columnIndex",
"]",
")",
";",
"}"
] |
return a list with all rows from given result
Allows to map the result into a list of values from one single column:
<code>
$userNames = $database->fetchColumn('SELECT username FROM users WHERE status = "blocked"');
</code>
@param string $sql sql query to fetch data with
@param array $values map of values in case $sql contains a prepared statement
@param int $columnIndex number of column to fetch
@return \stubbles\sequence\Sequence
|
[
"return",
"a",
"list",
"with",
"all",
"rows",
"from",
"given",
"result"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L143-L154
|
24,666
|
Innmind/Math
|
src/Regression/LinearRegression.php
|
LinearRegression.compute
|
private function compute(Dataset $data): array
{
$dimension = $data->dimension()->rows();
$elements = $dimension->value();
$x = $data->abscissas()->toArray();
$y = $data->ordinates()->toArray();
$xSum = $data->abscissas()->sum();
$ySum = $data->ordinates()->sum();
$xxSum = new Integer(0);
$xySum = new Integer(0);
for ($i = 0; $i < $elements; $i++) {
$xySum = add($xySum, multiply($x[$i], $y[$i]));
$xxSum = add($xxSum, multiply($x[$i], $x[$i]));
}
$slope = divide(
subtract(
$dimension->multiplyBy($xySum),
$xSum->multiplyBy($ySum)
),
subtract(
$dimension->multiplyBy($xxSum),
$xSum->power(new Integer(2))
)
);
$intercept = divide(
subtract(
$ySum,
$slope->multiplyBy($xSum)
),
$dimension
);
return [$slope, $intercept];
}
|
php
|
private function compute(Dataset $data): array
{
$dimension = $data->dimension()->rows();
$elements = $dimension->value();
$x = $data->abscissas()->toArray();
$y = $data->ordinates()->toArray();
$xSum = $data->abscissas()->sum();
$ySum = $data->ordinates()->sum();
$xxSum = new Integer(0);
$xySum = new Integer(0);
for ($i = 0; $i < $elements; $i++) {
$xySum = add($xySum, multiply($x[$i], $y[$i]));
$xxSum = add($xxSum, multiply($x[$i], $x[$i]));
}
$slope = divide(
subtract(
$dimension->multiplyBy($xySum),
$xSum->multiplyBy($ySum)
),
subtract(
$dimension->multiplyBy($xxSum),
$xSum->power(new Integer(2))
)
);
$intercept = divide(
subtract(
$ySum,
$slope->multiplyBy($xSum)
),
$dimension
);
return [$slope, $intercept];
}
|
[
"private",
"function",
"compute",
"(",
"Dataset",
"$",
"data",
")",
":",
"array",
"{",
"$",
"dimension",
"=",
"$",
"data",
"->",
"dimension",
"(",
")",
"->",
"rows",
"(",
")",
";",
"$",
"elements",
"=",
"$",
"dimension",
"->",
"value",
"(",
")",
";",
"$",
"x",
"=",
"$",
"data",
"->",
"abscissas",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"y",
"=",
"$",
"data",
"->",
"ordinates",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"xSum",
"=",
"$",
"data",
"->",
"abscissas",
"(",
")",
"->",
"sum",
"(",
")",
";",
"$",
"ySum",
"=",
"$",
"data",
"->",
"ordinates",
"(",
")",
"->",
"sum",
"(",
")",
";",
"$",
"xxSum",
"=",
"new",
"Integer",
"(",
"0",
")",
";",
"$",
"xySum",
"=",
"new",
"Integer",
"(",
"0",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"elements",
";",
"$",
"i",
"++",
")",
"{",
"$",
"xySum",
"=",
"add",
"(",
"$",
"xySum",
",",
"multiply",
"(",
"$",
"x",
"[",
"$",
"i",
"]",
",",
"$",
"y",
"[",
"$",
"i",
"]",
")",
")",
";",
"$",
"xxSum",
"=",
"add",
"(",
"$",
"xxSum",
",",
"multiply",
"(",
"$",
"x",
"[",
"$",
"i",
"]",
",",
"$",
"x",
"[",
"$",
"i",
"]",
")",
")",
";",
"}",
"$",
"slope",
"=",
"divide",
"(",
"subtract",
"(",
"$",
"dimension",
"->",
"multiplyBy",
"(",
"$",
"xySum",
")",
",",
"$",
"xSum",
"->",
"multiplyBy",
"(",
"$",
"ySum",
")",
")",
",",
"subtract",
"(",
"$",
"dimension",
"->",
"multiplyBy",
"(",
"$",
"xxSum",
")",
",",
"$",
"xSum",
"->",
"power",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
")",
")",
";",
"$",
"intercept",
"=",
"divide",
"(",
"subtract",
"(",
"$",
"ySum",
",",
"$",
"slope",
"->",
"multiplyBy",
"(",
"$",
"xSum",
")",
")",
",",
"$",
"dimension",
")",
";",
"return",
"[",
"$",
"slope",
",",
"$",
"intercept",
"]",
";",
"}"
] |
Determine the slope and intercept for the given dataset
@see https://richardathome.wordpress.com/2006/01/25/a-php-linear-regression-function/
@param Dataset $data
@return array
|
[
"Determine",
"the",
"slope",
"and",
"intercept",
"for",
"the",
"given",
"dataset"
] |
ac9ad4dd1852c145e90f5edc0f38a873b125a50b
|
https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Regression/LinearRegression.php#L80-L116
|
24,667
|
drdplusinfo/drdplus-skills
|
DrdPlus/Skills/Skills.php
|
Skills.getMalusToBaseOfWoundsWithWeaponlike
|
public function getMalusToBaseOfWoundsWithWeaponlike(
WeaponlikeCode $weaponlikeCode,
Tables $tables,
bool $fightsWithTwoWeapons
): int
{
if ($weaponlikeCode->isMelee() || $weaponlikeCode->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToBaseOfWoundsWithWeaponlike($weaponlikeCode, $tables, $fightsWithTwoWeapons);
}
if ($weaponlikeCode->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToBaseOfWoundsWithShootingWeapon(
$weaponlikeCode->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
if ($weaponlikeCode->isProjectile()) {
return 0;
}
throw new Exceptions\UnknownTypeOfWeapon($weaponlikeCode);
}
|
php
|
public function getMalusToBaseOfWoundsWithWeaponlike(
WeaponlikeCode $weaponlikeCode,
Tables $tables,
bool $fightsWithTwoWeapons
): int
{
if ($weaponlikeCode->isMelee() || $weaponlikeCode->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToBaseOfWoundsWithWeaponlike($weaponlikeCode, $tables, $fightsWithTwoWeapons);
}
if ($weaponlikeCode->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToBaseOfWoundsWithShootingWeapon(
$weaponlikeCode->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
if ($weaponlikeCode->isProjectile()) {
return 0;
}
throw new Exceptions\UnknownTypeOfWeapon($weaponlikeCode);
}
|
[
"public",
"function",
"getMalusToBaseOfWoundsWithWeaponlike",
"(",
"WeaponlikeCode",
"$",
"weaponlikeCode",
",",
"Tables",
"$",
"tables",
",",
"bool",
"$",
"fightsWithTwoWeapons",
")",
":",
"int",
"{",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isMelee",
"(",
")",
"||",
"$",
"weaponlikeCode",
"->",
"isThrowingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getPhysicalSkills",
"(",
")",
"->",
"getMalusToBaseOfWoundsWithWeaponlike",
"(",
"$",
"weaponlikeCode",
",",
"$",
"tables",
",",
"$",
"fightsWithTwoWeapons",
")",
";",
"}",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isShootingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getCombinedSkills",
"(",
")",
"->",
"getMalusToBaseOfWoundsWithShootingWeapon",
"(",
"$",
"weaponlikeCode",
"->",
"convertToRangedWeaponCodeEquivalent",
"(",
")",
",",
"$",
"tables",
")",
";",
"}",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isProjectile",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"throw",
"new",
"Exceptions",
"\\",
"UnknownTypeOfWeapon",
"(",
"$",
"weaponlikeCode",
")",
";",
"}"
] |
If you want to use shield as a PROTECTIVE item, there is no base of wounds malus from that.
@param WeaponlikeCode $weaponlikeCode
@param Tables $tables
@param bool $fightsWithTwoWeapons
@return int
@throws Exceptions\UnknownTypeOfWeapon
|
[
"If",
"you",
"want",
"to",
"use",
"shield",
"as",
"a",
"PROTECTIVE",
"item",
"there",
"is",
"no",
"base",
"of",
"wounds",
"malus",
"from",
"that",
"."
] |
9ae6ecdbaadf594d6572ec0c190fc13572c0a53f
|
https://github.com/drdplusinfo/drdplus-skills/blob/9ae6ecdbaadf594d6572ec0c190fc13572c0a53f/DrdPlus/Skills/Skills.php#L685-L704
|
24,668
|
thomasez/BisonLabSakonninBundle
|
EventListener/SakonninFileListener.php
|
SakonninFileListener.preRemove
|
public function preRemove(EventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof SakonninFile) {
// VichUploader removes this property when it removes the file,
// alas I need to store it somehow.
$this->removes[] = $entity->getStoredAs();
}
}
|
php
|
public function preRemove(EventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof SakonninFile) {
// VichUploader removes this property when it removes the file,
// alas I need to store it somehow.
$this->removes[] = $entity->getStoredAs();
}
}
|
[
"public",
"function",
"preRemove",
"(",
"EventArgs",
"$",
"args",
")",
"{",
"$",
"entity",
"=",
"$",
"args",
"->",
"getEntity",
"(",
")",
";",
"if",
"(",
"$",
"entity",
"instanceof",
"SakonninFile",
")",
"{",
"// VichUploader removes this property when it removes the file,",
"// alas I need to store it somehow.",
"$",
"this",
"->",
"removes",
"[",
"]",
"=",
"$",
"entity",
"->",
"getStoredAs",
"(",
")",
";",
"}",
"}"
] |
Ensures a proxy will be usable in the postRemove.
@param EventArgs $event The event.
|
[
"Ensures",
"a",
"proxy",
"will",
"be",
"usable",
"in",
"the",
"postRemove",
"."
] |
45ca7ce9874c4a2be7b503d7067b3d11d2b518cb
|
https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/EventListener/SakonninFileListener.php#L45-L53
|
24,669
|
NukaCode/Front-End-Bootstrap
|
src/NukaCode/Bootstrap/Filesystem/Less/Variables.php
|
Variables.updateEntry
|
public function updateEntry($package)
{
$this->verifyCommand($package);
$lines = file($this->less);
// Set the new colors
$lines[0] = '@bg: ' . $package['bg'] . ";\n";
$lines[1] = '@gray: ' . $package['gray'] . ";\n";
$lines[2] = '@brand-primary: ' . $package['primary'] . ";\n";
$lines[3] = '@brand-info: ' . $package['info'] . ";\n";
$lines[4] = '@brand-success: ' . $package['success'] . ";\n";
$lines[5] = '@brand-warning: ' . $package['warning'] . ";\n";
$lines[6] = '@brand-danger: ' . $package['danger'] . ";\n";
$lines[7] = '@menuColor: ' . $package['menu'] . ";\n";
$this->file->delete($this->less);
$this->file->put($this->less, implode($lines));
}
|
php
|
public function updateEntry($package)
{
$this->verifyCommand($package);
$lines = file($this->less);
// Set the new colors
$lines[0] = '@bg: ' . $package['bg'] . ";\n";
$lines[1] = '@gray: ' . $package['gray'] . ";\n";
$lines[2] = '@brand-primary: ' . $package['primary'] . ";\n";
$lines[3] = '@brand-info: ' . $package['info'] . ";\n";
$lines[4] = '@brand-success: ' . $package['success'] . ";\n";
$lines[5] = '@brand-warning: ' . $package['warning'] . ";\n";
$lines[6] = '@brand-danger: ' . $package['danger'] . ";\n";
$lines[7] = '@menuColor: ' . $package['menu'] . ";\n";
$this->file->delete($this->less);
$this->file->put($this->less, implode($lines));
}
|
[
"public",
"function",
"updateEntry",
"(",
"$",
"package",
")",
"{",
"$",
"this",
"->",
"verifyCommand",
"(",
"$",
"package",
")",
";",
"$",
"lines",
"=",
"file",
"(",
"$",
"this",
"->",
"less",
")",
";",
"// Set the new colors",
"$",
"lines",
"[",
"0",
"]",
"=",
"'@bg: '",
".",
"$",
"package",
"[",
"'bg'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"1",
"]",
"=",
"'@gray: '",
".",
"$",
"package",
"[",
"'gray'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"2",
"]",
"=",
"'@brand-primary: '",
".",
"$",
"package",
"[",
"'primary'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"3",
"]",
"=",
"'@brand-info: '",
".",
"$",
"package",
"[",
"'info'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"4",
"]",
"=",
"'@brand-success: '",
".",
"$",
"package",
"[",
"'success'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"5",
"]",
"=",
"'@brand-warning: '",
".",
"$",
"package",
"[",
"'warning'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"6",
"]",
"=",
"'@brand-danger: '",
".",
"$",
"package",
"[",
"'danger'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"7",
"]",
"=",
"'@menuColor: '",
".",
"$",
"package",
"[",
"'menu'",
"]",
".",
"\";\\n\"",
";",
"$",
"this",
"->",
"file",
"->",
"delete",
"(",
"$",
"this",
"->",
"less",
")",
";",
"$",
"this",
"->",
"file",
"->",
"put",
"(",
"$",
"this",
"->",
"less",
",",
"implode",
"(",
"$",
"lines",
")",
")",
";",
"}"
] |
Update the colors.less file to persist the changes
@param $package
|
[
"Update",
"the",
"colors",
".",
"less",
"file",
"to",
"persist",
"the",
"changes"
] |
46c30fba4c77afb74ec4a4d70c43c9cffd464d6e
|
https://github.com/NukaCode/Front-End-Bootstrap/blob/46c30fba4c77afb74ec4a4d70c43c9cffd464d6e/src/NukaCode/Bootstrap/Filesystem/Less/Variables.php#L36-L54
|
24,670
|
zhaoxianfang/tools
|
src/Symfony/Component/DependencyInjection/Compiler/Compiler.php
|
Compiler.getLoggingFormatter
|
public function getLoggingFormatter()
{
if (null === $this->loggingFormatter) {
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', __METHOD__), E_USER_DEPRECATED);
$this->loggingFormatter = new LoggingFormatter();
}
return $this->loggingFormatter;
}
|
php
|
public function getLoggingFormatter()
{
if (null === $this->loggingFormatter) {
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', __METHOD__), E_USER_DEPRECATED);
$this->loggingFormatter = new LoggingFormatter();
}
return $this->loggingFormatter;
}
|
[
"public",
"function",
"getLoggingFormatter",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"loggingFormatter",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.'",
",",
"__METHOD__",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"loggingFormatter",
"=",
"new",
"LoggingFormatter",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"loggingFormatter",
";",
"}"
] |
Returns the logging formatter which can be used by compilation passes.
@return LoggingFormatter
@deprecated since version 3.3, to be removed in 4.0. Use the ContainerBuilder::log() method instead.
|
[
"Returns",
"the",
"logging",
"formatter",
"which",
"can",
"be",
"used",
"by",
"compilation",
"passes",
"."
] |
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
|
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php#L62-L71
|
24,671
|
creios/creiwork-framework
|
src/Util/JsonValidator.php
|
JsonValidator.validateJson
|
public function validateJson(string $json, string $schemaName): ValidationResult
{
$schemaDir = $this->config->get('schema-dir');
$schemaPath = $this->configDirectoryPath.$schemaDir.'/'.$schemaName.'.json';
if(!file_exists($schemaPath)){
throw new FileNotFoundException("File $schemaPath not found");
}
$schemaJsonString = file_get_contents($schemaPath);
$decodedJson = json_decode($json);
if ($decodedJson === false) {
$schema = json_decode($schemaJsonString);
// error decoding json
return (new ValidationResult())
->addError(new ValidationError($json,
[],
[],
$schema,
"Failed to decode JSON string")
);
}
return $this->dataValidation($decodedJson, $schemaJsonString);
}
|
php
|
public function validateJson(string $json, string $schemaName): ValidationResult
{
$schemaDir = $this->config->get('schema-dir');
$schemaPath = $this->configDirectoryPath.$schemaDir.'/'.$schemaName.'.json';
if(!file_exists($schemaPath)){
throw new FileNotFoundException("File $schemaPath not found");
}
$schemaJsonString = file_get_contents($schemaPath);
$decodedJson = json_decode($json);
if ($decodedJson === false) {
$schema = json_decode($schemaJsonString);
// error decoding json
return (new ValidationResult())
->addError(new ValidationError($json,
[],
[],
$schema,
"Failed to decode JSON string")
);
}
return $this->dataValidation($decodedJson, $schemaJsonString);
}
|
[
"public",
"function",
"validateJson",
"(",
"string",
"$",
"json",
",",
"string",
"$",
"schemaName",
")",
":",
"ValidationResult",
"{",
"$",
"schemaDir",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'schema-dir'",
")",
";",
"$",
"schemaPath",
"=",
"$",
"this",
"->",
"configDirectoryPath",
".",
"$",
"schemaDir",
".",
"'/'",
".",
"$",
"schemaName",
".",
"'.json'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"schemaPath",
")",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"\"File $schemaPath not found\"",
")",
";",
"}",
"$",
"schemaJsonString",
"=",
"file_get_contents",
"(",
"$",
"schemaPath",
")",
";",
"$",
"decodedJson",
"=",
"json_decode",
"(",
"$",
"json",
")",
";",
"if",
"(",
"$",
"decodedJson",
"===",
"false",
")",
"{",
"$",
"schema",
"=",
"json_decode",
"(",
"$",
"schemaJsonString",
")",
";",
"// error decoding json",
"return",
"(",
"new",
"ValidationResult",
"(",
")",
")",
"->",
"addError",
"(",
"new",
"ValidationError",
"(",
"$",
"json",
",",
"[",
"]",
",",
"[",
"]",
",",
"$",
"schema",
",",
"\"Failed to decode JSON string\"",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"dataValidation",
"(",
"$",
"decodedJson",
",",
"$",
"schemaJsonString",
")",
";",
"}"
] |
Validates JSON strings against a schema.
@param string $json
@param string $schemaName Name of the .json file providing the schema (without file extension)
@return ValidationResult
|
[
"Validates",
"JSON",
"strings",
"against",
"a",
"schema",
"."
] |
5089578b44ef6af725ab0c8a2dfe691bfe07ffb6
|
https://github.com/creios/creiwork-framework/blob/5089578b44ef6af725ab0c8a2dfe691bfe07ffb6/src/Util/JsonValidator.php#L84-L106
|
24,672
|
agentmedia/phine-core
|
src/Core/Logic/Installation/BundleInstaller.php
|
BundleInstaller.ExecuteSql
|
function ExecuteSql()
{
$versionCompare = version_compare($this->installedVersion, $this->manifest->Version());
if ($versionCompare > 0)
{
$bundle = $this->manifest->BundleName();
throw new \Exception("Error instaling bundle $bundle: Previously installed version is greater than curren code version. Please re-install the bundle.");
}
else if ($versionCompare === 0)
{
return;
}
$engineFolder = $this->FindEngineFolder();
if (!$engineFolder)
{
return;
}
$this->ExecuteScripts($engineFolder);
}
|
php
|
function ExecuteSql()
{
$versionCompare = version_compare($this->installedVersion, $this->manifest->Version());
if ($versionCompare > 0)
{
$bundle = $this->manifest->BundleName();
throw new \Exception("Error instaling bundle $bundle: Previously installed version is greater than curren code version. Please re-install the bundle.");
}
else if ($versionCompare === 0)
{
return;
}
$engineFolder = $this->FindEngineFolder();
if (!$engineFolder)
{
return;
}
$this->ExecuteScripts($engineFolder);
}
|
[
"function",
"ExecuteSql",
"(",
")",
"{",
"$",
"versionCompare",
"=",
"version_compare",
"(",
"$",
"this",
"->",
"installedVersion",
",",
"$",
"this",
"->",
"manifest",
"->",
"Version",
"(",
")",
")",
";",
"if",
"(",
"$",
"versionCompare",
">",
"0",
")",
"{",
"$",
"bundle",
"=",
"$",
"this",
"->",
"manifest",
"->",
"BundleName",
"(",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error instaling bundle $bundle: Previously installed version is greater than curren code version. Please re-install the bundle.\"",
")",
";",
"}",
"else",
"if",
"(",
"$",
"versionCompare",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"engineFolder",
"=",
"$",
"this",
"->",
"FindEngineFolder",
"(",
")",
";",
"if",
"(",
"!",
"$",
"engineFolder",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"ExecuteScripts",
"(",
"$",
"engineFolder",
")",
";",
"}"
] |
Executes all necessary sql scripts
|
[
"Executes",
"all",
"necessary",
"sql",
"scripts"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Installation/BundleInstaller.php#L52-L71
|
24,673
|
agentmedia/phine-core
|
src/Core/Logic/Installation/BundleInstaller.php
|
BundleInstaller.ExecuteScripts
|
private function ExecuteScripts($engineFolder)
{
$files = $this->SortFilesByVersion(Folder::GetFiles($engineFolder));
$completeSql = '';
foreach ($files as $file)
{
$sqlFile = Path::Combine($engineFolder, $file);
$completeSql .= "\r\n" . File::GetContents($sqlFile);
}
try
{
$this->CleanAllForeignKeys();
//$this->connection->StartTransaction();
$this->connection->ExecuteMultiQuery($completeSql);
}
catch (\Exception $exc)
{
//$this->connection->RollBack();
throw $exc;
//throw new \Exception("Error executing SQL in folder $engineFolder: " . $completeSql, null, $exc);
}
//$this->connection->Commit();
}
|
php
|
private function ExecuteScripts($engineFolder)
{
$files = $this->SortFilesByVersion(Folder::GetFiles($engineFolder));
$completeSql = '';
foreach ($files as $file)
{
$sqlFile = Path::Combine($engineFolder, $file);
$completeSql .= "\r\n" . File::GetContents($sqlFile);
}
try
{
$this->CleanAllForeignKeys();
//$this->connection->StartTransaction();
$this->connection->ExecuteMultiQuery($completeSql);
}
catch (\Exception $exc)
{
//$this->connection->RollBack();
throw $exc;
//throw new \Exception("Error executing SQL in folder $engineFolder: " . $completeSql, null, $exc);
}
//$this->connection->Commit();
}
|
[
"private",
"function",
"ExecuteScripts",
"(",
"$",
"engineFolder",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"SortFilesByVersion",
"(",
"Folder",
"::",
"GetFiles",
"(",
"$",
"engineFolder",
")",
")",
";",
"$",
"completeSql",
"=",
"''",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"sqlFile",
"=",
"Path",
"::",
"Combine",
"(",
"$",
"engineFolder",
",",
"$",
"file",
")",
";",
"$",
"completeSql",
".=",
"\"\\r\\n\"",
".",
"File",
"::",
"GetContents",
"(",
"$",
"sqlFile",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"CleanAllForeignKeys",
"(",
")",
";",
"//$this->connection->StartTransaction();",
"$",
"this",
"->",
"connection",
"->",
"ExecuteMultiQuery",
"(",
"$",
"completeSql",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exc",
")",
"{",
"//$this->connection->RollBack();",
"throw",
"$",
"exc",
";",
"//throw new \\Exception(\"Error executing SQL in folder $engineFolder: \" . $completeSql, null, $exc);",
"}",
"//$this->connection->Commit();",
"}"
] |
Executes all necessary scripts in the engine folder
@param string $engineFolder The folder
@throws \Exception Raises error if any of the scripts fail
|
[
"Executes",
"all",
"necessary",
"scripts",
"in",
"the",
"engine",
"folder"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Installation/BundleInstaller.php#L78-L101
|
24,674
|
agentmedia/phine-core
|
src/Core/Logic/Installation/BundleInstaller.php
|
BundleInstaller.CleanForeignKeys
|
private function CleanForeignKeys($table)
{
$foreignKeys = $this->connection->GetForeignKeys($table);
foreach ($foreignKeys as $foreignKey)
{
$this->connection->DropForeignKey($table, $foreignKey);
}
}
|
php
|
private function CleanForeignKeys($table)
{
$foreignKeys = $this->connection->GetForeignKeys($table);
foreach ($foreignKeys as $foreignKey)
{
$this->connection->DropForeignKey($table, $foreignKey);
}
}
|
[
"private",
"function",
"CleanForeignKeys",
"(",
"$",
"table",
")",
"{",
"$",
"foreignKeys",
"=",
"$",
"this",
"->",
"connection",
"->",
"GetForeignKeys",
"(",
"$",
"table",
")",
";",
"foreach",
"(",
"$",
"foreignKeys",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"DropForeignKey",
"(",
"$",
"table",
",",
"$",
"foreignKey",
")",
";",
"}",
"}"
] |
Cleans all foreign keys of a table
@param strign $table The table name
|
[
"Cleans",
"all",
"foreign",
"keys",
"of",
"a",
"table"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Installation/BundleInstaller.php#L119-L126
|
24,675
|
agentmedia/phine-core
|
src/Core/Logic/Installation/BundleInstaller.php
|
BundleInstaller.SortFilesByVersion
|
private function SortFilesByVersion(array $files)
{
$result = array();
$foreignKeysFile = '';
foreach ($files as $file)
{
if ($file == 'foreign-keys.sql')
{
$foreignKeysFile = $file;
continue;
}
$version = Path::RemoveExtension($file);
if ($this->installedVersion && version_compare($version, $this->installedVersion) <= 0)
{
continue;
}
$result[$version] = $file;
}
uksort($result, "version_compare");
if ($foreignKeysFile)
{
$result[] = $foreignKeysFile;
}
return $result;
}
|
php
|
private function SortFilesByVersion(array $files)
{
$result = array();
$foreignKeysFile = '';
foreach ($files as $file)
{
if ($file == 'foreign-keys.sql')
{
$foreignKeysFile = $file;
continue;
}
$version = Path::RemoveExtension($file);
if ($this->installedVersion && version_compare($version, $this->installedVersion) <= 0)
{
continue;
}
$result[$version] = $file;
}
uksort($result, "version_compare");
if ($foreignKeysFile)
{
$result[] = $foreignKeysFile;
}
return $result;
}
|
[
"private",
"function",
"SortFilesByVersion",
"(",
"array",
"$",
"files",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"foreignKeysFile",
"=",
"''",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"==",
"'foreign-keys.sql'",
")",
"{",
"$",
"foreignKeysFile",
"=",
"$",
"file",
";",
"continue",
";",
"}",
"$",
"version",
"=",
"Path",
"::",
"RemoveExtension",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"this",
"->",
"installedVersion",
"&&",
"version_compare",
"(",
"$",
"version",
",",
"$",
"this",
"->",
"installedVersion",
")",
"<=",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"version",
"]",
"=",
"$",
"file",
";",
"}",
"uksort",
"(",
"$",
"result",
",",
"\"version_compare\"",
")",
";",
"if",
"(",
"$",
"foreignKeysFile",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"foreignKeysFile",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Sorts files by version
@param string[] $files The files
@return string[] Returns the sorted files
|
[
"Sorts",
"files",
"by",
"version"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Installation/BundleInstaller.php#L156-L180
|
24,676
|
yuncms/yii2-oauth2
|
frontend/controllers/ClientController.php
|
ClientController.actionIndex
|
public function actionIndex()
{
$query = Client::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['created_at' => SORT_DESC]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
|
php
|
public function actionIndex()
{
$query = Client::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['created_at' => SORT_DESC]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
|
[
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"query",
"=",
"Client",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
"]",
")",
"->",
"orderBy",
"(",
"[",
"'created_at'",
"=>",
"SORT_DESC",
"]",
")",
";",
"$",
"dataProvider",
"=",
"new",
"ActiveDataProvider",
"(",
"[",
"'query'",
"=>",
"$",
"query",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'index'",
",",
"[",
"'dataProvider'",
"=>",
"$",
"dataProvider",
",",
"]",
")",
";",
"}"
] |
Lists all App models.
@return mixed
|
[
"Lists",
"all",
"App",
"models",
"."
] |
7fb41fc56d4a6a5f4107aec5429580729257ed3a
|
https://github.com/yuncms/yii2-oauth2/blob/7fb41fc56d4a6a5f4107aec5429580729257ed3a/frontend/controllers/ClientController.php#L53-L62
|
24,677
|
yuncms/yii2-oauth2
|
frontend/controllers/ClientController.php
|
ClientController.actionCreate
|
public function actionCreate()
{
$model = new Client();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
} else if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('success', Yii::t('oauth2', 'Successful operation'));
return $this->redirect(['view', 'id' => $model->client_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
|
php
|
public function actionCreate()
{
$model = new Client();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
} else if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('success', Yii::t('oauth2', 'Successful operation'));
return $this->redirect(['view', 'id' => $model->client_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
|
[
"public",
"function",
"actionCreate",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"Client",
"(",
")",
";",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"isAjax",
"&&",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"response",
"->",
"format",
"=",
"Response",
"::",
"FORMAT_JSON",
";",
"return",
"ActiveForm",
"::",
"validate",
"(",
"$",
"model",
")",
";",
"}",
"else",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getSession",
"(",
")",
"->",
"setFlash",
"(",
"'success'",
",",
"Yii",
"::",
"t",
"(",
"'oauth2'",
",",
"'Successful operation'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'view'",
",",
"'id'",
"=>",
"$",
"model",
"->",
"client_id",
"]",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'create'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}",
"}"
] |
Creates a new Rest model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
|
[
"Creates",
"a",
"new",
"Rest",
"model",
".",
"If",
"creation",
"is",
"successful",
"the",
"browser",
"will",
"be",
"redirected",
"to",
"the",
"view",
"page",
"."
] |
7fb41fc56d4a6a5f4107aec5429580729257ed3a
|
https://github.com/yuncms/yii2-oauth2/blob/7fb41fc56d4a6a5f4107aec5429580729257ed3a/frontend/controllers/ClientController.php#L69-L83
|
24,678
|
TiMESPLiNTER/tsFramework
|
src/ch/timesplinter/core/Core.php
|
Core.createHttpRequest
|
protected function createHttpRequest()
{
$protocol = (isset($_SERVER['HTTPS']) === true && $_SERVER['HTTPS'] === 'on') ? HttpRequest::PROTOCOL_HTTPS : HttpRequest::PROTOCOL_HTTP;
$uri = StringUtils::startsWith($_SERVER['REQUEST_URI'], '/index.php')?StringUtils::afterFirst($_SERVER['REQUEST_URI'], '/index.php'):$_SERVER['REQUEST_URI'];
$subFolder = StringUtils::afterFirst(getcwd(), $_SERVER['DOCUMENT_ROOT']);
$cleanPath = StringUtils::between($uri, $subFolder, '?');
$languages = array();
$langsRates = explode(',', isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null);
foreach($langsRates as $lr) {
$lrParts = explode(';', $lr);
$languages[$lrParts[0]] = isset($lrParts[1])?(float)StringUtils::afterFirst($lrParts[1], 'q='):1.0;
}
$requestTime = new \DateTime();
$requestTime->setTimestamp($_SERVER['REQUEST_TIME']);
$httpRequest = new HttpRequest();
$httpRequest->setHost($_SERVER['SERVER_NAME']);
$httpRequest->setPath($cleanPath);
$httpRequest->setPort($_SERVER['SERVER_PORT']);
$httpRequest->setProtocol($protocol);
$httpRequest->setQuery($_SERVER['QUERY_STRING']);
$httpRequest->setURI($uri);
$httpRequest->setRequestTime($requestTime);
$httpRequest->setRequestMethod($_SERVER['REQUEST_METHOD']);
$httpRequest->setUserAgent(isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:null);
$httpRequest->setLanguages($languages);
$httpRequest->setAcceptLanguage(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?$_SERVER['HTTP_ACCEPT_LANGUAGE']:null);
$httpRequest->setRemoteAddress($_SERVER['REMOTE_ADDR']);
$httpRequest->setReferrer(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
return $httpRequest;
}
|
php
|
protected function createHttpRequest()
{
$protocol = (isset($_SERVER['HTTPS']) === true && $_SERVER['HTTPS'] === 'on') ? HttpRequest::PROTOCOL_HTTPS : HttpRequest::PROTOCOL_HTTP;
$uri = StringUtils::startsWith($_SERVER['REQUEST_URI'], '/index.php')?StringUtils::afterFirst($_SERVER['REQUEST_URI'], '/index.php'):$_SERVER['REQUEST_URI'];
$subFolder = StringUtils::afterFirst(getcwd(), $_SERVER['DOCUMENT_ROOT']);
$cleanPath = StringUtils::between($uri, $subFolder, '?');
$languages = array();
$langsRates = explode(',', isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null);
foreach($langsRates as $lr) {
$lrParts = explode(';', $lr);
$languages[$lrParts[0]] = isset($lrParts[1])?(float)StringUtils::afterFirst($lrParts[1], 'q='):1.0;
}
$requestTime = new \DateTime();
$requestTime->setTimestamp($_SERVER['REQUEST_TIME']);
$httpRequest = new HttpRequest();
$httpRequest->setHost($_SERVER['SERVER_NAME']);
$httpRequest->setPath($cleanPath);
$httpRequest->setPort($_SERVER['SERVER_PORT']);
$httpRequest->setProtocol($protocol);
$httpRequest->setQuery($_SERVER['QUERY_STRING']);
$httpRequest->setURI($uri);
$httpRequest->setRequestTime($requestTime);
$httpRequest->setRequestMethod($_SERVER['REQUEST_METHOD']);
$httpRequest->setUserAgent(isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:null);
$httpRequest->setLanguages($languages);
$httpRequest->setAcceptLanguage(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?$_SERVER['HTTP_ACCEPT_LANGUAGE']:null);
$httpRequest->setRemoteAddress($_SERVER['REMOTE_ADDR']);
$httpRequest->setReferrer(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
return $httpRequest;
}
|
[
"protected",
"function",
"createHttpRequest",
"(",
")",
"{",
"$",
"protocol",
"=",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"===",
"true",
"&&",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
"===",
"'on'",
")",
"?",
"HttpRequest",
"::",
"PROTOCOL_HTTPS",
":",
"HttpRequest",
"::",
"PROTOCOL_HTTP",
";",
"$",
"uri",
"=",
"StringUtils",
"::",
"startsWith",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
",",
"'/index.php'",
")",
"?",
"StringUtils",
"::",
"afterFirst",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
",",
"'/index.php'",
")",
":",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"$",
"subFolder",
"=",
"StringUtils",
"::",
"afterFirst",
"(",
"getcwd",
"(",
")",
",",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
")",
";",
"$",
"cleanPath",
"=",
"StringUtils",
"::",
"between",
"(",
"$",
"uri",
",",
"$",
"subFolder",
",",
"'?'",
")",
";",
"$",
"languages",
"=",
"array",
"(",
")",
";",
"$",
"langsRates",
"=",
"explode",
"(",
"','",
",",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
":",
"null",
")",
";",
"foreach",
"(",
"$",
"langsRates",
"as",
"$",
"lr",
")",
"{",
"$",
"lrParts",
"=",
"explode",
"(",
"';'",
",",
"$",
"lr",
")",
";",
"$",
"languages",
"[",
"$",
"lrParts",
"[",
"0",
"]",
"]",
"=",
"isset",
"(",
"$",
"lrParts",
"[",
"1",
"]",
")",
"?",
"(",
"float",
")",
"StringUtils",
"::",
"afterFirst",
"(",
"$",
"lrParts",
"[",
"1",
"]",
",",
"'q='",
")",
":",
"1.0",
";",
"}",
"$",
"requestTime",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"requestTime",
"->",
"setTimestamp",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_TIME'",
"]",
")",
";",
"$",
"httpRequest",
"=",
"new",
"HttpRequest",
"(",
")",
";",
"$",
"httpRequest",
"->",
"setHost",
"(",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setPath",
"(",
"$",
"cleanPath",
")",
";",
"$",
"httpRequest",
"->",
"setPort",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PORT'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setProtocol",
"(",
"$",
"protocol",
")",
";",
"$",
"httpRequest",
"->",
"setQuery",
"(",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setURI",
"(",
"$",
"uri",
")",
";",
"$",
"httpRequest",
"->",
"setRequestTime",
"(",
"$",
"requestTime",
")",
";",
"$",
"httpRequest",
"->",
"setRequestMethod",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setUserAgent",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
":",
"null",
")",
";",
"$",
"httpRequest",
"->",
"setLanguages",
"(",
"$",
"languages",
")",
";",
"$",
"httpRequest",
"->",
"setAcceptLanguage",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
":",
"null",
")",
";",
"$",
"httpRequest",
"->",
"setRemoteAddress",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setReferrer",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_REFERER'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_REFERER'",
"]",
":",
"null",
")",
";",
"return",
"$",
"httpRequest",
";",
"}"
] |
Creates a HttpRequest object for the current request
@return HttpRequest
|
[
"Creates",
"a",
"HttpRequest",
"object",
"for",
"the",
"current",
"request"
] |
b3b9fd98f6d456a9e571015877ecca203786fd0c
|
https://github.com/TiMESPLiNTER/tsFramework/blob/b3b9fd98f6d456a9e571015877ecca203786fd0c/src/ch/timesplinter/core/Core.php#L95-L133
|
24,679
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.camelTo_
|
public static function camelTo_($str) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return "_" . strtolower($c[1]);');
return preg_replace_callback('/([A-Z])/', $func, $str);
}
|
php
|
public static function camelTo_($str) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return "_" . strtolower($c[1]);');
return preg_replace_callback('/([A-Z])/', $func, $str);
}
|
[
"public",
"static",
"function",
"camelTo_",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"str",
")",
")",
"return",
"''",
";",
"$",
"str",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"str",
"[",
"0",
"]",
")",
";",
"$",
"func",
"=",
"create_function",
"(",
"'$c'",
",",
"'return \"_\" . strtolower($c[1]);'",
")",
";",
"return",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"$",
"func",
",",
"$",
"str",
")",
";",
"}"
] |
Turns camelCasedString to under_scored_string
@param string $str
@return string
|
[
"Turns",
"camelCasedString",
"to",
"under_scored_string"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L24-L30
|
24,680
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.camelToHyphen
|
public static function camelToHyphen($str, $strtolower = true) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return "-" . $c[1];');
$str = preg_replace_callback('/([A-Z])/', $func, $str);
return ($strtolower) ? strtolower($str) : $str;
}
|
php
|
public static function camelToHyphen($str, $strtolower = true) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return "-" . $c[1];');
$str = preg_replace_callback('/([A-Z])/', $func, $str);
return ($strtolower) ? strtolower($str) : $str;
}
|
[
"public",
"static",
"function",
"camelToHyphen",
"(",
"$",
"str",
",",
"$",
"strtolower",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"str",
")",
")",
"return",
"''",
";",
"$",
"str",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"str",
"[",
"0",
"]",
")",
";",
"$",
"func",
"=",
"create_function",
"(",
"'$c'",
",",
"'return \"-\" . $c[1];'",
")",
";",
"$",
"str",
"=",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"$",
"func",
",",
"$",
"str",
")",
";",
"return",
"(",
"$",
"strtolower",
")",
"?",
"strtolower",
"(",
"$",
"str",
")",
":",
"$",
"str",
";",
"}"
] |
Turns camelCasedString to hyphened-string
@param string $str
@param boolean $strtolower
@return string
|
[
"Turns",
"camelCasedString",
"to",
"hyphened",
"-",
"string"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L38-L45
|
24,681
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.camelToSpace
|
public static function camelToSpace($str) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return " " . $c[1];');
return preg_replace_callback('/([A-Z])/', $func, $str);
}
|
php
|
public static function camelToSpace($str) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return " " . $c[1];');
return preg_replace_callback('/([A-Z])/', $func, $str);
}
|
[
"public",
"static",
"function",
"camelToSpace",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"str",
")",
")",
"return",
"''",
";",
"$",
"str",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"str",
"[",
"0",
"]",
")",
";",
"$",
"func",
"=",
"create_function",
"(",
"'$c'",
",",
"'return \" \" . $c[1];'",
")",
";",
"return",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"$",
"func",
",",
"$",
"str",
")",
";",
"}"
] |
Turns camelCasedString to spaced out string
@param string $str
@return string
|
[
"Turns",
"camelCasedString",
"to",
"spaced",
"out",
"string"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L63-L69
|
24,682
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.readDir
|
public static function readDir($dir, $return = Util::ALL, $recursive = false, $extension = NULL, $nameOnly = false, array $options = array()) {
if (!is_dir($dir))
return array(
'error' => 'Directory "' . $dir . '" does not exist',
);
if (!is_array($extension) && !empty($extension)) {
$extension = array($extension);
}
if (substr($dir, strlen($dir) - 1) !== DIRECTORY_SEPARATOR)
$dir .= DIRECTORY_SEPARATOR;
$toReturn = array('dirs' => array(), 'files' => array());
try {
foreach (scandir($dir) as $current) {
if (in_array($current, array('.', '..')))
continue;
if (is_dir($dir . $current)) {
if (in_array($return, array(self::DIRS_ONLY, self::ALL))) {
$toReturn['dirs'][] = ($nameOnly) ? $current : $dir . $current;
}
if ($recursive) {
$toReturn = array_merge_recursive($toReturn, self::readDir($dir . $current, self::ALL, true, $extension, $nameOnly, $options));
}
} else if (is_file($dir . $current) && in_array($return, array(self::FILES_ONLY, self::ALL))) {
if ($extension)
$info = pathinfo($current);
if (empty($extension) || (is_array($extension) && in_array($info['extension'], $extension))) {
$toReturn['files'][$dir][] = ($nameOnly) ? $current : $dir . $current;
}
}
}
if ($return == self::ALL)
return $toReturn;
elseif ($return == self::DIRS_ONLY)
return $toReturn['dirs'];
elseif ($return == self::FILES_ONLY)
return $toReturn['files'];
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage());
}
}
|
php
|
public static function readDir($dir, $return = Util::ALL, $recursive = false, $extension = NULL, $nameOnly = false, array $options = array()) {
if (!is_dir($dir))
return array(
'error' => 'Directory "' . $dir . '" does not exist',
);
if (!is_array($extension) && !empty($extension)) {
$extension = array($extension);
}
if (substr($dir, strlen($dir) - 1) !== DIRECTORY_SEPARATOR)
$dir .= DIRECTORY_SEPARATOR;
$toReturn = array('dirs' => array(), 'files' => array());
try {
foreach (scandir($dir) as $current) {
if (in_array($current, array('.', '..')))
continue;
if (is_dir($dir . $current)) {
if (in_array($return, array(self::DIRS_ONLY, self::ALL))) {
$toReturn['dirs'][] = ($nameOnly) ? $current : $dir . $current;
}
if ($recursive) {
$toReturn = array_merge_recursive($toReturn, self::readDir($dir . $current, self::ALL, true, $extension, $nameOnly, $options));
}
} else if (is_file($dir . $current) && in_array($return, array(self::FILES_ONLY, self::ALL))) {
if ($extension)
$info = pathinfo($current);
if (empty($extension) || (is_array($extension) && in_array($info['extension'], $extension))) {
$toReturn['files'][$dir][] = ($nameOnly) ? $current : $dir . $current;
}
}
}
if ($return == self::ALL)
return $toReturn;
elseif ($return == self::DIRS_ONLY)
return $toReturn['dirs'];
elseif ($return == self::FILES_ONLY)
return $toReturn['files'];
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage());
}
}
|
[
"public",
"static",
"function",
"readDir",
"(",
"$",
"dir",
",",
"$",
"return",
"=",
"Util",
"::",
"ALL",
",",
"$",
"recursive",
"=",
"false",
",",
"$",
"extension",
"=",
"NULL",
",",
"$",
"nameOnly",
"=",
"false",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"return",
"array",
"(",
"'error'",
"=>",
"'Directory \"'",
".",
"$",
"dir",
".",
"'\" does not exist'",
",",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"extension",
")",
"&&",
"!",
"empty",
"(",
"$",
"extension",
")",
")",
"{",
"$",
"extension",
"=",
"array",
"(",
"$",
"extension",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"dir",
",",
"strlen",
"(",
"$",
"dir",
")",
"-",
"1",
")",
"!==",
"DIRECTORY_SEPARATOR",
")",
"$",
"dir",
".=",
"DIRECTORY_SEPARATOR",
";",
"$",
"toReturn",
"=",
"array",
"(",
"'dirs'",
"=>",
"array",
"(",
")",
",",
"'files'",
"=>",
"array",
"(",
")",
")",
";",
"try",
"{",
"foreach",
"(",
"scandir",
"(",
"$",
"dir",
")",
"as",
"$",
"current",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"current",
",",
"array",
"(",
"'.'",
",",
"'..'",
")",
")",
")",
"continue",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
".",
"$",
"current",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"return",
",",
"array",
"(",
"self",
"::",
"DIRS_ONLY",
",",
"self",
"::",
"ALL",
")",
")",
")",
"{",
"$",
"toReturn",
"[",
"'dirs'",
"]",
"[",
"]",
"=",
"(",
"$",
"nameOnly",
")",
"?",
"$",
"current",
":",
"$",
"dir",
".",
"$",
"current",
";",
"}",
"if",
"(",
"$",
"recursive",
")",
"{",
"$",
"toReturn",
"=",
"array_merge_recursive",
"(",
"$",
"toReturn",
",",
"self",
"::",
"readDir",
"(",
"$",
"dir",
".",
"$",
"current",
",",
"self",
"::",
"ALL",
",",
"true",
",",
"$",
"extension",
",",
"$",
"nameOnly",
",",
"$",
"options",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_file",
"(",
"$",
"dir",
".",
"$",
"current",
")",
"&&",
"in_array",
"(",
"$",
"return",
",",
"array",
"(",
"self",
"::",
"FILES_ONLY",
",",
"self",
"::",
"ALL",
")",
")",
")",
"{",
"if",
"(",
"$",
"extension",
")",
"$",
"info",
"=",
"pathinfo",
"(",
"$",
"current",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"extension",
")",
"||",
"(",
"is_array",
"(",
"$",
"extension",
")",
"&&",
"in_array",
"(",
"$",
"info",
"[",
"'extension'",
"]",
",",
"$",
"extension",
")",
")",
")",
"{",
"$",
"toReturn",
"[",
"'files'",
"]",
"[",
"$",
"dir",
"]",
"[",
"]",
"=",
"(",
"$",
"nameOnly",
")",
"?",
"$",
"current",
":",
"$",
"dir",
".",
"$",
"current",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"return",
"==",
"self",
"::",
"ALL",
")",
"return",
"$",
"toReturn",
";",
"elseif",
"(",
"$",
"return",
"==",
"self",
"::",
"DIRS_ONLY",
")",
"return",
"$",
"toReturn",
"[",
"'dirs'",
"]",
";",
"elseif",
"(",
"$",
"return",
"==",
"self",
"::",
"FILES_ONLY",
")",
"return",
"$",
"toReturn",
"[",
"'files'",
"]",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Reads the required source directory
@param string $dir
@param int $return
@param boolean $recursive
@param string|array\null $extension Extensions without the dot (.)
@param boolean $nameOnly Indicates whether to return full path of dirs/files or names only
@param array $options keys include:
@return array
@throws \Exception
|
[
"Reads",
"the",
"required",
"source",
"directory"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L107-L151
|
24,683
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.copyDir
|
public static function copyDir($source, $destination, $permission = 0777, $recursive = true) {
if (substr($source, strlen($destination) - 1) !== DIRECTORY_SEPARATOR)
$destination .= DIRECTORY_SEPARATOR;
try {
if (!is_dir($destination))
mkdir($destination, $permission);
$contents = self::readDir($source, self::ALL, $recursive, NULL);
if (isset($contents['dirs'])) {
foreach ($contents['dirs'] as $fullPath) {
@mkdir(str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath), $permission);
}
}
if (isset($contents['files'])) {
foreach ($contents['files'] as $fullPathsArray) {
foreach ($fullPathsArray as $fullPath) {
@copy($fullPath, str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath));
}
}
}
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage());
}
}
|
php
|
public static function copyDir($source, $destination, $permission = 0777, $recursive = true) {
if (substr($source, strlen($destination) - 1) !== DIRECTORY_SEPARATOR)
$destination .= DIRECTORY_SEPARATOR;
try {
if (!is_dir($destination))
mkdir($destination, $permission);
$contents = self::readDir($source, self::ALL, $recursive, NULL);
if (isset($contents['dirs'])) {
foreach ($contents['dirs'] as $fullPath) {
@mkdir(str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath), $permission);
}
}
if (isset($contents['files'])) {
foreach ($contents['files'] as $fullPathsArray) {
foreach ($fullPathsArray as $fullPath) {
@copy($fullPath, str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath));
}
}
}
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage());
}
}
|
[
"public",
"static",
"function",
"copyDir",
"(",
"$",
"source",
",",
"$",
"destination",
",",
"$",
"permission",
"=",
"0777",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"source",
",",
"strlen",
"(",
"$",
"destination",
")",
"-",
"1",
")",
"!==",
"DIRECTORY_SEPARATOR",
")",
"$",
"destination",
".=",
"DIRECTORY_SEPARATOR",
";",
"try",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"destination",
")",
")",
"mkdir",
"(",
"$",
"destination",
",",
"$",
"permission",
")",
";",
"$",
"contents",
"=",
"self",
"::",
"readDir",
"(",
"$",
"source",
",",
"self",
"::",
"ALL",
",",
"$",
"recursive",
",",
"NULL",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"contents",
"[",
"'dirs'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"contents",
"[",
"'dirs'",
"]",
"as",
"$",
"fullPath",
")",
"{",
"@",
"mkdir",
"(",
"str_replace",
"(",
"array",
"(",
"$",
"source",
",",
"DIRECTORY_SEPARATOR",
".",
"DIRECTORY_SEPARATOR",
")",
",",
"array",
"(",
"$",
"destination",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"$",
"fullPath",
")",
",",
"$",
"permission",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"contents",
"[",
"'files'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"contents",
"[",
"'files'",
"]",
"as",
"$",
"fullPathsArray",
")",
"{",
"foreach",
"(",
"$",
"fullPathsArray",
"as",
"$",
"fullPath",
")",
"{",
"@",
"copy",
"(",
"$",
"fullPath",
",",
"str_replace",
"(",
"array",
"(",
"$",
"source",
",",
"DIRECTORY_SEPARATOR",
".",
"DIRECTORY_SEPARATOR",
")",
",",
"array",
"(",
"$",
"destination",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"$",
"fullPath",
")",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Copies a directory to another location
@param string $source
@param string $destination
@param string $permission
@param boolean $recursive
@throws \Exception
|
[
"Copies",
"a",
"directory",
"to",
"another",
"location"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L161-L186
|
24,684
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.delDir
|
public static function delDir($dir) {
$all = self::readDir($dir, self::ALL, true, NULL);
if (isset($all['files'])) {
foreach ($all['files'] as $file) {
if (is_array($file)) {
foreach ($file as $fil) {
if (!unlink($fil)) {
return false;
}
}
} else {
if (!unlink($file)) {
return false;
}
}
}
}
if (isset($all['dirs'])) {
foreach (array_reverse($all['dirs']) as $_dir) {
if (is_array($_dir)) {
foreach ($_dir as $_dr) {
if (!rmdir($_dr)) {
return false;
}
}
} else {
if (!rmdir($_dir)) {
return false;
}
}
}
}
return rmdir($dir);
}
|
php
|
public static function delDir($dir) {
$all = self::readDir($dir, self::ALL, true, NULL);
if (isset($all['files'])) {
foreach ($all['files'] as $file) {
if (is_array($file)) {
foreach ($file as $fil) {
if (!unlink($fil)) {
return false;
}
}
} else {
if (!unlink($file)) {
return false;
}
}
}
}
if (isset($all['dirs'])) {
foreach (array_reverse($all['dirs']) as $_dir) {
if (is_array($_dir)) {
foreach ($_dir as $_dr) {
if (!rmdir($_dr)) {
return false;
}
}
} else {
if (!rmdir($_dir)) {
return false;
}
}
}
}
return rmdir($dir);
}
|
[
"public",
"static",
"function",
"delDir",
"(",
"$",
"dir",
")",
"{",
"$",
"all",
"=",
"self",
"::",
"readDir",
"(",
"$",
"dir",
",",
"self",
"::",
"ALL",
",",
"true",
",",
"NULL",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"all",
"[",
"'files'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"all",
"[",
"'files'",
"]",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"file",
")",
")",
"{",
"foreach",
"(",
"$",
"file",
"as",
"$",
"fil",
")",
"{",
"if",
"(",
"!",
"unlink",
"(",
"$",
"fil",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"unlink",
"(",
"$",
"file",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"all",
"[",
"'dirs'",
"]",
")",
")",
"{",
"foreach",
"(",
"array_reverse",
"(",
"$",
"all",
"[",
"'dirs'",
"]",
")",
"as",
"$",
"_dir",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"_dir",
")",
")",
"{",
"foreach",
"(",
"$",
"_dir",
"as",
"$",
"_dr",
")",
"{",
"if",
"(",
"!",
"rmdir",
"(",
"$",
"_dr",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"rmdir",
"(",
"$",
"_dir",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"rmdir",
"(",
"$",
"dir",
")",
";",
"}"
] |
Deletes a directory and all contents including subdirectories and files
@param string $file
@return boolean
|
[
"Deletes",
"a",
"directory",
"and",
"all",
"contents",
"including",
"subdirectories",
"and",
"files"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L194-L229
|
24,685
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.resizeImageDirectory
|
public static function resizeImageDirectory($dir, $desiredWidth = 200, $overwrite = false, $recursive = true, $subDir = 'resized') {
foreach (self::readDir($dir, self::FILES_ONLY, $recursive, null, true) as $path => $filesArray) {
foreach ($filesArray as $file) {
$destination = null;
if (!$overwrite) {
if (!is_dir($path . $subDir)) {
mkdir($path . $subDir);
}
$destination = $path . $subDir . DIRECTORY_SEPARATOR . $file;
}
self::resizeImage($path . $file, $desiredWidth, $destination);
}
}
}
|
php
|
public static function resizeImageDirectory($dir, $desiredWidth = 200, $overwrite = false, $recursive = true, $subDir = 'resized') {
foreach (self::readDir($dir, self::FILES_ONLY, $recursive, null, true) as $path => $filesArray) {
foreach ($filesArray as $file) {
$destination = null;
if (!$overwrite) {
if (!is_dir($path . $subDir)) {
mkdir($path . $subDir);
}
$destination = $path . $subDir . DIRECTORY_SEPARATOR . $file;
}
self::resizeImage($path . $file, $desiredWidth, $destination);
}
}
}
|
[
"public",
"static",
"function",
"resizeImageDirectory",
"(",
"$",
"dir",
",",
"$",
"desiredWidth",
"=",
"200",
",",
"$",
"overwrite",
"=",
"false",
",",
"$",
"recursive",
"=",
"true",
",",
"$",
"subDir",
"=",
"'resized'",
")",
"{",
"foreach",
"(",
"self",
"::",
"readDir",
"(",
"$",
"dir",
",",
"self",
"::",
"FILES_ONLY",
",",
"$",
"recursive",
",",
"null",
",",
"true",
")",
"as",
"$",
"path",
"=>",
"$",
"filesArray",
")",
"{",
"foreach",
"(",
"$",
"filesArray",
"as",
"$",
"file",
")",
"{",
"$",
"destination",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"overwrite",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
".",
"$",
"subDir",
")",
")",
"{",
"mkdir",
"(",
"$",
"path",
".",
"$",
"subDir",
")",
";",
"}",
"$",
"destination",
"=",
"$",
"path",
".",
"$",
"subDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"}",
"self",
"::",
"resizeImage",
"(",
"$",
"path",
".",
"$",
"file",
",",
"$",
"desiredWidth",
",",
"$",
"destination",
")",
";",
"}",
"}",
"}"
] |
Resize all images in a directory
@param string $dir Directory path of images
@param int $desiredWidth Desired width of new images
@param boolean $overwrite Overwrite old images?
@param boolean $recursive Indicates if subdirectories should be searched too
@param string $subDir If not overwrite, name of subfolder within the $dir
to resize into
|
[
"Resize",
"all",
"images",
"in",
"a",
"directory"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L300-L313
|
24,686
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.shortenString
|
public static function shortenString($str, $length = 75, $break = '...') {
if (strlen($str) < $length)
return $str;
$str = strip_tags($str);
return substr($str, 0, $length) . $break;
}
|
php
|
public static function shortenString($str, $length = 75, $break = '...') {
if (strlen($str) < $length)
return $str;
$str = strip_tags($str);
return substr($str, 0, $length) . $break;
}
|
[
"public",
"static",
"function",
"shortenString",
"(",
"$",
"str",
",",
"$",
"length",
"=",
"75",
",",
"$",
"break",
"=",
"'...'",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"str",
")",
"<",
"$",
"length",
")",
"return",
"$",
"str",
";",
"$",
"str",
"=",
"strip_tags",
"(",
"$",
"str",
")",
";",
"return",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"$",
"length",
")",
".",
"$",
"break",
";",
"}"
] |
Shortens a string to desired length
@param string $str String to shorten
@param integer $length Length of the string to return
@param string $break String to replace the truncated part with
@return string
|
[
"Shortens",
"a",
"string",
"to",
"desired",
"length"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L322-L329
|
24,687
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.randomPassword
|
public static function randomPassword($length = 8, $string = null) {
if (!$string)
$string = 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ123456789&^%$#@!_-+=';
$chars = str_split(str_shuffle($string));
$password = '';
foreach (array_rand($chars, $length) as $key) {
$password .= $chars[$key];
}
return $password;
}
|
php
|
public static function randomPassword($length = 8, $string = null) {
if (!$string)
$string = 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ123456789&^%$#@!_-+=';
$chars = str_split(str_shuffle($string));
$password = '';
foreach (array_rand($chars, $length) as $key) {
$password .= $chars[$key];
}
return $password;
}
|
[
"public",
"static",
"function",
"randomPassword",
"(",
"$",
"length",
"=",
"8",
",",
"$",
"string",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"string",
")",
"$",
"string",
"=",
"'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ123456789&^%$#@!_-+='",
";",
"$",
"chars",
"=",
"str_split",
"(",
"str_shuffle",
"(",
"$",
"string",
")",
")",
";",
"$",
"password",
"=",
"''",
";",
"foreach",
"(",
"array_rand",
"(",
"$",
"chars",
",",
"$",
"length",
")",
"as",
"$",
"key",
")",
"{",
"$",
"password",
".=",
"$",
"chars",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"password",
";",
"}"
] |
Generates a random password
@param int $length Length of the password to generate. Default is 8
@return string
|
[
"Generates",
"a",
"random",
"password"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L401-L410
|
24,688
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.listTimezones
|
public static function listTimezones() {
if (self::$timezones === null) {
self::$timezones = array();
$offsets = array();
$now = new DateTime();
foreach (DateTimeZone::listIdentifiers() as $timezone) {
$now->setTimezone(new DateTimeZone($timezone));
$offsets[] = $offset = $now->getOffset();
self::$timezones[$timezone] = '(' . self::formatGmtOffset($offset) . ') ' . self::formatTimezoneName($timezone);
}
array_multisort($offsets, self::$timezones);
}
return self::$timezones;
}
|
php
|
public static function listTimezones() {
if (self::$timezones === null) {
self::$timezones = array();
$offsets = array();
$now = new DateTime();
foreach (DateTimeZone::listIdentifiers() as $timezone) {
$now->setTimezone(new DateTimeZone($timezone));
$offsets[] = $offset = $now->getOffset();
self::$timezones[$timezone] = '(' . self::formatGmtOffset($offset) . ') ' . self::formatTimezoneName($timezone);
}
array_multisort($offsets, self::$timezones);
}
return self::$timezones;
}
|
[
"public",
"static",
"function",
"listTimezones",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"timezones",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"timezones",
"=",
"array",
"(",
")",
";",
"$",
"offsets",
"=",
"array",
"(",
")",
";",
"$",
"now",
"=",
"new",
"DateTime",
"(",
")",
";",
"foreach",
"(",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
")",
"as",
"$",
"timezone",
")",
"{",
"$",
"now",
"->",
"setTimezone",
"(",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
")",
";",
"$",
"offsets",
"[",
"]",
"=",
"$",
"offset",
"=",
"$",
"now",
"->",
"getOffset",
"(",
")",
";",
"self",
"::",
"$",
"timezones",
"[",
"$",
"timezone",
"]",
"=",
"'('",
".",
"self",
"::",
"formatGmtOffset",
"(",
"$",
"offset",
")",
".",
"') '",
".",
"self",
"::",
"formatTimezoneName",
"(",
"$",
"timezone",
")",
";",
"}",
"array_multisort",
"(",
"$",
"offsets",
",",
"self",
"::",
"$",
"timezones",
")",
";",
"}",
"return",
"self",
"::",
"$",
"timezones",
";",
"}"
] |
Create a list of time zones
@return array
|
[
"Create",
"a",
"list",
"of",
"time",
"zones"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L448-L464
|
24,689
|
ezra-obiwale/dSCore
|
src/Stdlib/Util.php
|
Util.formatGmtOffset
|
public static function formatGmtOffset($offset) {
$hours = intval($offset / 3600);
$minutes = abs(intval($offset % 3600 / 60));
return 'GMT' . ($offset ? sprintf('%+03d:%02d', $hours, $minutes) : '');
}
|
php
|
public static function formatGmtOffset($offset) {
$hours = intval($offset / 3600);
$minutes = abs(intval($offset % 3600 / 60));
return 'GMT' . ($offset ? sprintf('%+03d:%02d', $hours, $minutes) : '');
}
|
[
"public",
"static",
"function",
"formatGmtOffset",
"(",
"$",
"offset",
")",
"{",
"$",
"hours",
"=",
"intval",
"(",
"$",
"offset",
"/",
"3600",
")",
";",
"$",
"minutes",
"=",
"abs",
"(",
"intval",
"(",
"$",
"offset",
"%",
"3600",
"/",
"60",
")",
")",
";",
"return",
"'GMT'",
".",
"(",
"$",
"offset",
"?",
"sprintf",
"(",
"'%+03d:%02d'",
",",
"$",
"hours",
",",
"$",
"minutes",
")",
":",
"''",
")",
";",
"}"
] |
Formats GMT offset to string
@param string $offset
@return string
|
[
"Formats",
"GMT",
"offset",
"to",
"string"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L471-L475
|
24,690
|
swaros/golib
|
src/Types/Props.php
|
Props.applyData
|
public function applyData ( $data = NULL ) {
if (NULL != $data && is_array( $data )) {
foreach ($data as $propName => $propValue) {
$this->assignValue( $propName, $propValue );
}
} else {
$this->buildVars();
}
}
|
php
|
public function applyData ( $data = NULL ) {
if (NULL != $data && is_array( $data )) {
foreach ($data as $propName => $propValue) {
$this->assignValue( $propName, $propValue );
}
} else {
$this->buildVars();
}
}
|
[
"public",
"function",
"applyData",
"(",
"$",
"data",
"=",
"NULL",
")",
"{",
"if",
"(",
"NULL",
"!=",
"$",
"data",
"&&",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"propName",
"=>",
"$",
"propValue",
")",
"{",
"$",
"this",
"->",
"assignValue",
"(",
"$",
"propName",
",",
"$",
"propValue",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"buildVars",
"(",
")",
";",
"}",
"}"
] |
apply given data to properties
@param array $data
|
[
"apply",
"given",
"data",
"to",
"properties"
] |
9e75c8fb36de7c09b01a6c1c0d27c45f02fed567
|
https://github.com/swaros/golib/blob/9e75c8fb36de7c09b01a6c1c0d27c45f02fed567/src/Types/Props.php#L36-L44
|
24,691
|
swaros/golib
|
src/Types/Props.php
|
Props.assignExisting
|
public function assignExisting ( $propName, $propValue ) {
if (is_bool( $this->$propName )) {
if (strtolower( $propValue ) == 'false') {
$propValue = false;
}
$this->$propName = (bool) $propValue;
} elseif (is_int( $this->$propName )) {
$this->$propName = (int) $propValue;
} elseif (is_bool( $this->$propName )) {
$this->$propName = (bool) $propValue;
} elseif ($this->$propName instanceof Timer || $this->$propName == MapConst::TIMER) {
$this->$propName = new Timer( $propValue );
} else {
$this->$propName = $propValue;
}
}
|
php
|
public function assignExisting ( $propName, $propValue ) {
if (is_bool( $this->$propName )) {
if (strtolower( $propValue ) == 'false') {
$propValue = false;
}
$this->$propName = (bool) $propValue;
} elseif (is_int( $this->$propName )) {
$this->$propName = (int) $propValue;
} elseif (is_bool( $this->$propName )) {
$this->$propName = (bool) $propValue;
} elseif ($this->$propName instanceof Timer || $this->$propName == MapConst::TIMER) {
$this->$propName = new Timer( $propValue );
} else {
$this->$propName = $propValue;
}
}
|
[
"public",
"function",
"assignExisting",
"(",
"$",
"propName",
",",
"$",
"propValue",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"this",
"->",
"$",
"propName",
")",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"propValue",
")",
"==",
"'false'",
")",
"{",
"$",
"propValue",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"$",
"propName",
"=",
"(",
"bool",
")",
"$",
"propValue",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"this",
"->",
"$",
"propName",
")",
")",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"(",
"int",
")",
"$",
"propValue",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"this",
"->",
"$",
"propName",
")",
")",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"(",
"bool",
")",
"$",
"propValue",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"$",
"propName",
"instanceof",
"Timer",
"||",
"$",
"this",
"->",
"$",
"propName",
"==",
"MapConst",
"::",
"TIMER",
")",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"new",
"Timer",
"(",
"$",
"propValue",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"$",
"propValue",
";",
"}",
"}"
] |
assign value to a existing propertie and
cast depending on defined default value
@param string $propName
@param boolean $propValue
|
[
"assign",
"value",
"to",
"a",
"existing",
"propertie",
"and",
"cast",
"depending",
"on",
"defined",
"default",
"value"
] |
9e75c8fb36de7c09b01a6c1c0d27c45f02fed567
|
https://github.com/swaros/golib/blob/9e75c8fb36de7c09b01a6c1c0d27c45f02fed567/src/Types/Props.php#L61-L76
|
24,692
|
swaros/golib
|
src/Types/Props.php
|
Props.assignValue
|
public function assignValue ( $propNameOrig, $propValue ) {
$propNameA = str_replace( self::$replaceChars, '_', $propNameOrig );
$propName = preg_replace( "/[^A-Za-z0-9_]/", "", $propNameA );
if (property_exists( $this, $propName ) && $this->$propName !== NULL) {
$this->assignExisting( $propName, $propValue );
} elseif ($propName !== '') {
$this->$propName = $propValue;
}
}
|
php
|
public function assignValue ( $propNameOrig, $propValue ) {
$propNameA = str_replace( self::$replaceChars, '_', $propNameOrig );
$propName = preg_replace( "/[^A-Za-z0-9_]/", "", $propNameA );
if (property_exists( $this, $propName ) && $this->$propName !== NULL) {
$this->assignExisting( $propName, $propValue );
} elseif ($propName !== '') {
$this->$propName = $propValue;
}
}
|
[
"public",
"function",
"assignValue",
"(",
"$",
"propNameOrig",
",",
"$",
"propValue",
")",
"{",
"$",
"propNameA",
"=",
"str_replace",
"(",
"self",
"::",
"$",
"replaceChars",
",",
"'_'",
",",
"$",
"propNameOrig",
")",
";",
"$",
"propName",
"=",
"preg_replace",
"(",
"\"/[^A-Za-z0-9_]/\"",
",",
"\"\"",
",",
"$",
"propNameA",
")",
";",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"propName",
")",
"&&",
"$",
"this",
"->",
"$",
"propName",
"!==",
"NULL",
")",
"{",
"$",
"this",
"->",
"assignExisting",
"(",
"$",
"propName",
",",
"$",
"propValue",
")",
";",
"}",
"elseif",
"(",
"$",
"propName",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"$",
"propValue",
";",
"}",
"}"
] |
main assign value method.
@param string $propNameOrig
@param mixed $propValue
|
[
"main",
"assign",
"value",
"method",
"."
] |
9e75c8fb36de7c09b01a6c1c0d27c45f02fed567
|
https://github.com/swaros/golib/blob/9e75c8fb36de7c09b01a6c1c0d27c45f02fed567/src/Types/Props.php#L84-L92
|
24,693
|
libreworks/caridea-auth
|
src/Service.php
|
Service.getPrincipal
|
public function getPrincipal(): Principal
{
if ($this->principal === null && !$this->resume()) {
$this->principal = Principal::getAnonymous();
}
return $this->principal;
}
|
php
|
public function getPrincipal(): Principal
{
if ($this->principal === null && !$this->resume()) {
$this->principal = Principal::getAnonymous();
}
return $this->principal;
}
|
[
"public",
"function",
"getPrincipal",
"(",
")",
":",
"Principal",
"{",
"if",
"(",
"$",
"this",
"->",
"principal",
"===",
"null",
"&&",
"!",
"$",
"this",
"->",
"resume",
"(",
")",
")",
"{",
"$",
"this",
"->",
"principal",
"=",
"Principal",
"::",
"getAnonymous",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"principal",
";",
"}"
] |
Gets the currently authenticated principal.
If no one is authenticated, this will return an anonymous Principal. If
The session is not started but can be resumed, it will be resumed and the
principal will be loaded.
@return Principal the authenticated principal
|
[
"Gets",
"the",
"currently",
"authenticated",
"principal",
"."
] |
1bf965c57716942b18ca3204629f6bda99cf876a
|
https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L81-L87
|
24,694
|
libreworks/caridea-auth
|
src/Service.php
|
Service.login
|
public function login(ServerRequestInterface $request, ?Adapter $adapter = null): bool
{
$started = $this->session->resume() || $this->session->start();
if (!$started) {
return false;
}
$login = $adapter ?? $this->adapter;
if ($login === null) {
throw new \InvalidArgumentException('You must specify an adapter for authentication');
}
$this->principal = $principal = $login->login($request);
$this->session->clear();
$this->session->regenerateId();
$this->values->offsetSet('principal', $principal);
$now = microtime(true);
$this->values->offsetSet('firstActive', $now);
$this->values->offsetSet('lastActive', $now);
$this->logger->info(
"Authentication login: {user}",
['user' => $principal]
);
return $this->publishLogin($principal);
}
|
php
|
public function login(ServerRequestInterface $request, ?Adapter $adapter = null): bool
{
$started = $this->session->resume() || $this->session->start();
if (!$started) {
return false;
}
$login = $adapter ?? $this->adapter;
if ($login === null) {
throw new \InvalidArgumentException('You must specify an adapter for authentication');
}
$this->principal = $principal = $login->login($request);
$this->session->clear();
$this->session->regenerateId();
$this->values->offsetSet('principal', $principal);
$now = microtime(true);
$this->values->offsetSet('firstActive', $now);
$this->values->offsetSet('lastActive', $now);
$this->logger->info(
"Authentication login: {user}",
['user' => $principal]
);
return $this->publishLogin($principal);
}
|
[
"public",
"function",
"login",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"?",
"Adapter",
"$",
"adapter",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"started",
"=",
"$",
"this",
"->",
"session",
"->",
"resume",
"(",
")",
"||",
"$",
"this",
"->",
"session",
"->",
"start",
"(",
")",
";",
"if",
"(",
"!",
"$",
"started",
")",
"{",
"return",
"false",
";",
"}",
"$",
"login",
"=",
"$",
"adapter",
"??",
"$",
"this",
"->",
"adapter",
";",
"if",
"(",
"$",
"login",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'You must specify an adapter for authentication'",
")",
";",
"}",
"$",
"this",
"->",
"principal",
"=",
"$",
"principal",
"=",
"$",
"login",
"->",
"login",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"session",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"session",
"->",
"regenerateId",
"(",
")",
";",
"$",
"this",
"->",
"values",
"->",
"offsetSet",
"(",
"'principal'",
",",
"$",
"principal",
")",
";",
"$",
"now",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"values",
"->",
"offsetSet",
"(",
"'firstActive'",
",",
"$",
"now",
")",
";",
"$",
"this",
"->",
"values",
"->",
"offsetSet",
"(",
"'lastActive'",
",",
"$",
"now",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Authentication login: {user}\"",
",",
"[",
"'user'",
"=>",
"$",
"principal",
"]",
")",
";",
"return",
"$",
"this",
"->",
"publishLogin",
"(",
"$",
"principal",
")",
";",
"}"
] |
Authenticates a principal.
@param ServerRequestInterface $request The Server Request message containing credentials
@param Adapter|null $adapter An optional adapter to use.
Will use the default authentication adapter if none is specified.
@return bool Whether the session could be established
@throws \InvalidArgumentException If no adapter is provided and no default adapter is set
@throws Exception\UsernameNotFound if the provided username wasn't found
@throws Exception\UsernameAmbiguous if the provided username matches multiple accounts
@throws Exception\InvalidPassword if the provided password is invalid
@throws Exception\ConnectionFailed if the access to a remote data source failed
(e.g. missing flat file, unreachable LDAP server, database login denied)
|
[
"Authenticates",
"a",
"principal",
"."
] |
1bf965c57716942b18ca3204629f6bda99cf876a
|
https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L103-L129
|
24,695
|
libreworks/caridea-auth
|
src/Service.php
|
Service.publishLogin
|
protected function publishLogin(Principal $principal): bool
{
$this->publisher->publish(new Event\Login($this, $principal));
return true;
}
|
php
|
protected function publishLogin(Principal $principal): bool
{
$this->publisher->publish(new Event\Login($this, $principal));
return true;
}
|
[
"protected",
"function",
"publishLogin",
"(",
"Principal",
"$",
"principal",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"publisher",
"->",
"publish",
"(",
"new",
"Event",
"\\",
"Login",
"(",
"$",
"this",
",",
"$",
"principal",
")",
")",
";",
"return",
"true",
";",
"}"
] |
Publishes the login event.
@param \Caridea\Auth\Principal $principal The authenticated principal
@return bool Always true
|
[
"Publishes",
"the",
"login",
"event",
"."
] |
1bf965c57716942b18ca3204629f6bda99cf876a
|
https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L137-L141
|
24,696
|
libreworks/caridea-auth
|
src/Service.php
|
Service.resume
|
public function resume(): bool
{
if ($this->values->offsetExists('principal')) {
$this->principal = $this->values->get('principal');
$this->logger->info(
"Authentication resume: {user}",
['user' => $this->principal]
);
$this->publishResume($this->principal, $this->values);
$this->values->offsetSet('lastActive', microtime(true));
return true;
}
return false;
}
|
php
|
public function resume(): bool
{
if ($this->values->offsetExists('principal')) {
$this->principal = $this->values->get('principal');
$this->logger->info(
"Authentication resume: {user}",
['user' => $this->principal]
);
$this->publishResume($this->principal, $this->values);
$this->values->offsetSet('lastActive', microtime(true));
return true;
}
return false;
}
|
[
"public",
"function",
"resume",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"values",
"->",
"offsetExists",
"(",
"'principal'",
")",
")",
"{",
"$",
"this",
"->",
"principal",
"=",
"$",
"this",
"->",
"values",
"->",
"get",
"(",
"'principal'",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Authentication resume: {user}\"",
",",
"[",
"'user'",
"=>",
"$",
"this",
"->",
"principal",
"]",
")",
";",
"$",
"this",
"->",
"publishResume",
"(",
"$",
"this",
"->",
"principal",
",",
"$",
"this",
"->",
"values",
")",
";",
"$",
"this",
"->",
"values",
"->",
"offsetSet",
"(",
"'lastActive'",
",",
"microtime",
"(",
"true",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Resumes an existing authenticated session.
@return bool If an authentication session existed
|
[
"Resumes",
"an",
"existing",
"authenticated",
"session",
"."
] |
1bf965c57716942b18ca3204629f6bda99cf876a
|
https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L148-L164
|
24,697
|
libreworks/caridea-auth
|
src/Service.php
|
Service.publishResume
|
protected function publishResume(Principal $principal, Map $values)
{
$this->publisher->publish(new Event\Resume(
$this,
$principal,
$values->get('firstActive') ?? 0.0,
$values->get('lastActive') ?? 0.0
));
}
|
php
|
protected function publishResume(Principal $principal, Map $values)
{
$this->publisher->publish(new Event\Resume(
$this,
$principal,
$values->get('firstActive') ?? 0.0,
$values->get('lastActive') ?? 0.0
));
}
|
[
"protected",
"function",
"publishResume",
"(",
"Principal",
"$",
"principal",
",",
"Map",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"publisher",
"->",
"publish",
"(",
"new",
"Event",
"\\",
"Resume",
"(",
"$",
"this",
",",
"$",
"principal",
",",
"$",
"values",
"->",
"get",
"(",
"'firstActive'",
")",
"??",
"0.0",
",",
"$",
"values",
"->",
"get",
"(",
"'lastActive'",
")",
"??",
"0.0",
")",
")",
";",
"}"
] |
Publishes the resume event.
@param \Caridea\Auth\Principal $principal The authenticated principal
@param \Caridea\Session\Map $values The session values
|
[
"Publishes",
"the",
"resume",
"event",
"."
] |
1bf965c57716942b18ca3204629f6bda99cf876a
|
https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L172-L180
|
24,698
|
libreworks/caridea-auth
|
src/Service.php
|
Service.logout
|
public function logout(): bool
{
if ($this->values->offsetExists('principal')) {
$principal = $this->getPrincipal();
$this->principal = Principal::getAnonymous();
$this->session->destroy();
$this->logger->info(
"Authentication logout: {user}",
['user' => $principal]
);
return $this->publishLogout($principal);
}
return false;
}
|
php
|
public function logout(): bool
{
if ($this->values->offsetExists('principal')) {
$principal = $this->getPrincipal();
$this->principal = Principal::getAnonymous();
$this->session->destroy();
$this->logger->info(
"Authentication logout: {user}",
['user' => $principal]
);
return $this->publishLogout($principal);
}
return false;
}
|
[
"public",
"function",
"logout",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"values",
"->",
"offsetExists",
"(",
"'principal'",
")",
")",
"{",
"$",
"principal",
"=",
"$",
"this",
"->",
"getPrincipal",
"(",
")",
";",
"$",
"this",
"->",
"principal",
"=",
"Principal",
"::",
"getAnonymous",
"(",
")",
";",
"$",
"this",
"->",
"session",
"->",
"destroy",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Authentication logout: {user}\"",
",",
"[",
"'user'",
"=>",
"$",
"principal",
"]",
")",
";",
"return",
"$",
"this",
"->",
"publishLogout",
"(",
"$",
"principal",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Logs out the currently authenticated principal.
@return bool If a principal existed in the session to log out
|
[
"Logs",
"out",
"the",
"currently",
"authenticated",
"principal",
"."
] |
1bf965c57716942b18ca3204629f6bda99cf876a
|
https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L187-L202
|
24,699
|
libreworks/caridea-auth
|
src/Service.php
|
Service.publishLogout
|
protected function publishLogout(Principal $principal): bool
{
$this->publisher->publish(new Event\Logout($this, $principal));
return true;
}
|
php
|
protected function publishLogout(Principal $principal): bool
{
$this->publisher->publish(new Event\Logout($this, $principal));
return true;
}
|
[
"protected",
"function",
"publishLogout",
"(",
"Principal",
"$",
"principal",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"publisher",
"->",
"publish",
"(",
"new",
"Event",
"\\",
"Logout",
"(",
"$",
"this",
",",
"$",
"principal",
")",
")",
";",
"return",
"true",
";",
"}"
] |
Publishes the logout event.
@param \Caridea\Auth\Principal $principal The authenticated principal
@return bool Always true
|
[
"Publishes",
"the",
"logout",
"event",
"."
] |
1bf965c57716942b18ca3204629f6bda99cf876a
|
https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L210-L214
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.