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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
25,600
|
RudyMas/Emvc_Login
|
src/Login.php
|
Login.translateData
|
private function translateData(): void
{
foreach ($this->db->data as $key => $value) {
$this->data[$key] = $value;
}
}
|
php
|
private function translateData(): void
{
foreach ($this->db->data as $key => $value) {
$this->data[$key] = $value;
}
}
|
[
"private",
"function",
"translateData",
"(",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"db",
"->",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] |
Transform clean SQL data to normal data
|
[
"Transform",
"clean",
"SQL",
"data",
"to",
"normal",
"data"
] |
9bcb50b08836d0639338ca2bc173182bc6b4bce3
|
https://github.com/RudyMas/Emvc_Login/blob/9bcb50b08836d0639338ca2bc173182bc6b4bce3/src/Login.php#L358-L363
|
25,601
|
RudyMas/Emvc_Login
|
src/Login.php
|
Login.setData
|
public function setData(string $key, $value): bool
{
if ($key !== 'password' || $key !== 'salt' || $key !== 'remember_md') {
$this->data[$key] = $value;
return true;
} else {
return false;
}
}
|
php
|
public function setData(string $key, $value): bool
{
if ($key !== 'password' || $key !== 'salt' || $key !== 'remember_md') {
$this->data[$key] = $value;
return true;
} else {
return false;
}
}
|
[
"public",
"function",
"setData",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"key",
"!==",
"'password'",
"||",
"$",
"key",
"!==",
"'salt'",
"||",
"$",
"key",
"!==",
"'remember_md'",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Set any other field from the table
@param string $key
@param mixed $value
@return bool
|
[
"Set",
"any",
"other",
"field",
"from",
"the",
"table"
] |
9bcb50b08836d0639338ca2bc173182bc6b4bce3
|
https://github.com/RudyMas/Emvc_Login/blob/9bcb50b08836d0639338ca2bc173182bc6b4bce3/src/Login.php#L460-L468
|
25,602
|
RudyMas/Emvc_Login
|
src/Login.php
|
Login.getData
|
public function getData(string $key)
{
return ($key !== 'password' || $key !== 'salt' || $key !== 'remember_me') ? $this->data[$key] : false;
}
|
php
|
public function getData(string $key)
{
return ($key !== 'password' || $key !== 'salt' || $key !== 'remember_me') ? $this->data[$key] : false;
}
|
[
"public",
"function",
"getData",
"(",
"string",
"$",
"key",
")",
"{",
"return",
"(",
"$",
"key",
"!==",
"'password'",
"||",
"$",
"key",
"!==",
"'salt'",
"||",
"$",
"key",
"!==",
"'remember_me'",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
":",
"false",
";",
"}"
] |
Get any other field from the table
Will return 'false' is key 'password', 'salt' or 'remember_me' is accessed
@param string $key
@return bool|mixed
|
[
"Get",
"any",
"other",
"field",
"from",
"the",
"table",
"Will",
"return",
"false",
"is",
"key",
"password",
"salt",
"or",
"remember_me",
"is",
"accessed"
] |
9bcb50b08836d0639338ca2bc173182bc6b4bce3
|
https://github.com/RudyMas/Emvc_Login/blob/9bcb50b08836d0639338ca2bc173182bc6b4bce3/src/Login.php#L477-L480
|
25,603
|
wb-crowdfusion/crowdfusion
|
system/core/classes/systemdb/plugins/PluginDAO.php
|
PluginDAO.postCacheTranslateObject
|
public function postCacheTranslateObject(ModelObject $obj)
{
if(strpos($obj->Path, $this->rootPath) === FALSE)
$obj->setPath($this->rootPath.DIRECTORY_SEPARATOR.$obj->Path);
return $obj;
}
|
php
|
public function postCacheTranslateObject(ModelObject $obj)
{
if(strpos($obj->Path, $this->rootPath) === FALSE)
$obj->setPath($this->rootPath.DIRECTORY_SEPARATOR.$obj->Path);
return $obj;
}
|
[
"public",
"function",
"postCacheTranslateObject",
"(",
"ModelObject",
"$",
"obj",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"obj",
"->",
"Path",
",",
"$",
"this",
"->",
"rootPath",
")",
"===",
"FALSE",
")",
"$",
"obj",
"->",
"setPath",
"(",
"$",
"this",
"->",
"rootPath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"obj",
"->",
"Path",
")",
";",
"return",
"$",
"obj",
";",
"}"
] |
Sets the path and returns the object
@param ModelObject $obj The plugin
@return ModelObject
|
[
"Sets",
"the",
"path",
"and",
"returns",
"the",
"object"
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/plugins/PluginDAO.php#L62-L67
|
25,604
|
koolkode/http
|
src/UriBuilder.php
|
UriBuilder.param
|
public function param($name, $value)
{
if(is_integer($name))
{
if(array_key_exists($name, $this->pathParamNames))
{
$this->path[$this->pathParamNames[$name]] = $value;
return $this;
}
throw new \OutOfBoundsException(sprintf('No path param at position %u', $name));
}
if(in_array($name, $this->pathParamNames, true))
{
$this->path[(string)$name] = $value;
return $this;
}
$this->query[(string)$name] = $value;
return $this;
}
|
php
|
public function param($name, $value)
{
if(is_integer($name))
{
if(array_key_exists($name, $this->pathParamNames))
{
$this->path[$this->pathParamNames[$name]] = $value;
return $this;
}
throw new \OutOfBoundsException(sprintf('No path param at position %u', $name));
}
if(in_array($name, $this->pathParamNames, true))
{
$this->path[(string)$name] = $value;
return $this;
}
$this->query[(string)$name] = $value;
return $this;
}
|
[
"public",
"function",
"param",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_integer",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"pathParamNames",
")",
")",
"{",
"$",
"this",
"->",
"path",
"[",
"$",
"this",
"->",
"pathParamNames",
"[",
"$",
"name",
"]",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'No path param at position %u'",
",",
"$",
"name",
")",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"pathParamNames",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"path",
"[",
"(",
"string",
")",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"query",
"[",
"(",
"string",
")",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] |
Assign a value to a path or query param depending on the URI pattern checking
the name of the param.
@param string $name
@param string $value
@return UriBuilder
|
[
"Assign",
"a",
"value",
"to",
"a",
"path",
"or",
"query",
"param",
"depending",
"on",
"the",
"URI",
"pattern",
"checking",
"the",
"name",
"of",
"the",
"param",
"."
] |
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
|
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/UriBuilder.php#L167-L191
|
25,605
|
koolkode/http
|
src/UriBuilder.php
|
UriBuilder.pathParam
|
public function pathParam($name, $value)
{
if(is_integer($name))
{
if(array_key_exists($name, $this->pathParamNames))
{
$this->path[$this->pathParamNames[$name]] = $value;
return $this;
}
throw new \OutOfBoundsException(sprintf('Path param %u not found in pattern "%s"', $name, $this->uri));
}
if(in_array($name, $this->pathParamNames, true))
{
$this->path[(string)$name] = $value;
return $this;
}
throw new \OutOfBoundsException(sprintf('Path param "%s" not found in pattern "%s"', $name, $this->uri));
}
|
php
|
public function pathParam($name, $value)
{
if(is_integer($name))
{
if(array_key_exists($name, $this->pathParamNames))
{
$this->path[$this->pathParamNames[$name]] = $value;
return $this;
}
throw new \OutOfBoundsException(sprintf('Path param %u not found in pattern "%s"', $name, $this->uri));
}
if(in_array($name, $this->pathParamNames, true))
{
$this->path[(string)$name] = $value;
return $this;
}
throw new \OutOfBoundsException(sprintf('Path param "%s" not found in pattern "%s"', $name, $this->uri));
}
|
[
"public",
"function",
"pathParam",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_integer",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"pathParamNames",
")",
")",
"{",
"$",
"this",
"->",
"path",
"[",
"$",
"this",
"->",
"pathParamNames",
"[",
"$",
"name",
"]",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'Path param %u not found in pattern \"%s\"'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"uri",
")",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"pathParamNames",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"path",
"[",
"(",
"string",
")",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'Path param \"%s\" not found in pattern \"%s\"'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"uri",
")",
")",
";",
"}"
] |
Assign a value to a path param.
@param string $name
@param string $value
@return UriBuilder
@throws \OutOfBoundsException When no such param (name or index) exists.
|
[
"Assign",
"a",
"value",
"to",
"a",
"path",
"param",
"."
] |
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
|
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/UriBuilder.php#L212-L234
|
25,606
|
koolkode/http
|
src/UriBuilder.php
|
UriBuilder.queryParam
|
public function queryParam($name, $value)
{
if($value === NULL)
{
unset($this->query[(string)$name]);
}
else
{
$this->query[(string)$name] = $value;
}
return $this;
}
|
php
|
public function queryParam($name, $value)
{
if($value === NULL)
{
unset($this->query[(string)$name]);
}
else
{
$this->query[(string)$name] = $value;
}
return $this;
}
|
[
"public",
"function",
"queryParam",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"NULL",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"query",
"[",
"(",
"string",
")",
"$",
"name",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"query",
"[",
"(",
"string",
")",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Assign a value to a query param, assigning a NULL value will remove the query param.
@param string $name
@param mixed $value
@return UriBuilder
|
[
"Assign",
"a",
"value",
"to",
"a",
"query",
"param",
"assigning",
"a",
"NULL",
"value",
"will",
"remove",
"the",
"query",
"param",
"."
] |
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
|
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/UriBuilder.php#L243-L255
|
25,607
|
koolkode/http
|
src/UriBuilder.php
|
UriBuilder.queryParams
|
public function queryParams(array $query)
{
$this->query = Arrays::mergeDeep($this->query, $query);
return $this;
}
|
php
|
public function queryParams(array $query)
{
$this->query = Arrays::mergeDeep($this->query, $query);
return $this;
}
|
[
"public",
"function",
"queryParams",
"(",
"array",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"query",
"=",
"Arrays",
"::",
"mergeDeep",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"query",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Merges query params recursively.
@param array<string, mixed> $query
@return UriBuilder
|
[
"Merges",
"query",
"params",
"recursively",
"."
] |
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
|
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/UriBuilder.php#L263-L268
|
25,608
|
koolkode/http
|
src/UriBuilder.php
|
UriBuilder.setParams
|
public function setParams(array $params)
{
$this->path = [];
$this->query = [];
foreach($params as $k => $v)
{
if(is_integer($k))
{
if(array_key_exists($k, $this->pathParamNames))
{
$this->path[$this->pathParamNames[$k]] = $v;
continue;
}
throw new \OutOfBoundsException(sprintf('No path param at position %u', $k));
}
if(in_array($k, $this->pathParamNames, true))
{
$this->path[$k] = $v;
continue;
}
$this->query[$k] = $v;
}
return $this;
}
|
php
|
public function setParams(array $params)
{
$this->path = [];
$this->query = [];
foreach($params as $k => $v)
{
if(is_integer($k))
{
if(array_key_exists($k, $this->pathParamNames))
{
$this->path[$this->pathParamNames[$k]] = $v;
continue;
}
throw new \OutOfBoundsException(sprintf('No path param at position %u', $k));
}
if(in_array($k, $this->pathParamNames, true))
{
$this->path[$k] = $v;
continue;
}
$this->query[$k] = $v;
}
return $this;
}
|
[
"public",
"function",
"setParams",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"path",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"query",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_integer",
"(",
"$",
"k",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"k",
",",
"$",
"this",
"->",
"pathParamNames",
")",
")",
"{",
"$",
"this",
"->",
"path",
"[",
"$",
"this",
"->",
"pathParamNames",
"[",
"$",
"k",
"]",
"]",
"=",
"$",
"v",
";",
"continue",
";",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'No path param at position %u'",
",",
"$",
"k",
")",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"k",
",",
"$",
"this",
"->",
"pathParamNames",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"path",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"query",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Removes all param values from path and query and re-populates using the given values.
@param array<string, mixed> $params Path and query params to be set.
@return UriBuilder
|
[
"Removes",
"all",
"param",
"values",
"from",
"path",
"and",
"query",
"and",
"re",
"-",
"populates",
"using",
"the",
"given",
"values",
"."
] |
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
|
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/UriBuilder.php#L288-L318
|
25,609
|
koolkode/http
|
src/UriBuilder.php
|
UriBuilder.fragment
|
public function fragment($fragment)
{
$this->fragment = ($fragment === NULL || $fragment == '') ? NULL : (string)$fragment;
return $this;
}
|
php
|
public function fragment($fragment)
{
$this->fragment = ($fragment === NULL || $fragment == '') ? NULL : (string)$fragment;
return $this;
}
|
[
"public",
"function",
"fragment",
"(",
"$",
"fragment",
")",
"{",
"$",
"this",
"->",
"fragment",
"=",
"(",
"$",
"fragment",
"===",
"NULL",
"||",
"$",
"fragment",
"==",
"''",
")",
"?",
"NULL",
":",
"(",
"string",
")",
"$",
"fragment",
";",
"return",
"$",
"this",
";",
"}"
] |
Set or remove the fragment part of this URI.
@param string $fragment
@return UriBuilder
|
[
"Set",
"or",
"remove",
"the",
"fragment",
"part",
"of",
"this",
"URI",
"."
] |
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
|
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/UriBuilder.php#L326-L331
|
25,610
|
koolkode/http
|
src/UriBuilder.php
|
UriBuilder.build
|
public function build($trailingSlash = false)
{
$result = '';
foreach(preg_split("'(\\{(?:(?>[^\\{\\}]+)|(?R))+\\})'S", $this->uri, -1, PREG_SPLIT_DELIM_CAPTURE) as $part)
{
if(substr($part, 0, 1) == '{')
{
$result .= Uri::encode($this->path[substr($part, 1, -1)]);
}
else
{
$result .= $part;
}
}
$result = $this->replaceParams($this->uri, $this->path);
if($trailingSlash && substr($result, -1) != '/')
{
$uri = new Uri($result . '/');
}
else
{
$uri = new Uri($result);
}
if(!empty($this->query))
{
$uri = $uri->setQuery($this->query);
}
if($this->fragment !== NULL)
{
if(false === strpos($this->fragment, '{'))
{
$uri = $uri->setFragment($this->fragment);
}
else
{
$uri = $uri->setFragment($this->replaceParams($this->fragment, $this->path));
}
}
return $uri;
}
|
php
|
public function build($trailingSlash = false)
{
$result = '';
foreach(preg_split("'(\\{(?:(?>[^\\{\\}]+)|(?R))+\\})'S", $this->uri, -1, PREG_SPLIT_DELIM_CAPTURE) as $part)
{
if(substr($part, 0, 1) == '{')
{
$result .= Uri::encode($this->path[substr($part, 1, -1)]);
}
else
{
$result .= $part;
}
}
$result = $this->replaceParams($this->uri, $this->path);
if($trailingSlash && substr($result, -1) != '/')
{
$uri = new Uri($result . '/');
}
else
{
$uri = new Uri($result);
}
if(!empty($this->query))
{
$uri = $uri->setQuery($this->query);
}
if($this->fragment !== NULL)
{
if(false === strpos($this->fragment, '{'))
{
$uri = $uri->setFragment($this->fragment);
}
else
{
$uri = $uri->setFragment($this->replaceParams($this->fragment, $this->path));
}
}
return $uri;
}
|
[
"public",
"function",
"build",
"(",
"$",
"trailingSlash",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"''",
";",
"foreach",
"(",
"preg_split",
"(",
"\"'(\\\\{(?:(?>[^\\\\{\\\\}]+)|(?R))+\\\\})'S\"",
",",
"$",
"this",
"->",
"uri",
",",
"-",
"1",
",",
"PREG_SPLIT_DELIM_CAPTURE",
")",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"part",
",",
"0",
",",
"1",
")",
"==",
"'{'",
")",
"{",
"$",
"result",
".=",
"Uri",
"::",
"encode",
"(",
"$",
"this",
"->",
"path",
"[",
"substr",
"(",
"$",
"part",
",",
"1",
",",
"-",
"1",
")",
"]",
")",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"$",
"part",
";",
"}",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"replaceParams",
"(",
"$",
"this",
"->",
"uri",
",",
"$",
"this",
"->",
"path",
")",
";",
"if",
"(",
"$",
"trailingSlash",
"&&",
"substr",
"(",
"$",
"result",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"uri",
"=",
"new",
"Uri",
"(",
"$",
"result",
".",
"'/'",
")",
";",
"}",
"else",
"{",
"$",
"uri",
"=",
"new",
"Uri",
"(",
"$",
"result",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"query",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"setQuery",
"(",
"$",
"this",
"->",
"query",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"fragment",
"!==",
"NULL",
")",
"{",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"this",
"->",
"fragment",
",",
"'{'",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"setFragment",
"(",
"$",
"this",
"->",
"fragment",
")",
";",
"}",
"else",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"setFragment",
"(",
"$",
"this",
"->",
"replaceParams",
"(",
"$",
"this",
"->",
"fragment",
",",
"$",
"this",
"->",
"path",
")",
")",
";",
"}",
"}",
"return",
"$",
"uri",
";",
"}"
] |
Build a URI from template and assigned parameters.
@param boolean $trailingSlash
@return Uri
@throws \OutOfBoundsException When at least one path parameter value is missing.
|
[
"Build",
"a",
"URI",
"from",
"template",
"and",
"assigned",
"parameters",
"."
] |
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
|
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/UriBuilder.php#L341-L386
|
25,611
|
shgysk8zer0/core_api
|
traits/console.php
|
Console._formatLocation
|
final protected function _formatLocation($file, $line, $format = self::LOG_FORMAT)
{
return sprintf($format, $file, $line);
}
|
php
|
final protected function _formatLocation($file, $line, $format = self::LOG_FORMAT)
{
return sprintf($format, $file, $line);
}
|
[
"final",
"protected",
"function",
"_formatLocation",
"(",
"$",
"file",
",",
"$",
"line",
",",
"$",
"format",
"=",
"self",
"::",
"LOG_FORMAT",
")",
"{",
"return",
"sprintf",
"(",
"$",
"format",
",",
"$",
"file",
",",
"$",
"line",
")",
";",
"}"
] |
formats the location from backtrace using sprintf
@param string $file the file the log was created in
@param int $line the line the log was created on
@param string $format output format
@return string location formatted according to $format
|
[
"formats",
"the",
"location",
"from",
"backtrace",
"using",
"sprintf"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/console.php#L154-L157
|
25,612
|
shgysk8zer0/core_api
|
traits/console.php
|
Console._convert
|
final protected function _convert($object)
{
// if this isn't an object then just return it
if (!is_object($object)) {
return $object;
}
//Mark this object as processed so we don't convert it twice and it
//Also avoid recursion when objects refer to each other
$this->_processed[] = $object;
$object_as_array = array();
// first add the class name
$object_as_array['___class_name'] = get_class($object);
// loop through object vars
$object_vars = get_object_vars($object);
foreach ($object_vars as $key => $value) {
// same instance as parent object
if ($value === $object || in_array($value, $this->_processed, true)) {
$value = 'recursion - parent object [' . get_class($value) . ']';
}
$object_as_array[$key] = $this->_convert($value);
}
$reflection = new \ReflectionClass($object);
// loop through the properties and add those
foreach ($reflection->getProperties() as $property) {
// if one of these properties was already added above then ignore it
if (array_key_exists($property->getName(), $object_vars)) {
continue;
}
$type = $this->_getPropertyKey($property);
if ($this->_php_version >= 5.3) {
$property->setAccessible(true);
}
try {
$value = $property->getValue($object);
} catch (\ReflectionException $e) {
$value = 'only PHP 5.3 can access private/protected properties';
}
// same instance as parent object
if ($value === $object || in_array($value, $this->_processed, true)) {
$value = 'recursion - parent object [' . get_class($value) . ']';
}
$object_as_array[$type] = $this->_convert($value);
}
return $object_as_array;
}
|
php
|
final protected function _convert($object)
{
// if this isn't an object then just return it
if (!is_object($object)) {
return $object;
}
//Mark this object as processed so we don't convert it twice and it
//Also avoid recursion when objects refer to each other
$this->_processed[] = $object;
$object_as_array = array();
// first add the class name
$object_as_array['___class_name'] = get_class($object);
// loop through object vars
$object_vars = get_object_vars($object);
foreach ($object_vars as $key => $value) {
// same instance as parent object
if ($value === $object || in_array($value, $this->_processed, true)) {
$value = 'recursion - parent object [' . get_class($value) . ']';
}
$object_as_array[$key] = $this->_convert($value);
}
$reflection = new \ReflectionClass($object);
// loop through the properties and add those
foreach ($reflection->getProperties() as $property) {
// if one of these properties was already added above then ignore it
if (array_key_exists($property->getName(), $object_vars)) {
continue;
}
$type = $this->_getPropertyKey($property);
if ($this->_php_version >= 5.3) {
$property->setAccessible(true);
}
try {
$value = $property->getValue($object);
} catch (\ReflectionException $e) {
$value = 'only PHP 5.3 can access private/protected properties';
}
// same instance as parent object
if ($value === $object || in_array($value, $this->_processed, true)) {
$value = 'recursion - parent object [' . get_class($value) . ']';
}
$object_as_array[$type] = $this->_convert($value);
}
return $object_as_array;
}
|
[
"final",
"protected",
"function",
"_convert",
"(",
"$",
"object",
")",
"{",
"// if this isn't an object then just return it",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"return",
"$",
"object",
";",
"}",
"//Mark this object as processed so we don't convert it twice and it",
"//Also avoid recursion when objects refer to each other",
"$",
"this",
"->",
"_processed",
"[",
"]",
"=",
"$",
"object",
";",
"$",
"object_as_array",
"=",
"array",
"(",
")",
";",
"// first add the class name",
"$",
"object_as_array",
"[",
"'___class_name'",
"]",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"// loop through object vars",
"$",
"object_vars",
"=",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"object_vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// same instance as parent object",
"if",
"(",
"$",
"value",
"===",
"$",
"object",
"||",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"_processed",
",",
"true",
")",
")",
"{",
"$",
"value",
"=",
"'recursion - parent object ['",
".",
"get_class",
"(",
"$",
"value",
")",
".",
"']'",
";",
"}",
"$",
"object_as_array",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"_convert",
"(",
"$",
"value",
")",
";",
"}",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"object",
")",
";",
"// loop through the properties and add those",
"foreach",
"(",
"$",
"reflection",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"// if one of these properties was already added above then ignore it",
"if",
"(",
"array_key_exists",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"object_vars",
")",
")",
"{",
"continue",
";",
"}",
"$",
"type",
"=",
"$",
"this",
"->",
"_getPropertyKey",
"(",
"$",
"property",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_php_version",
">=",
"5.3",
")",
"{",
"$",
"property",
"->",
"setAccessible",
"(",
"true",
")",
";",
"}",
"try",
"{",
"$",
"value",
"=",
"$",
"property",
"->",
"getValue",
"(",
"$",
"object",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"$",
"value",
"=",
"'only PHP 5.3 can access private/protected properties'",
";",
"}",
"// same instance as parent object",
"if",
"(",
"$",
"value",
"===",
"$",
"object",
"||",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"_processed",
",",
"true",
")",
")",
"{",
"$",
"value",
"=",
"'recursion - parent object ['",
".",
"get_class",
"(",
"$",
"value",
")",
".",
"']'",
";",
"}",
"$",
"object_as_array",
"[",
"$",
"type",
"]",
"=",
"$",
"this",
"->",
"_convert",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"object_as_array",
";",
"}"
] |
converts an object to a better format for logging
@param Object
@return array
|
[
"converts",
"an",
"object",
"to",
"a",
"better",
"format",
"for",
"logging"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/console.php#L192-L236
|
25,613
|
shgysk8zer0/core_api
|
traits/console.php
|
Console._getPropertyKey
|
final protected function _getPropertyKey(\ReflectionProperty $property)
{
$static = $property->isStatic() ? ' static' : '';
if ($property->isPublic()) {
return 'public' . $static . ' ' . $property->getName();
}
if ($property->isProtected()) {
return 'protected' . $static . ' ' . $property->getName();
}
if ($property->isPrivate()) {
return 'private' . $static . ' ' . $property->getName();
}
}
|
php
|
final protected function _getPropertyKey(\ReflectionProperty $property)
{
$static = $property->isStatic() ? ' static' : '';
if ($property->isPublic()) {
return 'public' . $static . ' ' . $property->getName();
}
if ($property->isProtected()) {
return 'protected' . $static . ' ' . $property->getName();
}
if ($property->isPrivate()) {
return 'private' . $static . ' ' . $property->getName();
}
}
|
[
"final",
"protected",
"function",
"_getPropertyKey",
"(",
"\\",
"ReflectionProperty",
"$",
"property",
")",
"{",
"$",
"static",
"=",
"$",
"property",
"->",
"isStatic",
"(",
")",
"?",
"' static'",
":",
"''",
";",
"if",
"(",
"$",
"property",
"->",
"isPublic",
"(",
")",
")",
"{",
"return",
"'public'",
".",
"$",
"static",
".",
"' '",
".",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"if",
"(",
"$",
"property",
"->",
"isProtected",
"(",
")",
")",
"{",
"return",
"'protected'",
".",
"$",
"static",
".",
"' '",
".",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"if",
"(",
"$",
"property",
"->",
"isPrivate",
"(",
")",
")",
"{",
"return",
"'private'",
".",
"$",
"static",
".",
"' '",
".",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"}"
] |
takes a reflection property and returns a nicely formatted key of the property name
@param ReflectionProperty
@return string
|
[
"takes",
"a",
"reflection",
"property",
"and",
"returns",
"a",
"nicely",
"formatted",
"key",
"of",
"the",
"property",
"name"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/console.php#L244-L256
|
25,614
|
OxfordInfoLabs/kinikit-core
|
src/Util/Caching/CachingHeaders.php
|
CachingHeaders.addCachingHeaders
|
public function addCachingHeaders($numberOfMinutes = 60, $mustRevalidate = true) {
// Add cache control header if revalidate
$numberOfSeconds = $numberOfMinutes * 60;
$header = "Cache-Control: public, max-age=" . ($numberOfSeconds);
if ($mustRevalidate)
$header .= ", must-revalidate";
header($header);
// Add the Expires header.
$expStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $numberOfSeconds) . " GMT";
header($expStr);
// Add the last modified header.
$lastModified = "Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT";
header($lastModified);
header_remove("Pragma");
$etag = '"' . filemtime(__FILE__) . '.' . date("U") . '"';
header("ETag: $etag");
}
|
php
|
public function addCachingHeaders($numberOfMinutes = 60, $mustRevalidate = true) {
// Add cache control header if revalidate
$numberOfSeconds = $numberOfMinutes * 60;
$header = "Cache-Control: public, max-age=" . ($numberOfSeconds);
if ($mustRevalidate)
$header .= ", must-revalidate";
header($header);
// Add the Expires header.
$expStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $numberOfSeconds) . " GMT";
header($expStr);
// Add the last modified header.
$lastModified = "Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT";
header($lastModified);
header_remove("Pragma");
$etag = '"' . filemtime(__FILE__) . '.' . date("U") . '"';
header("ETag: $etag");
}
|
[
"public",
"function",
"addCachingHeaders",
"(",
"$",
"numberOfMinutes",
"=",
"60",
",",
"$",
"mustRevalidate",
"=",
"true",
")",
"{",
"// Add cache control header if revalidate",
"$",
"numberOfSeconds",
"=",
"$",
"numberOfMinutes",
"*",
"60",
";",
"$",
"header",
"=",
"\"Cache-Control: public, max-age=\"",
".",
"(",
"$",
"numberOfSeconds",
")",
";",
"if",
"(",
"$",
"mustRevalidate",
")",
"$",
"header",
".=",
"\", must-revalidate\"",
";",
"header",
"(",
"$",
"header",
")",
";",
"// Add the Expires header.",
"$",
"expStr",
"=",
"\"Expires: \"",
".",
"gmdate",
"(",
"\"D, d M Y H:i:s\"",
",",
"time",
"(",
")",
"+",
"$",
"numberOfSeconds",
")",
".",
"\" GMT\"",
";",
"header",
"(",
"$",
"expStr",
")",
";",
"// Add the last modified header.",
"$",
"lastModified",
"=",
"\"Last-Modified: \"",
".",
"gmdate",
"(",
"\"D, d M Y H:i:s\"",
",",
"time",
"(",
")",
")",
".",
"\" GMT\"",
";",
"header",
"(",
"$",
"lastModified",
")",
";",
"header_remove",
"(",
"\"Pragma\"",
")",
";",
"$",
"etag",
"=",
"'\"'",
".",
"filemtime",
"(",
"__FILE__",
")",
".",
"'.'",
".",
"date",
"(",
"\"U\"",
")",
".",
"'\"'",
";",
"header",
"(",
"\"ETag: $etag\"",
")",
";",
"}"
] |
Add caching headers to the current request.
|
[
"Add",
"caching",
"headers",
"to",
"the",
"current",
"request",
"."
] |
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
|
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Caching/CachingHeaders.php#L43-L67
|
25,615
|
freialib/freia.autoloader
|
src/SymbolEnvironment.php
|
SymbolEnvironment.autoresolve
|
function autoresolve($symbol) {
// is the symbol an alias?
if (\array_key_exists($symbol, $this->state['aliases'])) {
// then resolve the alias
// you can only alias to know symbols so the following will succeed
$this->autoresolve($this->state['aliases'][$symbol]);
// and afterwards alias the symbol
$this->class_alias($this->state['aliases'][$symbol], $symbol);
return true;
}
// do we know of the symbol's path?
if (\array_key_exists($symbol, $this->state['symbols'])) {
$this->requirefile($this->state['symbols'][$symbol]);
return true;
}
return false; // none of the above
}
|
php
|
function autoresolve($symbol) {
// is the symbol an alias?
if (\array_key_exists($symbol, $this->state['aliases'])) {
// then resolve the alias
// you can only alias to know symbols so the following will succeed
$this->autoresolve($this->state['aliases'][$symbol]);
// and afterwards alias the symbol
$this->class_alias($this->state['aliases'][$symbol], $symbol);
return true;
}
// do we know of the symbol's path?
if (\array_key_exists($symbol, $this->state['symbols'])) {
$this->requirefile($this->state['symbols'][$symbol]);
return true;
}
return false; // none of the above
}
|
[
"function",
"autoresolve",
"(",
"$",
"symbol",
")",
"{",
"// is the symbol an alias?",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"symbol",
",",
"$",
"this",
"->",
"state",
"[",
"'aliases'",
"]",
")",
")",
"{",
"// then resolve the alias",
"// you can only alias to know symbols so the following will succeed",
"$",
"this",
"->",
"autoresolve",
"(",
"$",
"this",
"->",
"state",
"[",
"'aliases'",
"]",
"[",
"$",
"symbol",
"]",
")",
";",
"// and afterwards alias the symbol",
"$",
"this",
"->",
"class_alias",
"(",
"$",
"this",
"->",
"state",
"[",
"'aliases'",
"]",
"[",
"$",
"symbol",
"]",
",",
"$",
"symbol",
")",
";",
"return",
"true",
";",
"}",
"// do we know of the symbol's path?",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"symbol",
",",
"$",
"this",
"->",
"state",
"[",
"'symbols'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"requirefile",
"(",
"$",
"this",
"->",
"state",
"[",
"'symbols'",
"]",
"[",
"$",
"symbol",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"// none of the above",
"}"
] |
Attempt to auto-resolve a symbol based on past state.
|
[
"Attempt",
"to",
"auto",
"-",
"resolve",
"a",
"symbol",
"based",
"on",
"past",
"state",
"."
] |
45e0dfcd56d55cf533f12255db647e8a05fcd494
|
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L408-L427
|
25,616
|
freialib/freia.autoloader
|
src/SymbolEnvironment.php
|
SymbolEnvironment.save
|
function save() {
if ($this->cacheConf['type'] == 'noop') {
// do nothing
}
else { // non-noop
$stateCopy = $this->state;
$stateCopy['loaded'] = [];
if ($this->cacheConf['type'] == 'file') {
$username = \get_current_user();
$cacheDir = realpath($this->syspath.'/'.\trim($this->cacheConf['path'], '\\/'));
$cachePath = $cacheDir.'/freia.'.(\php_sapi_name() === 'cli' ? 'cli' : 'server').'.'.$username.'.symbols.json';
if ($this->file_exists($cacheDir)) {
try {
$this->file_put_contents($cachePath, \json_encode($stateCopy, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
if ( ! $this->chmod($cachePath, $this->filePermission())) {
$this->error_log("Unable to set permissions on cache file: $cachePath");
}
}
catch (\Exception $e) {
$this->error_log('Failed to save state to cache file ['.$cachePath.'] Error: '.$e->getMessage());
}
}
else {
$this->error_log('Missing cache directory: '.$this->cacheConf['path']);
}
}
else if ($this->cacheConf['type'] == 'memcached') {
$mc = $this->memcachedInstance();
$success = $mc->set('freia-symbols', $stateCopy, time() + 604800);
if ( ! $success) {
$this->error_log("Memcached failed to store key freia-symbols, code: ".$mc->getResultCode());
}
}
}
}
|
php
|
function save() {
if ($this->cacheConf['type'] == 'noop') {
// do nothing
}
else { // non-noop
$stateCopy = $this->state;
$stateCopy['loaded'] = [];
if ($this->cacheConf['type'] == 'file') {
$username = \get_current_user();
$cacheDir = realpath($this->syspath.'/'.\trim($this->cacheConf['path'], '\\/'));
$cachePath = $cacheDir.'/freia.'.(\php_sapi_name() === 'cli' ? 'cli' : 'server').'.'.$username.'.symbols.json';
if ($this->file_exists($cacheDir)) {
try {
$this->file_put_contents($cachePath, \json_encode($stateCopy, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
if ( ! $this->chmod($cachePath, $this->filePermission())) {
$this->error_log("Unable to set permissions on cache file: $cachePath");
}
}
catch (\Exception $e) {
$this->error_log('Failed to save state to cache file ['.$cachePath.'] Error: '.$e->getMessage());
}
}
else {
$this->error_log('Missing cache directory: '.$this->cacheConf['path']);
}
}
else if ($this->cacheConf['type'] == 'memcached') {
$mc = $this->memcachedInstance();
$success = $mc->set('freia-symbols', $stateCopy, time() + 604800);
if ( ! $success) {
$this->error_log("Memcached failed to store key freia-symbols, code: ".$mc->getResultCode());
}
}
}
}
|
[
"function",
"save",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'noop'",
")",
"{",
"// do nothing",
"}",
"else",
"{",
"// non-noop",
"$",
"stateCopy",
"=",
"$",
"this",
"->",
"state",
";",
"$",
"stateCopy",
"[",
"'loaded'",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'file'",
")",
"{",
"$",
"username",
"=",
"\\",
"get_current_user",
"(",
")",
";",
"$",
"cacheDir",
"=",
"realpath",
"(",
"$",
"this",
"->",
"syspath",
".",
"'/'",
".",
"\\",
"trim",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'path'",
"]",
",",
"'\\\\/'",
")",
")",
";",
"$",
"cachePath",
"=",
"$",
"cacheDir",
".",
"'/freia.'",
".",
"(",
"\\",
"php_sapi_name",
"(",
")",
"===",
"'cli'",
"?",
"'cli'",
":",
"'server'",
")",
".",
"'.'",
".",
"$",
"username",
".",
"'.symbols.json'",
";",
"if",
"(",
"$",
"this",
"->",
"file_exists",
"(",
"$",
"cacheDir",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"file_put_contents",
"(",
"$",
"cachePath",
",",
"\\",
"json_encode",
"(",
"$",
"stateCopy",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"chmod",
"(",
"$",
"cachePath",
",",
"$",
"this",
"->",
"filePermission",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"error_log",
"(",
"\"Unable to set permissions on cache file: $cachePath\"",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"error_log",
"(",
"'Failed to save state to cache file ['",
".",
"$",
"cachePath",
".",
"'] Error: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"error_log",
"(",
"'Missing cache directory: '",
".",
"$",
"this",
"->",
"cacheConf",
"[",
"'path'",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'memcached'",
")",
"{",
"$",
"mc",
"=",
"$",
"this",
"->",
"memcachedInstance",
"(",
")",
";",
"$",
"success",
"=",
"$",
"mc",
"->",
"set",
"(",
"'freia-symbols'",
",",
"$",
"stateCopy",
",",
"time",
"(",
")",
"+",
"604800",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"$",
"this",
"->",
"error_log",
"(",
"\"Memcached failed to store key freia-symbols, code: \"",
".",
"$",
"mc",
"->",
"getResultCode",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Save current state to persistent store
|
[
"Save",
"current",
"state",
"to",
"persistent",
"store"
] |
45e0dfcd56d55cf533f12255db647e8a05fcd494
|
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L467-L504
|
25,617
|
freialib/freia.autoloader
|
src/SymbolEnvironment.php
|
SymbolEnvironment.load
|
function load() {
if ($this->cacheConf['type'] == 'noop') {
return null; // do nothing
}
else { // non-noop
$loadedState = null;
if ($this->cacheConf['type'] == 'file') {
$username = \get_current_user();
$cacheDir = realpath($this->syspath.'/'.\trim($this->cacheConf['path'], '\\/'));
$cachePath = $cacheDir.'/freia.'.(\php_sapi_name() === 'cli' ? 'cli' : 'server').'.'.$username.'.symbols.json';
if ($this->file_exists($cachePath)) {
try {
$loadedState = \json_decode($this->file_get_contents($cachePath), true);
}
catch (\Exception $e) {
$this->error_log('Failed to load cache file: '.$cachePath);
return null;
}
}
else { // couldn't find cache file
return null;
}
}
else if ($this->cacheConf['type'] == 'memcached') {
$mc = $this->memcachedInstance();
try {
$loadedState = $mc->get('freia-symbols');
}
catch (\Exception $e) {
$loadedState = null;
}
}
// Process Loaded State
// ====================
if ($loadedState == null) {
return null;
}
if ($loadedState['version'] == $this->state['version']) {
return $loadedState;
}
else { // deprecated state
return null;
}
}
}
|
php
|
function load() {
if ($this->cacheConf['type'] == 'noop') {
return null; // do nothing
}
else { // non-noop
$loadedState = null;
if ($this->cacheConf['type'] == 'file') {
$username = \get_current_user();
$cacheDir = realpath($this->syspath.'/'.\trim($this->cacheConf['path'], '\\/'));
$cachePath = $cacheDir.'/freia.'.(\php_sapi_name() === 'cli' ? 'cli' : 'server').'.'.$username.'.symbols.json';
if ($this->file_exists($cachePath)) {
try {
$loadedState = \json_decode($this->file_get_contents($cachePath), true);
}
catch (\Exception $e) {
$this->error_log('Failed to load cache file: '.$cachePath);
return null;
}
}
else { // couldn't find cache file
return null;
}
}
else if ($this->cacheConf['type'] == 'memcached') {
$mc = $this->memcachedInstance();
try {
$loadedState = $mc->get('freia-symbols');
}
catch (\Exception $e) {
$loadedState = null;
}
}
// Process Loaded State
// ====================
if ($loadedState == null) {
return null;
}
if ($loadedState['version'] == $this->state['version']) {
return $loadedState;
}
else { // deprecated state
return null;
}
}
}
|
[
"function",
"load",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'noop'",
")",
"{",
"return",
"null",
";",
"// do nothing",
"}",
"else",
"{",
"// non-noop",
"$",
"loadedState",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'file'",
")",
"{",
"$",
"username",
"=",
"\\",
"get_current_user",
"(",
")",
";",
"$",
"cacheDir",
"=",
"realpath",
"(",
"$",
"this",
"->",
"syspath",
".",
"'/'",
".",
"\\",
"trim",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'path'",
"]",
",",
"'\\\\/'",
")",
")",
";",
"$",
"cachePath",
"=",
"$",
"cacheDir",
".",
"'/freia.'",
".",
"(",
"\\",
"php_sapi_name",
"(",
")",
"===",
"'cli'",
"?",
"'cli'",
":",
"'server'",
")",
".",
"'.'",
".",
"$",
"username",
".",
"'.symbols.json'",
";",
"if",
"(",
"$",
"this",
"->",
"file_exists",
"(",
"$",
"cachePath",
")",
")",
"{",
"try",
"{",
"$",
"loadedState",
"=",
"\\",
"json_decode",
"(",
"$",
"this",
"->",
"file_get_contents",
"(",
"$",
"cachePath",
")",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"error_log",
"(",
"'Failed to load cache file: '",
".",
"$",
"cachePath",
")",
";",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"// couldn't find cache file",
"return",
"null",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'memcached'",
")",
"{",
"$",
"mc",
"=",
"$",
"this",
"->",
"memcachedInstance",
"(",
")",
";",
"try",
"{",
"$",
"loadedState",
"=",
"$",
"mc",
"->",
"get",
"(",
"'freia-symbols'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"loadedState",
"=",
"null",
";",
"}",
"}",
"// Process Loaded State",
"// ====================",
"if",
"(",
"$",
"loadedState",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"loadedState",
"[",
"'version'",
"]",
"==",
"$",
"this",
"->",
"state",
"[",
"'version'",
"]",
")",
"{",
"return",
"$",
"loadedState",
";",
"}",
"else",
"{",
"// deprecated state",
"return",
"null",
";",
"}",
"}",
"}"
] |
Load state from persistent store
@return array previously saved state
|
[
"Load",
"state",
"from",
"persistent",
"store"
] |
45e0dfcd56d55cf533f12255db647e8a05fcd494
|
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L511-L561
|
25,618
|
stubbles/stubbles-streams
|
src/main/php/file/FileInputStream.php
|
FileInputStream.castFrom
|
public static function castFrom($value): InputStream
{
if ($value instanceof InputStream) {
return $value;
}
if (is_string($value)) {
return new self($value);
}
throw new \InvalidArgumentException(
'Given value is neither an instance of' . InputStream::class
. ' nor a string denoting a file'
);
}
|
php
|
public static function castFrom($value): InputStream
{
if ($value instanceof InputStream) {
return $value;
}
if (is_string($value)) {
return new self($value);
}
throw new \InvalidArgumentException(
'Given value is neither an instance of' . InputStream::class
. ' nor a string denoting a file'
);
}
|
[
"public",
"static",
"function",
"castFrom",
"(",
"$",
"value",
")",
":",
"InputStream",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"InputStream",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"value",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Given value is neither an instance of'",
".",
"InputStream",
"::",
"class",
".",
"' nor a string denoting a file'",
")",
";",
"}"
] |
casts given value to an input stream
@param \stubbles\streams\InputStream|string $value
@return \stubbles\streams\InputStream
@throws \InvalidArgumentException
@since 5.2.0
|
[
"casts",
"given",
"value",
"to",
"an",
"input",
"stream"
] |
99b0dace5fcf71584d1456b4b5408017b896bdf5
|
https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileInputStream.php#L81-L95
|
25,619
|
stubbles/stubbles-streams
|
src/main/php/file/FileInputStream.php
|
FileInputStream.getResourceLength
|
protected function getResourceLength(): int
{
if (null === $this->fileName) {
return parent::getResourceLength();
}
if (substr($this->fileName, 0, 16) === 'compress.zlib://') {
return filesize(substr($this->fileName, 16));
} elseif (substr($this->fileName, 0, 17) === 'compress.bzip2://') {
return filesize(substr($this->fileName, 17));
}
return parent::getResourceLength();
}
|
php
|
protected function getResourceLength(): int
{
if (null === $this->fileName) {
return parent::getResourceLength();
}
if (substr($this->fileName, 0, 16) === 'compress.zlib://') {
return filesize(substr($this->fileName, 16));
} elseif (substr($this->fileName, 0, 17) === 'compress.bzip2://') {
return filesize(substr($this->fileName, 17));
}
return parent::getResourceLength();
}
|
[
"protected",
"function",
"getResourceLength",
"(",
")",
":",
"int",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"fileName",
")",
"{",
"return",
"parent",
"::",
"getResourceLength",
"(",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"fileName",
",",
"0",
",",
"16",
")",
"===",
"'compress.zlib://'",
")",
"{",
"return",
"filesize",
"(",
"substr",
"(",
"$",
"this",
"->",
"fileName",
",",
"16",
")",
")",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"this",
"->",
"fileName",
",",
"0",
",",
"17",
")",
"===",
"'compress.bzip2://'",
")",
"{",
"return",
"filesize",
"(",
"substr",
"(",
"$",
"this",
"->",
"fileName",
",",
"17",
")",
")",
";",
"}",
"return",
"parent",
"::",
"getResourceLength",
"(",
")",
";",
"}"
] |
helper method to retrieve the length of the resource
@return int
|
[
"helper",
"method",
"to",
"retrieve",
"the",
"length",
"of",
"the",
"resource"
] |
99b0dace5fcf71584d1456b4b5408017b896bdf5
|
https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileInputStream.php#L102-L115
|
25,620
|
stubbles/stubbles-streams
|
src/main/php/file/FileInputStream.php
|
FileInputStream.tell
|
public function tell(): int
{
if (null === $this->handle) {
throw new \LogicException('Can not read from closed input stream.');
}
$position = @ftell($this->handle);
if (false === $position) {
throw new StreamException(
'Can not read current position in file: '
. lastErrorMessage('unknown error')
);
}
return $position;
}
|
php
|
public function tell(): int
{
if (null === $this->handle) {
throw new \LogicException('Can not read from closed input stream.');
}
$position = @ftell($this->handle);
if (false === $position) {
throw new StreamException(
'Can not read current position in file: '
. lastErrorMessage('unknown error')
);
}
return $position;
}
|
[
"public",
"function",
"tell",
"(",
")",
":",
"int",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"handle",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Can not read from closed input stream.'",
")",
";",
"}",
"$",
"position",
"=",
"@",
"ftell",
"(",
"$",
"this",
"->",
"handle",
")",
";",
"if",
"(",
"false",
"===",
"$",
"position",
")",
"{",
"throw",
"new",
"StreamException",
"(",
"'Can not read current position in file: '",
".",
"lastErrorMessage",
"(",
"'unknown error'",
")",
")",
";",
"}",
"return",
"$",
"position",
";",
"}"
] |
return current position
@return int
@throws \LogicException
@throws \stubbles\streams\StreamException
|
[
"return",
"current",
"position"
] |
99b0dace5fcf71584d1456b4b5408017b896bdf5
|
https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileInputStream.php#L140-L155
|
25,621
|
afroware/jwtauth
|
src/Http/Middleware/BaseMiddleware.php
|
BaseMiddleware.checkForToken
|
public function checkForToken(Request $request)
{
if (! $this->auth->parser()->setRequest($request)->hasToken()) {
throw new UnauthorizedHttpException('jwTauth', 'Token not provided');
}
}
|
php
|
public function checkForToken(Request $request)
{
if (! $this->auth->parser()->setRequest($request)->hasToken()) {
throw new UnauthorizedHttpException('jwTauth', 'Token not provided');
}
}
|
[
"public",
"function",
"checkForToken",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"auth",
"->",
"parser",
"(",
")",
"->",
"setRequest",
"(",
"$",
"request",
")",
"->",
"hasToken",
"(",
")",
")",
"{",
"throw",
"new",
"UnauthorizedHttpException",
"(",
"'jwTauth'",
",",
"'Token not provided'",
")",
";",
"}",
"}"
] |
Check the request for the presence of a token.
@param \Illuminate\Http\Request $request
@throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
@return void
|
[
"Check",
"the",
"request",
"for",
"the",
"presence",
"of",
"a",
"token",
"."
] |
54a0aebd811d87bfdd2b3668696fd53f50490cc1
|
https://github.com/afroware/jwtauth/blob/54a0aebd811d87bfdd2b3668696fd53f50490cc1/src/Http/Middleware/BaseMiddleware.php#L49-L54
|
25,622
|
Danack/Weaver
|
src/Weaver/ImplementWeaveGenerator.php
|
ImplementWeaveGenerator.addDecoratedMethod
|
function addDecoratedMethod(MethodReflection $sourceMethod, MethodReflection $decoratorMethodReflection ) {
$weavedMethod = MethodGenerator::fromReflection($sourceMethod);
$newBody = $decoratorMethodReflection->getBody();
$newBody = trimBody($newBody);
$parameters = $sourceMethod->getParameters();
$paramArray = [];
$searchArray = [];
$count = 0;
foreach ($parameters as $parameter) {
$searchArray[] = '$param'.$count;
$paramArray[] = '$'.$parameter->getName();
}
$paramList = implode(', ', $paramArray);
$newBody = str_replace(
'$this->__prototype()',
'$this->weavedInstance->'.$sourceMethod->getName()."($paramList)",
$newBody
);
$newBody = str_replace($searchArray, $paramArray, $newBody);
$weavedMethod->setBody($newBody);
$this->generator->addMethodFromGenerator($weavedMethod);
}
|
php
|
function addDecoratedMethod(MethodReflection $sourceMethod, MethodReflection $decoratorMethodReflection ) {
$weavedMethod = MethodGenerator::fromReflection($sourceMethod);
$newBody = $decoratorMethodReflection->getBody();
$newBody = trimBody($newBody);
$parameters = $sourceMethod->getParameters();
$paramArray = [];
$searchArray = [];
$count = 0;
foreach ($parameters as $parameter) {
$searchArray[] = '$param'.$count;
$paramArray[] = '$'.$parameter->getName();
}
$paramList = implode(', ', $paramArray);
$newBody = str_replace(
'$this->__prototype()',
'$this->weavedInstance->'.$sourceMethod->getName()."($paramList)",
$newBody
);
$newBody = str_replace($searchArray, $paramArray, $newBody);
$weavedMethod->setBody($newBody);
$this->generator->addMethodFromGenerator($weavedMethod);
}
|
[
"function",
"addDecoratedMethod",
"(",
"MethodReflection",
"$",
"sourceMethod",
",",
"MethodReflection",
"$",
"decoratorMethodReflection",
")",
"{",
"$",
"weavedMethod",
"=",
"MethodGenerator",
"::",
"fromReflection",
"(",
"$",
"sourceMethod",
")",
";",
"$",
"newBody",
"=",
"$",
"decoratorMethodReflection",
"->",
"getBody",
"(",
")",
";",
"$",
"newBody",
"=",
"trimBody",
"(",
"$",
"newBody",
")",
";",
"$",
"parameters",
"=",
"$",
"sourceMethod",
"->",
"getParameters",
"(",
")",
";",
"$",
"paramArray",
"=",
"[",
"]",
";",
"$",
"searchArray",
"=",
"[",
"]",
";",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"$",
"searchArray",
"[",
"]",
"=",
"'$param'",
".",
"$",
"count",
";",
"$",
"paramArray",
"[",
"]",
"=",
"'$'",
".",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"paramList",
"=",
"implode",
"(",
"', '",
",",
"$",
"paramArray",
")",
";",
"$",
"newBody",
"=",
"str_replace",
"(",
"'$this->__prototype()'",
",",
"'$this->weavedInstance->'",
".",
"$",
"sourceMethod",
"->",
"getName",
"(",
")",
".",
"\"($paramList)\"",
",",
"$",
"newBody",
")",
";",
"$",
"newBody",
"=",
"str_replace",
"(",
"$",
"searchArray",
",",
"$",
"paramArray",
",",
"$",
"newBody",
")",
";",
"$",
"weavedMethod",
"->",
"setBody",
"(",
"$",
"newBody",
")",
";",
"$",
"this",
"->",
"generator",
"->",
"addMethodFromGenerator",
"(",
"$",
"weavedMethod",
")",
";",
"}"
] |
Decorate the method and call the instance.
@param MethodReflection $sourceMethod
@param MethodReflection $decoratorMethodReflection
|
[
"Decorate",
"the",
"method",
"and",
"call",
"the",
"instance",
"."
] |
414894cd397daff22d2c71e4988784a1f71b702e
|
https://github.com/Danack/Weaver/blob/414894cd397daff22d2c71e4988784a1f71b702e/src/Weaver/ImplementWeaveGenerator.php#L112-L140
|
25,623
|
Danack/Weaver
|
src/Weaver/ImplementWeaveGenerator.php
|
ImplementWeaveGenerator.addPlainMethod
|
function addPlainMethod(MethodReflection $sourceMethod) {
$parameters = $sourceMethod->getParameters();
$paramArray = [];
foreach ($parameters as $parameter) {
$paramArray[] = '$'.$parameter->getName();
}
$paramList = implode(', ', $paramArray);
$weavedMethod = MethodGenerator::fromReflection($sourceMethod);
$body = sprintf(
" return \$this->%s->%s(%s);",
$this->implementWeaveInfo->getInstancePropertyName(),
$sourceMethod->getName(),
$paramList
);
$weavedMethod->setBody($body);
$this->generator->addMethodFromGenerator($weavedMethod);
}
|
php
|
function addPlainMethod(MethodReflection $sourceMethod) {
$parameters = $sourceMethod->getParameters();
$paramArray = [];
foreach ($parameters as $parameter) {
$paramArray[] = '$'.$parameter->getName();
}
$paramList = implode(', ', $paramArray);
$weavedMethod = MethodGenerator::fromReflection($sourceMethod);
$body = sprintf(
" return \$this->%s->%s(%s);",
$this->implementWeaveInfo->getInstancePropertyName(),
$sourceMethod->getName(),
$paramList
);
$weavedMethod->setBody($body);
$this->generator->addMethodFromGenerator($weavedMethod);
}
|
[
"function",
"addPlainMethod",
"(",
"MethodReflection",
"$",
"sourceMethod",
")",
"{",
"$",
"parameters",
"=",
"$",
"sourceMethod",
"->",
"getParameters",
"(",
")",
";",
"$",
"paramArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"$",
"paramArray",
"[",
"]",
"=",
"'$'",
".",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"paramList",
"=",
"implode",
"(",
"', '",
",",
"$",
"paramArray",
")",
";",
"$",
"weavedMethod",
"=",
"MethodGenerator",
"::",
"fromReflection",
"(",
"$",
"sourceMethod",
")",
";",
"$",
"body",
"=",
"sprintf",
"(",
"\" return \\$this->%s->%s(%s);\"",
",",
"$",
"this",
"->",
"implementWeaveInfo",
"->",
"getInstancePropertyName",
"(",
")",
",",
"$",
"sourceMethod",
"->",
"getName",
"(",
")",
",",
"$",
"paramList",
")",
";",
"$",
"weavedMethod",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"$",
"this",
"->",
"generator",
"->",
"addMethodFromGenerator",
"(",
"$",
"weavedMethod",
")",
";",
"}"
] |
Add a call to the instance method.
@param MethodReflection $sourceMethod
|
[
"Add",
"a",
"call",
"to",
"the",
"instance",
"method",
"."
] |
414894cd397daff22d2c71e4988784a1f71b702e
|
https://github.com/Danack/Weaver/blob/414894cd397daff22d2c71e4988784a1f71b702e/src/Weaver/ImplementWeaveGenerator.php#L147-L168
|
25,624
|
Danack/Weaver
|
src/Weaver/ImplementWeaveGenerator.php
|
ImplementWeaveGenerator.addSourceMethods
|
function addSourceMethods() {
$methodBindingArray = $this->implementWeaveInfo->getMethodBindingArray();
$methods = $this->sourceClassReflection->getMethods();
foreach ($methods as $sourceMethod) {
if ($sourceMethod->getName() === '__construct') {
continue;
}
$methodBindingToApply = null;
foreach ($methodBindingArray as $methodBinding) {
if ($methodBinding->matchesMethod($sourceMethod->getName()) ) {
$methodBindingToApply = $methodBinding;
break;
}
}
if ($methodBindingToApply != null) {
$decoratorMethod = $methodBindingToApply->getMethod();
$decoratorMethodReflection = $this->decoratorReflection->getMethod($decoratorMethod);
$this->addDecoratedMethod($sourceMethod, $decoratorMethodReflection);
}
else {
$this->addPlainMethod($sourceMethod);
}
}
}
|
php
|
function addSourceMethods() {
$methodBindingArray = $this->implementWeaveInfo->getMethodBindingArray();
$methods = $this->sourceClassReflection->getMethods();
foreach ($methods as $sourceMethod) {
if ($sourceMethod->getName() === '__construct') {
continue;
}
$methodBindingToApply = null;
foreach ($methodBindingArray as $methodBinding) {
if ($methodBinding->matchesMethod($sourceMethod->getName()) ) {
$methodBindingToApply = $methodBinding;
break;
}
}
if ($methodBindingToApply != null) {
$decoratorMethod = $methodBindingToApply->getMethod();
$decoratorMethodReflection = $this->decoratorReflection->getMethod($decoratorMethod);
$this->addDecoratedMethod($sourceMethod, $decoratorMethodReflection);
}
else {
$this->addPlainMethod($sourceMethod);
}
}
}
|
[
"function",
"addSourceMethods",
"(",
")",
"{",
"$",
"methodBindingArray",
"=",
"$",
"this",
"->",
"implementWeaveInfo",
"->",
"getMethodBindingArray",
"(",
")",
";",
"$",
"methods",
"=",
"$",
"this",
"->",
"sourceClassReflection",
"->",
"getMethods",
"(",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"sourceMethod",
")",
"{",
"if",
"(",
"$",
"sourceMethod",
"->",
"getName",
"(",
")",
"===",
"'__construct'",
")",
"{",
"continue",
";",
"}",
"$",
"methodBindingToApply",
"=",
"null",
";",
"foreach",
"(",
"$",
"methodBindingArray",
"as",
"$",
"methodBinding",
")",
"{",
"if",
"(",
"$",
"methodBinding",
"->",
"matchesMethod",
"(",
"$",
"sourceMethod",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"methodBindingToApply",
"=",
"$",
"methodBinding",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"methodBindingToApply",
"!=",
"null",
")",
"{",
"$",
"decoratorMethod",
"=",
"$",
"methodBindingToApply",
"->",
"getMethod",
"(",
")",
";",
"$",
"decoratorMethodReflection",
"=",
"$",
"this",
"->",
"decoratorReflection",
"->",
"getMethod",
"(",
"$",
"decoratorMethod",
")",
";",
"$",
"this",
"->",
"addDecoratedMethod",
"(",
"$",
"sourceMethod",
",",
"$",
"decoratorMethodReflection",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addPlainMethod",
"(",
"$",
"sourceMethod",
")",
";",
"}",
"}",
"}"
] |
For all of the methods in that need to be decorated, generate the decorated version
and all the to the generator.
@TODO Shouldn't this only implement the methods in the interface that is being exposed?
|
[
"For",
"all",
"of",
"the",
"methods",
"in",
"that",
"need",
"to",
"be",
"decorated",
"generate",
"the",
"decorated",
"version",
"and",
"all",
"the",
"to",
"the",
"generator",
"."
] |
414894cd397daff22d2c71e4988784a1f71b702e
|
https://github.com/Danack/Weaver/blob/414894cd397daff22d2c71e4988784a1f71b702e/src/Weaver/ImplementWeaveGenerator.php#L175-L201
|
25,625
|
drdplusinfo/drdplus-background
|
DrdPlus/Background/BackgroundParts/Partials/AbstractBackgroundAdvantage.php
|
AbstractBackgroundAdvantage.getSpentBackgroundPoints
|
public function getSpentBackgroundPoints(): PositiveIntegerObject
{
if ($this->spentBackgroundPoints === null) {
$this->spentBackgroundPoints = new PositiveIntegerObject($this->getValue());
}
return $this->spentBackgroundPoints;
}
|
php
|
public function getSpentBackgroundPoints(): PositiveIntegerObject
{
if ($this->spentBackgroundPoints === null) {
$this->spentBackgroundPoints = new PositiveIntegerObject($this->getValue());
}
return $this->spentBackgroundPoints;
}
|
[
"public",
"function",
"getSpentBackgroundPoints",
"(",
")",
":",
"PositiveIntegerObject",
"{",
"if",
"(",
"$",
"this",
"->",
"spentBackgroundPoints",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"spentBackgroundPoints",
"=",
"new",
"PositiveIntegerObject",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"spentBackgroundPoints",
";",
"}"
] |
Spent background points are the same as advantage level.
@return PositiveIntegerObject
|
[
"Spent",
"background",
"points",
"are",
"the",
"same",
"as",
"advantage",
"level",
"."
] |
70aca51902e6c151c4b0e5d9066c6043c777435c
|
https://github.com/drdplusinfo/drdplus-background/blob/70aca51902e6c151c4b0e5d9066c6043c777435c/DrdPlus/Background/BackgroundParts/Partials/AbstractBackgroundAdvantage.php#L31-L38
|
25,626
|
wasinger/adaptimage
|
src/ResponsiveImages/ResponsiveImageHelper.php
|
ResponsiveImageHelper.addClass
|
public function addClass(ResponsiveImageClass $class)
{
$this->classes_added = true;
if (array_key_exists($class->getName(), $this->classes)) {
throw new \Exception(sprintf('A responsive image class with name "%s" is already registered', $class->getName()));
}
if ($this->default_filters instanceof FilterInterface) {
$class->addFilter($this->default_filters);
}
if ($this->default_post_filters instanceof FilterInterface) {
$class->addPostFilter($this->default_post_filters);
}
if ($this->default_scaling_algorithm != '') {
$class->setScaleAlgorithm($this->default_scaling_algorithm);
}
if ($this->default_output_type_map instanceof OutputTypeMap) {
$class->setOutputTypeMap($this->default_output_type_map);
}
$this->classes[$class->getName()] = $class;
}
|
php
|
public function addClass(ResponsiveImageClass $class)
{
$this->classes_added = true;
if (array_key_exists($class->getName(), $this->classes)) {
throw new \Exception(sprintf('A responsive image class with name "%s" is already registered', $class->getName()));
}
if ($this->default_filters instanceof FilterInterface) {
$class->addFilter($this->default_filters);
}
if ($this->default_post_filters instanceof FilterInterface) {
$class->addPostFilter($this->default_post_filters);
}
if ($this->default_scaling_algorithm != '') {
$class->setScaleAlgorithm($this->default_scaling_algorithm);
}
if ($this->default_output_type_map instanceof OutputTypeMap) {
$class->setOutputTypeMap($this->default_output_type_map);
}
$this->classes[$class->getName()] = $class;
}
|
[
"public",
"function",
"addClass",
"(",
"ResponsiveImageClass",
"$",
"class",
")",
"{",
"$",
"this",
"->",
"classes_added",
"=",
"true",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"classes",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'A responsive image class with name \"%s\" is already registered'",
",",
"$",
"class",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"default_filters",
"instanceof",
"FilterInterface",
")",
"{",
"$",
"class",
"->",
"addFilter",
"(",
"$",
"this",
"->",
"default_filters",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"default_post_filters",
"instanceof",
"FilterInterface",
")",
"{",
"$",
"class",
"->",
"addPostFilter",
"(",
"$",
"this",
"->",
"default_post_filters",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"default_scaling_algorithm",
"!=",
"''",
")",
"{",
"$",
"class",
"->",
"setScaleAlgorithm",
"(",
"$",
"this",
"->",
"default_scaling_algorithm",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"default_output_type_map",
"instanceof",
"OutputTypeMap",
")",
"{",
"$",
"class",
"->",
"setOutputTypeMap",
"(",
"$",
"this",
"->",
"default_output_type_map",
")",
";",
"}",
"$",
"this",
"->",
"classes",
"[",
"$",
"class",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"class",
";",
"}"
] |
Add a ResponsiveImageClass object to the registered responsive image classes
@param ResponsiveImageClass $class The ResponsiveImageClass object
@throws \Exception
|
[
"Add",
"a",
"ResponsiveImageClass",
"object",
"to",
"the",
"registered",
"responsive",
"image",
"classes"
] |
7b529b25081b399451c8bbd56d0cef7daaa83ec4
|
https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L102-L121
|
25,627
|
wasinger/adaptimage
|
src/ResponsiveImages/ResponsiveImageHelper.php
|
ResponsiveImageHelper.getClass
|
public function getClass($classname)
{
if ((string) $classname == '' || !array_key_exists($classname, $this->classes)) {
throw new ImageClassNotRegisteredException($classname);
}
return $this->classes[$classname];
}
|
php
|
public function getClass($classname)
{
if ((string) $classname == '' || !array_key_exists($classname, $this->classes)) {
throw new ImageClassNotRegisteredException($classname);
}
return $this->classes[$classname];
}
|
[
"public",
"function",
"getClass",
"(",
"$",
"classname",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"classname",
"==",
"''",
"||",
"!",
"array_key_exists",
"(",
"$",
"classname",
",",
"$",
"this",
"->",
"classes",
")",
")",
"{",
"throw",
"new",
"ImageClassNotRegisteredException",
"(",
"$",
"classname",
")",
";",
"}",
"return",
"$",
"this",
"->",
"classes",
"[",
"$",
"classname",
"]",
";",
"}"
] |
Get a ResponsiveImageClass by it's name
@param string $classname
@return ResponsiveImageClass
|
[
"Get",
"a",
"ResponsiveImageClass",
"by",
"it",
"s",
"name"
] |
7b529b25081b399451c8bbd56d0cef7daaa83ec4
|
https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L140-L146
|
25,628
|
wasinger/adaptimage
|
src/ResponsiveImages/ResponsiveImageHelper.php
|
ResponsiveImageHelper.makeImgElementResponsive
|
public function makeImgElementResponsive(
\DOMElement &$img,
$class,
$change_src_attr = false,
$add_default_dimension_attrs = false
)
{
if ($img->tagName != 'img') throw new \InvalidArgumentException('$img must be an "img" element');
if ((string) $class == '' || !array_key_exists($class, $this->classes)) {
throw new ImageClassNotRegisteredException($class);
}
$imageurl = $img->getAttribute('src');
if ($imageurl != '') {
try {
$ri = $this->getResponsiveImage($imageurl, $class);
$img->setAttribute('srcset', $ri->getSrcsetAttributeValue());
$img->setAttribute('sizes', $ri->getSizesAttributeValue());
$default = $ri->getDefaultImageInfo();
if ($default instanceof WebImageInfo) {
if ($change_src_attr) {
$img->setAttribute('src', $default->getUrl());
}
if ($add_default_dimension_attrs) {
$img->setAttribute('width', $default->getWidth());
$img->setAttribute('height', $default->getHeight());
}
}
} catch (\Exception $e) {
};
}
}
|
php
|
public function makeImgElementResponsive(
\DOMElement &$img,
$class,
$change_src_attr = false,
$add_default_dimension_attrs = false
)
{
if ($img->tagName != 'img') throw new \InvalidArgumentException('$img must be an "img" element');
if ((string) $class == '' || !array_key_exists($class, $this->classes)) {
throw new ImageClassNotRegisteredException($class);
}
$imageurl = $img->getAttribute('src');
if ($imageurl != '') {
try {
$ri = $this->getResponsiveImage($imageurl, $class);
$img->setAttribute('srcset', $ri->getSrcsetAttributeValue());
$img->setAttribute('sizes', $ri->getSizesAttributeValue());
$default = $ri->getDefaultImageInfo();
if ($default instanceof WebImageInfo) {
if ($change_src_attr) {
$img->setAttribute('src', $default->getUrl());
}
if ($add_default_dimension_attrs) {
$img->setAttribute('width', $default->getWidth());
$img->setAttribute('height', $default->getHeight());
}
}
} catch (\Exception $e) {
};
}
}
|
[
"public",
"function",
"makeImgElementResponsive",
"(",
"\\",
"DOMElement",
"&",
"$",
"img",
",",
"$",
"class",
",",
"$",
"change_src_attr",
"=",
"false",
",",
"$",
"add_default_dimension_attrs",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"img",
"->",
"tagName",
"!=",
"'img'",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$img must be an \"img\" element'",
")",
";",
"if",
"(",
"(",
"string",
")",
"$",
"class",
"==",
"''",
"||",
"!",
"array_key_exists",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"classes",
")",
")",
"{",
"throw",
"new",
"ImageClassNotRegisteredException",
"(",
"$",
"class",
")",
";",
"}",
"$",
"imageurl",
"=",
"$",
"img",
"->",
"getAttribute",
"(",
"'src'",
")",
";",
"if",
"(",
"$",
"imageurl",
"!=",
"''",
")",
"{",
"try",
"{",
"$",
"ri",
"=",
"$",
"this",
"->",
"getResponsiveImage",
"(",
"$",
"imageurl",
",",
"$",
"class",
")",
";",
"$",
"img",
"->",
"setAttribute",
"(",
"'srcset'",
",",
"$",
"ri",
"->",
"getSrcsetAttributeValue",
"(",
")",
")",
";",
"$",
"img",
"->",
"setAttribute",
"(",
"'sizes'",
",",
"$",
"ri",
"->",
"getSizesAttributeValue",
"(",
")",
")",
";",
"$",
"default",
"=",
"$",
"ri",
"->",
"getDefaultImageInfo",
"(",
")",
";",
"if",
"(",
"$",
"default",
"instanceof",
"WebImageInfo",
")",
"{",
"if",
"(",
"$",
"change_src_attr",
")",
"{",
"$",
"img",
"->",
"setAttribute",
"(",
"'src'",
",",
"$",
"default",
"->",
"getUrl",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"add_default_dimension_attrs",
")",
"{",
"$",
"img",
"->",
"setAttribute",
"(",
"'width'",
",",
"$",
"default",
"->",
"getWidth",
"(",
")",
")",
";",
"$",
"img",
"->",
"setAttribute",
"(",
"'height'",
",",
"$",
"default",
"->",
"getHeight",
"(",
")",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
";",
"}",
"}"
] |
Add srcset and sizes attributes to an HTML "img" tag
This method reads the image URL from the "src" attribute of an "img" element, calculates the URLs and dimensions of
the various available image sizes according to the given "responsive image class", and adds the "srcset" and
"sizes" attribute value.
Optionally, it can change the "src" attribute value to the URL of the default image size, and set the
"width" and "height" attributes for the default image size.
N.B. The URL given in the "src" attribute of the img element must be in a form the
ResponsiveImageRouterInterface object $this->router is able to convert to a local file path.
If the conversion fails, the method fails silently, i.e. the img element will not be changed.
@param \DOMElement $img The "img" HTML element
@param string $class The name of an "responsive image class" registered via addClass()
@param bool $change_src_attr If true, set "src" attribute to the URL of the default image size
@param bool $add_default_dimension_attrs If true, add "width" and "height" attributes for the default image size
@throws \InvalidArgumentException If the DOMElement provided as $img parameter is not an "img" element
@throws ImageClassNotRegisteredException If the $class parameter is not a registerd image class name
@API
|
[
"Add",
"srcset",
"and",
"sizes",
"attributes",
"to",
"an",
"HTML",
"img",
"tag"
] |
7b529b25081b399451c8bbd56d0cef7daaa83ec4
|
https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L170-L200
|
25,629
|
wasinger/adaptimage
|
src/ResponsiveImages/ResponsiveImageHelper.php
|
ResponsiveImageHelper.createResizedImageVersions
|
public function createResizedImageVersions($imageurl, $imageclass)
{
if (!$this->resizer instanceof ImageResizer) {
throw new \LogicException('no ImageResizer available, set it using ResponsiveImageHelper::setResizer()');
}
$image = $this->getResponsiveImage($imageurl, $imageclass);
$image->createResizedVersions($this->resizer);
}
|
php
|
public function createResizedImageVersions($imageurl, $imageclass)
{
if (!$this->resizer instanceof ImageResizer) {
throw new \LogicException('no ImageResizer available, set it using ResponsiveImageHelper::setResizer()');
}
$image = $this->getResponsiveImage($imageurl, $imageclass);
$image->createResizedVersions($this->resizer);
}
|
[
"public",
"function",
"createResizedImageVersions",
"(",
"$",
"imageurl",
",",
"$",
"imageclass",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"resizer",
"instanceof",
"ImageResizer",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'no ImageResizer available, set it using ResponsiveImageHelper::setResizer()'",
")",
";",
"}",
"$",
"image",
"=",
"$",
"this",
"->",
"getResponsiveImage",
"(",
"$",
"imageurl",
",",
"$",
"imageclass",
")",
";",
"$",
"image",
"->",
"createResizedVersions",
"(",
"$",
"this",
"->",
"resizer",
")",
";",
"}"
] |
Create the resized image versions for an image and a given image class
@param string $imageurl
@param string $imageclass
@throws \Exception
|
[
"Create",
"the",
"resized",
"image",
"versions",
"for",
"an",
"image",
"and",
"a",
"given",
"image",
"class"
] |
7b529b25081b399451c8bbd56d0cef7daaa83ec4
|
https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L263-L270
|
25,630
|
Dhii/exception-helper-base
|
src/CreateExceptionCapableTrait.php
|
CreateExceptionCapableTrait._createException
|
protected function _createException($message = null, $code = null, $previous = null)
{
return new Exception($message, $code, $previous);
}
|
php
|
protected function _createException($message = null, $code = null, $previous = null)
{
return new Exception($message, $code, $previous);
}
|
[
"protected",
"function",
"_createException",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"code",
"=",
"null",
",",
"$",
"previous",
"=",
"null",
")",
"{",
"return",
"new",
"Exception",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
")",
";",
"}"
] |
Creates a new basic Dhii exception.
@since [*next-version*]
@param string|Stringable|int|float|bool|null $message The message, if any.
@param int|float|string|Stringable|null $code The numeric error code, if any.
@param RootException|null $previous The inner exception, if any.
@return ThrowableInterface The new exception.
|
[
"Creates",
"a",
"new",
"basic",
"Dhii",
"exception",
"."
] |
e97bfa6c0f79ea079e36b2f1d8f84d7566a3ccf5
|
https://github.com/Dhii/exception-helper-base/blob/e97bfa6c0f79ea079e36b2f1d8f84d7566a3ccf5/src/CreateExceptionCapableTrait.php#L26-L29
|
25,631
|
Mandarin-Medien/MMCmfContentBundle
|
EventListeners/PageHookListener.php
|
PageHookListener.postLoad
|
public function postLoad(Page $page, LifecycleEventArgs $args)
{
$hookManager = $this->container->get('mm_cmf_content.page_hook_manager');
foreach($hookManager->getHooks() as $hook) {
$hook->process($page, $this->container->get('request_stack')->getCurrentRequest());
};
}
|
php
|
public function postLoad(Page $page, LifecycleEventArgs $args)
{
$hookManager = $this->container->get('mm_cmf_content.page_hook_manager');
foreach($hookManager->getHooks() as $hook) {
$hook->process($page, $this->container->get('request_stack')->getCurrentRequest());
};
}
|
[
"public",
"function",
"postLoad",
"(",
"Page",
"$",
"page",
",",
"LifecycleEventArgs",
"$",
"args",
")",
"{",
"$",
"hookManager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'mm_cmf_content.page_hook_manager'",
")",
";",
"foreach",
"(",
"$",
"hookManager",
"->",
"getHooks",
"(",
")",
"as",
"$",
"hook",
")",
"{",
"$",
"hook",
"->",
"process",
"(",
"$",
"page",
",",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'request_stack'",
")",
"->",
"getCurrentRequest",
"(",
")",
")",
";",
"}",
";",
"}"
] |
postLoad Callback for Page entity, gets all defined PageHooks and calls it
@param Page $page
@param LifecycleEventArgs $args
|
[
"postLoad",
"Callback",
"for",
"Page",
"entity",
"gets",
"all",
"defined",
"PageHooks",
"and",
"calls",
"it"
] |
503ab31cef3ce068f767de5b72f833526355b726
|
https://github.com/Mandarin-Medien/MMCmfContentBundle/blob/503ab31cef3ce068f767de5b72f833526355b726/EventListeners/PageHookListener.php#L42-L49
|
25,632
|
eureka-framework/component-notification
|
src/Notification/NotificationBootstrap.php
|
NotificationBootstrap.getCss
|
public function getCss()
{
switch ($this->type) {
case self::TYPE_ERROR:
$css = 'danger';
break;
case self::TYPE_WARNING:
$css = 'warning';
break;
case self::TYPE_INFO:
$css = 'info';
break;
case self::TYPE_SUCCESS:
$css = 'success';
break;
default:
$css = 'info';
break;
}
return $css;
}
|
php
|
public function getCss()
{
switch ($this->type) {
case self::TYPE_ERROR:
$css = 'danger';
break;
case self::TYPE_WARNING:
$css = 'warning';
break;
case self::TYPE_INFO:
$css = 'info';
break;
case self::TYPE_SUCCESS:
$css = 'success';
break;
default:
$css = 'info';
break;
}
return $css;
}
|
[
"public",
"function",
"getCss",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_ERROR",
":",
"$",
"css",
"=",
"'danger'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_WARNING",
":",
"$",
"css",
"=",
"'warning'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_INFO",
":",
"$",
"css",
"=",
"'info'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_SUCCESS",
":",
"$",
"css",
"=",
"'success'",
";",
"break",
";",
"default",
":",
"$",
"css",
"=",
"'info'",
";",
"break",
";",
"}",
"return",
"$",
"css",
";",
"}"
] |
Get css used.
@return string
|
[
"Get",
"css",
"used",
"."
] |
346c2932cf4ebdbae651aae513ac350df8f8c33a
|
https://github.com/eureka-framework/component-notification/blob/346c2932cf4ebdbae651aae513ac350df8f8c33a/src/Notification/NotificationBootstrap.php#L24-L45
|
25,633
|
eureka-framework/component-notification
|
src/Notification/NotificationBootstrap.php
|
NotificationBootstrap.getHeader
|
public function getHeader()
{
switch ($this->type) {
case self::TYPE_ERROR:
$header = 'Error!';
break;
case self::TYPE_WARNING:
$header = 'Warning!';
break;
case self::TYPE_INFO:
$header = 'Info';
break;
case self::TYPE_SUCCESS:
$header = 'Success';
break;
default:
$header = 'Info';
break;
}
return $header;
}
|
php
|
public function getHeader()
{
switch ($this->type) {
case self::TYPE_ERROR:
$header = 'Error!';
break;
case self::TYPE_WARNING:
$header = 'Warning!';
break;
case self::TYPE_INFO:
$header = 'Info';
break;
case self::TYPE_SUCCESS:
$header = 'Success';
break;
default:
$header = 'Info';
break;
}
return $header;
}
|
[
"public",
"function",
"getHeader",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_ERROR",
":",
"$",
"header",
"=",
"'Error!'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_WARNING",
":",
"$",
"header",
"=",
"'Warning!'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_INFO",
":",
"$",
"header",
"=",
"'Info'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_SUCCESS",
":",
"$",
"header",
"=",
"'Success'",
";",
"break",
";",
"default",
":",
"$",
"header",
"=",
"'Info'",
";",
"break",
";",
"}",
"return",
"$",
"header",
";",
"}"
] |
Get header title.
@return string
|
[
"Get",
"header",
"title",
"."
] |
346c2932cf4ebdbae651aae513ac350df8f8c33a
|
https://github.com/eureka-framework/component-notification/blob/346c2932cf4ebdbae651aae513ac350df8f8c33a/src/Notification/NotificationBootstrap.php#L52-L73
|
25,634
|
AnonymPHP/Anonym-Route
|
Matchers/NewMatcher.php
|
NewMatcher.match
|
public function match($url = null)
{
$match = parent::match($url);
$find = $this->replaceParameters();
if (false !== $find || true === $match) {
return true;
} else {
return false;
}
}
|
php
|
public function match($url = null)
{
$match = parent::match($url);
$find = $this->replaceParameters();
if (false !== $find || true === $match) {
return true;
} else {
return false;
}
}
|
[
"public",
"function",
"match",
"(",
"$",
"url",
"=",
"null",
")",
"{",
"$",
"match",
"=",
"parent",
"::",
"match",
"(",
"$",
"url",
")",
";",
"$",
"find",
"=",
"$",
"this",
"->",
"replaceParameters",
"(",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"find",
"||",
"true",
"===",
"$",
"match",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
make the match
@param string|null $url
@return bool
|
[
"make",
"the",
"match"
] |
bb7f8004fbbd2998af8b0061f404f026f11466ab
|
https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Matchers/NewMatcher.php#L51-L62
|
25,635
|
AnonymPHP/Anonym-Route
|
Matchers/NewMatcher.php
|
NewMatcher.resolvePregCallback
|
private function resolvePregCallback($finded)
{
$matchEx = explode(' ', $this->getMatchUrl());
$requestEx = explode(' ', $this->getRequestedUrl());
$key = array_search($finded[0], $matchEx);
$cln = $finded[1];
if (strstr($cln, ':')) {
list($cln, $filter) = explode(':', $cln);
}
if (!strstr($cln, '?')) {
$add = isset($requestEx[$key]) && $requestEx[$key] !== '' ? $requestEx[$key] : false;
} else {
$add = isset($requestEx[$key]) ? $requestEx[$key] : null;
}
if($add !== null){
// we gonna do run filter now
if (!$this->runFilter(isset($filter) ? $filter : $cln, $add)) {
throw new FilterMatchException('Your filter do not match');
}
}
$this->parameters[$cln] = $add;
}
|
php
|
private function resolvePregCallback($finded)
{
$matchEx = explode(' ', $this->getMatchUrl());
$requestEx = explode(' ', $this->getRequestedUrl());
$key = array_search($finded[0], $matchEx);
$cln = $finded[1];
if (strstr($cln, ':')) {
list($cln, $filter) = explode(':', $cln);
}
if (!strstr($cln, '?')) {
$add = isset($requestEx[$key]) && $requestEx[$key] !== '' ? $requestEx[$key] : false;
} else {
$add = isset($requestEx[$key]) ? $requestEx[$key] : null;
}
if($add !== null){
// we gonna do run filter now
if (!$this->runFilter(isset($filter) ? $filter : $cln, $add)) {
throw new FilterMatchException('Your filter do not match');
}
}
$this->parameters[$cln] = $add;
}
|
[
"private",
"function",
"resolvePregCallback",
"(",
"$",
"finded",
")",
"{",
"$",
"matchEx",
"=",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"getMatchUrl",
"(",
")",
")",
";",
"$",
"requestEx",
"=",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"getRequestedUrl",
"(",
")",
")",
";",
"$",
"key",
"=",
"array_search",
"(",
"$",
"finded",
"[",
"0",
"]",
",",
"$",
"matchEx",
")",
";",
"$",
"cln",
"=",
"$",
"finded",
"[",
"1",
"]",
";",
"if",
"(",
"strstr",
"(",
"$",
"cln",
",",
"':'",
")",
")",
"{",
"list",
"(",
"$",
"cln",
",",
"$",
"filter",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"cln",
")",
";",
"}",
"if",
"(",
"!",
"strstr",
"(",
"$",
"cln",
",",
"'?'",
")",
")",
"{",
"$",
"add",
"=",
"isset",
"(",
"$",
"requestEx",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"requestEx",
"[",
"$",
"key",
"]",
"!==",
"''",
"?",
"$",
"requestEx",
"[",
"$",
"key",
"]",
":",
"false",
";",
"}",
"else",
"{",
"$",
"add",
"=",
"isset",
"(",
"$",
"requestEx",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"requestEx",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}",
"if",
"(",
"$",
"add",
"!==",
"null",
")",
"{",
"// we gonna do run filter now",
"if",
"(",
"!",
"$",
"this",
"->",
"runFilter",
"(",
"isset",
"(",
"$",
"filter",
")",
"?",
"$",
"filter",
":",
"$",
"cln",
",",
"$",
"add",
")",
")",
"{",
"throw",
"new",
"FilterMatchException",
"(",
"'Your filter do not match'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"parameters",
"[",
"$",
"cln",
"]",
"=",
"$",
"add",
";",
"}"
] |
resolve the preg callback
@param array $finded
@return bool|string
|
[
"resolve",
"the",
"preg",
"callback"
] |
bb7f8004fbbd2998af8b0061f404f026f11466ab
|
https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Matchers/NewMatcher.php#L99-L125
|
25,636
|
AnonymPHP/Anonym-Route
|
Matchers/NewMatcher.php
|
NewMatcher.runFilter
|
private function runFilter($filter, $parameter)
{
if (!strstr($filter, '(') && !strstr($filter, ')')) {
if (!$filter = $this->getFilter($filter)) {
return false;
}
}
return preg_match('@' . $filter . '@si', $parameter) ?: false;
}
|
php
|
private function runFilter($filter, $parameter)
{
if (!strstr($filter, '(') && !strstr($filter, ')')) {
if (!$filter = $this->getFilter($filter)) {
return false;
}
}
return preg_match('@' . $filter . '@si', $parameter) ?: false;
}
|
[
"private",
"function",
"runFilter",
"(",
"$",
"filter",
",",
"$",
"parameter",
")",
"{",
"if",
"(",
"!",
"strstr",
"(",
"$",
"filter",
",",
"'('",
")",
"&&",
"!",
"strstr",
"(",
"$",
"filter",
",",
"')'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilter",
"(",
"$",
"filter",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"preg_match",
"(",
"'@'",
".",
"$",
"filter",
".",
"'@si'",
",",
"$",
"parameter",
")",
"?",
":",
"false",
";",
"}"
] |
execute a filter
@param string $filter
@param string $parameter
@return bool|int
|
[
"execute",
"a",
"filter"
] |
bb7f8004fbbd2998af8b0061f404f026f11466ab
|
https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Matchers/NewMatcher.php#L134-L143
|
25,637
|
bseries/base_tag
|
models/Tags.php
|
Tags.depend
|
public function depend($entity, $type) {
$depend = $type === 'count' ? 0 : [];
foreach (static::_dependent() as $model) {
$results = $model::find($type, [
'conditions' => [
'tags' => $entity->name
]
]);
if (!$results) {
continue;
}
if ($type === 'count') {
$depend += $results;
} else {
foreach ($results as $result) {
$depend[] = $result;
}
}
}
return $depend;
}
|
php
|
public function depend($entity, $type) {
$depend = $type === 'count' ? 0 : [];
foreach (static::_dependent() as $model) {
$results = $model::find($type, [
'conditions' => [
'tags' => $entity->name
]
]);
if (!$results) {
continue;
}
if ($type === 'count') {
$depend += $results;
} else {
foreach ($results as $result) {
$depend[] = $result;
}
}
}
return $depend;
}
|
[
"public",
"function",
"depend",
"(",
"$",
"entity",
",",
"$",
"type",
")",
"{",
"$",
"depend",
"=",
"$",
"type",
"===",
"'count'",
"?",
"0",
":",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"_dependent",
"(",
")",
"as",
"$",
"model",
")",
"{",
"$",
"results",
"=",
"$",
"model",
"::",
"find",
"(",
"$",
"type",
",",
"[",
"'conditions'",
"=>",
"[",
"'tags'",
"=>",
"$",
"entity",
"->",
"name",
"]",
"]",
")",
";",
"if",
"(",
"!",
"$",
"results",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"'count'",
")",
"{",
"$",
"depend",
"+=",
"$",
"results",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"depend",
"[",
"]",
"=",
"$",
"result",
";",
"}",
"}",
"}",
"return",
"$",
"depend",
";",
"}"
] |
Do not use in performance criticial parts.
|
[
"Do",
"not",
"use",
"in",
"performance",
"criticial",
"parts",
"."
] |
b66e817ac8268813790677fed259d8904b6dbb92
|
https://github.com/bseries/base_tag/blob/b66e817ac8268813790677fed259d8904b6dbb92/models/Tags.php#L79-L100
|
25,638
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.reset
|
public function reset()
{
$this->table = '';
$this->columns = [];
$this->joins = [];
$this->wheres = [];
$this->whereIn = [];
$this->groupBy = false;
$this->orderBy = false;
$this->offset = 0;
$this->limit = 10;
$this->fields = [];
return $this;
}
|
php
|
public function reset()
{
$this->table = '';
$this->columns = [];
$this->joins = [];
$this->wheres = [];
$this->whereIn = [];
$this->groupBy = false;
$this->orderBy = false;
$this->offset = 0;
$this->limit = 10;
$this->fields = [];
return $this;
}
|
[
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"table",
"=",
"''",
";",
"$",
"this",
"->",
"columns",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"joins",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"wheres",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"whereIn",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"groupBy",
"=",
"false",
";",
"$",
"this",
"->",
"orderBy",
"=",
"false",
";",
"$",
"this",
"->",
"offset",
"=",
"0",
";",
"$",
"this",
"->",
"limit",
"=",
"10",
";",
"$",
"this",
"->",
"fields",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Reset to default values
@return object Database instance
|
[
"Reset",
"to",
"default",
"values"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L101-L114
|
25,639
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.select
|
public function select($columns)
{
if (is_array($columns)) {
$this->columns = $columns;
} elseif ($columns === '*') {
$this->columns = ['*'];
}
return $this;
}
|
php
|
public function select($columns)
{
if (is_array($columns)) {
$this->columns = $columns;
} elseif ($columns === '*') {
$this->columns = ['*'];
}
return $this;
}
|
[
"public",
"function",
"select",
"(",
"$",
"columns",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"this",
"->",
"columns",
"=",
"$",
"columns",
";",
"}",
"elseif",
"(",
"$",
"columns",
"===",
"'*'",
")",
"{",
"$",
"this",
"->",
"columns",
"=",
"[",
"'*'",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the columns to be selected
@param array $columns Columns to select
@return object Database instance
|
[
"Sets",
"the",
"columns",
"to",
"be",
"selected"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L122-L130
|
25,640
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.join
|
public function join($table, $first, $operator, $second, $type = 'LEFT')
{
$this->joins[] = [
'table' => $table,
'first' => $first,
'operator' => $operator,
'second' => $second,
'type' => $type
];
return $this;
}
|
php
|
public function join($table, $first, $operator, $second, $type = 'LEFT')
{
$this->joins[] = [
'table' => $table,
'first' => $first,
'operator' => $operator,
'second' => $second,
'type' => $type
];
return $this;
}
|
[
"public",
"function",
"join",
"(",
"$",
"table",
",",
"$",
"first",
",",
"$",
"operator",
",",
"$",
"second",
",",
"$",
"type",
"=",
"'LEFT'",
")",
"{",
"$",
"this",
"->",
"joins",
"[",
"]",
"=",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'first'",
"=>",
"$",
"first",
",",
"'operator'",
"=>",
"$",
"operator",
",",
"'second'",
"=>",
"$",
"second",
",",
"'type'",
"=>",
"$",
"type",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets a table to JOIN with
@param string $table Table name
@param string $first Left key for the ON condition
@param string $operator Operator for the ON condition
@param string $second Right key for the ON condition
@param string $type Join type
@return object Database instance
|
[
"Sets",
"a",
"table",
"to",
"JOIN",
"with"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L169-L179
|
25,641
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.where
|
public function where($column, $value, $operator = '=', $table = null)
{
$table = $table? $table : $this->table;
$this->wheres[] = [
'table' => $table,
'column' => $column,
'value' => $value,
'operator' => $operator
];
return $this;
}
|
php
|
public function where($column, $value, $operator = '=', $table = null)
{
$table = $table? $table : $this->table;
$this->wheres[] = [
'table' => $table,
'column' => $column,
'value' => $value,
'operator' => $operator
];
return $this;
}
|
[
"public",
"function",
"where",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"operator",
"=",
"'='",
",",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"table",
"=",
"$",
"table",
"?",
"$",
"table",
":",
"$",
"this",
"->",
"table",
";",
"$",
"this",
"->",
"wheres",
"[",
"]",
"=",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'column'",
"=>",
"$",
"column",
",",
"'value'",
"=>",
"$",
"value",
",",
"'operator'",
"=>",
"$",
"operator",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets a WHERE condition
@param string $column Column name
@param string $value Value to match
@param string $operator Operator to compare with
@param string $table Table
@return object Database instance
|
[
"Sets",
"a",
"WHERE",
"condition"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L190-L200
|
25,642
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.whereIn
|
public function whereIn($column, $values, $table = null)
{
$table = isset($table)? $table : $this->table;
$this->whereIn[] = [
'table' => $table,
'column' => $column,
'values' => $values
];
return $this;
}
|
php
|
public function whereIn($column, $values, $table = null)
{
$table = isset($table)? $table : $this->table;
$this->whereIn[] = [
'table' => $table,
'column' => $column,
'values' => $values
];
return $this;
}
|
[
"public",
"function",
"whereIn",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"table",
"=",
"isset",
"(",
"$",
"table",
")",
"?",
"$",
"table",
":",
"$",
"this",
"->",
"table",
";",
"$",
"this",
"->",
"whereIn",
"[",
"]",
"=",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'column'",
"=>",
"$",
"column",
",",
"'values'",
"=>",
"$",
"values",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets a WHERE IN condition
@param string $column Column name
@param string $values Values to match
@param string $table Table
@return object Database instance
|
[
"Sets",
"a",
"WHERE",
"IN",
"condition"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L210-L219
|
25,643
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.get
|
public function get()
{
// Define columns
$columns = count($this->columns)? $this->getColumnsString() : $this->table . '.*';
// Define root
$root = 'SELECT ' . $columns . ' FROM ' . $this->table;
// Define joins
$joins = count($this->joins)? $this->getJoinString() : '';
// Define where conditions
$where = $this->getWhereString();
// Define where in conditions
$whereIn = $this->getWhereInString();
// Define group by
$groupBy = ($this->groupBy)? 'GROUP BY ' . $this->groupBy : '';
// Define order
$orderBy = ($this->orderBy)? $this->getOrderByString() : '';
// Define limit
$limit = 'LIMIT ' . $this->offset . ',' . $this->limit;
// Build query
$this->query = implode(' ', [$root, $joins, $where, $whereIn, $groupBy, $orderBy, $limit]);
// Debug
if ($this->app->config('queries.log')) {
file_put_contents($this->app->config('queries.log'), date('Y-m-d h:i:s') . ' - ' . $this->query . "\r\n", FILE_APPEND);
}
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
if (!$this->statement->execute()) {
throw new \PDOException('Error reading from database', 500);
}
// Return results
$result = $this->statement->fetchAll(\PDO::FETCH_ASSOC);
// Reset
$this->reset();
// Return result
return $result;
}
|
php
|
public function get()
{
// Define columns
$columns = count($this->columns)? $this->getColumnsString() : $this->table . '.*';
// Define root
$root = 'SELECT ' . $columns . ' FROM ' . $this->table;
// Define joins
$joins = count($this->joins)? $this->getJoinString() : '';
// Define where conditions
$where = $this->getWhereString();
// Define where in conditions
$whereIn = $this->getWhereInString();
// Define group by
$groupBy = ($this->groupBy)? 'GROUP BY ' . $this->groupBy : '';
// Define order
$orderBy = ($this->orderBy)? $this->getOrderByString() : '';
// Define limit
$limit = 'LIMIT ' . $this->offset . ',' . $this->limit;
// Build query
$this->query = implode(' ', [$root, $joins, $where, $whereIn, $groupBy, $orderBy, $limit]);
// Debug
if ($this->app->config('queries.log')) {
file_put_contents($this->app->config('queries.log'), date('Y-m-d h:i:s') . ' - ' . $this->query . "\r\n", FILE_APPEND);
}
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
if (!$this->statement->execute()) {
throw new \PDOException('Error reading from database', 500);
}
// Return results
$result = $this->statement->fetchAll(\PDO::FETCH_ASSOC);
// Reset
$this->reset();
// Return result
return $result;
}
|
[
"public",
"function",
"get",
"(",
")",
"{",
"// Define columns",
"$",
"columns",
"=",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
"?",
"$",
"this",
"->",
"getColumnsString",
"(",
")",
":",
"$",
"this",
"->",
"table",
".",
"'.*'",
";",
"// Define root",
"$",
"root",
"=",
"'SELECT '",
".",
"$",
"columns",
".",
"' FROM '",
".",
"$",
"this",
"->",
"table",
";",
"// Define joins",
"$",
"joins",
"=",
"count",
"(",
"$",
"this",
"->",
"joins",
")",
"?",
"$",
"this",
"->",
"getJoinString",
"(",
")",
":",
"''",
";",
"// Define where conditions",
"$",
"where",
"=",
"$",
"this",
"->",
"getWhereString",
"(",
")",
";",
"// Define where in conditions",
"$",
"whereIn",
"=",
"$",
"this",
"->",
"getWhereInString",
"(",
")",
";",
"// Define group by",
"$",
"groupBy",
"=",
"(",
"$",
"this",
"->",
"groupBy",
")",
"?",
"'GROUP BY '",
".",
"$",
"this",
"->",
"groupBy",
":",
"''",
";",
"// Define order",
"$",
"orderBy",
"=",
"(",
"$",
"this",
"->",
"orderBy",
")",
"?",
"$",
"this",
"->",
"getOrderByString",
"(",
")",
":",
"''",
";",
"// Define limit",
"$",
"limit",
"=",
"'LIMIT '",
".",
"$",
"this",
"->",
"offset",
".",
"','",
".",
"$",
"this",
"->",
"limit",
";",
"// Build query",
"$",
"this",
"->",
"query",
"=",
"implode",
"(",
"' '",
",",
"[",
"$",
"root",
",",
"$",
"joins",
",",
"$",
"where",
",",
"$",
"whereIn",
",",
"$",
"groupBy",
",",
"$",
"orderBy",
",",
"$",
"limit",
"]",
")",
";",
"// Debug",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'queries.log'",
")",
")",
"{",
"file_put_contents",
"(",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'queries.log'",
")",
",",
"date",
"(",
"'Y-m-d h:i:s'",
")",
".",
"' - '",
".",
"$",
"this",
"->",
"query",
".",
"\"\\r\\n\"",
",",
"FILE_APPEND",
")",
";",
"}",
"// Prepare statement",
"$",
"this",
"->",
"statement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"this",
"->",
"query",
")",
";",
"// Bind where values",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
")",
"{",
"$",
"this",
"->",
"bindWheres",
"(",
")",
";",
"}",
"// Execute statement",
"if",
"(",
"!",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"PDOException",
"(",
"'Error reading from database'",
",",
"500",
")",
";",
"}",
"// Return results",
"$",
"result",
"=",
"$",
"this",
"->",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"// Reset",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Return result",
"return",
"$",
"result",
";",
"}"
] |
Performs a SELECT query
@return bool|array Array of results, or false
|
[
"Performs",
"a",
"SELECT",
"query"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L290-L345
|
25,644
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.count
|
public function count($column)
{
// Set a really hight limit
$this->limit(pow(100, 3));
// Select only the COUNT column and get
$result = $this->select(['COUNT(' . $this->table . '.' . $column .') as count'])->get();
// Reset
$this->reset();
// Return number of records
return (count($result) === 1)? (int) reset($result)['count'] : count($result);
}
|
php
|
public function count($column)
{
// Set a really hight limit
$this->limit(pow(100, 3));
// Select only the COUNT column and get
$result = $this->select(['COUNT(' . $this->table . '.' . $column .') as count'])->get();
// Reset
$this->reset();
// Return number of records
return (count($result) === 1)? (int) reset($result)['count'] : count($result);
}
|
[
"public",
"function",
"count",
"(",
"$",
"column",
")",
"{",
"// Set a really hight limit",
"$",
"this",
"->",
"limit",
"(",
"pow",
"(",
"100",
",",
"3",
")",
")",
";",
"// Select only the COUNT column and get",
"$",
"result",
"=",
"$",
"this",
"->",
"select",
"(",
"[",
"'COUNT('",
".",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"column",
".",
"') as count'",
"]",
")",
"->",
"get",
"(",
")",
";",
"// Reset",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Return number of records",
"return",
"(",
"count",
"(",
"$",
"result",
")",
"===",
"1",
")",
"?",
"(",
"int",
")",
"reset",
"(",
"$",
"result",
")",
"[",
"'count'",
"]",
":",
"count",
"(",
"$",
"result",
")",
";",
"}"
] |
Performs a SELECT COUNT query
@param string $column Column to count by
@return int Number of rows matching the SELECT query
|
[
"Performs",
"a",
"SELECT",
"COUNT",
"query"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L367-L380
|
25,645
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.update
|
public function update($fields)
{
// Set fields
$this->fields($fields);
// Resolve fields
$fields = $this->getUpdateFieldsString();
// Define wheres
$where = $this->getWhereString();
// Build query
$this->query = 'UPDATE ' . $this->table . ' SET ' . $fields . ' '. $where;
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind fields values
$this->bindFields();
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
$result = $this->statement->execute();
// Reset values
$this->reset();
// Return result
return $result;
}
|
php
|
public function update($fields)
{
// Set fields
$this->fields($fields);
// Resolve fields
$fields = $this->getUpdateFieldsString();
// Define wheres
$where = $this->getWhereString();
// Build query
$this->query = 'UPDATE ' . $this->table . ' SET ' . $fields . ' '. $where;
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind fields values
$this->bindFields();
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
$result = $this->statement->execute();
// Reset values
$this->reset();
// Return result
return $result;
}
|
[
"public",
"function",
"update",
"(",
"$",
"fields",
")",
"{",
"// Set fields",
"$",
"this",
"->",
"fields",
"(",
"$",
"fields",
")",
";",
"// Resolve fields",
"$",
"fields",
"=",
"$",
"this",
"->",
"getUpdateFieldsString",
"(",
")",
";",
"// Define wheres",
"$",
"where",
"=",
"$",
"this",
"->",
"getWhereString",
"(",
")",
";",
"// Build query",
"$",
"this",
"->",
"query",
"=",
"'UPDATE '",
".",
"$",
"this",
"->",
"table",
".",
"' SET '",
".",
"$",
"fields",
".",
"' '",
".",
"$",
"where",
";",
"// Prepare statement",
"$",
"this",
"->",
"statement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"this",
"->",
"query",
")",
";",
"// Bind fields values",
"$",
"this",
"->",
"bindFields",
"(",
")",
";",
"// Bind where values",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
")",
"{",
"$",
"this",
"->",
"bindWheres",
"(",
")",
";",
"}",
"// Execute statement",
"$",
"result",
"=",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
")",
";",
"// Reset values",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Return result",
"return",
"$",
"result",
";",
"}"
] |
Performs an UPDATE query
@param array $fields Array of columns names and values to insert
@return bool Query success or fail
|
[
"Performs",
"an",
"UPDATE",
"query"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L438-L471
|
25,646
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.getWhereString
|
private function getWhereString()
{
// If there are not where conditions, return empty
if (!count($this->wheres)) {
return 'WHERE 1=1 ';
}
// Create where named placeholders
$wheres = array_map(function ($where) {
return $where['table'] . '.' . $where['column'] . ' ' . $where['operator'] . ' :' . $where['table'] . $where['column'];
}, $this->wheres);
// String holder
return 'WHERE 1 AND ' . implode(' AND ', $wheres);
}
|
php
|
private function getWhereString()
{
// If there are not where conditions, return empty
if (!count($this->wheres)) {
return 'WHERE 1=1 ';
}
// Create where named placeholders
$wheres = array_map(function ($where) {
return $where['table'] . '.' . $where['column'] . ' ' . $where['operator'] . ' :' . $where['table'] . $where['column'];
}, $this->wheres);
// String holder
return 'WHERE 1 AND ' . implode(' AND ', $wheres);
}
|
[
"private",
"function",
"getWhereString",
"(",
")",
"{",
"// If there are not where conditions, return empty",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
")",
"{",
"return",
"'WHERE 1=1 '",
";",
"}",
"// Create where named placeholders",
"$",
"wheres",
"=",
"array_map",
"(",
"function",
"(",
"$",
"where",
")",
"{",
"return",
"$",
"where",
"[",
"'table'",
"]",
".",
"'.'",
".",
"$",
"where",
"[",
"'column'",
"]",
".",
"' '",
".",
"$",
"where",
"[",
"'operator'",
"]",
".",
"' :'",
".",
"$",
"where",
"[",
"'table'",
"]",
".",
"$",
"where",
"[",
"'column'",
"]",
";",
"}",
",",
"$",
"this",
"->",
"wheres",
")",
";",
"// String holder",
"return",
"'WHERE 1 AND '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"wheres",
")",
";",
"}"
] |
Returns the wheres array as a WHERE string
@return string WHERE string
|
[
"Returns",
"the",
"wheres",
"array",
"as",
"a",
"WHERE",
"string"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L542-L556
|
25,647
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.getWhereInString
|
private function getWhereInString()
{
// String holder
$string = '';
// If there are not where in conditions, return empty
if (!count($this->whereIn)) {
return $string;
}
// Iterate where creating the full conditions
foreach ($this->whereIn as $where) {
$string .= ' AND ' . $where['column'] . ' IN (' . implode(', ', $where['values']) . ')';
}
// Return complete where in string
return $string;
}
|
php
|
private function getWhereInString()
{
// String holder
$string = '';
// If there are not where in conditions, return empty
if (!count($this->whereIn)) {
return $string;
}
// Iterate where creating the full conditions
foreach ($this->whereIn as $where) {
$string .= ' AND ' . $where['column'] . ' IN (' . implode(', ', $where['values']) . ')';
}
// Return complete where in string
return $string;
}
|
[
"private",
"function",
"getWhereInString",
"(",
")",
"{",
"// String holder",
"$",
"string",
"=",
"''",
";",
"// If there are not where in conditions, return empty",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"whereIn",
")",
")",
"{",
"return",
"$",
"string",
";",
"}",
"// Iterate where creating the full conditions",
"foreach",
"(",
"$",
"this",
"->",
"whereIn",
"as",
"$",
"where",
")",
"{",
"$",
"string",
".=",
"' AND '",
".",
"$",
"where",
"[",
"'column'",
"]",
".",
"' IN ('",
".",
"implode",
"(",
"', '",
",",
"$",
"where",
"[",
"'values'",
"]",
")",
".",
"')'",
";",
"}",
"// Return complete where in string",
"return",
"$",
"string",
";",
"}"
] |
Returns the where in array as a WHERE IN string
@return string WHERE string
|
[
"Returns",
"the",
"where",
"in",
"array",
"as",
"a",
"WHERE",
"IN",
"string"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L563-L580
|
25,648
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.getColumnsString
|
private function getColumnsString()
{
if (count($this->columns) === 1 && $this->columns[0] === '*') {
return '*';
}
$columns = array_map(function ($column) {
return (strpos($column, '.') === false)? $this->table . '.' . $column : $column;
}, $this->columns);
return implode(', ', $columns);
}
|
php
|
private function getColumnsString()
{
if (count($this->columns) === 1 && $this->columns[0] === '*') {
return '*';
}
$columns = array_map(function ($column) {
return (strpos($column, '.') === false)? $this->table . '.' . $column : $column;
}, $this->columns);
return implode(', ', $columns);
}
|
[
"private",
"function",
"getColumnsString",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
"===",
"1",
"&&",
"$",
"this",
"->",
"columns",
"[",
"0",
"]",
"===",
"'*'",
")",
"{",
"return",
"'*'",
";",
"}",
"$",
"columns",
"=",
"array_map",
"(",
"function",
"(",
"$",
"column",
")",
"{",
"return",
"(",
"strpos",
"(",
"$",
"column",
",",
"'.'",
")",
"===",
"false",
")",
"?",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"column",
":",
"$",
"column",
";",
"}",
",",
"$",
"this",
"->",
"columns",
")",
";",
"return",
"implode",
"(",
"', '",
",",
"$",
"columns",
")",
";",
"}"
] |
Returns the columns array as a field list string
@return string Field list string
|
[
"Returns",
"the",
"columns",
"array",
"as",
"a",
"field",
"list",
"string"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L587-L596
|
25,649
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.getJoinString
|
private function getJoinString()
{
// If there are not joins, return empty
if (!count($this->orderBy)) {
return '';
}
// Create join strings
$joins = array_map(function ($join) {
return $join['type'] . ' JOIN ' . $join['table'] . ' ON ' . $this->table . '.' . $join['first'] . $join['operator'] . $join['table'] . '.' . $join['second'];
}, $this->joins);
// Return complete join string
return implode(' ', $joins);
}
|
php
|
private function getJoinString()
{
// If there are not joins, return empty
if (!count($this->orderBy)) {
return '';
}
// Create join strings
$joins = array_map(function ($join) {
return $join['type'] . ' JOIN ' . $join['table'] . ' ON ' . $this->table . '.' . $join['first'] . $join['operator'] . $join['table'] . '.' . $join['second'];
}, $this->joins);
// Return complete join string
return implode(' ', $joins);
}
|
[
"private",
"function",
"getJoinString",
"(",
")",
"{",
"// If there are not joins, return empty",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"orderBy",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Create join strings",
"$",
"joins",
"=",
"array_map",
"(",
"function",
"(",
"$",
"join",
")",
"{",
"return",
"$",
"join",
"[",
"'type'",
"]",
".",
"' JOIN '",
".",
"$",
"join",
"[",
"'table'",
"]",
".",
"' ON '",
".",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"join",
"[",
"'first'",
"]",
".",
"$",
"join",
"[",
"'operator'",
"]",
".",
"$",
"join",
"[",
"'table'",
"]",
".",
"'.'",
".",
"$",
"join",
"[",
"'second'",
"]",
";",
"}",
",",
"$",
"this",
"->",
"joins",
")",
";",
"// Return complete join string",
"return",
"implode",
"(",
"' '",
",",
"$",
"joins",
")",
";",
"}"
] |
Returns the joins array as a JOIN string
@return string JOIN string
|
[
"Returns",
"the",
"joins",
"array",
"as",
"a",
"JOIN",
"string"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L603-L617
|
25,650
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.getInsertFieldsString
|
private function getInsertFieldsString()
{
// Get field keys
$fieldKeys = array_keys($this->fields);
// Create placeholders
$fieldsPlaceholders = array_map(function ($field) {
return ':' . $field;
}, $fieldKeys);
// Return complete fields string
return '(' . implode(',', $fieldKeys) . ') VALUES ('. implode(',', $fieldsPlaceholders) . ')';
}
|
php
|
private function getInsertFieldsString()
{
// Get field keys
$fieldKeys = array_keys($this->fields);
// Create placeholders
$fieldsPlaceholders = array_map(function ($field) {
return ':' . $field;
}, $fieldKeys);
// Return complete fields string
return '(' . implode(',', $fieldKeys) . ') VALUES ('. implode(',', $fieldsPlaceholders) . ')';
}
|
[
"private",
"function",
"getInsertFieldsString",
"(",
")",
"{",
"// Get field keys",
"$",
"fieldKeys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"fields",
")",
";",
"// Create placeholders",
"$",
"fieldsPlaceholders",
"=",
"array_map",
"(",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"':'",
".",
"$",
"field",
";",
"}",
",",
"$",
"fieldKeys",
")",
";",
"// Return complete fields string",
"return",
"'('",
".",
"implode",
"(",
"','",
",",
"$",
"fieldKeys",
")",
".",
"') VALUES ('",
".",
"implode",
"(",
"','",
",",
"$",
"fieldsPlaceholders",
")",
".",
"')'",
";",
"}"
] |
Returns the fields array as a VALUES string for inserts
@return string VALUES string for inserts
|
[
"Returns",
"the",
"fields",
"array",
"as",
"a",
"VALUES",
"string",
"for",
"inserts"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L640-L652
|
25,651
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.bindWheres
|
private function bindWheres()
{
foreach ($this->wheres as $where) {
$this->statement->bindValue(':' . $where['table'] . $where['column'], $where['value']);
}
}
|
php
|
private function bindWheres()
{
foreach ($this->wheres as $where) {
$this->statement->bindValue(':' . $where['table'] . $where['column'], $where['value']);
}
}
|
[
"private",
"function",
"bindWheres",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"wheres",
"as",
"$",
"where",
")",
"{",
"$",
"this",
"->",
"statement",
"->",
"bindValue",
"(",
"':'",
".",
"$",
"where",
"[",
"'table'",
"]",
".",
"$",
"where",
"[",
"'column'",
"]",
",",
"$",
"where",
"[",
"'value'",
"]",
")",
";",
"}",
"}"
] |
Binds the values of the WHERE conditions
|
[
"Binds",
"the",
"values",
"of",
"the",
"WHERE",
"conditions"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L674-L679
|
25,652
|
nicodevs/laito
|
src/Laito/Database.php
|
Database.bindFields
|
private function bindFields()
{
foreach ($this->fields as $key => $value) {
$this->statement->bindValue(':' . $key, $value);
}
}
|
php
|
private function bindFields()
{
foreach ($this->fields as $key => $value) {
$this->statement->bindValue(':' . $key, $value);
}
}
|
[
"private",
"function",
"bindFields",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"statement",
"->",
"bindValue",
"(",
"':'",
".",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] |
Binds the values of the fields to insert or update
|
[
"Binds",
"the",
"values",
"of",
"the",
"fields",
"to",
"insert",
"or",
"update"
] |
d2d28abfcbf981c4decfec28ce94f8849600e9fe
|
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L685-L690
|
25,653
|
Hnto/nuki
|
src/Handlers/Http/Files.php
|
Files.file
|
public function file($key) {
if (!isset($this->files[$key])) {
return null;
}
return $this->createFile($this->files[$key]);
}
|
php
|
public function file($key) {
if (!isset($this->files[$key])) {
return null;
}
return $this->createFile($this->files[$key]);
}
|
[
"public",
"function",
"file",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"files",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"createFile",
"(",
"$",
"this",
"->",
"files",
"[",
"$",
"key",
"]",
")",
";",
"}"
] |
Get file by key
@param int $key
@return \Nuki\Models\Data\File
|
[
"Get",
"file",
"by",
"key"
] |
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
|
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Http/Files.php#L31-L37
|
25,654
|
Hnto/nuki
|
src/Handlers/Http/Files.php
|
Files.createFile
|
private function createFile(array $fileInfo = []) {
$file = new \Nuki\Models\Data\File($fileInfo['tmp_name'], $fileInfo['size']);
$file->setExtension(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
$file->setName(pathinfo($fileInfo['name'], PATHINFO_BASENAME));
return $file;
}
|
php
|
private function createFile(array $fileInfo = []) {
$file = new \Nuki\Models\Data\File($fileInfo['tmp_name'], $fileInfo['size']);
$file->setExtension(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
$file->setName(pathinfo($fileInfo['name'], PATHINFO_BASENAME));
return $file;
}
|
[
"private",
"function",
"createFile",
"(",
"array",
"$",
"fileInfo",
"=",
"[",
"]",
")",
"{",
"$",
"file",
"=",
"new",
"\\",
"Nuki",
"\\",
"Models",
"\\",
"Data",
"\\",
"File",
"(",
"$",
"fileInfo",
"[",
"'tmp_name'",
"]",
",",
"$",
"fileInfo",
"[",
"'size'",
"]",
")",
";",
"$",
"file",
"->",
"setExtension",
"(",
"pathinfo",
"(",
"$",
"fileInfo",
"[",
"'name'",
"]",
",",
"PATHINFO_EXTENSION",
")",
")",
";",
"$",
"file",
"->",
"setName",
"(",
"pathinfo",
"(",
"$",
"fileInfo",
"[",
"'name'",
"]",
",",
"PATHINFO_BASENAME",
")",
")",
";",
"return",
"$",
"file",
";",
"}"
] |
Create file object
@param array $fileInfo
@return \Nuki\Models\Data\File
|
[
"Create",
"file",
"object"
] |
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
|
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Http/Files.php#L61-L68
|
25,655
|
stubbles/stubbles-streams
|
src/main/php/file/FileOutputStream.php
|
FileOutputStream.openFile
|
protected function openFile(string $file, string $mode)
{
$fp = @fopen($file, $mode);
if (false === $fp) {
throw new StreamException(
'Can not open file ' . $file . ' with mode ' . $mode . ': '
.
str_replace('fopen(' . $file . '): ', '', lastErrorMessage())
);
}
return $fp;
}
|
php
|
protected function openFile(string $file, string $mode)
{
$fp = @fopen($file, $mode);
if (false === $fp) {
throw new StreamException(
'Can not open file ' . $file . ' with mode ' . $mode . ': '
.
str_replace('fopen(' . $file . '): ', '', lastErrorMessage())
);
}
return $fp;
}
|
[
"protected",
"function",
"openFile",
"(",
"string",
"$",
"file",
",",
"string",
"$",
"mode",
")",
"{",
"$",
"fp",
"=",
"@",
"fopen",
"(",
"$",
"file",
",",
"$",
"mode",
")",
";",
"if",
"(",
"false",
"===",
"$",
"fp",
")",
"{",
"throw",
"new",
"StreamException",
"(",
"'Can not open file '",
".",
"$",
"file",
".",
"' with mode '",
".",
"$",
"mode",
".",
"': '",
".",
"str_replace",
"(",
"'fopen('",
".",
"$",
"file",
".",
"'): '",
",",
"''",
",",
"lastErrorMessage",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"fp",
";",
"}"
] |
helper method to open a file handle
@param string $file
@param string $mode
@return resource
@throws \stubbles\streams\StreamException
|
[
"helper",
"method",
"to",
"open",
"a",
"file",
"handle"
] |
99b0dace5fcf71584d1456b4b5408017b896bdf5
|
https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileOutputStream.php#L108-L120
|
25,656
|
leogitpro/php-zf3-base-module
|
module/src/Controller/BaseController.php
|
BaseController.addData
|
protected function addData($key, $data = null)
{
$this->data[self::RS_KEY_DATA]->{$key} = $data;
}
|
php
|
protected function addData($key, $data = null)
{
$this->data[self::RS_KEY_DATA]->{$key} = $data;
}
|
[
"protected",
"function",
"addData",
"(",
"$",
"key",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"self",
"::",
"RS_KEY_DATA",
"]",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"data",
";",
"}"
] |
Add data to result object
@param string $key
@param null|string|array|\stdClass $data
|
[
"Add",
"data",
"to",
"result",
"object"
] |
596fc89c25033eaef8f796418a4a3399c47a9638
|
https://github.com/leogitpro/php-zf3-base-module/blob/596fc89c25033eaef8f796418a4a3399c47a9638/module/src/Controller/BaseController.php#L87-L90
|
25,657
|
loevgaard/dandomain-foundation-entities
|
src/Entity/Product.php
|
Product.findPriceByCurrency
|
public function findPriceByCurrency($currency): ?PriceInterface
{
if ($currency instanceof \Money\Currency) {
$currency = $currency->getCode();
} elseif ($currency instanceof CurrencyInterface) {
$currency = $currency->getIsoCodeAlpha();
}
if (!is_string($currency)) {
throw new \InvalidArgumentException('$currency has to be a string');
}
foreach ($this->prices as $price) {
if ($price->getCurrency()->getIsoCodeAlpha() === $currency) {
return $price;
}
}
return null;
}
|
php
|
public function findPriceByCurrency($currency): ?PriceInterface
{
if ($currency instanceof \Money\Currency) {
$currency = $currency->getCode();
} elseif ($currency instanceof CurrencyInterface) {
$currency = $currency->getIsoCodeAlpha();
}
if (!is_string($currency)) {
throw new \InvalidArgumentException('$currency has to be a string');
}
foreach ($this->prices as $price) {
if ($price->getCurrency()->getIsoCodeAlpha() === $currency) {
return $price;
}
}
return null;
}
|
[
"public",
"function",
"findPriceByCurrency",
"(",
"$",
"currency",
")",
":",
"?",
"PriceInterface",
"{",
"if",
"(",
"$",
"currency",
"instanceof",
"\\",
"Money",
"\\",
"Currency",
")",
"{",
"$",
"currency",
"=",
"$",
"currency",
"->",
"getCode",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"currency",
"instanceof",
"CurrencyInterface",
")",
"{",
"$",
"currency",
"=",
"$",
"currency",
"->",
"getIsoCodeAlpha",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"currency",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$currency has to be a string'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"prices",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getIsoCodeAlpha",
"(",
")",
"===",
"$",
"currency",
")",
"{",
"return",
"$",
"price",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Will try to find a price based on currency.
@param string|\Money\Currency|CurrencyInterface $currency
@return PriceInterface|null
|
[
"Will",
"try",
"to",
"find",
"a",
"price",
"based",
"on",
"currency",
"."
] |
256f7aa8b40d2bd9488046c3c2b1e04e982d78ad
|
https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L669-L688
|
25,658
|
loevgaard/dandomain-foundation-entities
|
src/Entity/Product.php
|
Product.findPrice
|
protected function findPrice(PriceInterface $searchPrice): ?PriceInterface
{
foreach ($this->prices as $price) {
if ($price->getAmount() == $searchPrice->getAmount() && $price->getB2bGroupId() == $searchPrice->getB2bGroupId() && $price->getCurrency()->getId() == $searchPrice->getCurrency()->getId()) {
return $price;
}
}
return null;
}
|
php
|
protected function findPrice(PriceInterface $searchPrice): ?PriceInterface
{
foreach ($this->prices as $price) {
if ($price->getAmount() == $searchPrice->getAmount() && $price->getB2bGroupId() == $searchPrice->getB2bGroupId() && $price->getCurrency()->getId() == $searchPrice->getCurrency()->getId()) {
return $price;
}
}
return null;
}
|
[
"protected",
"function",
"findPrice",
"(",
"PriceInterface",
"$",
"searchPrice",
")",
":",
"?",
"PriceInterface",
"{",
"foreach",
"(",
"$",
"this",
"->",
"prices",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getAmount",
"(",
")",
"==",
"$",
"searchPrice",
"->",
"getAmount",
"(",
")",
"&&",
"$",
"price",
"->",
"getB2bGroupId",
"(",
")",
"==",
"$",
"searchPrice",
"->",
"getB2bGroupId",
"(",
")",
"&&",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"$",
"searchPrice",
"->",
"getCurrency",
"(",
")",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"$",
"price",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
This method will try to find a price based on the unique constraint defined in price.
@param PriceInterface $searchPrice
@return PriceInterface|null
|
[
"This",
"method",
"will",
"try",
"to",
"find",
"a",
"price",
"based",
"on",
"the",
"unique",
"constraint",
"defined",
"in",
"price",
"."
] |
256f7aa8b40d2bd9488046c3c2b1e04e982d78ad
|
https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L1756-L1765
|
25,659
|
helikopterspark/FlashMsg
|
src/FlashMsg/FlashMsg.php
|
FlashMsg.setMessage
|
public function setMessage($type, $message) {
if (!$this->session->has('flashmsgs')) {
$this->session->set('flashmsgs', array());
}
$temp = $this->session->get('flashmsgs');
$temp[] = array('type' => $type, 'content' => $message);
$this->session->set('flashmsgs', $temp);
}
|
php
|
public function setMessage($type, $message) {
if (!$this->session->has('flashmsgs')) {
$this->session->set('flashmsgs', array());
}
$temp = $this->session->get('flashmsgs');
$temp[] = array('type' => $type, 'content' => $message);
$this->session->set('flashmsgs', $temp);
}
|
[
"public",
"function",
"setMessage",
"(",
"$",
"type",
",",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"session",
"->",
"has",
"(",
"'flashmsgs'",
")",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'flashmsgs'",
",",
"array",
"(",
")",
")",
";",
"}",
"$",
"temp",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'flashmsgs'",
")",
";",
"$",
"temp",
"[",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"type",
",",
"'content'",
"=>",
"$",
"message",
")",
";",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'flashmsgs'",
",",
"$",
"temp",
")",
";",
"}"
] |
Add message to session array
@param $type string with message type
@param $message string with message text
@return void
|
[
"Add",
"message",
"to",
"session",
"array"
] |
85c2f16ca94db6dd800ed292d84f2e7422b3e7f5
|
https://github.com/helikopterspark/FlashMsg/blob/85c2f16ca94db6dd800ed292d84f2e7422b3e7f5/src/FlashMsg/FlashMsg.php#L20-L27
|
25,660
|
helikopterspark/FlashMsg
|
src/FlashMsg/FlashMsg.php
|
FlashMsg.outputMsgs
|
public function outputMsgs() {
$messages = $this->session->get('flashmsgs');
$output = null;
if ($messages) {
foreach ($messages as $key => $message) {
$output .= '<div class="' . $message['type'] . '"><p>' . $message['content'] . '</p></div>';
}
}
return $output;
}
|
php
|
public function outputMsgs() {
$messages = $this->session->get('flashmsgs');
$output = null;
if ($messages) {
foreach ($messages as $key => $message) {
$output .= '<div class="' . $message['type'] . '"><p>' . $message['content'] . '</p></div>';
}
}
return $output;
}
|
[
"public",
"function",
"outputMsgs",
"(",
")",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'flashmsgs'",
")",
";",
"$",
"output",
"=",
"null",
";",
"if",
"(",
"$",
"messages",
")",
"{",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"key",
"=>",
"$",
"message",
")",
"{",
"$",
"output",
".=",
"'<div class=\"'",
".",
"$",
"message",
"[",
"'type'",
"]",
".",
"'\"><p>'",
".",
"$",
"message",
"[",
"'content'",
"]",
".",
"'</p></div>'",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] |
Build HTML of messages in session array
@return $output HTML string with messages
|
[
"Build",
"HTML",
"of",
"messages",
"in",
"session",
"array"
] |
85c2f16ca94db6dd800ed292d84f2e7422b3e7f5
|
https://github.com/helikopterspark/FlashMsg/blob/85c2f16ca94db6dd800ed292d84f2e7422b3e7f5/src/FlashMsg/FlashMsg.php#L100-L111
|
25,661
|
vpg/titon.utility
|
src/Titon/Utility/Sanitize.php
|
Sanitize.escape
|
public static function escape($value, array $options = array()) {
$options = $options + array(
'encoding' => 'UTF-8',
'flags' => ENT_QUOTES,
'double' => false
);
return htmlentities($value, $options['flags'], $options['encoding'], $options['double']);
}
|
php
|
public static function escape($value, array $options = array()) {
$options = $options + array(
'encoding' => 'UTF-8',
'flags' => ENT_QUOTES,
'double' => false
);
return htmlentities($value, $options['flags'], $options['encoding'], $options['double']);
}
|
[
"public",
"static",
"function",
"escape",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'encoding'",
"=>",
"'UTF-8'",
",",
"'flags'",
"=>",
"ENT_QUOTES",
",",
"'double'",
"=>",
"false",
")",
";",
"return",
"htmlentities",
"(",
"$",
"value",
",",
"$",
"options",
"[",
"'flags'",
"]",
",",
"$",
"options",
"[",
"'encoding'",
"]",
",",
"$",
"options",
"[",
"'double'",
"]",
")",
";",
"}"
] |
Escape a string using the apps encoding.
@param string $value
@param array $options {
@type string $encoding Character encoding set; defaults to UTF-8
@type int $flags Encoding flags; defaults to ENT_QUOTES
@type bool $double Will double escape existing entities
}
@return string
|
[
"Escape",
"a",
"string",
"using",
"the",
"apps",
"encoding",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L39-L47
|
25,662
|
vpg/titon.utility
|
src/Titon/Utility/Sanitize.php
|
Sanitize.html
|
public static function html($value, array $options = array()) {
$options = $options + array(
'strip' => true,
'whitelist' => ''
);
if ($options['strip']) {
$value = strip_tags($value, $options['whitelist']);
}
return static::escape($value, $options);
}
|
php
|
public static function html($value, array $options = array()) {
$options = $options + array(
'strip' => true,
'whitelist' => ''
);
if ($options['strip']) {
$value = strip_tags($value, $options['whitelist']);
}
return static::escape($value, $options);
}
|
[
"public",
"static",
"function",
"html",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'strip'",
"=>",
"true",
",",
"'whitelist'",
"=>",
"''",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'strip'",
"]",
")",
"{",
"$",
"value",
"=",
"strip_tags",
"(",
"$",
"value",
",",
"$",
"options",
"[",
"'whitelist'",
"]",
")",
";",
"}",
"return",
"static",
"::",
"escape",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"}"
] |
Sanitize a string by removing xor escaping HTML characters and entities.
@param string $value
@param array $options {
@type bool $strip Will remove HTML tags
@type string $whitelist List of tags to not strip
}
@return string
|
[
"Sanitize",
"a",
"string",
"by",
"removing",
"xor",
"escaping",
"HTML",
"characters",
"and",
"entities",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L69-L80
|
25,663
|
vpg/titon.utility
|
src/Titon/Utility/Sanitize.php
|
Sanitize.newlines
|
public static function newlines($value, array $options = array()) {
$options = $options + array(
'cr' => true,
'lf' => true,
'crlf' => true,
'limit' => 2,
'trim' => true
);
if ($options['limit']) {
$pattern = '/(?:%s){' . $options['limit'] . ',}/u';
} else {
$pattern = '/(?:%s)+/u';
$replace = '';
}
if ($options['crlf']) {
$value = preg_replace(sprintf($pattern, '\r\n'), (isset($replace) ? $replace : "\r\n"), $value);
}
if ($options['cr']) {
$value = preg_replace(sprintf($pattern, '\r'), (isset($replace) ? $replace : "\r"), $value);
}
if ($options['lf']) {
$value = preg_replace(sprintf($pattern, '\n'), (isset($replace) ? $replace : "\n"), $value);
}
if ($options['trim']) {
$value = trim($value);
}
return $value;
}
|
php
|
public static function newlines($value, array $options = array()) {
$options = $options + array(
'cr' => true,
'lf' => true,
'crlf' => true,
'limit' => 2,
'trim' => true
);
if ($options['limit']) {
$pattern = '/(?:%s){' . $options['limit'] . ',}/u';
} else {
$pattern = '/(?:%s)+/u';
$replace = '';
}
if ($options['crlf']) {
$value = preg_replace(sprintf($pattern, '\r\n'), (isset($replace) ? $replace : "\r\n"), $value);
}
if ($options['cr']) {
$value = preg_replace(sprintf($pattern, '\r'), (isset($replace) ? $replace : "\r"), $value);
}
if ($options['lf']) {
$value = preg_replace(sprintf($pattern, '\n'), (isset($replace) ? $replace : "\n"), $value);
}
if ($options['trim']) {
$value = trim($value);
}
return $value;
}
|
[
"public",
"static",
"function",
"newlines",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'cr'",
"=>",
"true",
",",
"'lf'",
"=>",
"true",
",",
"'crlf'",
"=>",
"true",
",",
"'limit'",
"=>",
"2",
",",
"'trim'",
"=>",
"true",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
"{",
"$",
"pattern",
"=",
"'/(?:%s){'",
".",
"$",
"options",
"[",
"'limit'",
"]",
".",
"',}/u'",
";",
"}",
"else",
"{",
"$",
"pattern",
"=",
"'/(?:%s)+/u'",
";",
"$",
"replace",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'crlf'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"'\\r\\n'",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"\"\\r\\n\"",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'cr'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"'\\r'",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"\"\\r\"",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'lf'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"'\\n'",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"\"\\n\"",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'trim'",
"]",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Sanitize a string by removing excess CRLF characters.
@param string $value
@param array $options {
@type bool $cr Will remove carriage returns \r
@type bool $lf Will remove line feeds \n
@type bool $crlf Will remove CRLF \r\n
@type bool $trim Will remove whitespace and newlines around the edges
@type int $limit The start limit to remove extraneous characters
}
@return string
|
[
"Sanitize",
"a",
"string",
"by",
"removing",
"excess",
"CRLF",
"characters",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L106-L140
|
25,664
|
vpg/titon.utility
|
src/Titon/Utility/Sanitize.php
|
Sanitize.whitespace
|
public static function whitespace($value, array $options = array()) {
$options = $options + array(
'space' => true,
'tab' => true,
'limit' => 2,
'strip' => true,
'trim' => true
);
if ($options['limit']) {
$pattern = '/%s{' . $options['limit'] . ',}/u';
} else {
$pattern = '/%s+/u';
$replace = '';
}
if ($options['tab']) {
$value = preg_replace(sprintf($pattern, '\t'), (isset($replace) ? $replace : "\t"), $value);
}
if ($options['space']) {
$value = preg_replace(sprintf($pattern, ' '), (isset($replace) ? $replace : ' '), $value); // \s replaces other whitespace characters
}
if ($options['strip']) {
$value = str_replace(chr(0xCA), ' ', $value);
}
if ($options['trim']) {
$value = trim($value);
}
return $value;
}
|
php
|
public static function whitespace($value, array $options = array()) {
$options = $options + array(
'space' => true,
'tab' => true,
'limit' => 2,
'strip' => true,
'trim' => true
);
if ($options['limit']) {
$pattern = '/%s{' . $options['limit'] . ',}/u';
} else {
$pattern = '/%s+/u';
$replace = '';
}
if ($options['tab']) {
$value = preg_replace(sprintf($pattern, '\t'), (isset($replace) ? $replace : "\t"), $value);
}
if ($options['space']) {
$value = preg_replace(sprintf($pattern, ' '), (isset($replace) ? $replace : ' '), $value); // \s replaces other whitespace characters
}
if ($options['strip']) {
$value = str_replace(chr(0xCA), ' ', $value);
}
if ($options['trim']) {
$value = trim($value);
}
return $value;
}
|
[
"public",
"static",
"function",
"whitespace",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'space'",
"=>",
"true",
",",
"'tab'",
"=>",
"true",
",",
"'limit'",
"=>",
"2",
",",
"'strip'",
"=>",
"true",
",",
"'trim'",
"=>",
"true",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
"{",
"$",
"pattern",
"=",
"'/%s{'",
".",
"$",
"options",
"[",
"'limit'",
"]",
".",
"',}/u'",
";",
"}",
"else",
"{",
"$",
"pattern",
"=",
"'/%s+/u'",
";",
"$",
"replace",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'tab'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"'\\t'",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"\"\\t\"",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'space'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"' '",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"' '",
")",
",",
"$",
"value",
")",
";",
"// \\s replaces other whitespace characters",
"}",
"if",
"(",
"$",
"options",
"[",
"'strip'",
"]",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"chr",
"(",
"0xCA",
")",
",",
"' '",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'trim'",
"]",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Sanitize a string by removing excess whitespace and tab characters.
@param string $value
@param array $options {
@type bool $space Will remove white space
@type bool $tab Will remove tabs
@type bool $strip Will remove non-standard white space character
@type bool $trim Will remove whitespace and newlines around the edges
@type int $limit The start limit to remove extraneous characters
}
@return string
|
[
"Sanitize",
"a",
"string",
"by",
"removing",
"excess",
"whitespace",
"and",
"tab",
"characters",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L166-L200
|
25,665
|
ezra-obiwale/dSCore
|
src/Core/AService.php
|
AService.setModel
|
public function setModel(IModel $model, $initRepo = true) {
$this->model = $model;
if ($initRepo)
$this->initRepository();
return $this;
}
|
php
|
public function setModel(IModel $model, $initRepo = true) {
$this->model = $model;
if ($initRepo)
$this->initRepository();
return $this;
}
|
[
"public",
"function",
"setModel",
"(",
"IModel",
"$",
"model",
",",
"$",
"initRepo",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"model",
";",
"if",
"(",
"$",
"initRepo",
")",
"$",
"this",
"->",
"initRepository",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the model to class
@param IModel $model
|
[
"Sets",
"the",
"model",
"to",
"class"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AService.php#L43-L48
|
25,666
|
ezra-obiwale/dSCore
|
src/Core/AService.php
|
AService.initRepository
|
protected function initRepository() {
if ($this->model === null ||
($this->model !== null && !in_array('DScribe\Core\IModel', class_implements($this->model))))
return false;
if ($this->repository !== null && $this->model->getTableName() === $this->repository->getTableName())
return true;
$repository = ($this->repositoryClass !== null) ? $this->repositoryClass : 'DBScribe\Repository';
$this->repository = new $repository($this->model, engineGet('DB'), true);
}
|
php
|
protected function initRepository() {
if ($this->model === null ||
($this->model !== null && !in_array('DScribe\Core\IModel', class_implements($this->model))))
return false;
if ($this->repository !== null && $this->model->getTableName() === $this->repository->getTableName())
return true;
$repository = ($this->repositoryClass !== null) ? $this->repositoryClass : 'DBScribe\Repository';
$this->repository = new $repository($this->model, engineGet('DB'), true);
}
|
[
"protected",
"function",
"initRepository",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"model",
"===",
"null",
"||",
"(",
"$",
"this",
"->",
"model",
"!==",
"null",
"&&",
"!",
"in_array",
"(",
"'DScribe\\Core\\IModel'",
",",
"class_implements",
"(",
"$",
"this",
"->",
"model",
")",
")",
")",
")",
"return",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"repository",
"!==",
"null",
"&&",
"$",
"this",
"->",
"model",
"->",
"getTableName",
"(",
")",
"===",
"$",
"this",
"->",
"repository",
"->",
"getTableName",
"(",
")",
")",
"return",
"true",
";",
"$",
"repository",
"=",
"(",
"$",
"this",
"->",
"repositoryClass",
"!==",
"null",
")",
"?",
"$",
"this",
"->",
"repositoryClass",
":",
"'DBScribe\\Repository'",
";",
"$",
"this",
"->",
"repository",
"=",
"new",
"$",
"repository",
"(",
"$",
"this",
"->",
"model",
",",
"engineGet",
"(",
"'DB'",
")",
",",
"true",
")",
";",
"}"
] |
Initializes the repository
@return boolean
|
[
"Initializes",
"the",
"repository"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AService.php#L72-L82
|
25,667
|
ezra-obiwale/dSCore
|
src/Core/AService.php
|
AService.prepareInject
|
protected function prepareInject() {
$model = ($this->model) ? $this->model : $this->getModule() . '\Models\\' . $this->getClassName();
if (is_object($model))
$model = get_class($model);
if (!class_exists($model))
return array_merge(parent::prepareInject(), $this->getConfigInject('services'));
return array_merge(parent::prepareInject(), $this->getConfigInject('services'), array(
'model' => array(
'class' => $model
),
));
}
|
php
|
protected function prepareInject() {
$model = ($this->model) ? $this->model : $this->getModule() . '\Models\\' . $this->getClassName();
if (is_object($model))
$model = get_class($model);
if (!class_exists($model))
return array_merge(parent::prepareInject(), $this->getConfigInject('services'));
return array_merge(parent::prepareInject(), $this->getConfigInject('services'), array(
'model' => array(
'class' => $model
),
));
}
|
[
"protected",
"function",
"prepareInject",
"(",
")",
"{",
"$",
"model",
"=",
"(",
"$",
"this",
"->",
"model",
")",
"?",
"$",
"this",
"->",
"model",
":",
"$",
"this",
"->",
"getModule",
"(",
")",
".",
"'\\Models\\\\'",
".",
"$",
"this",
"->",
"getClassName",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"model",
")",
")",
"$",
"model",
"=",
"get_class",
"(",
"$",
"model",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"model",
")",
")",
"return",
"array_merge",
"(",
"parent",
"::",
"prepareInject",
"(",
")",
",",
"$",
"this",
"->",
"getConfigInject",
"(",
"'services'",
")",
")",
";",
"return",
"array_merge",
"(",
"parent",
"::",
"prepareInject",
"(",
")",
",",
"$",
"this",
"->",
"getConfigInject",
"(",
"'services'",
")",
",",
"array",
"(",
"'model'",
"=>",
"array",
"(",
"'class'",
"=>",
"$",
"model",
")",
",",
")",
")",
";",
"}"
] |
prepares injection of classes
@return array
|
[
"prepares",
"injection",
"of",
"classes"
] |
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
|
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AService.php#L103-L117
|
25,668
|
davedevelopment/pimple-aware-event-dispatcher
|
src/PimpleAwareEventDispatcher/PimpleAwareEventDispatcher.php
|
PimpleAwareEventDispatcher.addSubscriberService
|
public function addSubscriberService($serviceId, $class)
{
$rfc = new \ReflectionClass($class);
if (!$rfc->implementsInterface('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
throw new \InvalidArgumentException(
"$class must implement Symfony\Component\EventDispatcher\EventSubscriberInterface"
);
}
foreach ($class::getSubscribedEvents() as $eventName => $params) {
if (is_string($params)) {
$this->addListenerService($eventName, array($serviceId, $params), 0);
} elseif (is_string($params[0])) {
$this->addListenerService($eventName, array($serviceId, $params[0]), isset($params[1]) ? $params[1] : 0);
} else {
foreach ($params as $listener) {
$this->addListenerService($eventName, array($serviceId, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
}
}
}
}
|
php
|
public function addSubscriberService($serviceId, $class)
{
$rfc = new \ReflectionClass($class);
if (!$rfc->implementsInterface('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
throw new \InvalidArgumentException(
"$class must implement Symfony\Component\EventDispatcher\EventSubscriberInterface"
);
}
foreach ($class::getSubscribedEvents() as $eventName => $params) {
if (is_string($params)) {
$this->addListenerService($eventName, array($serviceId, $params), 0);
} elseif (is_string($params[0])) {
$this->addListenerService($eventName, array($serviceId, $params[0]), isset($params[1]) ? $params[1] : 0);
} else {
foreach ($params as $listener) {
$this->addListenerService($eventName, array($serviceId, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
}
}
}
}
|
[
"public",
"function",
"addSubscriberService",
"(",
"$",
"serviceId",
",",
"$",
"class",
")",
"{",
"$",
"rfc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"$",
"rfc",
"->",
"implementsInterface",
"(",
"'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface'",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"$class must implement Symfony\\Component\\EventDispatcher\\EventSubscriberInterface\"",
")",
";",
"}",
"foreach",
"(",
"$",
"class",
"::",
"getSubscribedEvents",
"(",
")",
"as",
"$",
"eventName",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"addListenerService",
"(",
"$",
"eventName",
",",
"array",
"(",
"$",
"serviceId",
",",
"$",
"params",
")",
",",
"0",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addListenerService",
"(",
"$",
"eventName",
",",
"array",
"(",
"$",
"serviceId",
",",
"$",
"params",
"[",
"0",
"]",
")",
",",
"isset",
"(",
"$",
"params",
"[",
"1",
"]",
")",
"?",
"$",
"params",
"[",
"1",
"]",
":",
"0",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"listener",
")",
"{",
"$",
"this",
"->",
"addListenerService",
"(",
"$",
"eventName",
",",
"array",
"(",
"$",
"serviceId",
",",
"$",
"listener",
"[",
"0",
"]",
")",
",",
"isset",
"(",
"$",
"listener",
"[",
"1",
"]",
")",
"?",
"$",
"listener",
"[",
"1",
"]",
":",
"0",
")",
";",
"}",
"}",
"}",
"}"
] |
Adds a service as event subscriber
@param string $serviceId The service ID of the subscriber service
@param string $class The service's class name (which must implement EventSubscriberInterface)
|
[
"Adds",
"a",
"service",
"as",
"event",
"subscriber"
] |
e0864988219da254c46690379634bce3f22a0eba
|
https://github.com/davedevelopment/pimple-aware-event-dispatcher/blob/e0864988219da254c46690379634bce3f22a0eba/src/PimpleAwareEventDispatcher/PimpleAwareEventDispatcher.php#L102-L122
|
25,669
|
brain-diminished/schema-version-control
|
src/Utils/SchemaNormalizer.php
|
SchemaNormalizer.normalize
|
public function normalize(Schema $schema): array
{
$this->schema = $schema;
$schemaDesc = [];
$schemaDesc['tables'] = [];
foreach ($schema->getTables() as $table) {
$schemaDesc['tables'][$table->getName()] = $this->normalizeTable($table);
}
return $schemaDesc;
}
|
php
|
public function normalize(Schema $schema): array
{
$this->schema = $schema;
$schemaDesc = [];
$schemaDesc['tables'] = [];
foreach ($schema->getTables() as $table) {
$schemaDesc['tables'][$table->getName()] = $this->normalizeTable($table);
}
return $schemaDesc;
}
|
[
"public",
"function",
"normalize",
"(",
"Schema",
"$",
"schema",
")",
":",
"array",
"{",
"$",
"this",
"->",
"schema",
"=",
"$",
"schema",
";",
"$",
"schemaDesc",
"=",
"[",
"]",
";",
"$",
"schemaDesc",
"[",
"'tables'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"schema",
"->",
"getTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"$",
"schemaDesc",
"[",
"'tables'",
"]",
"[",
"$",
"table",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"normalizeTable",
"(",
"$",
"table",
")",
";",
"}",
"return",
"$",
"schemaDesc",
";",
"}"
] |
Normalize a Schema object into an array descriptor
@param Schema $schema
@return array
|
[
"Normalize",
"a",
"Schema",
"object",
"into",
"an",
"array",
"descriptor"
] |
215dd96394072720b61a682e10a55a6520470c46
|
https://github.com/brain-diminished/schema-version-control/blob/215dd96394072720b61a682e10a55a6520470c46/src/Utils/SchemaNormalizer.php#L26-L35
|
25,670
|
ekyna/MediaBundle
|
Model/Import/MediaUpload.php
|
MediaUpload.removeMedia
|
public function removeMedia(MediaInterface $media)
{
if ($this->medias->contains($media)) {
$this->medias->removeElement($media);
}
return $this;
}
|
php
|
public function removeMedia(MediaInterface $media)
{
if ($this->medias->contains($media)) {
$this->medias->removeElement($media);
}
return $this;
}
|
[
"public",
"function",
"removeMedia",
"(",
"MediaInterface",
"$",
"media",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"medias",
"->",
"contains",
"(",
"$",
"media",
")",
")",
"{",
"$",
"this",
"->",
"medias",
"->",
"removeElement",
"(",
"$",
"media",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Removes the media.
@param MediaInterface $media
@return MediaUpload
|
[
"Removes",
"the",
"media",
"."
] |
512cf86c801a130a9f17eba8b48d646d23acdbab
|
https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Model/Import/MediaUpload.php#L49-L55
|
25,671
|
Subscribo/klarna-invoice-sdk-wrapped
|
src/klarnapclass.php
|
KlarnaPClass.toArray
|
public function toArray()
{
return array(
'eid' => $this->eid,
'id' => $this->id,
'description' => $this->description,
'months' => $this->months,
'startfee' => $this->startFee,
'invoicefee' => $this->invoiceFee,
'interestrate' => $this->interestRate,
'minamount' => $this->minAmount,
'country' => $this->country,
'type' => $this->type,
'expire' => $this->expire
);
}
|
php
|
public function toArray()
{
return array(
'eid' => $this->eid,
'id' => $this->id,
'description' => $this->description,
'months' => $this->months,
'startfee' => $this->startFee,
'invoicefee' => $this->invoiceFee,
'interestrate' => $this->interestRate,
'minamount' => $this->minAmount,
'country' => $this->country,
'type' => $this->type,
'expire' => $this->expire
);
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"array",
"(",
"'eid'",
"=>",
"$",
"this",
"->",
"eid",
",",
"'id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'description'",
"=>",
"$",
"this",
"->",
"description",
",",
"'months'",
"=>",
"$",
"this",
"->",
"months",
",",
"'startfee'",
"=>",
"$",
"this",
"->",
"startFee",
",",
"'invoicefee'",
"=>",
"$",
"this",
"->",
"invoiceFee",
",",
"'interestrate'",
"=>",
"$",
"this",
"->",
"interestRate",
",",
"'minamount'",
"=>",
"$",
"this",
"->",
"minAmount",
",",
"'country'",
"=>",
"$",
"this",
"->",
"country",
",",
"'type'",
"=>",
"$",
"this",
"->",
"type",
",",
"'expire'",
"=>",
"$",
"this",
"->",
"expire",
")",
";",
"}"
] |
Returns an associative array mirroring this PClass.
@return array
|
[
"Returns",
"an",
"associative",
"array",
"mirroring",
"this",
"PClass",
"."
] |
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
|
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnapclass.php#L268-L283
|
25,672
|
Subscribo/klarna-invoice-sdk-wrapped
|
src/klarnapclass.php
|
KlarnaPClass.isValid
|
public function isValid($now = null)
{
if ($this->expire == null
|| $this->expire == '-'
|| $this->expire <= 0
) {
//No expire, or unset? assume valid.
return true;
}
if ($now === null || !is_numeric($now)) {
$now = time();
}
//If now is before expire, it is still valid.
return ($now > $this->expire) ? false : true;
}
|
php
|
public function isValid($now = null)
{
if ($this->expire == null
|| $this->expire == '-'
|| $this->expire <= 0
) {
//No expire, or unset? assume valid.
return true;
}
if ($now === null || !is_numeric($now)) {
$now = time();
}
//If now is before expire, it is still valid.
return ($now > $this->expire) ? false : true;
}
|
[
"public",
"function",
"isValid",
"(",
"$",
"now",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"expire",
"==",
"null",
"||",
"$",
"this",
"->",
"expire",
"==",
"'-'",
"||",
"$",
"this",
"->",
"expire",
"<=",
"0",
")",
"{",
"//No expire, or unset? assume valid.",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"now",
"===",
"null",
"||",
"!",
"is_numeric",
"(",
"$",
"now",
")",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"}",
"//If now is before expire, it is still valid.",
"return",
"(",
"$",
"now",
">",
"$",
"this",
"->",
"expire",
")",
"?",
"false",
":",
"true",
";",
"}"
] |
Checks whether this PClass is valid.
@param int $now Unix timestamp
@return bool
|
[
"Checks",
"whether",
"this",
"PClass",
"is",
"valid",
"."
] |
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
|
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnapclass.php#L459-L475
|
25,673
|
Kris-Kuiper/sFire-Framework
|
src/MVC/MVCTrait.php
|
MVCTrait.helper
|
protected function helper($classname) {
$directories = explode('.', $classname); //Convert dots to directory seperators
$amount = count($directories) - 1;
$namespace = Router :: getRoute() -> getModule() . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', Application :: get(['directory', 'helper']));
foreach($directories as $index => $directory) {
if($amount === $index) {
$namespace .= Application :: get(['prefix', 'helper']) . $directory;
break;
}
$namespace .= $directory . '\\';
}
return new $namespace;
}
|
php
|
protected function helper($classname) {
$directories = explode('.', $classname); //Convert dots to directory seperators
$amount = count($directories) - 1;
$namespace = Router :: getRoute() -> getModule() . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', Application :: get(['directory', 'helper']));
foreach($directories as $index => $directory) {
if($amount === $index) {
$namespace .= Application :: get(['prefix', 'helper']) . $directory;
break;
}
$namespace .= $directory . '\\';
}
return new $namespace;
}
|
[
"protected",
"function",
"helper",
"(",
"$",
"classname",
")",
"{",
"$",
"directories",
"=",
"explode",
"(",
"'.'",
",",
"$",
"classname",
")",
";",
"//Convert dots to directory seperators\r",
"$",
"amount",
"=",
"count",
"(",
"$",
"directories",
")",
"-",
"1",
";",
"$",
"namespace",
"=",
"Router",
"::",
"getRoute",
"(",
")",
"->",
"getModule",
"(",
")",
".",
"'\\\\'",
".",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
",",
"Application",
"::",
"get",
"(",
"[",
"'directory'",
",",
"'helper'",
"]",
")",
")",
";",
"foreach",
"(",
"$",
"directories",
"as",
"$",
"index",
"=>",
"$",
"directory",
")",
"{",
"if",
"(",
"$",
"amount",
"===",
"$",
"index",
")",
"{",
"$",
"namespace",
".=",
"Application",
"::",
"get",
"(",
"[",
"'prefix'",
",",
"'helper'",
"]",
")",
".",
"$",
"directory",
";",
"break",
";",
"}",
"$",
"namespace",
".=",
"$",
"directory",
".",
"'\\\\'",
";",
"}",
"return",
"new",
"$",
"namespace",
";",
"}"
] |
Loads a helper class in current module directory
@param string $classname
@return Object
|
[
"Loads",
"a",
"helper",
"class",
"in",
"current",
"module",
"directory"
] |
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
|
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/MVCTrait.php#L26-L44
|
25,674
|
Kris-Kuiper/sFire-Framework
|
src/MVC/MVCTrait.php
|
MVCTrait.fails
|
protected function fails($fieldname = null) {
$helper = new StringToArray();
return $helper -> execute($fieldname, null, Message :: getErrors(true));
}
|
php
|
protected function fails($fieldname = null) {
$helper = new StringToArray();
return $helper -> execute($fieldname, null, Message :: getErrors(true));
}
|
[
"protected",
"function",
"fails",
"(",
"$",
"fieldname",
"=",
"null",
")",
"{",
"$",
"helper",
"=",
"new",
"StringToArray",
"(",
")",
";",
"return",
"$",
"helper",
"->",
"execute",
"(",
"$",
"fieldname",
",",
"null",
",",
"Message",
"::",
"getErrors",
"(",
"true",
")",
")",
";",
"}"
] |
Get the error message from the validator by fieldname
@param string $fieldname
@return string
|
[
"Get",
"the",
"error",
"message",
"from",
"the",
"validator",
"by",
"fieldname"
] |
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
|
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/MVCTrait.php#L52-L56
|
25,675
|
Kris-Kuiper/sFire-Framework
|
src/MVC/MVCTrait.php
|
MVCTrait.passes
|
protected function passes($fieldname = null) {
$helper = new StringToArray();
return true === Request :: isPost() && null === $helper -> execute($fieldname, null, Message :: getErrors(true));
}
|
php
|
protected function passes($fieldname = null) {
$helper = new StringToArray();
return true === Request :: isPost() && null === $helper -> execute($fieldname, null, Message :: getErrors(true));
}
|
[
"protected",
"function",
"passes",
"(",
"$",
"fieldname",
"=",
"null",
")",
"{",
"$",
"helper",
"=",
"new",
"StringToArray",
"(",
")",
";",
"return",
"true",
"===",
"Request",
"::",
"isPost",
"(",
")",
"&&",
"null",
"===",
"$",
"helper",
"->",
"execute",
"(",
"$",
"fieldname",
",",
"null",
",",
"Message",
"::",
"getErrors",
"(",
"true",
")",
")",
";",
"}"
] |
Returns if there is no validation error for the given fieldname when request method is equal to POST
@param string $fieldname
@return boolean
|
[
"Returns",
"if",
"there",
"is",
"no",
"validation",
"error",
"for",
"the",
"given",
"fieldname",
"when",
"request",
"method",
"is",
"equal",
"to",
"POST"
] |
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
|
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/MVCTrait.php#L64-L68
|
25,676
|
ekyna/MediaBundle
|
Form/Type/Step/MediaImportSelectionType.php
|
MediaImportSelectionType.buildKeysChoices
|
public function buildKeysChoices(MediaImport $import)
{
$prefix = $import->getFilesystem();
$fs = $this->mountManager->getFilesystem($prefix);
$contents = $fs->listContents('', true);
$choices = [];
foreach ($contents as $object) {
if (!($object['type'] == 'dir' || substr($object['path'], 0, 1) == '.')) {
$key = sprintf('%s://%s', $prefix, $object['path']);
$choices[$key] = $object['path'];
}
}
return $choices;
}
|
php
|
public function buildKeysChoices(MediaImport $import)
{
$prefix = $import->getFilesystem();
$fs = $this->mountManager->getFilesystem($prefix);
$contents = $fs->listContents('', true);
$choices = [];
foreach ($contents as $object) {
if (!($object['type'] == 'dir' || substr($object['path'], 0, 1) == '.')) {
$key = sprintf('%s://%s', $prefix, $object['path']);
$choices[$key] = $object['path'];
}
}
return $choices;
}
|
[
"public",
"function",
"buildKeysChoices",
"(",
"MediaImport",
"$",
"import",
")",
"{",
"$",
"prefix",
"=",
"$",
"import",
"->",
"getFilesystem",
"(",
")",
";",
"$",
"fs",
"=",
"$",
"this",
"->",
"mountManager",
"->",
"getFilesystem",
"(",
"$",
"prefix",
")",
";",
"$",
"contents",
"=",
"$",
"fs",
"->",
"listContents",
"(",
"''",
",",
"true",
")",
";",
"$",
"choices",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"object",
"[",
"'type'",
"]",
"==",
"'dir'",
"||",
"substr",
"(",
"$",
"object",
"[",
"'path'",
"]",
",",
"0",
",",
"1",
")",
"==",
"'.'",
")",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"'%s://%s'",
",",
"$",
"prefix",
",",
"$",
"object",
"[",
"'path'",
"]",
")",
";",
"$",
"choices",
"[",
"$",
"key",
"]",
"=",
"$",
"object",
"[",
"'path'",
"]",
";",
"}",
"}",
"return",
"$",
"choices",
";",
"}"
] |
Builds the keys choices.
@param MediaImport $import
@return array
|
[
"Builds",
"the",
"keys",
"choices",
"."
] |
512cf86c801a130a9f17eba8b48d646d23acdbab
|
https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Form/Type/Step/MediaImportSelectionType.php#L64-L77
|
25,677
|
shrink0r/monatic
|
src/Eventually.php
|
Eventually.bind
|
public function bind(callable $codeBlock)
{
assert($this->result === null, "'Eventually' instance may not be mutated after code-block execution.");
return static::unit(function ($success) use ($codeBlock) {
$this->run(function ($value) use ($codeBlock, $success) {
return $codeBlock($value)->run($success);
});
});
}
|
php
|
public function bind(callable $codeBlock)
{
assert($this->result === null, "'Eventually' instance may not be mutated after code-block execution.");
return static::unit(function ($success) use ($codeBlock) {
$this->run(function ($value) use ($codeBlock, $success) {
return $codeBlock($value)->run($success);
});
});
}
|
[
"public",
"function",
"bind",
"(",
"callable",
"$",
"codeBlock",
")",
"{",
"assert",
"(",
"$",
"this",
"->",
"result",
"===",
"null",
",",
"\"'Eventually' instance may not be mutated after code-block execution.\"",
")",
";",
"return",
"static",
"::",
"unit",
"(",
"function",
"(",
"$",
"success",
")",
"use",
"(",
"$",
"codeBlock",
")",
"{",
"$",
"this",
"->",
"run",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"codeBlock",
",",
"$",
"success",
")",
"{",
"return",
"$",
"codeBlock",
"(",
"$",
"value",
")",
"->",
"run",
"(",
"$",
"success",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Binds the given callable to the monad's managed code-block's successful execution.
@param callable $codeBlock Is expected to return an instance of Eventually.
@return Eventually
|
[
"Binds",
"the",
"given",
"callable",
"to",
"the",
"monad",
"s",
"managed",
"code",
"-",
"block",
"s",
"successful",
"execution",
"."
] |
f39b8b2ef68a397d31d844341487412b335fd107
|
https://github.com/shrink0r/monatic/blob/f39b8b2ef68a397d31d844341487412b335fd107/src/Eventually.php#L70-L79
|
25,678
|
kaiohken1982/NeobazaarDocumentModule
|
src/Document/Utils/AbstractImage.php
|
AbstractImage.isNoDateStrategy
|
public function isNoDateStrategy(Document $doc = null, $prefix = '150_')
{
$prefix = 'ups/';
return file_exists($this->cdnPath . $prefix . $doc->getTitle());
}
|
php
|
public function isNoDateStrategy(Document $doc = null, $prefix = '150_')
{
$prefix = 'ups/';
return file_exists($this->cdnPath . $prefix . $doc->getTitle());
}
|
[
"public",
"function",
"isNoDateStrategy",
"(",
"Document",
"$",
"doc",
"=",
"null",
",",
"$",
"prefix",
"=",
"'150_'",
")",
"{",
"$",
"prefix",
"=",
"'ups/'",
";",
"return",
"file_exists",
"(",
"$",
"this",
"->",
"cdnPath",
".",
"$",
"prefix",
".",
"$",
"doc",
"->",
"getTitle",
"(",
")",
")",
";",
"}"
] |
Check using no date strategy
|
[
"Check",
"using",
"no",
"date",
"strategy"
] |
edb0223878fe02e791d2a0266c5a7c0f2029e3fe
|
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Utils/AbstractImage.php#L39-L43
|
25,679
|
FuzeWorks/Core
|
src/FuzeWorks/Config.php
|
Config.getConfig
|
public function getConfig($configName, array $configPaths = array()): ConfigORM
{
// First determine what directories to use
$directories = (empty($configPaths) ? $this->configPaths : $configPaths);
// Determine the config name
$configName = strtolower($configName);
// If it's already loaded, return the existing object
if (isset($this->cfg[$configName]))
{
return $this->cfg[$configName];
}
// Otherwise try and load a new one
$this->cfg[$configName] = $this->loadConfigFile($configName, $directories);
return $this->cfg[$configName];
}
|
php
|
public function getConfig($configName, array $configPaths = array()): ConfigORM
{
// First determine what directories to use
$directories = (empty($configPaths) ? $this->configPaths : $configPaths);
// Determine the config name
$configName = strtolower($configName);
// If it's already loaded, return the existing object
if (isset($this->cfg[$configName]))
{
return $this->cfg[$configName];
}
// Otherwise try and load a new one
$this->cfg[$configName] = $this->loadConfigFile($configName, $directories);
return $this->cfg[$configName];
}
|
[
"public",
"function",
"getConfig",
"(",
"$",
"configName",
",",
"array",
"$",
"configPaths",
"=",
"array",
"(",
")",
")",
":",
"ConfigORM",
"{",
"// First determine what directories to use",
"$",
"directories",
"=",
"(",
"empty",
"(",
"$",
"configPaths",
")",
"?",
"$",
"this",
"->",
"configPaths",
":",
"$",
"configPaths",
")",
";",
"// Determine the config name",
"$",
"configName",
"=",
"strtolower",
"(",
"$",
"configName",
")",
";",
"// If it's already loaded, return the existing object",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"$",
"configName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cfg",
"[",
"$",
"configName",
"]",
";",
"}",
"// Otherwise try and load a new one",
"$",
"this",
"->",
"cfg",
"[",
"$",
"configName",
"]",
"=",
"$",
"this",
"->",
"loadConfigFile",
"(",
"$",
"configName",
",",
"$",
"directories",
")",
";",
"return",
"$",
"this",
"->",
"cfg",
"[",
"$",
"configName",
"]",
";",
"}"
] |
Retrieve a config file object
@param string $configName Name of the config file. Eg. 'main'
@param array $configPaths Optional array of where to look for the config files
@return ConfigORM of the config file. Allows for easy reading and editing of the file
@throws ConfigException
|
[
"Retrieve",
"a",
"config",
"file",
"object"
] |
051c64fdaa3a648174cbd54557d05ad553dd826b
|
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Config.php#L78-L95
|
25,680
|
FuzeWorks/Core
|
src/FuzeWorks/Config.php
|
Config.loadConfigFile
|
protected function loadConfigFile($configName, array $configPaths): ConfigORM
{
// Cycle through all directories
foreach ($configPaths as $directory)
{
// If file exists, load it and break the loop
$file = $directory . DS . 'config.'.$configName.'.php';
if (file_exists($file))
{
// Load object
return new ConfigORM($file);
break;
}
}
// Try fallback
$file = Core::$coreDir . DS . 'Config' . DS . 'config.' . $configName . '.php';
if (file_exists($file))
{
// Load object
return new ConfigORM($file);
}
throw new ConfigException("Could not load config. File $configName not found", 1);
}
|
php
|
protected function loadConfigFile($configName, array $configPaths): ConfigORM
{
// Cycle through all directories
foreach ($configPaths as $directory)
{
// If file exists, load it and break the loop
$file = $directory . DS . 'config.'.$configName.'.php';
if (file_exists($file))
{
// Load object
return new ConfigORM($file);
break;
}
}
// Try fallback
$file = Core::$coreDir . DS . 'Config' . DS . 'config.' . $configName . '.php';
if (file_exists($file))
{
// Load object
return new ConfigORM($file);
}
throw new ConfigException("Could not load config. File $configName not found", 1);
}
|
[
"protected",
"function",
"loadConfigFile",
"(",
"$",
"configName",
",",
"array",
"$",
"configPaths",
")",
":",
"ConfigORM",
"{",
"// Cycle through all directories",
"foreach",
"(",
"$",
"configPaths",
"as",
"$",
"directory",
")",
"{",
"// If file exists, load it and break the loop",
"$",
"file",
"=",
"$",
"directory",
".",
"DS",
".",
"'config.'",
".",
"$",
"configName",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"// Load object",
"return",
"new",
"ConfigORM",
"(",
"$",
"file",
")",
";",
"break",
";",
"}",
"}",
"// Try fallback",
"$",
"file",
"=",
"Core",
"::",
"$",
"coreDir",
".",
"DS",
".",
"'Config'",
".",
"DS",
".",
"'config.'",
".",
"$",
"configName",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"// Load object",
"return",
"new",
"ConfigORM",
"(",
"$",
"file",
")",
";",
"}",
"throw",
"new",
"ConfigException",
"(",
"\"Could not load config. File $configName not found\"",
",",
"1",
")",
";",
"}"
] |
Determine whether the file exists and, if so, load the ConfigORM
@param string $configName Name of the config file. Eg. 'main'
@param array $configPaths Required array of where to look for the config files
@return ConfigORM of the config file. Allows for easy reading and editing of the file
@throws ConfigException
|
[
"Determine",
"whether",
"the",
"file",
"exists",
"and",
"if",
"so",
"load",
"the",
"ConfigORM"
] |
051c64fdaa3a648174cbd54557d05ad553dd826b
|
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Config.php#L123-L147
|
25,681
|
FuzeWorks/Core
|
src/FuzeWorks/Config.php
|
Config.removeConfigPath
|
public function removeConfigPath($directory)
{
if (($key = array_search($directory, $this->configPaths)) !== false)
{
unset($this->configPaths[$key]);
}
}
|
php
|
public function removeConfigPath($directory)
{
if (($key = array_search($directory, $this->configPaths)) !== false)
{
unset($this->configPaths[$key]);
}
}
|
[
"public",
"function",
"removeConfigPath",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"directory",
",",
"$",
"this",
"->",
"configPaths",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"configPaths",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] |
Remove a path where config files can be found
@param string $directory The directory
@return void
|
[
"Remove",
"a",
"path",
"where",
"config",
"files",
"can",
"be",
"found"
] |
051c64fdaa3a648174cbd54557d05ad553dd826b
|
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Config.php#L169-L175
|
25,682
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.getContent
|
public function getContent()
{
try {
if ($this->response) {
if (isset($this->response['content'])) {
return $this->response['content'];
} else {
return $this->response;
}
}
}
catch (Exception $e) {
$message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
return NULL;
}
|
php
|
public function getContent()
{
try {
if ($this->response) {
if (isset($this->response['content'])) {
return $this->response['content'];
} else {
return $this->response;
}
}
}
catch (Exception $e) {
$message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
return NULL;
}
|
[
"public",
"function",
"getContent",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"response",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"response",
"[",
"'content'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"[",
"'content'",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"response",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"'Error File: '",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"' - Line: '",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"' - Code: '",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' - Message: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}",
"return",
"NULL",
";",
"}"
] |
Function getContent - Get Body Content from Request
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:08
@return array|mixed|string Return Response content if exists
Full Response content if $this->response['content'] not exists
Exception Error Message if Exception Error
Null if Not
|
[
"Function",
"getContent",
"-",
"Get",
"Body",
"Content",
"from",
"Request"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L249-L268
|
25,683
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.sendRequest
|
public function sendRequest()
{
try {
if (mb_strlen($this->url) >= 9) {
$response = $this->useFileGetContents();
$this->response = $response;
return $response;
}
}
catch (Exception $e) {
$message = "Error: " . __CLASS__ . ": Please make sure to set a URL to fetch - Line: " . $e->getLine() . ' - Msg: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
return NULL;
}
|
php
|
public function sendRequest()
{
try {
if (mb_strlen($this->url) >= 9) {
$response = $this->useFileGetContents();
$this->response = $response;
return $response;
}
}
catch (Exception $e) {
$message = "Error: " . __CLASS__ . ": Please make sure to set a URL to fetch - Line: " . $e->getLine() . ' - Msg: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
return NULL;
}
|
[
"public",
"function",
"sendRequest",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"this",
"->",
"url",
")",
">=",
"9",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"useFileGetContents",
"(",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"response",
";",
"return",
"$",
"response",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"\"Error: \"",
".",
"__CLASS__",
".",
"\": Please make sure to set a URL to fetch - Line: \"",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"' - Msg: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}",
"return",
"NULL",
";",
"}"
] |
Let's go to Request
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:12
@return array|null|string Response from Request if Exists
Exception Error Message if Exception Error
Null if Not
|
[
"Let",
"s",
"go",
"to",
"Request"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L329-L347
|
25,684
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.getPostBody
|
public function getPostBody()
{
$output = '';
if ($this->isJson) {
$jsonPretty = ($this->isJsonPretty ? JSON_PRETTY_PRINT : NULL);
if (count($this->data) > 0) {
$output = json_encode($this->data, $jsonPretty);
}
} elseif ($this->isXML) {
$output = $this->data;
} elseif (count($this->data) > 0) {
$output = http_build_query($this->data);
}
return $output;
}
|
php
|
public function getPostBody()
{
$output = '';
if ($this->isJson) {
$jsonPretty = ($this->isJsonPretty ? JSON_PRETTY_PRINT : NULL);
if (count($this->data) > 0) {
$output = json_encode($this->data, $jsonPretty);
}
} elseif ($this->isXML) {
$output = $this->data;
} elseif (count($this->data) > 0) {
$output = http_build_query($this->data);
}
return $output;
}
|
[
"public",
"function",
"getPostBody",
"(",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"isJson",
")",
"{",
"$",
"jsonPretty",
"=",
"(",
"$",
"this",
"->",
"isJsonPretty",
"?",
"JSON_PRETTY_PRINT",
":",
"NULL",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
")",
"{",
"$",
"output",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"jsonPretty",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isXML",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"data",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
")",
"{",
"$",
"output",
"=",
"http_build_query",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Get the post body - either JSON encoded or ready to be sent as a form post
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:19
@return array|false|string Data to be sent Request
|
[
"Get",
"the",
"post",
"body",
"-",
"either",
"JSON",
"encoded",
"or",
"ready",
"to",
"be",
"sent",
"as",
"a",
"form",
"post"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L497-L512
|
25,685
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.getQueryString
|
public function getQueryString()
{
$query_string = '';
if (count($this->query_string) > 0) {
$query_string .= http_build_query($this->query_string);
}
if ($this->method != 'POST') {
if (count($this->data) > 0) {
$query_string .= http_build_query($this->data);
}
}
if (mb_strlen($query_string) > 0) {
$query_string = (mb_strpos($this->url, '?') ? '&' : '?') . $query_string;
}
return $query_string;
}
|
php
|
public function getQueryString()
{
$query_string = '';
if (count($this->query_string) > 0) {
$query_string .= http_build_query($this->query_string);
}
if ($this->method != 'POST') {
if (count($this->data) > 0) {
$query_string .= http_build_query($this->data);
}
}
if (mb_strlen($query_string) > 0) {
$query_string = (mb_strpos($this->url, '?') ? '&' : '?') . $query_string;
}
return $query_string;
}
|
[
"public",
"function",
"getQueryString",
"(",
")",
"{",
"$",
"query_string",
"=",
"''",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"query_string",
")",
">",
"0",
")",
"{",
"$",
"query_string",
".=",
"http_build_query",
"(",
"$",
"this",
"->",
"query_string",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"method",
"!=",
"'POST'",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
")",
"{",
"$",
"query_string",
".=",
"http_build_query",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}",
"}",
"if",
"(",
"mb_strlen",
"(",
"$",
"query_string",
")",
">",
"0",
")",
"{",
"$",
"query_string",
"=",
"(",
"mb_strpos",
"(",
"$",
"this",
"->",
"url",
",",
"'?'",
")",
"?",
"'&'",
":",
"'?'",
")",
".",
"$",
"query_string",
";",
"}",
"return",
"$",
"query_string",
";",
"}"
] |
Get the query string by merging any supplied string
with that of the generated components.
@return string The query string
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:19
|
[
"Get",
"the",
"query",
"string",
"by",
"merging",
"any",
"supplied",
"string",
"with",
"that",
"of",
"the",
"generated",
"components",
"."
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L523-L539
|
25,686
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.setMethod
|
public function setMethod($method = '')
{
if (mb_strlen($method) == 0) {
$this->debug->debug(__FUNCTION__, 'Set Default Method = GET if $method is does not exist');
$method = 'GET';
} else {
$method = strtoupper($method);
$validMethods = [
'GET',
'HEAD',
'PUT',
'POST',
'DELETE'
];
if (!in_array($method, $validMethods)) {
$message = "Error: " . __CLASS__ . ": The requested method (${method}) is not valid here";
$this->debug->error(__FUNCTION__, $message);
return $message;
}
}
$this->method = $method;
return $this;
}
|
php
|
public function setMethod($method = '')
{
if (mb_strlen($method) == 0) {
$this->debug->debug(__FUNCTION__, 'Set Default Method = GET if $method is does not exist');
$method = 'GET';
} else {
$method = strtoupper($method);
$validMethods = [
'GET',
'HEAD',
'PUT',
'POST',
'DELETE'
];
if (!in_array($method, $validMethods)) {
$message = "Error: " . __CLASS__ . ": The requested method (${method}) is not valid here";
$this->debug->error(__FUNCTION__, $message);
return $message;
}
}
$this->method = $method;
return $this;
}
|
[
"public",
"function",
"setMethod",
"(",
"$",
"method",
"=",
"''",
")",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"method",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Set Default Method = GET if $method is does not exist'",
")",
";",
"$",
"method",
"=",
"'GET'",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"method",
")",
";",
"$",
"validMethods",
"=",
"[",
"'GET'",
",",
"'HEAD'",
",",
"'PUT'",
",",
"'POST'",
",",
"'DELETE'",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
",",
"$",
"validMethods",
")",
")",
"{",
"$",
"message",
"=",
"\"Error: \"",
".",
"__CLASS__",
".",
"\": The requested method (${method}) is not valid here\"",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}",
"}",
"$",
"this",
"->",
"method",
"=",
"$",
"method",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the HTTP method
GET, HEAD, PUT, POST are valid
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:15
@param string $method Method to Request GET, HEAD, PUT, POST are valid
@return $this|string Method
|
[
"Set",
"the",
"HTTP",
"method",
"GET",
"HEAD",
"PUT",
"POST",
"are",
"valid"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L589-L613
|
25,687
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.setData
|
public function setData($data = [])
{
if (!is_array($data) && is_string($data)) {
$data = parse_str($data);
}
if (count($data) == 0) {
$this->data = [];
} else {
$this->data = $data;
}
$this->debug->debug(__FUNCTION__, 'Data into Request: ', $this->data);
}
|
php
|
public function setData($data = [])
{
if (!is_array($data) && is_string($data)) {
$data = parse_str($data);
}
if (count($data) == 0) {
$this->data = [];
} else {
$this->data = $data;
}
$this->debug->debug(__FUNCTION__, 'Data into Request: ', $this->data);
}
|
[
"public",
"function",
"setData",
"(",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"&&",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"parse_str",
"(",
"$",
"data",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"data",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"}",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Data into Request: '",
",",
"$",
"this",
"->",
"data",
")",
";",
"}"
] |
Set Data contents
Must be supplied as an array
@param array $data The contents to be sent to the target URL
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:18
|
[
"Set",
"Data",
"contents",
"Must",
"be",
"supplied",
"as",
"an",
"array"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L624-L635
|
25,688
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.setQueryString
|
public function setQueryString($query_string = [])
{
if (!is_array($query_string) && is_string($query_string)) {
$query_string = parse_str($query_string);
}
if (count($query_string) == 0) {
$this->query_string = [];
} else {
$this->query_string = $query_string;
}
}
|
php
|
public function setQueryString($query_string = [])
{
if (!is_array($query_string) && is_string($query_string)) {
$query_string = parse_str($query_string);
}
if (count($query_string) == 0) {
$this->query_string = [];
} else {
$this->query_string = $query_string;
}
}
|
[
"public",
"function",
"setQueryString",
"(",
"$",
"query_string",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"query_string",
")",
"&&",
"is_string",
"(",
"$",
"query_string",
")",
")",
"{",
"$",
"query_string",
"=",
"parse_str",
"(",
"$",
"query_string",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"query_string",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"query_string",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"query_string",
"=",
"$",
"query_string",
";",
"}",
"}"
] |
Set query string data
Must be supplied as an array
@param array $query_string The query string to be sent to the target URL
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 01:36
|
[
"Set",
"query",
"string",
"data",
"Must",
"be",
"supplied",
"as",
"an",
"array"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L646-L656
|
25,689
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.setCookies
|
public function setCookies($cookies = [])
{
if (!is_array($cookies)) {
$this->cookies = [];
} else {
$this->cookies = $cookies;
$this->trackCookies = TRUE;
}
}
|
php
|
public function setCookies($cookies = [])
{
if (!is_array($cookies)) {
$this->cookies = [];
} else {
$this->cookies = $cookies;
$this->trackCookies = TRUE;
}
}
|
[
"public",
"function",
"setCookies",
"(",
"$",
"cookies",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"cookies",
")",
")",
"{",
"$",
"this",
"->",
"cookies",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cookies",
"=",
"$",
"cookies",
";",
"$",
"this",
"->",
"trackCookies",
"=",
"TRUE",
";",
"}",
"}"
] |
Set any cookies to be included in the headers
Must be supplied as an array
@param array $cookies The array of cookies to be sent
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:18
|
[
"Set",
"any",
"cookies",
"to",
"be",
"included",
"in",
"the",
"headers",
"Must",
"be",
"supplied",
"as",
"an",
"array"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L685-L693
|
25,690
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.setTrackCookies
|
public function setTrackCookies($value = FALSE)
{
if (!$value) {
$this->trackCookies = FALSE;
} else {
$this->trackCookies = TRUE;
}
}
|
php
|
public function setTrackCookies($value = FALSE)
{
if (!$value) {
$this->trackCookies = FALSE;
} else {
$this->trackCookies = TRUE;
}
}
|
[
"public",
"function",
"setTrackCookies",
"(",
"$",
"value",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"trackCookies",
"=",
"FALSE",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"trackCookies",
"=",
"TRUE",
";",
"}",
"}"
] |
Should cookies be tracked?
@param boolean $value true to track cookies
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:18
|
[
"Should",
"cookies",
"be",
"tracked?"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L703-L710
|
25,691
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.setJsonPretty
|
public function setJsonPretty($value = FALSE)
{
if (!$value) {
$this->isJsonPretty = FALSE;
} else {
$this->isJsonPretty = TRUE;
}
}
|
php
|
public function setJsonPretty($value = FALSE)
{
if (!$value) {
$this->isJsonPretty = FALSE;
} else {
$this->isJsonPretty = TRUE;
}
}
|
[
"public",
"function",
"setJsonPretty",
"(",
"$",
"value",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"isJsonPretty",
"=",
"FALSE",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"isJsonPretty",
"=",
"TRUE",
";",
"}",
"}"
] |
Should JSON being sent be encoded in an easily readable format?
Only useful for debugging
@param boolean $value true for JSON_PRETTY_PRINT
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:17
|
[
"Should",
"JSON",
"being",
"sent",
"be",
"encoded",
"in",
"an",
"easily",
"readable",
"format?",
"Only",
"useful",
"for",
"debugging"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L755-L762
|
25,692
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.setVerifyPeer
|
public function setVerifyPeer($value = FALSE)
{
if (!$value) {
$this->verifyPeer = FALSE;
} else {
$this->verifyPeer = TRUE;
}
}
|
php
|
public function setVerifyPeer($value = FALSE)
{
if (!$value) {
$this->verifyPeer = FALSE;
} else {
$this->verifyPeer = TRUE;
}
}
|
[
"public",
"function",
"setVerifyPeer",
"(",
"$",
"value",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"verifyPeer",
"=",
"FALSE",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"verifyPeer",
"=",
"TRUE",
";",
"}",
"}"
] |
Should SSL peers be verified?
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:17
@param bool $value
|
[
"Should",
"SSL",
"peers",
"be",
"verified?"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L772-L779
|
25,693
|
nguyenanhung/requests
|
src/GetContents.php
|
GetContents.parseReturnHeaders
|
public function parseReturnHeaders($headers)
{
$head = [];
foreach ($headers as $k => $v) {
$t = explode(':', $v, 2);
if (isset($t[1])) {
$head[trim($t[0])] = trim($t[1]);
} else {
$head[] = $v;
if (preg_match("#HTTP/[0-9\.]+\s+([0-9]+)#", $v, $out)) {
$head['reponse_code'] = intval($out[1]);
}
}
}
$this->debug->debug(__FUNCTION__, 'Response Header: ', $head);
return $head;
}
|
php
|
public function parseReturnHeaders($headers)
{
$head = [];
foreach ($headers as $k => $v) {
$t = explode(':', $v, 2);
if (isset($t[1])) {
$head[trim($t[0])] = trim($t[1]);
} else {
$head[] = $v;
if (preg_match("#HTTP/[0-9\.]+\s+([0-9]+)#", $v, $out)) {
$head['reponse_code'] = intval($out[1]);
}
}
}
$this->debug->debug(__FUNCTION__, 'Response Header: ', $head);
return $head;
}
|
[
"public",
"function",
"parseReturnHeaders",
"(",
"$",
"headers",
")",
"{",
"$",
"head",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"t",
"=",
"explode",
"(",
"':'",
",",
"$",
"v",
",",
"2",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"t",
"[",
"1",
"]",
")",
")",
"{",
"$",
"head",
"[",
"trim",
"(",
"$",
"t",
"[",
"0",
"]",
")",
"]",
"=",
"trim",
"(",
"$",
"t",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"head",
"[",
"]",
"=",
"$",
"v",
";",
"if",
"(",
"preg_match",
"(",
"\"#HTTP/[0-9\\.]+\\s+([0-9]+)#\"",
",",
"$",
"v",
",",
"$",
"out",
")",
")",
"{",
"$",
"head",
"[",
"'reponse_code'",
"]",
"=",
"intval",
"(",
"$",
"out",
"[",
"1",
"]",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Response Header: '",
",",
"$",
"head",
")",
";",
"return",
"$",
"head",
";",
"}"
] |
Parse HTTP response headers
@author: 713uk13m <dev@nguyenanhung.com>
@time : 10/7/18 02:17
@param array $headers
@return array Header Response
|
[
"Parse",
"HTTP",
"response",
"headers"
] |
fae98614a256be6a3ff9bea34a273d182a3ae730
|
https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L806-L823
|
25,694
|
Hnto/nuki
|
src/Application/Application.php
|
Application.registerService
|
public function registerService($service, $name = '') {
if (empty($name)) {
$name = Assist::classNameShort($service);
}
static::$container->offsetSet(strtolower($name), $service);
}
|
php
|
public function registerService($service, $name = '') {
if (empty($name)) {
$name = Assist::classNameShort($service);
}
static::$container->offsetSet(strtolower($name), $service);
}
|
[
"public",
"function",
"registerService",
"(",
"$",
"service",
",",
"$",
"name",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"Assist",
"::",
"classNameShort",
"(",
"$",
"service",
")",
";",
"}",
"static",
"::",
"$",
"container",
"->",
"offsetSet",
"(",
"strtolower",
"(",
"$",
"name",
")",
",",
"$",
"service",
")",
";",
"}"
] |
Register a service
@param object $service
@param string $name
|
[
"Register",
"a",
"service"
] |
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
|
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Application/Application.php#L155-L161
|
25,695
|
Hnto/nuki
|
src/Application/Application.php
|
Application.run
|
public function run()
{
/** @var Request $request */
$request = $this->getService('request-handler');
//Process incoming request
$request->incoming($this);
//Register helper services
$helpers = static::$container['helpers'];
foreach($helpers as $helper => $options) {
$this->registerService(new $helper($options));
}
//Start session
$this->getService('session-handler')->start();
//Execute callback
if ($this->getService('router')->routeIsCallable()) {
$this->executeCallback();
return;
}
//Execute extenders
$this->executeUnitExtenders($this->getActiveUnit());
$this->executeService();
}
|
php
|
public function run()
{
/** @var Request $request */
$request = $this->getService('request-handler');
//Process incoming request
$request->incoming($this);
//Register helper services
$helpers = static::$container['helpers'];
foreach($helpers as $helper => $options) {
$this->registerService(new $helper($options));
}
//Start session
$this->getService('session-handler')->start();
//Execute callback
if ($this->getService('router')->routeIsCallable()) {
$this->executeCallback();
return;
}
//Execute extenders
$this->executeUnitExtenders($this->getActiveUnit());
$this->executeService();
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"/** @var Request $request */",
"$",
"request",
"=",
"$",
"this",
"->",
"getService",
"(",
"'request-handler'",
")",
";",
"//Process incoming request",
"$",
"request",
"->",
"incoming",
"(",
"$",
"this",
")",
";",
"//Register helper services",
"$",
"helpers",
"=",
"static",
"::",
"$",
"container",
"[",
"'helpers'",
"]",
";",
"foreach",
"(",
"$",
"helpers",
"as",
"$",
"helper",
"=>",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"registerService",
"(",
"new",
"$",
"helper",
"(",
"$",
"options",
")",
")",
";",
"}",
"//Start session",
"$",
"this",
"->",
"getService",
"(",
"'session-handler'",
")",
"->",
"start",
"(",
")",
";",
"//Execute callback",
"if",
"(",
"$",
"this",
"->",
"getService",
"(",
"'router'",
")",
"->",
"routeIsCallable",
"(",
")",
")",
"{",
"$",
"this",
"->",
"executeCallback",
"(",
")",
";",
"return",
";",
"}",
"//Execute extenders",
"$",
"this",
"->",
"executeUnitExtenders",
"(",
"$",
"this",
"->",
"getActiveUnit",
"(",
")",
")",
";",
"$",
"this",
"->",
"executeService",
"(",
")",
";",
"}"
] |
Run the application
- Incoming request will be handled
- Registration in the application will be done
- Session will be started
- Service will be executed
@return mixed
|
[
"Run",
"the",
"application",
"-",
"Incoming",
"request",
"will",
"be",
"handled",
"-",
"Registration",
"in",
"the",
"application",
"will",
"be",
"done",
"-",
"Session",
"will",
"be",
"started",
"-",
"Service",
"will",
"be",
"executed"
] |
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
|
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Application/Application.php#L278-L306
|
25,696
|
Hnto/nuki
|
src/Application/Application.php
|
Application.executeUnitExtenders
|
public function executeUnitExtenders(string $unit)
{
$extenders = $this->getService('unit-extenders');
if (!is_array($extenders)) {
return;
}
foreach ($extenders as $extender) {
if (!class_exists($extender)) {
continue;
}
/** @var Resolver $resolver */
$resolver = $this->getService('resolver');
try {
$resolver->resolve(
$extender,
Extender::EXECUTE_METHOD,
$this
);
} catch (Base $e) {
$this->getService('response-handler')
->setContent(new Content($e->getMessage()))
->send();
}
}
}
|
php
|
public function executeUnitExtenders(string $unit)
{
$extenders = $this->getService('unit-extenders');
if (!is_array($extenders)) {
return;
}
foreach ($extenders as $extender) {
if (!class_exists($extender)) {
continue;
}
/** @var Resolver $resolver */
$resolver = $this->getService('resolver');
try {
$resolver->resolve(
$extender,
Extender::EXECUTE_METHOD,
$this
);
} catch (Base $e) {
$this->getService('response-handler')
->setContent(new Content($e->getMessage()))
->send();
}
}
}
|
[
"public",
"function",
"executeUnitExtenders",
"(",
"string",
"$",
"unit",
")",
"{",
"$",
"extenders",
"=",
"$",
"this",
"->",
"getService",
"(",
"'unit-extenders'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"extenders",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"extenders",
"as",
"$",
"extender",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"extender",
")",
")",
"{",
"continue",
";",
"}",
"/** @var Resolver $resolver */",
"$",
"resolver",
"=",
"$",
"this",
"->",
"getService",
"(",
"'resolver'",
")",
";",
"try",
"{",
"$",
"resolver",
"->",
"resolve",
"(",
"$",
"extender",
",",
"Extender",
"::",
"EXECUTE_METHOD",
",",
"$",
"this",
")",
";",
"}",
"catch",
"(",
"Base",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"getService",
"(",
"'response-handler'",
")",
"->",
"setContent",
"(",
"new",
"Content",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
"->",
"send",
"(",
")",
";",
"}",
"}",
"}"
] |
Execute unit extenders
@param string $unit
|
[
"Execute",
"unit",
"extenders"
] |
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
|
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Application/Application.php#L313-L341
|
25,697
|
Hnto/nuki
|
src/Application/Application.php
|
Application.terminate
|
public function terminate()
{
/** @var EventHandler $eventHandler */
$eventHandler = $this->getService('event-handler');
$eventHandler->getEvent(TerminateApplication::class)->attach(new LogBeforeTerminate());
$eventHandler->getEvent(TerminateApplication::class)->attach(new ExitApplication());
$eventHandler->fire(TerminateApplication::class, ['app' => $this]);
}
|
php
|
public function terminate()
{
/** @var EventHandler $eventHandler */
$eventHandler = $this->getService('event-handler');
$eventHandler->getEvent(TerminateApplication::class)->attach(new LogBeforeTerminate());
$eventHandler->getEvent(TerminateApplication::class)->attach(new ExitApplication());
$eventHandler->fire(TerminateApplication::class, ['app' => $this]);
}
|
[
"public",
"function",
"terminate",
"(",
")",
"{",
"/** @var EventHandler $eventHandler */",
"$",
"eventHandler",
"=",
"$",
"this",
"->",
"getService",
"(",
"'event-handler'",
")",
";",
"$",
"eventHandler",
"->",
"getEvent",
"(",
"TerminateApplication",
"::",
"class",
")",
"->",
"attach",
"(",
"new",
"LogBeforeTerminate",
"(",
")",
")",
";",
"$",
"eventHandler",
"->",
"getEvent",
"(",
"TerminateApplication",
"::",
"class",
")",
"->",
"attach",
"(",
"new",
"ExitApplication",
"(",
")",
")",
";",
"$",
"eventHandler",
"->",
"fire",
"(",
"TerminateApplication",
"::",
"class",
",",
"[",
"'app'",
"=>",
"$",
"this",
"]",
")",
";",
"}"
] |
Fire TerminateApplication event
with two framework watchers.
One to log and one to actually exit.
|
[
"Fire",
"TerminateApplication",
"event",
"with",
"two",
"framework",
"watchers",
".",
"One",
"to",
"log",
"and",
"one",
"to",
"actually",
"exit",
"."
] |
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
|
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Application/Application.php#L391-L400
|
25,698
|
geniv/nette-general-form
|
src/GeneralControl.php
|
GeneralControl.createComponentForm
|
protected function createComponentForm(string $name): Form
{
$form = new Form($this, $name);
$form->setTranslator($this->translator);
$this->formContainer->getForm($form);
$form->onSuccess[] = $this->eventContainer;
return $form;
}
|
php
|
protected function createComponentForm(string $name): Form
{
$form = new Form($this, $name);
$form->setTranslator($this->translator);
$this->formContainer->getForm($form);
$form->onSuccess[] = $this->eventContainer;
return $form;
}
|
[
"protected",
"function",
"createComponentForm",
"(",
"string",
"$",
"name",
")",
":",
"Form",
"{",
"$",
"form",
"=",
"new",
"Form",
"(",
"$",
"this",
",",
"$",
"name",
")",
";",
"$",
"form",
"->",
"setTranslator",
"(",
"$",
"this",
"->",
"translator",
")",
";",
"$",
"this",
"->",
"formContainer",
"->",
"getForm",
"(",
"$",
"form",
")",
";",
"$",
"form",
"->",
"onSuccess",
"[",
"]",
"=",
"$",
"this",
"->",
"eventContainer",
";",
"return",
"$",
"form",
";",
"}"
] |
Create component form.
@param string $name
@return Form
|
[
"Create",
"component",
"form",
"."
] |
0d0548b63cf7db58c17ee12d6933f2dd995a64e6
|
https://github.com/geniv/nette-general-form/blob/0d0548b63cf7db58c17ee12d6933f2dd995a64e6/src/GeneralControl.php#L79-L87
|
25,699
|
ekyna/SettingBundle
|
Validator/Constraints/RedirectionValidator.php
|
RedirectionValidator.isPathAccessible
|
private function isPathAccessible($path)
{
$uri = $this->httpUtils->generateUri($this->requestStack->getMasterRequest(), $path);
/** @var \Buzz\Message\Response $res */
$res = $this->browser->get($uri);
if ($res->isSuccessful()) {
return true;
}
return false;
}
|
php
|
private function isPathAccessible($path)
{
$uri = $this->httpUtils->generateUri($this->requestStack->getMasterRequest(), $path);
/** @var \Buzz\Message\Response $res */
$res = $this->browser->get($uri);
if ($res->isSuccessful()) {
return true;
}
return false;
}
|
[
"private",
"function",
"isPathAccessible",
"(",
"$",
"path",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"httpUtils",
"->",
"generateUri",
"(",
"$",
"this",
"->",
"requestStack",
"->",
"getMasterRequest",
"(",
")",
",",
"$",
"path",
")",
";",
"/** @var \\Buzz\\Message\\Response $res */",
"$",
"res",
"=",
"$",
"this",
"->",
"browser",
"->",
"get",
"(",
"$",
"uri",
")",
";",
"if",
"(",
"$",
"res",
"->",
"isSuccessful",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns whether the given path is accessible through http or not.
@param $path
@return bool
|
[
"Returns",
"whether",
"the",
"given",
"path",
"is",
"accessible",
"through",
"http",
"or",
"not",
"."
] |
df58f83eb3a01ef56cd76ea73639322c581e75c1
|
https://github.com/ekyna/SettingBundle/blob/df58f83eb3a01ef56cd76ea73639322c581e75c1/Validator/Constraints/RedirectionValidator.php#L84-L95
|
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.