repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
drpdigital/json-api-parser
|
src/Str.php
|
Str.snakeCase
|
public static function snakeCase($value)
{
if (! ctype_lower($value)) {
$value = preg_replace('/\s+/u', '', ucwords($value));
$value = preg_replace('/-/u', '_', $value);
$value = mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $value), 'UTF-8');
}
return $value;
}
|
php
|
public static function snakeCase($value)
{
if (! ctype_lower($value)) {
$value = preg_replace('/\s+/u', '', ucwords($value));
$value = preg_replace('/-/u', '_', $value);
$value = mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $value), 'UTF-8');
}
return $value;
}
|
[
"public",
"static",
"function",
"snakeCase",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"ctype_lower",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"'/\\s+/u'",
",",
"''",
",",
"ucwords",
"(",
"$",
"value",
")",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'/-/u'",
",",
"'_'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"mb_strtolower",
"(",
"preg_replace",
"(",
"'/(.)(?=[A-Z])/u'",
",",
"'$1_'",
",",
"$",
"value",
")",
",",
"'UTF-8'",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Convert given input into snake case.
@param string $value
@return string
|
[
"Convert",
"given",
"input",
"into",
"snake",
"case",
"."
] |
train
|
https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/Str.php#L13-L23
|
phpmob/twig-modify-bundle
|
Modifier/Modify.php
|
Modify.modify
|
public static function modify($content, $type)
{
if (!array_key_exists($type, self::$types)) {
throw new \LogicException(sprintf("Unsuported type `%s` of minifier.", $type));
}
$modifier = self::$types[$type];
if (!$modifier['enabled']) {
return $content;
}
$cacheId = md5($content);
if (self::$cache && self::$cache->hasItem($cacheId)) {
return self::$cache->getItem($cacheId)->get();
}
$content = call_user_func_array(
[$modifier['class'], $modifier['method']],
[$content, $modifier['options']]
);
self::$cache && self::$cache->save(self::$cache->getItem($cacheId)->set($content));
return $content;
}
|
php
|
public static function modify($content, $type)
{
if (!array_key_exists($type, self::$types)) {
throw new \LogicException(sprintf("Unsuported type `%s` of minifier.", $type));
}
$modifier = self::$types[$type];
if (!$modifier['enabled']) {
return $content;
}
$cacheId = md5($content);
if (self::$cache && self::$cache->hasItem($cacheId)) {
return self::$cache->getItem($cacheId)->get();
}
$content = call_user_func_array(
[$modifier['class'], $modifier['method']],
[$content, $modifier['options']]
);
self::$cache && self::$cache->save(self::$cache->getItem($cacheId)->set($content));
return $content;
}
|
[
"public",
"static",
"function",
"modify",
"(",
"$",
"content",
",",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"self",
"::",
"$",
"types",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"\"Unsuported type `%s` of minifier.\"",
",",
"$",
"type",
")",
")",
";",
"}",
"$",
"modifier",
"=",
"self",
"::",
"$",
"types",
"[",
"$",
"type",
"]",
";",
"if",
"(",
"!",
"$",
"modifier",
"[",
"'enabled'",
"]",
")",
"{",
"return",
"$",
"content",
";",
"}",
"$",
"cacheId",
"=",
"md5",
"(",
"$",
"content",
")",
";",
"if",
"(",
"self",
"::",
"$",
"cache",
"&&",
"self",
"::",
"$",
"cache",
"->",
"hasItem",
"(",
"$",
"cacheId",
")",
")",
"{",
"return",
"self",
"::",
"$",
"cache",
"->",
"getItem",
"(",
"$",
"cacheId",
")",
"->",
"get",
"(",
")",
";",
"}",
"$",
"content",
"=",
"call_user_func_array",
"(",
"[",
"$",
"modifier",
"[",
"'class'",
"]",
",",
"$",
"modifier",
"[",
"'method'",
"]",
"]",
",",
"[",
"$",
"content",
",",
"$",
"modifier",
"[",
"'options'",
"]",
"]",
")",
";",
"self",
"::",
"$",
"cache",
"&&",
"self",
"::",
"$",
"cache",
"->",
"save",
"(",
"self",
"::",
"$",
"cache",
"->",
"getItem",
"(",
"$",
"cacheId",
")",
"->",
"set",
"(",
"$",
"content",
")",
")",
";",
"return",
"$",
"content",
";",
"}"
] |
@param $content
@param $type
@return mixed
@throws \Psr\Cache\InvalidArgumentException
|
[
"@param",
"$content",
"@param",
"$type",
"@return",
"mixed"
] |
train
|
https://github.com/phpmob/twig-modify-bundle/blob/30b70ca3ea7b902f2f29c8457cd4f8da45b1d29e/Modifier/Modify.php#L54-L80
|
jasny/router
|
src/Router/Helper/NotFound.php
|
NotFound.notFound
|
protected function notFound(ServerRequestInterface $request, ResponseInterface $response)
{
$finalResponse = $response
->withProtocolVersion($request->getProtocolVersion())
->withStatus(404)
->withHeader('Content-Type', 'text/plain');
$finalResponse->getBody()->write("Not found");
return $finalResponse;
}
|
php
|
protected function notFound(ServerRequestInterface $request, ResponseInterface $response)
{
$finalResponse = $response
->withProtocolVersion($request->getProtocolVersion())
->withStatus(404)
->withHeader('Content-Type', 'text/plain');
$finalResponse->getBody()->write("Not found");
return $finalResponse;
}
|
[
"protected",
"function",
"notFound",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"finalResponse",
"=",
"$",
"response",
"->",
"withProtocolVersion",
"(",
"$",
"request",
"->",
"getProtocolVersion",
"(",
")",
")",
"->",
"withStatus",
"(",
"404",
")",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"'text/plain'",
")",
";",
"$",
"finalResponse",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"\"Not found\"",
")",
";",
"return",
"$",
"finalResponse",
";",
"}"
] |
Return with a 404 not found response
@param ServerRequestInterface $request
@param ResponseInterface $response
@return ResponseInterface
|
[
"Return",
"with",
"a",
"404",
"not",
"found",
"response"
] |
train
|
https://github.com/jasny/router/blob/4c776665ba343150b442c21893946e3d54190896/src/Router/Helper/NotFound.php#L20-L30
|
o2system/html
|
src/Dom/Beautifier.php
|
Beautifier.setElementType
|
public function setElementType($elementName, $type)
{
if ($type === static::ELEMENT_TYPE_BLOCK) {
$this->inlineElements = array_diff($this->inlineElements, [$elementName]);
} else {
if ($type === static::ELEMENT_TYPE_INLINE) {
$this->inlineElements[] = $elementName;
}
}
if ($this->inlineElements) {
$this->inlineElements = array_unique($this->inlineElements);
}
}
|
php
|
public function setElementType($elementName, $type)
{
if ($type === static::ELEMENT_TYPE_BLOCK) {
$this->inlineElements = array_diff($this->inlineElements, [$elementName]);
} else {
if ($type === static::ELEMENT_TYPE_INLINE) {
$this->inlineElements[] = $elementName;
}
}
if ($this->inlineElements) {
$this->inlineElements = array_unique($this->inlineElements);
}
}
|
[
"public",
"function",
"setElementType",
"(",
"$",
"elementName",
",",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"static",
"::",
"ELEMENT_TYPE_BLOCK",
")",
"{",
"$",
"this",
"->",
"inlineElements",
"=",
"array_diff",
"(",
"$",
"this",
"->",
"inlineElements",
",",
"[",
"$",
"elementName",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"type",
"===",
"static",
"::",
"ELEMENT_TYPE_INLINE",
")",
"{",
"$",
"this",
"->",
"inlineElements",
"[",
"]",
"=",
"$",
"elementName",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"inlineElements",
")",
"{",
"$",
"this",
"->",
"inlineElements",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"inlineElements",
")",
";",
"}",
"}"
] |
Beautifier::setElementType
@param string $elementName
@param int $type FormatOutput::ELEMENT_TYPE_BLOCK | FormatOutput::ELEMENT_TYPE_INLINE
|
[
"Beautifier",
"::",
"setElementType"
] |
train
|
https://github.com/o2system/html/blob/b7336fb45d42603ce1064b25572a05d495887670/src/Dom/Beautifier.php#L128-L141
|
o2system/html
|
src/Dom/Beautifier.php
|
Beautifier.format
|
public function format($source)
{
// We does not indent <script> body. Instead, it temporary removes it from the code, indents the input, and restores the script body.
$tempScriptElements = [];
if (preg_match_all('/<script\b[^>]*>([\s\S]*?)<\/script>/mi', $source, $matches)) {
$tempScriptElements = $matches[ 0 ];
foreach ($matches[ 0 ] as $i => $match) {
$source = str_replace($match, '<script>' . ($i + 1) . '</script>', $source);
}
}
// Removing double whitespaces to make the source code easier to read.
// With exception of <pre>/ CSS white-space changing the default behaviour, double whitespace is meaningless in HTML output.
// This reason alone is sufficient not to use indentation in production.
$source = str_replace("\t", '', $source);
$source = preg_replace('/\s{2,}/', ' ', $source);
// Remove inline elements and replace them with text entities.
$tempInlineElements = [];
if (preg_match_all(
'/<(' . implode('|', $this->inlineElements) . ')[^>]*>(?:[^<]*)<\/\1>/',
$source,
$matches
)) {
$tempInlineElements = $matches[ 0 ];
foreach ($matches[ 0 ] as $i => $match) {
$source = str_replace($match, 'ᐃ' . ($i + 1) . 'ᐃ', $source);
}
}
$output = '';
$nextLineIndentationLevel = 0;
do {
$indentationLevel = $nextLineIndentationLevel;
$patterns = [
// block tag
'/^(<([a-z]+)(?:[^>]*)>(?:[^<]*)<\/(?:\2)>)/' => static::MATCH_INDENT_NO,
// DOCTYPE
'/^<!([^>]*)>/' => static::MATCH_INDENT_NO,
// tag with implied closing
'/^<(input|link|meta|base|br|img|hr)([^>]*)>/' => static::MATCH_INDENT_NO,
// opening tag
'/^<[^\/]([^>]*)>/' => static::MATCH_INDENT_INCREASE,
// closing tag
'/^<\/([^>]*)>/' => static::MATCH_INDENT_DECREASE,
// self-closing tag
'/^<(.+)\/>/' => static::MATCH_INDENT_DECREASE,
// whitespace
'/^(\s+)/' => static::MATCH_DISCARD,
// text node
'/([^<]+)/' => static::MATCH_INDENT_NO,
];
foreach ($patterns as $pattern => $rule) {
if ($match = preg_match($pattern, $source, $matches)) {
if (function_exists('mb_substr')) {
$source = mb_substr($source, mb_strlen($matches[ 0 ]));
} else {
$source = substr($source, strlen($matches[ 0 ]));
}
if ($rule === static::MATCH_DISCARD) {
break;
}
if ($rule === static::MATCH_INDENT_NO) {
} else {
if ($rule === static::MATCH_INDENT_DECREASE) {
$nextLineIndentationLevel--;
$indentationLevel--;
} else {
$nextLineIndentationLevel++;
}
}
if ($indentationLevel < 0) {
$indentationLevel = 0;
}
$output .= str_repeat($this->indentCharacter, $indentationLevel) . $matches[ 0 ] . "\n";
break;
}
}
} while ($match);
$output = preg_replace('/(<(\w+)[^>]*>)\s*(<\/\2>)/', '\\1\\3', $output);
foreach ($tempScriptElements as $i => $original) {
$output = str_replace('<script>' . ($i + 1) . '</script>', $original, $output);
}
foreach ($tempInlineElements as $i => $original) {
$output = str_replace('ᐃ' . ($i + 1) . 'ᐃ', $original, $output);
}
return trim($output);
}
|
php
|
public function format($source)
{
// We does not indent <script> body. Instead, it temporary removes it from the code, indents the input, and restores the script body.
$tempScriptElements = [];
if (preg_match_all('/<script\b[^>]*>([\s\S]*?)<\/script>/mi', $source, $matches)) {
$tempScriptElements = $matches[ 0 ];
foreach ($matches[ 0 ] as $i => $match) {
$source = str_replace($match, '<script>' . ($i + 1) . '</script>', $source);
}
}
// Removing double whitespaces to make the source code easier to read.
// With exception of <pre>/ CSS white-space changing the default behaviour, double whitespace is meaningless in HTML output.
// This reason alone is sufficient not to use indentation in production.
$source = str_replace("\t", '', $source);
$source = preg_replace('/\s{2,}/', ' ', $source);
// Remove inline elements and replace them with text entities.
$tempInlineElements = [];
if (preg_match_all(
'/<(' . implode('|', $this->inlineElements) . ')[^>]*>(?:[^<]*)<\/\1>/',
$source,
$matches
)) {
$tempInlineElements = $matches[ 0 ];
foreach ($matches[ 0 ] as $i => $match) {
$source = str_replace($match, 'ᐃ' . ($i + 1) . 'ᐃ', $source);
}
}
$output = '';
$nextLineIndentationLevel = 0;
do {
$indentationLevel = $nextLineIndentationLevel;
$patterns = [
// block tag
'/^(<([a-z]+)(?:[^>]*)>(?:[^<]*)<\/(?:\2)>)/' => static::MATCH_INDENT_NO,
// DOCTYPE
'/^<!([^>]*)>/' => static::MATCH_INDENT_NO,
// tag with implied closing
'/^<(input|link|meta|base|br|img|hr)([^>]*)>/' => static::MATCH_INDENT_NO,
// opening tag
'/^<[^\/]([^>]*)>/' => static::MATCH_INDENT_INCREASE,
// closing tag
'/^<\/([^>]*)>/' => static::MATCH_INDENT_DECREASE,
// self-closing tag
'/^<(.+)\/>/' => static::MATCH_INDENT_DECREASE,
// whitespace
'/^(\s+)/' => static::MATCH_DISCARD,
// text node
'/([^<]+)/' => static::MATCH_INDENT_NO,
];
foreach ($patterns as $pattern => $rule) {
if ($match = preg_match($pattern, $source, $matches)) {
if (function_exists('mb_substr')) {
$source = mb_substr($source, mb_strlen($matches[ 0 ]));
} else {
$source = substr($source, strlen($matches[ 0 ]));
}
if ($rule === static::MATCH_DISCARD) {
break;
}
if ($rule === static::MATCH_INDENT_NO) {
} else {
if ($rule === static::MATCH_INDENT_DECREASE) {
$nextLineIndentationLevel--;
$indentationLevel--;
} else {
$nextLineIndentationLevel++;
}
}
if ($indentationLevel < 0) {
$indentationLevel = 0;
}
$output .= str_repeat($this->indentCharacter, $indentationLevel) . $matches[ 0 ] . "\n";
break;
}
}
} while ($match);
$output = preg_replace('/(<(\w+)[^>]*>)\s*(<\/\2>)/', '\\1\\3', $output);
foreach ($tempScriptElements as $i => $original) {
$output = str_replace('<script>' . ($i + 1) . '</script>', $original, $output);
}
foreach ($tempInlineElements as $i => $original) {
$output = str_replace('ᐃ' . ($i + 1) . 'ᐃ', $original, $output);
}
return trim($output);
}
|
[
"public",
"function",
"format",
"(",
"$",
"source",
")",
"{",
"// We does not indent <script> body. Instead, it temporary removes it from the code, indents the input, and restores the script body.\r",
"$",
"tempScriptElements",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match_all",
"(",
"'/<script\\b[^>]*>([\\s\\S]*?)<\\/script>/mi'",
",",
"$",
"source",
",",
"$",
"matches",
")",
")",
"{",
"$",
"tempScriptElements",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"i",
"=>",
"$",
"match",
")",
"{",
"$",
"source",
"=",
"str_replace",
"(",
"$",
"match",
",",
"'<script>'",
".",
"(",
"$",
"i",
"+",
"1",
")",
".",
"'</script>'",
",",
"$",
"source",
")",
";",
"}",
"}",
"// Removing double whitespaces to make the source code easier to read.\r",
"// With exception of <pre>/ CSS white-space changing the default behaviour, double whitespace is meaningless in HTML output.\r",
"// This reason alone is sufficient not to use indentation in production.\r",
"$",
"source",
"=",
"str_replace",
"(",
"\"\\t\"",
",",
"''",
",",
"$",
"source",
")",
";",
"$",
"source",
"=",
"preg_replace",
"(",
"'/\\s{2,}/'",
",",
"' '",
",",
"$",
"source",
")",
";",
"// Remove inline elements and replace them with text entities.\r",
"$",
"tempInlineElements",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match_all",
"(",
"'/<('",
".",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"inlineElements",
")",
".",
"')[^>]*>(?:[^<]*)<\\/\\1>/'",
",",
"$",
"source",
",",
"$",
"matches",
")",
")",
"{",
"$",
"tempInlineElements",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"i",
"=>",
"$",
"match",
")",
"{",
"$",
"source",
"=",
"str_replace",
"(",
"$",
"match",
",",
"'ᐃ' .",
"(",
"i",
" ",
"+",
"1",
" ",
".",
"'",
"', $s",
"o",
"r",
"ce);\r",
"",
"",
"}",
"}",
"$",
"output",
"=",
"''",
";",
"$",
"nextLineIndentationLevel",
"=",
"0",
";",
"do",
"{",
"$",
"indentationLevel",
"=",
"$",
"nextLineIndentationLevel",
";",
"$",
"patterns",
"=",
"[",
"// block tag\r",
"'/^(<([a-z]+)(?:[^>]*)>(?:[^<]*)<\\/(?:\\2)>)/'",
"=>",
"static",
"::",
"MATCH_INDENT_NO",
",",
"// DOCTYPE\r",
"'/^<!([^>]*)>/'",
"=>",
"static",
"::",
"MATCH_INDENT_NO",
",",
"// tag with implied closing\r",
"'/^<(input|link|meta|base|br|img|hr)([^>]*)>/'",
"=>",
"static",
"::",
"MATCH_INDENT_NO",
",",
"// opening tag\r",
"'/^<[^\\/]([^>]*)>/'",
"=>",
"static",
"::",
"MATCH_INDENT_INCREASE",
",",
"// closing tag\r",
"'/^<\\/([^>]*)>/'",
"=>",
"static",
"::",
"MATCH_INDENT_DECREASE",
",",
"// self-closing tag\r",
"'/^<(.+)\\/>/'",
"=>",
"static",
"::",
"MATCH_INDENT_DECREASE",
",",
"// whitespace\r",
"'/^(\\s+)/'",
"=>",
"static",
"::",
"MATCH_DISCARD",
",",
"// text node\r",
"'/([^<]+)/'",
"=>",
"static",
"::",
"MATCH_INDENT_NO",
",",
"]",
";",
"foreach",
"(",
"$",
"patterns",
"as",
"$",
"pattern",
"=>",
"$",
"rule",
")",
"{",
"if",
"(",
"$",
"match",
"=",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"source",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mb_substr'",
")",
")",
"{",
"$",
"source",
"=",
"mb_substr",
"(",
"$",
"source",
",",
"mb_strlen",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"source",
"=",
"substr",
"(",
"$",
"source",
",",
"strlen",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"rule",
"===",
"static",
"::",
"MATCH_DISCARD",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"rule",
"===",
"static",
"::",
"MATCH_INDENT_NO",
")",
"{",
"}",
"else",
"{",
"if",
"(",
"$",
"rule",
"===",
"static",
"::",
"MATCH_INDENT_DECREASE",
")",
"{",
"$",
"nextLineIndentationLevel",
"--",
";",
"$",
"indentationLevel",
"--",
";",
"}",
"else",
"{",
"$",
"nextLineIndentationLevel",
"++",
";",
"}",
"}",
"if",
"(",
"$",
"indentationLevel",
"<",
"0",
")",
"{",
"$",
"indentationLevel",
"=",
"0",
";",
"}",
"$",
"output",
".=",
"str_repeat",
"(",
"$",
"this",
"->",
"indentCharacter",
",",
"$",
"indentationLevel",
")",
".",
"$",
"matches",
"[",
"0",
"]",
".",
"\"\\n\"",
";",
"break",
";",
"}",
"}",
"}",
"while",
"(",
"$",
"match",
")",
";",
"$",
"output",
"=",
"preg_replace",
"(",
"'/(<(\\w+)[^>]*>)\\s*(<\\/\\2>)/'",
",",
"'\\\\1\\\\3'",
",",
"$",
"output",
")",
";",
"foreach",
"(",
"$",
"tempScriptElements",
"as",
"$",
"i",
"=>",
"$",
"original",
")",
"{",
"$",
"output",
"=",
"str_replace",
"(",
"'<script>'",
".",
"(",
"$",
"i",
"+",
"1",
")",
".",
"'</script>'",
",",
"$",
"original",
",",
"$",
"output",
")",
";",
"}",
"foreach",
"(",
"$",
"tempInlineElements",
"as",
"$",
"i",
"=>",
"$",
"original",
")",
"{",
"$",
"output",
"=",
"str_replace",
"(",
"'ᐃ' .",
"(",
"i",
" ",
"+",
"1",
" ",
".",
"'",
"', $o",
"r",
"g",
"inal, $o",
"u",
"p",
"ut);\r",
"",
"",
"}",
"return",
"trim",
"(",
"$",
"output",
")",
";",
"}"
] |
Beautifier::format
@param $source
@return string
|
[
"Beautifier",
"::",
"format"
] |
train
|
https://github.com/o2system/html/blob/b7336fb45d42603ce1064b25572a05d495887670/src/Dom/Beautifier.php#L152-L257
|
blast-project/CoreBundle
|
src/Profiler/Collector.php
|
Collector.collect
|
public function collect($name, $data, $destination = DataCollection::DESTINATION_PROFILER, $type = null)
{
$this->collectedKeys[] = $name;
$dataCollection = new DataCollection($name, $data, $destination, $type);
$this->data[$this->handleDataKey($name)] = $dataCollection;
return $this;
}
|
php
|
public function collect($name, $data, $destination = DataCollection::DESTINATION_PROFILER, $type = null)
{
$this->collectedKeys[] = $name;
$dataCollection = new DataCollection($name, $data, $destination, $type);
$this->data[$this->handleDataKey($name)] = $dataCollection;
return $this;
}
|
[
"public",
"function",
"collect",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"destination",
"=",
"DataCollection",
"::",
"DESTINATION_PROFILER",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"collectedKeys",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"dataCollection",
"=",
"new",
"DataCollection",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"destination",
",",
"$",
"type",
")",
";",
"$",
"this",
"->",
"data",
"[",
"$",
"this",
"->",
"handleDataKey",
"(",
"$",
"name",
")",
"]",
"=",
"$",
"dataCollection",
";",
"return",
"$",
"this",
";",
"}"
] |
@param string $name
@param mixed $data
@param string $destination
@param string $type
@return $this
|
[
"@param",
"string",
"$name",
"@param",
"mixed",
"$data",
"@param",
"string",
"$destination",
"@param",
"string",
"$type"
] |
train
|
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Profiler/Collector.php#L41-L49
|
blast-project/CoreBundle
|
src/Profiler/Collector.php
|
Collector.collectOnce
|
public function collectOnce($name, $data, $destination = DataCollection::DESTINATION_PROFILER, $type = null)
{
if (!in_array($name, $this->collectedKeys)) {
$this->collectedKeys[] = $name;
$dataCollection = new DataCollection($name, $data, $destination, $type);
$this->data[$this->handleDataKey($name)] = $dataCollection;
}
return $this;
}
|
php
|
public function collectOnce($name, $data, $destination = DataCollection::DESTINATION_PROFILER, $type = null)
{
if (!in_array($name, $this->collectedKeys)) {
$this->collectedKeys[] = $name;
$dataCollection = new DataCollection($name, $data, $destination, $type);
$this->data[$this->handleDataKey($name)] = $dataCollection;
}
return $this;
}
|
[
"public",
"function",
"collectOnce",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"destination",
"=",
"DataCollection",
"::",
"DESTINATION_PROFILER",
",",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"collectedKeys",
")",
")",
"{",
"$",
"this",
"->",
"collectedKeys",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"dataCollection",
"=",
"new",
"DataCollection",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"destination",
",",
"$",
"type",
")",
";",
"$",
"this",
"->",
"data",
"[",
"$",
"this",
"->",
"handleDataKey",
"(",
"$",
"name",
")",
"]",
"=",
"$",
"dataCollection",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
@param string $name
@param mixed $data
@param string $destination
@param string $type
@return $this
|
[
"@param",
"string",
"$name",
"@param",
"mixed",
"$data",
"@param",
"string",
"$destination",
"@param",
"string",
"$type"
] |
train
|
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Profiler/Collector.php#L59-L68
|
awesomite/chariot
|
src/Pattern/StdPatterns/AbstractPattern.php
|
AbstractPattern.newInvalidToUrl
|
protected function newInvalidToUrl($data)
{
switch (\gettype($data)) {
case 'string':
$type = \sprintf('(string) %s', \var_export($data, true));
break;
case 'object':
$type = \sprintf('(object) %s', \get_class($data));
break;
case 'integer':
case 'double':
case 'float':
$type = \sprintf('(%s) %s', \gettype($data), \var_export($data, true));
break;
default:
$type = \gettype($data);
break;
}
return new PatternException(
\sprintf('Value %s cannot be converted to url param (%s)', $type, static::class),
PatternException::CODE_TO_URL
);
}
|
php
|
protected function newInvalidToUrl($data)
{
switch (\gettype($data)) {
case 'string':
$type = \sprintf('(string) %s', \var_export($data, true));
break;
case 'object':
$type = \sprintf('(object) %s', \get_class($data));
break;
case 'integer':
case 'double':
case 'float':
$type = \sprintf('(%s) %s', \gettype($data), \var_export($data, true));
break;
default:
$type = \gettype($data);
break;
}
return new PatternException(
\sprintf('Value %s cannot be converted to url param (%s)', $type, static::class),
PatternException::CODE_TO_URL
);
}
|
[
"protected",
"function",
"newInvalidToUrl",
"(",
"$",
"data",
")",
"{",
"switch",
"(",
"\\",
"gettype",
"(",
"$",
"data",
")",
")",
"{",
"case",
"'string'",
":",
"$",
"type",
"=",
"\\",
"sprintf",
"(",
"'(string) %s'",
",",
"\\",
"var_export",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"'object'",
":",
"$",
"type",
"=",
"\\",
"sprintf",
"(",
"'(object) %s'",
",",
"\\",
"get_class",
"(",
"$",
"data",
")",
")",
";",
"break",
";",
"case",
"'integer'",
":",
"case",
"'double'",
":",
"case",
"'float'",
":",
"$",
"type",
"=",
"\\",
"sprintf",
"(",
"'(%s) %s'",
",",
"\\",
"gettype",
"(",
"$",
"data",
")",
",",
"\\",
"var_export",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"break",
";",
"default",
":",
"$",
"type",
"=",
"\\",
"gettype",
"(",
"$",
"data",
")",
";",
"break",
";",
"}",
"return",
"new",
"PatternException",
"(",
"\\",
"sprintf",
"(",
"'Value %s cannot be converted to url param (%s)'",
",",
"$",
"type",
",",
"static",
"::",
"class",
")",
",",
"PatternException",
"::",
"CODE_TO_URL",
")",
";",
"}"
] |
@param $data
@return PatternException
|
[
"@param",
"$data"
] |
train
|
https://github.com/awesomite/chariot/blob/3229e38537b857be1d352308ba340dc530b12afb/src/Pattern/StdPatterns/AbstractPattern.php#L32-L58
|
chriswoodford/foursquare-php
|
lib/TheTwelve/Foursquare/AuthenticationGateway.php
|
AuthenticationGateway.initiateLogin
|
public function initiateLogin()
{
if (!$this->canInitiateLogin()) {
throw new \RuntimeException(
'Unable to initiate login'
);
}
$uri = $this->getAuthenticationUri();
return $this->redirector->redirect($uri);
}
|
php
|
public function initiateLogin()
{
if (!$this->canInitiateLogin()) {
throw new \RuntimeException(
'Unable to initiate login'
);
}
$uri = $this->getAuthenticationUri();
return $this->redirector->redirect($uri);
}
|
[
"public",
"function",
"initiateLogin",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"canInitiateLogin",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to initiate login'",
")",
";",
"}",
"$",
"uri",
"=",
"$",
"this",
"->",
"getAuthenticationUri",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirector",
"->",
"redirect",
"(",
"$",
"uri",
")",
";",
"}"
] |
initiate the login process
@see https://developer.foursquare.com/overview/auth.html
@throws \RuntimeException
@return mixed
|
[
"initiate",
"the",
"login",
"process"
] |
train
|
https://github.com/chriswoodford/foursquare-php/blob/edbfcba2993a101ead8f381394742a4689aec398/lib/TheTwelve/Foursquare/AuthenticationGateway.php#L78-L90
|
chriswoodford/foursquare-php
|
lib/TheTwelve/Foursquare/AuthenticationGateway.php
|
AuthenticationGateway.getAuthenticationUri
|
public function getAuthenticationUri()
{
if (!$this->canBuildAuthenticationUri()) {
throw new \RuntimeException(
'Cannot build authentication uri, dependencies are missing'
);
}
$uriParams = array(
'client_id' => $this->clientId,
'response_type' => 'code',
'redirect_uri' => $this->redirectUri,
);
return $this->authorizeUri . '?' . http_build_query($uriParams);
}
|
php
|
public function getAuthenticationUri()
{
if (!$this->canBuildAuthenticationUri()) {
throw new \RuntimeException(
'Cannot build authentication uri, dependencies are missing'
);
}
$uriParams = array(
'client_id' => $this->clientId,
'response_type' => 'code',
'redirect_uri' => $this->redirectUri,
);
return $this->authorizeUri . '?' . http_build_query($uriParams);
}
|
[
"public",
"function",
"getAuthenticationUri",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"canBuildAuthenticationUri",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot build authentication uri, dependencies are missing'",
")",
";",
"}",
"$",
"uriParams",
"=",
"array",
"(",
"'client_id'",
"=>",
"$",
"this",
"->",
"clientId",
",",
"'response_type'",
"=>",
"'code'",
",",
"'redirect_uri'",
"=>",
"$",
"this",
"->",
"redirectUri",
",",
")",
";",
"return",
"$",
"this",
"->",
"authorizeUri",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"uriParams",
")",
";",
"}"
] |
build the foursquare authentication uri that users are
forwarded to for authentication
@see https://developer.foursquare.com/overview/auth.html
@return string
|
[
"build",
"the",
"foursquare",
"authentication",
"uri",
"that",
"users",
"are",
"forwarded",
"to",
"for",
"authentication"
] |
train
|
https://github.com/chriswoodford/foursquare-php/blob/edbfcba2993a101ead8f381394742a4689aec398/lib/TheTwelve/Foursquare/AuthenticationGateway.php#L98-L115
|
chriswoodford/foursquare-php
|
lib/TheTwelve/Foursquare/AuthenticationGateway.php
|
AuthenticationGateway.authenticateUser
|
public function authenticateUser($code)
{
if (!$this->canAuthenticateUser()) {
throw new \RuntimeException(
'Cannot authenticate user, dependencies are missing'
);
}
if (!$this->codeIsValid($code)) {
throw new \InvalidArgumentException('Foursquare code is invalid');
}
$response = json_decode($this->httpClient->get($this->accessTokenUri, array(
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectUri,
'code' => $code,
)));
$this->token = isset($response->access_token)
? $response->access_token : null;
return $this->token;
}
|
php
|
public function authenticateUser($code)
{
if (!$this->canAuthenticateUser()) {
throw new \RuntimeException(
'Cannot authenticate user, dependencies are missing'
);
}
if (!$this->codeIsValid($code)) {
throw new \InvalidArgumentException('Foursquare code is invalid');
}
$response = json_decode($this->httpClient->get($this->accessTokenUri, array(
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectUri,
'code' => $code,
)));
$this->token = isset($response->access_token)
? $response->access_token : null;
return $this->token;
}
|
[
"public",
"function",
"authenticateUser",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"canAuthenticateUser",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot authenticate user, dependencies are missing'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"codeIsValid",
"(",
"$",
"code",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Foursquare code is invalid'",
")",
";",
"}",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"$",
"this",
"->",
"accessTokenUri",
",",
"array",
"(",
"'client_id'",
"=>",
"$",
"this",
"->",
"clientId",
",",
"'client_secret'",
"=>",
"$",
"this",
"->",
"clientSecret",
",",
"'grant_type'",
"=>",
"'authorization_code'",
",",
"'redirect_uri'",
"=>",
"$",
"this",
"->",
"redirectUri",
",",
"'code'",
"=>",
"$",
"code",
",",
")",
")",
")",
";",
"$",
"this",
"->",
"token",
"=",
"isset",
"(",
"$",
"response",
"->",
"access_token",
")",
"?",
"$",
"response",
"->",
"access_token",
":",
"null",
";",
"return",
"$",
"this",
"->",
"token",
";",
"}"
] |
authenticate the user with the response code
@see https://developer.foursquare.com/overview/auth.html
@param string $code
@throws \RuntimeException
@throws \InvalidArgumentException
@return string
|
[
"authenticate",
"the",
"user",
"with",
"the",
"response",
"code"
] |
train
|
https://github.com/chriswoodford/foursquare-php/blob/edbfcba2993a101ead8f381394742a4689aec398/lib/TheTwelve/Foursquare/AuthenticationGateway.php#L125-L151
|
yosmanyga/resource
|
src/Yosmanyga/Resource/Cacher/Checker/FileVersionChecker.php
|
FileVersionChecker.add
|
public function add(Resource $resource)
{
$this->storer->add(
filemtime($resource->getMetadata('file')),
$resource
);
}
|
php
|
public function add(Resource $resource)
{
$this->storer->add(
filemtime($resource->getMetadata('file')),
$resource
);
}
|
[
"public",
"function",
"add",
"(",
"Resource",
"$",
"resource",
")",
"{",
"$",
"this",
"->",
"storer",
"->",
"add",
"(",
"filemtime",
"(",
"$",
"resource",
"->",
"getMetadata",
"(",
"'file'",
")",
")",
",",
"$",
"resource",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Cacher/Checker/FileVersionChecker.php#L39-L45
|
sulu/SuluSalesShippingBundle
|
src/Sulu/Bundle/Sales/OrderBundle/Entity/BaseOrder.php
|
BaseOrder.updateTotalNetPrice
|
public function updateTotalNetPrice()
{
if (!$this->getItems()) {
return;
}
$sum = 0;
foreach ($this->getItems() as $item) {
$sum += $item->getTotalNetPrice();
}
$this->setTotalNetPrice($sum);
}
|
php
|
public function updateTotalNetPrice()
{
if (!$this->getItems()) {
return;
}
$sum = 0;
foreach ($this->getItems() as $item) {
$sum += $item->getTotalNetPrice();
}
$this->setTotalNetPrice($sum);
}
|
[
"public",
"function",
"updateTotalNetPrice",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getItems",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"sum",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"getItems",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"sum",
"+=",
"$",
"item",
"->",
"getTotalNetPrice",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setTotalNetPrice",
"(",
"$",
"sum",
")",
";",
"}"
] |
FIXME: this function does not really belong here
Updates the total net price
|
[
"FIXME",
":",
"this",
"function",
"does",
"not",
"really",
"belong",
"here"
] |
train
|
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Entity/BaseOrder.php#L386-L397
|
cronario/cronario
|
src/Producer.php
|
Producer.setQueue
|
protected function setQueue(Queue $queue)
{
$this->queue = $queue;
$this->queue->setProducer($this);
return $this;
}
|
php
|
protected function setQueue(Queue $queue)
{
$this->queue = $queue;
$this->queue->setProducer($this);
return $this;
}
|
[
"protected",
"function",
"setQueue",
"(",
"Queue",
"$",
"queue",
")",
"{",
"$",
"this",
"->",
"queue",
"=",
"$",
"queue",
";",
"$",
"this",
"->",
"queue",
"->",
"setProducer",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
@param Queue $queue
@return $this
@throws Exception\QueueException
|
[
"@param",
"Queue",
"$queue"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L107-L113
|
cronario/cronario
|
src/Producer.php
|
Producer.getData
|
protected function getData($key = null)
{
if (null === $key) {
return $this->getRedis()->hgetall($this->getRedisNamespace());
}
return $this->getRedis()->hget($this->getRedisNamespace(), $key);
}
|
php
|
protected function getData($key = null)
{
if (null === $key) {
return $this->getRedis()->hgetall($this->getRedisNamespace());
}
return $this->getRedis()->hget($this->getRedisNamespace(), $key);
}
|
[
"protected",
"function",
"getData",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"getRedis",
"(",
")",
"->",
"hgetall",
"(",
"$",
"this",
"->",
"getRedisNamespace",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getRedis",
"(",
")",
"->",
"hget",
"(",
"$",
"this",
"->",
"getRedisNamespace",
"(",
")",
",",
"$",
"key",
")",
";",
"}"
] |
@param null $key
@return array|string
|
[
"@param",
"null",
"$key"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L231-L238
|
cronario/cronario
|
src/Producer.php
|
Producer.isState
|
protected function isState($state)
{
$current = $this->getState();
return (is_array($state))
? in_array($current, $state)
: $current == $state;
}
|
php
|
protected function isState($state)
{
$current = $this->getState();
return (is_array($state))
? in_array($current, $state)
: $current == $state;
}
|
[
"protected",
"function",
"isState",
"(",
"$",
"state",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"return",
"(",
"is_array",
"(",
"$",
"state",
")",
")",
"?",
"in_array",
"(",
"$",
"current",
",",
"$",
"state",
")",
":",
"$",
"current",
"==",
"$",
"state",
";",
"}"
] |
@param $state
@return bool
|
[
"@param",
"$state"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L323-L330
|
cronario/cronario
|
src/Producer.php
|
Producer.parseManagerId
|
protected function parseManagerId($string)
{
list($appId, $workerClass, $managerId) = explode('@', $string);
return [
Manager::P_APP_ID => $appId,
Manager::P_WORKER_CLASS => $workerClass,
Manager::P_ID => $managerId,
];
}
|
php
|
protected function parseManagerId($string)
{
list($appId, $workerClass, $managerId) = explode('@', $string);
return [
Manager::P_APP_ID => $appId,
Manager::P_WORKER_CLASS => $workerClass,
Manager::P_ID => $managerId,
];
}
|
[
"protected",
"function",
"parseManagerId",
"(",
"$",
"string",
")",
"{",
"list",
"(",
"$",
"appId",
",",
"$",
"workerClass",
",",
"$",
"managerId",
")",
"=",
"explode",
"(",
"'@'",
",",
"$",
"string",
")",
";",
"return",
"[",
"Manager",
"::",
"P_APP_ID",
"=>",
"$",
"appId",
",",
"Manager",
"::",
"P_WORKER_CLASS",
"=>",
"$",
"workerClass",
",",
"Manager",
"::",
"P_ID",
"=>",
"$",
"managerId",
",",
"]",
";",
"}"
] |
@param $string
@return array
|
[
"@param",
"$string"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L402-L411
|
cronario/cronario
|
src/Producer.php
|
Producer.cleanManagerSet
|
protected function cleanManagerSet()
{
foreach ($this->managerSet as $managerKey => $manager) {
/** @var $manager \Thread */
if (!$manager->isRunning()) {
$this->getLogger()->debug("Daemon clean old manager : {$managerKey}", [__NAMESPACE__]);
unset($this->managerSet[$managerKey]);
}
}
return $this;
}
|
php
|
protected function cleanManagerSet()
{
foreach ($this->managerSet as $managerKey => $manager) {
/** @var $manager \Thread */
if (!$manager->isRunning()) {
$this->getLogger()->debug("Daemon clean old manager : {$managerKey}", [__NAMESPACE__]);
unset($this->managerSet[$managerKey]);
}
}
return $this;
}
|
[
"protected",
"function",
"cleanManagerSet",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"managerSet",
"as",
"$",
"managerKey",
"=>",
"$",
"manager",
")",
"{",
"/** @var $manager \\Thread */",
"if",
"(",
"!",
"$",
"manager",
"->",
"isRunning",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"\"Daemon clean old manager : {$managerKey}\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"managerSet",
"[",
"$",
"managerKey",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Clean Manager SET
Checking each manager in ManagerSet and delete manager that done theirs work
@return $this
|
[
"Clean",
"Manager",
"SET"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L428-L440
|
cronario/cronario
|
src/Producer.php
|
Producer.updateManagerSet
|
protected function updateManagerSet()
{
$queueStatsServer = $this->getQueue()->getStats();
if (!isset($queueStatsServer[Queue::STATS_QUEUES]) || count($queueStatsServer[Queue::STATS_QUEUES]) == 0) {
return $this;
}
/**
* filter if queue not stopped
* filter if queue has jobs
*/
$managerOptionsSet = [];
foreach ($queueStatsServer[Queue::STATS_QUEUES] as $workerClass => $queueStats) {
if (in_array($workerClass, $this->managerIgnoreSet)) {
continue;
}
if (!class_exists($workerClass)) {
$this->managerIgnoreSet[] = $workerClass;
continue;
}
if ($queueStats[Queue::STATS_QUEUE_STOP]) {
continue;
}
if ($queueStats[Queue::STATS_JOBS_READY] == 0) {
continue;
}
try {
/** @var AbstractWorker $workerClass */
$workerConfig = $workerClass::getConfig();
// we need threads ..
$managerCount = $this->calcManagerSize(
$queueStats[Queue::STATS_JOBS_READY],
$workerConfig[AbstractWorker::CONFIG_P_MANAGER_POOL_SIZE],
$workerConfig[AbstractWorker::CONFIG_P_MANAGERS_LIMIT]
);
/** @var string $workerClass */
$managerOptionsSet[$workerClass] = $managerCount;
} catch (WorkerException $ex) {
$this->managerIgnoreSet[] = $workerClass;
$this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
$this->getLogger()
->warning("Daemon {$this->getAppId()} will ignore worker class {$workerClass}", [__NAMESPACE__]);
continue;
} catch (\Exception $ex) {
$this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
continue;
}
}
if (count($managerOptionsSet) == 0) {
return $this;
}
$appId = $this->getAppId();
$bootstrapFile = $this->getConfig(self::CONFIG_BOOTSTRAP_FILE);
foreach ($managerOptionsSet as $workerClass => $managerCount) {
while ($managerCount--) {
$managerId = $this->buildManagerId($workerClass, $managerCount);
if (array_key_exists($managerId, $this->managerSet)) {
continue;
}
$this->getLogger()->debug("Daemon create manager : {$managerId}", [__NAMESPACE__]);
$this->managerSet[$managerId] = new Manager($managerId, $appId, $workerClass, $bootstrapFile);
}
}
return $this;
}
|
php
|
protected function updateManagerSet()
{
$queueStatsServer = $this->getQueue()->getStats();
if (!isset($queueStatsServer[Queue::STATS_QUEUES]) || count($queueStatsServer[Queue::STATS_QUEUES]) == 0) {
return $this;
}
/**
* filter if queue not stopped
* filter if queue has jobs
*/
$managerOptionsSet = [];
foreach ($queueStatsServer[Queue::STATS_QUEUES] as $workerClass => $queueStats) {
if (in_array($workerClass, $this->managerIgnoreSet)) {
continue;
}
if (!class_exists($workerClass)) {
$this->managerIgnoreSet[] = $workerClass;
continue;
}
if ($queueStats[Queue::STATS_QUEUE_STOP]) {
continue;
}
if ($queueStats[Queue::STATS_JOBS_READY] == 0) {
continue;
}
try {
/** @var AbstractWorker $workerClass */
$workerConfig = $workerClass::getConfig();
// we need threads ..
$managerCount = $this->calcManagerSize(
$queueStats[Queue::STATS_JOBS_READY],
$workerConfig[AbstractWorker::CONFIG_P_MANAGER_POOL_SIZE],
$workerConfig[AbstractWorker::CONFIG_P_MANAGERS_LIMIT]
);
/** @var string $workerClass */
$managerOptionsSet[$workerClass] = $managerCount;
} catch (WorkerException $ex) {
$this->managerIgnoreSet[] = $workerClass;
$this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
$this->getLogger()
->warning("Daemon {$this->getAppId()} will ignore worker class {$workerClass}", [__NAMESPACE__]);
continue;
} catch (\Exception $ex) {
$this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
continue;
}
}
if (count($managerOptionsSet) == 0) {
return $this;
}
$appId = $this->getAppId();
$bootstrapFile = $this->getConfig(self::CONFIG_BOOTSTRAP_FILE);
foreach ($managerOptionsSet as $workerClass => $managerCount) {
while ($managerCount--) {
$managerId = $this->buildManagerId($workerClass, $managerCount);
if (array_key_exists($managerId, $this->managerSet)) {
continue;
}
$this->getLogger()->debug("Daemon create manager : {$managerId}", [__NAMESPACE__]);
$this->managerSet[$managerId] = new Manager($managerId, $appId, $workerClass, $bootstrapFile);
}
}
return $this;
}
|
[
"protected",
"function",
"updateManagerSet",
"(",
")",
"{",
"$",
"queueStatsServer",
"=",
"$",
"this",
"->",
"getQueue",
"(",
")",
"->",
"getStats",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"queueStatsServer",
"[",
"Queue",
"::",
"STATS_QUEUES",
"]",
")",
"||",
"count",
"(",
"$",
"queueStatsServer",
"[",
"Queue",
"::",
"STATS_QUEUES",
"]",
")",
"==",
"0",
")",
"{",
"return",
"$",
"this",
";",
"}",
"/**\n * filter if queue not stopped\n * filter if queue has jobs\n */",
"$",
"managerOptionsSet",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"queueStatsServer",
"[",
"Queue",
"::",
"STATS_QUEUES",
"]",
"as",
"$",
"workerClass",
"=>",
"$",
"queueStats",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"workerClass",
",",
"$",
"this",
"->",
"managerIgnoreSet",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"workerClass",
")",
")",
"{",
"$",
"this",
"->",
"managerIgnoreSet",
"[",
"]",
"=",
"$",
"workerClass",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"queueStats",
"[",
"Queue",
"::",
"STATS_QUEUE_STOP",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"queueStats",
"[",
"Queue",
"::",
"STATS_JOBS_READY",
"]",
"==",
"0",
")",
"{",
"continue",
";",
"}",
"try",
"{",
"/** @var AbstractWorker $workerClass */",
"$",
"workerConfig",
"=",
"$",
"workerClass",
"::",
"getConfig",
"(",
")",
";",
"// we need threads ..",
"$",
"managerCount",
"=",
"$",
"this",
"->",
"calcManagerSize",
"(",
"$",
"queueStats",
"[",
"Queue",
"::",
"STATS_JOBS_READY",
"]",
",",
"$",
"workerConfig",
"[",
"AbstractWorker",
"::",
"CONFIG_P_MANAGER_POOL_SIZE",
"]",
",",
"$",
"workerConfig",
"[",
"AbstractWorker",
"::",
"CONFIG_P_MANAGERS_LIMIT",
"]",
")",
";",
"/** @var string $workerClass */",
"$",
"managerOptionsSet",
"[",
"$",
"workerClass",
"]",
"=",
"$",
"managerCount",
";",
"}",
"catch",
"(",
"WorkerException",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"managerIgnoreSet",
"[",
"]",
"=",
"$",
"workerClass",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"\"Daemon {$this->getAppId()} will ignore worker class {$workerClass}\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"continue",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"continue",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"managerOptionsSet",
")",
"==",
"0",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"appId",
"=",
"$",
"this",
"->",
"getAppId",
"(",
")",
";",
"$",
"bootstrapFile",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"self",
"::",
"CONFIG_BOOTSTRAP_FILE",
")",
";",
"foreach",
"(",
"$",
"managerOptionsSet",
"as",
"$",
"workerClass",
"=>",
"$",
"managerCount",
")",
"{",
"while",
"(",
"$",
"managerCount",
"--",
")",
"{",
"$",
"managerId",
"=",
"$",
"this",
"->",
"buildManagerId",
"(",
"$",
"workerClass",
",",
"$",
"managerCount",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"managerId",
",",
"$",
"this",
"->",
"managerSet",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"\"Daemon create manager : {$managerId}\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"$",
"this",
"->",
"managerSet",
"[",
"$",
"managerId",
"]",
"=",
"new",
"Manager",
"(",
"$",
"managerId",
",",
"$",
"appId",
",",
"$",
"workerClass",
",",
"$",
"bootstrapFile",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Update Manager SET
REMEMBER queueName === workerClass (cause we have relation one queue name for one type of worker)
1) get Queue stats for all queues on server
2) filter queues (stopping flag / existing ready job in it)
3) get worker configuration (to know what manager balance should do later)
- if worker have problems with config we will add him to ignore manager set
4) then we try to create manager depend on exists managerSet and current balance
@return $this
|
[
"Update",
"Manager",
"SET"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L456-L538
|
cronario/cronario
|
src/Producer.php
|
Producer.calcManagerSize
|
protected function calcManagerSize($countJobsReady, $managerPoolSize, $managersLimit)
{
$managerCount = floor($countJobsReady / $managerPoolSize) + 1;
return ($managerCount > $managersLimit) ? $managersLimit : $managerCount;
}
|
php
|
protected function calcManagerSize($countJobsReady, $managerPoolSize, $managersLimit)
{
$managerCount = floor($countJobsReady / $managerPoolSize) + 1;
return ($managerCount > $managersLimit) ? $managersLimit : $managerCount;
}
|
[
"protected",
"function",
"calcManagerSize",
"(",
"$",
"countJobsReady",
",",
"$",
"managerPoolSize",
",",
"$",
"managersLimit",
")",
"{",
"$",
"managerCount",
"=",
"floor",
"(",
"$",
"countJobsReady",
"/",
"$",
"managerPoolSize",
")",
"+",
"1",
";",
"return",
"(",
"$",
"managerCount",
">",
"$",
"managersLimit",
")",
"?",
"$",
"managersLimit",
":",
"$",
"managerCount",
";",
"}"
] |
@param $countJobsReady
@param $managerPoolSize
@param $managersLimit
@return float
|
[
"@param",
"$countJobsReady",
"@param",
"$managerPoolSize",
"@param",
"$managersLimit"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L547-L552
|
cronario/cronario
|
src/Producer.php
|
Producer.mainLoop
|
protected function mainLoop()
{
$sleep = $this->getConfig(self::CONFIG_SLEEP_MAIN_LOOP);
while ($this->isStateStart()) {
$this->updateInfo();
$this->getQueue()->migrate();
$this->updateManagerSet();
$this->cleanManagerSet();
sleep($sleep);
}
$this->getLogger()->debug("Daemon loop catch \"STOP\" flag (X)", [__NAMESPACE__]);
return $this;
}
|
php
|
protected function mainLoop()
{
$sleep = $this->getConfig(self::CONFIG_SLEEP_MAIN_LOOP);
while ($this->isStateStart()) {
$this->updateInfo();
$this->getQueue()->migrate();
$this->updateManagerSet();
$this->cleanManagerSet();
sleep($sleep);
}
$this->getLogger()->debug("Daemon loop catch \"STOP\" flag (X)", [__NAMESPACE__]);
return $this;
}
|
[
"protected",
"function",
"mainLoop",
"(",
")",
"{",
"$",
"sleep",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"self",
"::",
"CONFIG_SLEEP_MAIN_LOOP",
")",
";",
"while",
"(",
"$",
"this",
"->",
"isStateStart",
"(",
")",
")",
"{",
"$",
"this",
"->",
"updateInfo",
"(",
")",
";",
"$",
"this",
"->",
"getQueue",
"(",
")",
"->",
"migrate",
"(",
")",
";",
"$",
"this",
"->",
"updateManagerSet",
"(",
")",
";",
"$",
"this",
"->",
"cleanManagerSet",
"(",
")",
";",
"sleep",
"(",
"$",
"sleep",
")",
";",
"}",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"\"Daemon loop catch \\\"STOP\\\" flag (X)\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Daemon Main Loop
1) checking if Daemon should finish work (if redis flag is finish then finish loop)
2) updating info about loop and current process
3) Migrate all 'delayed job' to 'ready queue' if time is become
4) Update Manager set with theirs worker balance (create new Managers if needed)
5) Clean Manager if they are finished theirs works
6) loop sleep cause and run again until redis flag is 'start'
@return $this
|
[
"Daemon",
"Main",
"Loop",
"1",
")",
"checking",
"if",
"Daemon",
"should",
"finish",
"work",
"(",
"if",
"redis",
"flag",
"is",
"finish",
"then",
"finish",
"loop",
")",
"2",
")",
"updating",
"info",
"about",
"loop",
"and",
"current",
"process",
"3",
")",
"Migrate",
"all",
"delayed",
"job",
"to",
"ready",
"queue",
"if",
"time",
"is",
"become",
"4",
")",
"Update",
"Manager",
"set",
"with",
"theirs",
"worker",
"balance",
"(",
"create",
"new",
"Managers",
"if",
"needed",
")",
"5",
")",
"Clean",
"Manager",
"if",
"they",
"are",
"finished",
"theirs",
"works",
"6",
")",
"loop",
"sleep",
"cause",
"and",
"run",
"again",
"until",
"redis",
"flag",
"is",
"start"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L570-L586
|
cronario/cronario
|
src/Producer.php
|
Producer.start
|
public function start()
{
$state = $this->getState();
if (in_array($state, [self::STATE_T_START, self::STATE_T_STOP, self::STATE_T_KILL])) {
$processId = $this->getProcessId();
if (!$this->processExists()) {
$this->getLogger()
->warning("Daemon is ill can't find process {$processId}, try clean data and continue starting",
[__NAMESPACE__]);
$this->cleanData();
// continue start
} else {
$this->getLogger()
->info("Daemon can't START, cause state : {$state}, and process exists {$processId}",
[__NAMESPACE__]);
return false;
}
}
$this->setProcessId($pid = intval(getmypid()));
$this->setData(self::P_CREATED_TIME, time());
$this->setState(self::STATE_T_START);
try {
$this->mainLoop();
$this->waitManagersDone();
} catch (\Exception $ex) {
$this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
}
$this->cleanData();
return true;
}
|
php
|
public function start()
{
$state = $this->getState();
if (in_array($state, [self::STATE_T_START, self::STATE_T_STOP, self::STATE_T_KILL])) {
$processId = $this->getProcessId();
if (!$this->processExists()) {
$this->getLogger()
->warning("Daemon is ill can't find process {$processId}, try clean data and continue starting",
[__NAMESPACE__]);
$this->cleanData();
// continue start
} else {
$this->getLogger()
->info("Daemon can't START, cause state : {$state}, and process exists {$processId}",
[__NAMESPACE__]);
return false;
}
}
$this->setProcessId($pid = intval(getmypid()));
$this->setData(self::P_CREATED_TIME, time());
$this->setState(self::STATE_T_START);
try {
$this->mainLoop();
$this->waitManagersDone();
} catch (\Exception $ex) {
$this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
}
$this->cleanData();
return true;
}
|
[
"public",
"function",
"start",
"(",
")",
"{",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"state",
",",
"[",
"self",
"::",
"STATE_T_START",
",",
"self",
"::",
"STATE_T_STOP",
",",
"self",
"::",
"STATE_T_KILL",
"]",
")",
")",
"{",
"$",
"processId",
"=",
"$",
"this",
"->",
"getProcessId",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"processExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"\"Daemon is ill can't find process {$processId}, try clean data and continue starting\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"$",
"this",
"->",
"cleanData",
"(",
")",
";",
"// continue start",
"}",
"else",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Daemon can't START, cause state : {$state}, and process exists {$processId}\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"return",
"false",
";",
"}",
"}",
"$",
"this",
"->",
"setProcessId",
"(",
"$",
"pid",
"=",
"intval",
"(",
"getmypid",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"setData",
"(",
"self",
"::",
"P_CREATED_TIME",
",",
"time",
"(",
")",
")",
";",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_T_START",
")",
";",
"try",
"{",
"$",
"this",
"->",
"mainLoop",
"(",
")",
";",
"$",
"this",
"->",
"waitManagersDone",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"}",
"$",
"this",
"->",
"cleanData",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
START daemon
1) get
@return bool
|
[
"START",
"daemon"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L616-L657
|
cronario/cronario
|
src/Producer.php
|
Producer.stop
|
public function stop($async = false)
{
$state = $this->getState();
if (in_array($state, [self::STATE_T_START, self::STATE_T_STOP, self::STATE_T_KILL])
&& !$this->processExists()
) {
$this->getLogger()
->warning("Daemon is ill cant find process {$this->getProcessId()}, try clean data", [__NAMESPACE__]);
$this->cleanData();
return true;
}
if (in_array($state, [self::STATE_T_STOP, self::STATE_T_KILL])) {
$this->getLogger()->info("Daemon can't STOP, cause state : {$state}", [__NAMESPACE__]);
return true;
}
if (!in_array($state, [self::STATE_T_START])) {
$this->getLogger()->info("Daemon can't STOP, cause daemon not START", [__NAMESPACE__]);
return true;
}
$this->setState(self::STATE_T_STOP);
// sync mode (wait for stopping loop)
if ($async) {
return true;
}
$this->getLogger()->info("Daemon sync STOP, wait loop ...", [__NAMESPACE__]);
$sleep = $this->getConfig(self::CONFIG_SLEEP_STOP_LOOP);
while ($this->isState(
[self::STATE_T_STOP, self::STATE_T_KILL, self::STATE_T_START]
)) {
$this->getLogger()->debug("Daemon sync STOP, wait loop .......", [__NAMESPACE__]);
sleep($sleep);
}
return true;
}
|
php
|
public function stop($async = false)
{
$state = $this->getState();
if (in_array($state, [self::STATE_T_START, self::STATE_T_STOP, self::STATE_T_KILL])
&& !$this->processExists()
) {
$this->getLogger()
->warning("Daemon is ill cant find process {$this->getProcessId()}, try clean data", [__NAMESPACE__]);
$this->cleanData();
return true;
}
if (in_array($state, [self::STATE_T_STOP, self::STATE_T_KILL])) {
$this->getLogger()->info("Daemon can't STOP, cause state : {$state}", [__NAMESPACE__]);
return true;
}
if (!in_array($state, [self::STATE_T_START])) {
$this->getLogger()->info("Daemon can't STOP, cause daemon not START", [__NAMESPACE__]);
return true;
}
$this->setState(self::STATE_T_STOP);
// sync mode (wait for stopping loop)
if ($async) {
return true;
}
$this->getLogger()->info("Daemon sync STOP, wait loop ...", [__NAMESPACE__]);
$sleep = $this->getConfig(self::CONFIG_SLEEP_STOP_LOOP);
while ($this->isState(
[self::STATE_T_STOP, self::STATE_T_KILL, self::STATE_T_START]
)) {
$this->getLogger()->debug("Daemon sync STOP, wait loop .......", [__NAMESPACE__]);
sleep($sleep);
}
return true;
}
|
[
"public",
"function",
"stop",
"(",
"$",
"async",
"=",
"false",
")",
"{",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"state",
",",
"[",
"self",
"::",
"STATE_T_START",
",",
"self",
"::",
"STATE_T_STOP",
",",
"self",
"::",
"STATE_T_KILL",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"processExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"\"Daemon is ill cant find process {$this->getProcessId()}, try clean data\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"$",
"this",
"->",
"cleanData",
"(",
")",
";",
"return",
"true",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"state",
",",
"[",
"self",
"::",
"STATE_T_STOP",
",",
"self",
"::",
"STATE_T_KILL",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Daemon can't STOP, cause state : {$state}\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"state",
",",
"[",
"self",
"::",
"STATE_T_START",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Daemon can't STOP, cause daemon not START\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_T_STOP",
")",
";",
"// sync mode (wait for stopping loop)",
"if",
"(",
"$",
"async",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Daemon sync STOP, wait loop ...\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"$",
"sleep",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"self",
"::",
"CONFIG_SLEEP_STOP_LOOP",
")",
";",
"while",
"(",
"$",
"this",
"->",
"isState",
"(",
"[",
"self",
"::",
"STATE_T_STOP",
",",
"self",
"::",
"STATE_T_KILL",
",",
"self",
"::",
"STATE_T_START",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"\"Daemon sync STOP, wait loop .......\"",
",",
"[",
"__NAMESPACE__",
"]",
")",
";",
"sleep",
"(",
"$",
"sleep",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
@param bool $async
@return bool
|
[
"@param",
"bool",
"$async"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Producer.php#L664-L711
|
WellCommerce/CoreBundle
|
Form/DataTransformer/AbstractDataTransformer.php
|
AbstractDataTransformer.getClassMetadata
|
protected function getClassMetadata(string $class): ClassMetadata
{
$factory = $this->getDoctrineHelper()->getMetadataFactory();
if (!$factory->hasMetadataFor($class)) {
throw new \InvalidArgumentException(sprintf('No metadata found for class "%s"', $class));
}
return $factory->getMetadataFor($class);
}
|
php
|
protected function getClassMetadata(string $class): ClassMetadata
{
$factory = $this->getDoctrineHelper()->getMetadataFactory();
if (!$factory->hasMetadataFor($class)) {
throw new \InvalidArgumentException(sprintf('No metadata found for class "%s"', $class));
}
return $factory->getMetadataFor($class);
}
|
[
"protected",
"function",
"getClassMetadata",
"(",
"string",
"$",
"class",
")",
":",
"ClassMetadata",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"getDoctrineHelper",
"(",
")",
"->",
"getMetadataFactory",
"(",
")",
";",
"if",
"(",
"!",
"$",
"factory",
"->",
"hasMetadataFor",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No metadata found for class \"%s\"'",
",",
"$",
"class",
")",
")",
";",
"}",
"return",
"$",
"factory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
";",
"}"
] |
Returns mapping information for class
@param string $class
@return ClassMetadata
|
[
"Returns",
"mapping",
"information",
"for",
"class"
] |
train
|
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Form/DataTransformer/AbstractDataTransformer.php#L96-L104
|
verschoof/bunq-api
|
src/Token/TokenType.php
|
TokenType.protect
|
private function protect()
{
if (!in_array($this->type, self::allAsString(), true)) {
throw new \InvalidArgumentException(sprintf('Invalid token type "%s"', $this->type));
}
}
|
php
|
private function protect()
{
if (!in_array($this->type, self::allAsString(), true)) {
throw new \InvalidArgumentException(sprintf('Invalid token type "%s"', $this->type));
}
}
|
[
"private",
"function",
"protect",
"(",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"type",
",",
"self",
"::",
"allAsString",
"(",
")",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid token type \"%s\"'",
",",
"$",
"this",
"->",
"type",
")",
")",
";",
"}",
"}"
] |
Check if the tokenType exists in our list
|
[
"Check",
"if",
"the",
"tokenType",
"exists",
"in",
"our",
"list"
] |
train
|
https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Token/TokenType.php#L102-L107
|
movoin/one-swoole
|
src/Support/Helpers/Arr.php
|
Arr.get
|
public static function get($array, string $key, $default = null)
{
if (! Assert::array($array)) {
return $default;
}
$key = trim($key);
if ($key === '') {
return $array;
}
if (static::exists($array, $key)) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if (Assert::array($array) && static::exists($array, $segment)) {
$array = $array[$segment];
} else {
return $default;
}
}
return $array;
}
|
php
|
public static function get($array, string $key, $default = null)
{
if (! Assert::array($array)) {
return $default;
}
$key = trim($key);
if ($key === '') {
return $array;
}
if (static::exists($array, $key)) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if (Assert::array($array) && static::exists($array, $segment)) {
$array = $array[$segment];
} else {
return $default;
}
}
return $array;
}
|
[
"public",
"static",
"function",
"get",
"(",
"$",
"array",
",",
"string",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"Assert",
"::",
"array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"key",
"=",
"trim",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"key",
"===",
"''",
")",
"{",
"return",
"$",
"array",
";",
"}",
"if",
"(",
"static",
"::",
"exists",
"(",
"$",
"array",
",",
"$",
"key",
")",
")",
"{",
"return",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"segment",
")",
"{",
"if",
"(",
"Assert",
"::",
"array",
"(",
"$",
"array",
")",
"&&",
"static",
"::",
"exists",
"(",
"$",
"array",
",",
"$",
"segment",
")",
")",
"{",
"$",
"array",
"=",
"$",
"array",
"[",
"$",
"segment",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] |
从数组中获得指定键名的值,并支持使用 `.` 符号简化操作多维数组
@param \ArrayAccess|array $array
@param string $key
@param mixed $default
@return mixed
|
[
"从数组中获得指定键名的值,并支持使用",
".",
"符号简化操作多维数组"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Helpers/Arr.php#L48-L73
|
movoin/one-swoole
|
src/Support/Helpers/Arr.php
|
Arr.diff
|
public static function diff($before, $after): array
{
if (! Assert::array($before) || ! Assert::array($after)) {
throw new InvalidArgumentException(
'`Arr::diff` two parameters must be `array` or implements interface `ArrayAccess`'
);
}
$diff = [];
foreach ($after as $key => $value) {
if (! isset($before[$key])) {
$diff[$key] = $value;
} elseif ($value != $before[$key]) {
$diff[$key] = $value;
}
}
return $diff;
}
|
php
|
public static function diff($before, $after): array
{
if (! Assert::array($before) || ! Assert::array($after)) {
throw new InvalidArgumentException(
'`Arr::diff` two parameters must be `array` or implements interface `ArrayAccess`'
);
}
$diff = [];
foreach ($after as $key => $value) {
if (! isset($before[$key])) {
$diff[$key] = $value;
} elseif ($value != $before[$key]) {
$diff[$key] = $value;
}
}
return $diff;
}
|
[
"public",
"static",
"function",
"diff",
"(",
"$",
"before",
",",
"$",
"after",
")",
":",
"array",
"{",
"if",
"(",
"!",
"Assert",
"::",
"array",
"(",
"$",
"before",
")",
"||",
"!",
"Assert",
"::",
"array",
"(",
"$",
"after",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'`Arr::diff` two parameters must be `array` or implements interface `ArrayAccess`'",
")",
";",
"}",
"$",
"diff",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"after",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"before",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"diff",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"elseif",
"(",
"$",
"value",
"!=",
"$",
"before",
"[",
"$",
"key",
"]",
")",
"{",
"$",
"diff",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"diff",
";",
"}"
] |
返回数组间的差异
@param \ArrayAccess|array $before
@param \ArrayAccess|array $after
@return array
@throws \InvalidArgumentException
|
[
"返回数组间的差异"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Helpers/Arr.php#L97-L116
|
movoin/one-swoole
|
src/Support/Helpers/Arr.php
|
Arr.removeByValue
|
public static function removeByValue($array, $value): array
{
if (! Assert::array($array)) {
throw new InvalidArgumentException(
'`Arr::removeByValue` first parameter must be `array` or implements interface `ArrayAccess`'
);
}
foreach ($array as $i => $val) {
if (trim($val) === trim($value)) {
unset($array[$i]);
}
}
return $array;
}
|
php
|
public static function removeByValue($array, $value): array
{
if (! Assert::array($array)) {
throw new InvalidArgumentException(
'`Arr::removeByValue` first parameter must be `array` or implements interface `ArrayAccess`'
);
}
foreach ($array as $i => $val) {
if (trim($val) === trim($value)) {
unset($array[$i]);
}
}
return $array;
}
|
[
"public",
"static",
"function",
"removeByValue",
"(",
"$",
"array",
",",
"$",
"value",
")",
":",
"array",
"{",
"if",
"(",
"!",
"Assert",
"::",
"array",
"(",
"$",
"array",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'`Arr::removeByValue` first parameter must be `array` or implements interface `ArrayAccess`'",
")",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"$",
"i",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"val",
")",
"===",
"trim",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"array",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] |
根据键值删除数组项
@param \ArrayAccess|array $array
@param mixed $value
@return array
@throws \InvalidArgumentException
|
[
"根据键值删除数组项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Helpers/Arr.php#L127-L142
|
movoin/one-swoole
|
src/Support/Helpers/Arr.php
|
Arr.groupBy
|
public static function groupBy($array, string $key): array
{
if (! Assert::array($array)) {
throw new InvalidArgumentException(
'`Arr::groupBy` first parameter must be `array` or implements interface `ArrayAccess`'
);
}
$grouped = [];
foreach ($array as $row) {
$k = $row[$key];
$grouped[$k][] = $row;
unset($k);
}
return $grouped;
}
|
php
|
public static function groupBy($array, string $key): array
{
if (! Assert::array($array)) {
throw new InvalidArgumentException(
'`Arr::groupBy` first parameter must be `array` or implements interface `ArrayAccess`'
);
}
$grouped = [];
foreach ($array as $row) {
$k = $row[$key];
$grouped[$k][] = $row;
unset($k);
}
return $grouped;
}
|
[
"public",
"static",
"function",
"groupBy",
"(",
"$",
"array",
",",
"string",
"$",
"key",
")",
":",
"array",
"{",
"if",
"(",
"!",
"Assert",
"::",
"array",
"(",
"$",
"array",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'`Arr::groupBy` first parameter must be `array` or implements interface `ArrayAccess`'",
")",
";",
"}",
"$",
"grouped",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"row",
")",
"{",
"$",
"k",
"=",
"$",
"row",
"[",
"$",
"key",
"]",
";",
"$",
"grouped",
"[",
"$",
"k",
"]",
"[",
"]",
"=",
"$",
"row",
";",
"unset",
"(",
"$",
"k",
")",
";",
"}",
"return",
"$",
"grouped",
";",
"}"
] |
根据指定键名对数组分组
@param \ArrayAccess|array $array
@param string $key
@return array
@throws \InvalidArgumentException
|
[
"根据指定键名对数组分组"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Helpers/Arr.php#L153-L170
|
movoin/one-swoole
|
src/Support/Helpers/Arr.php
|
Arr.columns
|
public static function columns($array, string $key): array
{
if (! Assert::array($array)) {
throw new InvalidArgumentException(
'`Arr::columns` first parameter must be `array` or implements interface `ArrayAccess`'
);
}
if (empty($array)) {
return [];
}
$columns = [];
foreach ($array as $item) {
if (self::exists($item, $key)) {
$columns[] = $item[$key];
}
}
return $columns;
}
|
php
|
public static function columns($array, string $key): array
{
if (! Assert::array($array)) {
throw new InvalidArgumentException(
'`Arr::columns` first parameter must be `array` or implements interface `ArrayAccess`'
);
}
if (empty($array)) {
return [];
}
$columns = [];
foreach ($array as $item) {
if (self::exists($item, $key)) {
$columns[] = $item[$key];
}
}
return $columns;
}
|
[
"public",
"static",
"function",
"columns",
"(",
"$",
"array",
",",
"string",
"$",
"key",
")",
":",
"array",
"{",
"if",
"(",
"!",
"Assert",
"::",
"array",
"(",
"$",
"array",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'`Arr::columns` first parameter must be `array` or implements interface `ArrayAccess`'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"self",
"::",
"exists",
"(",
"$",
"item",
",",
"$",
"key",
")",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"$",
"item",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"columns",
";",
"}"
] |
返回指定 Keys 的对应值
@param \ArrayAccess|array $array
@param string $key
@return array
@throws \InvalidArgumentException
|
[
"返回指定",
"Keys",
"的对应值"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Helpers/Arr.php#L181-L202
|
movoin/one-swoole
|
src/Support/Helpers/Arr.php
|
Arr.hashMap
|
public static function hashMap($array, $key, $value = null): array
{
if (! Assert::array($array)) {
throw new InvalidArgumentException(
'`Arr::hashMap` first parameter must be `array` or implements interface `ArrayAccess`'
);
}
$hashMap = [];
$key = trim($key);
$value = trim($value);
if (! empty($value)) {
foreach ($array as $row) {
$hashMap[$row[$key]] = $row[$value];
}
} else {
foreach ($array as $row) {
$hashMap[$row[$key]] = $row;
}
}
return $hashMap;
}
|
php
|
public static function hashMap($array, $key, $value = null): array
{
if (! Assert::array($array)) {
throw new InvalidArgumentException(
'`Arr::hashMap` first parameter must be `array` or implements interface `ArrayAccess`'
);
}
$hashMap = [];
$key = trim($key);
$value = trim($value);
if (! empty($value)) {
foreach ($array as $row) {
$hashMap[$row[$key]] = $row[$value];
}
} else {
foreach ($array as $row) {
$hashMap[$row[$key]] = $row;
}
}
return $hashMap;
}
|
[
"public",
"static",
"function",
"hashMap",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"!",
"Assert",
"::",
"array",
"(",
"$",
"array",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'`Arr::hashMap` first parameter must be `array` or implements interface `ArrayAccess`'",
")",
";",
"}",
"$",
"hashMap",
"=",
"[",
"]",
";",
"$",
"key",
"=",
"trim",
"(",
"$",
"key",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"row",
")",
"{",
"$",
"hashMap",
"[",
"$",
"row",
"[",
"$",
"key",
"]",
"]",
"=",
"$",
"row",
"[",
"$",
"value",
"]",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"row",
")",
"{",
"$",
"hashMap",
"[",
"$",
"row",
"[",
"$",
"key",
"]",
"]",
"=",
"$",
"row",
";",
"}",
"}",
"return",
"$",
"hashMap",
";",
"}"
] |
将一个多维数组转换为键值映射数组
@param \ArrayAccess|array $array
@param string $key
@param string $value
@return array
@throws \InvalidArgumentException
|
[
"将一个多维数组转换为键值映射数组"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Helpers/Arr.php#L214-L237
|
huasituo/hstcms
|
src/Libraries/Fields/DateTime.php
|
DateTime.input
|
public function input($cname, $name, $cfg, $value = NULL, $id = 0)
{
// 字段显示名称
$text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font> ' : '').$cname.'';
// 表单宽度设置
$width = isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '150';
$width = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';"';
// 表单附加参数
$attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : '';
// 字段提示信息
$tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips'] : '';
// 字段默认值
if (!$value) {
if(isset($cfg['option']['value']) && is_numeric($cfg['option']['value'])) {
$value = isset($cfg['option']['value']) && (int)$cfg['option']['value'] === '0' ? 0 : hst_time();
} else if(isset($cfg['option']['value']) && !is_numeric($cfg['option']['value'])) {
$value = hst_str2time($cfg['option']['value']);
}
} else {
$value = $value ? $value : (strlen($value) == 1 && $value == 0 ? '' : hst_time());
}
$format = isset($cfg['option']['format']) && $cfg['option']['format'] ? $cfg['option']['format'] : 'Y-m-d H:i';
$show = $value ? hst_time2str($value, $format) : '';
$disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && !$cfg['validate']['isedit'] ? ' disabled' : ' ';
$required = isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? ' required="required"' : '';
$str = '';
$str.= '<input type="text" class="hstui-input J_datetime" value="'.$show.'" name="'.$name.'" id="hstcms_'.$name.'" ' . $width . $disabled . $attr.$required.' />';
if ($name == 'updatetime') {
}
return $this->input_format($name, $text, $str, $tips);
}
|
php
|
public function input($cname, $name, $cfg, $value = NULL, $id = 0)
{
// 字段显示名称
$text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font> ' : '').$cname.'';
// 表单宽度设置
$width = isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '150';
$width = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';"';
// 表单附加参数
$attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : '';
// 字段提示信息
$tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips'] : '';
// 字段默认值
if (!$value) {
if(isset($cfg['option']['value']) && is_numeric($cfg['option']['value'])) {
$value = isset($cfg['option']['value']) && (int)$cfg['option']['value'] === '0' ? 0 : hst_time();
} else if(isset($cfg['option']['value']) && !is_numeric($cfg['option']['value'])) {
$value = hst_str2time($cfg['option']['value']);
}
} else {
$value = $value ? $value : (strlen($value) == 1 && $value == 0 ? '' : hst_time());
}
$format = isset($cfg['option']['format']) && $cfg['option']['format'] ? $cfg['option']['format'] : 'Y-m-d H:i';
$show = $value ? hst_time2str($value, $format) : '';
$disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && !$cfg['validate']['isedit'] ? ' disabled' : ' ';
$required = isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? ' required="required"' : '';
$str = '';
$str.= '<input type="text" class="hstui-input J_datetime" value="'.$show.'" name="'.$name.'" id="hstcms_'.$name.'" ' . $width . $disabled . $attr.$required.' />';
if ($name == 'updatetime') {
}
return $this->input_format($name, $text, $str, $tips);
}
|
[
"public",
"function",
"input",
"(",
"$",
"cname",
",",
"$",
"name",
",",
"$",
"cfg",
",",
"$",
"value",
"=",
"NULL",
",",
"$",
"id",
"=",
"0",
")",
"{",
"// 字段显示名称",
"$",
"text",
"=",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
"==",
"1",
"?",
"'<font color=\"red\">*</font> '",
":",
"''",
")",
".",
"$",
"cname",
".",
"''",
";",
"// 表单宽度设置",
"$",
"width",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'width'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'width'",
"]",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'width'",
"]",
":",
"'150'",
";",
"$",
"width",
"=",
"'style=\"width:'",
".",
"$",
"width",
".",
"(",
"is_numeric",
"(",
"$",
"width",
")",
"?",
"'px'",
":",
"''",
")",
".",
"';\"'",
";",
"// 表单附加参数",
"$",
"attr",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'formattr'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'formattr'",
"]",
"?",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'formattr'",
"]",
":",
"''",
";",
"// 字段提示信息",
"$",
"tips",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
"?",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
":",
"''",
";",
"// 字段默认值",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
")",
"&&",
"(",
"int",
")",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
"===",
"'0'",
"?",
"0",
":",
"hst_time",
"(",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"hst_str2time",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"value",
"?",
"$",
"value",
":",
"(",
"strlen",
"(",
"$",
"value",
")",
"==",
"1",
"&&",
"$",
"value",
"==",
"0",
"?",
"''",
":",
"hst_time",
"(",
")",
")",
";",
"}",
"$",
"format",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'format'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'format'",
"]",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'format'",
"]",
":",
"'Y-m-d H:i'",
";",
"$",
"show",
"=",
"$",
"value",
"?",
"hst_time2str",
"(",
"$",
"value",
",",
"$",
"format",
")",
":",
"''",
";",
"$",
"disabled",
"=",
"!",
"$",
"this",
"->",
"isadmin",
"&&",
"$",
"id",
"&&",
"$",
"value",
"&&",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'isedit'",
"]",
")",
"&&",
"!",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'isedit'",
"]",
"?",
"' disabled'",
":",
"' '",
";",
"$",
"required",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
"==",
"1",
"?",
"' required=\"required\"'",
":",
"''",
";",
"$",
"str",
"=",
"''",
";",
"$",
"str",
".=",
"'<input type=\"text\" class=\"hstui-input J_datetime\" value=\"'",
".",
"$",
"show",
".",
"'\" name=\"'",
".",
"$",
"name",
".",
"'\" id=\"hstcms_'",
".",
"$",
"name",
".",
"'\" '",
".",
"$",
"width",
".",
"$",
"disabled",
".",
"$",
"attr",
".",
"$",
"required",
".",
"' />'",
";",
"if",
"(",
"$",
"name",
"==",
"'updatetime'",
")",
"{",
"}",
"return",
"$",
"this",
"->",
"input_format",
"(",
"$",
"name",
",",
"$",
"text",
",",
"$",
"str",
",",
"$",
"tips",
")",
";",
"}"
] |
字段表单输入
@param string $cname 字段别名
@param string $name 字段名称
@param array $cfg 字段配置
@param string $value 值
@return string
|
[
"字段表单输入"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/DateTime.php#L87-L119
|
huasituo/hstcms
|
src/Libraries/Fields/DateTime.php
|
DateTime.output_data
|
public function output_data($data, $field = [])
{
if(!isset($data[$field['fieldname']])) {
return $data;
}
$value = $data[$field['fieldname']];
if(!$value) {
return $data;
}
$data['_'.$field['fieldname']] = $value;
$format = isset($cfg['option']['format']) && $cfg['option']['format'] ? $cfg['option']['format'] : 'Y-m-d H:i';
$data[$field['fieldname']] = hst_time2str($value, $format);
return $data;
}
|
php
|
public function output_data($data, $field = [])
{
if(!isset($data[$field['fieldname']])) {
return $data;
}
$value = $data[$field['fieldname']];
if(!$value) {
return $data;
}
$data['_'.$field['fieldname']] = $value;
$format = isset($cfg['option']['format']) && $cfg['option']['format'] ? $cfg['option']['format'] : 'Y-m-d H:i';
$data[$field['fieldname']] = hst_time2str($value, $format);
return $data;
}
|
[
"public",
"function",
"output_data",
"(",
"$",
"data",
",",
"$",
"field",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"value",
"=",
"$",
"data",
"[",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
";",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"data",
"[",
"'_'",
".",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
"=",
"$",
"value",
";",
"$",
"format",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'format'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'format'",
"]",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'format'",
"]",
":",
"'Y-m-d H:i'",
";",
"$",
"data",
"[",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
"=",
"hst_time2str",
"(",
"$",
"value",
",",
"$",
"format",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
字段输出
|
[
"字段输出"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/DateTime.php#L124-L137
|
tonicospinelli/class-generation
|
src/ClassGeneration/ConstantCollection.php
|
ConstantCollection.add
|
public function add($constant)
{
if (!$constant instanceof ConstantInterface) {
throw new \InvalidArgumentException(
'This Constant must be a instance of \ClassGeneration\ConstantInterface'
);
}
if ($constant->getName() === null) {
$constant->setName('constant' . ($this->count() + 1));
}
return parent::add($constant);
}
|
php
|
public function add($constant)
{
if (!$constant instanceof ConstantInterface) {
throw new \InvalidArgumentException(
'This Constant must be a instance of \ClassGeneration\ConstantInterface'
);
}
if ($constant->getName() === null) {
$constant->setName('constant' . ($this->count() + 1));
}
return parent::add($constant);
}
|
[
"public",
"function",
"add",
"(",
"$",
"constant",
")",
"{",
"if",
"(",
"!",
"$",
"constant",
"instanceof",
"ConstantInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'This Constant must be a instance of \\ClassGeneration\\ConstantInterface'",
")",
";",
"}",
"if",
"(",
"$",
"constant",
"->",
"getName",
"(",
")",
"===",
"null",
")",
"{",
"$",
"constant",
"->",
"setName",
"(",
"'constant'",
".",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"+",
"1",
")",
")",
";",
"}",
"return",
"parent",
"::",
"add",
"(",
"$",
"constant",
")",
";",
"}"
] |
Adds a new Constant at ConstantCollection.
@param ConstantInterface $constant
@throws \InvalidArgumentException
@return bool
|
[
"Adds",
"a",
"new",
"Constant",
"at",
"ConstantCollection",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/ConstantCollection.php#L31-L44
|
tonicospinelli/class-generation
|
src/ClassGeneration/ConstantCollection.php
|
ConstantCollection.toString
|
public function toString()
{
$string = '';
$constants = $this->getIterator();
foreach ($constants as $constant) {
$string .= $constant->toString();
}
return $string;
}
|
php
|
public function toString()
{
$string = '';
$constants = $this->getIterator();
foreach ($constants as $constant) {
$string .= $constant->toString();
}
return $string;
}
|
[
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"$",
"constants",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"constants",
"as",
"$",
"constant",
")",
"{",
"$",
"string",
".=",
"$",
"constant",
"->",
"toString",
"(",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] |
Parse the Constant Collection to string.
@return string
|
[
"Parse",
"the",
"Constant",
"Collection",
"to",
"string",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/ConstantCollection.php#L68-L77
|
tonicospinelli/class-generation
|
src/ClassGeneration/ConstantCollection.php
|
ConstantCollection.removeByName
|
public function removeByName($constantName)
{
$removedList = new self();
$list = $this->getIterator();
foreach ($list as $index => $constant) {
$currentName = $constant->getName();
if ((is_array($constantName) && in_array($currentName, $constantName))
|| ($constant->getName() === $constantName)
) {
$removedList->add(clone $constant);
$this->remove($index);
}
}
return $removedList;
}
|
php
|
public function removeByName($constantName)
{
$removedList = new self();
$list = $this->getIterator();
foreach ($list as $index => $constant) {
$currentName = $constant->getName();
if ((is_array($constantName) && in_array($currentName, $constantName))
|| ($constant->getName() === $constantName)
) {
$removedList->add(clone $constant);
$this->remove($index);
}
}
return $removedList;
}
|
[
"public",
"function",
"removeByName",
"(",
"$",
"constantName",
")",
"{",
"$",
"removedList",
"=",
"new",
"self",
"(",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"index",
"=>",
"$",
"constant",
")",
"{",
"$",
"currentName",
"=",
"$",
"constant",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"(",
"is_array",
"(",
"$",
"constantName",
")",
"&&",
"in_array",
"(",
"$",
"currentName",
",",
"$",
"constantName",
")",
")",
"||",
"(",
"$",
"constant",
"->",
"getName",
"(",
")",
"===",
"$",
"constantName",
")",
")",
"{",
"$",
"removedList",
"->",
"add",
"(",
"clone",
"$",
"constant",
")",
";",
"$",
"this",
"->",
"remove",
"(",
"$",
"index",
")",
";",
"}",
"}",
"return",
"$",
"removedList",
";",
"}"
] |
Removes tags by name.
@param $constantName
@return ConstantCollection
|
[
"Removes",
"tags",
"by",
"name",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/ConstantCollection.php#L86-L101
|
huasituo/hstcms
|
src/Database/Migrations/2016_12_06_044026_create_common_fields_table.php
|
CreateCommonFieldsTable.up
|
public function up()
{
Schema::create('common_fields', function (Blueprint $table) {
$table->increments('id')->comment('ID');
$table->string('name')->nullable()->comment(hst_lang('hstcms::public.name'));
$table->string('fieldname')->nullable()->comment();
$table->string('fieldtype')->nullable()->comment();
$table->string('relatedtable')->nullable()->comment();
$table->string('relatedid')->nullable()->comment();
$table->string('module')->nullable()->comment();
$table->tinyInteger('ismain', false)->nullable(0)->comment();
$table->tinyInteger('ismshow', false)->nullable(0)->comment();
$table->tinyInteger('ismember', false)->nullable(0)->comment();
$table->tinyInteger('issearch', false)->nullable(0)->comment();
$table->tinyInteger('vieworder', false)->nullable(0)->comment();
$table->tinyInteger('disabled', false)->nullable(0)->comment();
$table->integer('times')->nullable()->comment(hst_lang('hstcms::public.times'));
$table->text('setting')->nullable()->comment();
//$table->timestamps();
});
}
|
php
|
public function up()
{
Schema::create('common_fields', function (Blueprint $table) {
$table->increments('id')->comment('ID');
$table->string('name')->nullable()->comment(hst_lang('hstcms::public.name'));
$table->string('fieldname')->nullable()->comment();
$table->string('fieldtype')->nullable()->comment();
$table->string('relatedtable')->nullable()->comment();
$table->string('relatedid')->nullable()->comment();
$table->string('module')->nullable()->comment();
$table->tinyInteger('ismain', false)->nullable(0)->comment();
$table->tinyInteger('ismshow', false)->nullable(0)->comment();
$table->tinyInteger('ismember', false)->nullable(0)->comment();
$table->tinyInteger('issearch', false)->nullable(0)->comment();
$table->tinyInteger('vieworder', false)->nullable(0)->comment();
$table->tinyInteger('disabled', false)->nullable(0)->comment();
$table->integer('times')->nullable()->comment(hst_lang('hstcms::public.times'));
$table->text('setting')->nullable()->comment();
//$table->timestamps();
});
}
|
[
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"create",
"(",
"'common_fields'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"increments",
"(",
"'id'",
")",
"->",
"comment",
"(",
"'ID'",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'name'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
"hst_lang",
"(",
"'hstcms::public.name'",
")",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'fieldname'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'fieldtype'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'relatedtable'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'relatedid'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'module'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"tinyInteger",
"(",
"'ismain'",
",",
"false",
")",
"->",
"nullable",
"(",
"0",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"tinyInteger",
"(",
"'ismshow'",
",",
"false",
")",
"->",
"nullable",
"(",
"0",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"tinyInteger",
"(",
"'ismember'",
",",
"false",
")",
"->",
"nullable",
"(",
"0",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"tinyInteger",
"(",
"'issearch'",
",",
"false",
")",
"->",
"nullable",
"(",
"0",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"tinyInteger",
"(",
"'vieworder'",
",",
"false",
")",
"->",
"nullable",
"(",
"0",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"tinyInteger",
"(",
"'disabled'",
",",
"false",
")",
"->",
"nullable",
"(",
"0",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'times'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
"hst_lang",
"(",
"'hstcms::public.times'",
")",
")",
";",
"$",
"table",
"->",
"text",
"(",
"'setting'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
")",
";",
"//$table->timestamps();",
"}",
")",
";",
"}"
] |
Run the migrations.
@return void
|
[
"Run",
"the",
"migrations",
"."
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Database/Migrations/2016_12_06_044026_create_common_fields_table.php#L18-L38
|
jan-dolata/crude-crud
|
src/Engine/CrudeSetupTrait/SelectOptions.php
|
SelectOptions.setSelectOptions
|
public function setSelectOptions($attr, $options = null)
{
$optionsList = is_array($attr)
? $attr
: [$attr => $options];
foreach ($optionsList as $key => $value)
$this->selectOptions[$key] = $value;
return $this;
}
|
php
|
public function setSelectOptions($attr, $options = null)
{
$optionsList = is_array($attr)
? $attr
: [$attr => $options];
foreach ($optionsList as $key => $value)
$this->selectOptions[$key] = $value;
return $this;
}
|
[
"public",
"function",
"setSelectOptions",
"(",
"$",
"attr",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"optionsList",
"=",
"is_array",
"(",
"$",
"attr",
")",
"?",
"$",
"attr",
":",
"[",
"$",
"attr",
"=>",
"$",
"options",
"]",
";",
"foreach",
"(",
"$",
"optionsList",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"$",
"this",
"->",
"selectOptions",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the Select options.
@param string|array $attr
@param array $options = null
@return self
|
[
"Sets",
"the",
"Select",
"options",
"."
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/CrudeSetupTrait/SelectOptions.php#L32-L42
|
movoin/one-swoole
|
src/Protocol/Message/Response.php
|
Response.sendHeaders
|
public function sendHeaders()
{
// Status
$this->swResponse->status($this->getStatusCode());
// Headers
foreach ($this->getHeaders() as $name => $value) {
$this->swResponse->header($name, implode(', ', $value));
}
}
|
php
|
public function sendHeaders()
{
// Status
$this->swResponse->status($this->getStatusCode());
// Headers
foreach ($this->getHeaders() as $name => $value) {
$this->swResponse->header($name, implode(', ', $value));
}
}
|
[
"public",
"function",
"sendHeaders",
"(",
")",
"{",
"// Status",
"$",
"this",
"->",
"swResponse",
"->",
"status",
"(",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
")",
";",
"// Headers",
"foreach",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"swResponse",
"->",
"header",
"(",
"$",
"name",
",",
"implode",
"(",
"', '",
",",
"$",
"value",
")",
")",
";",
"}",
"}"
] |
发送响应头部报文
|
[
"发送响应头部报文"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Response.php#L158-L166
|
movoin/one-swoole
|
src/Protocol/Message/Response.php
|
Response.sendSecurityHeaders
|
public function sendSecurityHeaders()
{
$this->swResponse->header('Content-Security-Policy', "default-src 'none'");
$this->swResponse->header('X-Content-Type-Options', 'nosniff');
$this->swResponse->header('X-Frame-Options', 'deny');
}
|
php
|
public function sendSecurityHeaders()
{
$this->swResponse->header('Content-Security-Policy', "default-src 'none'");
$this->swResponse->header('X-Content-Type-Options', 'nosniff');
$this->swResponse->header('X-Frame-Options', 'deny');
}
|
[
"public",
"function",
"sendSecurityHeaders",
"(",
")",
"{",
"$",
"this",
"->",
"swResponse",
"->",
"header",
"(",
"'Content-Security-Policy'",
",",
"\"default-src 'none'\"",
")",
";",
"$",
"this",
"->",
"swResponse",
"->",
"header",
"(",
"'X-Content-Type-Options'",
",",
"'nosniff'",
")",
";",
"$",
"this",
"->",
"swResponse",
"->",
"header",
"(",
"'X-Frame-Options'",
",",
"'deny'",
")",
";",
"}"
] |
发送安全相关的头部报文
|
[
"发送安全相关的头部报文"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Response.php#L171-L176
|
movoin/one-swoole
|
src/Protocol/Message/Response.php
|
Response.withSwooleResponse
|
public function withSwooleResponse(SwooleResponse $swResponse): self
{
if ($this->swResponse === $swResponse) {
return $this;
}
$clone = clone $this;
$clone->swResponse = $swResponse;
return $clone;
}
|
php
|
public function withSwooleResponse(SwooleResponse $swResponse): self
{
if ($this->swResponse === $swResponse) {
return $this;
}
$clone = clone $this;
$clone->swResponse = $swResponse;
return $clone;
}
|
[
"public",
"function",
"withSwooleResponse",
"(",
"SwooleResponse",
"$",
"swResponse",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"swResponse",
"===",
"$",
"swResponse",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"swResponse",
"=",
"$",
"swResponse",
";",
"return",
"$",
"clone",
";",
"}"
] |
获得指定 Swoole 响应对象的响应对象
@param \Swoole\Http\Response $swResponse
@return self
|
[
"获得指定",
"Swoole",
"响应对象的响应对象"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Response.php#L203-L213
|
movoin/one-swoole
|
src/Protocol/Message/Response.php
|
Response.getReasonPhrase
|
public function getReasonPhrase(): string
{
if ($this->reasonPhrase) {
return $this->reasonPhrase;
}
return isset(static::$messages[$this->status]) ? static::$messages[$this->status] : null;
}
|
php
|
public function getReasonPhrase(): string
{
if ($this->reasonPhrase) {
return $this->reasonPhrase;
}
return isset(static::$messages[$this->status]) ? static::$messages[$this->status] : null;
}
|
[
"public",
"function",
"getReasonPhrase",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"reasonPhrase",
")",
"{",
"return",
"$",
"this",
"->",
"reasonPhrase",
";",
"}",
"return",
"isset",
"(",
"static",
"::",
"$",
"messages",
"[",
"$",
"this",
"->",
"status",
"]",
")",
"?",
"static",
"::",
"$",
"messages",
"[",
"$",
"this",
"->",
"status",
"]",
":",
"null",
";",
"}"
] |
获得错误原因
@return string
|
[
"获得错误原因"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Response.php#L279-L286
|
movoin/one-swoole
|
src/Protocol/Message/Response.php
|
Response.withHeader
|
public function withHeader($name, $value): self
{
$this->assertHeaderName($name);
$clone = clone $this;
$clone->headers->set($name, $value);
if ($clone->getStatusCode() === 200 && strtolower($name) === 'location') {
$clone = $clone->withStatus(302);
}
return $clone;
}
|
php
|
public function withHeader($name, $value): self
{
$this->assertHeaderName($name);
$clone = clone $this;
$clone->headers->set($name, $value);
if ($clone->getStatusCode() === 200 && strtolower($name) === 'location') {
$clone = $clone->withStatus(302);
}
return $clone;
}
|
[
"public",
"function",
"withHeader",
"(",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"assertHeaderName",
"(",
"$",
"name",
")",
";",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"headers",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"clone",
"->",
"getStatusCode",
"(",
")",
"===",
"200",
"&&",
"strtolower",
"(",
"$",
"name",
")",
"===",
"'location'",
")",
"{",
"$",
"clone",
"=",
"$",
"clone",
"->",
"withStatus",
"(",
"302",
")",
";",
"}",
"return",
"$",
"clone",
";",
"}"
] |
获得指定头信息的消息对象
@param string $name
@param mixed $value
@return self
@throws \InvalidArgumentException
|
[
"获得指定头信息的消息对象"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Response.php#L297-L309
|
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
|
src/App/Normalizer/Component/ErrorDocNormalizer.php
|
ErrorDocNormalizer.normalize
|
public function normalize(ErrorDoc $errorDoc) : array
{
$requiredDoc = ['required' => ['code']];
$properties = [
'code' => ['example' => $errorDoc->getCode()]
];
if (null !== $errorDoc->getDataDoc()) {
$properties['data'] = $this->typeDocNormalizer->normalize($errorDoc->getDataDoc());
if (false !== $errorDoc->getDataDoc()->isRequired()) {
$requiredDoc['required'][] = 'data';
}
}
if (null !== $errorDoc->getMessage()) {
$properties['message'] = ['example' => $errorDoc->getMessage()];
}
return [
'title' => $errorDoc->getTitle(),
'allOf' => [
$this->shapeNormalizer->getErrorShapeDefinition(),
(['type' => 'object'] + $requiredDoc + ['properties' => $properties]),
],
];
}
|
php
|
public function normalize(ErrorDoc $errorDoc) : array
{
$requiredDoc = ['required' => ['code']];
$properties = [
'code' => ['example' => $errorDoc->getCode()]
];
if (null !== $errorDoc->getDataDoc()) {
$properties['data'] = $this->typeDocNormalizer->normalize($errorDoc->getDataDoc());
if (false !== $errorDoc->getDataDoc()->isRequired()) {
$requiredDoc['required'][] = 'data';
}
}
if (null !== $errorDoc->getMessage()) {
$properties['message'] = ['example' => $errorDoc->getMessage()];
}
return [
'title' => $errorDoc->getTitle(),
'allOf' => [
$this->shapeNormalizer->getErrorShapeDefinition(),
(['type' => 'object'] + $requiredDoc + ['properties' => $properties]),
],
];
}
|
[
"public",
"function",
"normalize",
"(",
"ErrorDoc",
"$",
"errorDoc",
")",
":",
"array",
"{",
"$",
"requiredDoc",
"=",
"[",
"'required'",
"=>",
"[",
"'code'",
"]",
"]",
";",
"$",
"properties",
"=",
"[",
"'code'",
"=>",
"[",
"'example'",
"=>",
"$",
"errorDoc",
"->",
"getCode",
"(",
")",
"]",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"errorDoc",
"->",
"getDataDoc",
"(",
")",
")",
"{",
"$",
"properties",
"[",
"'data'",
"]",
"=",
"$",
"this",
"->",
"typeDocNormalizer",
"->",
"normalize",
"(",
"$",
"errorDoc",
"->",
"getDataDoc",
"(",
")",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"errorDoc",
"->",
"getDataDoc",
"(",
")",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"requiredDoc",
"[",
"'required'",
"]",
"[",
"]",
"=",
"'data'",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"errorDoc",
"->",
"getMessage",
"(",
")",
")",
"{",
"$",
"properties",
"[",
"'message'",
"]",
"=",
"[",
"'example'",
"=>",
"$",
"errorDoc",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"return",
"[",
"'title'",
"=>",
"$",
"errorDoc",
"->",
"getTitle",
"(",
")",
",",
"'allOf'",
"=>",
"[",
"$",
"this",
"->",
"shapeNormalizer",
"->",
"getErrorShapeDefinition",
"(",
")",
",",
"(",
"[",
"'type'",
"=>",
"'object'",
"]",
"+",
"$",
"requiredDoc",
"+",
"[",
"'properties'",
"=>",
"$",
"properties",
"]",
")",
",",
"]",
",",
"]",
";",
"}"
] |
@param ErrorDoc $errorDoc
@return array
@throws \ReflectionException
|
[
"@param",
"ErrorDoc",
"$errorDoc"
] |
train
|
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/src/App/Normalizer/Component/ErrorDocNormalizer.php#L35-L58
|
datasift/datasift-php
|
lib/DataSift/ODP.php
|
DataSift_ODP.ingest
|
public function ingest($data_set)
{
if (strlen($this->_source_id) == 0) {
throw new DataSift_Exception_InvalidData('Cannot make request without a source ID');
}
if (empty($data_set)) {
throw new DataSift_Exception_InvalidData('Cannot make request without a valid data set');
}
return $this->_user->post($this->getSourceId(), $data_set, array(), true);
}
|
php
|
public function ingest($data_set)
{
if (strlen($this->_source_id) == 0) {
throw new DataSift_Exception_InvalidData('Cannot make request without a source ID');
}
if (empty($data_set)) {
throw new DataSift_Exception_InvalidData('Cannot make request without a valid data set');
}
return $this->_user->post($this->getSourceId(), $data_set, array(), true);
}
|
[
"public",
"function",
"ingest",
"(",
"$",
"data_set",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"_source_id",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"DataSift_Exception_InvalidData",
"(",
"'Cannot make request without a source ID'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data_set",
")",
")",
"{",
"throw",
"new",
"DataSift_Exception_InvalidData",
"(",
"'Cannot make request without a valid data set'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_user",
"->",
"post",
"(",
"$",
"this",
"->",
"getSourceId",
"(",
")",
",",
"$",
"data_set",
",",
"array",
"(",
")",
",",
"true",
")",
";",
"}"
] |
Generates a curl request to the Ingestion Endpoint
|
[
"Generates",
"a",
"curl",
"request",
"to",
"the",
"Ingestion",
"Endpoint"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/ODP.php#L67-L78
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/ObjectManager.php
|
ObjectManager.addObject
|
public function addObject($object, $state, $repository)
{
$data = $repository->getHydrator()->unhydrate($object);
$oid = spl_object_hash($object);
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
if (!isset($this->objectStates[$id])) {
$this->objectStates[$id] = $state;
}
$this->objects[$id] = $object;
$this->objectsRepository[$oid] = $repository;
}
|
php
|
public function addObject($object, $state, $repository)
{
$data = $repository->getHydrator()->unhydrate($object);
$oid = spl_object_hash($object);
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
if (!isset($this->objectStates[$id])) {
$this->objectStates[$id] = $state;
}
$this->objects[$id] = $object;
$this->objectsRepository[$oid] = $repository;
}
|
[
"public",
"function",
"addObject",
"(",
"$",
"object",
",",
"$",
"state",
",",
"$",
"repository",
")",
"{",
"$",
"data",
"=",
"$",
"repository",
"->",
"getHydrator",
"(",
")",
"->",
"unhydrate",
"(",
"$",
"object",
")",
";",
"$",
"oid",
"=",
"spl_object_hash",
"(",
"$",
"object",
")",
";",
"$",
"id",
"=",
"isset",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
"?",
"serialize",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
".",
"$",
"repository",
"->",
"getCollection",
"(",
")",
":",
"$",
"oid",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
"=",
"$",
"state",
";",
"}",
"$",
"this",
"->",
"objects",
"[",
"$",
"id",
"]",
"=",
"$",
"object",
";",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
"=",
"$",
"repository",
";",
"}"
] |
Add an object
@param mixed $object Object to add
@param int $state State of this object
@return void
|
[
"Add",
"an",
"object"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/ObjectManager.php#L43-L54
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/ObjectManager.php
|
ObjectManager.removeObject
|
public function removeObject($object)
{
$oid = spl_object_hash($object);
$data = [];
if (isset($this->objectsRepository[$oid])) {
$repository = $this->objectsRepository[$oid];
$data = $repository->getHydrator()->unhydrate($object);
}
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
if (!isset($this->objectStates[$id])) {
throw new Exception\StateException("Can't remove object, it does not be managed");
}
unset($this->objectStates[$id]);
unset($this->objects[$id]);
unset($this->objectsRepository[$id]);
unset($this->objectStates[$oid]);
unset($this->objects[$oid]);
unset($this->objectsRepository[$oid]);
}
|
php
|
public function removeObject($object)
{
$oid = spl_object_hash($object);
$data = [];
if (isset($this->objectsRepository[$oid])) {
$repository = $this->objectsRepository[$oid];
$data = $repository->getHydrator()->unhydrate($object);
}
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
if (!isset($this->objectStates[$id])) {
throw new Exception\StateException("Can't remove object, it does not be managed");
}
unset($this->objectStates[$id]);
unset($this->objects[$id]);
unset($this->objectsRepository[$id]);
unset($this->objectStates[$oid]);
unset($this->objects[$oid]);
unset($this->objectsRepository[$oid]);
}
|
[
"public",
"function",
"removeObject",
"(",
"$",
"object",
")",
"{",
"$",
"oid",
"=",
"spl_object_hash",
"(",
"$",
"object",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
")",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
";",
"$",
"data",
"=",
"$",
"repository",
"->",
"getHydrator",
"(",
")",
"->",
"unhydrate",
"(",
"$",
"object",
")",
";",
"}",
"$",
"id",
"=",
"isset",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
"?",
"serialize",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
".",
"$",
"repository",
"->",
"getCollection",
"(",
")",
":",
"$",
"oid",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"StateException",
"(",
"\"Can't remove object, it does not be managed\"",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"oid",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"oid",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
")",
";",
"}"
] |
Unpersist object
@param mixed $object Object to unpersist
@return void
|
[
"Unpersist",
"object"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/ObjectManager.php#L62-L82
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/ObjectManager.php
|
ObjectManager.setObjectState
|
public function setObjectState($object, $state)
{
if (is_object($object)) {
$oid = spl_object_hash($object);
$repository = $this->objectsRepository[$oid];
$data = $repository->getHydrator()->unhydrate($object);
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
} else {
return false;
}
if (!isset($this->objectStates[$id]) && !isset($this->objectStates[$oid])) {
throw new Exception\StateException();
}
if (!in_array($state, [self::OBJ_MANAGED, self::OBJ_NEW, self::OBJ_REMOVED])) {
throw new Exception\StateException("Invalid state '$state'");
}
if ($state == self::OBJ_REMOVED && isset($this->objectStates[$oid]) && $this->objectStates[$oid] == self::OBJ_NEW) {
throw new Exception\StateException("Can't change state to removed because object is not managed. Insert it in database before");
}
if (isset($this->objectStates[$oid])) {
unset($this->objectStates[$oid]);
unset($this->objects[$oid]);
}
$this->objectStates[$id] = $state;
$this->objects[$id] = $object;
return true;
}
|
php
|
public function setObjectState($object, $state)
{
if (is_object($object)) {
$oid = spl_object_hash($object);
$repository = $this->objectsRepository[$oid];
$data = $repository->getHydrator()->unhydrate($object);
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
} else {
return false;
}
if (!isset($this->objectStates[$id]) && !isset($this->objectStates[$oid])) {
throw new Exception\StateException();
}
if (!in_array($state, [self::OBJ_MANAGED, self::OBJ_NEW, self::OBJ_REMOVED])) {
throw new Exception\StateException("Invalid state '$state'");
}
if ($state == self::OBJ_REMOVED && isset($this->objectStates[$oid]) && $this->objectStates[$oid] == self::OBJ_NEW) {
throw new Exception\StateException("Can't change state to removed because object is not managed. Insert it in database before");
}
if (isset($this->objectStates[$oid])) {
unset($this->objectStates[$oid]);
unset($this->objects[$oid]);
}
$this->objectStates[$id] = $state;
$this->objects[$id] = $object;
return true;
}
|
[
"public",
"function",
"setObjectState",
"(",
"$",
"object",
",",
"$",
"state",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"$",
"oid",
"=",
"spl_object_hash",
"(",
"$",
"object",
")",
";",
"$",
"repository",
"=",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
";",
"$",
"data",
"=",
"$",
"repository",
"->",
"getHydrator",
"(",
")",
"->",
"unhydrate",
"(",
"$",
"object",
")",
";",
"$",
"id",
"=",
"isset",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
"?",
"serialize",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
".",
"$",
"repository",
"->",
"getCollection",
"(",
")",
":",
"$",
"oid",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"oid",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"StateException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"state",
",",
"[",
"self",
"::",
"OBJ_MANAGED",
",",
"self",
"::",
"OBJ_NEW",
",",
"self",
"::",
"OBJ_REMOVED",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"StateException",
"(",
"\"Invalid state '$state'\"",
")",
";",
"}",
"if",
"(",
"$",
"state",
"==",
"self",
"::",
"OBJ_REMOVED",
"&&",
"isset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"oid",
"]",
")",
"&&",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"oid",
"]",
"==",
"self",
"::",
"OBJ_NEW",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"StateException",
"(",
"\"Can't change state to removed because object is not managed. Insert it in database before\"",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"oid",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"oid",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"oid",
"]",
")",
";",
"}",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
"=",
"$",
"state",
";",
"$",
"this",
"->",
"objects",
"[",
"$",
"id",
"]",
"=",
"$",
"object",
";",
"return",
"true",
";",
"}"
] |
Update object state
@param mixed $object Object to change state
@param int $state New state
@return void
|
[
"Update",
"object",
"state"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/ObjectManager.php#L91-L123
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/ObjectManager.php
|
ObjectManager.getObjectState
|
public function getObjectState($object)
{
$oid = spl_object_hash($object);
if (isset($this->objectsRepository[$oid])) {
$repository = $this->objectsRepository[$oid];
$data = $repository->getHydrator()->unhydrate($object);
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
if (isset($this->objectStates[$id])) {
return $this->objectStates[$id];
}
}
return null;
}
|
php
|
public function getObjectState($object)
{
$oid = spl_object_hash($object);
if (isset($this->objectsRepository[$oid])) {
$repository = $this->objectsRepository[$oid];
$data = $repository->getHydrator()->unhydrate($object);
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
if (isset($this->objectStates[$id])) {
return $this->objectStates[$id];
}
}
return null;
}
|
[
"public",
"function",
"getObjectState",
"(",
"$",
"object",
")",
"{",
"$",
"oid",
"=",
"spl_object_hash",
"(",
"$",
"object",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
")",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
";",
"$",
"data",
"=",
"$",
"repository",
"->",
"getHydrator",
"(",
")",
"->",
"unhydrate",
"(",
"$",
"object",
")",
";",
"$",
"id",
"=",
"isset",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
"?",
"serialize",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
".",
"$",
"repository",
"->",
"getCollection",
"(",
")",
":",
"$",
"oid",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get object state
@param mixed $object
@return void
|
[
"Get",
"object",
"state"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/ObjectManager.php#L131-L145
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/ObjectManager.php
|
ObjectManager.getObjects
|
public function getObjects($state = null)
{
if (!isset($state)) {
return $this->objects;
}
$objectList = [];
foreach ($this->objects as $id => $object) {
if ($this->objectStates[$id] == $state) {
$objectList[$id] = $object;
}
}
return $objectList;
}
|
php
|
public function getObjects($state = null)
{
if (!isset($state)) {
return $this->objects;
}
$objectList = [];
foreach ($this->objects as $id => $object) {
if ($this->objectStates[$id] == $state) {
$objectList[$id] = $object;
}
}
return $objectList;
}
|
[
"public",
"function",
"getObjects",
"(",
"$",
"state",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"state",
")",
")",
"{",
"return",
"$",
"this",
"->",
"objects",
";",
"}",
"$",
"objectList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"objects",
"as",
"$",
"id",
"=>",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"objectStates",
"[",
"$",
"id",
"]",
"==",
"$",
"state",
")",
"{",
"$",
"objectList",
"[",
"$",
"id",
"]",
"=",
"$",
"object",
";",
"}",
"}",
"return",
"$",
"objectList",
";",
"}"
] |
Get object with specified state
@param int $state State to search
@return array
|
[
"Get",
"object",
"with",
"specified",
"state"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/ObjectManager.php#L153-L167
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/ObjectManager.php
|
ObjectManager.hasObject
|
public function hasObject($object)
{
$oid = spl_object_hash($object);
if (!isset($this->objectsRepository[$oid])) {
return false;
}
$repository = $this->objectsRepository[$oid];
$data = $repository->getHydrator()->unhydrate($object);
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
return isset($this->objects[$oid]) || isset($this->objects[$id]);
}
|
php
|
public function hasObject($object)
{
$oid = spl_object_hash($object);
if (!isset($this->objectsRepository[$oid])) {
return false;
}
$repository = $this->objectsRepository[$oid];
$data = $repository->getHydrator()->unhydrate($object);
$id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;
return isset($this->objects[$oid]) || isset($this->objects[$id]);
}
|
[
"public",
"function",
"hasObject",
"(",
"$",
"object",
")",
"{",
"$",
"oid",
"=",
"spl_object_hash",
"(",
"$",
"object",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"repository",
"=",
"$",
"this",
"->",
"objectsRepository",
"[",
"$",
"oid",
"]",
";",
"$",
"data",
"=",
"$",
"repository",
"->",
"getHydrator",
"(",
")",
"->",
"unhydrate",
"(",
"$",
"object",
")",
";",
"$",
"id",
"=",
"isset",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
"?",
"serialize",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
".",
"$",
"repository",
"->",
"getCollection",
"(",
")",
":",
"$",
"oid",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"oid",
"]",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"id",
"]",
")",
";",
"}"
] |
Check if object is managed
@param mixed $object Object to search
@return boolean
|
[
"Check",
"if",
"object",
"is",
"managed"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/ObjectManager.php#L188-L199
|
fsi-open/datasource-bundle
|
DataSource/Extension/Symfony/DependencyInjection/Driver/DriverExtension.php
|
DriverExtension.getFieldType
|
public function getFieldType($type)
{
if (!array_key_exists($type, $this->fieldTypes)) {
throw new \InvalidArgumentException(sprintf('The field type "%s" is not registered within the service container.', $type));
}
return $this->fieldTypes[$type];
}
|
php
|
public function getFieldType($type)
{
if (!array_key_exists($type, $this->fieldTypes)) {
throw new \InvalidArgumentException(sprintf('The field type "%s" is not registered within the service container.', $type));
}
return $this->fieldTypes[$type];
}
|
[
"public",
"function",
"getFieldType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"fieldTypes",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The field type \"%s\" is not registered within the service container.'",
",",
"$",
"type",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"fieldTypes",
"[",
"$",
"type",
"]",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/fsi-open/datasource-bundle/blob/06964672c838af9f4125065e3a90b2df4e8aa077/DataSource/Extension/Symfony/DependencyInjection/Driver/DriverExtension.php#L88-L95
|
vardius/list-bundle
|
Column/Types/Type/DateType.php
|
DateType.getData
|
public function getData($entity = null, array $options = []):array
{
$property = null;
$callable = $options['callback'];
if (is_callable($callable)) {
$property = call_user_func_array($callable, [$entity]);
} else {
$method = ucfirst($options['property']);
if (method_exists($entity, 'get' . $method)) {
$property = $entity->{'get' . $method}();
} elseif (method_exists($entity, 'is' . $method)) {
$property = $entity->{'is' . $method}();
}
}
$action = $options['row_action'];
if (is_array($action) && !empty($action) && $entity !== null) {
$action['parameters']['id'] = $entity->getId();
}
return [
'property' => $property,
'action' => $action,
'format' => $options['date_format'],
];
}
|
php
|
public function getData($entity = null, array $options = []):array
{
$property = null;
$callable = $options['callback'];
if (is_callable($callable)) {
$property = call_user_func_array($callable, [$entity]);
} else {
$method = ucfirst($options['property']);
if (method_exists($entity, 'get' . $method)) {
$property = $entity->{'get' . $method}();
} elseif (method_exists($entity, 'is' . $method)) {
$property = $entity->{'is' . $method}();
}
}
$action = $options['row_action'];
if (is_array($action) && !empty($action) && $entity !== null) {
$action['parameters']['id'] = $entity->getId();
}
return [
'property' => $property,
'action' => $action,
'format' => $options['date_format'],
];
}
|
[
"public",
"function",
"getData",
"(",
"$",
"entity",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"array",
"{",
"$",
"property",
"=",
"null",
";",
"$",
"callable",
"=",
"$",
"options",
"[",
"'callback'",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"callable",
")",
")",
"{",
"$",
"property",
"=",
"call_user_func_array",
"(",
"$",
"callable",
",",
"[",
"$",
"entity",
"]",
")",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"ucfirst",
"(",
"$",
"options",
"[",
"'property'",
"]",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"entity",
",",
"'get'",
".",
"$",
"method",
")",
")",
"{",
"$",
"property",
"=",
"$",
"entity",
"->",
"{",
"'get'",
".",
"$",
"method",
"}",
"(",
")",
";",
"}",
"elseif",
"(",
"method_exists",
"(",
"$",
"entity",
",",
"'is'",
".",
"$",
"method",
")",
")",
"{",
"$",
"property",
"=",
"$",
"entity",
"->",
"{",
"'is'",
".",
"$",
"method",
"}",
"(",
")",
";",
"}",
"}",
"$",
"action",
"=",
"$",
"options",
"[",
"'row_action'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"action",
")",
"&&",
"!",
"empty",
"(",
"$",
"action",
")",
"&&",
"$",
"entity",
"!==",
"null",
")",
"{",
"$",
"action",
"[",
"'parameters'",
"]",
"[",
"'id'",
"]",
"=",
"$",
"entity",
"->",
"getId",
"(",
")",
";",
"}",
"return",
"[",
"'property'",
"=>",
"$",
"property",
",",
"'action'",
"=>",
"$",
"action",
",",
"'format'",
"=>",
"$",
"options",
"[",
"'date_format'",
"]",
",",
"]",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vardius/list-bundle/blob/70d3079ce22eed7dad7c467fee532aa2f18c68c9/Column/Types/Type/DateType.php#L26-L51
|
drunomics/service-utils
|
src/Core/Path/AliasManagerTrait.php
|
AliasManagerTrait.getAliasManager
|
public function getAliasManager() {
if (empty($this->aliasManager)) {
$this->aliasManager = \Drupal::service('path.alias_manager');
}
return $this->aliasManager;
}
|
php
|
public function getAliasManager() {
if (empty($this->aliasManager)) {
$this->aliasManager = \Drupal::service('path.alias_manager');
}
return $this->aliasManager;
}
|
[
"public",
"function",
"getAliasManager",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"aliasManager",
")",
")",
"{",
"$",
"this",
"->",
"aliasManager",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'path.alias_manager'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"aliasManager",
";",
"}"
] |
Gets the entity repository.
@return \Drupal\Core\Path\AliasManagerInterface
The alias manager.
|
[
"Gets",
"the",
"entity",
"repository",
"."
] |
train
|
https://github.com/drunomics/service-utils/blob/56761750043132365ef4ae5d9e0cf4263459328f/src/Core/Path/AliasManagerTrait.php#L38-L43
|
PandawanTechnology/neo4j-data-fixtures
|
src/AbstractNeo4jFixture.php
|
AbstractNeo4jFixture.getReference
|
public function getReference($name)
{
if (!isset(static::$references[$name])) {
throw new \OutOfBoundsException(sprintf('The reference "%s" does not exist.', $name));
}
return static::$references[$name];
}
|
php
|
public function getReference($name)
{
if (!isset(static::$references[$name])) {
throw new \OutOfBoundsException(sprintf('The reference "%s" does not exist.', $name));
}
return static::$references[$name];
}
|
[
"public",
"function",
"getReference",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"references",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'The reference \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"static",
"::",
"$",
"references",
"[",
"$",
"name",
"]",
";",
"}"
] |
@param string $name
@return mixed
|
[
"@param",
"string",
"$name"
] |
train
|
https://github.com/PandawanTechnology/neo4j-data-fixtures/blob/58701f30f3de9c848308623c5e773aada106a2aa/src/AbstractNeo4jFixture.php#L39-L46
|
yosmanyga/resource
|
src/Yosmanyga/Resource/Reader/Iterator/DelegatorReader.php
|
DelegatorReader.open
|
public function open(Resource $resource)
{
$this->reader = $this->pickReader($resource);
$this->reader->open($resource);
}
|
php
|
public function open(Resource $resource)
{
$this->reader = $this->pickReader($resource);
$this->reader->open($resource);
}
|
[
"public",
"function",
"open",
"(",
"Resource",
"$",
"resource",
")",
"{",
"$",
"this",
"->",
"reader",
"=",
"$",
"this",
"->",
"pickReader",
"(",
"$",
"resource",
")",
";",
"$",
"this",
"->",
"reader",
"->",
"open",
"(",
"$",
"resource",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Reader/Iterator/DelegatorReader.php#L51-L55
|
yosmanyga/resource
|
src/Yosmanyga/Resource/Reader/Iterator/DelegatorReader.php
|
DelegatorReader.pickReader
|
protected function pickReader($resource)
{
foreach ($this->readers as $i => $reader) {
if ($reader->supports($resource)) {
if (0 != $i) {
// Move reader to top to improve next pick
unset($this->readers[$i]);
array_unshift($this->readers, $reader);
}
return $reader;
}
}
throw new \RuntimeException('No reader is able to support the resource.');
}
|
php
|
protected function pickReader($resource)
{
foreach ($this->readers as $i => $reader) {
if ($reader->supports($resource)) {
if (0 != $i) {
// Move reader to top to improve next pick
unset($this->readers[$i]);
array_unshift($this->readers, $reader);
}
return $reader;
}
}
throw new \RuntimeException('No reader is able to support the resource.');
}
|
[
"protected",
"function",
"pickReader",
"(",
"$",
"resource",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"readers",
"as",
"$",
"i",
"=>",
"$",
"reader",
")",
"{",
"if",
"(",
"$",
"reader",
"->",
"supports",
"(",
"$",
"resource",
")",
")",
"{",
"if",
"(",
"0",
"!=",
"$",
"i",
")",
"{",
"// Move reader to top to improve next pick",
"unset",
"(",
"$",
"this",
"->",
"readers",
"[",
"$",
"i",
"]",
")",
";",
"array_unshift",
"(",
"$",
"this",
"->",
"readers",
",",
"$",
"reader",
")",
";",
"}",
"return",
"$",
"reader",
";",
"}",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No reader is able to support the resource.'",
")",
";",
"}"
] |
@param \Yosmanyga\Resource\Resource $resource
@throws \RuntimeException If no reader is able to support the
resource
@return \Yosmanyga\Resource\Reader\Iterator\ReaderInterface
|
[
"@param",
"\\",
"Yosmanyga",
"\\",
"Resource",
"\\",
"Resource",
"$resource"
] |
train
|
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Reader/Iterator/DelegatorReader.php#L91-L106
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.start
|
public function start()
{
if ($this->isRunning() === false) {
$this
->createProtocol(
$this->getConfig('protocol')
)
->createSwooleServer(
$this->getConfig('protocol'),
$this->getConfig('')
)
->initializeCoreProviders()
->initializeProviders()
;
// {{ log
$this->get('logger')->info(
sprintf(
'启动服务 %s',
$this->getConfig('listen')
)
);
// }}
$this->bootServerStartItems();
$this->runSwoole();
}
}
|
php
|
public function start()
{
if ($this->isRunning() === false) {
$this
->createProtocol(
$this->getConfig('protocol')
)
->createSwooleServer(
$this->getConfig('protocol'),
$this->getConfig('')
)
->initializeCoreProviders()
->initializeProviders()
;
// {{ log
$this->get('logger')->info(
sprintf(
'启动服务 %s',
$this->getConfig('listen')
)
);
// }}
$this->bootServerStartItems();
$this->runSwoole();
}
}
|
[
"public",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isRunning",
"(",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"createProtocol",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'protocol'",
")",
")",
"->",
"createSwooleServer",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'protocol'",
")",
",",
"$",
"this",
"->",
"getConfig",
"(",
"''",
")",
")",
"->",
"initializeCoreProviders",
"(",
")",
"->",
"initializeProviders",
"(",
")",
";",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"sprintf",
"(",
"'启动服务 %s',",
"",
"$",
"this",
"->",
"getConfig",
"(",
"'listen'",
")",
")",
")",
";",
"// }}",
"$",
"this",
"->",
"bootServerStartItems",
"(",
")",
";",
"$",
"this",
"->",
"runSwoole",
"(",
")",
";",
"}",
"}"
] |
启动 Server
|
[
"启动",
"Server"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L53-L80
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.stop
|
public function stop()
{
if ($this->isRunning()) {
$pid = $this->getPid();
// {{
$this->initializeCoreProviders();
$this->createProtocol($this->getConfig('protocol'));
$this->shutdownServerStartItems();
// }}
// {{ log
$this->get('logger')->info(
sprintf(
'停止服务 %s',
$this->getConfig('listen')
),
[
'pid' => $pid
]
);
// }}
posix_kill($pid, SIGTERM);
}
}
|
php
|
public function stop()
{
if ($this->isRunning()) {
$pid = $this->getPid();
// {{
$this->initializeCoreProviders();
$this->createProtocol($this->getConfig('protocol'));
$this->shutdownServerStartItems();
// }}
// {{ log
$this->get('logger')->info(
sprintf(
'停止服务 %s',
$this->getConfig('listen')
),
[
'pid' => $pid
]
);
// }}
posix_kill($pid, SIGTERM);
}
}
|
[
"public",
"function",
"stop",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isRunning",
"(",
")",
")",
"{",
"$",
"pid",
"=",
"$",
"this",
"->",
"getPid",
"(",
")",
";",
"// {{",
"$",
"this",
"->",
"initializeCoreProviders",
"(",
")",
";",
"$",
"this",
"->",
"createProtocol",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'protocol'",
")",
")",
";",
"$",
"this",
"->",
"shutdownServerStartItems",
"(",
")",
";",
"// }}",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"sprintf",
"(",
"'停止服务 %s',",
"",
"$",
"this",
"->",
"getConfig",
"(",
"'listen'",
")",
")",
",",
"[",
"'pid'",
"=>",
"$",
"pid",
"]",
")",
";",
"// }}",
"posix_kill",
"(",
"$",
"pid",
",",
"SIGTERM",
")",
";",
"}",
"}"
] |
停止 Server
|
[
"停止",
"Server"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L85-L110
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onMasterStart
|
public function onMasterStart(SwServer $server)
{
// {{
$this->setRunUser();
$this->setProcessName('master');
// }}
// {{ log
$this->get('logger')->info('启动 Master 进程', [
'pid' => $server->master_pid
]);
// }}
}
|
php
|
public function onMasterStart(SwServer $server)
{
// {{
$this->setRunUser();
$this->setProcessName('master');
// }}
// {{ log
$this->get('logger')->info('启动 Master 进程', [
'pid' => $server->master_pid
]);
// }}
}
|
[
"public",
"function",
"onMasterStart",
"(",
"SwServer",
"$",
"server",
")",
"{",
"// {{",
"$",
"this",
"->",
"setRunUser",
"(",
")",
";",
"$",
"this",
"->",
"setProcessName",
"(",
"'master'",
")",
";",
"// }}",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'启动 Master 进程', [",
"",
"",
"'pid'",
"=>",
"$",
"server",
"->",
"master_pid",
"]",
")",
";",
"// }}",
"}"
] |
主进程启动
@param \Swoole\Server $server
|
[
"主进程启动"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L119-L131
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onManagerStart
|
public function onManagerStart(SwServer $server)
{
// {{
$this->setRunUser();
$this->setProcessName('manager');
// }}
// {{ log
$this->get('logger')->info('启动 Manager 进程', [
'pid' => $server->manager_pid
]);
// }}
}
|
php
|
public function onManagerStart(SwServer $server)
{
// {{
$this->setRunUser();
$this->setProcessName('manager');
// }}
// {{ log
$this->get('logger')->info('启动 Manager 进程', [
'pid' => $server->manager_pid
]);
// }}
}
|
[
"public",
"function",
"onManagerStart",
"(",
"SwServer",
"$",
"server",
")",
"{",
"// {{",
"$",
"this",
"->",
"setRunUser",
"(",
")",
";",
"$",
"this",
"->",
"setProcessName",
"(",
"'manager'",
")",
";",
"// }}",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'启动 Manager 进程', [",
"",
"",
"'pid'",
"=>",
"$",
"server",
"->",
"manager_pid",
"]",
")",
";",
"// }}",
"}"
] |
管理进程启动
@param \Swoole\Server $server
|
[
"管理进程启动"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L150-L162
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onWorkerStart
|
public function onWorkerStart(SwServer $server, int $workerId)
{
$workerType = $server->taskworker ? 'task' : 'worker';
// {{
$this->setRunUser();
$this->setProcessName($workerType . ' #' . $workerId);
// }}
// {{ log
$this->get('logger')->info('启动 Worker 进程', [
'id' => $workerId,
'pid' => $server->worker_pid,
'type' => ucfirst($workerType)
]);
// }}
if ($workerType === 'worker') {
// {{
$this->bootWorkerStartItems($workerId);
// }}
$this->callProtocolMethod('onStart', $server, $workerId);
}
unset($workerType);
}
|
php
|
public function onWorkerStart(SwServer $server, int $workerId)
{
$workerType = $server->taskworker ? 'task' : 'worker';
// {{
$this->setRunUser();
$this->setProcessName($workerType . ' #' . $workerId);
// }}
// {{ log
$this->get('logger')->info('启动 Worker 进程', [
'id' => $workerId,
'pid' => $server->worker_pid,
'type' => ucfirst($workerType)
]);
// }}
if ($workerType === 'worker') {
// {{
$this->bootWorkerStartItems($workerId);
// }}
$this->callProtocolMethod('onStart', $server, $workerId);
}
unset($workerType);
}
|
[
"public",
"function",
"onWorkerStart",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"workerId",
")",
"{",
"$",
"workerType",
"=",
"$",
"server",
"->",
"taskworker",
"?",
"'task'",
":",
"'worker'",
";",
"// {{",
"$",
"this",
"->",
"setRunUser",
"(",
")",
";",
"$",
"this",
"->",
"setProcessName",
"(",
"$",
"workerType",
".",
"' #'",
".",
"$",
"workerId",
")",
";",
"// }}",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'启动 Worker 进程', [",
"",
"",
"'id'",
"=>",
"$",
"workerId",
",",
"'pid'",
"=>",
"$",
"server",
"->",
"worker_pid",
",",
"'type'",
"=>",
"ucfirst",
"(",
"$",
"workerType",
")",
"]",
")",
";",
"// }}",
"if",
"(",
"$",
"workerType",
"===",
"'worker'",
")",
"{",
"// {{",
"$",
"this",
"->",
"bootWorkerStartItems",
"(",
"$",
"workerId",
")",
";",
"// }}",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onStart'",
",",
"$",
"server",
",",
"$",
"workerId",
")",
";",
"}",
"unset",
"(",
"$",
"workerType",
")",
";",
"}"
] |
工作进程启动
@param \Swoole\Server $server
@param int $workerId
|
[
"工作进程启动"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L170-L195
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onWorkerStop
|
public function onWorkerStop(SwServer $server, int $workerId)
{
$workerType = $server->taskworker ? 'task' : 'worker';
// {{ log
$this->get('logger')->info('结束 Worker 进程', [
'id' => $workerId,
'type' => ucfirst($workerType)
]);
// }}
if ($workerType === 'worker') {
$this->shutdownWorkerStartItems();
$this->callProtocolMethod('onStop', $server, $workerId);
}
unset($workerType);
}
|
php
|
public function onWorkerStop(SwServer $server, int $workerId)
{
$workerType = $server->taskworker ? 'task' : 'worker';
// {{ log
$this->get('logger')->info('结束 Worker 进程', [
'id' => $workerId,
'type' => ucfirst($workerType)
]);
// }}
if ($workerType === 'worker') {
$this->shutdownWorkerStartItems();
$this->callProtocolMethod('onStop', $server, $workerId);
}
unset($workerType);
}
|
[
"public",
"function",
"onWorkerStop",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"workerId",
")",
"{",
"$",
"workerType",
"=",
"$",
"server",
"->",
"taskworker",
"?",
"'task'",
":",
"'worker'",
";",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'结束 Worker 进程', [",
"",
"",
"'id'",
"=>",
"$",
"workerId",
",",
"'type'",
"=>",
"ucfirst",
"(",
"$",
"workerType",
")",
"]",
")",
";",
"// }}",
"if",
"(",
"$",
"workerType",
"===",
"'worker'",
")",
"{",
"$",
"this",
"->",
"shutdownWorkerStartItems",
"(",
")",
";",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onStop'",
",",
"$",
"server",
",",
"$",
"workerId",
")",
";",
"}",
"unset",
"(",
"$",
"workerType",
")",
";",
"}"
] |
工作进程结束
@param \Swoole\Server $server
@param int $workerId
|
[
"工作进程结束"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L203-L220
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onWorkerError
|
public function onWorkerError(SwServer $server, int $workerId, int $workerPid, int $exitCode)
{
$workerType = $server->taskworker ? 'task' : 'worker';
// {{ log
$this->get('logger')->info('Worker 进程异常退出', [
'id' => $workerId,
'pid' => $workerPid,
'type' => ucfirst($workerType),
'exitcode' => $exitCode,
]);
// }}
unset($workerType);
$this->callProtocolMethod('onError', $server, $workerId);
}
|
php
|
public function onWorkerError(SwServer $server, int $workerId, int $workerPid, int $exitCode)
{
$workerType = $server->taskworker ? 'task' : 'worker';
// {{ log
$this->get('logger')->info('Worker 进程异常退出', [
'id' => $workerId,
'pid' => $workerPid,
'type' => ucfirst($workerType),
'exitcode' => $exitCode,
]);
// }}
unset($workerType);
$this->callProtocolMethod('onError', $server, $workerId);
}
|
[
"public",
"function",
"onWorkerError",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"workerId",
",",
"int",
"$",
"workerPid",
",",
"int",
"$",
"exitCode",
")",
"{",
"$",
"workerType",
"=",
"$",
"server",
"->",
"taskworker",
"?",
"'task'",
":",
"'worker'",
";",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'Worker 进程异常退出', [",
"",
"",
"'id'",
"=>",
"$",
"workerId",
",",
"'pid'",
"=>",
"$",
"workerPid",
",",
"'type'",
"=>",
"ucfirst",
"(",
"$",
"workerType",
")",
",",
"'exitcode'",
"=>",
"$",
"exitCode",
",",
"]",
")",
";",
"// }}",
"unset",
"(",
"$",
"workerType",
")",
";",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onError'",
",",
"$",
"server",
",",
"$",
"workerId",
")",
";",
"}"
] |
工作进程报错
@param \Swoole\Server $server
@param int $workerId
@param int $workerPid
@param int $exitCode
|
[
"工作进程报错"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L230-L246
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onWorkerExit
|
public function onWorkerExit(SwServer $server, int $workerId)
{
// {{ log
$this->get('logger')->info('Worker 进程重启退出', [
'id' => $workerId
]);
// }}
$this->callProtocolMethod('onExit', $server, $workerId);
}
|
php
|
public function onWorkerExit(SwServer $server, int $workerId)
{
// {{ log
$this->get('logger')->info('Worker 进程重启退出', [
'id' => $workerId
]);
// }}
$this->callProtocolMethod('onExit', $server, $workerId);
}
|
[
"public",
"function",
"onWorkerExit",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"workerId",
")",
"{",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'Worker 进程重启退出', [",
"",
"",
"'id'",
"=>",
"$",
"workerId",
"]",
")",
";",
"// }}",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onExit'",
",",
"$",
"server",
",",
"$",
"workerId",
")",
";",
"}"
] |
工作进程退出
@param \Swoole\Server $server
@param int $workerId
|
[
"工作进程退出"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L254-L263
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onPipeMessage
|
public function onPipeMessage(SwServer $server, int $fromId, string $message)
{
// {{ log
$this->get('logger')->info('接收管道消息', [
'fromWorkerId' => $fromId,
'message' => $message
]);
// }}
$this->callProtocolMethod('onPipeMessage', $server, $fd, $fromId, $data);
}
|
php
|
public function onPipeMessage(SwServer $server, int $fromId, string $message)
{
// {{ log
$this->get('logger')->info('接收管道消息', [
'fromWorkerId' => $fromId,
'message' => $message
]);
// }}
$this->callProtocolMethod('onPipeMessage', $server, $fd, $fromId, $data);
}
|
[
"public",
"function",
"onPipeMessage",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"fromId",
",",
"string",
"$",
"message",
")",
"{",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'接收管道消息', [",
"",
"",
"'fromWorkerId'",
"=>",
"$",
"fromId",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"// }}",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onPipeMessage'",
",",
"$",
"server",
",",
"$",
"fd",
",",
"$",
"fromId",
",",
"$",
"data",
")",
";",
"}"
] |
接收管道消息
@param \Swoole\Server $server
@param int $fromId
@param string $message
|
[
"接收管道消息"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L272-L282
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onConnect
|
public function onConnect(SwServer $server, int $fd, int $reactorId)
{
// {{ log
$this->get('logger')->info('连接接入', $server->getClientInfo($fd));
// }}
$this->callProtocolMethod('onConnect', $server, $fd, $fromId);
}
|
php
|
public function onConnect(SwServer $server, int $fd, int $reactorId)
{
// {{ log
$this->get('logger')->info('连接接入', $server->getClientInfo($fd));
// }}
$this->callProtocolMethod('onConnect', $server, $fd, $fromId);
}
|
[
"public",
"function",
"onConnect",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"fd",
",",
"int",
"$",
"reactorId",
")",
"{",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'连接接入', $serve",
"r",
">",
"getCli",
"en",
"tInfo($fd));",
"",
"",
"",
"",
"",
"",
"// }}",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onConnect'",
",",
"$",
"server",
",",
"$",
"fd",
",",
"$",
"fromId",
")",
";",
"}"
] |
连接接入
@param \Swoole\Server $server
@param int $fd
@param int $reactorId
|
[
"连接接入"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L291-L298
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onReceive
|
public function onReceive(SwServer $server, int $fd, int $fromId, string $data)
{
// {{ log
$this->get('logger')->info('接收数据', [
'type' => 'TCP',
'client' => $server->getClientInfo($fd),
'data' => $data
]);
// }}
$this->callProtocolMethod('onReceive', $server, $fd, $fromId, $data);
}
|
php
|
public function onReceive(SwServer $server, int $fd, int $fromId, string $data)
{
// {{ log
$this->get('logger')->info('接收数据', [
'type' => 'TCP',
'client' => $server->getClientInfo($fd),
'data' => $data
]);
// }}
$this->callProtocolMethod('onReceive', $server, $fd, $fromId, $data);
}
|
[
"public",
"function",
"onReceive",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"fd",
",",
"int",
"$",
"fromId",
",",
"string",
"$",
"data",
")",
"{",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'接收数据', [",
"",
"",
"'type'",
"=>",
"'TCP'",
",",
"'client'",
"=>",
"$",
"server",
"->",
"getClientInfo",
"(",
"$",
"fd",
")",
",",
"'data'",
"=>",
"$",
"data",
"]",
")",
";",
"// }}",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onReceive'",
",",
"$",
"server",
",",
"$",
"fd",
",",
"$",
"fromId",
",",
"$",
"data",
")",
";",
"}"
] |
接收 TCP 数据
@param \Swoole\Server $server
@param int $fd
@param int $fromId
@param string $data
|
[
"接收",
"TCP",
"数据"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L324-L335
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onPacket
|
public function onPacket(SwServer $server, string $data, array $clientInfo)
{
// {{ log
$this->get('logger')->info('接收数据', [
'type' => 'UDP',
'client' => $clientInfo,
'data' => $data
]);
// }}
$this->callProtocolMethod('onPacket', $server, $data, $clientInfo);
}
|
php
|
public function onPacket(SwServer $server, string $data, array $clientInfo)
{
// {{ log
$this->get('logger')->info('接收数据', [
'type' => 'UDP',
'client' => $clientInfo,
'data' => $data
]);
// }}
$this->callProtocolMethod('onPacket', $server, $data, $clientInfo);
}
|
[
"public",
"function",
"onPacket",
"(",
"SwServer",
"$",
"server",
",",
"string",
"$",
"data",
",",
"array",
"$",
"clientInfo",
")",
"{",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'接收数据', [",
"",
"",
"'type'",
"=>",
"'UDP'",
",",
"'client'",
"=>",
"$",
"clientInfo",
",",
"'data'",
"=>",
"$",
"data",
"]",
")",
";",
"// }}",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onPacket'",
",",
"$",
"server",
",",
"$",
"data",
",",
"$",
"clientInfo",
")",
";",
"}"
] |
接收 UDP 数据
@param \Swoole\Server $server
@param string $data
@param array $clientInfo
|
[
"接收",
"UDP",
"数据"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L344-L355
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onRequest
|
public function onRequest(SwRequest $swRequest, SwResponse $swResponse)
{
$request = Factory::newHttpRequest($swRequest);
$response = Factory::newHttpResponse($swResponse);
// {{ log
$this->get('logger')->info('接收数据', [
'type' => 'HTTP',
'method' => $request->getMethod(),
'uri' => $request->getRequestTarget(),
'client' => $request->getClientIP()
]);
// }}
// {{
$this->callProtocolMethod('onRequest', $request, $response);
// }}
unset($request, $response);
}
|
php
|
public function onRequest(SwRequest $swRequest, SwResponse $swResponse)
{
$request = Factory::newHttpRequest($swRequest);
$response = Factory::newHttpResponse($swResponse);
// {{ log
$this->get('logger')->info('接收数据', [
'type' => 'HTTP',
'method' => $request->getMethod(),
'uri' => $request->getRequestTarget(),
'client' => $request->getClientIP()
]);
// }}
// {{
$this->callProtocolMethod('onRequest', $request, $response);
// }}
unset($request, $response);
}
|
[
"public",
"function",
"onRequest",
"(",
"SwRequest",
"$",
"swRequest",
",",
"SwResponse",
"$",
"swResponse",
")",
"{",
"$",
"request",
"=",
"Factory",
"::",
"newHttpRequest",
"(",
"$",
"swRequest",
")",
";",
"$",
"response",
"=",
"Factory",
"::",
"newHttpResponse",
"(",
"$",
"swResponse",
")",
";",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'接收数据', [",
"",
"",
"'type'",
"=>",
"'HTTP'",
",",
"'method'",
"=>",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"'uri'",
"=>",
"$",
"request",
"->",
"getRequestTarget",
"(",
")",
",",
"'client'",
"=>",
"$",
"request",
"->",
"getClientIP",
"(",
")",
"]",
")",
";",
"// }}",
"// {{",
"$",
"this",
"->",
"callProtocolMethod",
"(",
"'onRequest'",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"// }}",
"unset",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] |
接收 HTTP 请求
@param \Swoole\Http\Request $swRequest
@param \Swoole\Http\Response $swResponse
|
[
"接收",
"HTTP",
"请求"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L363-L382
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onTask
|
public function onTask(SwServer $server, int $taskId, int $fromId, $data)
{
// {{ log
$this->get('logger')->info('投递任务', [
'id' => $taskId,
'fromId' => $fromId,
'data' => is_array($data) ? json_encode($data) : $data
]);
// }}
// {{
return $this->get('task')->onTask($server, $taskId, $fromId, $data);
// }}
}
|
php
|
public function onTask(SwServer $server, int $taskId, int $fromId, $data)
{
// {{ log
$this->get('logger')->info('投递任务', [
'id' => $taskId,
'fromId' => $fromId,
'data' => is_array($data) ? json_encode($data) : $data
]);
// }}
// {{
return $this->get('task')->onTask($server, $taskId, $fromId, $data);
// }}
}
|
[
"public",
"function",
"onTask",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"taskId",
",",
"int",
"$",
"fromId",
",",
"$",
"data",
")",
"{",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'投递任务', [",
"",
"",
"'id'",
"=>",
"$",
"taskId",
",",
"'fromId'",
"=>",
"$",
"fromId",
",",
"'data'",
"=>",
"is_array",
"(",
"$",
"data",
")",
"?",
"json_encode",
"(",
"$",
"data",
")",
":",
"$",
"data",
"]",
")",
";",
"// }}",
"// {{",
"return",
"$",
"this",
"->",
"get",
"(",
"'task'",
")",
"->",
"onTask",
"(",
"$",
"server",
",",
"$",
"taskId",
",",
"$",
"fromId",
",",
"$",
"data",
")",
";",
"// }}",
"}"
] |
投递任务
@param \Swoole\Server $server
@param int $taskId
@param int $fromId
@param mixed $data
@return array
|
[
"投递任务"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L394-L407
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.onFinish
|
public function onFinish(SwServer $server, int $taskId, $data)
{
// {{
$this->get('task')->onFinish($server, $taskId, $data);
// }}
// {{ log
$this->get('logger')->info('结束任务', [
'id' => $taskId,
'data' => is_array($data) ? json_encode($data) : $data
]);
// }}
}
|
php
|
public function onFinish(SwServer $server, int $taskId, $data)
{
// {{
$this->get('task')->onFinish($server, $taskId, $data);
// }}
// {{ log
$this->get('logger')->info('结束任务', [
'id' => $taskId,
'data' => is_array($data) ? json_encode($data) : $data
]);
// }}
}
|
[
"public",
"function",
"onFinish",
"(",
"SwServer",
"$",
"server",
",",
"int",
"$",
"taskId",
",",
"$",
"data",
")",
"{",
"// {{",
"$",
"this",
"->",
"get",
"(",
"'task'",
")",
"->",
"onFinish",
"(",
"$",
"server",
",",
"$",
"taskId",
",",
"$",
"data",
")",
";",
"// }}",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'结束任务', [",
"",
"",
"'id'",
"=>",
"$",
"taskId",
",",
"'data'",
"=>",
"is_array",
"(",
"$",
"data",
")",
"?",
"json_encode",
"(",
"$",
"data",
")",
":",
"$",
"data",
"]",
")",
";",
"// }}",
"}"
] |
结束任务
@param \Swoole\Server $server
@param int $taskId
@param mixed $data
|
[
"结束任务"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L416-L428
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.initializeCoreProviders
|
protected function initializeCoreProviders(): self
{
array_walk($this->core, function ($item) {
$provider = $this->make($item, [$this]);
$provider->register();
$provider->boot();
unset($provider);
});
// {{ log
array_walk($this->core, function ($provider) {
$this->get('logger')->info('注册核心组件 ' . $provider);
});
// }}
return $this;
}
|
php
|
protected function initializeCoreProviders(): self
{
array_walk($this->core, function ($item) {
$provider = $this->make($item, [$this]);
$provider->register();
$provider->boot();
unset($provider);
});
// {{ log
array_walk($this->core, function ($provider) {
$this->get('logger')->info('注册核心组件 ' . $provider);
});
// }}
return $this;
}
|
[
"protected",
"function",
"initializeCoreProviders",
"(",
")",
":",
"self",
"{",
"array_walk",
"(",
"$",
"this",
"->",
"core",
",",
"function",
"(",
"$",
"item",
")",
"{",
"$",
"provider",
"=",
"$",
"this",
"->",
"make",
"(",
"$",
"item",
",",
"[",
"$",
"this",
"]",
")",
";",
"$",
"provider",
"->",
"register",
"(",
")",
";",
"$",
"provider",
"->",
"boot",
"(",
")",
";",
"unset",
"(",
"$",
"provider",
")",
";",
"}",
")",
";",
"// {{ log",
"array_walk",
"(",
"$",
"this",
"->",
"core",
",",
"function",
"(",
"$",
"provider",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'注册核心组件 ' . $provider",
";",
"",
"",
"",
"",
"}",
")",
";",
"// }}",
"return",
"$",
"this",
";",
"}"
] |
初始化核心组件
|
[
"初始化核心组件"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L435-L452
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.initializeProviders
|
protected function initializeProviders(): self
{
array_walk($this->providers, function ($item) {
$provider = $this->make($item, [$this]);
$provider->register();
$provider->boot();
// {{ log
$this->get('logger')->info('注册基础组件 ' . $item);
// }}
unset($provider);
});
return $this;
}
|
php
|
protected function initializeProviders(): self
{
array_walk($this->providers, function ($item) {
$provider = $this->make($item, [$this]);
$provider->register();
$provider->boot();
// {{ log
$this->get('logger')->info('注册基础组件 ' . $item);
// }}
unset($provider);
});
return $this;
}
|
[
"protected",
"function",
"initializeProviders",
"(",
")",
":",
"self",
"{",
"array_walk",
"(",
"$",
"this",
"->",
"providers",
",",
"function",
"(",
"$",
"item",
")",
"{",
"$",
"provider",
"=",
"$",
"this",
"->",
"make",
"(",
"$",
"item",
",",
"[",
"$",
"this",
"]",
")",
";",
"$",
"provider",
"->",
"register",
"(",
")",
";",
"$",
"provider",
"->",
"boot",
"(",
")",
";",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'注册基础组件 ' . $item);",
"",
"",
"",
"",
"",
"// }}",
"unset",
"(",
"$",
"provider",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
初始化基础组件
|
[
"初始化基础组件"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L457-L472
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.bootServerStartItems
|
protected function bootServerStartItems()
{
// 协议启动项
$inherents = $this->getProtocol()->getServerStartItems();
// 自定义启动项
$customs = Config::get('startup.server', []);
$providers = array_merge($customs, $inherents);
unset($inherents, $customs);
$this->bootItems('server', $providers);
}
|
php
|
protected function bootServerStartItems()
{
// 协议启动项
$inherents = $this->getProtocol()->getServerStartItems();
// 自定义启动项
$customs = Config::get('startup.server', []);
$providers = array_merge($customs, $inherents);
unset($inherents, $customs);
$this->bootItems('server', $providers);
}
|
[
"protected",
"function",
"bootServerStartItems",
"(",
")",
"{",
"// 协议启动项",
"$",
"inherents",
"=",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getServerStartItems",
"(",
")",
";",
"// 自定义启动项",
"$",
"customs",
"=",
"Config",
"::",
"get",
"(",
"'startup.server'",
",",
"[",
"]",
")",
";",
"$",
"providers",
"=",
"array_merge",
"(",
"$",
"customs",
",",
"$",
"inherents",
")",
";",
"unset",
"(",
"$",
"inherents",
",",
"$",
"customs",
")",
";",
"$",
"this",
"->",
"bootItems",
"(",
"'server'",
",",
"$",
"providers",
")",
";",
"}"
] |
启动服务进程启动项
|
[
"启动服务进程启动项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L477-L488
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.shutdownServerStartItems
|
protected function shutdownServerStartItems()
{
// 协议启动项
$inherents = $this->getProtocol()->getServerStartItems();
// 自定义启动项
$customs = Config::get('startup.server', []);
$providers = array_merge($customs, $inherents);
unset($inherents, $customs);
$this->shutdownItems('server', $providers);
}
|
php
|
protected function shutdownServerStartItems()
{
// 协议启动项
$inherents = $this->getProtocol()->getServerStartItems();
// 自定义启动项
$customs = Config::get('startup.server', []);
$providers = array_merge($customs, $inherents);
unset($inherents, $customs);
$this->shutdownItems('server', $providers);
}
|
[
"protected",
"function",
"shutdownServerStartItems",
"(",
")",
"{",
"// 协议启动项",
"$",
"inherents",
"=",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getServerStartItems",
"(",
")",
";",
"// 自定义启动项",
"$",
"customs",
"=",
"Config",
"::",
"get",
"(",
"'startup.server'",
",",
"[",
"]",
")",
";",
"$",
"providers",
"=",
"array_merge",
"(",
"$",
"customs",
",",
"$",
"inherents",
")",
";",
"unset",
"(",
"$",
"inherents",
",",
"$",
"customs",
")",
";",
"$",
"this",
"->",
"shutdownItems",
"(",
"'server'",
",",
"$",
"providers",
")",
";",
"}"
] |
关闭服务进程启动项
|
[
"关闭服务进程启动项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L493-L504
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.bootWorkerStartItems
|
protected function bootWorkerStartItems()
{
// 协议启动项
$inherents = $this->getProtocol()->getWorkerStartItems();
// 自定义启动项
$customs = Config::get('startup.worker', []);
$providers = array_merge($customs, $inherents);
unset($inherents, $customs);
$this->bootItems('worker', $providers);
}
|
php
|
protected function bootWorkerStartItems()
{
// 协议启动项
$inherents = $this->getProtocol()->getWorkerStartItems();
// 自定义启动项
$customs = Config::get('startup.worker', []);
$providers = array_merge($customs, $inherents);
unset($inherents, $customs);
$this->bootItems('worker', $providers);
}
|
[
"protected",
"function",
"bootWorkerStartItems",
"(",
")",
"{",
"// 协议启动项",
"$",
"inherents",
"=",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getWorkerStartItems",
"(",
")",
";",
"// 自定义启动项",
"$",
"customs",
"=",
"Config",
"::",
"get",
"(",
"'startup.worker'",
",",
"[",
"]",
")",
";",
"$",
"providers",
"=",
"array_merge",
"(",
"$",
"customs",
",",
"$",
"inherents",
")",
";",
"unset",
"(",
"$",
"inherents",
",",
"$",
"customs",
")",
";",
"$",
"this",
"->",
"bootItems",
"(",
"'worker'",
",",
"$",
"providers",
")",
";",
"}"
] |
启动工作进程启动项
|
[
"启动工作进程启动项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L509-L520
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.shutdownWorkerStartItems
|
protected function shutdownWorkerStartItems()
{
// 协议启动项
$inherents = $this->getProtocol()->getWorkerStartItems();
// 自定义启动项
$customs = Config::get('startup.worker', []);
$providers = array_merge($customs, $inherents);
unset($inherents, $customs);
$this->shutdownItems('worker', $providers);
}
|
php
|
protected function shutdownWorkerStartItems()
{
// 协议启动项
$inherents = $this->getProtocol()->getWorkerStartItems();
// 自定义启动项
$customs = Config::get('startup.worker', []);
$providers = array_merge($customs, $inherents);
unset($inherents, $customs);
$this->shutdownItems('worker', $providers);
}
|
[
"protected",
"function",
"shutdownWorkerStartItems",
"(",
")",
"{",
"// 协议启动项",
"$",
"inherents",
"=",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getWorkerStartItems",
"(",
")",
";",
"// 自定义启动项",
"$",
"customs",
"=",
"Config",
"::",
"get",
"(",
"'startup.worker'",
",",
"[",
"]",
")",
";",
"$",
"providers",
"=",
"array_merge",
"(",
"$",
"customs",
",",
"$",
"inherents",
")",
";",
"unset",
"(",
"$",
"inherents",
",",
"$",
"customs",
")",
";",
"$",
"this",
"->",
"shutdownItems",
"(",
"'worker'",
",",
"$",
"providers",
")",
";",
"}"
] |
关闭工作进程启动项
|
[
"关闭工作进程启动项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L525-L536
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.bootItems
|
protected function bootItems(string $type, array $items)
{
if ($items !== []) {
array_walk($items, function ($item) use ($type) {
$provider = $this->make($item, [$this]);
$provider->register();
$provider->boot();
unset($boot);
// {{ log
$this->get('logger')->info('加载 ' . ucfirst($type) . ' 启动项 ' . $item);
// }}
});
}
}
|
php
|
protected function bootItems(string $type, array $items)
{
if ($items !== []) {
array_walk($items, function ($item) use ($type) {
$provider = $this->make($item, [$this]);
$provider->register();
$provider->boot();
unset($boot);
// {{ log
$this->get('logger')->info('加载 ' . ucfirst($type) . ' 启动项 ' . $item);
// }}
});
}
}
|
[
"protected",
"function",
"bootItems",
"(",
"string",
"$",
"type",
",",
"array",
"$",
"items",
")",
"{",
"if",
"(",
"$",
"items",
"!==",
"[",
"]",
")",
"{",
"array_walk",
"(",
"$",
"items",
",",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"type",
")",
"{",
"$",
"provider",
"=",
"$",
"this",
"->",
"make",
"(",
"$",
"item",
",",
"[",
"$",
"this",
"]",
")",
";",
"$",
"provider",
"->",
"register",
"(",
")",
";",
"$",
"provider",
"->",
"boot",
"(",
")",
";",
"unset",
"(",
"$",
"boot",
")",
";",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'加载 ' . u",
"f",
"rst($ty",
"p",
"e",
") . ",
"'",
"启",
"项 ' . $item);",
"",
"",
"",
"",
"",
"// }}",
"}",
")",
";",
"}",
"}"
] |
启动自定义启动项
@param string $type
@param array $items
|
[
"启动自定义启动项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L544-L559
|
movoin/one-swoole
|
src/Protocol/Server.php
|
Server.shutdownItems
|
protected function shutdownItems(string $type, array $items)
{
if ($items !== []) {
array_walk($items, function ($item) use ($type) {
$provider = $this->make($item, [$this]);
$provider->shutdown();
unset($boot);
// {{ log
$this->get('logger')->info('关闭 ' . ucfirst($type) . ' 启动项 ' . $item);
// }}
});
}
}
|
php
|
protected function shutdownItems(string $type, array $items)
{
if ($items !== []) {
array_walk($items, function ($item) use ($type) {
$provider = $this->make($item, [$this]);
$provider->shutdown();
unset($boot);
// {{ log
$this->get('logger')->info('关闭 ' . ucfirst($type) . ' 启动项 ' . $item);
// }}
});
}
}
|
[
"protected",
"function",
"shutdownItems",
"(",
"string",
"$",
"type",
",",
"array",
"$",
"items",
")",
"{",
"if",
"(",
"$",
"items",
"!==",
"[",
"]",
")",
"{",
"array_walk",
"(",
"$",
"items",
",",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"type",
")",
"{",
"$",
"provider",
"=",
"$",
"this",
"->",
"make",
"(",
"$",
"item",
",",
"[",
"$",
"this",
"]",
")",
";",
"$",
"provider",
"->",
"shutdown",
"(",
")",
";",
"unset",
"(",
"$",
"boot",
")",
";",
"// {{ log",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
"->",
"info",
"(",
"'关闭 ' . u",
"f",
"rst($ty",
"p",
"e",
") . ",
"'",
"启",
"项 ' . $item);",
"",
"",
"",
"",
"",
"// }}",
"}",
")",
";",
"}",
"}"
] |
关闭自定义启动项
@param string $type
@param array $items
|
[
"关闭自定义启动项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Server.php#L567-L581
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php
|
UserQuery.filterByPassword
|
public function filterByPassword($password = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($password)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $password)) {
$password = str_replace('*', '%', $password);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UserTableMap::COL_PASSWORD, $password, $comparison);
}
|
php
|
public function filterByPassword($password = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($password)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $password)) {
$password = str_replace('*', '%', $password);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UserTableMap::COL_PASSWORD, $password, $comparison);
}
|
[
"public",
"function",
"filterByPassword",
"(",
"$",
"password",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"password",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/[\\%\\*]/'",
",",
"$",
"password",
")",
")",
"{",
"$",
"password",
"=",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"password",
")",
";",
"$",
"comparison",
"=",
"Criteria",
"::",
"LIKE",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"UserTableMap",
"::",
"COL_PASSWORD",
",",
"$",
"password",
",",
"$",
"comparison",
")",
";",
"}"
] |
Filter the query on the password column
Example usage:
<code>
$query->filterByPassword('fooValue'); // WHERE password = 'fooValue'
$query->filterByPassword('%fooValue%'); // WHERE password LIKE '%fooValue%'
</code>
@param string $password The value to use as filter.
Accepts wildcards (* and % trigger a LIKE)
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildUserQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"on",
"the",
"password",
"column"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php#L336-L348
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php
|
UserQuery.filterByFirstName
|
public function filterByFirstName($firstName = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($firstName)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $firstName)) {
$firstName = str_replace('*', '%', $firstName);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UserTableMap::COL_FIRST_NAME, $firstName, $comparison);
}
|
php
|
public function filterByFirstName($firstName = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($firstName)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $firstName)) {
$firstName = str_replace('*', '%', $firstName);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UserTableMap::COL_FIRST_NAME, $firstName, $comparison);
}
|
[
"public",
"function",
"filterByFirstName",
"(",
"$",
"firstName",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"firstName",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/[\\%\\*]/'",
",",
"$",
"firstName",
")",
")",
"{",
"$",
"firstName",
"=",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"firstName",
")",
";",
"$",
"comparison",
"=",
"Criteria",
"::",
"LIKE",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"UserTableMap",
"::",
"COL_FIRST_NAME",
",",
"$",
"firstName",
",",
"$",
"comparison",
")",
";",
"}"
] |
Filter the query on the first_name column
Example usage:
<code>
$query->filterByFirstName('fooValue'); // WHERE first_name = 'fooValue'
$query->filterByFirstName('%fooValue%'); // WHERE first_name LIKE '%fooValue%'
</code>
@param string $firstName The value to use as filter.
Accepts wildcards (* and % trigger a LIKE)
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildUserQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"on",
"the",
"first_name",
"column"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php#L365-L377
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php
|
UserQuery.filterByLastName
|
public function filterByLastName($lastName = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($lastName)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $lastName)) {
$lastName = str_replace('*', '%', $lastName);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UserTableMap::COL_LAST_NAME, $lastName, $comparison);
}
|
php
|
public function filterByLastName($lastName = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($lastName)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $lastName)) {
$lastName = str_replace('*', '%', $lastName);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UserTableMap::COL_LAST_NAME, $lastName, $comparison);
}
|
[
"public",
"function",
"filterByLastName",
"(",
"$",
"lastName",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"lastName",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/[\\%\\*]/'",
",",
"$",
"lastName",
")",
")",
"{",
"$",
"lastName",
"=",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"lastName",
")",
";",
"$",
"comparison",
"=",
"Criteria",
"::",
"LIKE",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"UserTableMap",
"::",
"COL_LAST_NAME",
",",
"$",
"lastName",
",",
"$",
"comparison",
")",
";",
"}"
] |
Filter the query on the last_name column
Example usage:
<code>
$query->filterByLastName('fooValue'); // WHERE last_name = 'fooValue'
$query->filterByLastName('%fooValue%'); // WHERE last_name LIKE '%fooValue%'
</code>
@param string $lastName The value to use as filter.
Accepts wildcards (* and % trigger a LIKE)
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildUserQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"on",
"the",
"last_name",
"column"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php#L394-L406
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php
|
UserQuery.filterByStatus
|
public function filterByStatus($status = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($status)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $status)) {
$status = str_replace('*', '%', $status);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UserTableMap::COL_STATUS, $status, $comparison);
}
|
php
|
public function filterByStatus($status = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($status)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $status)) {
$status = str_replace('*', '%', $status);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UserTableMap::COL_STATUS, $status, $comparison);
}
|
[
"public",
"function",
"filterByStatus",
"(",
"$",
"status",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"status",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/[\\%\\*]/'",
",",
"$",
"status",
")",
")",
"{",
"$",
"status",
"=",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"status",
")",
";",
"$",
"comparison",
"=",
"Criteria",
"::",
"LIKE",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"UserTableMap",
"::",
"COL_STATUS",
",",
"$",
"status",
",",
"$",
"comparison",
")",
";",
"}"
] |
Filter the query on the status column
Example usage:
<code>
$query->filterByStatus('fooValue'); // WHERE status = 'fooValue'
$query->filterByStatus('%fooValue%'); // WHERE status LIKE '%fooValue%'
</code>
@param string $status The value to use as filter.
Accepts wildcards (* and % trigger a LIKE)
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildUserQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"on",
"the",
"status",
"column"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php#L509-L521
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php
|
UserQuery.filterByRole
|
public function filterByRole($role, $comparison = Criteria::EQUAL)
{
return $this
->useUserRoleQuery()
->filterByRole($role, $comparison)
->endUse();
}
|
php
|
public function filterByRole($role, $comparison = Criteria::EQUAL)
{
return $this
->useUserRoleQuery()
->filterByRole($role, $comparison)
->endUse();
}
|
[
"public",
"function",
"filterByRole",
"(",
"$",
"role",
",",
"$",
"comparison",
"=",
"Criteria",
"::",
"EQUAL",
")",
"{",
"return",
"$",
"this",
"->",
"useUserRoleQuery",
"(",
")",
"->",
"filterByRole",
"(",
"$",
"role",
",",
"$",
"comparison",
")",
"->",
"endUse",
"(",
")",
";",
"}"
] |
Filter the query by a related Role object
using the user_role table as cross reference
@param Role $role the related object to use as filter
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildUserQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"by",
"a",
"related",
"Role",
"object",
"using",
"the",
"user_role",
"table",
"as",
"cross",
"reference"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php#L605-L611
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php
|
UserQuery.prune
|
public function prune($user = null)
{
if ($user) {
$this->addUsingAlias(UserTableMap::COL_ID, $user->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
|
php
|
public function prune($user = null)
{
if ($user) {
$this->addUsingAlias(UserTableMap::COL_ID, $user->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
|
[
"public",
"function",
"prune",
"(",
"$",
"user",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"UserTableMap",
"::",
"COL_ID",
",",
"$",
"user",
"->",
"getId",
"(",
")",
",",
"Criteria",
"::",
"NOT_EQUAL",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Exclude object from result
@param ChildUser $user Object to remove from the list of results
@return $this|ChildUserQuery The current query, for fluid interface
|
[
"Exclude",
"object",
"from",
"result"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/UserQuery.php#L620-L627
|
sulu/SuluSalesShippingBundle
|
src/Sulu/Bundle/Sales/OrderBundle/Widgets/FlowOfDocuments.php
|
FlowOfDocuments.fetchDocumentData
|
protected function fetchDocumentData($options)
{
$documents = $this->dependencyManager->getDocuments($options['orderId'], $options['locale']);
if (!empty($documents)) {
/* @var SalesDocument $document */
foreach ($documents as $document) {
$data = $document->getSalesDocumentData();
parent::addEntry(
$data['id'],
$data['number'],
$data['type'],
$data['date'],
parent::getRoute($data['id'], $data['type'], 'details'),
$data['pdfBaseUrl']
);
}
}
}
|
php
|
protected function fetchDocumentData($options)
{
$documents = $this->dependencyManager->getDocuments($options['orderId'], $options['locale']);
if (!empty($documents)) {
/* @var SalesDocument $document */
foreach ($documents as $document) {
$data = $document->getSalesDocumentData();
parent::addEntry(
$data['id'],
$data['number'],
$data['type'],
$data['date'],
parent::getRoute($data['id'], $data['type'], 'details'),
$data['pdfBaseUrl']
);
}
}
}
|
[
"protected",
"function",
"fetchDocumentData",
"(",
"$",
"options",
")",
"{",
"$",
"documents",
"=",
"$",
"this",
"->",
"dependencyManager",
"->",
"getDocuments",
"(",
"$",
"options",
"[",
"'orderId'",
"]",
",",
"$",
"options",
"[",
"'locale'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"documents",
")",
")",
"{",
"/* @var SalesDocument $document */",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"$",
"data",
"=",
"$",
"document",
"->",
"getSalesDocumentData",
"(",
")",
";",
"parent",
"::",
"addEntry",
"(",
"$",
"data",
"[",
"'id'",
"]",
",",
"$",
"data",
"[",
"'number'",
"]",
",",
"$",
"data",
"[",
"'type'",
"]",
",",
"$",
"data",
"[",
"'date'",
"]",
",",
"parent",
"::",
"getRoute",
"(",
"$",
"data",
"[",
"'id'",
"]",
",",
"$",
"data",
"[",
"'type'",
"]",
",",
"'details'",
")",
",",
"$",
"data",
"[",
"'pdfBaseUrl'",
"]",
")",
";",
"}",
"}",
"}"
] |
Retrieves document data for a specific order and adds it to the entries
@param $options
@throws \Sulu\Bundle\AdminBundle\Widgets\WidgetParameterException
|
[
"Retrieves",
"document",
"data",
"for",
"a",
"specific",
"order",
"and",
"adds",
"it",
"to",
"the",
"entries"
] |
train
|
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Widgets/FlowOfDocuments.php#L93-L110
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.getInstance
|
static function getInstance($name = null)
{
if (empty($name)) {
$name = get_called_class();
}
if (!empty(static::$plugins[$name])) {
return static::$plugins[$name];
}
return false;
}
|
php
|
static function getInstance($name = null)
{
if (empty($name)) {
$name = get_called_class();
}
if (!empty(static::$plugins[$name])) {
return static::$plugins[$name];
}
return false;
}
|
[
"static",
"function",
"getInstance",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"get_called_class",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"plugins",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"plugins",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Get the existing instance of this Plugin.
@param string Optionally, the name or classname of the Plugin to retrieve
@return Plugin instance if bootstrapped, otherwise false
|
[
"Get",
"the",
"existing",
"instance",
"of",
"this",
"Plugin",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L157-L166
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.registerLogBindings
|
protected function registerLogBindings()
{
$this->singleton('Psr\Log\LoggerInterface', function () {
$name = Str::slug($this->getNamespaceName());
if ($this->monologConfigurator) {
return call_user_func($this->monologConfigurator, new Logger($name));
} else {
return new Logger($name, [$this->getMonologHandler()]);
}
});
}
|
php
|
protected function registerLogBindings()
{
$this->singleton('Psr\Log\LoggerInterface', function () {
$name = Str::slug($this->getNamespaceName());
if ($this->monologConfigurator) {
return call_user_func($this->monologConfigurator, new Logger($name));
} else {
return new Logger($name, [$this->getMonologHandler()]);
}
});
}
|
[
"protected",
"function",
"registerLogBindings",
"(",
")",
"{",
"$",
"this",
"->",
"singleton",
"(",
"'Psr\\Log\\LoggerInterface'",
",",
"function",
"(",
")",
"{",
"$",
"name",
"=",
"Str",
"::",
"slug",
"(",
"$",
"this",
"->",
"getNamespaceName",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"monologConfigurator",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"monologConfigurator",
",",
"new",
"Logger",
"(",
"$",
"name",
")",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Logger",
"(",
"$",
"name",
",",
"[",
"$",
"this",
"->",
"getMonologHandler",
"(",
")",
"]",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Register container bindings for the application.
@return void
|
[
"Register",
"container",
"bindings",
"for",
"the",
"application",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L202-L212
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.getMonologHandler
|
protected function getMonologHandler()
{
$name = Str::slug($this->getNamespaceName());
return (new StreamHandler($this->storagePath("logs/{$name}.log"), Logger::DEBUG))
->setFormatter(new LineFormatter(null, null, true, true));
}
|
php
|
protected function getMonologHandler()
{
$name = Str::slug($this->getNamespaceName());
return (new StreamHandler($this->storagePath("logs/{$name}.log"), Logger::DEBUG))
->setFormatter(new LineFormatter(null, null, true, true));
}
|
[
"protected",
"function",
"getMonologHandler",
"(",
")",
"{",
"$",
"name",
"=",
"Str",
"::",
"slug",
"(",
"$",
"this",
"->",
"getNamespaceName",
"(",
")",
")",
";",
"return",
"(",
"new",
"StreamHandler",
"(",
"$",
"this",
"->",
"storagePath",
"(",
"\"logs/{$name}.log\"",
")",
",",
"Logger",
"::",
"DEBUG",
")",
")",
"->",
"setFormatter",
"(",
"new",
"LineFormatter",
"(",
"null",
",",
"null",
",",
"true",
",",
"true",
")",
")",
";",
"}"
] |
Get the Monolog handler for the application.
@return \Monolog\Handler\AbstractHandler
|
[
"Get",
"the",
"Monolog",
"handler",
"for",
"the",
"application",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L232-L237
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.registerRequestBindings
|
protected function registerRequestBindings()
{
$this->singleton('Illuminate\Http\Request', function () {
// create a new request object
$request = Request::capture();
// create an arbitrary response object
$this->response = new Response;
// get a SessionManager from the container
$manager = $this['session'];
// startup the StartSession middleware
$middleware = new StartSession($manager);
$middleware->handle($request, function() {
return $this->response;
});
// print out any cookies created by the session system
foreach($this->response->headers->getCookies() as $cookie) {
@header('Set-Cookie: '.$cookie);
}
return $request;
});
}
|
php
|
protected function registerRequestBindings()
{
$this->singleton('Illuminate\Http\Request', function () {
// create a new request object
$request = Request::capture();
// create an arbitrary response object
$this->response = new Response;
// get a SessionManager from the container
$manager = $this['session'];
// startup the StartSession middleware
$middleware = new StartSession($manager);
$middleware->handle($request, function() {
return $this->response;
});
// print out any cookies created by the session system
foreach($this->response->headers->getCookies() as $cookie) {
@header('Set-Cookie: '.$cookie);
}
return $request;
});
}
|
[
"protected",
"function",
"registerRequestBindings",
"(",
")",
"{",
"$",
"this",
"->",
"singleton",
"(",
"'Illuminate\\Http\\Request'",
",",
"function",
"(",
")",
"{",
"// create a new request object",
"$",
"request",
"=",
"Request",
"::",
"capture",
"(",
")",
";",
"// create an arbitrary response object",
"$",
"this",
"->",
"response",
"=",
"new",
"Response",
";",
"// get a SessionManager from the container",
"$",
"manager",
"=",
"$",
"this",
"[",
"'session'",
"]",
";",
"// startup the StartSession middleware",
"$",
"middleware",
"=",
"new",
"StartSession",
"(",
"$",
"manager",
")",
";",
"$",
"middleware",
"->",
"handle",
"(",
"$",
"request",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"response",
";",
"}",
")",
";",
"// print out any cookies created by the session system",
"foreach",
"(",
"$",
"this",
"->",
"response",
"->",
"headers",
"->",
"getCookies",
"(",
")",
"as",
"$",
"cookie",
")",
"{",
"@",
"header",
"(",
"'Set-Cookie: '",
".",
"$",
"cookie",
")",
";",
"}",
"return",
"$",
"request",
";",
"}",
")",
";",
"}"
] |
Register container bindings for the plugin.
@return void
|
[
"Register",
"container",
"bindings",
"for",
"the",
"plugin",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L244-L264
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.prepareForConsoleCommand
|
public function prepareForConsoleCommand(WordPressConsoleKernel $console, $aliases = true)
{
$this->make('cache');
$this->make('queue');
$this->configure('database');
$this->register('Illuminate\Database\MigrationServiceProvider');
$console->setCommands(array_merge($this->commands, [
Console\Commands\ConsoleMakeCommand::class,
Console\Commands\CustomPostTypeMakeCommand::class,
]));
}
|
php
|
public function prepareForConsoleCommand(WordPressConsoleKernel $console, $aliases = true)
{
$this->make('cache');
$this->make('queue');
$this->configure('database');
$this->register('Illuminate\Database\MigrationServiceProvider');
$console->setCommands(array_merge($this->commands, [
Console\Commands\ConsoleMakeCommand::class,
Console\Commands\CustomPostTypeMakeCommand::class,
]));
}
|
[
"public",
"function",
"prepareForConsoleCommand",
"(",
"WordPressConsoleKernel",
"$",
"console",
",",
"$",
"aliases",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"make",
"(",
"'cache'",
")",
";",
"$",
"this",
"->",
"make",
"(",
"'queue'",
")",
";",
"$",
"this",
"->",
"configure",
"(",
"'database'",
")",
";",
"$",
"this",
"->",
"register",
"(",
"'Illuminate\\Database\\MigrationServiceProvider'",
")",
";",
"$",
"console",
"->",
"setCommands",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"commands",
",",
"[",
"Console",
"\\",
"Commands",
"\\",
"ConsoleMakeCommand",
"::",
"class",
",",
"Console",
"\\",
"Commands",
"\\",
"CustomPostTypeMakeCommand",
"::",
"class",
",",
"]",
")",
")",
";",
"}"
] |
Prepare the application to execute a console command.
@param bool $aliases
@return void
|
[
"Prepare",
"the",
"application",
"to",
"execute",
"a",
"console",
"command",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L272-L285
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.bootstrap
|
static function bootstrap($bootstrap)
{
$basepath = realpath(dirname($bootstrap));
$fs = new Filesystem;
$pluginSrcFile = $basepath.'/src/plugin.php';
require_once $pluginSrcFile;
$source = $fs->get($pluginSrcFile);
$pluginClass = static::getFirstPluginClassName($source);
// now check to see if we've been here before...
if (!empty(static::$plugins[$pluginClass])) {
return static::$plugins[$pluginClass];
}
// the plugin will have already been bootstrapped by
// the time we get here IF the autoload file exists;
// if it doesn't, setup a fallback class loader
if (!file_exists($composer = $basepath.'/vendor/autoload.php')) {
spl_autoload_register(function($name) use ($fs, $basepath) {
$src = $basepath.'/src';
$files = $fs->glob($src.'/**/*.php');
static $classmap;
// build the classmap
if ($classmap === null) {
$classmap = [];
foreach($files as $file) {
$contents = $fs->get($file);
$namespace = '';
if (preg_match('/namespace\s+(.*?);/i', $contents, $matches)) {
$namespace = $matches[1];
}
if (preg_match_all('/class\s+([\w\_]+).*?{/i', $contents, $matches)) {
foreach($matches[1] as $className) {
$classmap["{$namespace}\\{$className}"] = $file;
}
}
}
}
// if we found a match, load it
if (!empty($classmap[$name])) {
require_once $classmap[$name];
}
});
}
$plugin = new $pluginClass($bootstrap);
static::$plugins[$pluginClass] = $plugin;
static::$plugins[$plugin->getSlug()] = $plugin;
return static::$plugins[$pluginClass];
}
|
php
|
static function bootstrap($bootstrap)
{
$basepath = realpath(dirname($bootstrap));
$fs = new Filesystem;
$pluginSrcFile = $basepath.'/src/plugin.php';
require_once $pluginSrcFile;
$source = $fs->get($pluginSrcFile);
$pluginClass = static::getFirstPluginClassName($source);
// now check to see if we've been here before...
if (!empty(static::$plugins[$pluginClass])) {
return static::$plugins[$pluginClass];
}
// the plugin will have already been bootstrapped by
// the time we get here IF the autoload file exists;
// if it doesn't, setup a fallback class loader
if (!file_exists($composer = $basepath.'/vendor/autoload.php')) {
spl_autoload_register(function($name) use ($fs, $basepath) {
$src = $basepath.'/src';
$files = $fs->glob($src.'/**/*.php');
static $classmap;
// build the classmap
if ($classmap === null) {
$classmap = [];
foreach($files as $file) {
$contents = $fs->get($file);
$namespace = '';
if (preg_match('/namespace\s+(.*?);/i', $contents, $matches)) {
$namespace = $matches[1];
}
if (preg_match_all('/class\s+([\w\_]+).*?{/i', $contents, $matches)) {
foreach($matches[1] as $className) {
$classmap["{$namespace}\\{$className}"] = $file;
}
}
}
}
// if we found a match, load it
if (!empty($classmap[$name])) {
require_once $classmap[$name];
}
});
}
$plugin = new $pluginClass($bootstrap);
static::$plugins[$pluginClass] = $plugin;
static::$plugins[$plugin->getSlug()] = $plugin;
return static::$plugins[$pluginClass];
}
|
[
"static",
"function",
"bootstrap",
"(",
"$",
"bootstrap",
")",
"{",
"$",
"basepath",
"=",
"realpath",
"(",
"dirname",
"(",
"$",
"bootstrap",
")",
")",
";",
"$",
"fs",
"=",
"new",
"Filesystem",
";",
"$",
"pluginSrcFile",
"=",
"$",
"basepath",
".",
"'/src/plugin.php'",
";",
"require_once",
"$",
"pluginSrcFile",
";",
"$",
"source",
"=",
"$",
"fs",
"->",
"get",
"(",
"$",
"pluginSrcFile",
")",
";",
"$",
"pluginClass",
"=",
"static",
"::",
"getFirstPluginClassName",
"(",
"$",
"source",
")",
";",
"// now check to see if we've been here before...",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"plugins",
"[",
"$",
"pluginClass",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"plugins",
"[",
"$",
"pluginClass",
"]",
";",
"}",
"// the plugin will have already been bootstrapped by",
"// the time we get here IF the autoload file exists;",
"// if it doesn't, setup a fallback class loader",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"composer",
"=",
"$",
"basepath",
".",
"'/vendor/autoload.php'",
")",
")",
"{",
"spl_autoload_register",
"(",
"function",
"(",
"$",
"name",
")",
"use",
"(",
"$",
"fs",
",",
"$",
"basepath",
")",
"{",
"$",
"src",
"=",
"$",
"basepath",
".",
"'/src'",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"glob",
"(",
"$",
"src",
".",
"'/**/*.php'",
")",
";",
"static",
"$",
"classmap",
";",
"// build the classmap",
"if",
"(",
"$",
"classmap",
"===",
"null",
")",
"{",
"$",
"classmap",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"contents",
"=",
"$",
"fs",
"->",
"get",
"(",
"$",
"file",
")",
";",
"$",
"namespace",
"=",
"''",
";",
"if",
"(",
"preg_match",
"(",
"'/namespace\\s+(.*?);/i'",
",",
"$",
"contents",
",",
"$",
"matches",
")",
")",
"{",
"$",
"namespace",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"preg_match_all",
"(",
"'/class\\s+([\\w\\_]+).*?{/i'",
",",
"$",
"contents",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"1",
"]",
"as",
"$",
"className",
")",
"{",
"$",
"classmap",
"[",
"\"{$namespace}\\\\{$className}\"",
"]",
"=",
"$",
"file",
";",
"}",
"}",
"}",
"}",
"// if we found a match, load it",
"if",
"(",
"!",
"empty",
"(",
"$",
"classmap",
"[",
"$",
"name",
"]",
")",
")",
"{",
"require_once",
"$",
"classmap",
"[",
"$",
"name",
"]",
";",
"}",
"}",
")",
";",
"}",
"$",
"plugin",
"=",
"new",
"$",
"pluginClass",
"(",
"$",
"bootstrap",
")",
";",
"static",
"::",
"$",
"plugins",
"[",
"$",
"pluginClass",
"]",
"=",
"$",
"plugin",
";",
"static",
"::",
"$",
"plugins",
"[",
"$",
"plugin",
"->",
"getSlug",
"(",
")",
"]",
"=",
"$",
"plugin",
";",
"return",
"static",
"::",
"$",
"plugins",
"[",
"$",
"pluginClass",
"]",
";",
"}"
] |
Bootstrap a plugin found in the given bootstrap file.
@param string The full path to a Plugin's bootstrap file
@return Plugin
|
[
"Bootstrap",
"a",
"plugin",
"found",
"in",
"the",
"given",
"bootstrap",
"file",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L538-L600
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.getDefaultDatabaseConnectionConfig
|
protected function getDefaultDatabaseConnectionConfig()
{
global $table_prefix;
$default = [
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'port' => getenv('DB_PORT'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASSWORD'),
'charset' => getenv('DB_CHARSET'),
'collation' => getenv('DB_COLLATE'),
'prefix' => getenv('DB_PREFIX') ?: $table_prefix,
'timezone' => getenv('DB_TIMEZONE') ?: '+00:00',
'strict' => getenv('DB_STRICT_MODE') ?: false,
];
if (empty($default['database']) && defined('DB_NAME')) {
$default['database'] = DB_NAME;
}
if (empty($default['username']) && defined('DB_USER')) {
$default['username'] = DB_USER;
}
if (empty($default['password']) && defined('DB_PASSWORD')) {
$default['password'] = DB_PASSWORD;
}
if (empty($default['host']) && defined('DB_HOST')) {
$default['host'] = DB_HOST;
}
if (empty($default['charset']) && defined('DB_CHARSET')) {
$default['charset'] = DB_CHARSET;
}
if (empty($default['collation'])) {
if (defined('DB_COLLATE') && DB_COLLATE) {
$default['collation'] = DB_COLLATE;
} else {
$default['collation'] = 'utf8_unicode_ci';
}
}
return $default;
}
|
php
|
protected function getDefaultDatabaseConnectionConfig()
{
global $table_prefix;
$default = [
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'port' => getenv('DB_PORT'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASSWORD'),
'charset' => getenv('DB_CHARSET'),
'collation' => getenv('DB_COLLATE'),
'prefix' => getenv('DB_PREFIX') ?: $table_prefix,
'timezone' => getenv('DB_TIMEZONE') ?: '+00:00',
'strict' => getenv('DB_STRICT_MODE') ?: false,
];
if (empty($default['database']) && defined('DB_NAME')) {
$default['database'] = DB_NAME;
}
if (empty($default['username']) && defined('DB_USER')) {
$default['username'] = DB_USER;
}
if (empty($default['password']) && defined('DB_PASSWORD')) {
$default['password'] = DB_PASSWORD;
}
if (empty($default['host']) && defined('DB_HOST')) {
$default['host'] = DB_HOST;
}
if (empty($default['charset']) && defined('DB_CHARSET')) {
$default['charset'] = DB_CHARSET;
}
if (empty($default['collation'])) {
if (defined('DB_COLLATE') && DB_COLLATE) {
$default['collation'] = DB_COLLATE;
} else {
$default['collation'] = 'utf8_unicode_ci';
}
}
return $default;
}
|
[
"protected",
"function",
"getDefaultDatabaseConnectionConfig",
"(",
")",
"{",
"global",
"$",
"table_prefix",
";",
"$",
"default",
"=",
"[",
"'driver'",
"=>",
"'mysql'",
",",
"'host'",
"=>",
"getenv",
"(",
"'DB_HOST'",
")",
",",
"'port'",
"=>",
"getenv",
"(",
"'DB_PORT'",
")",
",",
"'database'",
"=>",
"getenv",
"(",
"'DB_NAME'",
")",
",",
"'username'",
"=>",
"getenv",
"(",
"'DB_USER'",
")",
",",
"'password'",
"=>",
"getenv",
"(",
"'DB_PASSWORD'",
")",
",",
"'charset'",
"=>",
"getenv",
"(",
"'DB_CHARSET'",
")",
",",
"'collation'",
"=>",
"getenv",
"(",
"'DB_COLLATE'",
")",
",",
"'prefix'",
"=>",
"getenv",
"(",
"'DB_PREFIX'",
")",
"?",
":",
"$",
"table_prefix",
",",
"'timezone'",
"=>",
"getenv",
"(",
"'DB_TIMEZONE'",
")",
"?",
":",
"'+00:00'",
",",
"'strict'",
"=>",
"getenv",
"(",
"'DB_STRICT_MODE'",
")",
"?",
":",
"false",
",",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"default",
"[",
"'database'",
"]",
")",
"&&",
"defined",
"(",
"'DB_NAME'",
")",
")",
"{",
"$",
"default",
"[",
"'database'",
"]",
"=",
"DB_NAME",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"default",
"[",
"'username'",
"]",
")",
"&&",
"defined",
"(",
"'DB_USER'",
")",
")",
"{",
"$",
"default",
"[",
"'username'",
"]",
"=",
"DB_USER",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"default",
"[",
"'password'",
"]",
")",
"&&",
"defined",
"(",
"'DB_PASSWORD'",
")",
")",
"{",
"$",
"default",
"[",
"'password'",
"]",
"=",
"DB_PASSWORD",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"default",
"[",
"'host'",
"]",
")",
"&&",
"defined",
"(",
"'DB_HOST'",
")",
")",
"{",
"$",
"default",
"[",
"'host'",
"]",
"=",
"DB_HOST",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"default",
"[",
"'charset'",
"]",
")",
"&&",
"defined",
"(",
"'DB_CHARSET'",
")",
")",
"{",
"$",
"default",
"[",
"'charset'",
"]",
"=",
"DB_CHARSET",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"default",
"[",
"'collation'",
"]",
")",
")",
"{",
"if",
"(",
"defined",
"(",
"'DB_COLLATE'",
")",
"&&",
"DB_COLLATE",
")",
"{",
"$",
"default",
"[",
"'collation'",
"]",
"=",
"DB_COLLATE",
";",
"}",
"else",
"{",
"$",
"default",
"[",
"'collation'",
"]",
"=",
"'utf8_unicode_ci'",
";",
"}",
"}",
"return",
"$",
"default",
";",
"}"
] |
Try to load the database configuration from the environment first
using getenv; finding none, look to the traditional constants typically
defined in wp-config.php
@return array
|
[
"Try",
"to",
"load",
"the",
"database",
"configuration",
"from",
"the",
"environment",
"first",
"using",
"getenv",
";",
"finding",
"none",
"look",
"to",
"the",
"traditional",
"constants",
"typically",
"defined",
"in",
"wp",
"-",
"config",
".",
"php"
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L608-L655
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.bootstrapContainer
|
protected function bootstrapContainer()
{
$this->instance('app', $this);
$this->instance('Illuminate\Container\Container', $this);
$this->instance('path', $this->path());
$this->configure('app');
$this->configure('scout');
$this->configure('services');
$this->configure('session');
$this->configure('mail');
$this->registerContainerAliases();
$this->bindActionsAndFilters();
$this->register(\Illuminate\Session\SessionServiceProvider::class);
$this->register(\FatPanda\Illuminate\WordPress\Providers\Mail\MailServiceProvider::class);
$this->register(Providers\Session\WordPressSessionServiceProvider::class);
$this->register(Providers\Scout\ScoutServiceProvider::class);
$this->singleton(\Illuminate\Contracts\Console\Kernel::class, WordPressConsoleKernel::class);
$this->singleton(\Illuminate\Contracts\Debug\ExceptionHandler::class, WordPressExceptionHandler::class);
}
|
php
|
protected function bootstrapContainer()
{
$this->instance('app', $this);
$this->instance('Illuminate\Container\Container', $this);
$this->instance('path', $this->path());
$this->configure('app');
$this->configure('scout');
$this->configure('services');
$this->configure('session');
$this->configure('mail');
$this->registerContainerAliases();
$this->bindActionsAndFilters();
$this->register(\Illuminate\Session\SessionServiceProvider::class);
$this->register(\FatPanda\Illuminate\WordPress\Providers\Mail\MailServiceProvider::class);
$this->register(Providers\Session\WordPressSessionServiceProvider::class);
$this->register(Providers\Scout\ScoutServiceProvider::class);
$this->singleton(\Illuminate\Contracts\Console\Kernel::class, WordPressConsoleKernel::class);
$this->singleton(\Illuminate\Contracts\Debug\ExceptionHandler::class, WordPressExceptionHandler::class);
}
|
[
"protected",
"function",
"bootstrapContainer",
"(",
")",
"{",
"$",
"this",
"->",
"instance",
"(",
"'app'",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"instance",
"(",
"'Illuminate\\Container\\Container'",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"instance",
"(",
"'path'",
",",
"$",
"this",
"->",
"path",
"(",
")",
")",
";",
"$",
"this",
"->",
"configure",
"(",
"'app'",
")",
";",
"$",
"this",
"->",
"configure",
"(",
"'scout'",
")",
";",
"$",
"this",
"->",
"configure",
"(",
"'services'",
")",
";",
"$",
"this",
"->",
"configure",
"(",
"'session'",
")",
";",
"$",
"this",
"->",
"configure",
"(",
"'mail'",
")",
";",
"$",
"this",
"->",
"registerContainerAliases",
"(",
")",
";",
"$",
"this",
"->",
"bindActionsAndFilters",
"(",
")",
";",
"$",
"this",
"->",
"register",
"(",
"\\",
"Illuminate",
"\\",
"Session",
"\\",
"SessionServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"register",
"(",
"\\",
"FatPanda",
"\\",
"Illuminate",
"\\",
"WordPress",
"\\",
"Providers",
"\\",
"Mail",
"\\",
"MailServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"register",
"(",
"Providers",
"\\",
"Session",
"\\",
"WordPressSessionServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"register",
"(",
"Providers",
"\\",
"Scout",
"\\",
"ScoutServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"singleton",
"(",
"\\",
"Illuminate",
"\\",
"Contracts",
"\\",
"Console",
"\\",
"Kernel",
"::",
"class",
",",
"WordPressConsoleKernel",
"::",
"class",
")",
";",
"$",
"this",
"->",
"singleton",
"(",
"\\",
"Illuminate",
"\\",
"Contracts",
"\\",
"Debug",
"\\",
"ExceptionHandler",
"::",
"class",
",",
"WordPressExceptionHandler",
"::",
"class",
")",
";",
"}"
] |
Bootstrap the plugin container.
@return void
|
[
"Bootstrap",
"the",
"plugin",
"container",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L662-L686
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.storagePath
|
public function storagePath($path = null)
{
return WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . Str::slug($this->getNamespaceName()) . DIRECTORY_SEPARATOR . ( $path ? DIRECTORY_SEPARATOR . $path : $path );
}
|
php
|
public function storagePath($path = null)
{
return WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . Str::slug($this->getNamespaceName()) . DIRECTORY_SEPARATOR . ( $path ? DIRECTORY_SEPARATOR . $path : $path );
}
|
[
"public",
"function",
"storagePath",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"return",
"WP_CONTENT_DIR",
".",
"DIRECTORY_SEPARATOR",
".",
"'storage'",
".",
"DIRECTORY_SEPARATOR",
".",
"Str",
"::",
"slug",
"(",
"$",
"this",
"->",
"getNamespaceName",
"(",
")",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"(",
"$",
"path",
"?",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
":",
"$",
"path",
")",
";",
"}"
] |
Get the storage path for the plugin
@param string|null $path
@return string
|
[
"Get",
"the",
"storage",
"path",
"for",
"the",
"plugin"
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L747-L750
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.getContextualConcrete
|
protected function getContextualConcrete($abstract)
{
if (isset($this->contextual[end($this->buildStack)][$abstract])) {
return $this->contextual[end($this->buildStack)][$abstract];
}
}
|
php
|
protected function getContextualConcrete($abstract)
{
if (isset($this->contextual[end($this->buildStack)][$abstract])) {
return $this->contextual[end($this->buildStack)][$abstract];
}
}
|
[
"protected",
"function",
"getContextualConcrete",
"(",
"$",
"abstract",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"contextual",
"[",
"end",
"(",
"$",
"this",
"->",
"buildStack",
")",
"]",
"[",
"$",
"abstract",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"contextual",
"[",
"end",
"(",
"$",
"this",
"->",
"buildStack",
")",
"]",
"[",
"$",
"abstract",
"]",
";",
"}",
"}"
] |
Find the concrete binding for the given abstract in the contextual binding array.
@param string $abstract
@return string|null
|
[
"Find",
"the",
"concrete",
"binding",
"for",
"the",
"given",
"abstract",
"in",
"the",
"contextual",
"binding",
"array",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L789-L794
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.bindActionsAndFilters
|
protected function bindActionsAndFilters()
{
// setup activation and deactivation hooks
$this->bindActivationAndDeactivationHooks();
// reflect on the contents of this class
$this->reflection = new \ReflectionClass($this);
// get a list of all the methods on this class
$methods = $this->reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
// look for candidates for actions or filter hooks
foreach($methods as $method) {
// skip activation/deactivation hooks (handled above)
if ($method->getName() === 'onActivate' || $method->getName() === 'onDeactivate') {
continue;
}
// look in codedoc for @priority
$priority = 10;
$docComment = $method->getDocComment();
if ($docComment !== false) {
if (preg_match('/@priority\s+(\d+)/', $docComment, $matches)) {
$priority = (int) $matches[1];
}
}
// action methods begin with "on"
if ('on' === strtolower(substr($method->getName(), 0, 2))) {
$action = trim(strtolower(preg_replace('/(?<!\ )[A-Z]/', '_$0', substr($method->getName(), 2))), '_');
$parameterCount = $method->getNumberOfParameters();
add_action($action, [ $this, $method->getName() ], $priority, $parameterCount);
// filter methods begin with "filter"
} else if ('filter' === strtolower(substr($method->getName(), 0, 6))) {
$filter = trim(strtolower(preg_replace('/(?<!\ )[A-Z]/', '_$0', substr($method->getName(), 6))), '_');
$parameterCount = $method->getNumberOfParameters();
add_filter($filter, [ $this, $method->getName() ], $priority, $parameterCount);
}
}
// setup some internal event handlers
add_action('plugins_loaded', [ $this, 'finalOnPluginsLoaded' ], 9);
add_action('init', [ $this, 'finalOnInit' ], 9);
add_action('shutdown', [ $this, 'finalOnShutdown' ], 9);
}
|
php
|
protected function bindActionsAndFilters()
{
// setup activation and deactivation hooks
$this->bindActivationAndDeactivationHooks();
// reflect on the contents of this class
$this->reflection = new \ReflectionClass($this);
// get a list of all the methods on this class
$methods = $this->reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
// look for candidates for actions or filter hooks
foreach($methods as $method) {
// skip activation/deactivation hooks (handled above)
if ($method->getName() === 'onActivate' || $method->getName() === 'onDeactivate') {
continue;
}
// look in codedoc for @priority
$priority = 10;
$docComment = $method->getDocComment();
if ($docComment !== false) {
if (preg_match('/@priority\s+(\d+)/', $docComment, $matches)) {
$priority = (int) $matches[1];
}
}
// action methods begin with "on"
if ('on' === strtolower(substr($method->getName(), 0, 2))) {
$action = trim(strtolower(preg_replace('/(?<!\ )[A-Z]/', '_$0', substr($method->getName(), 2))), '_');
$parameterCount = $method->getNumberOfParameters();
add_action($action, [ $this, $method->getName() ], $priority, $parameterCount);
// filter methods begin with "filter"
} else if ('filter' === strtolower(substr($method->getName(), 0, 6))) {
$filter = trim(strtolower(preg_replace('/(?<!\ )[A-Z]/', '_$0', substr($method->getName(), 6))), '_');
$parameterCount = $method->getNumberOfParameters();
add_filter($filter, [ $this, $method->getName() ], $priority, $parameterCount);
}
}
// setup some internal event handlers
add_action('plugins_loaded', [ $this, 'finalOnPluginsLoaded' ], 9);
add_action('init', [ $this, 'finalOnInit' ], 9);
add_action('shutdown', [ $this, 'finalOnShutdown' ], 9);
}
|
[
"protected",
"function",
"bindActionsAndFilters",
"(",
")",
"{",
"// setup activation and deactivation hooks",
"$",
"this",
"->",
"bindActivationAndDeactivationHooks",
"(",
")",
";",
"// reflect on the contents of this class",
"$",
"this",
"->",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"// get a list of all the methods on this class",
"$",
"methods",
"=",
"$",
"this",
"->",
"reflection",
"->",
"getMethods",
"(",
"\\",
"ReflectionMethod",
"::",
"IS_PUBLIC",
")",
";",
"// look for candidates for actions or filter hooks",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"// skip activation/deactivation hooks (handled above)",
"if",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
"===",
"'onActivate'",
"||",
"$",
"method",
"->",
"getName",
"(",
")",
"===",
"'onDeactivate'",
")",
"{",
"continue",
";",
"}",
"// look in codedoc for @priority",
"$",
"priority",
"=",
"10",
";",
"$",
"docComment",
"=",
"$",
"method",
"->",
"getDocComment",
"(",
")",
";",
"if",
"(",
"$",
"docComment",
"!==",
"false",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/@priority\\s+(\\d+)/'",
",",
"$",
"docComment",
",",
"$",
"matches",
")",
")",
"{",
"$",
"priority",
"=",
"(",
"int",
")",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"}",
"// action methods begin with \"on\"",
"if",
"(",
"'on'",
"===",
"strtolower",
"(",
"substr",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"0",
",",
"2",
")",
")",
")",
"{",
"$",
"action",
"=",
"trim",
"(",
"strtolower",
"(",
"preg_replace",
"(",
"'/(?<!\\ )[A-Z]/'",
",",
"'_$0'",
",",
"substr",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"2",
")",
")",
")",
",",
"'_'",
")",
";",
"$",
"parameterCount",
"=",
"$",
"method",
"->",
"getNumberOfParameters",
"(",
")",
";",
"add_action",
"(",
"$",
"action",
",",
"[",
"$",
"this",
",",
"$",
"method",
"->",
"getName",
"(",
")",
"]",
",",
"$",
"priority",
",",
"$",
"parameterCount",
")",
";",
"// filter methods begin with \"filter\"",
"}",
"else",
"if",
"(",
"'filter'",
"===",
"strtolower",
"(",
"substr",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"0",
",",
"6",
")",
")",
")",
"{",
"$",
"filter",
"=",
"trim",
"(",
"strtolower",
"(",
"preg_replace",
"(",
"'/(?<!\\ )[A-Z]/'",
",",
"'_$0'",
",",
"substr",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"6",
")",
")",
")",
",",
"'_'",
")",
";",
"$",
"parameterCount",
"=",
"$",
"method",
"->",
"getNumberOfParameters",
"(",
")",
";",
"add_filter",
"(",
"$",
"filter",
",",
"[",
"$",
"this",
",",
"$",
"method",
"->",
"getName",
"(",
")",
"]",
",",
"$",
"priority",
",",
"$",
"parameterCount",
")",
";",
"}",
"}",
"// setup some internal event handlers",
"add_action",
"(",
"'plugins_loaded'",
",",
"[",
"$",
"this",
",",
"'finalOnPluginsLoaded'",
"]",
",",
"9",
")",
";",
"add_action",
"(",
"'init'",
",",
"[",
"$",
"this",
",",
"'finalOnInit'",
"]",
",",
"9",
")",
";",
"add_action",
"(",
"'shutdown'",
",",
"[",
"$",
"this",
",",
"'finalOnShutdown'",
"]",
",",
"9",
")",
";",
"}"
] |
Using reflection, put together a list of all the action and filter hooks
defined by this class, and then setup bindings for them.
Action hooks begin with the prefix "on" and filter hooks begin with the
prefix "filter". Additionally, look for the @priority doc comment, and
use that to configure the priority loading order for the hook. Finally, count
the number of parameters in the method signature, and use that to control
the number of arguments that should be passed to the hook when it is invoked.
@return void
|
[
"Using",
"reflection",
"put",
"together",
"a",
"list",
"of",
"all",
"the",
"action",
"and",
"filter",
"hooks",
"defined",
"by",
"this",
"class",
"and",
"then",
"setup",
"bindings",
"for",
"them",
".",
"Action",
"hooks",
"begin",
"with",
"the",
"prefix",
"on",
"and",
"filter",
"hooks",
"begin",
"with",
"the",
"prefix",
"filter",
".",
"Additionally",
"look",
"for",
"the",
"@priority",
"doc",
"comment",
"and",
"use",
"that",
"to",
"configure",
"the",
"priority",
"loading",
"order",
"for",
"the",
"hook",
".",
"Finally",
"count",
"the",
"number",
"of",
"parameters",
"in",
"the",
"method",
"signature",
"and",
"use",
"that",
"to",
"control",
"the",
"number",
"of",
"arguments",
"that",
"should",
"be",
"passed",
"to",
"the",
"hook",
"when",
"it",
"is",
"invoked",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L844-L889
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.finalOnPluginsLoaded
|
final function finalOnPluginsLoaded()
{
// setup easy to access git revision number
if (file_exists($revFilePath = ABSPATH.'../../.rev')) {
$rev = array_map('trim', explode(' ', file_get_contents($revFilePath)));
$this->config->set('.rev', $rev[0]);
} else {
$this->config->set('.rev', 'dev');
}
// if we don't have the get_plugin_data() function, load it
if (!function_exists('get_plugin_data')) {
require_once ABSPATH.'wp-admin/includes/plugin.php';
}
$this->pluginData = get_plugin_data($this->mainFile);
foreach($this->pluginData as $key => $value) {
$propertyName = Str::camel($key);
$this->bind($propertyName, function() use ($value) {
return $value;
});
}
$this->loadTextDomain();
// TODO: check to see if routes.php file is empty or not, and
// then only do this extra initialization if it has routes in it
$this->make('router');
}
|
php
|
final function finalOnPluginsLoaded()
{
// setup easy to access git revision number
if (file_exists($revFilePath = ABSPATH.'../../.rev')) {
$rev = array_map('trim', explode(' ', file_get_contents($revFilePath)));
$this->config->set('.rev', $rev[0]);
} else {
$this->config->set('.rev', 'dev');
}
// if we don't have the get_plugin_data() function, load it
if (!function_exists('get_plugin_data')) {
require_once ABSPATH.'wp-admin/includes/plugin.php';
}
$this->pluginData = get_plugin_data($this->mainFile);
foreach($this->pluginData as $key => $value) {
$propertyName = Str::camel($key);
$this->bind($propertyName, function() use ($value) {
return $value;
});
}
$this->loadTextDomain();
// TODO: check to see if routes.php file is empty or not, and
// then only do this extra initialization if it has routes in it
$this->make('router');
}
|
[
"final",
"function",
"finalOnPluginsLoaded",
"(",
")",
"{",
"// setup easy to access git revision number",
"if",
"(",
"file_exists",
"(",
"$",
"revFilePath",
"=",
"ABSPATH",
".",
"'../../.rev'",
")",
")",
"{",
"$",
"rev",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"' '",
",",
"file_get_contents",
"(",
"$",
"revFilePath",
")",
")",
")",
";",
"$",
"this",
"->",
"config",
"->",
"set",
"(",
"'.rev'",
",",
"$",
"rev",
"[",
"0",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"config",
"->",
"set",
"(",
"'.rev'",
",",
"'dev'",
")",
";",
"}",
"// if we don't have the get_plugin_data() function, load it",
"if",
"(",
"!",
"function_exists",
"(",
"'get_plugin_data'",
")",
")",
"{",
"require_once",
"ABSPATH",
".",
"'wp-admin/includes/plugin.php'",
";",
"}",
"$",
"this",
"->",
"pluginData",
"=",
"get_plugin_data",
"(",
"$",
"this",
"->",
"mainFile",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"pluginData",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"propertyName",
"=",
"Str",
"::",
"camel",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"bind",
"(",
"$",
"propertyName",
",",
"function",
"(",
")",
"use",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
";",
"}",
")",
";",
"}",
"$",
"this",
"->",
"loadTextDomain",
"(",
")",
";",
"// TODO: check to see if routes.php file is empty or not, and",
"// then only do this extra initialization if it has routes in it",
"$",
"this",
"->",
"make",
"(",
"'router'",
")",
";",
"}"
] |
Load plugin meta data, finish configuring various features, including
the REST router and text translation.
@see https://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded
@return void
|
[
"Load",
"plugin",
"meta",
"data",
"finish",
"configuring",
"various",
"features",
"including",
"the",
"REST",
"router",
"and",
"text",
"translation",
".",
"@see",
"https",
":",
"//",
"codex",
".",
"wordpress",
".",
"org",
"/",
"Plugin_API",
"/",
"Action_Reference",
"/",
"plugins_loaded"
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L920-L949
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.register
|
public function register($provider, $options = [], $force = false)
{
if (is_string($provider) || is_class($provider)) {
$implements = class_implements($provider);
if (isset($implements['FatPanda\Illuminate\WordPress\Concerns\CustomSchema'])) {
$this->customSchema[] = $provider;
return $this;
}
if (isset($implements['FatPanda\Illuminate\WordPress\Concerns\CanShortcode'])) {
// we have to do this right away
call_user_func_array($provider . '::register', [ $this ]);
return $this;
}
}
if (!$provider instanceof ServiceProvider) {
$provider = new $provider($this);
}
if (array_key_exists($providerName = get_class($provider), $this->loadedProviders)) {
return $this;
}
$this->loadedProviders[$providerName] = true;
if (method_exists($provider, 'register')) {
$provider->register();
}
if (method_exists($provider, 'boot')) {
return $this->call([$provider, 'boot']);
}
return $this;
}
|
php
|
public function register($provider, $options = [], $force = false)
{
if (is_string($provider) || is_class($provider)) {
$implements = class_implements($provider);
if (isset($implements['FatPanda\Illuminate\WordPress\Concerns\CustomSchema'])) {
$this->customSchema[] = $provider;
return $this;
}
if (isset($implements['FatPanda\Illuminate\WordPress\Concerns\CanShortcode'])) {
// we have to do this right away
call_user_func_array($provider . '::register', [ $this ]);
return $this;
}
}
if (!$provider instanceof ServiceProvider) {
$provider = new $provider($this);
}
if (array_key_exists($providerName = get_class($provider), $this->loadedProviders)) {
return $this;
}
$this->loadedProviders[$providerName] = true;
if (method_exists($provider, 'register')) {
$provider->register();
}
if (method_exists($provider, 'boot')) {
return $this->call([$provider, 'boot']);
}
return $this;
}
|
[
"public",
"function",
"register",
"(",
"$",
"provider",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"provider",
")",
"||",
"is_class",
"(",
"$",
"provider",
")",
")",
"{",
"$",
"implements",
"=",
"class_implements",
"(",
"$",
"provider",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"implements",
"[",
"'FatPanda\\Illuminate\\WordPress\\Concerns\\CustomSchema'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"customSchema",
"[",
"]",
"=",
"$",
"provider",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"implements",
"[",
"'FatPanda\\Illuminate\\WordPress\\Concerns\\CanShortcode'",
"]",
")",
")",
"{",
"// we have to do this right away",
"call_user_func_array",
"(",
"$",
"provider",
".",
"'::register'",
",",
"[",
"$",
"this",
"]",
")",
";",
"return",
"$",
"this",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"provider",
"instanceof",
"ServiceProvider",
")",
"{",
"$",
"provider",
"=",
"new",
"$",
"provider",
"(",
"$",
"this",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"providerName",
"=",
"get_class",
"(",
"$",
"provider",
")",
",",
"$",
"this",
"->",
"loadedProviders",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"loadedProviders",
"[",
"$",
"providerName",
"]",
"=",
"true",
";",
"if",
"(",
"method_exists",
"(",
"$",
"provider",
",",
"'register'",
")",
")",
"{",
"$",
"provider",
"->",
"register",
"(",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"provider",
",",
"'boot'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"call",
"(",
"[",
"$",
"provider",
",",
"'boot'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Register a service provider or a CustomSchema with the plugin.
@param mixed $provider
@param array $options
@param bool $force
@return Plugin
|
[
"Register",
"a",
"service",
"provider",
"or",
"a",
"CustomSchema",
"with",
"the",
"plugin",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L998-L1034
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.