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
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.sequenceMatches | protected function sequenceMatches($sequence) {
$len = strlen($sequence);
$buffer = '';
for ($i = 0; $i < $len; ++$i) {
$buffer .= $this->scanner->current();
// EOF. Rewind and let the caller handle it.
if ($this->scanner->current() === false) {
$this->scanner->unconsume($i);
return false;
}
$this->scanner->next();
}
$this->scanner->unconsume($len);
return $buffer == $sequence;
} | php | protected function sequenceMatches($sequence) {
$len = strlen($sequence);
$buffer = '';
for ($i = 0; $i < $len; ++$i) {
$buffer .= $this->scanner->current();
// EOF. Rewind and let the caller handle it.
if ($this->scanner->current() === false) {
$this->scanner->unconsume($i);
return false;
}
$this->scanner->next();
}
$this->scanner->unconsume($len);
return $buffer == $sequence;
} | [
"protected",
"function",
"sequenceMatches",
"(",
"$",
"sequence",
")",
"{",
"$",
"len",
"=",
"strlen",
"(",
"$",
"sequence",
")",
";",
"$",
"buffer",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"++",
"$",
"i",
")",
"{",
"$",
"buffer",
".=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"// EOF. Rewind and let the caller handle it.",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"scanner",
"->",
"unconsume",
"(",
"$",
"i",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"$",
"this",
"->",
"scanner",
"->",
"unconsume",
"(",
"$",
"len",
")",
";",
"return",
"$",
"buffer",
"==",
"$",
"sequence",
";",
"}"
] | Check if upcomming chars match the given sequence.
This will read the stream for the $sequence. If it's
found, this will return true. If not, return false.
Since this unconsumes any chars it reads, the caller
will still need to read the next sequence, even if
this returns true.
Example: $this->sequenceMatches('</script>') will
see if the input stream is at the start of a
'</script>' string. | [
"Check",
"if",
"upcomming",
"chars",
"match",
"the",
"given",
"sequence",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L965-L981 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.flushBuffer | protected function flushBuffer() {
if ($this->text === '') {
return;
}
$this->events->text($this->text);
$this->text = '';
} | php | protected function flushBuffer() {
if ($this->text === '') {
return;
}
$this->events->text($this->text);
$this->text = '';
} | [
"protected",
"function",
"flushBuffer",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"text",
"===",
"''",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"events",
"->",
"text",
"(",
"$",
"this",
"->",
"text",
")",
";",
"$",
"this",
"->",
"text",
"=",
"''",
";",
"}"
] | Send a TEXT event with the contents of the text buffer.
This emits an HTML5_Parser_EventHandler::text() event with the current contents of the
temporary text buffer. (The buffer is used to group as much PCDATA
as we can instead of emitting lots and lots of TEXT events.) | [
"Send",
"a",
"TEXT",
"event",
"with",
"the",
"contents",
"of",
"the",
"text",
"buffer",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L990-L996 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.parseError | protected function parseError($msg) {
$args = func_get_args();
if (count($args) > 1) {
array_shift($args);
$msg = vsprintf($msg, $args);
}
$line = $this->scanner->currentLine();
$col = $this->scanner->columnOffset();
$this->events->parseError($msg, $line, $col);
return false;
} | php | protected function parseError($msg) {
$args = func_get_args();
if (count($args) > 1) {
array_shift($args);
$msg = vsprintf($msg, $args);
}
$line = $this->scanner->currentLine();
$col = $this->scanner->columnOffset();
$this->events->parseError($msg, $line, $col);
return false;
} | [
"protected",
"function",
"parseError",
"(",
"$",
"msg",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"1",
")",
"{",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"msg",
"=",
"vsprintf",
"(",
"$",
"msg",
",",
"$",
"args",
")",
";",
"}",
"$",
"line",
"=",
"$",
"this",
"->",
"scanner",
"->",
"currentLine",
"(",
")",
";",
"$",
"col",
"=",
"$",
"this",
"->",
"scanner",
"->",
"columnOffset",
"(",
")",
";",
"$",
"this",
"->",
"events",
"->",
"parseError",
"(",
"$",
"msg",
",",
"$",
"line",
",",
"$",
"col",
")",
";",
"return",
"false",
";",
"}"
] | Emit a parse error.
A parse error always returns false because it never consumes any
characters. | [
"Emit",
"a",
"parse",
"error",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L1013-L1025 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.decodeCharacterReference | protected function decodeCharacterReference($inAttribute = false) {
// If it fails this, it's definitely not an entity.
if ($this->scanner->current() != '&') {
return false;
}
// Next char after &.
$tok = $this->scanner->next();
$entity = '';
$start = $this->scanner->position();
if ($tok == false) {
return '&';
}
// These indicate not an entity. We return just
// the &.
if (strspn($tok, static::WHITE . "&<") == 1) {
// $this->scanner->next();
return '&';
}
// Numeric entity
if ($tok == '#') {
$tok = $this->scanner->next();
// Hexidecimal encoding.
// X[0-9a-fA-F]+;
// x[0-9a-fA-F]+;
if ($tok == 'x' || $tok == 'X') {
$tok = $this->scanner->next(); // Consume x
// Convert from hex code to char.
$hex = $this->scanner->getHex();
if (empty($hex)) {
$this->parseError("Expected &#xHEX;, got &#x%s", $tok);
// We unconsume because we don't know what parser rules might
// be in effect for the remaining chars. For example. '&#>'
// might result in a specific parsing rule inside of tag
// contexts, while not inside of pcdata context.
$this->scanner->unconsume(2);
return '&';
}
$entity = HTML5_Parser_CharacterReference::lookupHex($hex);
} // Decimal encoding.
// [0-9]+;
else {
// Convert from decimal to char.
$numeric = $this->scanner->getNumeric();
if ($numeric === false) {
$this->parseError("Expected &#DIGITS;, got &#%s", $tok);
$this->scanner->unconsume(2);
return '&';
}
$entity = HTML5_Parser_CharacterReference::lookupDecimal($numeric);
}
} // String entity.
else {
// Attempt to consume a string up to a ';'.
// [a-zA-Z0-9]+;
$cname = $this->scanner->getAsciiAlpha();
$entity = HTML5_Parser_CharacterReference::lookupName($cname);
if ($entity == null) {
$this->parseError("No match in entity table for '%s'", $entity);
}
}
// The scanner has advanced the cursor for us.
$tok = $this->scanner->current();
// We have an entity. We're done here.
if ($tok == ';') {
$this->scanner->next();
return $entity;
}
// If in an attribute, then failing to match ; means unconsume the
// entire string. Otherwise, failure to match is an error.
if ($inAttribute) {
$this->scanner->unconsume($this->scanner->position() - $start);
return '&';
}
$this->parseError("Expected &ENTITY;, got &ENTITY%s (no trailing ;) ", $tok);
return '&' . $entity;
} | php | protected function decodeCharacterReference($inAttribute = false) {
// If it fails this, it's definitely not an entity.
if ($this->scanner->current() != '&') {
return false;
}
// Next char after &.
$tok = $this->scanner->next();
$entity = '';
$start = $this->scanner->position();
if ($tok == false) {
return '&';
}
// These indicate not an entity. We return just
// the &.
if (strspn($tok, static::WHITE . "&<") == 1) {
// $this->scanner->next();
return '&';
}
// Numeric entity
if ($tok == '#') {
$tok = $this->scanner->next();
// Hexidecimal encoding.
// X[0-9a-fA-F]+;
// x[0-9a-fA-F]+;
if ($tok == 'x' || $tok == 'X') {
$tok = $this->scanner->next(); // Consume x
// Convert from hex code to char.
$hex = $this->scanner->getHex();
if (empty($hex)) {
$this->parseError("Expected &#xHEX;, got &#x%s", $tok);
// We unconsume because we don't know what parser rules might
// be in effect for the remaining chars. For example. '&#>'
// might result in a specific parsing rule inside of tag
// contexts, while not inside of pcdata context.
$this->scanner->unconsume(2);
return '&';
}
$entity = HTML5_Parser_CharacterReference::lookupHex($hex);
} // Decimal encoding.
// [0-9]+;
else {
// Convert from decimal to char.
$numeric = $this->scanner->getNumeric();
if ($numeric === false) {
$this->parseError("Expected &#DIGITS;, got &#%s", $tok);
$this->scanner->unconsume(2);
return '&';
}
$entity = HTML5_Parser_CharacterReference::lookupDecimal($numeric);
}
} // String entity.
else {
// Attempt to consume a string up to a ';'.
// [a-zA-Z0-9]+;
$cname = $this->scanner->getAsciiAlpha();
$entity = HTML5_Parser_CharacterReference::lookupName($cname);
if ($entity == null) {
$this->parseError("No match in entity table for '%s'", $entity);
}
}
// The scanner has advanced the cursor for us.
$tok = $this->scanner->current();
// We have an entity. We're done here.
if ($tok == ';') {
$this->scanner->next();
return $entity;
}
// If in an attribute, then failing to match ; means unconsume the
// entire string. Otherwise, failure to match is an error.
if ($inAttribute) {
$this->scanner->unconsume($this->scanner->position() - $start);
return '&';
}
$this->parseError("Expected &ENTITY;, got &ENTITY%s (no trailing ;) ", $tok);
return '&' . $entity;
} | [
"protected",
"function",
"decodeCharacterReference",
"(",
"$",
"inAttribute",
"=",
"false",
")",
"{",
"// If it fails this, it's definitely not an entity.",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'&'",
")",
"{",
"return",
"false",
";",
"}",
"// Next char after &.",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"$",
"entity",
"=",
"''",
";",
"$",
"start",
"=",
"$",
"this",
"->",
"scanner",
"->",
"position",
"(",
")",
";",
"if",
"(",
"$",
"tok",
"==",
"false",
")",
"{",
"return",
"'&'",
";",
"}",
"// These indicate not an entity. We return just",
"// the &.",
"if",
"(",
"strspn",
"(",
"$",
"tok",
",",
"static",
"::",
"WHITE",
".",
"\"&<\"",
")",
"==",
"1",
")",
"{",
"// $this->scanner->next();",
"return",
"'&'",
";",
"}",
"// Numeric entity",
"if",
"(",
"$",
"tok",
"==",
"'#'",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// Hexidecimal encoding.",
"// X[0-9a-fA-F]+;",
"// x[0-9a-fA-F]+;",
"if",
"(",
"$",
"tok",
"==",
"'x'",
"||",
"$",
"tok",
"==",
"'X'",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// Consume x",
"// Convert from hex code to char.",
"$",
"hex",
"=",
"$",
"this",
"->",
"scanner",
"->",
"getHex",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"hex",
")",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected &#xHEX;, got &#x%s\"",
",",
"$",
"tok",
")",
";",
"// We unconsume because we don't know what parser rules might",
"// be in effect for the remaining chars. For example. '&#>'",
"// might result in a specific parsing rule inside of tag",
"// contexts, while not inside of pcdata context.",
"$",
"this",
"->",
"scanner",
"->",
"unconsume",
"(",
"2",
")",
";",
"return",
"'&'",
";",
"}",
"$",
"entity",
"=",
"HTML5_Parser_CharacterReference",
"::",
"lookupHex",
"(",
"$",
"hex",
")",
";",
"}",
"// Decimal encoding.",
"// [0-9]+;",
"else",
"{",
"// Convert from decimal to char.",
"$",
"numeric",
"=",
"$",
"this",
"->",
"scanner",
"->",
"getNumeric",
"(",
")",
";",
"if",
"(",
"$",
"numeric",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected &#DIGITS;, got &#%s\"",
",",
"$",
"tok",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"unconsume",
"(",
"2",
")",
";",
"return",
"'&'",
";",
"}",
"$",
"entity",
"=",
"HTML5_Parser_CharacterReference",
"::",
"lookupDecimal",
"(",
"$",
"numeric",
")",
";",
"}",
"}",
"// String entity.",
"else",
"{",
"// Attempt to consume a string up to a ';'.",
"// [a-zA-Z0-9]+;",
"$",
"cname",
"=",
"$",
"this",
"->",
"scanner",
"->",
"getAsciiAlpha",
"(",
")",
";",
"$",
"entity",
"=",
"HTML5_Parser_CharacterReference",
"::",
"lookupName",
"(",
"$",
"cname",
")",
";",
"if",
"(",
"$",
"entity",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"No match in entity table for '%s'\"",
",",
"$",
"entity",
")",
";",
"}",
"}",
"// The scanner has advanced the cursor for us.",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"// We have an entity. We're done here.",
"if",
"(",
"$",
"tok",
"==",
"';'",
")",
"{",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"$",
"entity",
";",
"}",
"// If in an attribute, then failing to match ; means unconsume the",
"// entire string. Otherwise, failure to match is an error.",
"if",
"(",
"$",
"inAttribute",
")",
"{",
"$",
"this",
"->",
"scanner",
"->",
"unconsume",
"(",
"$",
"this",
"->",
"scanner",
"->",
"position",
"(",
")",
"-",
"$",
"start",
")",
";",
"return",
"'&'",
";",
"}",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected &ENTITY;, got &ENTITY%s (no trailing ;) \"",
",",
"$",
"tok",
")",
";",
"return",
"'&'",
".",
"$",
"entity",
";",
"}"
] | Decode a character reference and return the string.
Returns false if the entity could not be found. If $inAttribute is set
to true, a bare & will be returned as-is.
@param boolean $inAttribute
Set to true if the text is inside of an attribute value.
false otherwise. | [
"Decode",
"a",
"character",
"reference",
"and",
"return",
"the",
"string",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L1037-L1122 |
Danack/GithubArtaxService | lib/GithubService/Operation/updateAuthorization.php | updateAuthorization.createRequest | public function createRequest() {
$request = new \Amp\Artax\Request();
$url = null;
$request->setMethod('');
$jsonParams = [];
$value = $this->getFilteredParameter('scopes');
$jsonParams['scopes'] = $value;
$value = $this->getFilteredParameter('add_scopes');
$jsonParams['add_scopes'] = $value;
$value = $this->getFilteredParameter('remove_scopes');
$jsonParams['remove_scopes'] = $value;
$value = $this->getFilteredParameter('note');
$jsonParams['note'] = $value;
$value = $this->getFilteredParameter('note_url');
$jsonParams['note_url'] = $value;
$value = $this->getFilteredParameter('fingerprint');
$jsonParams['fingerprint'] = $value;
//Parameters are parsed and set, lets prepare the request
if (count($jsonParams)) {
$jsonBody = json_encode($jsonParams);
$request->setHeader("Content-Type", "application/json");
$request->setBody($jsonBody);
}
if ($url == null) {
$url = "https://api.github.com/authorizations/{id}";
}
$request->setUri($url);
return $request;
} | php | public function createRequest() {
$request = new \Amp\Artax\Request();
$url = null;
$request->setMethod('');
$jsonParams = [];
$value = $this->getFilteredParameter('scopes');
$jsonParams['scopes'] = $value;
$value = $this->getFilteredParameter('add_scopes');
$jsonParams['add_scopes'] = $value;
$value = $this->getFilteredParameter('remove_scopes');
$jsonParams['remove_scopes'] = $value;
$value = $this->getFilteredParameter('note');
$jsonParams['note'] = $value;
$value = $this->getFilteredParameter('note_url');
$jsonParams['note_url'] = $value;
$value = $this->getFilteredParameter('fingerprint');
$jsonParams['fingerprint'] = $value;
//Parameters are parsed and set, lets prepare the request
if (count($jsonParams)) {
$jsonBody = json_encode($jsonParams);
$request->setHeader("Content-Type", "application/json");
$request->setBody($jsonBody);
}
if ($url == null) {
$url = "https://api.github.com/authorizations/{id}";
}
$request->setUri($url);
return $request;
} | [
"public",
"function",
"createRequest",
"(",
")",
"{",
"$",
"request",
"=",
"new",
"\\",
"Amp",
"\\",
"Artax",
"\\",
"Request",
"(",
")",
";",
"$",
"url",
"=",
"null",
";",
"$",
"request",
"->",
"setMethod",
"(",
"''",
")",
";",
"$",
"jsonParams",
"=",
"[",
"]",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getFilteredParameter",
"(",
"'scopes'",
")",
";",
"$",
"jsonParams",
"[",
"'scopes'",
"]",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getFilteredParameter",
"(",
"'add_scopes'",
")",
";",
"$",
"jsonParams",
"[",
"'add_scopes'",
"]",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getFilteredParameter",
"(",
"'remove_scopes'",
")",
";",
"$",
"jsonParams",
"[",
"'remove_scopes'",
"]",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getFilteredParameter",
"(",
"'note'",
")",
";",
"$",
"jsonParams",
"[",
"'note'",
"]",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getFilteredParameter",
"(",
"'note_url'",
")",
";",
"$",
"jsonParams",
"[",
"'note_url'",
"]",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getFilteredParameter",
"(",
"'fingerprint'",
")",
";",
"$",
"jsonParams",
"[",
"'fingerprint'",
"]",
"=",
"$",
"value",
";",
"//Parameters are parsed and set, lets prepare the request",
"if",
"(",
"count",
"(",
"$",
"jsonParams",
")",
")",
"{",
"$",
"jsonBody",
"=",
"json_encode",
"(",
"$",
"jsonParams",
")",
";",
"$",
"request",
"->",
"setHeader",
"(",
"\"Content-Type\"",
",",
"\"application/json\"",
")",
";",
"$",
"request",
"->",
"setBody",
"(",
"$",
"jsonBody",
")",
";",
"}",
"if",
"(",
"$",
"url",
"==",
"null",
")",
"{",
"$",
"url",
"=",
"\"https://api.github.com/authorizations/{id}\"",
";",
"}",
"$",
"request",
"->",
"setUri",
"(",
"$",
"url",
")",
";",
"return",
"$",
"request",
";",
"}"
] | Create an Amp\Artax\Request object from the operation.
@return \Amp\Artax\Request | [
"Create",
"an",
"Amp",
"\\",
"Artax",
"\\",
"Request",
"object",
"from",
"the",
"operation",
"."
] | train | https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/updateAuthorization.php#L192-L224 |
wenbinye/PhalconX | src/Helper/ClassHelper.php | ClassHelper.splitName | public static function splitName($class)
{
$pos = strrpos($class, '\\');
if ($pos === false) {
return [null, $class];
} else {
return [substr($class, 0, $pos), substr($class, $pos+1)];
}
} | php | public static function splitName($class)
{
$pos = strrpos($class, '\\');
if ($pos === false) {
return [null, $class];
} else {
return [substr($class, 0, $pos), substr($class, $pos+1)];
}
} | [
"public",
"static",
"function",
"splitName",
"(",
"$",
"class",
")",
"{",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"class",
",",
"'\\\\'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"return",
"[",
"null",
",",
"$",
"class",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"substr",
"(",
"$",
"class",
",",
"0",
",",
"$",
"pos",
")",
",",
"substr",
"(",
"$",
"class",
",",
"$",
"pos",
"+",
"1",
")",
"]",
";",
"}",
"}"
] | Splits class name to namespace and class name
@param string $class
@return array | [
"Splits",
"class",
"name",
"to",
"namespace",
"and",
"class",
"name"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/ClassHelper.php#L47-L55 |
weew/http | src/Weew/Http/HttpRequest.php | HttpRequest.getParameter | public function getParameter($key, $default = null) {
$value = $this->getUrl()->getQuery()->get($key);
if ($value === null) {
$value = $this->getData()->get($key, $default);
}
return $value;
} | php | public function getParameter($key, $default = null) {
$value = $this->getUrl()->getQuery()->get($key);
if ($value === null) {
$value = $this->getData()->get($key, $default);
}
return $value;
} | [
"public",
"function",
"getParameter",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getUrl",
"(",
")",
"->",
"getQuery",
"(",
")",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Retrieve a value from url query or message body.
@param string $key
@param null $default
@return mixed | [
"Retrieve",
"a",
"value",
"from",
"url",
"query",
"or",
"message",
"body",
"."
] | train | https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/HttpRequest.php#L314-L322 |
weew/http | src/Weew/Http/HttpRequest.php | HttpRequest.setDefaults | protected function setDefaults() {
if ($this->getAccept() === null) {
$this->setDefaultAccept();
}
if ($this->getContentType() === null) {
$this->setDefaultContentType();
}
} | php | protected function setDefaults() {
if ($this->getAccept() === null) {
$this->setDefaultAccept();
}
if ($this->getContentType() === null) {
$this->setDefaultContentType();
}
} | [
"protected",
"function",
"setDefaults",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getAccept",
"(",
")",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setDefaultAccept",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getContentType",
"(",
")",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setDefaultContentType",
"(",
")",
";",
"}",
"}"
] | Use this as hook to extend your custom request. | [
"Use",
"this",
"as",
"hook",
"to",
"extend",
"your",
"custom",
"request",
"."
] | train | https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/HttpRequest.php#L344-L352 |
DesignPond/newsletter | src/Http/Controllers/Backend/SubscriberController.php | SubscriberController.subscribers | public function subscribers(Request $request)
{
$order = $request->input('order');
$search = $request->input('search',null);
$search = ($search ? $search['value'] : null);
return $this->subscriber->get_ajax(
$request->input('draw'), $request->input('start'), $request->input('length'), $order[0]['column'], $order[0]['dir'], $search
);
} | php | public function subscribers(Request $request)
{
$order = $request->input('order');
$search = $request->input('search',null);
$search = ($search ? $search['value'] : null);
return $this->subscriber->get_ajax(
$request->input('draw'), $request->input('start'), $request->input('length'), $order[0]['column'], $order[0]['dir'], $search
);
} | [
"public",
"function",
"subscribers",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"order",
"=",
"$",
"request",
"->",
"input",
"(",
"'order'",
")",
";",
"$",
"search",
"=",
"$",
"request",
"->",
"input",
"(",
"'search'",
",",
"null",
")",
";",
"$",
"search",
"=",
"(",
"$",
"search",
"?",
"$",
"search",
"[",
"'value'",
"]",
":",
"null",
")",
";",
"return",
"$",
"this",
"->",
"subscriber",
"->",
"get_ajax",
"(",
"$",
"request",
"->",
"input",
"(",
"'draw'",
")",
",",
"$",
"request",
"->",
"input",
"(",
"'start'",
")",
",",
"$",
"request",
"->",
"input",
"(",
"'length'",
")",
",",
"$",
"order",
"[",
"0",
"]",
"[",
"'column'",
"]",
",",
"$",
"order",
"[",
"0",
"]",
"[",
"'dir'",
"]",
",",
"$",
"search",
")",
";",
"}"
] | Display a listing of tsubscribers for ajax
GET /subscriber/getAllAbos
@return Response | [
"Display",
"a",
"listing",
"of",
"tsubscribers",
"for",
"ajax",
"GET",
"/",
"subscriber",
"/",
"getAllAbos"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/SubscriberController.php#L50-L59 |
DesignPond/newsletter | src/Http/Controllers/Backend/SubscriberController.php | SubscriberController.store | public function store(Request $request)
{
// Subscribe user with activation token to website list and sync newsletter abos
$subscribe = $this->subscriber->create(
[
'email' => $request->input('email'),
'activated_at' => \Carbon\Carbon::now(),
'newsletter_id' => $request->input('newsletter_id')
]
);
//Subscribe to mailjet
$lists = $request->input('newsletter_id');
if(!empty($lists))
{
foreach($lists as $list)
{
$newsletter = $this->newsletter->find($list);
$this->worker->setList($newsletter->list_id);
$this->worker->subscribeEmailToList($subscribe->email);
}
}
alert()->success('Abonné ajouté');
return redirect('build/subscriber');
} | php | public function store(Request $request)
{
// Subscribe user with activation token to website list and sync newsletter abos
$subscribe = $this->subscriber->create(
[
'email' => $request->input('email'),
'activated_at' => \Carbon\Carbon::now(),
'newsletter_id' => $request->input('newsletter_id')
]
);
//Subscribe to mailjet
$lists = $request->input('newsletter_id');
if(!empty($lists))
{
foreach($lists as $list)
{
$newsletter = $this->newsletter->find($list);
$this->worker->setList($newsletter->list_id);
$this->worker->subscribeEmailToList($subscribe->email);
}
}
alert()->success('Abonné ajouté');
return redirect('build/subscriber');
} | [
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"// Subscribe user with activation token to website list and sync newsletter abos",
"$",
"subscribe",
"=",
"$",
"this",
"->",
"subscriber",
"->",
"create",
"(",
"[",
"'email'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'email'",
")",
",",
"'activated_at'",
"=>",
"\\",
"Carbon",
"\\",
"Carbon",
"::",
"now",
"(",
")",
",",
"'newsletter_id'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
")",
"]",
")",
";",
"//Subscribe to mailjet",
"$",
"lists",
"=",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"lists",
")",
")",
"{",
"foreach",
"(",
"$",
"lists",
"as",
"$",
"list",
")",
"{",
"$",
"newsletter",
"=",
"$",
"this",
"->",
"newsletter",
"->",
"find",
"(",
"$",
"list",
")",
";",
"$",
"this",
"->",
"worker",
"->",
"setList",
"(",
"$",
"newsletter",
"->",
"list_id",
")",
";",
"$",
"this",
"->",
"worker",
"->",
"subscribeEmailToList",
"(",
"$",
"subscribe",
"->",
"email",
")",
";",
"}",
"}",
"alert",
"(",
")",
"->",
"success",
"(",
"'Abonné ajouté');",
"",
"",
"return",
"redirect",
"(",
"'build/subscriber'",
")",
";",
"}"
] | Store a newly created resource in storage.
POST /subscriber
@return Response | [
"Store",
"a",
"newly",
"created",
"resource",
"in",
"storage",
".",
"POST",
"/",
"subscriber"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/SubscriberController.php#L80-L107 |
DesignPond/newsletter | src/Http/Controllers/Backend/SubscriberController.php | SubscriberController.show | public function show($id)
{
$subscriber = $this->subscriber->find($id);
$newsletter = $this->newsletter->getAll();
return view('newsletter::Backend.subscribers.show')->with(['subscriber' => $subscriber , 'newsletter' => $newsletter]);
} | php | public function show($id)
{
$subscriber = $this->subscriber->find($id);
$newsletter = $this->newsletter->getAll();
return view('newsletter::Backend.subscribers.show')->with(['subscriber' => $subscriber , 'newsletter' => $newsletter]);
} | [
"public",
"function",
"show",
"(",
"$",
"id",
")",
"{",
"$",
"subscriber",
"=",
"$",
"this",
"->",
"subscriber",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"newsletter",
"=",
"$",
"this",
"->",
"newsletter",
"->",
"getAll",
"(",
")",
";",
"return",
"view",
"(",
"'newsletter::Backend.subscribers.show'",
")",
"->",
"with",
"(",
"[",
"'subscriber'",
"=>",
"$",
"subscriber",
",",
"'newsletter'",
"=>",
"$",
"newsletter",
"]",
")",
";",
"}"
] | Show the form for editing the specified resource.
GET /subscriber/{id}/edit
@param int $id
@return Response | [
"Show",
"the",
"form",
"for",
"editing",
"the",
"specified",
"resource",
".",
"GET",
"/",
"subscriber",
"/",
"{",
"id",
"}",
"/",
"edit"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/SubscriberController.php#L116-L122 |
DesignPond/newsletter | src/Http/Controllers/Backend/SubscriberController.php | SubscriberController.update | public function update(RemoveNewsletterUserRequest $request, $id)
{
$activated_at = ($request->input('activation') ? date('Y-m-d G:i:s') : null);
$subscriber = $this->subscriber->find($id);
$new = $request->input('newsletter_id',[]);
$has = $subscriber->subscriptions->pluck('id')->all();
$added = array_diff($new, $has);
$removed = array_diff(array_unique(array_merge($new, $has)), $new);
// if email edited we have to change it
if($request->input('email') != $subscriber->email){
// unsubscribe all and delete
$this->subscription_worker->unsubscribe($subscriber,$has);
// make new subscriber and add all
$newsubscriber = $this->subscriber->create([
'email' => $request->input('email'), 'activated_at' => $activated_at, 'activation_token' => md5($request->input('email').\Carbon\Carbon::now()),
]);
$this->subscription_worker->subscribe($newsubscriber,$new);
alert()->success('Abonné édité');
return redirect('build/subscriber/'.$newsubscriber->id);
}
else{
$subscriber = $this->subscriber->update(['id' => $id,'activated_at' => $request->input('activation') ? date('Y-m-d G:i:s') : null]);
$this->subscription_worker->subscribe($subscriber,$added);
$subscriber = $this->subscription_worker->unsubscribe($subscriber,$removed);
if(!$subscriber){
alert()->success('Abonné édité et supprimé');
return redirect('build/subscriber');
}
alert()->success('Abonné édité');
return redirect('build/subscriber/'.$subscriber->id);
}
} | php | public function update(RemoveNewsletterUserRequest $request, $id)
{
$activated_at = ($request->input('activation') ? date('Y-m-d G:i:s') : null);
$subscriber = $this->subscriber->find($id);
$new = $request->input('newsletter_id',[]);
$has = $subscriber->subscriptions->pluck('id')->all();
$added = array_diff($new, $has);
$removed = array_diff(array_unique(array_merge($new, $has)), $new);
// if email edited we have to change it
if($request->input('email') != $subscriber->email){
// unsubscribe all and delete
$this->subscription_worker->unsubscribe($subscriber,$has);
// make new subscriber and add all
$newsubscriber = $this->subscriber->create([
'email' => $request->input('email'), 'activated_at' => $activated_at, 'activation_token' => md5($request->input('email').\Carbon\Carbon::now()),
]);
$this->subscription_worker->subscribe($newsubscriber,$new);
alert()->success('Abonné édité');
return redirect('build/subscriber/'.$newsubscriber->id);
}
else{
$subscriber = $this->subscriber->update(['id' => $id,'activated_at' => $request->input('activation') ? date('Y-m-d G:i:s') : null]);
$this->subscription_worker->subscribe($subscriber,$added);
$subscriber = $this->subscription_worker->unsubscribe($subscriber,$removed);
if(!$subscriber){
alert()->success('Abonné édité et supprimé');
return redirect('build/subscriber');
}
alert()->success('Abonné édité');
return redirect('build/subscriber/'.$subscriber->id);
}
} | [
"public",
"function",
"update",
"(",
"RemoveNewsletterUserRequest",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"activated_at",
"=",
"(",
"$",
"request",
"->",
"input",
"(",
"'activation'",
")",
"?",
"date",
"(",
"'Y-m-d G:i:s'",
")",
":",
"null",
")",
";",
"$",
"subscriber",
"=",
"$",
"this",
"->",
"subscriber",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"new",
"=",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
",",
"[",
"]",
")",
";",
"$",
"has",
"=",
"$",
"subscriber",
"->",
"subscriptions",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"all",
"(",
")",
";",
"$",
"added",
"=",
"array_diff",
"(",
"$",
"new",
",",
"$",
"has",
")",
";",
"$",
"removed",
"=",
"array_diff",
"(",
"array_unique",
"(",
"array_merge",
"(",
"$",
"new",
",",
"$",
"has",
")",
")",
",",
"$",
"new",
")",
";",
"// if email edited we have to change it",
"if",
"(",
"$",
"request",
"->",
"input",
"(",
"'email'",
")",
"!=",
"$",
"subscriber",
"->",
"email",
")",
"{",
"// unsubscribe all and delete",
"$",
"this",
"->",
"subscription_worker",
"->",
"unsubscribe",
"(",
"$",
"subscriber",
",",
"$",
"has",
")",
";",
"// make new subscriber and add all",
"$",
"newsubscriber",
"=",
"$",
"this",
"->",
"subscriber",
"->",
"create",
"(",
"[",
"'email'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'email'",
")",
",",
"'activated_at'",
"=>",
"$",
"activated_at",
",",
"'activation_token'",
"=>",
"md5",
"(",
"$",
"request",
"->",
"input",
"(",
"'email'",
")",
".",
"\\",
"Carbon",
"\\",
"Carbon",
"::",
"now",
"(",
")",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"subscription_worker",
"->",
"subscribe",
"(",
"$",
"newsubscriber",
",",
"$",
"new",
")",
";",
"alert",
"(",
")",
"->",
"success",
"(",
"'Abonné édité');",
"",
"",
"return",
"redirect",
"(",
"'build/subscriber/'",
".",
"$",
"newsubscriber",
"->",
"id",
")",
";",
"}",
"else",
"{",
"$",
"subscriber",
"=",
"$",
"this",
"->",
"subscriber",
"->",
"update",
"(",
"[",
"'id'",
"=>",
"$",
"id",
",",
"'activated_at'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'activation'",
")",
"?",
"date",
"(",
"'Y-m-d G:i:s'",
")",
":",
"null",
"]",
")",
";",
"$",
"this",
"->",
"subscription_worker",
"->",
"subscribe",
"(",
"$",
"subscriber",
",",
"$",
"added",
")",
";",
"$",
"subscriber",
"=",
"$",
"this",
"->",
"subscription_worker",
"->",
"unsubscribe",
"(",
"$",
"subscriber",
",",
"$",
"removed",
")",
";",
"if",
"(",
"!",
"$",
"subscriber",
")",
"{",
"alert",
"(",
")",
"->",
"success",
"(",
"'Abonné édité et supprimé');",
"",
"",
"return",
"redirect",
"(",
"'build/subscriber'",
")",
";",
"}",
"alert",
"(",
")",
"->",
"success",
"(",
"'Abonné édité');",
"",
"",
"return",
"redirect",
"(",
"'build/subscriber/'",
".",
"$",
"subscriber",
"->",
"id",
")",
";",
"}",
"}"
] | Update the specified resource in storage.
PUT /subscriber/{id}
@param int $id
@return Response | [
"Update",
"the",
"specified",
"resource",
"in",
"storage",
".",
"PUT",
"/",
"subscriber",
"/",
"{",
"id",
"}"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/SubscriberController.php#L131-L171 |
DesignPond/newsletter | src/Http/Controllers/Backend/SubscriberController.php | SubscriberController.destroy | public function destroy($id,Request $request)
{
// Validate the email
$this->validate($request, array('email' => 'required'));
// find the abo
$subscriber = $this->subscriber->findByEmail($request->email);
// Remove all the abos we have
$subscriber->subscriptions()->detach();
// Delete the subscriber from DB
$this->subscriber->delete($subscriber->email);
$newsletters = $this->newsletter->getAll();
foreach($newsletters as $newsletter)
{
$this->worker->setList($newsletter->list_id);
// Remove subscriber from list mailjet
if(!$this->worker->removeContact($subscriber->email))
{
throw new \designpond\newsletter\Exceptions\DeleteUserException('Erreur avec la suppression de l\'abonnés sur mailjet');
}
}
alert()->success('Abonné supprimé');
return redirect('build/subscriber');
} | php | public function destroy($id,Request $request)
{
// Validate the email
$this->validate($request, array('email' => 'required'));
// find the abo
$subscriber = $this->subscriber->findByEmail($request->email);
// Remove all the abos we have
$subscriber->subscriptions()->detach();
// Delete the subscriber from DB
$this->subscriber->delete($subscriber->email);
$newsletters = $this->newsletter->getAll();
foreach($newsletters as $newsletter)
{
$this->worker->setList($newsletter->list_id);
// Remove subscriber from list mailjet
if(!$this->worker->removeContact($subscriber->email))
{
throw new \designpond\newsletter\Exceptions\DeleteUserException('Erreur avec la suppression de l\'abonnés sur mailjet');
}
}
alert()->success('Abonné supprimé');
return redirect('build/subscriber');
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"// Validate the email",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"array",
"(",
"'email'",
"=>",
"'required'",
")",
")",
";",
"// find the abo",
"$",
"subscriber",
"=",
"$",
"this",
"->",
"subscriber",
"->",
"findByEmail",
"(",
"$",
"request",
"->",
"email",
")",
";",
"// Remove all the abos we have",
"$",
"subscriber",
"->",
"subscriptions",
"(",
")",
"->",
"detach",
"(",
")",
";",
"// Delete the subscriber from DB",
"$",
"this",
"->",
"subscriber",
"->",
"delete",
"(",
"$",
"subscriber",
"->",
"email",
")",
";",
"$",
"newsletters",
"=",
"$",
"this",
"->",
"newsletter",
"->",
"getAll",
"(",
")",
";",
"foreach",
"(",
"$",
"newsletters",
"as",
"$",
"newsletter",
")",
"{",
"$",
"this",
"->",
"worker",
"->",
"setList",
"(",
"$",
"newsletter",
"->",
"list_id",
")",
";",
"// Remove subscriber from list mailjet",
"if",
"(",
"!",
"$",
"this",
"->",
"worker",
"->",
"removeContact",
"(",
"$",
"subscriber",
"->",
"email",
")",
")",
"{",
"throw",
"new",
"\\",
"designpond",
"\\",
"newsletter",
"\\",
"Exceptions",
"\\",
"DeleteUserException",
"(",
"'Erreur avec la suppression de l\\'abonnés sur mailjet')",
";",
"",
"}",
"}",
"alert",
"(",
")",
"->",
"success",
"(",
"'Abonné supprimé');",
"",
"",
"return",
"redirect",
"(",
"'build/subscriber'",
")",
";",
"}"
] | Remove the specified resource from storage.
DELETE /subscriber/{id}
@param int $email
@return Response | [
"Remove",
"the",
"specified",
"resource",
"from",
"storage",
".",
"DELETE",
"/",
"subscriber",
"/",
"{",
"id",
"}"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/SubscriberController.php#L180-L210 |
m4grio/bangkok-insurance-php | src/Client/PremiumClient.php | PremiumClient.call | public function call($method, Array $params = [])
{
$rawResult = parent::call($method, $params);
/**
* I know this is just awful; will do it properly later on
*
* @todo
*/
switch ($method) {
case 'calculator_vol_prem':
$result = $rawResult->calculator_vol_premReturn->VolPremiumBean;
break;
case 'calculator_comp_prem':
break;
}
return $result;
} | php | public function call($method, Array $params = [])
{
$rawResult = parent::call($method, $params);
/**
* I know this is just awful; will do it properly later on
*
* @todo
*/
switch ($method) {
case 'calculator_vol_prem':
$result = $rawResult->calculator_vol_premReturn->VolPremiumBean;
break;
case 'calculator_comp_prem':
break;
}
return $result;
} | [
"public",
"function",
"call",
"(",
"$",
"method",
",",
"Array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"rawResult",
"=",
"parent",
"::",
"call",
"(",
"$",
"method",
",",
"$",
"params",
")",
";",
"/**\n * I know this is just awful; will do it properly later on\n *\n * @todo\n */",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'calculator_vol_prem'",
":",
"$",
"result",
"=",
"$",
"rawResult",
"->",
"calculator_vol_premReturn",
"->",
"VolPremiumBean",
";",
"break",
";",
"case",
"'calculator_comp_prem'",
":",
"break",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | @param $method
@param array $params
@return PremiumResult | [
"@param",
"$method",
"@param",
"array",
"$params"
] | train | https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/Client/PremiumClient.php#L23-L42 |
wenbinye/PhalconX | src/Helper/ClassParser.php | ClassParser.getImports | public function getImports()
{
$imports = [];
$tokens = token_get_all(file_get_contents($this->file));
reset($tokens);
$token = '';
while ($token !== false) {
$token = next($tokens);
if (!is_array($token)) {
continue;
}
if ($token[0] === T_USE) {
$stmt = $this->parseUseStatement($tokens);
$imports += $stmt;
} elseif ($token[0] === T_CLASS) {
break;
}
}
return $imports;
} | php | public function getImports()
{
$imports = [];
$tokens = token_get_all(file_get_contents($this->file));
reset($tokens);
$token = '';
while ($token !== false) {
$token = next($tokens);
if (!is_array($token)) {
continue;
}
if ($token[0] === T_USE) {
$stmt = $this->parseUseStatement($tokens);
$imports += $stmt;
} elseif ($token[0] === T_CLASS) {
break;
}
}
return $imports;
} | [
"public",
"function",
"getImports",
"(",
")",
"{",
"$",
"imports",
"=",
"[",
"]",
";",
"$",
"tokens",
"=",
"token_get_all",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"file",
")",
")",
";",
"reset",
"(",
"$",
"tokens",
")",
";",
"$",
"token",
"=",
"''",
";",
"while",
"(",
"$",
"token",
"!==",
"false",
")",
"{",
"$",
"token",
"=",
"next",
"(",
"$",
"tokens",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"token",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"T_USE",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"parseUseStatement",
"(",
"$",
"tokens",
")",
";",
"$",
"imports",
"+=",
"$",
"stmt",
";",
"}",
"elseif",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"T_CLASS",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"imports",
";",
"}"
] | Gets all imported classes
@return array | [
"Gets",
"all",
"imported",
"classes"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/ClassParser.php#L57-L76 |
zicht/z | src/Zicht/Tool/Container/Task.php | Task.compile | public function compile(Buffer $buffer)
{
parent::compile($buffer);
if (substr($this->getName(), 0, 1) !== '_') {
$buffer
->writeln('try {')
->indent(1)
->writeln('$z->addCommand(')
->indent(1)
->write('new \Zicht\Tool\Command\TaskCommand(')
->asPhp($this->getName())
->raw(', ')
->asPhp($this->getArguments(true))
->raw(', ')
->asPhp($this->getOptions())
->raw(', ')
->asPhp($this->taskDef['flags'])
->raw(', ')
->asPhp($this->getHelp() ? $this->getHelp() : "(no help available for this task)")
->raw(')')->eol()
->indent(-1)
->writeln(');')
->indent(-1)
->writeln('} catch (\Exception $e) {')
->indent(1)
->writeln('throw new \Zicht\Tool\Container\ConfigurationException("Error while initializing task \'' . $this->getName() . '\'", 0, $e);')
->indent(-1)
->writeln('}')
;
}
} | php | public function compile(Buffer $buffer)
{
parent::compile($buffer);
if (substr($this->getName(), 0, 1) !== '_') {
$buffer
->writeln('try {')
->indent(1)
->writeln('$z->addCommand(')
->indent(1)
->write('new \Zicht\Tool\Command\TaskCommand(')
->asPhp($this->getName())
->raw(', ')
->asPhp($this->getArguments(true))
->raw(', ')
->asPhp($this->getOptions())
->raw(', ')
->asPhp($this->taskDef['flags'])
->raw(', ')
->asPhp($this->getHelp() ? $this->getHelp() : "(no help available for this task)")
->raw(')')->eol()
->indent(-1)
->writeln(');')
->indent(-1)
->writeln('} catch (\Exception $e) {')
->indent(1)
->writeln('throw new \Zicht\Tool\Container\ConfigurationException("Error while initializing task \'' . $this->getName() . '\'", 0, $e);')
->indent(-1)
->writeln('}')
;
}
} | [
"public",
"function",
"compile",
"(",
"Buffer",
"$",
"buffer",
")",
"{",
"parent",
"::",
"compile",
"(",
"$",
"buffer",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"0",
",",
"1",
")",
"!==",
"'_'",
")",
"{",
"$",
"buffer",
"->",
"writeln",
"(",
"'try {'",
")",
"->",
"indent",
"(",
"1",
")",
"->",
"writeln",
"(",
"'$z->addCommand('",
")",
"->",
"indent",
"(",
"1",
")",
"->",
"write",
"(",
"'new \\Zicht\\Tool\\Command\\TaskCommand('",
")",
"->",
"asPhp",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
"->",
"raw",
"(",
"', '",
")",
"->",
"asPhp",
"(",
"$",
"this",
"->",
"getArguments",
"(",
"true",
")",
")",
"->",
"raw",
"(",
"', '",
")",
"->",
"asPhp",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
")",
"->",
"raw",
"(",
"', '",
")",
"->",
"asPhp",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'flags'",
"]",
")",
"->",
"raw",
"(",
"', '",
")",
"->",
"asPhp",
"(",
"$",
"this",
"->",
"getHelp",
"(",
")",
"?",
"$",
"this",
"->",
"getHelp",
"(",
")",
":",
"\"(no help available for this task)\"",
")",
"->",
"raw",
"(",
"')'",
")",
"->",
"eol",
"(",
")",
"->",
"indent",
"(",
"-",
"1",
")",
"->",
"writeln",
"(",
"');'",
")",
"->",
"indent",
"(",
"-",
"1",
")",
"->",
"writeln",
"(",
"'} catch (\\Exception $e) {'",
")",
"->",
"indent",
"(",
"1",
")",
"->",
"writeln",
"(",
"'throw new \\Zicht\\Tool\\Container\\ConfigurationException(\"Error while initializing task \\''",
".",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'\\'\", 0, $e);'",
")",
"->",
"indent",
"(",
"-",
"1",
")",
"->",
"writeln",
"(",
"'}'",
")",
";",
"}",
"}"
] | Compiles the task initialization code into the buffer.
@param \Zicht\Tool\Script\Buffer $buffer
@return void | [
"Compiles",
"the",
"task",
"initialization",
"code",
"into",
"the",
"buffer",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/Task.php#L63-L93 |
zicht/z | src/Zicht/Tool/Container/Task.php | Task.compileBody | public function compileBody(Buffer $buffer)
{
$buffer->writeln('$ret = null;');
foreach ($this->taskDef['flags'] as $flag => $value) {
$buffer
->write('if (null === $z->resolve(')->asPhp($flag)->raw(', false)) {')->eol()
->indent(1)
->write('$z->set(')->asPhp($flag)->raw(', ')->asPhp($value)->raw(');')->eol()
->indent(-1)
->writeln('}')
;
}
foreach ($this->taskDef['args'] as $node) {
$node->compile($buffer);
}
foreach ($this->taskDef['opts'] as $node) {
$node->compile($buffer);
}
foreach ($this->taskDef['set'] as $node) {
$node->compile($buffer);
}
$buffer->writeln('$skip = false;');
foreach (array('pre', 'do', 'post') as $scope) {
if ($scope === 'do') {
if (!empty($this->taskDef['unless'])) {
$buffer->write('if (!$z->resolve(\'FORCE\') &&');
$this->taskDef['unless']->compile($buffer);
$buffer->raw(') {')->eol()->indent(1);
$echoStr = sprintf('echo "%s skipped", because \'unless\' evaluated to true.', join('.', $this->path));
$buffer->writeln(sprintf('$z->cmd(%s);', Util::toPhp($echoStr)));
$buffer->writeln('$skip = true;');
$buffer->indent(-1);
$buffer->writeln('}');
}
if (!empty($this->taskDef['if'])) {
$buffer->write('if (!$z->resolve(\'FORCE\') && !(');
$this->taskDef['if']->compile($buffer);
$buffer->raw(') ) {')->eol()->indent(1);
$echoStr = sprintf('echo "%s skipped", because \'if\' evaluated to false.', join('.', $this->path));
$buffer->writeln(sprintf('$z->cmd(%s);', Util::toPhp($echoStr)));
$buffer->writeln('$skip = true;');
$buffer->indent(-1);
$buffer->writeln('}');
}
if (!empty($this->taskDef['assert'])) {
$buffer->write('if (!(');
$this->taskDef['assert']->compile($buffer);
$buffer->raw(')) {')->eol()->indent(1);
$buffer->writeln('throw new \RuntimeException("Assertion failed");');
$buffer->indent(-1)->writeln('}');
}
$buffer->writeln('if (!$skip) {');
$buffer->indent(1);
}
foreach ($this->taskDef[$scope] as $i => $cmd) {
$buffer->write('Debug::enterScope(')->asPhp($scope . '[' . $i . ']')->raw(');')->eol();
if ($cmd) {
$cmd->compile($buffer);
}
$buffer->write('Debug::exitScope(')->asPhp($scope . '[' . $i . ']')->raw(');')->eol();
}
if ($scope === 'post') {
$buffer->indent(-1);
$buffer->writeln('}');
}
}
if (!empty($this->taskDef['yield'])) {
$buffer->writeln('$ret = ');
$this->taskDef['yield']->compile($buffer);
$buffer->write(';');
}
$buffer->writeln('return $ret;');
} | php | public function compileBody(Buffer $buffer)
{
$buffer->writeln('$ret = null;');
foreach ($this->taskDef['flags'] as $flag => $value) {
$buffer
->write('if (null === $z->resolve(')->asPhp($flag)->raw(', false)) {')->eol()
->indent(1)
->write('$z->set(')->asPhp($flag)->raw(', ')->asPhp($value)->raw(');')->eol()
->indent(-1)
->writeln('}')
;
}
foreach ($this->taskDef['args'] as $node) {
$node->compile($buffer);
}
foreach ($this->taskDef['opts'] as $node) {
$node->compile($buffer);
}
foreach ($this->taskDef['set'] as $node) {
$node->compile($buffer);
}
$buffer->writeln('$skip = false;');
foreach (array('pre', 'do', 'post') as $scope) {
if ($scope === 'do') {
if (!empty($this->taskDef['unless'])) {
$buffer->write('if (!$z->resolve(\'FORCE\') &&');
$this->taskDef['unless']->compile($buffer);
$buffer->raw(') {')->eol()->indent(1);
$echoStr = sprintf('echo "%s skipped", because \'unless\' evaluated to true.', join('.', $this->path));
$buffer->writeln(sprintf('$z->cmd(%s);', Util::toPhp($echoStr)));
$buffer->writeln('$skip = true;');
$buffer->indent(-1);
$buffer->writeln('}');
}
if (!empty($this->taskDef['if'])) {
$buffer->write('if (!$z->resolve(\'FORCE\') && !(');
$this->taskDef['if']->compile($buffer);
$buffer->raw(') ) {')->eol()->indent(1);
$echoStr = sprintf('echo "%s skipped", because \'if\' evaluated to false.', join('.', $this->path));
$buffer->writeln(sprintf('$z->cmd(%s);', Util::toPhp($echoStr)));
$buffer->writeln('$skip = true;');
$buffer->indent(-1);
$buffer->writeln('}');
}
if (!empty($this->taskDef['assert'])) {
$buffer->write('if (!(');
$this->taskDef['assert']->compile($buffer);
$buffer->raw(')) {')->eol()->indent(1);
$buffer->writeln('throw new \RuntimeException("Assertion failed");');
$buffer->indent(-1)->writeln('}');
}
$buffer->writeln('if (!$skip) {');
$buffer->indent(1);
}
foreach ($this->taskDef[$scope] as $i => $cmd) {
$buffer->write('Debug::enterScope(')->asPhp($scope . '[' . $i . ']')->raw(');')->eol();
if ($cmd) {
$cmd->compile($buffer);
}
$buffer->write('Debug::exitScope(')->asPhp($scope . '[' . $i . ']')->raw(');')->eol();
}
if ($scope === 'post') {
$buffer->indent(-1);
$buffer->writeln('}');
}
}
if (!empty($this->taskDef['yield'])) {
$buffer->writeln('$ret = ');
$this->taskDef['yield']->compile($buffer);
$buffer->write(';');
}
$buffer->writeln('return $ret;');
} | [
"public",
"function",
"compileBody",
"(",
"Buffer",
"$",
"buffer",
")",
"{",
"$",
"buffer",
"->",
"writeln",
"(",
"'$ret = null;'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'flags'",
"]",
"as",
"$",
"flag",
"=>",
"$",
"value",
")",
"{",
"$",
"buffer",
"->",
"write",
"(",
"'if (null === $z->resolve('",
")",
"->",
"asPhp",
"(",
"$",
"flag",
")",
"->",
"raw",
"(",
"', false)) {'",
")",
"->",
"eol",
"(",
")",
"->",
"indent",
"(",
"1",
")",
"->",
"write",
"(",
"'$z->set('",
")",
"->",
"asPhp",
"(",
"$",
"flag",
")",
"->",
"raw",
"(",
"', '",
")",
"->",
"asPhp",
"(",
"$",
"value",
")",
"->",
"raw",
"(",
"');'",
")",
"->",
"eol",
"(",
")",
"->",
"indent",
"(",
"-",
"1",
")",
"->",
"writeln",
"(",
"'}'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'args'",
"]",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'opts'",
"]",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'set'",
"]",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"}",
"$",
"buffer",
"->",
"writeln",
"(",
"'$skip = false;'",
")",
";",
"foreach",
"(",
"array",
"(",
"'pre'",
",",
"'do'",
",",
"'post'",
")",
"as",
"$",
"scope",
")",
"{",
"if",
"(",
"$",
"scope",
"===",
"'do'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'unless'",
"]",
")",
")",
"{",
"$",
"buffer",
"->",
"write",
"(",
"'if (!$z->resolve(\\'FORCE\\') &&'",
")",
";",
"$",
"this",
"->",
"taskDef",
"[",
"'unless'",
"]",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"$",
"buffer",
"->",
"raw",
"(",
"') {'",
")",
"->",
"eol",
"(",
")",
"->",
"indent",
"(",
"1",
")",
";",
"$",
"echoStr",
"=",
"sprintf",
"(",
"'echo \"%s skipped\", because \\'unless\\' evaluated to true.'",
",",
"join",
"(",
"'.'",
",",
"$",
"this",
"->",
"path",
")",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"sprintf",
"(",
"'$z->cmd(%s);'",
",",
"Util",
"::",
"toPhp",
"(",
"$",
"echoStr",
")",
")",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"'$skip = true;'",
")",
";",
"$",
"buffer",
"->",
"indent",
"(",
"-",
"1",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"'}'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'if'",
"]",
")",
")",
"{",
"$",
"buffer",
"->",
"write",
"(",
"'if (!$z->resolve(\\'FORCE\\') && !('",
")",
";",
"$",
"this",
"->",
"taskDef",
"[",
"'if'",
"]",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"$",
"buffer",
"->",
"raw",
"(",
"') ) {'",
")",
"->",
"eol",
"(",
")",
"->",
"indent",
"(",
"1",
")",
";",
"$",
"echoStr",
"=",
"sprintf",
"(",
"'echo \"%s skipped\", because \\'if\\' evaluated to false.'",
",",
"join",
"(",
"'.'",
",",
"$",
"this",
"->",
"path",
")",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"sprintf",
"(",
"'$z->cmd(%s);'",
",",
"Util",
"::",
"toPhp",
"(",
"$",
"echoStr",
")",
")",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"'$skip = true;'",
")",
";",
"$",
"buffer",
"->",
"indent",
"(",
"-",
"1",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"'}'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'assert'",
"]",
")",
")",
"{",
"$",
"buffer",
"->",
"write",
"(",
"'if (!('",
")",
";",
"$",
"this",
"->",
"taskDef",
"[",
"'assert'",
"]",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"$",
"buffer",
"->",
"raw",
"(",
"')) {'",
")",
"->",
"eol",
"(",
")",
"->",
"indent",
"(",
"1",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"'throw new \\RuntimeException(\"Assertion failed\");'",
")",
";",
"$",
"buffer",
"->",
"indent",
"(",
"-",
"1",
")",
"->",
"writeln",
"(",
"'}'",
")",
";",
"}",
"$",
"buffer",
"->",
"writeln",
"(",
"'if (!$skip) {'",
")",
";",
"$",
"buffer",
"->",
"indent",
"(",
"1",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"$",
"scope",
"]",
"as",
"$",
"i",
"=>",
"$",
"cmd",
")",
"{",
"$",
"buffer",
"->",
"write",
"(",
"'Debug::enterScope('",
")",
"->",
"asPhp",
"(",
"$",
"scope",
".",
"'['",
".",
"$",
"i",
".",
"']'",
")",
"->",
"raw",
"(",
"');'",
")",
"->",
"eol",
"(",
")",
";",
"if",
"(",
"$",
"cmd",
")",
"{",
"$",
"cmd",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"}",
"$",
"buffer",
"->",
"write",
"(",
"'Debug::exitScope('",
")",
"->",
"asPhp",
"(",
"$",
"scope",
".",
"'['",
".",
"$",
"i",
".",
"']'",
")",
"->",
"raw",
"(",
"');'",
")",
"->",
"eol",
"(",
")",
";",
"}",
"if",
"(",
"$",
"scope",
"===",
"'post'",
")",
"{",
"$",
"buffer",
"->",
"indent",
"(",
"-",
"1",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"'}'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'yield'",
"]",
")",
")",
"{",
"$",
"buffer",
"->",
"writeln",
"(",
"'$ret = '",
")",
";",
"$",
"this",
"->",
"taskDef",
"[",
"'yield'",
"]",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"$",
"buffer",
"->",
"write",
"(",
"';'",
")",
";",
"}",
"$",
"buffer",
"->",
"writeln",
"(",
"'return $ret;'",
")",
";",
"}"
] | Compile the node
@param Buffer $buffer
@return void | [
"Compile",
"the",
"node"
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/Task.php#L102-L178 |
zicht/z | src/Zicht/Tool/Container/Task.php | Task.getArguments | public function getArguments($onlyPublic = true)
{
$ret = array();
if (isset($this->taskDef['args'])) {
foreach ($this->taskDef['args'] as $name => $expr) {
if ($onlyPublic && $name{0} === '_') {
// Variables prefixed with an underscore are considered non public
continue;
}
if ($expr->conditional) {
// if the part after the question mark is empty, the variable is assumed to be required
// for execution of the task
$ret[$name] = ($expr->nodes[0] === null);
}
}
}
return $ret;
} | php | public function getArguments($onlyPublic = true)
{
$ret = array();
if (isset($this->taskDef['args'])) {
foreach ($this->taskDef['args'] as $name => $expr) {
if ($onlyPublic && $name{0} === '_') {
// Variables prefixed with an underscore are considered non public
continue;
}
if ($expr->conditional) {
// if the part after the question mark is empty, the variable is assumed to be required
// for execution of the task
$ret[$name] = ($expr->nodes[0] === null);
}
}
}
return $ret;
} | [
"public",
"function",
"getArguments",
"(",
"$",
"onlyPublic",
"=",
"true",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'args'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'args'",
"]",
"as",
"$",
"name",
"=>",
"$",
"expr",
")",
"{",
"if",
"(",
"$",
"onlyPublic",
"&&",
"$",
"name",
"{",
"0",
"}",
"===",
"'_'",
")",
"{",
"// Variables prefixed with an underscore are considered non public",
"continue",
";",
"}",
"if",
"(",
"$",
"expr",
"->",
"conditional",
")",
"{",
"// if the part after the question mark is empty, the variable is assumed to be required",
"// for execution of the task",
"$",
"ret",
"[",
"$",
"name",
"]",
"=",
"(",
"$",
"expr",
"->",
"nodes",
"[",
"0",
"]",
"===",
"null",
")",
";",
"}",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Returns all variables that can be injected into the task.
@param bool $onlyPublic
@return array | [
"Returns",
"all",
"variables",
"that",
"can",
"be",
"injected",
"into",
"the",
"task",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/Task.php#L187-L204 |
zicht/z | src/Zicht/Tool/Container/Task.php | Task.getOptions | public function getOptions()
{
$ret = array();
if (!empty($this->taskDef['opts'])) {
foreach ($this->taskDef['opts'] as $opt) {
$ret[] = $opt->name;
}
}
return $ret;
} | php | public function getOptions()
{
$ret = array();
if (!empty($this->taskDef['opts'])) {
foreach ($this->taskDef['opts'] as $opt) {
$ret[] = $opt->name;
}
}
return $ret;
} | [
"public",
"function",
"getOptions",
"(",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'opts'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"taskDef",
"[",
"'opts'",
"]",
"as",
"$",
"opt",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"opt",
"->",
"name",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Returns all variables that can be injected into the task.
@return array | [
"Returns",
"all",
"variables",
"that",
"can",
"be",
"injected",
"into",
"the",
"task",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/Task.php#L211-L220 |
heidelpay/PhpDoc | src/phpDocumentor/Compiler/Pass/PackageTreeBuilder.php | PackageTreeBuilder.execute | public function execute(ProjectDescriptor $project)
{
$rootPackageDescriptor = new PackageDescriptor();
$rootPackageDescriptor->setName('\\');
$project->getIndexes()->set('packages', new Collection());
$project->getIndexes()->packages['\\'] = $rootPackageDescriptor;
foreach ($project->getFiles() as $file) {
$this->addElementsOfTypeToPackage($project, array($file), 'files');
$this->addElementsOfTypeToPackage($project, $file->getConstants()->getAll(), 'constants');
$this->addElementsOfTypeToPackage($project, $file->getFunctions()->getAll(), 'functions');
$this->addElementsOfTypeToPackage($project, $file->getClasses()->getAll(), 'classes');
$this->addElementsOfTypeToPackage($project, $file->getInterfaces()->getAll(), 'interfaces');
$this->addElementsOfTypeToPackage($project, $file->getTraits()->getAll(), 'traits');
}
} | php | public function execute(ProjectDescriptor $project)
{
$rootPackageDescriptor = new PackageDescriptor();
$rootPackageDescriptor->setName('\\');
$project->getIndexes()->set('packages', new Collection());
$project->getIndexes()->packages['\\'] = $rootPackageDescriptor;
foreach ($project->getFiles() as $file) {
$this->addElementsOfTypeToPackage($project, array($file), 'files');
$this->addElementsOfTypeToPackage($project, $file->getConstants()->getAll(), 'constants');
$this->addElementsOfTypeToPackage($project, $file->getFunctions()->getAll(), 'functions');
$this->addElementsOfTypeToPackage($project, $file->getClasses()->getAll(), 'classes');
$this->addElementsOfTypeToPackage($project, $file->getInterfaces()->getAll(), 'interfaces');
$this->addElementsOfTypeToPackage($project, $file->getTraits()->getAll(), 'traits');
}
} | [
"public",
"function",
"execute",
"(",
"ProjectDescriptor",
"$",
"project",
")",
"{",
"$",
"rootPackageDescriptor",
"=",
"new",
"PackageDescriptor",
"(",
")",
";",
"$",
"rootPackageDescriptor",
"->",
"setName",
"(",
"'\\\\'",
")",
";",
"$",
"project",
"->",
"getIndexes",
"(",
")",
"->",
"set",
"(",
"'packages'",
",",
"new",
"Collection",
"(",
")",
")",
";",
"$",
"project",
"->",
"getIndexes",
"(",
")",
"->",
"packages",
"[",
"'\\\\'",
"]",
"=",
"$",
"rootPackageDescriptor",
";",
"foreach",
"(",
"$",
"project",
"->",
"getFiles",
"(",
")",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"addElementsOfTypeToPackage",
"(",
"$",
"project",
",",
"array",
"(",
"$",
"file",
")",
",",
"'files'",
")",
";",
"$",
"this",
"->",
"addElementsOfTypeToPackage",
"(",
"$",
"project",
",",
"$",
"file",
"->",
"getConstants",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"'constants'",
")",
";",
"$",
"this",
"->",
"addElementsOfTypeToPackage",
"(",
"$",
"project",
",",
"$",
"file",
"->",
"getFunctions",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"'functions'",
")",
";",
"$",
"this",
"->",
"addElementsOfTypeToPackage",
"(",
"$",
"project",
",",
"$",
"file",
"->",
"getClasses",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"'classes'",
")",
";",
"$",
"this",
"->",
"addElementsOfTypeToPackage",
"(",
"$",
"project",
",",
"$",
"file",
"->",
"getInterfaces",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"'interfaces'",
")",
";",
"$",
"this",
"->",
"addElementsOfTypeToPackage",
"(",
"$",
"project",
",",
"$",
"file",
"->",
"getTraits",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"'traits'",
")",
";",
"}",
"}"
] | Compiles a 'packages' index on the project and create all Package Descriptors necessary.
@param ProjectDescriptor $project
@return void | [
"Compiles",
"a",
"packages",
"index",
"on",
"the",
"project",
"and",
"create",
"all",
"Package",
"Descriptors",
"necessary",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Pass/PackageTreeBuilder.php#L49-L64 |
heidelpay/PhpDoc | src/phpDocumentor/Compiler/Pass/PackageTreeBuilder.php | PackageTreeBuilder.addElementsOfTypeToPackage | protected function addElementsOfTypeToPackage(ProjectDescriptor $project, array $elements, $type)
{
/** @var DescriptorAbstract $element */
foreach ($elements as $element) {
$packageName = '';
$packageTags = $element->getTags()->get('package');
if ($packageTags instanceof Collection) {
$packageTag = $packageTags->getIterator()->current();
if ($packageTag instanceof TagDescriptor) {
$packageName = $packageTag->getDescription();
}
}
$subpackageCollection = $element->getTags()->get('subpackage');
if ($subpackageCollection instanceof Collection && $subpackageCollection->count() > 0) {
$subpackageTag = $subpackageCollection->getIterator()->current();
if ($subpackageTag instanceof TagDescriptor) {
$packageName .= '\\' . $subpackageTag->getDescription();
}
}
// ensure consistency by trimming the slash prefix and then re-appending it.
$packageIndexName = '\\' . ltrim($packageName, '\\');
if (!isset($project->getIndexes()->packages[$packageIndexName])) {
$this->createPackageDescriptorTree($project, $packageName);
}
/** @var PackageDescriptor $package */
$package = $project->getIndexes()->packages[$packageIndexName];
// replace textual representation with an object representation
$element->setPackage($package);
// add element to package
$getter = 'get'.ucfirst($type);
/** @var Collection $collection */
$collection = $package->$getter();
$collection->add($element);
}
} | php | protected function addElementsOfTypeToPackage(ProjectDescriptor $project, array $elements, $type)
{
/** @var DescriptorAbstract $element */
foreach ($elements as $element) {
$packageName = '';
$packageTags = $element->getTags()->get('package');
if ($packageTags instanceof Collection) {
$packageTag = $packageTags->getIterator()->current();
if ($packageTag instanceof TagDescriptor) {
$packageName = $packageTag->getDescription();
}
}
$subpackageCollection = $element->getTags()->get('subpackage');
if ($subpackageCollection instanceof Collection && $subpackageCollection->count() > 0) {
$subpackageTag = $subpackageCollection->getIterator()->current();
if ($subpackageTag instanceof TagDescriptor) {
$packageName .= '\\' . $subpackageTag->getDescription();
}
}
// ensure consistency by trimming the slash prefix and then re-appending it.
$packageIndexName = '\\' . ltrim($packageName, '\\');
if (!isset($project->getIndexes()->packages[$packageIndexName])) {
$this->createPackageDescriptorTree($project, $packageName);
}
/** @var PackageDescriptor $package */
$package = $project->getIndexes()->packages[$packageIndexName];
// replace textual representation with an object representation
$element->setPackage($package);
// add element to package
$getter = 'get'.ucfirst($type);
/** @var Collection $collection */
$collection = $package->$getter();
$collection->add($element);
}
} | [
"protected",
"function",
"addElementsOfTypeToPackage",
"(",
"ProjectDescriptor",
"$",
"project",
",",
"array",
"$",
"elements",
",",
"$",
"type",
")",
"{",
"/** @var DescriptorAbstract $element */",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"packageName",
"=",
"''",
";",
"$",
"packageTags",
"=",
"$",
"element",
"->",
"getTags",
"(",
")",
"->",
"get",
"(",
"'package'",
")",
";",
"if",
"(",
"$",
"packageTags",
"instanceof",
"Collection",
")",
"{",
"$",
"packageTag",
"=",
"$",
"packageTags",
"->",
"getIterator",
"(",
")",
"->",
"current",
"(",
")",
";",
"if",
"(",
"$",
"packageTag",
"instanceof",
"TagDescriptor",
")",
"{",
"$",
"packageName",
"=",
"$",
"packageTag",
"->",
"getDescription",
"(",
")",
";",
"}",
"}",
"$",
"subpackageCollection",
"=",
"$",
"element",
"->",
"getTags",
"(",
")",
"->",
"get",
"(",
"'subpackage'",
")",
";",
"if",
"(",
"$",
"subpackageCollection",
"instanceof",
"Collection",
"&&",
"$",
"subpackageCollection",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"subpackageTag",
"=",
"$",
"subpackageCollection",
"->",
"getIterator",
"(",
")",
"->",
"current",
"(",
")",
";",
"if",
"(",
"$",
"subpackageTag",
"instanceof",
"TagDescriptor",
")",
"{",
"$",
"packageName",
".=",
"'\\\\'",
".",
"$",
"subpackageTag",
"->",
"getDescription",
"(",
")",
";",
"}",
"}",
"// ensure consistency by trimming the slash prefix and then re-appending it.",
"$",
"packageIndexName",
"=",
"'\\\\'",
".",
"ltrim",
"(",
"$",
"packageName",
",",
"'\\\\'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"project",
"->",
"getIndexes",
"(",
")",
"->",
"packages",
"[",
"$",
"packageIndexName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"createPackageDescriptorTree",
"(",
"$",
"project",
",",
"$",
"packageName",
")",
";",
"}",
"/** @var PackageDescriptor $package */",
"$",
"package",
"=",
"$",
"project",
"->",
"getIndexes",
"(",
")",
"->",
"packages",
"[",
"$",
"packageIndexName",
"]",
";",
"// replace textual representation with an object representation",
"$",
"element",
"->",
"setPackage",
"(",
"$",
"package",
")",
";",
"// add element to package",
"$",
"getter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"type",
")",
";",
"/** @var Collection $collection */",
"$",
"collection",
"=",
"$",
"package",
"->",
"$",
"getter",
"(",
")",
";",
"$",
"collection",
"->",
"add",
"(",
"$",
"element",
")",
";",
"}",
"}"
] | Adds the given elements of a specific type to their respective Package Descriptors.
This method will assign the given elements to the package as registered in the package field of that
element. If a package does not exist yet it will automatically be created.
@param ProjectDescriptor $project
@param DescriptorAbstract[] $elements Series of elements to add to their respective package.
@param string $type Declares which field of the package will be populated with the given
series of elements. This name will be transformed to a getter which must exist. Out of performance
considerations will no effort be done to verify whether the provided type is valid.
@return void | [
"Adds",
"the",
"given",
"elements",
"of",
"a",
"specific",
"type",
"to",
"their",
"respective",
"Package",
"Descriptors",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Pass/PackageTreeBuilder.php#L80-L120 |
platformsh/platformsh-oauth2-php | src/Provider/Platformsh.php | Platformsh.checkResponse | protected function checkResponse(ResponseInterface $response, $data)
{
if (!empty($data['error'])) {
$message = !empty($data['error_description']) ? $data['error_description'] : $data['error'];
if ($this->requiresTfa($response)) {
throw new TfaRequiredException($message);
}
throw new IdentityProviderException($message, 0, $data);
}
} | php | protected function checkResponse(ResponseInterface $response, $data)
{
if (!empty($data['error'])) {
$message = !empty($data['error_description']) ? $data['error_description'] : $data['error'];
if ($this->requiresTfa($response)) {
throw new TfaRequiredException($message);
}
throw new IdentityProviderException($message, 0, $data);
}
} | [
"protected",
"function",
"checkResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'error'",
"]",
")",
")",
"{",
"$",
"message",
"=",
"!",
"empty",
"(",
"$",
"data",
"[",
"'error_description'",
"]",
")",
"?",
"$",
"data",
"[",
"'error_description'",
"]",
":",
"$",
"data",
"[",
"'error'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"requiresTfa",
"(",
"$",
"response",
")",
")",
"{",
"throw",
"new",
"TfaRequiredException",
"(",
"$",
"message",
")",
";",
"}",
"throw",
"new",
"IdentityProviderException",
"(",
"$",
"message",
",",
"0",
",",
"$",
"data",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/platformsh/platformsh-oauth2-php/blob/c5056b818f326e8ee358521224ac7f803d1e9d6b/src/Provider/Platformsh.php#L73-L82 |
platformsh/platformsh-oauth2-php | src/Provider/Platformsh.php | Platformsh.getAccessToken | public function getAccessToken($grant, array $options = [])
{
$grant = $this->verifyGrant($grant);
$params = [
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'redirect_uri' => $this->redirectUri,
];
$params = $grant->prepareRequestParameters($params, $options);
// Modify the request for TFA (two-factor authentication) support.
$request = $this->getAccessTokenRequest($params);
if ($grant->__toString() === 'password' && isset($options['totp'])) {
$request = $request->withHeader(self::TFA_HEADER, $options['totp']);
}
$response = $this->getParsedResponse($request);
$prepared = $this->prepareAccessTokenResponse($response);
return $this->createAccessToken($prepared, $grant);
} | php | public function getAccessToken($grant, array $options = [])
{
$grant = $this->verifyGrant($grant);
$params = [
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'redirect_uri' => $this->redirectUri,
];
$params = $grant->prepareRequestParameters($params, $options);
// Modify the request for TFA (two-factor authentication) support.
$request = $this->getAccessTokenRequest($params);
if ($grant->__toString() === 'password' && isset($options['totp'])) {
$request = $request->withHeader(self::TFA_HEADER, $options['totp']);
}
$response = $this->getParsedResponse($request);
$prepared = $this->prepareAccessTokenResponse($response);
return $this->createAccessToken($prepared, $grant);
} | [
"public",
"function",
"getAccessToken",
"(",
"$",
"grant",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"grant",
"=",
"$",
"this",
"->",
"verifyGrant",
"(",
"$",
"grant",
")",
";",
"$",
"params",
"=",
"[",
"'client_id'",
"=>",
"$",
"this",
"->",
"clientId",
",",
"'client_secret'",
"=>",
"$",
"this",
"->",
"clientSecret",
",",
"'redirect_uri'",
"=>",
"$",
"this",
"->",
"redirectUri",
",",
"]",
";",
"$",
"params",
"=",
"$",
"grant",
"->",
"prepareRequestParameters",
"(",
"$",
"params",
",",
"$",
"options",
")",
";",
"// Modify the request for TFA (two-factor authentication) support.",
"$",
"request",
"=",
"$",
"this",
"->",
"getAccessTokenRequest",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"grant",
"->",
"__toString",
"(",
")",
"===",
"'password'",
"&&",
"isset",
"(",
"$",
"options",
"[",
"'totp'",
"]",
")",
")",
"{",
"$",
"request",
"=",
"$",
"request",
"->",
"withHeader",
"(",
"self",
"::",
"TFA_HEADER",
",",
"$",
"options",
"[",
"'totp'",
"]",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getParsedResponse",
"(",
"$",
"request",
")",
";",
"$",
"prepared",
"=",
"$",
"this",
"->",
"prepareAccessTokenResponse",
"(",
"$",
"response",
")",
";",
"return",
"$",
"this",
"->",
"createAccessToken",
"(",
"$",
"prepared",
",",
"$",
"grant",
")",
";",
"}"
] | {@inheritdoc}
The option 'totp' can be provided for two-factor authentication. | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/platformsh/platformsh-oauth2-php/blob/c5056b818f326e8ee358521224ac7f803d1e9d6b/src/Provider/Platformsh.php#L97-L119 |
platformsh/platformsh-oauth2-php | src/Provider/Platformsh.php | Platformsh.requiresTfa | private function requiresTfa(ResponseInterface $response)
{
return substr($response->getStatusCode(), 0, 1) === '4' && $response->hasHeader(self::TFA_HEADER);
} | php | private function requiresTfa(ResponseInterface $response)
{
return substr($response->getStatusCode(), 0, 1) === '4' && $response->hasHeader(self::TFA_HEADER);
} | [
"private",
"function",
"requiresTfa",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"return",
"substr",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"0",
",",
"1",
")",
"===",
"'4'",
"&&",
"$",
"response",
"->",
"hasHeader",
"(",
"self",
"::",
"TFA_HEADER",
")",
";",
"}"
] | Check whether the response requires two-factor authentication.
@param \Psr\Http\Message\ResponseInterface $response
@return bool | [
"Check",
"whether",
"the",
"response",
"requires",
"two",
"-",
"factor",
"authentication",
"."
] | train | https://github.com/platformsh/platformsh-oauth2-php/blob/c5056b818f326e8ee358521224ac7f803d1e9d6b/src/Provider/Platformsh.php#L128-L131 |
maestroprog/saw-php | src/Standalone/Worker/WorkerThreadRunner.php | WorkerThreadRunner.runThreads | public function runThreads(array $threads): bool
{
if (!$this->disabled) {
foreach ($threads as $thread) {
$this->runThreadPool->add($thread);
try {
$this->commander->runAsync(new ThreadRun(
$this->client,
$thread->getId(),
$thread->getApplicationId(),
$thread->getUniqueId(),
$thread->getArguments()
));
} catch (\Throwable $e) {
$thread->run();
Log::log($e->getMessage());
}
}
} else {
$this->enable();
}
return true;
} | php | public function runThreads(array $threads): bool
{
if (!$this->disabled) {
foreach ($threads as $thread) {
$this->runThreadPool->add($thread);
try {
$this->commander->runAsync(new ThreadRun(
$this->client,
$thread->getId(),
$thread->getApplicationId(),
$thread->getUniqueId(),
$thread->getArguments()
));
} catch (\Throwable $e) {
$thread->run();
Log::log($e->getMessage());
}
}
} else {
$this->enable();
}
return true;
} | [
"public",
"function",
"runThreads",
"(",
"array",
"$",
"threads",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"disabled",
")",
"{",
"foreach",
"(",
"$",
"threads",
"as",
"$",
"thread",
")",
"{",
"$",
"this",
"->",
"runThreadPool",
"->",
"add",
"(",
"$",
"thread",
")",
";",
"try",
"{",
"$",
"this",
"->",
"commander",
"->",
"runAsync",
"(",
"new",
"ThreadRun",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"thread",
"->",
"getId",
"(",
")",
",",
"$",
"thread",
"->",
"getApplicationId",
"(",
")",
",",
"$",
"thread",
"->",
"getUniqueId",
"(",
")",
",",
"$",
"thread",
"->",
"getArguments",
"(",
")",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"thread",
"->",
"run",
"(",
")",
";",
"Log",
"::",
"log",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"enable",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Воркер не должен запускать потоки из приложения.
Метод нужен для совместимости работы приложений из скрипта и на воркерах.
@param AbstractThread[] $threads
@return bool | [
"Воркер",
"не",
"должен",
"запускать",
"потоки",
"из",
"приложения",
".",
"Метод",
"нужен",
"для",
"совместимости",
"работы",
"приложений",
"из",
"скрипта",
"и",
"на",
"воркерах",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Standalone/Worker/WorkerThreadRunner.php#L63-L86 |
surebert/surebert-framework | src/sb/Controller/HTTP.php | HTTP.unsetCookie | public function unsetCookie($name, $path = '/')
{
setcookie($name, '', time() - 86400, '/', '', 0);
if (isset($_COOKIE) && isset($_COOKIE[$name])) {
unset($_COOKIE[$name]);
}
if (isset($this->request->cookie[$name])) {
unset($this->request->cookie[$name]);
}
} | php | public function unsetCookie($name, $path = '/')
{
setcookie($name, '', time() - 86400, '/', '', 0);
if (isset($_COOKIE) && isset($_COOKIE[$name])) {
unset($_COOKIE[$name]);
}
if (isset($this->request->cookie[$name])) {
unset($this->request->cookie[$name]);
}
} | [
"public",
"function",
"unsetCookie",
"(",
"$",
"name",
",",
"$",
"path",
"=",
"'/'",
")",
"{",
"setcookie",
"(",
"$",
"name",
",",
"''",
",",
"time",
"(",
")",
"-",
"86400",
",",
"'/'",
",",
"''",
",",
"0",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_COOKIE",
")",
"&&",
"isset",
"(",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"request",
"->",
"cookie",
"[",
"$",
"name",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"request",
"->",
"cookie",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}"
] | Unsets a cookie value by setting it to expire
@param string $name The cookie name
@param string path The path to clear, defaults to / | [
"Unsets",
"a",
"cookie",
"value",
"by",
"setting",
"it",
"to",
"expire"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/HTTP.php#L79-L88 |
surebert/surebert-framework | src/sb/Controller/HTTP.php | HTTP.sendError | public function sendError($error_num, $err_str = '')
{
if (empty($err_str)) {
switch ($error_num) {
case 400:
$err_str = 'Bad Request';
break;
case 401:
$err_str = 'Unauthorized';
break;
case 403:
$err_str = 'Forbidden';
break;
case 404:
$err_str = 'Not Found';
break;
case 405:
$err_str = 'Method Not Allowed';
break;
case 410:
$err_str = 'Gone';
break;
case 415:
$err_str = 'Unsupported Media Type';
break;
case 500:
$err_str = 'Internal Server Error';
break;
case 501:
$err_str = 'Not Implemented';
break;
}
}
$this->sendHeader("HTTP/1.0 $error_num $err_str");
} | php | public function sendError($error_num, $err_str = '')
{
if (empty($err_str)) {
switch ($error_num) {
case 400:
$err_str = 'Bad Request';
break;
case 401:
$err_str = 'Unauthorized';
break;
case 403:
$err_str = 'Forbidden';
break;
case 404:
$err_str = 'Not Found';
break;
case 405:
$err_str = 'Method Not Allowed';
break;
case 410:
$err_str = 'Gone';
break;
case 415:
$err_str = 'Unsupported Media Type';
break;
case 500:
$err_str = 'Internal Server Error';
break;
case 501:
$err_str = 'Not Implemented';
break;
}
}
$this->sendHeader("HTTP/1.0 $error_num $err_str");
} | [
"public",
"function",
"sendError",
"(",
"$",
"error_num",
",",
"$",
"err_str",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"err_str",
")",
")",
"{",
"switch",
"(",
"$",
"error_num",
")",
"{",
"case",
"400",
":",
"$",
"err_str",
"=",
"'Bad Request'",
";",
"break",
";",
"case",
"401",
":",
"$",
"err_str",
"=",
"'Unauthorized'",
";",
"break",
";",
"case",
"403",
":",
"$",
"err_str",
"=",
"'Forbidden'",
";",
"break",
";",
"case",
"404",
":",
"$",
"err_str",
"=",
"'Not Found'",
";",
"break",
";",
"case",
"405",
":",
"$",
"err_str",
"=",
"'Method Not Allowed'",
";",
"break",
";",
"case",
"410",
":",
"$",
"err_str",
"=",
"'Gone'",
";",
"break",
";",
"case",
"415",
":",
"$",
"err_str",
"=",
"'Unsupported Media Type'",
";",
"break",
";",
"case",
"500",
":",
"$",
"err_str",
"=",
"'Internal Server Error'",
";",
"break",
";",
"case",
"501",
":",
"$",
"err_str",
"=",
"'Not Implemented'",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"sendHeader",
"(",
"\"HTTP/1.0 $error_num $err_str\"",
")",
";",
"}"
] | Send an http error header
@param integer $error_num The number of the error as found http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
@param string $err_str The error string to send, defaults sent for
400, 401, 403, 404, 405, 410, 415, 500, 501 unless specified | [
"Send",
"an",
"http",
"error",
"header"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/HTTP.php#L119-L162 |
surebert/surebert-framework | src/sb/Controller/HTTP.php | HTTP.requireBasicAuth | public function requireBasicAuth($check_auth = '', $realm = 'Please enter your username and password')
{
$authorized = false;
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="' . $realm . '"');
header('HTTP/1.0 401 Unauthorized');
echo 'You must authenticate to continue';
} else {
if (is_callable($check_auth)) {
$authorized = $check_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
}
if (!$authorized) {
session_unset();
unset($_SERVER['PHP_AUTH_USER']);
return $this->requireBasicAuth($check_auth, $realm);
}
}
return $authorized;
} | php | public function requireBasicAuth($check_auth = '', $realm = 'Please enter your username and password')
{
$authorized = false;
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="' . $realm . '"');
header('HTTP/1.0 401 Unauthorized');
echo 'You must authenticate to continue';
} else {
if (is_callable($check_auth)) {
$authorized = $check_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
}
if (!$authorized) {
session_unset();
unset($_SERVER['PHP_AUTH_USER']);
return $this->requireBasicAuth($check_auth, $realm);
}
}
return $authorized;
} | [
"public",
"function",
"requireBasicAuth",
"(",
"$",
"check_auth",
"=",
"''",
",",
"$",
"realm",
"=",
"'Please enter your username and password'",
")",
"{",
"$",
"authorized",
"=",
"false",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
")",
")",
"{",
"header",
"(",
"'WWW-Authenticate: Basic realm=\"'",
".",
"$",
"realm",
".",
"'\"'",
")",
";",
"header",
"(",
"'HTTP/1.0 401 Unauthorized'",
")",
";",
"echo",
"'You must authenticate to continue'",
";",
"}",
"else",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"check_auth",
")",
")",
"{",
"$",
"authorized",
"=",
"$",
"check_auth",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
",",
"$",
"_SERVER",
"[",
"'PHP_AUTH_PW'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"authorized",
")",
"{",
"session_unset",
"(",
")",
";",
"unset",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"requireBasicAuth",
"(",
"$",
"check_auth",
",",
"$",
"realm",
")",
";",
"}",
"}",
"return",
"$",
"authorized",
";",
"}"
] | Added option for requesting basic auth. ONLY USE OVER SSL
@param callable $check_auth the callable that determines success or not
@param string $realm the realm beings used
@return boolean | [
"Added",
"option",
"for",
"requesting",
"basic",
"auth",
".",
"ONLY",
"USE",
"OVER",
"SSL"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/HTTP.php#L295-L317 |
php-lug/lug | src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php | ResourceConfiguration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = $this->createTreeBuilder();
$children = $treeBuilder->root($this->bundle->getAlias())->children();
$this->configureBundle($children);
$children->append($this->createResourceNodes());
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = $this->createTreeBuilder();
$children = $treeBuilder->root($this->bundle->getAlias())->children();
$this->configureBundle($children);
$children->append($this->createResourceNodes());
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"$",
"this",
"->",
"createTreeBuilder",
"(",
")",
";",
"$",
"children",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"$",
"this",
"->",
"bundle",
"->",
"getAlias",
"(",
")",
")",
"->",
"children",
"(",
")",
";",
"$",
"this",
"->",
"configureBundle",
"(",
"$",
"children",
")",
";",
"$",
"children",
"->",
"append",
"(",
"$",
"this",
"->",
"createResourceNodes",
"(",
")",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php#L48-L57 |
php-lug/lug | src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php | ResourceConfiguration.createResourceNode | private function createResourceNode(ResourceInterface $resource, $name = null)
{
$resourceNode = $this->createNode($name ?: $resource->getName())->addDefaultsIfNotSet();
$childrenNode = $resourceNode->children()
->append($this->createClassNode(
'model',
$resource->getModel(),
$resource->getInterfaces(),
true
))
->append($this->createDriverNode($resource))
->append($this->createClassNode(
'repository',
$resource->getRepository(),
[RepositoryInterface::class]
))
->append($this->createClassNode(
'factory',
$resource->getFactory(),
[FactoryInterface::class]
))
->append($this->createClassNode(
'form',
$resource->getForm(),
[FormTypeInterface::class]
))
->append($this->createClassNode(
'choice_form',
$resource->getChoiceForm(),
[FormTypeInterface::class]
))
->append($this->createClassNode(
'domain_manager',
$resource->getDomainManager(),
[DomainManagerInterface::class]
))
->append($this->createClassNode(
'controller',
$resource->getController(),
[ControllerInterface::class]
))
->append($this->createNode('id_property_path', 'scalar', $resource->getIdPropertyPath()))
->append($this->createNode('label_property_path', 'scalar', $resource->getLabelPropertyPath()));
foreach ($resource->getRelations() as $name => $relation) {
$childrenNode->append($this->createResourceNode($relation, $name));
}
return $resourceNode;
} | php | private function createResourceNode(ResourceInterface $resource, $name = null)
{
$resourceNode = $this->createNode($name ?: $resource->getName())->addDefaultsIfNotSet();
$childrenNode = $resourceNode->children()
->append($this->createClassNode(
'model',
$resource->getModel(),
$resource->getInterfaces(),
true
))
->append($this->createDriverNode($resource))
->append($this->createClassNode(
'repository',
$resource->getRepository(),
[RepositoryInterface::class]
))
->append($this->createClassNode(
'factory',
$resource->getFactory(),
[FactoryInterface::class]
))
->append($this->createClassNode(
'form',
$resource->getForm(),
[FormTypeInterface::class]
))
->append($this->createClassNode(
'choice_form',
$resource->getChoiceForm(),
[FormTypeInterface::class]
))
->append($this->createClassNode(
'domain_manager',
$resource->getDomainManager(),
[DomainManagerInterface::class]
))
->append($this->createClassNode(
'controller',
$resource->getController(),
[ControllerInterface::class]
))
->append($this->createNode('id_property_path', 'scalar', $resource->getIdPropertyPath()))
->append($this->createNode('label_property_path', 'scalar', $resource->getLabelPropertyPath()));
foreach ($resource->getRelations() as $name => $relation) {
$childrenNode->append($this->createResourceNode($relation, $name));
}
return $resourceNode;
} | [
"private",
"function",
"createResourceNode",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"resourceNode",
"=",
"$",
"this",
"->",
"createNode",
"(",
"$",
"name",
"?",
":",
"$",
"resource",
"->",
"getName",
"(",
")",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
";",
"$",
"childrenNode",
"=",
"$",
"resourceNode",
"->",
"children",
"(",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createClassNode",
"(",
"'model'",
",",
"$",
"resource",
"->",
"getModel",
"(",
")",
",",
"$",
"resource",
"->",
"getInterfaces",
"(",
")",
",",
"true",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createDriverNode",
"(",
"$",
"resource",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createClassNode",
"(",
"'repository'",
",",
"$",
"resource",
"->",
"getRepository",
"(",
")",
",",
"[",
"RepositoryInterface",
"::",
"class",
"]",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createClassNode",
"(",
"'factory'",
",",
"$",
"resource",
"->",
"getFactory",
"(",
")",
",",
"[",
"FactoryInterface",
"::",
"class",
"]",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createClassNode",
"(",
"'form'",
",",
"$",
"resource",
"->",
"getForm",
"(",
")",
",",
"[",
"FormTypeInterface",
"::",
"class",
"]",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createClassNode",
"(",
"'choice_form'",
",",
"$",
"resource",
"->",
"getChoiceForm",
"(",
")",
",",
"[",
"FormTypeInterface",
"::",
"class",
"]",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createClassNode",
"(",
"'domain_manager'",
",",
"$",
"resource",
"->",
"getDomainManager",
"(",
")",
",",
"[",
"DomainManagerInterface",
"::",
"class",
"]",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createClassNode",
"(",
"'controller'",
",",
"$",
"resource",
"->",
"getController",
"(",
")",
",",
"[",
"ControllerInterface",
"::",
"class",
"]",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createNode",
"(",
"'id_property_path'",
",",
"'scalar'",
",",
"$",
"resource",
"->",
"getIdPropertyPath",
"(",
")",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createNode",
"(",
"'label_property_path'",
",",
"'scalar'",
",",
"$",
"resource",
"->",
"getLabelPropertyPath",
"(",
")",
")",
")",
";",
"foreach",
"(",
"$",
"resource",
"->",
"getRelations",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"relation",
")",
"{",
"$",
"childrenNode",
"->",
"append",
"(",
"$",
"this",
"->",
"createResourceNode",
"(",
"$",
"relation",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"resourceNode",
";",
"}"
] | @param ResourceInterface $resource
@param string|null $name
@return ArrayNodeDefinition | [
"@param",
"ResourceInterface",
"$resource",
"@param",
"string|null",
"$name"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php#L87-L136 |
php-lug/lug | src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php | ResourceConfiguration.createDriverNode | private function createDriverNode(ResourceInterface $resource)
{
$driverNode = $this->createNode('driver')->addDefaultsIfNotSet();
$driverNode->children()
->append($this->createNode('name', 'scalar', $resource->getDriver()))
->append($this->createNode('manager', 'scalar', $resource->getDriverManager()))
->append($this->createDriverMappingNode($resource));
return $driverNode;
} | php | private function createDriverNode(ResourceInterface $resource)
{
$driverNode = $this->createNode('driver')->addDefaultsIfNotSet();
$driverNode->children()
->append($this->createNode('name', 'scalar', $resource->getDriver()))
->append($this->createNode('manager', 'scalar', $resource->getDriverManager()))
->append($this->createDriverMappingNode($resource));
return $driverNode;
} | [
"private",
"function",
"createDriverNode",
"(",
"ResourceInterface",
"$",
"resource",
")",
"{",
"$",
"driverNode",
"=",
"$",
"this",
"->",
"createNode",
"(",
"'driver'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
";",
"$",
"driverNode",
"->",
"children",
"(",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createNode",
"(",
"'name'",
",",
"'scalar'",
",",
"$",
"resource",
"->",
"getDriver",
"(",
")",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createNode",
"(",
"'manager'",
",",
"'scalar'",
",",
"$",
"resource",
"->",
"getDriverManager",
"(",
")",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createDriverMappingNode",
"(",
"$",
"resource",
")",
")",
";",
"return",
"$",
"driverNode",
";",
"}"
] | @param ResourceInterface $resource
@return ArrayNodeDefinition | [
"@param",
"ResourceInterface",
"$resource"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php#L143-L152 |
php-lug/lug | src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php | ResourceConfiguration.createDriverMappingNode | private function createDriverMappingNode(ResourceInterface $resource)
{
$mappingNode = $this->createNode('mapping')->addDefaultsIfNotSet();
$mappingNode->children()
->append($this->createNode('path', 'scalar', $resource->getDriverMappingPath()))
->append($this->createNode('format', 'scalar', $resource->getDriverMappingFormat()));
return $mappingNode;
} | php | private function createDriverMappingNode(ResourceInterface $resource)
{
$mappingNode = $this->createNode('mapping')->addDefaultsIfNotSet();
$mappingNode->children()
->append($this->createNode('path', 'scalar', $resource->getDriverMappingPath()))
->append($this->createNode('format', 'scalar', $resource->getDriverMappingFormat()));
return $mappingNode;
} | [
"private",
"function",
"createDriverMappingNode",
"(",
"ResourceInterface",
"$",
"resource",
")",
"{",
"$",
"mappingNode",
"=",
"$",
"this",
"->",
"createNode",
"(",
"'mapping'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
";",
"$",
"mappingNode",
"->",
"children",
"(",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createNode",
"(",
"'path'",
",",
"'scalar'",
",",
"$",
"resource",
"->",
"getDriverMappingPath",
"(",
")",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createNode",
"(",
"'format'",
",",
"'scalar'",
",",
"$",
"resource",
"->",
"getDriverMappingFormat",
"(",
")",
")",
")",
";",
"return",
"$",
"mappingNode",
";",
"}"
] | @param ResourceInterface $resource
@return ArrayNodeDefinition | [
"@param",
"ResourceInterface",
"$resource"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php#L159-L167 |
php-lug/lug | src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php | ResourceConfiguration.createClassNode | private function createClassNode($name, $class, array $interfaces = [], $required = false)
{
return $this->createNode($name, 'scalar', $class, function ($class) use ($interfaces, $required) {
if ($class === null) {
return $required;
}
if (!class_exists($class)) {
return true;
}
$classInterfaces = class_implements($class);
foreach ($interfaces as $interface) {
if (!in_array($interface, $classInterfaces, true)) {
return true;
}
}
return false;
}, 'The %s %%s does not exist.');
} | php | private function createClassNode($name, $class, array $interfaces = [], $required = false)
{
return $this->createNode($name, 'scalar', $class, function ($class) use ($interfaces, $required) {
if ($class === null) {
return $required;
}
if (!class_exists($class)) {
return true;
}
$classInterfaces = class_implements($class);
foreach ($interfaces as $interface) {
if (!in_array($interface, $classInterfaces, true)) {
return true;
}
}
return false;
}, 'The %s %%s does not exist.');
} | [
"private",
"function",
"createClassNode",
"(",
"$",
"name",
",",
"$",
"class",
",",
"array",
"$",
"interfaces",
"=",
"[",
"]",
",",
"$",
"required",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"createNode",
"(",
"$",
"name",
",",
"'scalar'",
",",
"$",
"class",
",",
"function",
"(",
"$",
"class",
")",
"use",
"(",
"$",
"interfaces",
",",
"$",
"required",
")",
"{",
"if",
"(",
"$",
"class",
"===",
"null",
")",
"{",
"return",
"$",
"required",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"classInterfaces",
"=",
"class_implements",
"(",
"$",
"class",
")",
";",
"foreach",
"(",
"$",
"interfaces",
"as",
"$",
"interface",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"interface",
",",
"$",
"classInterfaces",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
",",
"'The %s %%s does not exist.'",
")",
";",
"}"
] | @param string $name
@param string $class
@param string[] $interfaces
@param bool $required
@return NodeDefinition | [
"@param",
"string",
"$name",
"@param",
"string",
"$class",
"@param",
"string",
"[]",
"$interfaces",
"@param",
"bool",
"$required"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php#L177-L198 |
php-lug/lug | src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php | ResourceConfiguration.createNode | private function createNode($name, $type = 'array', $default = null, $if = null, $then = null)
{
$node = $this->createTreeBuilder()->root($name, $type);
if ($default !== null) {
$node->defaultValue($default);
}
if ($if !== null && $then !== null) {
$node->validate()->ifTrue($if)->thenInvalid(sprintf($then, $name));
}
return $node;
} | php | private function createNode($name, $type = 'array', $default = null, $if = null, $then = null)
{
$node = $this->createTreeBuilder()->root($name, $type);
if ($default !== null) {
$node->defaultValue($default);
}
if ($if !== null && $then !== null) {
$node->validate()->ifTrue($if)->thenInvalid(sprintf($then, $name));
}
return $node;
} | [
"private",
"function",
"createNode",
"(",
"$",
"name",
",",
"$",
"type",
"=",
"'array'",
",",
"$",
"default",
"=",
"null",
",",
"$",
"if",
"=",
"null",
",",
"$",
"then",
"=",
"null",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"createTreeBuilder",
"(",
")",
"->",
"root",
"(",
"$",
"name",
",",
"$",
"type",
")",
";",
"if",
"(",
"$",
"default",
"!==",
"null",
")",
"{",
"$",
"node",
"->",
"defaultValue",
"(",
"$",
"default",
")",
";",
"}",
"if",
"(",
"$",
"if",
"!==",
"null",
"&&",
"$",
"then",
"!==",
"null",
")",
"{",
"$",
"node",
"->",
"validate",
"(",
")",
"->",
"ifTrue",
"(",
"$",
"if",
")",
"->",
"thenInvalid",
"(",
"sprintf",
"(",
"$",
"then",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"node",
";",
"}"
] | @param string $name
@param string $type
@param mixed $default
@param callable|null $if
@param string|null $then
@return ArrayNodeDefinition|NodeDefinition | [
"@param",
"string",
"$name",
"@param",
"string",
"$type",
"@param",
"mixed",
"$default",
"@param",
"callable|null",
"$if",
"@param",
"string|null",
"$then"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/DependencyInjection/Extension/ResourceConfiguration.php#L209-L222 |
wenbinye/PhalconX | src/Di/FactoryDefault.php | FactoryDefault.autoload | public function autoload(array $autoloads, $provider, $options = [])
{
foreach ($autoloads as $name => $alias) {
if (is_int($name)) {
$name = $alias;
}
if (empty($name)) {
throw new \InvalidArgumentException("Cannot not autoload empty service");
}
if (!empty($options['prefix'])) {
$alias = $options['prefix'] . ucfirst($alias);
}
$shared = true;
if (isset($options['shared'])) {
if (is_array($options['shared'])) {
$shared = in_array($name, $options['shared']);
} else {
$shared = $options['shared'];
}
} elseif (isset($options['instances'])) {
$shared = !in_array($name, $options['instances']);
}
$this->set($alias, function () use ($name, $provider) {
if (!is_object($provider)) {
$provider = $this->getShared($provider);
}
return $provider->provide($name, func_get_args());
}, $shared);
}
return $this;
} | php | public function autoload(array $autoloads, $provider, $options = [])
{
foreach ($autoloads as $name => $alias) {
if (is_int($name)) {
$name = $alias;
}
if (empty($name)) {
throw new \InvalidArgumentException("Cannot not autoload empty service");
}
if (!empty($options['prefix'])) {
$alias = $options['prefix'] . ucfirst($alias);
}
$shared = true;
if (isset($options['shared'])) {
if (is_array($options['shared'])) {
$shared = in_array($name, $options['shared']);
} else {
$shared = $options['shared'];
}
} elseif (isset($options['instances'])) {
$shared = !in_array($name, $options['instances']);
}
$this->set($alias, function () use ($name, $provider) {
if (!is_object($provider)) {
$provider = $this->getShared($provider);
}
return $provider->provide($name, func_get_args());
}, $shared);
}
return $this;
} | [
"public",
"function",
"autoload",
"(",
"array",
"$",
"autoloads",
",",
"$",
"provider",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"autoloads",
"as",
"$",
"name",
"=>",
"$",
"alias",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"alias",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Cannot not autoload empty service\"",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'prefix'",
"]",
")",
")",
"{",
"$",
"alias",
"=",
"$",
"options",
"[",
"'prefix'",
"]",
".",
"ucfirst",
"(",
"$",
"alias",
")",
";",
"}",
"$",
"shared",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'shared'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'shared'",
"]",
")",
")",
"{",
"$",
"shared",
"=",
"in_array",
"(",
"$",
"name",
",",
"$",
"options",
"[",
"'shared'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"shared",
"=",
"$",
"options",
"[",
"'shared'",
"]",
";",
"}",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"options",
"[",
"'instances'",
"]",
")",
")",
"{",
"$",
"shared",
"=",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"options",
"[",
"'instances'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"$",
"alias",
",",
"function",
"(",
")",
"use",
"(",
"$",
"name",
",",
"$",
"provider",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"provider",
")",
")",
"{",
"$",
"provider",
"=",
"$",
"this",
"->",
"getShared",
"(",
"$",
"provider",
")",
";",
"}",
"return",
"$",
"provider",
"->",
"provide",
"(",
"$",
"name",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
",",
"$",
"shared",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | mark autoload service definition from service provider
@param array $autoloads name of service. service alias
@param string|ServiceProvider $provider service provider
@param array options: shared, instances, prefix | [
"mark",
"autoload",
"service",
"definition",
"from",
"service",
"provider"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Di/FactoryDefault.php#L78-L108 |
wenbinye/PhalconX | src/Di/FactoryDefault.php | FactoryDefault.load | public function load($provider, $options = null)
{
if (!is_object($provider)) {
$provider = $this->getShared($provider);
}
$names = $provider->getNames();
if (isset($options['aliases'])) {
$services = $this->createServiceAliases($names, $options['aliases']);
unset($options['aliases']);
} else {
$services = $names;
}
return $this->autoload($services, $provider, $options);
} | php | public function load($provider, $options = null)
{
if (!is_object($provider)) {
$provider = $this->getShared($provider);
}
$names = $provider->getNames();
if (isset($options['aliases'])) {
$services = $this->createServiceAliases($names, $options['aliases']);
unset($options['aliases']);
} else {
$services = $names;
}
return $this->autoload($services, $provider, $options);
} | [
"public",
"function",
"load",
"(",
"$",
"provider",
",",
"$",
"options",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"provider",
")",
")",
"{",
"$",
"provider",
"=",
"$",
"this",
"->",
"getShared",
"(",
"$",
"provider",
")",
";",
"}",
"$",
"names",
"=",
"$",
"provider",
"->",
"getNames",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'aliases'",
"]",
")",
")",
"{",
"$",
"services",
"=",
"$",
"this",
"->",
"createServiceAliases",
"(",
"$",
"names",
",",
"$",
"options",
"[",
"'aliases'",
"]",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'aliases'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"services",
"=",
"$",
"names",
";",
"}",
"return",
"$",
"this",
"->",
"autoload",
"(",
"$",
"services",
",",
"$",
"provider",
",",
"$",
"options",
")",
";",
"}"
] | load all service definition from service provider
@param string|ServiceProvider $provider service provider
@param array $options non-shared service names
- aliases
- shared
- instances
- prefix | [
"load",
"all",
"service",
"definition",
"from",
"service",
"provider"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Di/FactoryDefault.php#L120-L133 |
nabab/bbn | src/bbn/appui/observer.php | observer.get_file | private static function get_file(): string
{
if ( null === self::$path ){
if ( \defined('BBN_DATA_PATH') ){
self::$path = BBN_DATA_PATH;
}
else{
self::$path = __DIR__.'/';
}
}
return self::$path.'plugins/appui-cron/appui-observer.txt';
} | php | private static function get_file(): string
{
if ( null === self::$path ){
if ( \defined('BBN_DATA_PATH') ){
self::$path = BBN_DATA_PATH;
}
else{
self::$path = __DIR__.'/';
}
}
return self::$path.'plugins/appui-cron/appui-observer.txt';
} | [
"private",
"static",
"function",
"get_file",
"(",
")",
":",
"string",
"{",
"if",
"(",
"null",
"===",
"self",
"::",
"$",
"path",
")",
"{",
"if",
"(",
"\\",
"defined",
"(",
"'BBN_DATA_PATH'",
")",
")",
"{",
"self",
"::",
"$",
"path",
"=",
"BBN_DATA_PATH",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"path",
"=",
"__DIR__",
".",
"'/'",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"path",
".",
"'plugins/appui-cron/appui-observer.txt'",
";",
"}"
] | Returns the observer txt file's full path.
@return string | [
"Returns",
"the",
"observer",
"txt",
"file",
"s",
"full",
"path",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L48-L59 |
nabab/bbn | src/bbn/appui/observer.php | observer._exec | private function _exec($request, $params = null): ?string
{
if ( is_string($request) && bbn\str::is_json($request) ){
$request = json_decode($request, true);
}
if ( is_array($request) ){
return $this->_exec_array($request);
}
return $this->_exec_string($request, $params);
} | php | private function _exec($request, $params = null): ?string
{
if ( is_string($request) && bbn\str::is_json($request) ){
$request = json_decode($request, true);
}
if ( is_array($request) ){
return $this->_exec_array($request);
}
return $this->_exec_string($request, $params);
} | [
"private",
"function",
"_exec",
"(",
"$",
"request",
",",
"$",
"params",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"is_string",
"(",
"$",
"request",
")",
"&&",
"bbn",
"\\",
"str",
"::",
"is_json",
"(",
"$",
"request",
")",
")",
"{",
"$",
"request",
"=",
"json_decode",
"(",
"$",
"request",
",",
"true",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"request",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_exec_array",
"(",
"$",
"request",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_exec_string",
"(",
"$",
"request",
",",
"$",
"params",
")",
";",
"}"
] | Executes a request (kept in the observer) and returns its (single) result.
@param string $request The SQL Query to be executed.
@param string|null $params The base64 encoded of a JSON string of the parameters to send with the query.
@return mixed | [
"Executes",
"a",
"request",
"(",
"kept",
"in",
"the",
"observer",
")",
"and",
"returns",
"its",
"(",
"single",
")",
"result",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L68-L77 |
nabab/bbn | src/bbn/appui/observer.php | observer._exec_string | private function _exec_string(string $request, $params = null): ?string
{
if ( $this->check() ){
$res = !empty($params) ? $this->db->get_one($request, array_map('base64_decode', json_decode($params))) : $this->db->get_one($request);
return md5((string)$res);
}
return null;
} | php | private function _exec_string(string $request, $params = null): ?string
{
if ( $this->check() ){
$res = !empty($params) ? $this->db->get_one($request, array_map('base64_decode', json_decode($params))) : $this->db->get_one($request);
return md5((string)$res);
}
return null;
} | [
"private",
"function",
"_exec_string",
"(",
"string",
"$",
"request",
",",
"$",
"params",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"$",
"res",
"=",
"!",
"empty",
"(",
"$",
"params",
")",
"?",
"$",
"this",
"->",
"db",
"->",
"get_one",
"(",
"$",
"request",
",",
"array_map",
"(",
"'base64_decode'",
",",
"json_decode",
"(",
"$",
"params",
")",
")",
")",
":",
"$",
"this",
"->",
"db",
"->",
"get_one",
"(",
"$",
"request",
")",
";",
"return",
"md5",
"(",
"(",
"string",
")",
"$",
"res",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Executes a request (kept in the observer) and returns its (single) result.
@param string $request The SQL Query to be executed.
@param string|null $params The base64 encoded of a JSON string of the parameters to send with the query.
@return mixed | [
"Executes",
"a",
"request",
"(",
"kept",
"in",
"the",
"observer",
")",
"and",
"returns",
"its",
"(",
"single",
")",
"result",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L86-L93 |
nabab/bbn | src/bbn/appui/observer.php | observer._exec_array | private function _exec_array(array $request): ?string
{
if ( $this->check() ){
return md5((string)$this->db->select_one($request));
}
return null;
} | php | private function _exec_array(array $request): ?string
{
if ( $this->check() ){
return md5((string)$this->db->select_one($request));
}
return null;
} | [
"private",
"function",
"_exec_array",
"(",
"array",
"$",
"request",
")",
":",
"?",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"return",
"md5",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"db",
"->",
"select_one",
"(",
"$",
"request",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Executes a request (kept in the observer as an array) and returns its (single) result.
@param string $request The config to be executed.
@return mixed | [
"Executes",
"a",
"request",
"(",
"kept",
"in",
"the",
"observer",
"as",
"an",
"array",
")",
"and",
"returns",
"its",
"(",
"single",
")",
"result",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L101-L107 |
nabab/bbn | src/bbn/appui/observer.php | observer._get_id | private function _get_id(string $request, $params): ?string
{
if ( $this->check() ){
if ( $params ){
return $this->db->select_one('bbn_observers', 'id', [
'id_string' => $this->_get_id_string($request, $params)
]);
}
return $this->db->get_one("
SELECT id
FROM bbn_observers
WHERE `request` LIKE ?
AND `params` IS NULL
AND `public` = 1",
$request);
}
return null;
} | php | private function _get_id(string $request, $params): ?string
{
if ( $this->check() ){
if ( $params ){
return $this->db->select_one('bbn_observers', 'id', [
'id_string' => $this->_get_id_string($request, $params)
]);
}
return $this->db->get_one("
SELECT id
FROM bbn_observers
WHERE `request` LIKE ?
AND `params` IS NULL
AND `public` = 1",
$request);
}
return null;
} | [
"private",
"function",
"_get_id",
"(",
"string",
"$",
"request",
",",
"$",
"params",
")",
":",
"?",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"if",
"(",
"$",
"params",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"select_one",
"(",
"'bbn_observers'",
",",
"'id'",
",",
"[",
"'id_string'",
"=>",
"$",
"this",
"->",
"_get_id_string",
"(",
"$",
"request",
",",
"$",
"params",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"db",
"->",
"get_one",
"(",
"\"\n SELECT id\n FROM bbn_observers\n WHERE `request` LIKE ?\n AND `params` IS NULL\n AND `public` = 1\"",
",",
"$",
"request",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the ID of an observer with public = 1 and with similar request and params.
@param string $request
@param string $params
@return null|string | [
"Returns",
"the",
"ID",
"of",
"an",
"observer",
"with",
"public",
"=",
"1",
"and",
"with",
"similar",
"request",
"and",
"params",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L121-L138 |
nabab/bbn | src/bbn/appui/observer.php | observer._get_id_from_user | private function _get_id_from_user(string $request, $params): ?string
{
if ( $this->id_user && $this->check() ){
$sql = '
SELECT `o`.`id`
FROM bbn_observers AS `o`
LEFT JOIN bbn_observers AS `ro`
ON `o`.`id_alias` = `ro`.`id`
WHERE `o`.`id_user` = ?
AND (
(
`o`.`request` LIKE ?
AND `o`.`params` '.($params ? 'LIKE ?' : 'IS NULL').'
)
OR (
`ro`.`request` LIKE ?
AND `ro`.`params` '.($params ? 'LIKE ?' : 'IS NULL').'
)
)';
$args = [hex2bin($this->id_user), $request, $request];
if ( $params ){
array_splice($args, 2, 0, $params);
array_push($args, $params);
}
return $this->db->get_one($sql, $args);
}
return null;
} | php | private function _get_id_from_user(string $request, $params): ?string
{
if ( $this->id_user && $this->check() ){
$sql = '
SELECT `o`.`id`
FROM bbn_observers AS `o`
LEFT JOIN bbn_observers AS `ro`
ON `o`.`id_alias` = `ro`.`id`
WHERE `o`.`id_user` = ?
AND (
(
`o`.`request` LIKE ?
AND `o`.`params` '.($params ? 'LIKE ?' : 'IS NULL').'
)
OR (
`ro`.`request` LIKE ?
AND `ro`.`params` '.($params ? 'LIKE ?' : 'IS NULL').'
)
)';
$args = [hex2bin($this->id_user), $request, $request];
if ( $params ){
array_splice($args, 2, 0, $params);
array_push($args, $params);
}
return $this->db->get_one($sql, $args);
}
return null;
} | [
"private",
"function",
"_get_id_from_user",
"(",
"string",
"$",
"request",
",",
"$",
"params",
")",
":",
"?",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"id_user",
"&&",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"$",
"sql",
"=",
"'\n SELECT `o`.`id`\n FROM bbn_observers AS `o`\n LEFT JOIN bbn_observers AS `ro`\n ON `o`.`id_alias` = `ro`.`id`\n WHERE `o`.`id_user` = ?\n AND (\n (\n `o`.`request` LIKE ?\n AND `o`.`params` '",
".",
"(",
"$",
"params",
"?",
"'LIKE ?'",
":",
"'IS NULL'",
")",
".",
"'\n )\n OR (\n `ro`.`request` LIKE ?\n AND `ro`.`params` '",
".",
"(",
"$",
"params",
"?",
"'LIKE ?'",
":",
"'IS NULL'",
")",
".",
"'\n )\n )'",
";",
"$",
"args",
"=",
"[",
"hex2bin",
"(",
"$",
"this",
"->",
"id_user",
")",
",",
"$",
"request",
",",
"$",
"request",
"]",
";",
"if",
"(",
"$",
"params",
")",
"{",
"array_splice",
"(",
"$",
"args",
",",
"2",
",",
"0",
",",
"$",
"params",
")",
";",
"array_push",
"(",
"$",
"args",
",",
"$",
"params",
")",
";",
"}",
"return",
"$",
"this",
"->",
"db",
"->",
"get_one",
"(",
"$",
"sql",
",",
"$",
"args",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the ID of an observer for the current user and with similar request and params.
@param string $request
@param string $params
@return null|string | [
"Returns",
"the",
"ID",
"of",
"an",
"observer",
"for",
"the",
"current",
"user",
"and",
"with",
"similar",
"request",
"and",
"params",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L147-L174 |
nabab/bbn | src/bbn/appui/observer.php | observer._get_id_string | private function _get_id_string(string $request, string $params = null): string
{
return md5($request.($params ?: ''));
} | php | private function _get_id_string(string $request, string $params = null): string
{
return md5($request.($params ?: ''));
} | [
"private",
"function",
"_get_id_string",
"(",
"string",
"$",
"request",
",",
"string",
"$",
"params",
"=",
"null",
")",
":",
"string",
"{",
"return",
"md5",
"(",
"$",
"request",
".",
"(",
"$",
"params",
"?",
":",
"''",
")",
")",
";",
"}"
] | Returns the unique string representing the request + the parameters (md5 of concatenated strings).
@param string $request
@param array|null $params
@return string | [
"Returns",
"the",
"unique",
"string",
"representing",
"the",
"request",
"+",
"the",
"parameters",
"(",
"md5",
"of",
"concatenated",
"strings",
")",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L183-L186 |
nabab/bbn | src/bbn/appui/observer.php | observer._update_next | private function _update_next($id): bool
{
$id_alias = $this->db->select_one('bbn_observers', 'id_alias', ['id' => $id]);
return $this->db->query(<<<MYSQL
UPDATE bbn_observers
SET next = NOW() + INTERVAL frequency SECOND
WHERE id = ?
MYSQL
,
hex2bin($id_alias ?: $id)) ? true : false;
} | php | private function _update_next($id): bool
{
$id_alias = $this->db->select_one('bbn_observers', 'id_alias', ['id' => $id]);
return $this->db->query(<<<MYSQL
UPDATE bbn_observers
SET next = NOW() + INTERVAL frequency SECOND
WHERE id = ?
MYSQL
,
hex2bin($id_alias ?: $id)) ? true : false;
} | [
"private",
"function",
"_update_next",
"(",
"$",
"id",
")",
":",
"bool",
"{",
"$",
"id_alias",
"=",
"$",
"this",
"->",
"db",
"->",
"select_one",
"(",
"'bbn_observers'",
",",
"'id_alias'",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"<<<MYSQL\n UPDATE bbn_observers\n SET next = NOW() + INTERVAL frequency SECOND\n WHERE id = ?\nMYSQL",
",",
"hex2bin",
"(",
"$",
"id_alias",
"?",
":",
"$",
"id",
")",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Sets the time of next execution in the observer's main row.
@param $id
@return bbn\db\query|int | [
"Sets",
"the",
"time",
"of",
"next",
"execution",
"in",
"the",
"observer",
"s",
"main",
"row",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L194-L204 |
nabab/bbn | src/bbn/appui/observer.php | observer.check_result | public function check_result($id)
{
if ( $d = $this->get($id) ){
$t = new bbn\util\timer();
$t->start();
$res = $this->_exec($d['request'], $d['params']);
$duration = (int)ceil($t->stop() * 1000);
if ( $res !== $d['result'] ){
$this->db->update('bbn_observers', [
'result' => $res,
'duration' => $duration
], [
'id' => $id
]);
return false;
}
return true;
}
} | php | public function check_result($id)
{
if ( $d = $this->get($id) ){
$t = new bbn\util\timer();
$t->start();
$res = $this->_exec($d['request'], $d['params']);
$duration = (int)ceil($t->stop() * 1000);
if ( $res !== $d['result'] ){
$this->db->update('bbn_observers', [
'result' => $res,
'duration' => $duration
], [
'id' => $id
]);
return false;
}
return true;
}
} | [
"public",
"function",
"check_result",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"d",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
")",
"{",
"$",
"t",
"=",
"new",
"bbn",
"\\",
"util",
"\\",
"timer",
"(",
")",
";",
"$",
"t",
"->",
"start",
"(",
")",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"_exec",
"(",
"$",
"d",
"[",
"'request'",
"]",
",",
"$",
"d",
"[",
"'params'",
"]",
")",
";",
"$",
"duration",
"=",
"(",
"int",
")",
"ceil",
"(",
"$",
"t",
"->",
"stop",
"(",
")",
"*",
"1000",
")",
";",
"if",
"(",
"$",
"res",
"!==",
"$",
"d",
"[",
"'result'",
"]",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"'bbn_observers'",
",",
"[",
"'result'",
"=>",
"$",
"res",
",",
"'duration'",
"=>",
"$",
"duration",
"]",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"}"
] | Confronts the current result with the one kept in database.
@param $id
@return bool | [
"Confronts",
"the",
"current",
"result",
"with",
"the",
"one",
"kept",
"in",
"database",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L223-L241 |
nabab/bbn | src/bbn/appui/observer.php | observer.add | public function add(array $cfg): ?string
{
if (
$this->id_user &&
(null !== $cfg['request']) &&
$this->check()
){
$t = new bbn\util\timer();
$t->start();
if ( is_string($cfg['request']) ){
$params = self::sanitize_params($cfg['params'] ?? []);
$request = trim($cfg['request']);
}
else if ( is_array($cfg['request']) ){
$params = null;
$request = $cfg['request'];
}
else{
return null;
}
$res = $this->_exec($request, $params);
$duration = (int)ceil($t->stop() * 1000);
if ( is_array($request) ){
$request = json_encode($request);
}
$id_alias = $this->_get_id($request, $params);
//die(var_dump($id_alias, $this->db->last()));
// If it is a public observer it will be the id_alias and the main observer
if (
!$id_alias &&
!empty($cfg['public']) &&
$this->db->insert('bbn_observers', [
'request' => $request,
'params' => $params ?: null,
'name' => $cfg['name'] ?? null,
'duration' => $duration,
'id_user' => null,
'public' => 1,
'result' => $res
])
){
$id_alias = $this->db->last_id();
}
// Getting the ID of the observer corresponding to current user
if ( $id_obs = $this->_get_id_from_user($request, $params) ){
//
$this->check_result($id_obs);
return $id_obs;
}
else if ( $id_alias ){
if ( $this->db->insert('bbn_observers', [
'id_user' => $this->id_user,
'public' => 0,
'id_alias' => $id_alias,
'next' => null,
'result' => $res
]) ){
return $this->db->last_id();
}
}
else{
if ( $this->db->insert('bbn_observers', [
'request' => $request,
'params' => $params ?: null,
'name' => $cfg['name'] ?? null,
'duration' => $duration,
'id_user' => $this->id_user,
'public' => 0,
'result' => $res
]) ){
return $this->db->last_id();
}
}
}
return null;
} | php | public function add(array $cfg): ?string
{
if (
$this->id_user &&
(null !== $cfg['request']) &&
$this->check()
){
$t = new bbn\util\timer();
$t->start();
if ( is_string($cfg['request']) ){
$params = self::sanitize_params($cfg['params'] ?? []);
$request = trim($cfg['request']);
}
else if ( is_array($cfg['request']) ){
$params = null;
$request = $cfg['request'];
}
else{
return null;
}
$res = $this->_exec($request, $params);
$duration = (int)ceil($t->stop() * 1000);
if ( is_array($request) ){
$request = json_encode($request);
}
$id_alias = $this->_get_id($request, $params);
//die(var_dump($id_alias, $this->db->last()));
// If it is a public observer it will be the id_alias and the main observer
if (
!$id_alias &&
!empty($cfg['public']) &&
$this->db->insert('bbn_observers', [
'request' => $request,
'params' => $params ?: null,
'name' => $cfg['name'] ?? null,
'duration' => $duration,
'id_user' => null,
'public' => 1,
'result' => $res
])
){
$id_alias = $this->db->last_id();
}
// Getting the ID of the observer corresponding to current user
if ( $id_obs = $this->_get_id_from_user($request, $params) ){
//
$this->check_result($id_obs);
return $id_obs;
}
else if ( $id_alias ){
if ( $this->db->insert('bbn_observers', [
'id_user' => $this->id_user,
'public' => 0,
'id_alias' => $id_alias,
'next' => null,
'result' => $res
]) ){
return $this->db->last_id();
}
}
else{
if ( $this->db->insert('bbn_observers', [
'request' => $request,
'params' => $params ?: null,
'name' => $cfg['name'] ?? null,
'duration' => $duration,
'id_user' => $this->id_user,
'public' => 0,
'result' => $res
]) ){
return $this->db->last_id();
}
}
}
return null;
} | [
"public",
"function",
"add",
"(",
"array",
"$",
"cfg",
")",
":",
"?",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"id_user",
"&&",
"(",
"null",
"!==",
"$",
"cfg",
"[",
"'request'",
"]",
")",
"&&",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"$",
"t",
"=",
"new",
"bbn",
"\\",
"util",
"\\",
"timer",
"(",
")",
";",
"$",
"t",
"->",
"start",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"cfg",
"[",
"'request'",
"]",
")",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"sanitize_params",
"(",
"$",
"cfg",
"[",
"'params'",
"]",
"??",
"[",
"]",
")",
";",
"$",
"request",
"=",
"trim",
"(",
"$",
"cfg",
"[",
"'request'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"cfg",
"[",
"'request'",
"]",
")",
")",
"{",
"$",
"params",
"=",
"null",
";",
"$",
"request",
"=",
"$",
"cfg",
"[",
"'request'",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"$",
"res",
"=",
"$",
"this",
"->",
"_exec",
"(",
"$",
"request",
",",
"$",
"params",
")",
";",
"$",
"duration",
"=",
"(",
"int",
")",
"ceil",
"(",
"$",
"t",
"->",
"stop",
"(",
")",
"*",
"1000",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"request",
")",
")",
"{",
"$",
"request",
"=",
"json_encode",
"(",
"$",
"request",
")",
";",
"}",
"$",
"id_alias",
"=",
"$",
"this",
"->",
"_get_id",
"(",
"$",
"request",
",",
"$",
"params",
")",
";",
"//die(var_dump($id_alias, $this->db->last()));",
"// If it is a public observer it will be the id_alias and the main observer",
"if",
"(",
"!",
"$",
"id_alias",
"&&",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'public'",
"]",
")",
"&&",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"'bbn_observers'",
",",
"[",
"'request'",
"=>",
"$",
"request",
",",
"'params'",
"=>",
"$",
"params",
"?",
":",
"null",
",",
"'name'",
"=>",
"$",
"cfg",
"[",
"'name'",
"]",
"??",
"null",
",",
"'duration'",
"=>",
"$",
"duration",
",",
"'id_user'",
"=>",
"null",
",",
"'public'",
"=>",
"1",
",",
"'result'",
"=>",
"$",
"res",
"]",
")",
")",
"{",
"$",
"id_alias",
"=",
"$",
"this",
"->",
"db",
"->",
"last_id",
"(",
")",
";",
"}",
"// Getting the ID of the observer corresponding to current user",
"if",
"(",
"$",
"id_obs",
"=",
"$",
"this",
"->",
"_get_id_from_user",
"(",
"$",
"request",
",",
"$",
"params",
")",
")",
"{",
"//",
"$",
"this",
"->",
"check_result",
"(",
"$",
"id_obs",
")",
";",
"return",
"$",
"id_obs",
";",
"}",
"else",
"if",
"(",
"$",
"id_alias",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"'bbn_observers'",
",",
"[",
"'id_user'",
"=>",
"$",
"this",
"->",
"id_user",
",",
"'public'",
"=>",
"0",
",",
"'id_alias'",
"=>",
"$",
"id_alias",
",",
"'next'",
"=>",
"null",
",",
"'result'",
"=>",
"$",
"res",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"last_id",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"'bbn_observers'",
",",
"[",
"'request'",
"=>",
"$",
"request",
",",
"'params'",
"=>",
"$",
"params",
"?",
":",
"null",
",",
"'name'",
"=>",
"$",
"cfg",
"[",
"'name'",
"]",
"??",
"null",
",",
"'duration'",
"=>",
"$",
"duration",
",",
"'id_user'",
"=>",
"$",
"this",
"->",
"id_user",
",",
"'public'",
"=>",
"0",
",",
"'result'",
"=>",
"$",
"res",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"last_id",
"(",
")",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Adds a new observer and returns its id or the id of an existing one.
@param array $cfg
@return null|string | [
"Adds",
"a",
"new",
"observer",
"and",
"returns",
"its",
"id",
"or",
"the",
"id",
"of",
"an",
"existing",
"one",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L249-L324 |
nabab/bbn | src/bbn/appui/observer.php | observer.get | public function get($id): ?array
{
if ( $this->check() ){
$d = $this->db->rselect('bbn_observers', [], [
'id' => $id
]);
if ( !$d['id_alias'] ){
return $d;
}
$alias = $this->db->rselect('bbn_observers', [], [
'id' => $d['id_alias']
]);
$alias['id'] = $d['id'];
$alias['result'] = $d['result'];
$alias['id_alias'] = $d['id_alias'];
return $alias;
}
return null;
} | php | public function get($id): ?array
{
if ( $this->check() ){
$d = $this->db->rselect('bbn_observers', [], [
'id' => $id
]);
if ( !$d['id_alias'] ){
return $d;
}
$alias = $this->db->rselect('bbn_observers', [], [
'id' => $d['id_alias']
]);
$alias['id'] = $d['id'];
$alias['result'] = $d['result'];
$alias['id_alias'] = $d['id_alias'];
return $alias;
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
":",
"?",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"$",
"d",
"=",
"$",
"this",
"->",
"db",
"->",
"rselect",
"(",
"'bbn_observers'",
",",
"[",
"]",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"if",
"(",
"!",
"$",
"d",
"[",
"'id_alias'",
"]",
")",
"{",
"return",
"$",
"d",
";",
"}",
"$",
"alias",
"=",
"$",
"this",
"->",
"db",
"->",
"rselect",
"(",
"'bbn_observers'",
",",
"[",
"]",
",",
"[",
"'id'",
"=>",
"$",
"d",
"[",
"'id_alias'",
"]",
"]",
")",
";",
"$",
"alias",
"[",
"'id'",
"]",
"=",
"$",
"d",
"[",
"'id'",
"]",
";",
"$",
"alias",
"[",
"'result'",
"]",
"=",
"$",
"d",
"[",
"'result'",
"]",
";",
"$",
"alias",
"[",
"'id_alias'",
"]",
"=",
"$",
"d",
"[",
"'id_alias'",
"]",
";",
"return",
"$",
"alias",
";",
"}",
"return",
"null",
";",
"}"
] | Returns an observer with its alias properties if there is one (except id and result).
@param $id
@return array|null | [
"Returns",
"an",
"observer",
"with",
"its",
"alias",
"properties",
"if",
"there",
"is",
"one",
"(",
"except",
"id",
"and",
"result",
")",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L332-L350 |
nabab/bbn | src/bbn/appui/observer.php | observer.user_delete | public function user_delete($id): int
{
if ( property_exists($this, 'user') && $this->check() ){
return $this->db->delete('bbn_observers', ['id' => $id, 'id_user' => $this->user]);
}
return 0;
} | php | public function user_delete($id): int
{
if ( property_exists($this, 'user') && $this->check() ){
return $this->db->delete('bbn_observers', ['id' => $id, 'id_user' => $this->user]);
}
return 0;
} | [
"public",
"function",
"user_delete",
"(",
"$",
"id",
")",
":",
"int",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"'user'",
")",
"&&",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"delete",
"(",
"'bbn_observers'",
",",
"[",
"'id'",
"=>",
"$",
"id",
",",
"'id_user'",
"=>",
"$",
"this",
"->",
"user",
"]",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Deletes the given observer for the current user
@param string $id
@return int | [
"Deletes",
"the",
"given",
"observer",
"for",
"the",
"current",
"user"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L403-L409 |
nabab/bbn | src/bbn/appui/observer.php | observer.observe | public function observe()
{
if ( $this->check() ){
$sql = <<<MYSQL
SELECT o.id, o.id_user, o.request, o.params,
GROUP_CONCAT(HEX(aliases.id) SEPARATOR ',') AS aliases,
GROUP_CONCAT(HEX(aliases.id_user) SEPARATOR ',') AS users,
GROUP_CONCAT(aliases.result SEPARATOR ',') AS results
FROM bbn_observers AS o
LEFT JOIN bbn_observers AS aliases
ON aliases.id_alias = o.id
WHERE o.id_alias IS NULL
AND o.next < NOW()
GROUP BY o.id
HAVING COUNT(aliases.id) > 0
OR o.id_user IS NOT NULL
MYSQL;
$diff = [];
//MAX: 2000
$this->db->query('SET @@group_concat_max_len = ?', 2000 * 32);
foreach ( $this->db->get_rows($sql) as $d ){
$aliases = $d['aliases'] ? array_map('strtolower', explode(',', $d['aliases'])) : [];
$users = $d['users'] ? array_map('strtolower', explode(',', $d['users'])) : [];
$results = $d['results'] ? explode(',', $d['results']) : [];
if ( \bbn\str::is_json($d['request']) ){
$d['request'] = json_decode($d['request'], true);
$real_result = $this->_exec_array($d['request']);
}
else{
$real_result = $this->_exec($d['request'], $d['params']);
}
$db_result = $this->get_result($d['id']);
// Only if users are attached to the
echo '+';
if ( $real_result !== $db_result ){
$this->db->update('bbn_observers', ['result' => $real_result], ['id' => $d['id']]);
if ( $d['id_user'] ){
if ( !isset($diff[$d['id_user']]) ){
$diff[$d['id_user']] = [];
}
$diff[$d['id_user']][] = [
'id' => $d['id'],
'result' => $real_result
];
}
}
foreach ( $aliases as $i => $a ){
if ( $real_result !== $results[$i] ){
$this->db->update('bbn_observers', ['result' => $real_result], ['id' => $a]);
$t = $users[$i];
if ( !isset($diff[$t]) ){
$diff[$t] = [];
}
$diff[$t][] = [
'id' => $a,
'result' => $real_result
];
}
}
bbn\x::log(['-------------------', $d, $diff], 'error');
$this->_update_next($d['id']);
}
echo '.';
$this->db->flush();
if ( count($diff) ){
bbn\x::dump('Returning diff!', $diff);
return $diff;
}
if ( ob_get_contents() ){
ob_end_flush();
}
return true;
}
bbn\x::dump('Canceling observer: '.date('H:i:s Y-m-d'));
return false;
} | php | public function observe()
{
if ( $this->check() ){
$sql = <<<MYSQL
SELECT o.id, o.id_user, o.request, o.params,
GROUP_CONCAT(HEX(aliases.id) SEPARATOR ',') AS aliases,
GROUP_CONCAT(HEX(aliases.id_user) SEPARATOR ',') AS users,
GROUP_CONCAT(aliases.result SEPARATOR ',') AS results
FROM bbn_observers AS o
LEFT JOIN bbn_observers AS aliases
ON aliases.id_alias = o.id
WHERE o.id_alias IS NULL
AND o.next < NOW()
GROUP BY o.id
HAVING COUNT(aliases.id) > 0
OR o.id_user IS NOT NULL
MYSQL;
$diff = [];
//MAX: 2000
$this->db->query('SET @@group_concat_max_len = ?', 2000 * 32);
foreach ( $this->db->get_rows($sql) as $d ){
$aliases = $d['aliases'] ? array_map('strtolower', explode(',', $d['aliases'])) : [];
$users = $d['users'] ? array_map('strtolower', explode(',', $d['users'])) : [];
$results = $d['results'] ? explode(',', $d['results']) : [];
if ( \bbn\str::is_json($d['request']) ){
$d['request'] = json_decode($d['request'], true);
$real_result = $this->_exec_array($d['request']);
}
else{
$real_result = $this->_exec($d['request'], $d['params']);
}
$db_result = $this->get_result($d['id']);
// Only if users are attached to the
echo '+';
if ( $real_result !== $db_result ){
$this->db->update('bbn_observers', ['result' => $real_result], ['id' => $d['id']]);
if ( $d['id_user'] ){
if ( !isset($diff[$d['id_user']]) ){
$diff[$d['id_user']] = [];
}
$diff[$d['id_user']][] = [
'id' => $d['id'],
'result' => $real_result
];
}
}
foreach ( $aliases as $i => $a ){
if ( $real_result !== $results[$i] ){
$this->db->update('bbn_observers', ['result' => $real_result], ['id' => $a]);
$t = $users[$i];
if ( !isset($diff[$t]) ){
$diff[$t] = [];
}
$diff[$t][] = [
'id' => $a,
'result' => $real_result
];
}
}
bbn\x::log(['-------------------', $d, $diff], 'error');
$this->_update_next($d['id']);
}
echo '.';
$this->db->flush();
if ( count($diff) ){
bbn\x::dump('Returning diff!', $diff);
return $diff;
}
if ( ob_get_contents() ){
ob_end_flush();
}
return true;
}
bbn\x::dump('Canceling observer: '.date('H:i:s Y-m-d'));
return false;
} | [
"public",
"function",
"observe",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"$",
"sql",
"=",
" <<<MYSQL\n SELECT o.id, o.id_user, o.request, o.params,\n GROUP_CONCAT(HEX(aliases.id) SEPARATOR ',') AS aliases,\n GROUP_CONCAT(HEX(aliases.id_user) SEPARATOR ',') AS users,\n GROUP_CONCAT(aliases.result SEPARATOR ',') AS results\n FROM bbn_observers AS o\n LEFT JOIN bbn_observers AS aliases\n ON aliases.id_alias = o.id\n WHERE o.id_alias IS NULL\n AND o.next < NOW()\n GROUP BY o.id\n HAVING COUNT(aliases.id) > 0\n OR o.id_user IS NOT NULL\nMYSQL",
";",
"$",
"diff",
"=",
"[",
"]",
";",
"//MAX: 2000",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"'SET @@group_concat_max_len = ?'",
",",
"2000",
"*",
"32",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"db",
"->",
"get_rows",
"(",
"$",
"sql",
")",
"as",
"$",
"d",
")",
"{",
"$",
"aliases",
"=",
"$",
"d",
"[",
"'aliases'",
"]",
"?",
"array_map",
"(",
"'strtolower'",
",",
"explode",
"(",
"','",
",",
"$",
"d",
"[",
"'aliases'",
"]",
")",
")",
":",
"[",
"]",
";",
"$",
"users",
"=",
"$",
"d",
"[",
"'users'",
"]",
"?",
"array_map",
"(",
"'strtolower'",
",",
"explode",
"(",
"','",
",",
"$",
"d",
"[",
"'users'",
"]",
")",
")",
":",
"[",
"]",
";",
"$",
"results",
"=",
"$",
"d",
"[",
"'results'",
"]",
"?",
"explode",
"(",
"','",
",",
"$",
"d",
"[",
"'results'",
"]",
")",
":",
"[",
"]",
";",
"if",
"(",
"\\",
"bbn",
"\\",
"str",
"::",
"is_json",
"(",
"$",
"d",
"[",
"'request'",
"]",
")",
")",
"{",
"$",
"d",
"[",
"'request'",
"]",
"=",
"json_decode",
"(",
"$",
"d",
"[",
"'request'",
"]",
",",
"true",
")",
";",
"$",
"real_result",
"=",
"$",
"this",
"->",
"_exec_array",
"(",
"$",
"d",
"[",
"'request'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"real_result",
"=",
"$",
"this",
"->",
"_exec",
"(",
"$",
"d",
"[",
"'request'",
"]",
",",
"$",
"d",
"[",
"'params'",
"]",
")",
";",
"}",
"$",
"db_result",
"=",
"$",
"this",
"->",
"get_result",
"(",
"$",
"d",
"[",
"'id'",
"]",
")",
";",
"// Only if users are attached to the",
"echo",
"'+'",
";",
"if",
"(",
"$",
"real_result",
"!==",
"$",
"db_result",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"'bbn_observers'",
",",
"[",
"'result'",
"=>",
"$",
"real_result",
"]",
",",
"[",
"'id'",
"=>",
"$",
"d",
"[",
"'id'",
"]",
"]",
")",
";",
"if",
"(",
"$",
"d",
"[",
"'id_user'",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"diff",
"[",
"$",
"d",
"[",
"'id_user'",
"]",
"]",
")",
")",
"{",
"$",
"diff",
"[",
"$",
"d",
"[",
"'id_user'",
"]",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"diff",
"[",
"$",
"d",
"[",
"'id_user'",
"]",
"]",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"d",
"[",
"'id'",
"]",
",",
"'result'",
"=>",
"$",
"real_result",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"i",
"=>",
"$",
"a",
")",
"{",
"if",
"(",
"$",
"real_result",
"!==",
"$",
"results",
"[",
"$",
"i",
"]",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"'bbn_observers'",
",",
"[",
"'result'",
"=>",
"$",
"real_result",
"]",
",",
"[",
"'id'",
"=>",
"$",
"a",
"]",
")",
";",
"$",
"t",
"=",
"$",
"users",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"diff",
"[",
"$",
"t",
"]",
")",
")",
"{",
"$",
"diff",
"[",
"$",
"t",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"diff",
"[",
"$",
"t",
"]",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"a",
",",
"'result'",
"=>",
"$",
"real_result",
"]",
";",
"}",
"}",
"bbn",
"\\",
"x",
"::",
"log",
"(",
"[",
"'-------------------'",
",",
"$",
"d",
",",
"$",
"diff",
"]",
",",
"'error'",
")",
";",
"$",
"this",
"->",
"_update_next",
"(",
"$",
"d",
"[",
"'id'",
"]",
")",
";",
"}",
"echo",
"'.'",
";",
"$",
"this",
"->",
"db",
"->",
"flush",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"diff",
")",
")",
"{",
"bbn",
"\\",
"x",
"::",
"dump",
"(",
"'Returning diff!'",
",",
"$",
"diff",
")",
";",
"return",
"$",
"diff",
";",
"}",
"if",
"(",
"ob_get_contents",
"(",
")",
")",
"{",
"ob_end_flush",
"(",
")",
";",
"}",
"return",
"true",
";",
"}",
"bbn",
"\\",
"x",
"::",
"dump",
"(",
"'Canceling observer: '",
".",
"date",
"(",
"'H:i:s Y-m-d'",
")",
")",
";",
"return",
"false",
";",
"}"
] | Checks the observers, execute their requests every given interval, it will stop when it finds differences in the
results, and returns the observers to be updated (meant to be executed from a cron task).
@return array | [
"Checks",
"the",
"observers",
"execute",
"their",
"requests",
"every",
"given",
"interval",
"it",
"will",
"stop",
"when",
"it",
"finds",
"differences",
"in",
"the",
"results",
"and",
"returns",
"the",
"observers",
"to",
"be",
"updated",
"(",
"meant",
"to",
"be",
"executed",
"from",
"a",
"cron",
"task",
")",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/observer.php#L417-L493 |
technote-space/wordpress-plugin-base | src/classes/models/lib/define.php | Define.initialize | protected function initialize() {
$this->plugin_name = $this->app->plugin_name;
$this->plugin_file = $this->app->plugin_file;
$this->plugin_namespace = ucwords( $this->plugin_name, '_' );
$this->plugin_dir = dirname( $this->plugin_file );
$this->plugin_dir_name = basename( $this->plugin_dir );
$this->plugin_base_name = $this->app->is_theme ? 'theme/' . $this->plugin_dir : plugin_basename( $this->plugin_file );
$cache = $this->app->get_shared_object( 'lib_defines_cache', 'all' );
if ( ! isset( $cache ) ) {
$cache = [];
$cache['lib_name'] = TECHNOTE_PLUGIN;
$cache['lib_dir'] = $this->app->get_library_directory();
$cache['lib_namespace'] = ucfirst( $cache['lib_name'] );
$cache['lib_assets_dir'] = $cache['lib_dir'] . DS . 'assets';
$cache['lib_src_dir'] = $cache['lib_dir'] . DS . 'src';
$cache['lib_configs_dir'] = $cache['lib_dir'] . DS . 'configs';
$cache['lib_views_dir'] = $cache['lib_src_dir'] . DS . 'views';
$cache['lib_textdomain'] = TECHNOTE_PLUGIN;
$cache['lib_languages_dir'] = $cache['lib_dir'] . DS . 'languages';
$cache['lib_languages_rel_path'] = ltrim( str_replace( WP_PLUGIN_DIR, '', $cache['lib_languages_dir'] ), DS );
$cache['lib_vendor_dir'] = $cache['lib_dir'] . DS . 'vendor';
$cache['lib_assets_url'] = plugins_url( 'assets', $cache['lib_assets_dir'] );
$this->app->set_shared_object( 'lib_defines_cache', $cache, 'all' );
}
foreach ( $cache as $k => $v ) {
$this->$k = $v;
}
$this->plugin_assets_dir = $this->plugin_dir . DS . 'assets';
$this->plugin_src_dir = $this->plugin_dir . DS . 'src';
$this->plugin_configs_dir = $this->plugin_dir . DS . 'configs';
$this->plugin_views_dir = $this->plugin_src_dir . DS . 'views';
$domain_path = trim( $this->app->get_plugin_data( 'DomainPath' ), '/' . DS );
if ( empty( $domain_path ) || ! is_dir( $this->plugin_dir . DS . $domain_path ) ) {
$this->plugin_textdomain = false;
$this->plugin_languages_dir = false;
$this->plugin_languages_rel_path = false;
} else {
$this->plugin_textdomain = $this->app->get_plugin_data( 'TextDomain' );
$this->plugin_languages_dir = $this->plugin_dir . DS . $domain_path;
$this->plugin_languages_rel_path = ltrim( str_replace( WP_PLUGIN_DIR, '', $this->plugin_languages_dir ), DS );
}
$this->plugin_logs_dir = $this->plugin_dir . DS . 'logs';
if ( $this->app->is_theme ) {
$this->plugin_url = get_template_directory_uri();
if ( get_template_directory() !== get_stylesheet_directory() ) {
$this->child_theme_dir = get_stylesheet_directory();
$this->child_theme_url = get_stylesheet_directory_uri();
$this->child_theme_assets_dir = $this->child_theme_dir . DS . 'assets';
$this->child_theme_assets_url = $this->child_theme_url . '/assets';
}
} else {
$this->plugin_url = plugins_url( '', $this->plugin_file );
}
$this->plugin_assets_url = $this->plugin_url . '/assets';
} | php | protected function initialize() {
$this->plugin_name = $this->app->plugin_name;
$this->plugin_file = $this->app->plugin_file;
$this->plugin_namespace = ucwords( $this->plugin_name, '_' );
$this->plugin_dir = dirname( $this->plugin_file );
$this->plugin_dir_name = basename( $this->plugin_dir );
$this->plugin_base_name = $this->app->is_theme ? 'theme/' . $this->plugin_dir : plugin_basename( $this->plugin_file );
$cache = $this->app->get_shared_object( 'lib_defines_cache', 'all' );
if ( ! isset( $cache ) ) {
$cache = [];
$cache['lib_name'] = TECHNOTE_PLUGIN;
$cache['lib_dir'] = $this->app->get_library_directory();
$cache['lib_namespace'] = ucfirst( $cache['lib_name'] );
$cache['lib_assets_dir'] = $cache['lib_dir'] . DS . 'assets';
$cache['lib_src_dir'] = $cache['lib_dir'] . DS . 'src';
$cache['lib_configs_dir'] = $cache['lib_dir'] . DS . 'configs';
$cache['lib_views_dir'] = $cache['lib_src_dir'] . DS . 'views';
$cache['lib_textdomain'] = TECHNOTE_PLUGIN;
$cache['lib_languages_dir'] = $cache['lib_dir'] . DS . 'languages';
$cache['lib_languages_rel_path'] = ltrim( str_replace( WP_PLUGIN_DIR, '', $cache['lib_languages_dir'] ), DS );
$cache['lib_vendor_dir'] = $cache['lib_dir'] . DS . 'vendor';
$cache['lib_assets_url'] = plugins_url( 'assets', $cache['lib_assets_dir'] );
$this->app->set_shared_object( 'lib_defines_cache', $cache, 'all' );
}
foreach ( $cache as $k => $v ) {
$this->$k = $v;
}
$this->plugin_assets_dir = $this->plugin_dir . DS . 'assets';
$this->plugin_src_dir = $this->plugin_dir . DS . 'src';
$this->plugin_configs_dir = $this->plugin_dir . DS . 'configs';
$this->plugin_views_dir = $this->plugin_src_dir . DS . 'views';
$domain_path = trim( $this->app->get_plugin_data( 'DomainPath' ), '/' . DS );
if ( empty( $domain_path ) || ! is_dir( $this->plugin_dir . DS . $domain_path ) ) {
$this->plugin_textdomain = false;
$this->plugin_languages_dir = false;
$this->plugin_languages_rel_path = false;
} else {
$this->plugin_textdomain = $this->app->get_plugin_data( 'TextDomain' );
$this->plugin_languages_dir = $this->plugin_dir . DS . $domain_path;
$this->plugin_languages_rel_path = ltrim( str_replace( WP_PLUGIN_DIR, '', $this->plugin_languages_dir ), DS );
}
$this->plugin_logs_dir = $this->plugin_dir . DS . 'logs';
if ( $this->app->is_theme ) {
$this->plugin_url = get_template_directory_uri();
if ( get_template_directory() !== get_stylesheet_directory() ) {
$this->child_theme_dir = get_stylesheet_directory();
$this->child_theme_url = get_stylesheet_directory_uri();
$this->child_theme_assets_dir = $this->child_theme_dir . DS . 'assets';
$this->child_theme_assets_url = $this->child_theme_url . '/assets';
}
} else {
$this->plugin_url = plugins_url( '', $this->plugin_file );
}
$this->plugin_assets_url = $this->plugin_url . '/assets';
} | [
"protected",
"function",
"initialize",
"(",
")",
"{",
"$",
"this",
"->",
"plugin_name",
"=",
"$",
"this",
"->",
"app",
"->",
"plugin_name",
";",
"$",
"this",
"->",
"plugin_file",
"=",
"$",
"this",
"->",
"app",
"->",
"plugin_file",
";",
"$",
"this",
"->",
"plugin_namespace",
"=",
"ucwords",
"(",
"$",
"this",
"->",
"plugin_name",
",",
"'_'",
")",
";",
"$",
"this",
"->",
"plugin_dir",
"=",
"dirname",
"(",
"$",
"this",
"->",
"plugin_file",
")",
";",
"$",
"this",
"->",
"plugin_dir_name",
"=",
"basename",
"(",
"$",
"this",
"->",
"plugin_dir",
")",
";",
"$",
"this",
"->",
"plugin_base_name",
"=",
"$",
"this",
"->",
"app",
"->",
"is_theme",
"?",
"'theme/'",
".",
"$",
"this",
"->",
"plugin_dir",
":",
"plugin_basename",
"(",
"$",
"this",
"->",
"plugin_file",
")",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"app",
"->",
"get_shared_object",
"(",
"'lib_defines_cache'",
",",
"'all'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"cache",
")",
")",
"{",
"$",
"cache",
"=",
"[",
"]",
";",
"$",
"cache",
"[",
"'lib_name'",
"]",
"=",
"TECHNOTE_PLUGIN",
";",
"$",
"cache",
"[",
"'lib_dir'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"get_library_directory",
"(",
")",
";",
"$",
"cache",
"[",
"'lib_namespace'",
"]",
"=",
"ucfirst",
"(",
"$",
"cache",
"[",
"'lib_name'",
"]",
")",
";",
"$",
"cache",
"[",
"'lib_assets_dir'",
"]",
"=",
"$",
"cache",
"[",
"'lib_dir'",
"]",
".",
"DS",
".",
"'assets'",
";",
"$",
"cache",
"[",
"'lib_src_dir'",
"]",
"=",
"$",
"cache",
"[",
"'lib_dir'",
"]",
".",
"DS",
".",
"'src'",
";",
"$",
"cache",
"[",
"'lib_configs_dir'",
"]",
"=",
"$",
"cache",
"[",
"'lib_dir'",
"]",
".",
"DS",
".",
"'configs'",
";",
"$",
"cache",
"[",
"'lib_views_dir'",
"]",
"=",
"$",
"cache",
"[",
"'lib_src_dir'",
"]",
".",
"DS",
".",
"'views'",
";",
"$",
"cache",
"[",
"'lib_textdomain'",
"]",
"=",
"TECHNOTE_PLUGIN",
";",
"$",
"cache",
"[",
"'lib_languages_dir'",
"]",
"=",
"$",
"cache",
"[",
"'lib_dir'",
"]",
".",
"DS",
".",
"'languages'",
";",
"$",
"cache",
"[",
"'lib_languages_rel_path'",
"]",
"=",
"ltrim",
"(",
"str_replace",
"(",
"WP_PLUGIN_DIR",
",",
"''",
",",
"$",
"cache",
"[",
"'lib_languages_dir'",
"]",
")",
",",
"DS",
")",
";",
"$",
"cache",
"[",
"'lib_vendor_dir'",
"]",
"=",
"$",
"cache",
"[",
"'lib_dir'",
"]",
".",
"DS",
".",
"'vendor'",
";",
"$",
"cache",
"[",
"'lib_assets_url'",
"]",
"=",
"plugins_url",
"(",
"'assets'",
",",
"$",
"cache",
"[",
"'lib_assets_dir'",
"]",
")",
";",
"$",
"this",
"->",
"app",
"->",
"set_shared_object",
"(",
"'lib_defines_cache'",
",",
"$",
"cache",
",",
"'all'",
")",
";",
"}",
"foreach",
"(",
"$",
"cache",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"$",
"k",
"=",
"$",
"v",
";",
"}",
"$",
"this",
"->",
"plugin_assets_dir",
"=",
"$",
"this",
"->",
"plugin_dir",
".",
"DS",
".",
"'assets'",
";",
"$",
"this",
"->",
"plugin_src_dir",
"=",
"$",
"this",
"->",
"plugin_dir",
".",
"DS",
".",
"'src'",
";",
"$",
"this",
"->",
"plugin_configs_dir",
"=",
"$",
"this",
"->",
"plugin_dir",
".",
"DS",
".",
"'configs'",
";",
"$",
"this",
"->",
"plugin_views_dir",
"=",
"$",
"this",
"->",
"plugin_src_dir",
".",
"DS",
".",
"'views'",
";",
"$",
"domain_path",
"=",
"trim",
"(",
"$",
"this",
"->",
"app",
"->",
"get_plugin_data",
"(",
"'DomainPath'",
")",
",",
"'/'",
".",
"DS",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"domain_path",
")",
"||",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"plugin_dir",
".",
"DS",
".",
"$",
"domain_path",
")",
")",
"{",
"$",
"this",
"->",
"plugin_textdomain",
"=",
"false",
";",
"$",
"this",
"->",
"plugin_languages_dir",
"=",
"false",
";",
"$",
"this",
"->",
"plugin_languages_rel_path",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"plugin_textdomain",
"=",
"$",
"this",
"->",
"app",
"->",
"get_plugin_data",
"(",
"'TextDomain'",
")",
";",
"$",
"this",
"->",
"plugin_languages_dir",
"=",
"$",
"this",
"->",
"plugin_dir",
".",
"DS",
".",
"$",
"domain_path",
";",
"$",
"this",
"->",
"plugin_languages_rel_path",
"=",
"ltrim",
"(",
"str_replace",
"(",
"WP_PLUGIN_DIR",
",",
"''",
",",
"$",
"this",
"->",
"plugin_languages_dir",
")",
",",
"DS",
")",
";",
"}",
"$",
"this",
"->",
"plugin_logs_dir",
"=",
"$",
"this",
"->",
"plugin_dir",
".",
"DS",
".",
"'logs'",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"is_theme",
")",
"{",
"$",
"this",
"->",
"plugin_url",
"=",
"get_template_directory_uri",
"(",
")",
";",
"if",
"(",
"get_template_directory",
"(",
")",
"!==",
"get_stylesheet_directory",
"(",
")",
")",
"{",
"$",
"this",
"->",
"child_theme_dir",
"=",
"get_stylesheet_directory",
"(",
")",
";",
"$",
"this",
"->",
"child_theme_url",
"=",
"get_stylesheet_directory_uri",
"(",
")",
";",
"$",
"this",
"->",
"child_theme_assets_dir",
"=",
"$",
"this",
"->",
"child_theme_dir",
".",
"DS",
".",
"'assets'",
";",
"$",
"this",
"->",
"child_theme_assets_url",
"=",
"$",
"this",
"->",
"child_theme_url",
".",
"'/assets'",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"plugin_url",
"=",
"plugins_url",
"(",
"''",
",",
"$",
"this",
"->",
"plugin_file",
")",
";",
"}",
"$",
"this",
"->",
"plugin_assets_url",
"=",
"$",
"this",
"->",
"plugin_url",
".",
"'/assets'",
";",
"}"
] | initialize
@since 2.1.0 Changed: load textdomain from plugin data
@since 2.10.1 Improved: for theme (#115) | [
"initialize"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/define.php#L109-L167 |
odiaseo/pagebuilder | src/PageBuilder/View/Helper/PageBuilder.php | PageBuilder.init | public function init($pageId, Navigation $menuTree = null, AbstractEntity $activeSiteTheme = null)
{
if ($this->getOptions()->getEnabled()) {
/** @var PageTemplateModel $templateModel */
/** @var PageModel $pageModel */
/** @var LayoutService $layoutService */
/** @var Site $site */
$templateModel = $this->getServiceLocator()->get('pagebuilder\model\pageTemplate');
$layoutService = $this->getServiceLocator()->get('pagebuilder\service\layout');
$site = $this->getServiceLocator()->get('active\site');
$siteThemeId = $activeSiteTheme ? $activeSiteTheme->getId() : 'default';
$pageTemplate = $templateModel->getActivePageThemeForSite($pageId, $siteThemeId, $site->getId());
$this->menuTree = $menuTree;
if ($pageTemplate) {
$layout = $pageTemplate->getTemplate()->getLayout();
$this->activeTheme = $pageTemplate->getTemplate()->getTheme();
}
if (empty($layout)) {
//get layout from the page root from the tree
$layout = $layoutService->resolvePageLayout($pageId);
}
if (empty($this->activeTheme)) {
$this->activeTheme = $activeSiteTheme;
}
foreach ($layout as $index => &$template) {
if (array_key_exists('status', $template) and empty($template['status'])) {
unset($layout[$index]);
} else {
$sectionAttr = isset($template['tagAttributes']) ? $template['tagAttributes'] : [];
$secAttrObj = new TagAttributes($sectionAttr);
if ($secAttrObj->getActive()) {
$template['tagAttributes'] = $secAttrObj;
if (isset($template['items'])) {
foreach ($template['items'] as &$row) {
$rowAttr = isset($row['tagAttributes']) ? $row['tagAttributes'] : [];
$row['tagAttributes'] = new TagAttributes($rowAttr);
if (isset($row['rowItems'])) {
foreach ($row['rowItems'] as &$col) {
$colAttr = isset($col['tagAttributes']) ? $col['tagAttributes']
: [];
$col['tagAttributes'] = new TagAttributes($colAttr);
if (isset($col['item'])) {
foreach ($col['item'] as $index => $item) {
list($itemType, $itemId) = explode('-', $item['name']);
$attr = isset($item['tagAttributes'])
? $item['tagAttributes']
: [];
$item['tagAttributes'] = new TagAttributes($attr);
$col['item'][$index] = $this->getItem(
$itemType, $itemId, $item['tagAttributes']
);
}
} else {
$col['item'] = [];
}
}
}
}
}
}
}
}
$this->layout = $layout;
}
return $this;
} | php | public function init($pageId, Navigation $menuTree = null, AbstractEntity $activeSiteTheme = null)
{
if ($this->getOptions()->getEnabled()) {
/** @var PageTemplateModel $templateModel */
/** @var PageModel $pageModel */
/** @var LayoutService $layoutService */
/** @var Site $site */
$templateModel = $this->getServiceLocator()->get('pagebuilder\model\pageTemplate');
$layoutService = $this->getServiceLocator()->get('pagebuilder\service\layout');
$site = $this->getServiceLocator()->get('active\site');
$siteThemeId = $activeSiteTheme ? $activeSiteTheme->getId() : 'default';
$pageTemplate = $templateModel->getActivePageThemeForSite($pageId, $siteThemeId, $site->getId());
$this->menuTree = $menuTree;
if ($pageTemplate) {
$layout = $pageTemplate->getTemplate()->getLayout();
$this->activeTheme = $pageTemplate->getTemplate()->getTheme();
}
if (empty($layout)) {
//get layout from the page root from the tree
$layout = $layoutService->resolvePageLayout($pageId);
}
if (empty($this->activeTheme)) {
$this->activeTheme = $activeSiteTheme;
}
foreach ($layout as $index => &$template) {
if (array_key_exists('status', $template) and empty($template['status'])) {
unset($layout[$index]);
} else {
$sectionAttr = isset($template['tagAttributes']) ? $template['tagAttributes'] : [];
$secAttrObj = new TagAttributes($sectionAttr);
if ($secAttrObj->getActive()) {
$template['tagAttributes'] = $secAttrObj;
if (isset($template['items'])) {
foreach ($template['items'] as &$row) {
$rowAttr = isset($row['tagAttributes']) ? $row['tagAttributes'] : [];
$row['tagAttributes'] = new TagAttributes($rowAttr);
if (isset($row['rowItems'])) {
foreach ($row['rowItems'] as &$col) {
$colAttr = isset($col['tagAttributes']) ? $col['tagAttributes']
: [];
$col['tagAttributes'] = new TagAttributes($colAttr);
if (isset($col['item'])) {
foreach ($col['item'] as $index => $item) {
list($itemType, $itemId) = explode('-', $item['name']);
$attr = isset($item['tagAttributes'])
? $item['tagAttributes']
: [];
$item['tagAttributes'] = new TagAttributes($attr);
$col['item'][$index] = $this->getItem(
$itemType, $itemId, $item['tagAttributes']
);
}
} else {
$col['item'] = [];
}
}
}
}
}
}
}
}
$this->layout = $layout;
}
return $this;
} | [
"public",
"function",
"init",
"(",
"$",
"pageId",
",",
"Navigation",
"$",
"menuTree",
"=",
"null",
",",
"AbstractEntity",
"$",
"activeSiteTheme",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getEnabled",
"(",
")",
")",
"{",
"/** @var PageTemplateModel $templateModel */",
"/** @var PageModel $pageModel */",
"/** @var LayoutService $layoutService */",
"/** @var Site $site */",
"$",
"templateModel",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'pagebuilder\\model\\pageTemplate'",
")",
";",
"$",
"layoutService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'pagebuilder\\service\\layout'",
")",
";",
"$",
"site",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'active\\site'",
")",
";",
"$",
"siteThemeId",
"=",
"$",
"activeSiteTheme",
"?",
"$",
"activeSiteTheme",
"->",
"getId",
"(",
")",
":",
"'default'",
";",
"$",
"pageTemplate",
"=",
"$",
"templateModel",
"->",
"getActivePageThemeForSite",
"(",
"$",
"pageId",
",",
"$",
"siteThemeId",
",",
"$",
"site",
"->",
"getId",
"(",
")",
")",
";",
"$",
"this",
"->",
"menuTree",
"=",
"$",
"menuTree",
";",
"if",
"(",
"$",
"pageTemplate",
")",
"{",
"$",
"layout",
"=",
"$",
"pageTemplate",
"->",
"getTemplate",
"(",
")",
"->",
"getLayout",
"(",
")",
";",
"$",
"this",
"->",
"activeTheme",
"=",
"$",
"pageTemplate",
"->",
"getTemplate",
"(",
")",
"->",
"getTheme",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"layout",
")",
")",
"{",
"//get layout from the page root from the tree\r",
"$",
"layout",
"=",
"$",
"layoutService",
"->",
"resolvePageLayout",
"(",
"$",
"pageId",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"activeTheme",
")",
")",
"{",
"$",
"this",
"->",
"activeTheme",
"=",
"$",
"activeSiteTheme",
";",
"}",
"foreach",
"(",
"$",
"layout",
"as",
"$",
"index",
"=>",
"&",
"$",
"template",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'status'",
",",
"$",
"template",
")",
"and",
"empty",
"(",
"$",
"template",
"[",
"'status'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"layout",
"[",
"$",
"index",
"]",
")",
";",
"}",
"else",
"{",
"$",
"sectionAttr",
"=",
"isset",
"(",
"$",
"template",
"[",
"'tagAttributes'",
"]",
")",
"?",
"$",
"template",
"[",
"'tagAttributes'",
"]",
":",
"[",
"]",
";",
"$",
"secAttrObj",
"=",
"new",
"TagAttributes",
"(",
"$",
"sectionAttr",
")",
";",
"if",
"(",
"$",
"secAttrObj",
"->",
"getActive",
"(",
")",
")",
"{",
"$",
"template",
"[",
"'tagAttributes'",
"]",
"=",
"$",
"secAttrObj",
";",
"if",
"(",
"isset",
"(",
"$",
"template",
"[",
"'items'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"template",
"[",
"'items'",
"]",
"as",
"&",
"$",
"row",
")",
"{",
"$",
"rowAttr",
"=",
"isset",
"(",
"$",
"row",
"[",
"'tagAttributes'",
"]",
")",
"?",
"$",
"row",
"[",
"'tagAttributes'",
"]",
":",
"[",
"]",
";",
"$",
"row",
"[",
"'tagAttributes'",
"]",
"=",
"new",
"TagAttributes",
"(",
"$",
"rowAttr",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'rowItems'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"row",
"[",
"'rowItems'",
"]",
"as",
"&",
"$",
"col",
")",
"{",
"$",
"colAttr",
"=",
"isset",
"(",
"$",
"col",
"[",
"'tagAttributes'",
"]",
")",
"?",
"$",
"col",
"[",
"'tagAttributes'",
"]",
":",
"[",
"]",
";",
"$",
"col",
"[",
"'tagAttributes'",
"]",
"=",
"new",
"TagAttributes",
"(",
"$",
"colAttr",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"col",
"[",
"'item'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"col",
"[",
"'item'",
"]",
"as",
"$",
"index",
"=>",
"$",
"item",
")",
"{",
"list",
"(",
"$",
"itemType",
",",
"$",
"itemId",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"item",
"[",
"'name'",
"]",
")",
";",
"$",
"attr",
"=",
"isset",
"(",
"$",
"item",
"[",
"'tagAttributes'",
"]",
")",
"?",
"$",
"item",
"[",
"'tagAttributes'",
"]",
":",
"[",
"]",
";",
"$",
"item",
"[",
"'tagAttributes'",
"]",
"=",
"new",
"TagAttributes",
"(",
"$",
"attr",
")",
";",
"$",
"col",
"[",
"'item'",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"getItem",
"(",
"$",
"itemType",
",",
"$",
"itemId",
",",
"$",
"item",
"[",
"'tagAttributes'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"col",
"[",
"'item'",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"layout",
"=",
"$",
"layout",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Prepare page data and widgets
Get the active site theme and find a layout for the the current page that matches the site theme
If not layout is found, use the template assigned to the page if set
@param int $pageId
@param Navigation $menuTree
@param AbstractEntity $activeSiteTheme
@return $this | [
"Prepare",
"page",
"data",
"and",
"widgets",
"Get",
"the",
"active",
"site",
"theme",
"and",
"find",
"a",
"layout",
"for",
"the",
"the",
"current",
"page",
"that",
"matches",
"the",
"site",
"theme",
"If",
"not",
"layout",
"is",
"found",
"use",
"the",
"template",
"assigned",
"to",
"the",
"page",
"if",
"set"
] | train | https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/View/Helper/PageBuilder.php#L77-L150 |
odiaseo/pagebuilder | src/PageBuilder/View/Helper/PageBuilder.php | PageBuilder.getItem | protected function getItem($itemType, $itemId, TagAttributes $attr)
{
$data = '';
switch ($itemType) {
case self::LAYOUT_WIDGET:
try {
/** @var $data \PageBuilder\BaseWidget */
$widgetName = $itemId . WidgetFactory::WIDGET_SUFFIX;
$options = $attr->getOptions();
if (!$this->isShared($options)) {
$this->getServiceLocator()->setShared($widgetName, false);
}
if (array_key_exists('shared', $options) and empty($options['shared'])) {
$this->getServiceLocator()->setShared($widgetName, false);
}
$data = $this->getServiceLocator()->get($widgetName);
$attr->addClass($data->getId());
$data->setAttributes($attr);
} catch (ServiceNotFoundException $e) {
$data = '';
}
break;
case self::LAYOUT_USER_DEFINED:
/** @var $componentModel \PageBuilder\Model\ComponentModel */
$componentModel = $this->getServiceLocator()->get('pagebuilder\model\component');
/** @var $component \PageBuilder\Entity\Component */
if ($component = $componentModel->findOneTranslatedBy(['id' => $itemId])) {
$data = $this->transform($component->getContent());
$comId = "data-id='{$itemType}-{$itemId}'";
$cssClass = trim("{$itemType} {$component->getCssClass()}");
$attr->addClass($cssClass)
->addClass($component->getCssId())
->addAttr($comId)
->addAttr("id='{$component->getCssId()}'");
//Apply replaces to the output
$replacements = $this->getOptions()->getReplacements();
$data = str_replace(array_keys($replacements), array_values($replacements), $data);
//apply formats to the data
$data = $this->applyFormats($data);
}
break;
default:
$message = 'Layout itemType ' . $itemType . ' not found';
if ($this->serviceManager->has('logger')) {
$this->serviceManager->get('logger')->err($message);
} else {
throw new RuntimeException($message);
}
}
return new WidgetData(
[
'data' => $data,
'attributes' => $attr,
]
);
} | php | protected function getItem($itemType, $itemId, TagAttributes $attr)
{
$data = '';
switch ($itemType) {
case self::LAYOUT_WIDGET:
try {
/** @var $data \PageBuilder\BaseWidget */
$widgetName = $itemId . WidgetFactory::WIDGET_SUFFIX;
$options = $attr->getOptions();
if (!$this->isShared($options)) {
$this->getServiceLocator()->setShared($widgetName, false);
}
if (array_key_exists('shared', $options) and empty($options['shared'])) {
$this->getServiceLocator()->setShared($widgetName, false);
}
$data = $this->getServiceLocator()->get($widgetName);
$attr->addClass($data->getId());
$data->setAttributes($attr);
} catch (ServiceNotFoundException $e) {
$data = '';
}
break;
case self::LAYOUT_USER_DEFINED:
/** @var $componentModel \PageBuilder\Model\ComponentModel */
$componentModel = $this->getServiceLocator()->get('pagebuilder\model\component');
/** @var $component \PageBuilder\Entity\Component */
if ($component = $componentModel->findOneTranslatedBy(['id' => $itemId])) {
$data = $this->transform($component->getContent());
$comId = "data-id='{$itemType}-{$itemId}'";
$cssClass = trim("{$itemType} {$component->getCssClass()}");
$attr->addClass($cssClass)
->addClass($component->getCssId())
->addAttr($comId)
->addAttr("id='{$component->getCssId()}'");
//Apply replaces to the output
$replacements = $this->getOptions()->getReplacements();
$data = str_replace(array_keys($replacements), array_values($replacements), $data);
//apply formats to the data
$data = $this->applyFormats($data);
}
break;
default:
$message = 'Layout itemType ' . $itemType . ' not found';
if ($this->serviceManager->has('logger')) {
$this->serviceManager->get('logger')->err($message);
} else {
throw new RuntimeException($message);
}
}
return new WidgetData(
[
'data' => $data,
'attributes' => $attr,
]
);
} | [
"protected",
"function",
"getItem",
"(",
"$",
"itemType",
",",
"$",
"itemId",
",",
"TagAttributes",
"$",
"attr",
")",
"{",
"$",
"data",
"=",
"''",
";",
"switch",
"(",
"$",
"itemType",
")",
"{",
"case",
"self",
"::",
"LAYOUT_WIDGET",
":",
"try",
"{",
"/** @var $data \\PageBuilder\\BaseWidget */",
"$",
"widgetName",
"=",
"$",
"itemId",
".",
"WidgetFactory",
"::",
"WIDGET_SUFFIX",
";",
"$",
"options",
"=",
"$",
"attr",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isShared",
"(",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"setShared",
"(",
"$",
"widgetName",
",",
"false",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'shared'",
",",
"$",
"options",
")",
"and",
"empty",
"(",
"$",
"options",
"[",
"'shared'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"setShared",
"(",
"$",
"widgetName",
",",
"false",
")",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"$",
"widgetName",
")",
";",
"$",
"attr",
"->",
"addClass",
"(",
"$",
"data",
"->",
"getId",
"(",
")",
")",
";",
"$",
"data",
"->",
"setAttributes",
"(",
"$",
"attr",
")",
";",
"}",
"catch",
"(",
"ServiceNotFoundException",
"$",
"e",
")",
"{",
"$",
"data",
"=",
"''",
";",
"}",
"break",
";",
"case",
"self",
"::",
"LAYOUT_USER_DEFINED",
":",
"/** @var $componentModel \\PageBuilder\\Model\\ComponentModel */",
"$",
"componentModel",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'pagebuilder\\model\\component'",
")",
";",
"/** @var $component \\PageBuilder\\Entity\\Component */",
"if",
"(",
"$",
"component",
"=",
"$",
"componentModel",
"->",
"findOneTranslatedBy",
"(",
"[",
"'id'",
"=>",
"$",
"itemId",
"]",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"transform",
"(",
"$",
"component",
"->",
"getContent",
"(",
")",
")",
";",
"$",
"comId",
"=",
"\"data-id='{$itemType}-{$itemId}'\"",
";",
"$",
"cssClass",
"=",
"trim",
"(",
"\"{$itemType} {$component->getCssClass()}\"",
")",
";",
"$",
"attr",
"->",
"addClass",
"(",
"$",
"cssClass",
")",
"->",
"addClass",
"(",
"$",
"component",
"->",
"getCssId",
"(",
")",
")",
"->",
"addAttr",
"(",
"$",
"comId",
")",
"->",
"addAttr",
"(",
"\"id='{$component->getCssId()}'\"",
")",
";",
"//Apply replaces to the output\r",
"$",
"replacements",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getReplacements",
"(",
")",
";",
"$",
"data",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"replacements",
")",
",",
"array_values",
"(",
"$",
"replacements",
")",
",",
"$",
"data",
")",
";",
"//apply formats to the data\r",
"$",
"data",
"=",
"$",
"this",
"->",
"applyFormats",
"(",
"$",
"data",
")",
";",
"}",
"break",
";",
"default",
":",
"$",
"message",
"=",
"'Layout itemType '",
".",
"$",
"itemType",
".",
"' not found'",
";",
"if",
"(",
"$",
"this",
"->",
"serviceManager",
"->",
"has",
"(",
"'logger'",
")",
")",
"{",
"$",
"this",
"->",
"serviceManager",
"->",
"get",
"(",
"'logger'",
")",
"->",
"err",
"(",
"$",
"message",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"}",
"return",
"new",
"WidgetData",
"(",
"[",
"'data'",
"=>",
"$",
"data",
",",
"'attributes'",
"=>",
"$",
"attr",
",",
"]",
")",
";",
"}"
] | @param $itemType
@param $itemId
@param TagAttributes $attr
@return object
@throws RuntimeException | [
"@param",
"$itemType",
"@param",
"$itemId",
"@param",
"TagAttributes",
"$attr"
] | train | https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/View/Helper/PageBuilder.php#L259-L325 |
odiaseo/pagebuilder | src/PageBuilder/View/Helper/PageBuilder.php | PageBuilder.applyFormats | protected function applyFormats($data)
{
if ($this->getOptions()->getOutputFormatters()) {
foreach ($this->getOptions()->getOutputFormatters() as $formatter) {
if ($formatter instanceof FormatterInterface) {
/** @var $formatter \PageBuilder\FormatterInterface */
$data = $formatter->format($data);
} elseif (is_callable($formatter)) {
$data = $formatter($data, $this->serviceManager);
}
}
}
return $data;
} | php | protected function applyFormats($data)
{
if ($this->getOptions()->getOutputFormatters()) {
foreach ($this->getOptions()->getOutputFormatters() as $formatter) {
if ($formatter instanceof FormatterInterface) {
/** @var $formatter \PageBuilder\FormatterInterface */
$data = $formatter->format($data);
} elseif (is_callable($formatter)) {
$data = $formatter($data, $this->serviceManager);
}
}
}
return $data;
} | [
"protected",
"function",
"applyFormats",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getOutputFormatters",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getOutputFormatters",
"(",
")",
"as",
"$",
"formatter",
")",
"{",
"if",
"(",
"$",
"formatter",
"instanceof",
"FormatterInterface",
")",
"{",
"/** @var $formatter \\PageBuilder\\FormatterInterface */",
"$",
"data",
"=",
"$",
"formatter",
"->",
"format",
"(",
"$",
"data",
")",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"formatter",
")",
")",
"{",
"$",
"data",
"=",
"$",
"formatter",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"serviceManager",
")",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Apply formatter using the formatters in the order they were defined
@param $data
@return string | [
"Apply",
"formatter",
"using",
"the",
"formatters",
"in",
"the",
"order",
"they",
"were",
"defined"
] | train | https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/View/Helper/PageBuilder.php#L334-L349 |
odiaseo/pagebuilder | src/PageBuilder/View/Helper/PageBuilder.php | PageBuilder.setServiceLocator | public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
/** @var ServiceManager $serviceLocator */
$this->serviceManager = $serviceLocator;
$this->serviceManager->setAllowOverride(true);
$this->setPluginManager($serviceLocator);
return $this;
} | php | public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
/** @var ServiceManager $serviceLocator */
$this->serviceManager = $serviceLocator;
$this->serviceManager->setAllowOverride(true);
$this->setPluginManager($serviceLocator);
return $this;
} | [
"public",
"function",
"setServiceLocator",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"/** @var ServiceManager $serviceLocator */",
"$",
"this",
"->",
"serviceManager",
"=",
"$",
"serviceLocator",
";",
"$",
"this",
"->",
"serviceManager",
"->",
"setAllowOverride",
"(",
"true",
")",
";",
"$",
"this",
"->",
"setPluginManager",
"(",
"$",
"serviceLocator",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param ServiceLocatorInterface $serviceLocator
@return $this | [
"@param",
"ServiceLocatorInterface",
"$serviceLocator"
] | train | https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/View/Helper/PageBuilder.php#L378-L386 |
odiaseo/pagebuilder | src/PageBuilder/View/Helper/PageBuilder.php | PageBuilder.getTopBottomContainers | protected function getTopBottomContainers(TagAttributes $attr, $section = '')
{
$top = $bottom = '';
if ($wrapper = $attr->getWrapper()) {
/** @var $microDataHelper MicroData */
$microDataHelper = $this->pluginManager->get('microData');
switch ($section) {
case 'header':
$microData = $microDataHelper->scopeAndProperty('WebPage', 'WPHeader');
break;
case 'footer':
$microData = $microDataHelper->scopeAndProperty('WebPage', 'WPFooter');
break;
default:
$microData = '';
break;
}
$variables = [
trim($wrapper),
$this->transform(trim($attr->formatClass())),
trim($attr->formatId()),
trim($attr->formatAttr()),
trim($microData),
];
$variables = array_filter($variables);
$top .= sprintf('<%s>', implode(' ', $variables));
}
if ($containerClass = $attr->getContainer()) {
$top .= '<div class="' . $this->transform($containerClass) . '">';
$bottom .= '</div>';
if ($container2 = $attr->getContainer2()) {
$top .= '<div class="' . $this->transform($container2) . '">';
$bottom .= '</div>';
}
}
//main wrapper close
if ($wrapper) {
$bottom .= '</' . $wrapper . '>';
}
return [$top, $bottom];
} | php | protected function getTopBottomContainers(TagAttributes $attr, $section = '')
{
$top = $bottom = '';
if ($wrapper = $attr->getWrapper()) {
/** @var $microDataHelper MicroData */
$microDataHelper = $this->pluginManager->get('microData');
switch ($section) {
case 'header':
$microData = $microDataHelper->scopeAndProperty('WebPage', 'WPHeader');
break;
case 'footer':
$microData = $microDataHelper->scopeAndProperty('WebPage', 'WPFooter');
break;
default:
$microData = '';
break;
}
$variables = [
trim($wrapper),
$this->transform(trim($attr->formatClass())),
trim($attr->formatId()),
trim($attr->formatAttr()),
trim($microData),
];
$variables = array_filter($variables);
$top .= sprintf('<%s>', implode(' ', $variables));
}
if ($containerClass = $attr->getContainer()) {
$top .= '<div class="' . $this->transform($containerClass) . '">';
$bottom .= '</div>';
if ($container2 = $attr->getContainer2()) {
$top .= '<div class="' . $this->transform($container2) . '">';
$bottom .= '</div>';
}
}
//main wrapper close
if ($wrapper) {
$bottom .= '</' . $wrapper . '>';
}
return [$top, $bottom];
} | [
"protected",
"function",
"getTopBottomContainers",
"(",
"TagAttributes",
"$",
"attr",
",",
"$",
"section",
"=",
"''",
")",
"{",
"$",
"top",
"=",
"$",
"bottom",
"=",
"''",
";",
"if",
"(",
"$",
"wrapper",
"=",
"$",
"attr",
"->",
"getWrapper",
"(",
")",
")",
"{",
"/** @var $microDataHelper MicroData */",
"$",
"microDataHelper",
"=",
"$",
"this",
"->",
"pluginManager",
"->",
"get",
"(",
"'microData'",
")",
";",
"switch",
"(",
"$",
"section",
")",
"{",
"case",
"'header'",
":",
"$",
"microData",
"=",
"$",
"microDataHelper",
"->",
"scopeAndProperty",
"(",
"'WebPage'",
",",
"'WPHeader'",
")",
";",
"break",
";",
"case",
"'footer'",
":",
"$",
"microData",
"=",
"$",
"microDataHelper",
"->",
"scopeAndProperty",
"(",
"'WebPage'",
",",
"'WPFooter'",
")",
";",
"break",
";",
"default",
":",
"$",
"microData",
"=",
"''",
";",
"break",
";",
"}",
"$",
"variables",
"=",
"[",
"trim",
"(",
"$",
"wrapper",
")",
",",
"$",
"this",
"->",
"transform",
"(",
"trim",
"(",
"$",
"attr",
"->",
"formatClass",
"(",
")",
")",
")",
",",
"trim",
"(",
"$",
"attr",
"->",
"formatId",
"(",
")",
")",
",",
"trim",
"(",
"$",
"attr",
"->",
"formatAttr",
"(",
")",
")",
",",
"trim",
"(",
"$",
"microData",
")",
",",
"]",
";",
"$",
"variables",
"=",
"array_filter",
"(",
"$",
"variables",
")",
";",
"$",
"top",
".=",
"sprintf",
"(",
"'<%s>'",
",",
"implode",
"(",
"' '",
",",
"$",
"variables",
")",
")",
";",
"}",
"if",
"(",
"$",
"containerClass",
"=",
"$",
"attr",
"->",
"getContainer",
"(",
")",
")",
"{",
"$",
"top",
".=",
"'<div class=\"'",
".",
"$",
"this",
"->",
"transform",
"(",
"$",
"containerClass",
")",
".",
"'\">'",
";",
"$",
"bottom",
".=",
"'</div>'",
";",
"if",
"(",
"$",
"container2",
"=",
"$",
"attr",
"->",
"getContainer2",
"(",
")",
")",
"{",
"$",
"top",
".=",
"'<div class=\"'",
".",
"$",
"this",
"->",
"transform",
"(",
"$",
"container2",
")",
".",
"'\">'",
";",
"$",
"bottom",
".=",
"'</div>'",
";",
"}",
"}",
"//main wrapper close\r",
"if",
"(",
"$",
"wrapper",
")",
"{",
"$",
"bottom",
".=",
"'</'",
".",
"$",
"wrapper",
".",
"'>'",
";",
"}",
"return",
"[",
"$",
"top",
",",
"$",
"bottom",
"]",
";",
"}"
] | @param TagAttributes $attr
@param TagAttributes $attr
@param string $section
@return array | [
"@param",
"TagAttributes",
"$attr",
"@param",
"TagAttributes",
"$attr",
"@param",
"string",
"$section"
] | train | https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/View/Helper/PageBuilder.php#L405-L453 |
odiaseo/pagebuilder | src/PageBuilder/View/Helper/PageBuilder.php | PageBuilder.isShared | private function isShared($options)
{
if (!array_key_exists(self::SHARE_KEY, $options)) {
return true;
}
if (is_bool($options[self::SHARE_KEY])) {
return $options[self::SHARE_KEY];
}
if (is_numeric($options[self::SHARE_KEY])) {
$shared = $options[self::SHARE_KEY] * 1;
return ($shared <= 0) ? false : true;
}
if ($options[self::SHARE_KEY] == 'true') {
return true;
} else {
return false;
}
} | php | private function isShared($options)
{
if (!array_key_exists(self::SHARE_KEY, $options)) {
return true;
}
if (is_bool($options[self::SHARE_KEY])) {
return $options[self::SHARE_KEY];
}
if (is_numeric($options[self::SHARE_KEY])) {
$shared = $options[self::SHARE_KEY] * 1;
return ($shared <= 0) ? false : true;
}
if ($options[self::SHARE_KEY] == 'true') {
return true;
} else {
return false;
}
} | [
"private",
"function",
"isShared",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"self",
"::",
"SHARE_KEY",
",",
"$",
"options",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"options",
"[",
"self",
"::",
"SHARE_KEY",
"]",
")",
")",
"{",
"return",
"$",
"options",
"[",
"self",
"::",
"SHARE_KEY",
"]",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"options",
"[",
"self",
"::",
"SHARE_KEY",
"]",
")",
")",
"{",
"$",
"shared",
"=",
"$",
"options",
"[",
"self",
"::",
"SHARE_KEY",
"]",
"*",
"1",
";",
"return",
"(",
"$",
"shared",
"<=",
"0",
")",
"?",
"false",
":",
"true",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"self",
"::",
"SHARE_KEY",
"]",
"==",
"'true'",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | @param $options
@return bool | [
"@param",
"$options"
] | train | https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/View/Helper/PageBuilder.php#L476-L496 |
odiaseo/pagebuilder | src/PageBuilder/View/Helper/PageBuilder.php | PageBuilder.transform | protected function transform($class)
{
if ($this->options->getBootstrapVersion() > 2) {
foreach ($this->options->getCssClassmap() as $search => $replace) {
$pattern = '/' . $search . '/i';
if (preg_match($pattern, $class, $matches)) {
$done = str_replace($search, $replace, $class);
return $done;
}
}
}
return $class;
} | php | protected function transform($class)
{
if ($this->options->getBootstrapVersion() > 2) {
foreach ($this->options->getCssClassmap() as $search => $replace) {
$pattern = '/' . $search . '/i';
if (preg_match($pattern, $class, $matches)) {
$done = str_replace($search, $replace, $class);
return $done;
}
}
}
return $class;
} | [
"protected",
"function",
"transform",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"->",
"getBootstrapVersion",
"(",
")",
">",
"2",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"options",
"->",
"getCssClassmap",
"(",
")",
"as",
"$",
"search",
"=>",
"$",
"replace",
")",
"{",
"$",
"pattern",
"=",
"'/'",
".",
"$",
"search",
".",
"'/i'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"class",
",",
"$",
"matches",
")",
")",
"{",
"$",
"done",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"class",
")",
";",
"return",
"$",
"done",
";",
"}",
"}",
"}",
"return",
"$",
"class",
";",
"}"
] | @param $class
@return mixed | [
"@param",
"$class"
] | train | https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/View/Helper/PageBuilder.php#L503-L517 |
lokhman/silex-tools | src/Silex/Application/ToolsTrait.php | ToolsTrait.redirectToRoute | public function redirectToRoute($route, array $parameters = [], $status = 302)
{
return new RedirectResponse($this['url_generator']->generate($route, $parameters), $status);
} | php | public function redirectToRoute($route, array $parameters = [], $status = 302)
{
return new RedirectResponse($this['url_generator']->generate($route, $parameters), $status);
} | [
"public",
"function",
"redirectToRoute",
"(",
"$",
"route",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"status",
"=",
"302",
")",
"{",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"[",
"'url_generator'",
"]",
"->",
"generate",
"(",
"$",
"route",
",",
"$",
"parameters",
")",
",",
"$",
"status",
")",
";",
"}"
] | Redirects the user to route with the given parameters.
@param string $route The name of the route
@param mixed $parameters An array of parameters
@param int $status The status code (302 by default)
@return RedirectResponse | [
"Redirects",
"the",
"user",
"to",
"route",
"with",
"the",
"given",
"parameters",
"."
] | train | https://github.com/lokhman/silex-tools/blob/91e84099479beb4e866abc88a55ed1e457a8a9e9/src/Silex/Application/ToolsTrait.php#L54-L57 |
lokhman/silex-tools | src/Silex/Application/ToolsTrait.php | ToolsTrait.forward | public function forward($uri, $method, array $parameters = [])
{
$request = Request::create($uri, $method, $parameters);
return $this->handle($request, HttpKernelInterface::SUB_REQUEST);
} | php | public function forward($uri, $method, array $parameters = [])
{
$request = Request::create($uri, $method, $parameters);
return $this->handle($request, HttpKernelInterface::SUB_REQUEST);
} | [
"public",
"function",
"forward",
"(",
"$",
"uri",
",",
"$",
"method",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"request",
"=",
"Request",
"::",
"create",
"(",
"$",
"uri",
",",
"$",
"method",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"this",
"->",
"handle",
"(",
"$",
"request",
",",
"HttpKernelInterface",
"::",
"SUB_REQUEST",
")",
";",
"}"
] | Forward the request to another controller by the URI.
@param string $uri
@param string $method
@param array $parameters
@return Symfony\Component\HttpFoundation\Response | [
"Forward",
"the",
"request",
"to",
"another",
"controller",
"by",
"the",
"URI",
"."
] | train | https://github.com/lokhman/silex-tools/blob/91e84099479beb4e866abc88a55ed1e457a8a9e9/src/Silex/Application/ToolsTrait.php#L68-L73 |
lokhman/silex-tools | src/Silex/Application/ToolsTrait.php | ToolsTrait.forwardToRoute | public function forwardToRoute($route, $method, array $parameters = [])
{
return $this->forward($this['url_generator']->generate($route, $parameters), $method);
} | php | public function forwardToRoute($route, $method, array $parameters = [])
{
return $this->forward($this['url_generator']->generate($route, $parameters), $method);
} | [
"public",
"function",
"forwardToRoute",
"(",
"$",
"route",
",",
"$",
"method",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"forward",
"(",
"$",
"this",
"[",
"'url_generator'",
"]",
"->",
"generate",
"(",
"$",
"route",
",",
"$",
"parameters",
")",
",",
"$",
"method",
")",
";",
"}"
] | Forward the request to another controller by the route name.
@param string $route
@param string $method
@param array $parameters
@return Symfony\Component\HttpFoundation\Response | [
"Forward",
"the",
"request",
"to",
"another",
"controller",
"by",
"the",
"route",
"name",
"."
] | train | https://github.com/lokhman/silex-tools/blob/91e84099479beb4e866abc88a55ed1e457a8a9e9/src/Silex/Application/ToolsTrait.php#L84-L87 |
sabre-io/cs | lib/ControlSpaces.php | ControlSpaces.fix | function fix(\SplFileInfo $file, $content)
{
$tokens = Tokens::fromCode($content);
$controlStructureTokens = $this->getControlStructureTokens();
foreach ($tokens as $index => $token) {
// looking for start brace
if (!$token->equals('(')) {
continue;
}
// last non-whitespace token
$lastTokenIndex = $tokens->getPrevNonWhitespace($index);
if (null === $lastTokenIndex) {
continue;
}
// check if it is a control structure.
if ($tokens[$lastTokenIndex]->isGivenKind($controlStructureTokens)) {
$this->fixControlStructure($tokens, $index);
}
}
return $tokens->generateCode();
} | php | function fix(\SplFileInfo $file, $content)
{
$tokens = Tokens::fromCode($content);
$controlStructureTokens = $this->getControlStructureTokens();
foreach ($tokens as $index => $token) {
// looking for start brace
if (!$token->equals('(')) {
continue;
}
// last non-whitespace token
$lastTokenIndex = $tokens->getPrevNonWhitespace($index);
if (null === $lastTokenIndex) {
continue;
}
// check if it is a control structure.
if ($tokens[$lastTokenIndex]->isGivenKind($controlStructureTokens)) {
$this->fixControlStructure($tokens, $index);
}
}
return $tokens->generateCode();
} | [
"function",
"fix",
"(",
"\\",
"SplFileInfo",
"$",
"file",
",",
"$",
"content",
")",
"{",
"$",
"tokens",
"=",
"Tokens",
"::",
"fromCode",
"(",
"$",
"content",
")",
";",
"$",
"controlStructureTokens",
"=",
"$",
"this",
"->",
"getControlStructureTokens",
"(",
")",
";",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"index",
"=>",
"$",
"token",
")",
"{",
"// looking for start brace",
"if",
"(",
"!",
"$",
"token",
"->",
"equals",
"(",
"'('",
")",
")",
"{",
"continue",
";",
"}",
"// last non-whitespace token",
"$",
"lastTokenIndex",
"=",
"$",
"tokens",
"->",
"getPrevNonWhitespace",
"(",
"$",
"index",
")",
";",
"if",
"(",
"null",
"===",
"$",
"lastTokenIndex",
")",
"{",
"continue",
";",
"}",
"// check if it is a control structure.",
"if",
"(",
"$",
"tokens",
"[",
"$",
"lastTokenIndex",
"]",
"->",
"isGivenKind",
"(",
"$",
"controlStructureTokens",
")",
")",
"{",
"$",
"this",
"->",
"fixControlStructure",
"(",
"$",
"tokens",
",",
"$",
"index",
")",
";",
"}",
"}",
"return",
"$",
"tokens",
"->",
"generateCode",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/sabre-io/cs/blob/a4c57e213bf3f5e7d6b29a2f70d1ca4b0dce6d86/lib/ControlSpaces.php#L45-L72 |
sabre-io/cs | lib/ControlSpaces.php | ControlSpaces.fixControlStructure | private function fixControlStructure(Tokens $tokens, $index)
{
// Ensure a single whitespace
if (!$tokens[$index - 1]->isWhitespace() || $tokens[$index - 1]->isWhitespace($this->singleLineWhitespaceOptions)) {
$tokens->ensureWhitespaceAtIndex($index - 1, 1, ' ');
}
} | php | private function fixControlStructure(Tokens $tokens, $index)
{
// Ensure a single whitespace
if (!$tokens[$index - 1]->isWhitespace() || $tokens[$index - 1]->isWhitespace($this->singleLineWhitespaceOptions)) {
$tokens->ensureWhitespaceAtIndex($index - 1, 1, ' ');
}
} | [
"private",
"function",
"fixControlStructure",
"(",
"Tokens",
"$",
"tokens",
",",
"$",
"index",
")",
"{",
"// Ensure a single whitespace",
"if",
"(",
"!",
"$",
"tokens",
"[",
"$",
"index",
"-",
"1",
"]",
"->",
"isWhitespace",
"(",
")",
"||",
"$",
"tokens",
"[",
"$",
"index",
"-",
"1",
"]",
"->",
"isWhitespace",
"(",
"$",
"this",
"->",
"singleLineWhitespaceOptions",
")",
")",
"{",
"$",
"tokens",
"->",
"ensureWhitespaceAtIndex",
"(",
"$",
"index",
"-",
"1",
",",
"1",
",",
"' '",
")",
";",
"}",
"}"
] | Fixes whitespaces around braces of a control structure.
@param Tokens $tokens tokens to handle
@param int $index index of token | [
"Fixes",
"whitespaces",
"around",
"braces",
"of",
"a",
"control",
"structure",
"."
] | train | https://github.com/sabre-io/cs/blob/a4c57e213bf3f5e7d6b29a2f70d1ca4b0dce6d86/lib/ControlSpaces.php#L88-L95 |
sabre-io/cs | lib/ControlSpaces.php | ControlSpaces.getControlStructureTokens | private function getControlStructureTokens()
{
static $tokens = null;
if (null === $tokens) {
$tokens = [
T_IF,
T_ELSEIF,
T_FOR,
T_FOREACH,
T_WHILE,
T_DO,
T_CATCH,
T_SWITCH,
T_DECLARE,
];
}
return $tokens;
} | php | private function getControlStructureTokens()
{
static $tokens = null;
if (null === $tokens) {
$tokens = [
T_IF,
T_ELSEIF,
T_FOR,
T_FOREACH,
T_WHILE,
T_DO,
T_CATCH,
T_SWITCH,
T_DECLARE,
];
}
return $tokens;
} | [
"private",
"function",
"getControlStructureTokens",
"(",
")",
"{",
"static",
"$",
"tokens",
"=",
"null",
";",
"if",
"(",
"null",
"===",
"$",
"tokens",
")",
"{",
"$",
"tokens",
"=",
"[",
"T_IF",
",",
"T_ELSEIF",
",",
"T_FOR",
",",
"T_FOREACH",
",",
"T_WHILE",
",",
"T_DO",
",",
"T_CATCH",
",",
"T_SWITCH",
",",
"T_DECLARE",
",",
"]",
";",
"}",
"return",
"$",
"tokens",
";",
"}"
] | Gets the name of control structure tokens.
@staticvar string[] $tokens Token names.
@return string[] Token names. | [
"Gets",
"the",
"name",
"of",
"control",
"structure",
"tokens",
"."
] | train | https://github.com/sabre-io/cs/blob/a4c57e213bf3f5e7d6b29a2f70d1ca4b0dce6d86/lib/ControlSpaces.php#L104-L123 |
php-lug/lug | src/Bundle/ResourceBundle/DependencyInjection/Compiler/RegisterResourcePass.php | RegisterResourcePass.process | public function process(ContainerBuilder $container)
{
$registry = $container->getDefinition('lug.resource.registry');
foreach (array_keys($container->findTaggedServiceIds('lug.resource')) as $resource) {
$registry->addMethodCall('offsetSet', [
$container->getDefinition($resource)->getArgument(0),
new Reference($resource),
]);
}
} | php | public function process(ContainerBuilder $container)
{
$registry = $container->getDefinition('lug.resource.registry');
foreach (array_keys($container->findTaggedServiceIds('lug.resource')) as $resource) {
$registry->addMethodCall('offsetSet', [
$container->getDefinition($resource)->getArgument(0),
new Reference($resource),
]);
}
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"registry",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'lug.resource.registry'",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"'lug.resource'",
")",
")",
"as",
"$",
"resource",
")",
"{",
"$",
"registry",
"->",
"addMethodCall",
"(",
"'offsetSet'",
",",
"[",
"$",
"container",
"->",
"getDefinition",
"(",
"$",
"resource",
")",
"->",
"getArgument",
"(",
"0",
")",
",",
"new",
"Reference",
"(",
"$",
"resource",
")",
",",
"]",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/DependencyInjection/Compiler/RegisterResourcePass.php#L26-L36 |
blast-project/BaseEntitiesBundle | src/Entity/Traits/Addressable.php | Addressable.getFulltextAddress | public function getFulltextAddress($separator = "\n")
{
$elems = [];
if ($this->address) {
$elems[] = $this->address;
}
$zip_city = [];
if ($this->zip) {
$zip_city[] = $this->zip;
}
if ($this->city) {
$zip_city[] = $this->city;
}
if ($zip_city) {
$elems[] = implode(' ', $zip_city);
}
if ($this->country) {
$elems[] = $this->country;
}
return implode($separator, $elems);
} | php | public function getFulltextAddress($separator = "\n")
{
$elems = [];
if ($this->address) {
$elems[] = $this->address;
}
$zip_city = [];
if ($this->zip) {
$zip_city[] = $this->zip;
}
if ($this->city) {
$zip_city[] = $this->city;
}
if ($zip_city) {
$elems[] = implode(' ', $zip_city);
}
if ($this->country) {
$elems[] = $this->country;
}
return implode($separator, $elems);
} | [
"public",
"function",
"getFulltextAddress",
"(",
"$",
"separator",
"=",
"\"\\n\"",
")",
"{",
"$",
"elems",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"address",
")",
"{",
"$",
"elems",
"[",
"]",
"=",
"$",
"this",
"->",
"address",
";",
"}",
"$",
"zip_city",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"zip",
")",
"{",
"$",
"zip_city",
"[",
"]",
"=",
"$",
"this",
"->",
"zip",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"city",
")",
"{",
"$",
"zip_city",
"[",
"]",
"=",
"$",
"this",
"->",
"city",
";",
"}",
"if",
"(",
"$",
"zip_city",
")",
"{",
"$",
"elems",
"[",
"]",
"=",
"implode",
"(",
"' '",
",",
"$",
"zip_city",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"country",
")",
"{",
"$",
"elems",
"[",
"]",
"=",
"$",
"this",
"->",
"country",
";",
"}",
"return",
"implode",
"(",
"$",
"separator",
",",
"$",
"elems",
")",
";",
"}"
] | @param string $separator
@return string | [
"@param",
"string",
"$separator"
] | train | https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Entity/Traits/Addressable.php#L199-L221 |
AOEpeople/Aoe_Layout | app/code/local/Aoe/Layout/Block/Widget/Tabs.php | Aoe_Layout_Block_Widget_Tabs.addTab | public function addTab($tabId, $tab)
{
parent::addTab($tabId, $tab);
if ($this->_tabs[$tabId] instanceof Mage_Core_Block_Abstract && $this->_tabs[$tabId]->getParentBlock() === null) {
$this->append($this->_tabs[$tabId]);
}
return $this;
} | php | public function addTab($tabId, $tab)
{
parent::addTab($tabId, $tab);
if ($this->_tabs[$tabId] instanceof Mage_Core_Block_Abstract && $this->_tabs[$tabId]->getParentBlock() === null) {
$this->append($this->_tabs[$tabId]);
}
return $this;
} | [
"public",
"function",
"addTab",
"(",
"$",
"tabId",
",",
"$",
"tab",
")",
"{",
"parent",
"::",
"addTab",
"(",
"$",
"tabId",
",",
"$",
"tab",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_tabs",
"[",
"$",
"tabId",
"]",
"instanceof",
"Mage_Core_Block_Abstract",
"&&",
"$",
"this",
"->",
"_tabs",
"[",
"$",
"tabId",
"]",
"->",
"getParentBlock",
"(",
")",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"append",
"(",
"$",
"this",
"->",
"_tabs",
"[",
"$",
"tabId",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add new tab
@param string $tabId
@param array|Varien_Object $tab
@return Mage_Adminhtml_Block_Widget_Tabs | [
"Add",
"new",
"tab"
] | train | https://github.com/AOEpeople/Aoe_Layout/blob/d88ba3406cf12dbaf09548477133c3cb27d155ed/app/code/local/Aoe/Layout/Block/Widget/Tabs.php#L15-L24 |
NuclearCMS/Hierarchy | src/Builders/MigrationBuilder.php | MigrationBuilder.buildSourceTableMigration | public function buildSourceTableMigration($name)
{
$path = $this->getMigrationPath($name);
$migration = $this->getTableMigrationName($name);
$contents = view('_hierarchy::migrations.table', [
'table' => source_table_name($name),
'migration' => $migration
])->render();
$this->write($path, $contents);
return $this->getMigrationClassPath($migration);
} | php | public function buildSourceTableMigration($name)
{
$path = $this->getMigrationPath($name);
$migration = $this->getTableMigrationName($name);
$contents = view('_hierarchy::migrations.table', [
'table' => source_table_name($name),
'migration' => $migration
])->render();
$this->write($path, $contents);
return $this->getMigrationClassPath($migration);
} | [
"public",
"function",
"buildSourceTableMigration",
"(",
"$",
"name",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getMigrationPath",
"(",
"$",
"name",
")",
";",
"$",
"migration",
"=",
"$",
"this",
"->",
"getTableMigrationName",
"(",
"$",
"name",
")",
";",
"$",
"contents",
"=",
"view",
"(",
"'_hierarchy::migrations.table'",
",",
"[",
"'table'",
"=>",
"source_table_name",
"(",
"$",
"name",
")",
",",
"'migration'",
"=>",
"$",
"migration",
"]",
")",
"->",
"render",
"(",
")",
";",
"$",
"this",
"->",
"write",
"(",
"$",
"path",
",",
"$",
"contents",
")",
";",
"return",
"$",
"this",
"->",
"getMigrationClassPath",
"(",
"$",
"migration",
")",
";",
"}"
] | Builds a source table migration
@param string $name
@return string | [
"Builds",
"a",
"source",
"table",
"migration"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/MigrationBuilder.php#L81-L94 |
NuclearCMS/Hierarchy | src/Builders/MigrationBuilder.php | MigrationBuilder.destroySourceTableMigration | public function destroySourceTableMigration($name, array $fields)
{
$path = $this->getMigrationPath($name);
$this->delete($path);
foreach ($fields as $field)
{
$this->destroyFieldMigrationForTable($field, $name);
}
} | php | public function destroySourceTableMigration($name, array $fields)
{
$path = $this->getMigrationPath($name);
$this->delete($path);
foreach ($fields as $field)
{
$this->destroyFieldMigrationForTable($field, $name);
}
} | [
"public",
"function",
"destroySourceTableMigration",
"(",
"$",
"name",
",",
"array",
"$",
"fields",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getMigrationPath",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"delete",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"destroyFieldMigrationForTable",
"(",
"$",
"field",
",",
"$",
"name",
")",
";",
"}",
"}"
] | Destroy a source table migration
@param string $name
@param array $fields | [
"Destroy",
"a",
"source",
"table",
"migration"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/MigrationBuilder.php#L102-L112 |
NuclearCMS/Hierarchy | src/Builders/MigrationBuilder.php | MigrationBuilder.buildFieldMigrationForTable | public function buildFieldMigrationForTable($name, $type, $indexed, $tableName)
{
$path = $this->getMigrationPath($tableName, $name);
$migration = $this->getTableFieldMigrationName($name, $tableName);
$contents = view('_hierarchy::migrations.field', [
'field' => $name,
'table' => source_table_name($tableName),
'migration' => $migration,
'type' => $this->getColumnType($type),
'indexed' => $indexed
])->render();
$this->write($path, $contents);
return $this->getMigrationClassPath($migration);
} | php | public function buildFieldMigrationForTable($name, $type, $indexed, $tableName)
{
$path = $this->getMigrationPath($tableName, $name);
$migration = $this->getTableFieldMigrationName($name, $tableName);
$contents = view('_hierarchy::migrations.field', [
'field' => $name,
'table' => source_table_name($tableName),
'migration' => $migration,
'type' => $this->getColumnType($type),
'indexed' => $indexed
])->render();
$this->write($path, $contents);
return $this->getMigrationClassPath($migration);
} | [
"public",
"function",
"buildFieldMigrationForTable",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"indexed",
",",
"$",
"tableName",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getMigrationPath",
"(",
"$",
"tableName",
",",
"$",
"name",
")",
";",
"$",
"migration",
"=",
"$",
"this",
"->",
"getTableFieldMigrationName",
"(",
"$",
"name",
",",
"$",
"tableName",
")",
";",
"$",
"contents",
"=",
"view",
"(",
"'_hierarchy::migrations.field'",
",",
"[",
"'field'",
"=>",
"$",
"name",
",",
"'table'",
"=>",
"source_table_name",
"(",
"$",
"tableName",
")",
",",
"'migration'",
"=>",
"$",
"migration",
",",
"'type'",
"=>",
"$",
"this",
"->",
"getColumnType",
"(",
"$",
"type",
")",
",",
"'indexed'",
"=>",
"$",
"indexed",
"]",
")",
"->",
"render",
"(",
")",
";",
"$",
"this",
"->",
"write",
"(",
"$",
"path",
",",
"$",
"contents",
")",
";",
"return",
"$",
"this",
"->",
"getMigrationClassPath",
"(",
"$",
"migration",
")",
";",
"}"
] | Builds a field migration for a table
@param string $name
@param string $type
@param bool $indexed
@param string $tableName
@return string | [
"Builds",
"a",
"field",
"migration",
"for",
"a",
"table"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/MigrationBuilder.php#L123-L139 |
NuclearCMS/Hierarchy | src/Builders/MigrationBuilder.php | MigrationBuilder.destroyFieldMigrationForTable | public function destroyFieldMigrationForTable($name, $tableName)
{
$path = $this->getMigrationPath($tableName, $name);
$this->delete($path);
} | php | public function destroyFieldMigrationForTable($name, $tableName)
{
$path = $this->getMigrationPath($tableName, $name);
$this->delete($path);
} | [
"public",
"function",
"destroyFieldMigrationForTable",
"(",
"$",
"name",
",",
"$",
"tableName",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getMigrationPath",
"(",
"$",
"tableName",
",",
"$",
"name",
")",
";",
"$",
"this",
"->",
"delete",
"(",
"$",
"path",
")",
";",
"}"
] | Destroys a field migration for a table
@param string $name
@param string $tableName | [
"Destroys",
"a",
"field",
"migration",
"for",
"a",
"table"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/MigrationBuilder.php#L147-L152 |
NuclearCMS/Hierarchy | src/Builders/MigrationBuilder.php | MigrationBuilder.getTableFieldMigrationName | public function getTableFieldMigrationName($name, $tableName)
{
return sprintf(
MigrationBuilder::PATTERN_FIELD,
ucfirst($name),
ucfirst($tableName)
);
} | php | public function getTableFieldMigrationName($name, $tableName)
{
return sprintf(
MigrationBuilder::PATTERN_FIELD,
ucfirst($name),
ucfirst($tableName)
);
} | [
"public",
"function",
"getTableFieldMigrationName",
"(",
"$",
"name",
",",
"$",
"tableName",
")",
"{",
"return",
"sprintf",
"(",
"MigrationBuilder",
"::",
"PATTERN_FIELD",
",",
"ucfirst",
"(",
"$",
"name",
")",
",",
"ucfirst",
"(",
"$",
"tableName",
")",
")",
";",
"}"
] | Returns the migration name for a field in table
@param string $name
@param string $tableName
@return string | [
"Returns",
"the",
"migration",
"name",
"for",
"a",
"field",
"in",
"table"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/MigrationBuilder.php#L175-L182 |
NuclearCMS/Hierarchy | src/Builders/MigrationBuilder.php | MigrationBuilder.getMigrationPath | public function getMigrationPath($table, $field = null)
{
$name = is_null($field) ?
$this->getTableMigrationName($table) :
$this->getTableFieldMigrationName($field, $table);
return sprintf(
$this->getBasePath() . '/%s.php',
$name);
} | php | public function getMigrationPath($table, $field = null)
{
$name = is_null($field) ?
$this->getTableMigrationName($table) :
$this->getTableFieldMigrationName($field, $table);
return sprintf(
$this->getBasePath() . '/%s.php',
$name);
} | [
"public",
"function",
"getMigrationPath",
"(",
"$",
"table",
",",
"$",
"field",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"is_null",
"(",
"$",
"field",
")",
"?",
"$",
"this",
"->",
"getTableMigrationName",
"(",
"$",
"table",
")",
":",
"$",
"this",
"->",
"getTableFieldMigrationName",
"(",
"$",
"field",
",",
"$",
"table",
")",
";",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getBasePath",
"(",
")",
".",
"'/%s.php'",
",",
"$",
"name",
")",
";",
"}"
] | Returns the path for the migration
@param string $table
@param string|null $field
@return string | [
"Returns",
"the",
"path",
"for",
"the",
"migration"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/MigrationBuilder.php#L201-L210 |
NuclearCMS/Hierarchy | src/Builders/MigrationBuilder.php | MigrationBuilder.getMigrationClassPathByKey | public function getMigrationClassPathByKey($table, $field = null)
{
$name = is_null($field) ?
$this->getTableMigrationName($table) :
$this->getTableFieldMigrationName($field, $table);
return $this->getMigrationClassPath($name);
} | php | public function getMigrationClassPathByKey($table, $field = null)
{
$name = is_null($field) ?
$this->getTableMigrationName($table) :
$this->getTableFieldMigrationName($field, $table);
return $this->getMigrationClassPath($name);
} | [
"public",
"function",
"getMigrationClassPathByKey",
"(",
"$",
"table",
",",
"$",
"field",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"is_null",
"(",
"$",
"field",
")",
"?",
"$",
"this",
"->",
"getTableMigrationName",
"(",
"$",
"table",
")",
":",
"$",
"this",
"->",
"getTableFieldMigrationName",
"(",
"$",
"field",
",",
"$",
"table",
")",
";",
"return",
"$",
"this",
"->",
"getMigrationClassPath",
"(",
"$",
"name",
")",
";",
"}"
] | Returns the migration class path by key
@param string $table
@param string|null $field
@return string | [
"Returns",
"the",
"migration",
"class",
"path",
"by",
"key"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/MigrationBuilder.php#L230-L237 |
NuclearCMS/Hierarchy | src/Builders/MigrationBuilder.php | MigrationBuilder.getColumnType | public function getColumnType($type)
{
if (array_key_exists($type, $this->typeMap))
{
return $this->typeMap[$type];
}
return $this->defaultType;
} | php | public function getColumnType($type)
{
if (array_key_exists($type, $this->typeMap))
{
return $this->typeMap[$type];
}
return $this->defaultType;
} | [
"public",
"function",
"getColumnType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"typeMap",
")",
")",
"{",
"return",
"$",
"this",
"->",
"typeMap",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"defaultType",
";",
"}"
] | Returns the column type for key
@param string $type
@return string | [
"Returns",
"the",
"column",
"type",
"for",
"key"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/MigrationBuilder.php#L245-L253 |
xiewulong/yii2-fileupload | oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassLoader.php | ClassLoader.addPrefix | public function addPrefix($prefix, $paths)
{
if (!$prefix) {
foreach ((array) $paths as $path) {
$this->fallbackDirs[] = $path;
}
return;
}
if (isset($this->prefixes[$prefix])) {
$this->prefixes[$prefix] = array_merge(
$this->prefixes[$prefix],
(array) $paths
);
} else {
$this->prefixes[$prefix] = (array) $paths;
}
} | php | public function addPrefix($prefix, $paths)
{
if (!$prefix) {
foreach ((array) $paths as $path) {
$this->fallbackDirs[] = $path;
}
return;
}
if (isset($this->prefixes[$prefix])) {
$this->prefixes[$prefix] = array_merge(
$this->prefixes[$prefix],
(array) $paths
);
} else {
$this->prefixes[$prefix] = (array) $paths;
}
} | [
"public",
"function",
"addPrefix",
"(",
"$",
"prefix",
",",
"$",
"paths",
")",
"{",
"if",
"(",
"!",
"$",
"prefix",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"fallbackDirs",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"return",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"prefixes",
"[",
"$",
"prefix",
"]",
")",
")",
"{",
"$",
"this",
"->",
"prefixes",
"[",
"$",
"prefix",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"prefixes",
"[",
"$",
"prefix",
"]",
",",
"(",
"array",
")",
"$",
"paths",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"prefixes",
"[",
"$",
"prefix",
"]",
"=",
"(",
"array",
")",
"$",
"paths",
";",
"}",
"}"
] | Registers a set of classes
@param string $prefix The classes prefix
@param array|string $paths The location(s) of the classes | [
"Registers",
"a",
"set",
"of",
"classes"
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassLoader.php#L84-L101 |
xiewulong/yii2-fileupload | oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassLoader.php | ClassLoader.findFile | public function findFile($class)
{
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)).DIRECTORY_SEPARATOR;
$className = substr($class, $pos + 1);
} else {
// PEAR-like class name
$classPath = null;
$className = $class;
}
$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
foreach ($this->prefixes as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
return $dir.DIRECTORY_SEPARATOR.$classPath;
}
}
}
}
foreach ($this->fallbackDirs as $dir) {
if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
return $dir.DIRECTORY_SEPARATOR.$classPath;
}
}
if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) {
return $file;
}
} | php | public function findFile($class)
{
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)).DIRECTORY_SEPARATOR;
$className = substr($class, $pos + 1);
} else {
// PEAR-like class name
$classPath = null;
$className = $class;
}
$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
foreach ($this->prefixes as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
return $dir.DIRECTORY_SEPARATOR.$classPath;
}
}
}
}
foreach ($this->fallbackDirs as $dir) {
if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
return $dir.DIRECTORY_SEPARATOR.$classPath;
}
}
if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) {
return $file;
}
} | [
"public",
"function",
"findFile",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"class",
",",
"'\\\\'",
")",
")",
"{",
"// namespaced class name",
"$",
"classPath",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"DIRECTORY_SEPARATOR",
",",
"substr",
"(",
"$",
"class",
",",
"0",
",",
"$",
"pos",
")",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"className",
"=",
"substr",
"(",
"$",
"class",
",",
"$",
"pos",
"+",
"1",
")",
";",
"}",
"else",
"{",
"// PEAR-like class name",
"$",
"classPath",
"=",
"null",
";",
"$",
"className",
"=",
"$",
"class",
";",
"}",
"$",
"classPath",
".=",
"str_replace",
"(",
"'_'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"className",
")",
".",
"'.php'",
";",
"foreach",
"(",
"$",
"this",
"->",
"prefixes",
"as",
"$",
"prefix",
"=>",
"$",
"dirs",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"class",
",",
"$",
"prefix",
")",
")",
"{",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"classPath",
")",
")",
"{",
"return",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"classPath",
";",
"}",
"}",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"fallbackDirs",
"as",
"$",
"dir",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"classPath",
")",
")",
"{",
"return",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"classPath",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"useIncludePath",
"&&",
"$",
"file",
"=",
"stream_resolve_include_path",
"(",
"$",
"classPath",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"}"
] | Finds the path to the file where the class is defined.
@param string $class The name of the class
@return string|null The path, if found | [
"Finds",
"the",
"path",
"to",
"the",
"file",
"where",
"the",
"class",
"is",
"defined",
"."
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassLoader.php#L165-L198 |
mothership-ec/composer | src/Composer/Repository/RepositoryManager.php | RepositoryManager.findPackages | public function findPackages($name, $version)
{
$packages = array();
foreach ($this->repositories as $repository) {
$packages = array_merge($packages, $repository->findPackages($name, $version));
}
return $packages;
} | php | public function findPackages($name, $version)
{
$packages = array();
foreach ($this->repositories as $repository) {
$packages = array_merge($packages, $repository->findPackages($name, $version));
}
return $packages;
} | [
"public",
"function",
"findPackages",
"(",
"$",
"name",
",",
"$",
"version",
")",
"{",
"$",
"packages",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"repositories",
"as",
"$",
"repository",
")",
"{",
"$",
"packages",
"=",
"array_merge",
"(",
"$",
"packages",
",",
"$",
"repository",
"->",
"findPackages",
"(",
"$",
"name",
",",
"$",
"version",
")",
")",
";",
"}",
"return",
"$",
"packages",
";",
"}"
] | Searches for all packages matching a name and optionally a version in managed repositories.
@param string $name package name
@param string $version package version
@return array | [
"Searches",
"for",
"all",
"packages",
"matching",
"a",
"name",
"and",
"optionally",
"a",
"version",
"in",
"managed",
"repositories",
"."
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/RepositoryManager.php#L67-L76 |
mothership-ec/composer | src/Composer/Repository/RepositoryManager.php | RepositoryManager.createRepository | public function createRepository($type, $config)
{
if (!isset($this->repositoryClasses[$type])) {
throw new \InvalidArgumentException('Repository type is not registered: '.$type);
}
$class = $this->repositoryClasses[$type];
return new $class($config, $this->io, $this->config, $this->eventDispatcher);
} | php | public function createRepository($type, $config)
{
if (!isset($this->repositoryClasses[$type])) {
throw new \InvalidArgumentException('Repository type is not registered: '.$type);
}
$class = $this->repositoryClasses[$type];
return new $class($config, $this->io, $this->config, $this->eventDispatcher);
} | [
"public",
"function",
"createRepository",
"(",
"$",
"type",
",",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"repositoryClasses",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Repository type is not registered: '",
".",
"$",
"type",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"repositoryClasses",
"[",
"$",
"type",
"]",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"config",
",",
"$",
"this",
"->",
"io",
",",
"$",
"this",
"->",
"config",
",",
"$",
"this",
"->",
"eventDispatcher",
")",
";",
"}"
] | Returns a new repository for a specific installation type.
@param string $type repository type
@param array $config repository configuration
@return RepositoryInterface
@throws \InvalidArgumentException if repository for provided type is not registered | [
"Returns",
"a",
"new",
"repository",
"for",
"a",
"specific",
"installation",
"type",
"."
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/RepositoryManager.php#L96-L105 |
zhouyl/mellivora | Mellivora/View/ViewServiceProvider.php | ViewServiceProvider.registerFactory | public function registerFactory()
{
$this->container['view'] = function ($container) {
// Next we need to grab the engine resolver instance that will be used by the
// environment. The resolver will be used by an environment to get each of
// the various engine implementations such as plain PHP or Blade engine.
$resolver = $container['view.engine.resolver'];
$view = new Factory($resolver, $container['view.finder'], $container['events']);
// We will also set the container instance on this view environment since the
// view composers may be classes registered in the container, which allows
// for great testable, flexible composers for the application developer.
$view->setContainer($container);
$view->share('container', $container);
return $view;
};
} | php | public function registerFactory()
{
$this->container['view'] = function ($container) {
// Next we need to grab the engine resolver instance that will be used by the
// environment. The resolver will be used by an environment to get each of
// the various engine implementations such as plain PHP or Blade engine.
$resolver = $container['view.engine.resolver'];
$view = new Factory($resolver, $container['view.finder'], $container['events']);
// We will also set the container instance on this view environment since the
// view composers may be classes registered in the container, which allows
// for great testable, flexible composers for the application developer.
$view->setContainer($container);
$view->share('container', $container);
return $view;
};
} | [
"public",
"function",
"registerFactory",
"(",
")",
"{",
"$",
"this",
"->",
"container",
"[",
"'view'",
"]",
"=",
"function",
"(",
"$",
"container",
")",
"{",
"// Next we need to grab the engine resolver instance that will be used by the",
"// environment. The resolver will be used by an environment to get each of",
"// the various engine implementations such as plain PHP or Blade engine.",
"$",
"resolver",
"=",
"$",
"container",
"[",
"'view.engine.resolver'",
"]",
";",
"$",
"view",
"=",
"new",
"Factory",
"(",
"$",
"resolver",
",",
"$",
"container",
"[",
"'view.finder'",
"]",
",",
"$",
"container",
"[",
"'events'",
"]",
")",
";",
"// We will also set the container instance on this view environment since the",
"// view composers may be classes registered in the container, which allows",
"// for great testable, flexible composers for the application developer.",
"$",
"view",
"->",
"setContainer",
"(",
"$",
"container",
")",
";",
"$",
"view",
"->",
"share",
"(",
"'container'",
",",
"$",
"container",
")",
";",
"return",
"$",
"view",
";",
"}",
";",
"}"
] | Register the view environment.
@return void | [
"Register",
"the",
"view",
"environment",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/View/ViewServiceProvider.php#L31-L50 |
zhouyl/mellivora | Mellivora/View/ViewServiceProvider.php | ViewServiceProvider.registerEngineResolver | public function registerEngineResolver()
{
$this->container['view.engine.resolver'] = function () {
$resolver = new EngineResolver;
// Next, we will register the various view engines with the resolver so that the
// environment will resolve the engines needed for various views based on the
// extension of view file. We call a method for each of the view's engines.
foreach (['file', 'php', 'blade'] as $engine) {
$this->{'register' . ucfirst($engine) . 'Engine'}($resolver);
}
return $resolver;
};
} | php | public function registerEngineResolver()
{
$this->container['view.engine.resolver'] = function () {
$resolver = new EngineResolver;
// Next, we will register the various view engines with the resolver so that the
// environment will resolve the engines needed for various views based on the
// extension of view file. We call a method for each of the view's engines.
foreach (['file', 'php', 'blade'] as $engine) {
$this->{'register' . ucfirst($engine) . 'Engine'}($resolver);
}
return $resolver;
};
} | [
"public",
"function",
"registerEngineResolver",
"(",
")",
"{",
"$",
"this",
"->",
"container",
"[",
"'view.engine.resolver'",
"]",
"=",
"function",
"(",
")",
"{",
"$",
"resolver",
"=",
"new",
"EngineResolver",
";",
"// Next, we will register the various view engines with the resolver so that the",
"// environment will resolve the engines needed for various views based on the",
"// extension of view file. We call a method for each of the view's engines.",
"foreach",
"(",
"[",
"'file'",
",",
"'php'",
",",
"'blade'",
"]",
"as",
"$",
"engine",
")",
"{",
"$",
"this",
"->",
"{",
"'register'",
".",
"ucfirst",
"(",
"$",
"engine",
")",
".",
"'Engine'",
"}",
"(",
"$",
"resolver",
")",
";",
"}",
"return",
"$",
"resolver",
";",
"}",
";",
"}"
] | Register the engine resolver instance.
@return void | [
"Register",
"the",
"engine",
"resolver",
"instance",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/View/ViewServiceProvider.php#L71-L85 |
zhouyl/mellivora | Mellivora/View/ViewServiceProvider.php | ViewServiceProvider.registerBladeEngine | public function registerBladeEngine($resolver)
{
// The Compiler engine requires an instance of the CompilerInterface, which in
// this case will be the Blade compiler, so we'll first create the compiler
// instance to pass into the engine so it can compile the views properly.
$this->container['blade.compiler'] = function ($container) {
return new BladeCompiler($container['config']->get('view.compiled'));
};
$resolver->register('blade', function () {
return new CompilerEngine($this->container['blade.compiler']);
});
} | php | public function registerBladeEngine($resolver)
{
// The Compiler engine requires an instance of the CompilerInterface, which in
// this case will be the Blade compiler, so we'll first create the compiler
// instance to pass into the engine so it can compile the views properly.
$this->container['blade.compiler'] = function ($container) {
return new BladeCompiler($container['config']->get('view.compiled'));
};
$resolver->register('blade', function () {
return new CompilerEngine($this->container['blade.compiler']);
});
} | [
"public",
"function",
"registerBladeEngine",
"(",
"$",
"resolver",
")",
"{",
"// The Compiler engine requires an instance of the CompilerInterface, which in",
"// this case will be the Blade compiler, so we'll first create the compiler",
"// instance to pass into the engine so it can compile the views properly.",
"$",
"this",
"->",
"container",
"[",
"'blade.compiler'",
"]",
"=",
"function",
"(",
"$",
"container",
")",
"{",
"return",
"new",
"BladeCompiler",
"(",
"$",
"container",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'view.compiled'",
")",
")",
";",
"}",
";",
"$",
"resolver",
"->",
"register",
"(",
"'blade'",
",",
"function",
"(",
")",
"{",
"return",
"new",
"CompilerEngine",
"(",
"$",
"this",
"->",
"container",
"[",
"'blade.compiler'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Register the Blade engine implementation.
@param \Mellivora\View\Engines\EngineResolver $resolver
@return void | [
"Register",
"the",
"Blade",
"engine",
"implementation",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/View/ViewServiceProvider.php#L122-L134 |
yuncms/yii2-authentication | backend/controllers/AuthenticationController.php | AuthenticationController.actionIndex | public function actionIndex()
{
$searchModel = Yii::createObject(AuthenticationSearch::className());
$dataProvider = $searchModel->search(Yii::$app->request->get());
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} | php | public function actionIndex()
{
$searchModel = Yii::createObject(AuthenticationSearch::className());
$dataProvider = $searchModel->search(Yii::$app->request->get());
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"searchModel",
"=",
"Yii",
"::",
"createObject",
"(",
"AuthenticationSearch",
"::",
"className",
"(",
")",
")",
";",
"$",
"dataProvider",
"=",
"$",
"searchModel",
"->",
"search",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"get",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'index'",
",",
"[",
"'searchModel'",
"=>",
"$",
"searchModel",
",",
"'dataProvider'",
"=>",
"$",
"dataProvider",
",",
"]",
")",
";",
"}"
] | Lists all Authentication models.
@return mixed | [
"Lists",
"all",
"Authentication",
"models",
"."
] | train | https://github.com/yuncms/yii2-authentication/blob/02b70f7d2587480edb6dcc18ce256db662f1ed0d/backend/controllers/AuthenticationController.php#L40-L49 |
inhere/php-librarys | src/DI/CallableResolver.php | CallableResolver.resolve | public function resolve($toResolve)
{
if (\is_callable($toResolve)) {
return $toResolve;
}
if (!\is_string($toResolve)) {
$this->assertCallable($toResolve);
}
// check for slim callable as "class:method"
if (preg_match(self::CALLABLE_PATTERN, $toResolve, $matches)) {
$resolved = $this->resolveCallable($matches[1], $matches[2]);
$this->assertCallable($resolved);
return $resolved;
}
$resolved = $this->resolveCallable($toResolve);
$this->assertCallable($resolved);
return $resolved;
} | php | public function resolve($toResolve)
{
if (\is_callable($toResolve)) {
return $toResolve;
}
if (!\is_string($toResolve)) {
$this->assertCallable($toResolve);
}
// check for slim callable as "class:method"
if (preg_match(self::CALLABLE_PATTERN, $toResolve, $matches)) {
$resolved = $this->resolveCallable($matches[1], $matches[2]);
$this->assertCallable($resolved);
return $resolved;
}
$resolved = $this->resolveCallable($toResolve);
$this->assertCallable($resolved);
return $resolved;
} | [
"public",
"function",
"resolve",
"(",
"$",
"toResolve",
")",
"{",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"toResolve",
")",
")",
"{",
"return",
"$",
"toResolve",
";",
"}",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"toResolve",
")",
")",
"{",
"$",
"this",
"->",
"assertCallable",
"(",
"$",
"toResolve",
")",
";",
"}",
"// check for slim callable as \"class:method\"",
"if",
"(",
"preg_match",
"(",
"self",
"::",
"CALLABLE_PATTERN",
",",
"$",
"toResolve",
",",
"$",
"matches",
")",
")",
"{",
"$",
"resolved",
"=",
"$",
"this",
"->",
"resolveCallable",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"$",
"this",
"->",
"assertCallable",
"(",
"$",
"resolved",
")",
";",
"return",
"$",
"resolved",
";",
"}",
"$",
"resolved",
"=",
"$",
"this",
"->",
"resolveCallable",
"(",
"$",
"toResolve",
")",
";",
"$",
"this",
"->",
"assertCallable",
"(",
"$",
"resolved",
")",
";",
"return",
"$",
"resolved",
";",
"}"
] | Resolve toResolve into a closure that that the router can dispatch.
If toResolve is of the format 'class:method', then try to extract 'class'
from the container otherwise instantiate it and then dispatch 'method'.
@param mixed $toResolve
@return callable
@throws RuntimeException if the callable does not exist
@throws RuntimeException if the callable is not resolvable | [
"Resolve",
"toResolve",
"into",
"a",
"closure",
"that",
"that",
"the",
"router",
"can",
"dispatch",
"."
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/CallableResolver.php#L50-L72 |
inhere/php-librarys | src/DI/CallableResolver.php | CallableResolver.resolveCallable | private function resolveCallable($class, $method = '__invoke')
{
if ($cb = $this->container->getIfExist($class)) {
return [$cb, $method];
}
if (!class_exists($class)) {
throw new RuntimeException(sprintf('Callable %s does not exist', $class));
}
return [new $class($this->container), $method];
} | php | private function resolveCallable($class, $method = '__invoke')
{
if ($cb = $this->container->getIfExist($class)) {
return [$cb, $method];
}
if (!class_exists($class)) {
throw new RuntimeException(sprintf('Callable %s does not exist', $class));
}
return [new $class($this->container), $method];
} | [
"private",
"function",
"resolveCallable",
"(",
"$",
"class",
",",
"$",
"method",
"=",
"'__invoke'",
")",
"{",
"if",
"(",
"$",
"cb",
"=",
"$",
"this",
"->",
"container",
"->",
"getIfExist",
"(",
"$",
"class",
")",
")",
"{",
"return",
"[",
"$",
"cb",
",",
"$",
"method",
"]",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Callable %s does not exist'",
",",
"$",
"class",
")",
")",
";",
"}",
"return",
"[",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"container",
")",
",",
"$",
"method",
"]",
";",
"}"
] | Check if string is something in the DIC
that's callable or is a class name which has an __invoke() method.
@param string $class
@param string $method
@return callable
@throws \InvalidArgumentException
@throws \RuntimeException if the callable does not exist | [
"Check",
"if",
"string",
"is",
"something",
"in",
"the",
"DIC",
"that",
"s",
"callable",
"or",
"is",
"a",
"class",
"name",
"which",
"has",
"an",
"__invoke",
"()",
"method",
"."
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/CallableResolver.php#L85-L96 |
GrupaZero/api | src/Gzero/Api/Controller/ApiController.php | ApiController.respond | protected function respond($data, $code, array $headers = [])
{
return response()->json($data, $code, array_merge($this->defaultHeaders(), $headers));
} | php | protected function respond($data, $code, array $headers = [])
{
return response()->json($data, $code, array_merge($this->defaultHeaders(), $headers));
} | [
"protected",
"function",
"respond",
"(",
"$",
"data",
",",
"$",
"code",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"data",
",",
"$",
"code",
",",
"array_merge",
"(",
"$",
"this",
"->",
"defaultHeaders",
"(",
")",
",",
"$",
"headers",
")",
")",
";",
"}"
] | Return response in json format
@param mixed $data Response data
@param int $code Response code
@param array $headers HTTP headers
@return \Illuminate\Http\JsonResponse | [
"Return",
"response",
"in",
"json",
"format"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/ApiController.php#L54-L57 |
GrupaZero/api | src/Gzero/Api/Controller/ApiController.php | ApiController.respondTransformer | protected function respondTransformer($data, $code, TransformerAbstract $transformer, array $headers = [])
{
if ($data === null) { // If we have empty result
return $this->respond(
[
'data' => []
],
$code,
$headers
);
}
if ($data instanceof LengthAwarePaginator) { // If we have paginated collection
$resource = new Collection($data->items(), $transformer);
return $this->respond(
[
'meta' => [
'total' => $data->total(),
'perPage' => $data->perPage(),
'currentPage' => $data->currentPage(),
'lastPage' => $data->lastPage(),
'link' => \URL::current()
],
'params' => $this->processor->getProcessedFields(),
'data' => $this->getSerializer()->createData($resource)->toArray()
],
$code,
$headers
);
} elseif ($data instanceof LaravelCollection) { // Collection without pagination
$resource = new Collection($data, $transformer);
return $this->respond(
[
'data' => $this->getSerializer()->createData($resource)->toArray()
],
$code,
$headers
);
} else { // Single entity
$resource = new Item($data, $transformer);
return $this->respond(
$this->getSerializer()->createData($resource)->toArray(),
$code,
$headers
);
}
} | php | protected function respondTransformer($data, $code, TransformerAbstract $transformer, array $headers = [])
{
if ($data === null) { // If we have empty result
return $this->respond(
[
'data' => []
],
$code,
$headers
);
}
if ($data instanceof LengthAwarePaginator) { // If we have paginated collection
$resource = new Collection($data->items(), $transformer);
return $this->respond(
[
'meta' => [
'total' => $data->total(),
'perPage' => $data->perPage(),
'currentPage' => $data->currentPage(),
'lastPage' => $data->lastPage(),
'link' => \URL::current()
],
'params' => $this->processor->getProcessedFields(),
'data' => $this->getSerializer()->createData($resource)->toArray()
],
$code,
$headers
);
} elseif ($data instanceof LaravelCollection) { // Collection without pagination
$resource = new Collection($data, $transformer);
return $this->respond(
[
'data' => $this->getSerializer()->createData($resource)->toArray()
],
$code,
$headers
);
} else { // Single entity
$resource = new Item($data, $transformer);
return $this->respond(
$this->getSerializer()->createData($resource)->toArray(),
$code,
$headers
);
}
} | [
"protected",
"function",
"respondTransformer",
"(",
"$",
"data",
",",
"$",
"code",
",",
"TransformerAbstract",
"$",
"transformer",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"// If we have empty result",
"return",
"$",
"this",
"->",
"respond",
"(",
"[",
"'data'",
"=>",
"[",
"]",
"]",
",",
"$",
"code",
",",
"$",
"headers",
")",
";",
"}",
"if",
"(",
"$",
"data",
"instanceof",
"LengthAwarePaginator",
")",
"{",
"// If we have paginated collection",
"$",
"resource",
"=",
"new",
"Collection",
"(",
"$",
"data",
"->",
"items",
"(",
")",
",",
"$",
"transformer",
")",
";",
"return",
"$",
"this",
"->",
"respond",
"(",
"[",
"'meta'",
"=>",
"[",
"'total'",
"=>",
"$",
"data",
"->",
"total",
"(",
")",
",",
"'perPage'",
"=>",
"$",
"data",
"->",
"perPage",
"(",
")",
",",
"'currentPage'",
"=>",
"$",
"data",
"->",
"currentPage",
"(",
")",
",",
"'lastPage'",
"=>",
"$",
"data",
"->",
"lastPage",
"(",
")",
",",
"'link'",
"=>",
"\\",
"URL",
"::",
"current",
"(",
")",
"]",
",",
"'params'",
"=>",
"$",
"this",
"->",
"processor",
"->",
"getProcessedFields",
"(",
")",
",",
"'data'",
"=>",
"$",
"this",
"->",
"getSerializer",
"(",
")",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
"]",
",",
"$",
"code",
",",
"$",
"headers",
")",
";",
"}",
"elseif",
"(",
"$",
"data",
"instanceof",
"LaravelCollection",
")",
"{",
"// Collection without pagination",
"$",
"resource",
"=",
"new",
"Collection",
"(",
"$",
"data",
",",
"$",
"transformer",
")",
";",
"return",
"$",
"this",
"->",
"respond",
"(",
"[",
"'data'",
"=>",
"$",
"this",
"->",
"getSerializer",
"(",
")",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
"]",
",",
"$",
"code",
",",
"$",
"headers",
")",
";",
"}",
"else",
"{",
"// Single entity",
"$",
"resource",
"=",
"new",
"Item",
"(",
"$",
"data",
",",
"$",
"transformer",
")",
";",
"return",
"$",
"this",
"->",
"respond",
"(",
"$",
"this",
"->",
"getSerializer",
"(",
")",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
",",
"$",
"code",
",",
"$",
"headers",
")",
";",
"}",
"}"
] | Return transformed response in json format
@param mixed $data Response data
@param int $code Response code
@param TransformerAbstract $transformer Transformer class
@param array $headers HTTP headers
@return \Illuminate\Http\JsonResponse | [
"Return",
"transformed",
"response",
"in",
"json",
"format"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/ApiController.php#L69-L115 |
GrupaZero/api | src/Gzero/Api/Controller/ApiController.php | ApiController.respondWithSuccess | protected function respondWithSuccess($data, TransformerAbstract $transformer = null, array $headers = [])
{
if ($transformer) {
return $this->respondTransformer($data, SymfonyResponse::HTTP_OK, $transformer, $headers);
}
return $this->respondWithSimpleSuccess($data);
} | php | protected function respondWithSuccess($data, TransformerAbstract $transformer = null, array $headers = [])
{
if ($transformer) {
return $this->respondTransformer($data, SymfonyResponse::HTTP_OK, $transformer, $headers);
}
return $this->respondWithSimpleSuccess($data);
} | [
"protected",
"function",
"respondWithSuccess",
"(",
"$",
"data",
",",
"TransformerAbstract",
"$",
"transformer",
"=",
"null",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"transformer",
")",
"{",
"return",
"$",
"this",
"->",
"respondTransformer",
"(",
"$",
"data",
",",
"SymfonyResponse",
"::",
"HTTP_OK",
",",
"$",
"transformer",
",",
"$",
"headers",
")",
";",
"}",
"return",
"$",
"this",
"->",
"respondWithSimpleSuccess",
"(",
"$",
"data",
")",
";",
"}"
] | Return success response in json format
@param mixed $data Response data
@param TransformerAbstract $transformer Transformer class
@param array $headers HTTP Header
@return mixed | [
"Return",
"success",
"response",
"in",
"json",
"format"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/ApiController.php#L126-L132 |
GrupaZero/api | src/Gzero/Api/Controller/ApiController.php | ApiController.respondWithError | protected function respondWithError(
$message = 'Bad Request',
$code = SymfonyResponse::HTTP_BAD_REQUEST,
array $headers = []
) {
return abort($code, $message, $headers);
} | php | protected function respondWithError(
$message = 'Bad Request',
$code = SymfonyResponse::HTTP_BAD_REQUEST,
array $headers = []
) {
return abort($code, $message, $headers);
} | [
"protected",
"function",
"respondWithError",
"(",
"$",
"message",
"=",
"'Bad Request'",
",",
"$",
"code",
"=",
"SymfonyResponse",
"::",
"HTTP_BAD_REQUEST",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"abort",
"(",
"$",
"code",
",",
"$",
"message",
",",
"$",
"headers",
")",
";",
"}"
] | Return server error response in json format
@param string $message Custom error message
@param int $code Error code
@param array $headers HTTP headers
@return mixed | [
"Return",
"server",
"error",
"response",
"in",
"json",
"format"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/ApiController.php#L156-L162 |
GrupaZero/api | src/Gzero/Api/Controller/ApiController.php | ApiController.getSerializer | protected function getSerializer()
{
if (!isset($this->serializer)) {
$this->serializer = \App::make('League\Fractal\Manager');
}
return $this->serializer;
} | php | protected function getSerializer()
{
if (!isset($this->serializer)) {
$this->serializer = \App::make('League\Fractal\Manager');
}
return $this->serializer;
} | [
"protected",
"function",
"getSerializer",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"serializer",
")",
")",
"{",
"$",
"this",
"->",
"serializer",
"=",
"\\",
"App",
"::",
"make",
"(",
"'League\\Fractal\\Manager'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"serializer",
";",
"}"
] | Get serializer
@return \League\Fractal\Manager | [
"Get",
"serializer"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/ApiController.php#L182-L188 |
jaxon-php/jaxon-jquery | src/Dom/Element.php | Element.getScript | public function getScript()
{
if(count($this->aScripts) == 0)
{
return '';
}
if(($this->sContext))
{
$js = "$('" . $this->sSelector . "', $('" . $this->sContext . "'))";
}
else
{
$js = "$('" . $this->sSelector . "')";
}
return $js . '.' . implode('.', $this->aScripts);
} | php | public function getScript()
{
if(count($this->aScripts) == 0)
{
return '';
}
if(($this->sContext))
{
$js = "$('" . $this->sSelector . "', $('" . $this->sContext . "'))";
}
else
{
$js = "$('" . $this->sSelector . "')";
}
return $js . '.' . implode('.', $this->aScripts);
} | [
"public",
"function",
"getScript",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"aScripts",
")",
"==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"(",
"$",
"this",
"->",
"sContext",
")",
")",
"{",
"$",
"js",
"=",
"\"$('\"",
".",
"$",
"this",
"->",
"sSelector",
".",
"\"', $('\"",
".",
"$",
"this",
"->",
"sContext",
".",
"\"'))\"",
";",
"}",
"else",
"{",
"$",
"js",
"=",
"\"$('\"",
".",
"$",
"this",
"->",
"sSelector",
".",
"\"')\"",
";",
"}",
"return",
"$",
"js",
".",
"'.'",
".",
"implode",
"(",
"'.'",
",",
"$",
"this",
"->",
"aScripts",
")",
";",
"}"
] | Generate the jQuery call.
@return string | [
"Generate",
"the",
"jQuery",
"call",
"."
] | train | https://github.com/jaxon-php/jaxon-jquery/blob/90766a8ea8a4124a3f110e96b316370f71762380/src/Dom/Element.php#L67-L82 |
kenphp/ken | src/Http/BaseMiddleware.php | BaseMiddleware.next | final protected function next(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
if ($this->_next) {
return $this->_next->process($request, $handler);
}
return $handler->handle($request);
} | php | final protected function next(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
if ($this->_next) {
return $this->_next->process($request, $handler);
}
return $handler->handle($request);
} | [
"final",
"protected",
"function",
"next",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"RequestHandlerInterface",
"$",
"handler",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"_next",
")",
"{",
"return",
"$",
"this",
"->",
"_next",
"->",
"process",
"(",
"$",
"request",
",",
"$",
"handler",
")",
";",
"}",
"return",
"$",
"handler",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"}"
] | Pass request to the next middleware. If there are no next middleware,
it will pass the request to the handler
@param ServerRequestInterface $request
@param RequestHandlerInterface $handler
@return ResponseInterface | [
"Pass",
"request",
"to",
"the",
"next",
"middleware",
".",
"If",
"there",
"are",
"no",
"next",
"middleware",
"it",
"will",
"pass",
"the",
"request",
"to",
"the",
"handler"
] | train | https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Http/BaseMiddleware.php#L44-L49 |
digitalingenieur/churchtools-php-sdk | src/Models/Model.php | Model.get | public static function get()
{
$instance = new static;
$request = new Request($instance->functionCall, $instance->module);
$instance->fill($request->execute());
return $instance;
} | php | public static function get()
{
$instance = new static;
$request = new Request($instance->functionCall, $instance->module);
$instance->fill($request->execute());
return $instance;
} | [
"public",
"static",
"function",
"get",
"(",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"instance",
"->",
"functionCall",
",",
"$",
"instance",
"->",
"module",
")",
";",
"$",
"instance",
"->",
"fill",
"(",
"$",
"request",
"->",
"execute",
"(",
")",
")",
";",
"return",
"$",
"instance",
";",
"}"
] | get wenn nur ein model zurückerwartet wird | [
"get",
"wenn",
"nur",
"ein",
"model",
"zurückerwartet",
"wird"
] | train | https://github.com/digitalingenieur/churchtools-php-sdk/blob/68af220e37c7cd2e52e3e5a717985dd582b50e34/src/Models/Model.php#L28-L37 |
digitalingenieur/churchtools-php-sdk | src/Models/Model.php | Model.all | public static function all($column='')
{
$instance = new static;
$result = $instance->newRequest($instance->functionCall,$instance->module);
$collection = $instance->newCollection();
foreach($result as $key => $object){
$collection->put($key, new static((array) $object));
}
return $collection;
} | php | public static function all($column='')
{
$instance = new static;
$result = $instance->newRequest($instance->functionCall,$instance->module);
$collection = $instance->newCollection();
foreach($result as $key => $object){
$collection->put($key, new static((array) $object));
}
return $collection;
} | [
"public",
"static",
"function",
"all",
"(",
"$",
"column",
"=",
"''",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
";",
"$",
"result",
"=",
"$",
"instance",
"->",
"newRequest",
"(",
"$",
"instance",
"->",
"functionCall",
",",
"$",
"instance",
"->",
"module",
")",
";",
"$",
"collection",
"=",
"$",
"instance",
"->",
"newCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"object",
")",
"{",
"$",
"collection",
"->",
"put",
"(",
"$",
"key",
",",
"new",
"static",
"(",
"(",
"array",
")",
"$",
"object",
")",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | all wenn eine collection zurückerwartet wird | [
"all",
"wenn",
"eine",
"collection",
"zurückerwartet",
"wird"
] | train | https://github.com/digitalingenieur/churchtools-php-sdk/blob/68af220e37c7cd2e52e3e5a717985dd582b50e34/src/Models/Model.php#L40-L51 |
technote-space/wordpress-plugin-base | src/classes/models/lib/social.php | Social.get_social_service | private function get_social_service( $state ) {
$name = $this->get_social_service_name( $state );
if ( empty( $name ) ) {
return null;
}
foreach ( $this->get_class_list() as $class ) {
/** @var \Technote\Interfaces\Helper\Social $class */
if ( $name === $class->get_service_name() ) {
return $class;
}
}
return null;
} | php | private function get_social_service( $state ) {
$name = $this->get_social_service_name( $state );
if ( empty( $name ) ) {
return null;
}
foreach ( $this->get_class_list() as $class ) {
/** @var \Technote\Interfaces\Helper\Social $class */
if ( $name === $class->get_service_name() ) {
return $class;
}
}
return null;
} | [
"private",
"function",
"get_social_service",
"(",
"$",
"state",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"get_social_service_name",
"(",
"$",
"state",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"null",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"get_class_list",
"(",
")",
"as",
"$",
"class",
")",
"{",
"/** @var \\Technote\\Interfaces\\Helper\\Social $class */",
"if",
"(",
"$",
"name",
"===",
"$",
"class",
"->",
"get_service_name",
"(",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | @param $state
@return \Technote\Interfaces\Helper\Social|null | [
"@param",
"$state"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/social.php#L135-L148 |
maestroprog/saw-php | src/Saw.php | Saw.init | public function init(string $configPath): self
{
defined('INTERVAL') or define('INTERVAL', 10000);
defined('SAW_DIR') or define('SAW_DIR', __DIR__);
$config = array_merge(
require __DIR__ . '/../config/saw.php',
require $configPath
);
// todo include config
foreach (['saw', 'factory', 'daemon', 'sockets', 'application', 'controller'] as $check) {
if (!isset($config[$check]) || !is_array($config[$check])) {
$config[$check] = [];
}
}
if (isset($config['saw']['debug'])) {
self::$debug = (bool)$config['saw']['debug'];
}
$initScript = __DIR__ . '/../bin/cli.php';
if (!isset($config['controller_starter'])) {
$config['controller_starter'] = <<<CMD
-r "require_once '{$initScript}';
\Maestroprog\Saw\Saw::instance()
->init('{$configPath}')
->instanceController()
->start();"
CMD;
}
if (!isset($config['worker_starter'])) {
$config['worker_starter'] = <<<CMD
-r "require_once '{$initScript}';
\Maestroprog\Saw\Saw::instance()
->init('{$configPath}')
->instanceWorker()
->start();"
CMD;
}
$this->container = Container::instance();
$this->container->register($this->sawContainer = new SawContainer(
$this->config = $config,
$this->daemonConfig = new DaemonConfig($config['daemon'], $configPath),
$this->config = new Configurator($config['sockets']),
$this->controllerConfig = new ControllerConfig($config['controller']),
SawEnv::web()
));
$this->container->register(new MemoryContainer());
$this->applicationLoader = new ApplicationLoader(
new ApplicationConfig($config['application']),
new ApplicationFactory($this->container)
);
if (!self::$debug) {
set_exception_handler(function (\Throwable $exception) {
if ($exception instanceof \Exception) {
switch ($exception->getCode()) {
case self::ERROR_WRONG_CONFIG:
echo $exception->getMessage();
exit($exception->getCode());
}
}
});
}
/*$compiler = new ContainerCompiler($this->container);
$compiler->compile('build/container.php');*/
return $this;
} | php | public function init(string $configPath): self
{
defined('INTERVAL') or define('INTERVAL', 10000);
defined('SAW_DIR') or define('SAW_DIR', __DIR__);
$config = array_merge(
require __DIR__ . '/../config/saw.php',
require $configPath
);
// todo include config
foreach (['saw', 'factory', 'daemon', 'sockets', 'application', 'controller'] as $check) {
if (!isset($config[$check]) || !is_array($config[$check])) {
$config[$check] = [];
}
}
if (isset($config['saw']['debug'])) {
self::$debug = (bool)$config['saw']['debug'];
}
$initScript = __DIR__ . '/../bin/cli.php';
if (!isset($config['controller_starter'])) {
$config['controller_starter'] = <<<CMD
-r "require_once '{$initScript}';
\Maestroprog\Saw\Saw::instance()
->init('{$configPath}')
->instanceController()
->start();"
CMD;
}
if (!isset($config['worker_starter'])) {
$config['worker_starter'] = <<<CMD
-r "require_once '{$initScript}';
\Maestroprog\Saw\Saw::instance()
->init('{$configPath}')
->instanceWorker()
->start();"
CMD;
}
$this->container = Container::instance();
$this->container->register($this->sawContainer = new SawContainer(
$this->config = $config,
$this->daemonConfig = new DaemonConfig($config['daemon'], $configPath),
$this->config = new Configurator($config['sockets']),
$this->controllerConfig = new ControllerConfig($config['controller']),
SawEnv::web()
));
$this->container->register(new MemoryContainer());
$this->applicationLoader = new ApplicationLoader(
new ApplicationConfig($config['application']),
new ApplicationFactory($this->container)
);
if (!self::$debug) {
set_exception_handler(function (\Throwable $exception) {
if ($exception instanceof \Exception) {
switch ($exception->getCode()) {
case self::ERROR_WRONG_CONFIG:
echo $exception->getMessage();
exit($exception->getCode());
}
}
});
}
/*$compiler = new ContainerCompiler($this->container);
$compiler->compile('build/container.php');*/
return $this;
} | [
"public",
"function",
"init",
"(",
"string",
"$",
"configPath",
")",
":",
"self",
"{",
"defined",
"(",
"'INTERVAL'",
")",
"or",
"define",
"(",
"'INTERVAL'",
",",
"10000",
")",
";",
"defined",
"(",
"'SAW_DIR'",
")",
"or",
"define",
"(",
"'SAW_DIR'",
",",
"__DIR__",
")",
";",
"$",
"config",
"=",
"array_merge",
"(",
"require",
"__DIR__",
".",
"'/../config/saw.php'",
",",
"require",
"$",
"configPath",
")",
";",
"// todo include config",
"foreach",
"(",
"[",
"'saw'",
",",
"'factory'",
",",
"'daemon'",
",",
"'sockets'",
",",
"'application'",
",",
"'controller'",
"]",
"as",
"$",
"check",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"$",
"check",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"config",
"[",
"$",
"check",
"]",
")",
")",
"{",
"$",
"config",
"[",
"$",
"check",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'saw'",
"]",
"[",
"'debug'",
"]",
")",
")",
"{",
"self",
"::",
"$",
"debug",
"=",
"(",
"bool",
")",
"$",
"config",
"[",
"'saw'",
"]",
"[",
"'debug'",
"]",
";",
"}",
"$",
"initScript",
"=",
"__DIR__",
".",
"'/../bin/cli.php'",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'controller_starter'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'controller_starter'",
"]",
"=",
" <<<CMD\n-r \"require_once '{$initScript}';\n\\Maestroprog\\Saw\\Saw::instance()\n ->init('{$configPath}')\n ->instanceController()\n ->start();\"\nCMD",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'worker_starter'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'worker_starter'",
"]",
"=",
" <<<CMD\n-r \"require_once '{$initScript}';\n\\Maestroprog\\Saw\\Saw::instance()\n ->init('{$configPath}')\n ->instanceWorker()\n ->start();\"\nCMD",
";",
"}",
"$",
"this",
"->",
"container",
"=",
"Container",
"::",
"instance",
"(",
")",
";",
"$",
"this",
"->",
"container",
"->",
"register",
"(",
"$",
"this",
"->",
"sawContainer",
"=",
"new",
"SawContainer",
"(",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
",",
"$",
"this",
"->",
"daemonConfig",
"=",
"new",
"DaemonConfig",
"(",
"$",
"config",
"[",
"'daemon'",
"]",
",",
"$",
"configPath",
")",
",",
"$",
"this",
"->",
"config",
"=",
"new",
"Configurator",
"(",
"$",
"config",
"[",
"'sockets'",
"]",
")",
",",
"$",
"this",
"->",
"controllerConfig",
"=",
"new",
"ControllerConfig",
"(",
"$",
"config",
"[",
"'controller'",
"]",
")",
",",
"SawEnv",
"::",
"web",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"container",
"->",
"register",
"(",
"new",
"MemoryContainer",
"(",
")",
")",
";",
"$",
"this",
"->",
"applicationLoader",
"=",
"new",
"ApplicationLoader",
"(",
"new",
"ApplicationConfig",
"(",
"$",
"config",
"[",
"'application'",
"]",
")",
",",
"new",
"ApplicationFactory",
"(",
"$",
"this",
"->",
"container",
")",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"debug",
")",
"{",
"set_exception_handler",
"(",
"function",
"(",
"\\",
"Throwable",
"$",
"exception",
")",
"{",
"if",
"(",
"$",
"exception",
"instanceof",
"\\",
"Exception",
")",
"{",
"switch",
"(",
"$",
"exception",
"->",
"getCode",
"(",
")",
")",
"{",
"case",
"self",
"::",
"ERROR_WRONG_CONFIG",
":",
"echo",
"$",
"exception",
"->",
"getMessage",
"(",
")",
";",
"exit",
"(",
"$",
"exception",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"/*$compiler = new ContainerCompiler($this->container);\n $compiler->compile('build/container.php');*/",
"return",
"$",
"this",
";",
"}"
] | Инициализация фреймворка с заданным конфигом.
@param string $configPath
@return Saw | [
"Инициализация",
"фреймворка",
"с",
"заданным",
"конфигом",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Saw.php#L85-L154 |
maestroprog/saw-php | src/Saw.php | Saw.instanceApp | public function instanceApp(string $appClass): ApplicationInterface
{
return $this
->container
->getApplicationContainer()
->add($this->applicationLoader->instanceApp($appClass));
} | php | public function instanceApp(string $appClass): ApplicationInterface
{
return $this
->container
->getApplicationContainer()
->add($this->applicationLoader->instanceApp($appClass));
} | [
"public",
"function",
"instanceApp",
"(",
"string",
"$",
"appClass",
")",
":",
"ApplicationInterface",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"getApplicationContainer",
"(",
")",
"->",
"add",
"(",
"$",
"this",
"->",
"applicationLoader",
"->",
"instanceApp",
"(",
"$",
"appClass",
")",
")",
";",
"}"
] | Инстанцирование приложения.
@param string $appClass
@return ApplicationInterface | [
"Инстанцирование",
"приложения",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Saw.php#L167-L173 |
maestroprog/saw-php | src/Saw.php | Saw.instanceController | public function instanceController(): Controller
{
$this->sawContainer->setEnvironment(SawEnv::controller());
return new Controller(
$this->container->get('WorkCycle'),
$this->container->get(ControllerCore::class),
$this->container->get('ControllerServer'),
$this->container->get(CommandDispatcher::class),
$this->daemonConfig->getControllerPid() // todo
);
} | php | public function instanceController(): Controller
{
$this->sawContainer->setEnvironment(SawEnv::controller());
return new Controller(
$this->container->get('WorkCycle'),
$this->container->get(ControllerCore::class),
$this->container->get('ControllerServer'),
$this->container->get(CommandDispatcher::class),
$this->daemonConfig->getControllerPid() // todo
);
} | [
"public",
"function",
"instanceController",
"(",
")",
":",
"Controller",
"{",
"$",
"this",
"->",
"sawContainer",
"->",
"setEnvironment",
"(",
"SawEnv",
"::",
"controller",
"(",
")",
")",
";",
"return",
"new",
"Controller",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'WorkCycle'",
")",
",",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"ControllerCore",
"::",
"class",
")",
",",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'ControllerServer'",
")",
",",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"CommandDispatcher",
"::",
"class",
")",
",",
"$",
"this",
"->",
"daemonConfig",
"->",
"getControllerPid",
"(",
")",
"// todo",
")",
";",
"}"
] | Создаёт новый инстанс объекта контроллера.
@return Controller | [
"Создаёт",
"новый",
"инстанс",
"объекта",
"контроллера",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Saw.php#L180-L191 |
heidelpay/PhpDoc | src/phpDocumentor/Descriptor/ClassDescriptor.php | ClassDescriptor.getInheritedConstants | public function getInheritedConstants()
{
if (!$this->getParent() || (!$this->getParent() instanceof ClassDescriptor)) {
return new Collection();
}
$inheritedConstants = clone $this->getParent()->getConstants();
return $inheritedConstants->merge($this->getParent()->getInheritedConstants());
} | php | public function getInheritedConstants()
{
if (!$this->getParent() || (!$this->getParent() instanceof ClassDescriptor)) {
return new Collection();
}
$inheritedConstants = clone $this->getParent()->getConstants();
return $inheritedConstants->merge($this->getParent()->getInheritedConstants());
} | [
"public",
"function",
"getInheritedConstants",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getParent",
"(",
")",
"||",
"(",
"!",
"$",
"this",
"->",
"getParent",
"(",
")",
"instanceof",
"ClassDescriptor",
")",
")",
"{",
"return",
"new",
"Collection",
"(",
")",
";",
"}",
"$",
"inheritedConstants",
"=",
"clone",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getConstants",
"(",
")",
";",
"return",
"$",
"inheritedConstants",
"->",
"merge",
"(",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getInheritedConstants",
"(",
")",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/ClassDescriptor.php#L140-L149 |
heidelpay/PhpDoc | src/phpDocumentor/Descriptor/ClassDescriptor.php | ClassDescriptor.getInheritedProperties | public function getInheritedProperties()
{
$inheritedProperties = new Collection();
foreach ($this->getUsedTraits() as $trait) {
if (!$trait instanceof TraitDescriptor) {
continue;
}
$inheritedProperties = $inheritedProperties->merge(clone $trait->getProperties());
}
if (!$this->getParent() || (!$this->getParent() instanceof ClassDescriptor)) {
return $inheritedProperties;
}
$inheritedProperties = $inheritedProperties->merge(clone $this->getParent()->getProperties());
return $inheritedProperties->merge($this->getParent()->getInheritedProperties());
} | php | public function getInheritedProperties()
{
$inheritedProperties = new Collection();
foreach ($this->getUsedTraits() as $trait) {
if (!$trait instanceof TraitDescriptor) {
continue;
}
$inheritedProperties = $inheritedProperties->merge(clone $trait->getProperties());
}
if (!$this->getParent() || (!$this->getParent() instanceof ClassDescriptor)) {
return $inheritedProperties;
}
$inheritedProperties = $inheritedProperties->merge(clone $this->getParent()->getProperties());
return $inheritedProperties->merge($this->getParent()->getInheritedProperties());
} | [
"public",
"function",
"getInheritedProperties",
"(",
")",
"{",
"$",
"inheritedProperties",
"=",
"new",
"Collection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getUsedTraits",
"(",
")",
"as",
"$",
"trait",
")",
"{",
"if",
"(",
"!",
"$",
"trait",
"instanceof",
"TraitDescriptor",
")",
"{",
"continue",
";",
"}",
"$",
"inheritedProperties",
"=",
"$",
"inheritedProperties",
"->",
"merge",
"(",
"clone",
"$",
"trait",
"->",
"getProperties",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getParent",
"(",
")",
"||",
"(",
"!",
"$",
"this",
"->",
"getParent",
"(",
")",
"instanceof",
"ClassDescriptor",
")",
")",
"{",
"return",
"$",
"inheritedProperties",
";",
"}",
"$",
"inheritedProperties",
"=",
"$",
"inheritedProperties",
"->",
"merge",
"(",
"clone",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getProperties",
"(",
")",
")",
";",
"return",
"$",
"inheritedProperties",
"->",
"merge",
"(",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getInheritedProperties",
"(",
")",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/ClassDescriptor.php#L244-L263 |
josegonzalez/cakephp-sanction | View/Helper/ClearanceHelper.php | ClearanceHelper.link | public function link($title, $url = null, $options = array(), $confirmMessage = false) {
if (!is_array($url)) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
if (!isset($url['plugin']) && !empty($url['plugin'])) {
$url['plugin'] = $this->params['plugin'];
}
if (!isset($url['controller']) && empty($url['controller'])) {
$url['controller'] = $this->params['controller'];
}
if (!isset($url['action']) && empty($url['action'])) {
$url['action'] = $this->params['action'];
}
if (empty($this->routes)) {
$Permit =& PermitComponent::getInstance();
$this->routes = $Permit->routes;
}
if (empty($this->routes)) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
foreach ($this->routes as $route) {
if ($this->parse($url, $route)) {
return $this->execute($route, $title, $url, $options, $confirmMessage);
}
}
return $this->Html->link($title, $url, $options, $confirmMessage);
} | php | public function link($title, $url = null, $options = array(), $confirmMessage = false) {
if (!is_array($url)) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
if (!isset($url['plugin']) && !empty($url['plugin'])) {
$url['plugin'] = $this->params['plugin'];
}
if (!isset($url['controller']) && empty($url['controller'])) {
$url['controller'] = $this->params['controller'];
}
if (!isset($url['action']) && empty($url['action'])) {
$url['action'] = $this->params['action'];
}
if (empty($this->routes)) {
$Permit =& PermitComponent::getInstance();
$this->routes = $Permit->routes;
}
if (empty($this->routes)) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
foreach ($this->routes as $route) {
if ($this->parse($url, $route)) {
return $this->execute($route, $title, $url, $options, $confirmMessage);
}
}
return $this->Html->link($title, $url, $options, $confirmMessage);
} | [
"public",
"function",
"link",
"(",
"$",
"title",
",",
"$",
"url",
"=",
"null",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"confirmMessage",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"url",
")",
")",
"{",
"return",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"url",
"[",
"'plugin'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"url",
"[",
"'plugin'",
"]",
")",
")",
"{",
"$",
"url",
"[",
"'plugin'",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"'plugin'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"url",
"[",
"'controller'",
"]",
")",
"&&",
"empty",
"(",
"$",
"url",
"[",
"'controller'",
"]",
")",
")",
"{",
"$",
"url",
"[",
"'controller'",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"'controller'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"url",
"[",
"'action'",
"]",
")",
"&&",
"empty",
"(",
"$",
"url",
"[",
"'action'",
"]",
")",
")",
"{",
"$",
"url",
"[",
"'action'",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"'action'",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"$",
"Permit",
"=",
"&",
"PermitComponent",
"::",
"getInstance",
"(",
")",
";",
"$",
"this",
"->",
"routes",
"=",
"$",
"Permit",
"->",
"routes",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"return",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parse",
"(",
"$",
"url",
",",
"$",
"route",
")",
")",
"{",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"route",
",",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}"
] | Creates an HTML link.
If $url starts with "http://" this is treated as an external link. Else,
it is treated as a path to controller/action and parsed against the routes
included in app/config/permit.php. If there is a match and the User's session
clears with the rules, it is then sent off to the HtmlHelper::link() method
If the $url is empty, $title is used instead.
### Options
- `escape` Set to false to disable escaping of title and attributes.
@param string $title The content to be wrapped by <a> tags.
@param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
@param array $options Array of HTML attributes.
@param string $confirmMessage JavaScript confirmation message.
@return string An `<a />` element.
@author Jose Diaz-Gonzalez | [
"Creates",
"an",
"HTML",
"link",
"."
] | train | https://github.com/josegonzalez/cakephp-sanction/blob/df2a8f0c0602c0ace802773db2c2ca6c89555c47/View/Helper/ClearanceHelper.php#L85-L118 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.