repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.htmlEntities
|
public function htmlEntities($flags = ENT_HTML5, string $encoding = 'UTF-8', bool $doubleEncode = true) : Manipulator
{
return new static(htmlentities($this->string, $flags, $encoding, $doubleEncode));
}
|
php
|
public function htmlEntities($flags = ENT_HTML5, string $encoding = 'UTF-8', bool $doubleEncode = true) : Manipulator
{
return new static(htmlentities($this->string, $flags, $encoding, $doubleEncode));
}
|
[
"public",
"function",
"htmlEntities",
"(",
"$",
"flags",
"=",
"ENT_HTML5",
",",
"string",
"$",
"encoding",
"=",
"'UTF-8'",
",",
"bool",
"$",
"doubleEncode",
"=",
"true",
")",
":",
"Manipulator",
"{",
"return",
"new",
"static",
"(",
"htmlentities",
"(",
"$",
"this",
"->",
"string",
",",
"$",
"flags",
",",
"$",
"encoding",
",",
"$",
"doubleEncode",
")",
")",
";",
"}"
] |
HTML Entities
@param constant $flags
@param string $encoding
@param boolean $doubleEncode
@return object|Manipulator
|
[
"HTML",
"Entities"
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L174-L177
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.htmlSpecialCharacters
|
public function htmlSpecialCharacters($flags = ENT_HTML5, string $encoding = 'UTF-8', bool $doubleEncode = true) : Manipulator
{
return new static(htmlspecialchars($this->string, $flags, $encoding, $doubleEncode));
}
|
php
|
public function htmlSpecialCharacters($flags = ENT_HTML5, string $encoding = 'UTF-8', bool $doubleEncode = true) : Manipulator
{
return new static(htmlspecialchars($this->string, $flags, $encoding, $doubleEncode));
}
|
[
"public",
"function",
"htmlSpecialCharacters",
"(",
"$",
"flags",
"=",
"ENT_HTML5",
",",
"string",
"$",
"encoding",
"=",
"'UTF-8'",
",",
"bool",
"$",
"doubleEncode",
"=",
"true",
")",
":",
"Manipulator",
"{",
"return",
"new",
"static",
"(",
"htmlspecialchars",
"(",
"$",
"this",
"->",
"string",
",",
"$",
"flags",
",",
"$",
"encoding",
",",
"$",
"doubleEncode",
")",
")",
";",
"}"
] |
HTML Special Characters
@param constant $flags
@param string $encoding
@param boolean $doubleEncode
@return object|Manipulator
|
[
"HTML",
"Special",
"Characters"
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L187-L190
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.pad
|
public function pad(int $length, string $string, $type = null) : Manipulator
{
return new static(str_pad($this->string, $length, $string, $type));
}
|
php
|
public function pad(int $length, string $string, $type = null) : Manipulator
{
return new static(str_pad($this->string, $length, $string, $type));
}
|
[
"public",
"function",
"pad",
"(",
"int",
"$",
"length",
",",
"string",
"$",
"string",
",",
"$",
"type",
"=",
"null",
")",
":",
"Manipulator",
"{",
"return",
"new",
"static",
"(",
"str_pad",
"(",
"$",
"this",
"->",
"string",
",",
"$",
"length",
",",
"$",
"string",
",",
"$",
"type",
")",
")",
";",
"}"
] |
Pad
@param int
@param string
@param constant
@return object|Manipulator
|
[
"Pad"
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L223-L226
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.pluralize
|
public function pluralize($items = null) : Manipulator
{
/**
* Optional parameter to determine if a string
* should be pluralized.
*/
if (!is_null($items)) {
$count = is_numeric($items) ? $items : count($items);
if ($count <= 1) {
return $this;
}
}
return new static(Inflector::pluralize($this->string));
}
|
php
|
public function pluralize($items = null) : Manipulator
{
/**
* Optional parameter to determine if a string
* should be pluralized.
*/
if (!is_null($items)) {
$count = is_numeric($items) ? $items : count($items);
if ($count <= 1) {
return $this;
}
}
return new static(Inflector::pluralize($this->string));
}
|
[
"public",
"function",
"pluralize",
"(",
"$",
"items",
"=",
"null",
")",
":",
"Manipulator",
"{",
"/**\n * Optional parameter to determine if a string\n * should be pluralized.\n */",
"if",
"(",
"!",
"is_null",
"(",
"$",
"items",
")",
")",
"{",
"$",
"count",
"=",
"is_numeric",
"(",
"$",
"items",
")",
"?",
"$",
"items",
":",
"count",
"(",
"$",
"items",
")",
";",
"if",
"(",
"$",
"count",
"<=",
"1",
")",
"{",
"return",
"$",
"this",
";",
"}",
"}",
"return",
"new",
"static",
"(",
"Inflector",
"::",
"pluralize",
"(",
"$",
"this",
"->",
"string",
")",
")",
";",
"}"
] |
Pluralize String
@param mixed
@return object|Manipulator
|
[
"Pluralize",
"String"
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L234-L249
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.nthCharacter
|
public function nthCharacter(int $nth, \Closure $closure) : Manipulator
{
$count = 1;
$modifiedString = '';
foreach (str_split($this->string) as $character) {
$modifiedString .= $count === $nth ? $closure($character) : $character;
$count++;
}
return new static($modifiedString);
}
|
php
|
public function nthCharacter(int $nth, \Closure $closure) : Manipulator
{
$count = 1;
$modifiedString = '';
foreach (str_split($this->string) as $character) {
$modifiedString .= $count === $nth ? $closure($character) : $character;
$count++;
}
return new static($modifiedString);
}
|
[
"public",
"function",
"nthCharacter",
"(",
"int",
"$",
"nth",
",",
"\\",
"Closure",
"$",
"closure",
")",
":",
"Manipulator",
"{",
"$",
"count",
"=",
"1",
";",
"$",
"modifiedString",
"=",
"''",
";",
"foreach",
"(",
"str_split",
"(",
"$",
"this",
"->",
"string",
")",
"as",
"$",
"character",
")",
"{",
"$",
"modifiedString",
".=",
"$",
"count",
"===",
"$",
"nth",
"?",
"$",
"closure",
"(",
"$",
"character",
")",
":",
"$",
"character",
";",
"$",
"count",
"++",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"modifiedString",
")",
";",
"}"
] |
Perfrom an action on the nth character.
@param int
@param Closure
@return object|Manipulator
|
[
"Perfrom",
"an",
"action",
"on",
"the",
"nth",
"character",
"."
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L269-L280
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.nthWord
|
public function nthWord(int $nth, \Closure $closure, bool $preserveSpaces = true) : Manipulator
{
$count = 1;
$modifiedString = '';
foreach (explode(' ', $this->string) as $word) {
$modifiedString .= $count === $nth ? $closure($word) : $word;
$modifiedString .= $preserveSpaces ? ' ' : '';
$count++;
}
return new static(trim($modifiedString));
}
|
php
|
public function nthWord(int $nth, \Closure $closure, bool $preserveSpaces = true) : Manipulator
{
$count = 1;
$modifiedString = '';
foreach (explode(' ', $this->string) as $word) {
$modifiedString .= $count === $nth ? $closure($word) : $word;
$modifiedString .= $preserveSpaces ? ' ' : '';
$count++;
}
return new static(trim($modifiedString));
}
|
[
"public",
"function",
"nthWord",
"(",
"int",
"$",
"nth",
",",
"\\",
"Closure",
"$",
"closure",
",",
"bool",
"$",
"preserveSpaces",
"=",
"true",
")",
":",
"Manipulator",
"{",
"$",
"count",
"=",
"1",
";",
"$",
"modifiedString",
"=",
"''",
";",
"foreach",
"(",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"string",
")",
"as",
"$",
"word",
")",
"{",
"$",
"modifiedString",
".=",
"$",
"count",
"===",
"$",
"nth",
"?",
"$",
"closure",
"(",
"$",
"word",
")",
":",
"$",
"word",
";",
"$",
"modifiedString",
".=",
"$",
"preserveSpaces",
"?",
"' '",
":",
"''",
";",
"$",
"count",
"++",
";",
"}",
"return",
"new",
"static",
"(",
"trim",
"(",
"$",
"modifiedString",
")",
")",
";",
"}"
] |
Perform an action on the nth word.
@param int
@param Closure
@param boolean
@return object|Manipulator
|
[
"Perform",
"an",
"action",
"on",
"the",
"nth",
"word",
"."
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L290-L302
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.remove
|
public function remove(string $string, bool $caseSensitive = true) : Manipulator
{
return new static($this->replace($string, '', $caseSensitive)->toString());
}
|
php
|
public function remove(string $string, bool $caseSensitive = true) : Manipulator
{
return new static($this->replace($string, '', $caseSensitive)->toString());
}
|
[
"public",
"function",
"remove",
"(",
"string",
"$",
"string",
",",
"bool",
"$",
"caseSensitive",
"=",
"true",
")",
":",
"Manipulator",
"{",
"return",
"new",
"static",
"(",
"$",
"this",
"->",
"replace",
"(",
"$",
"string",
",",
"''",
",",
"$",
"caseSensitive",
")",
"->",
"toString",
"(",
")",
")",
";",
"}"
] |
Remove from string.
@param string
@param boolean
@return object|Manipulator
|
[
"Remove",
"from",
"string",
"."
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L311-L314
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.removeSpecialCharacters
|
public function removeSpecialCharacters(array $exceptions = []) : Manipulator
{
$regEx = "/";
$regEx .= "[^\w\d";
foreach ($exceptions as $exception) {
$regEx .= "\\" . $exception;
}
$regEx .= "]/";
$modifiedString = preg_replace($regEx, '', $this->string);
return new static($modifiedString);
}
|
php
|
public function removeSpecialCharacters(array $exceptions = []) : Manipulator
{
$regEx = "/";
$regEx .= "[^\w\d";
foreach ($exceptions as $exception) {
$regEx .= "\\" . $exception;
}
$regEx .= "]/";
$modifiedString = preg_replace($regEx, '', $this->string);
return new static($modifiedString);
}
|
[
"public",
"function",
"removeSpecialCharacters",
"(",
"array",
"$",
"exceptions",
"=",
"[",
"]",
")",
":",
"Manipulator",
"{",
"$",
"regEx",
"=",
"\"/\"",
";",
"$",
"regEx",
".=",
"\"[^\\w\\d\"",
";",
"foreach",
"(",
"$",
"exceptions",
"as",
"$",
"exception",
")",
"{",
"$",
"regEx",
".=",
"\"\\\\\"",
".",
"$",
"exception",
";",
"}",
"$",
"regEx",
".=",
"\"]/\"",
";",
"$",
"modifiedString",
"=",
"preg_replace",
"(",
"$",
"regEx",
",",
"''",
",",
"$",
"this",
"->",
"string",
")",
";",
"return",
"new",
"static",
"(",
"$",
"modifiedString",
")",
";",
"}"
] |
Remove non-alphanumeric characters.
@param array
@return object|Manipulator
|
[
"Remove",
"non",
"-",
"alphanumeric",
"characters",
"."
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L322-L336
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.replace
|
public function replace(string $find, string $replace = '', bool $caseSensitive = true) : Manipulator
{
$replaced = $caseSensitive ? str_replace($find, $replace, $this->string) :
str_ireplace($find, $replace, $this->string);
return new static($replaced);
}
|
php
|
public function replace(string $find, string $replace = '', bool $caseSensitive = true) : Manipulator
{
$replaced = $caseSensitive ? str_replace($find, $replace, $this->string) :
str_ireplace($find, $replace, $this->string);
return new static($replaced);
}
|
[
"public",
"function",
"replace",
"(",
"string",
"$",
"find",
",",
"string",
"$",
"replace",
"=",
"''",
",",
"bool",
"$",
"caseSensitive",
"=",
"true",
")",
":",
"Manipulator",
"{",
"$",
"replaced",
"=",
"$",
"caseSensitive",
"?",
"str_replace",
"(",
"$",
"find",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"string",
")",
":",
"str_ireplace",
"(",
"$",
"find",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"string",
")",
";",
"return",
"new",
"static",
"(",
"$",
"replaced",
")",
";",
"}"
] |
Replace
@param string $find
@param string $replace
@param bool $caseSensitive
@return object|Manipulator
|
[
"Replace"
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L357-L363
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.snakeToCamel
|
public function snakeToCamel() : Manipulator
{
$modifiedString = $this->replace('_', ' ')
->capitalizeEach()
->lowercaseFirst()
->remove(' ')
->toString();
return new static($modifiedString);
}
|
php
|
public function snakeToCamel() : Manipulator
{
$modifiedString = $this->replace('_', ' ')
->capitalizeEach()
->lowercaseFirst()
->remove(' ')
->toString();
return new static($modifiedString);
}
|
[
"public",
"function",
"snakeToCamel",
"(",
")",
":",
"Manipulator",
"{",
"$",
"modifiedString",
"=",
"$",
"this",
"->",
"replace",
"(",
"'_'",
",",
"' '",
")",
"->",
"capitalizeEach",
"(",
")",
"->",
"lowercaseFirst",
"(",
")",
"->",
"remove",
"(",
"' '",
")",
"->",
"toString",
"(",
")",
";",
"return",
"new",
"static",
"(",
"$",
"modifiedString",
")",
";",
"}"
] |
Convert snake-case to camel-case.
@return object|Manipulator
|
[
"Convert",
"snake",
"-",
"case",
"to",
"camel",
"-",
"case",
"."
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L380-L389
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.snakeToClass
|
public function snakeToClass() : Manipulator
{
$modifiedString = $this->replace('_', ' ')
->toLower()
->capitalizeEach()
->replace(' ', '')
->toString();
return new static($modifiedString);
}
|
php
|
public function snakeToClass() : Manipulator
{
$modifiedString = $this->replace('_', ' ')
->toLower()
->capitalizeEach()
->replace(' ', '')
->toString();
return new static($modifiedString);
}
|
[
"public",
"function",
"snakeToClass",
"(",
")",
":",
"Manipulator",
"{",
"$",
"modifiedString",
"=",
"$",
"this",
"->",
"replace",
"(",
"'_'",
",",
"' '",
")",
"->",
"toLower",
"(",
")",
"->",
"capitalizeEach",
"(",
")",
"->",
"replace",
"(",
"' '",
",",
"''",
")",
"->",
"toString",
"(",
")",
";",
"return",
"new",
"static",
"(",
"$",
"modifiedString",
")",
";",
"}"
] |
snakeToClass
@return object|Manipulator
|
[
"snakeToClass"
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L396-L405
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.toCamelCase
|
public function toCamelCase() : Manipulator
{
$modifiedString = '';
foreach (explode(' ', $this->string) as $word) {
$modifiedString .= self::make($word)->toLower()->capitalize()->toString();
}
$final = self::make($modifiedString)
->replace(' ', '')
->lowercaseFirst()
->toString();
return new static($final);
}
|
php
|
public function toCamelCase() : Manipulator
{
$modifiedString = '';
foreach (explode(' ', $this->string) as $word) {
$modifiedString .= self::make($word)->toLower()->capitalize()->toString();
}
$final = self::make($modifiedString)
->replace(' ', '')
->lowercaseFirst()
->toString();
return new static($final);
}
|
[
"public",
"function",
"toCamelCase",
"(",
")",
":",
"Manipulator",
"{",
"$",
"modifiedString",
"=",
"''",
";",
"foreach",
"(",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"string",
")",
"as",
"$",
"word",
")",
"{",
"$",
"modifiedString",
".=",
"self",
"::",
"make",
"(",
"$",
"word",
")",
"->",
"toLower",
"(",
")",
"->",
"capitalize",
"(",
")",
"->",
"toString",
"(",
")",
";",
"}",
"$",
"final",
"=",
"self",
"::",
"make",
"(",
"$",
"modifiedString",
")",
"->",
"replace",
"(",
"' '",
",",
"''",
")",
"->",
"lowercaseFirst",
"(",
")",
"->",
"toString",
"(",
")",
";",
"return",
"new",
"static",
"(",
"$",
"final",
")",
";",
"}"
] |
Convert a string to camel-case.
@return object|Manipulator
|
[
"Convert",
"a",
"string",
"to",
"camel",
"-",
"case",
"."
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L423-L437
|
mattsparks/the-stringler
|
src/Manipulator.php
|
Manipulator.truncate
|
public function truncate(int $length = 100, string $append = '...') : Manipulator
{
return new static(mb_substr($this->string, 0, $length) . $append);
}
|
php
|
public function truncate(int $length = 100, string $append = '...') : Manipulator
{
return new static(mb_substr($this->string, 0, $length) . $append);
}
|
[
"public",
"function",
"truncate",
"(",
"int",
"$",
"length",
"=",
"100",
",",
"string",
"$",
"append",
"=",
"'...'",
")",
":",
"Manipulator",
"{",
"return",
"new",
"static",
"(",
"mb_substr",
"(",
"$",
"this",
"->",
"string",
",",
"0",
",",
"$",
"length",
")",
".",
"$",
"append",
")",
";",
"}"
] |
Truncate
@param int $length
@param string $append
@return object|Manipulator
|
[
"Truncate"
] |
train
|
https://github.com/mattsparks/the-stringler/blob/bc11319ae4330b8ee1ed7333934ff180423b5218/src/Manipulator.php#L547-L550
|
yuncms/framework
|
src/user/models/UserProfile.php
|
UserProfile.getCurrentName
|
public function getCurrentName()
{
switch ($this->current) {
case self::CURRENT_OTHER:
$currentName = Yii::t('yuncms', 'Other');
break;
case self::CURRENT_WORK:
$currentName = Yii::t('yuncms', 'Work');
break;
case self::CURRENT_FREELANCE:
$currentName = Yii::t('yuncms', 'Freelance');
break;
case self::CURRENT_START:
$currentName = Yii::t('yuncms', 'Start');
break;
case self::CURRENT_OUTSOURCE:
$currentName = Yii::t('yuncms', 'Outsource');
break;
case self::CURRENT_JOB:
$currentName = Yii::t('yuncms', 'Job');
break;
case self::CURRENT_STUDENT:
$currentName = Yii::t('yuncms', 'Student');
break;
default:
throw new \RuntimeException('Your database is not supported!');
}
return $currentName;
}
|
php
|
public function getCurrentName()
{
switch ($this->current) {
case self::CURRENT_OTHER:
$currentName = Yii::t('yuncms', 'Other');
break;
case self::CURRENT_WORK:
$currentName = Yii::t('yuncms', 'Work');
break;
case self::CURRENT_FREELANCE:
$currentName = Yii::t('yuncms', 'Freelance');
break;
case self::CURRENT_START:
$currentName = Yii::t('yuncms', 'Start');
break;
case self::CURRENT_OUTSOURCE:
$currentName = Yii::t('yuncms', 'Outsource');
break;
case self::CURRENT_JOB:
$currentName = Yii::t('yuncms', 'Job');
break;
case self::CURRENT_STUDENT:
$currentName = Yii::t('yuncms', 'Student');
break;
default:
throw new \RuntimeException('Your database is not supported!');
}
return $currentName;
}
|
[
"public",
"function",
"getCurrentName",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"current",
")",
"{",
"case",
"self",
"::",
"CURRENT_OTHER",
":",
"$",
"currentName",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Other'",
")",
";",
"break",
";",
"case",
"self",
"::",
"CURRENT_WORK",
":",
"$",
"currentName",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Work'",
")",
";",
"break",
";",
"case",
"self",
"::",
"CURRENT_FREELANCE",
":",
"$",
"currentName",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Freelance'",
")",
";",
"break",
";",
"case",
"self",
"::",
"CURRENT_START",
":",
"$",
"currentName",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Start'",
")",
";",
"break",
";",
"case",
"self",
"::",
"CURRENT_OUTSOURCE",
":",
"$",
"currentName",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Outsource'",
")",
";",
"break",
";",
"case",
"self",
"::",
"CURRENT_JOB",
":",
"$",
"currentName",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Job'",
")",
";",
"break",
";",
"case",
"self",
"::",
"CURRENT_STUDENT",
":",
"$",
"currentName",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Student'",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Your database is not supported!'",
")",
";",
"}",
"return",
"$",
"currentName",
";",
"}"
] |
获取职业的字符串标识
@return string
|
[
"获取职业的字符串标识"
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/UserProfile.php#L189-L217
|
yuncms/framework
|
src/user/models/UserProfile.php
|
UserProfile.validateTimeZone
|
public function validateTimeZone($attribute)
{
if (!in_array($this->$attribute, timezone_identifiers_list())) {
$this->addError($attribute, Yii::t('yuncms', 'Time zone is not valid'));
}
}
|
php
|
public function validateTimeZone($attribute)
{
if (!in_array($this->$attribute, timezone_identifiers_list())) {
$this->addError($attribute, Yii::t('yuncms', 'Time zone is not valid'));
}
}
|
[
"public",
"function",
"validateTimeZone",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"$",
"attribute",
",",
"timezone_identifiers_list",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Time zone is not valid'",
")",
")",
";",
"}",
"}"
] |
验证时区
Adds an error when the specified time zone doesn't exist.
@param string $attribute the attribute being validated
@return void
|
[
"验证时区",
"Adds",
"an",
"error",
"when",
"the",
"specified",
"time",
"zone",
"doesn",
"t",
"exist",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/UserProfile.php#L250-L255
|
inpsyde/inpsyde-filter
|
src/WordPress/StripTags.php
|
StripTags.filter
|
public function filter( $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not string or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
$strict = (bool) $this->options[ 'strict' ];
return wp_strip_all_tags( $value, $strict );
}
|
php
|
public function filter( $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not string or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
$strict = (bool) $this->options[ 'strict' ];
return wp_strip_all_tags( $value, $strict );
}
|
[
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
"||",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"do_action",
"(",
"'inpsyde.filter.error'",
",",
"'The given value is not string or empty.'",
",",
"[",
"'method'",
"=>",
"__METHOD__",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"return",
"$",
"value",
";",
"}",
"$",
"strict",
"=",
"(",
"bool",
")",
"$",
"this",
"->",
"options",
"[",
"'strict'",
"]",
";",
"return",
"wp_strip_all_tags",
"(",
"$",
"value",
",",
"$",
"strict",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/WordPress/StripTags.php#L25-L36
|
phpmob/changmin
|
src/PhpMob/CoreBundle/Context/ParameterContext.php
|
ParameterContext.get
|
public function get(string $parameter, $default = null)
{
if (false === $this->container->hasParameter($parameter)) {
return $default;
}
if (null === $value = $this->container->getParameter($parameter)) {
return $default;
}
return $value;
}
|
php
|
public function get(string $parameter, $default = null)
{
if (false === $this->container->hasParameter($parameter)) {
return $default;
}
if (null === $value = $this->container->getParameter($parameter)) {
return $default;
}
return $value;
}
|
[
"public",
"function",
"get",
"(",
"string",
"$",
"parameter",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"container",
"->",
"hasParameter",
"(",
"$",
"parameter",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"value",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"$",
"parameter",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
@param string $parameter
@param null $default
@return mixed|null
|
[
"@param",
"string",
"$parameter",
"@param",
"null",
"$default"
] |
train
|
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CoreBundle/Context/ParameterContext.php#L36-L47
|
GrahamDeprecated/CMS-Core
|
src/Classes/Viewer.php
|
Viewer.make
|
public function make($view, array $data = array(), $type = 'default')
{
if ($this->credentials->check()) {
if ($type === 'admin') {
if ($this->credentials->hasAccess('admin')) {
$data['site_name'] = 'Admin Panel';
$data['navigation'] = $this->navigation->getHTML('admin', 'admin', array('title' => $data['site_name'], 'side' => $this->credentials->getUser()->email, 'inverse' => $this->inverse));
} else {
$data['site_name'] = $this->name;
$data['navigation'] = $this->navigation->getHTML('default', 'default', array('title' => $data['site_name'], 'side' => $this->credentials->getUser()->email, 'inverse' => $this->inverse));
}
} else {
$data['site_name'] = $this->name;
$data['navigation'] = $this->navigation->getHTML('default', 'default', array('title' => $data['site_name'], 'side' => $this->credentials->getUser()->email, 'inverse' => $this->inverse));
}
} else {
$data['site_name'] = $this->name;
$data['navigation'] = $this->navigation->getHTML('default', false, array('title' => $data['site_name'], 'inverse' => $this->inverse));
}
return parent::make($view, $data);
}
|
php
|
public function make($view, array $data = array(), $type = 'default')
{
if ($this->credentials->check()) {
if ($type === 'admin') {
if ($this->credentials->hasAccess('admin')) {
$data['site_name'] = 'Admin Panel';
$data['navigation'] = $this->navigation->getHTML('admin', 'admin', array('title' => $data['site_name'], 'side' => $this->credentials->getUser()->email, 'inverse' => $this->inverse));
} else {
$data['site_name'] = $this->name;
$data['navigation'] = $this->navigation->getHTML('default', 'default', array('title' => $data['site_name'], 'side' => $this->credentials->getUser()->email, 'inverse' => $this->inverse));
}
} else {
$data['site_name'] = $this->name;
$data['navigation'] = $this->navigation->getHTML('default', 'default', array('title' => $data['site_name'], 'side' => $this->credentials->getUser()->email, 'inverse' => $this->inverse));
}
} else {
$data['site_name'] = $this->name;
$data['navigation'] = $this->navigation->getHTML('default', false, array('title' => $data['site_name'], 'inverse' => $this->inverse));
}
return parent::make($view, $data);
}
|
[
"public",
"function",
"make",
"(",
"$",
"view",
",",
"array",
"$",
"data",
"=",
"array",
"(",
")",
",",
"$",
"type",
"=",
"'default'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"credentials",
"->",
"check",
"(",
")",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'admin'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"credentials",
"->",
"hasAccess",
"(",
"'admin'",
")",
")",
"{",
"$",
"data",
"[",
"'site_name'",
"]",
"=",
"'Admin Panel'",
";",
"$",
"data",
"[",
"'navigation'",
"]",
"=",
"$",
"this",
"->",
"navigation",
"->",
"getHTML",
"(",
"'admin'",
",",
"'admin'",
",",
"array",
"(",
"'title'",
"=>",
"$",
"data",
"[",
"'site_name'",
"]",
",",
"'side'",
"=>",
"$",
"this",
"->",
"credentials",
"->",
"getUser",
"(",
")",
"->",
"email",
",",
"'inverse'",
"=>",
"$",
"this",
"->",
"inverse",
")",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'site_name'",
"]",
"=",
"$",
"this",
"->",
"name",
";",
"$",
"data",
"[",
"'navigation'",
"]",
"=",
"$",
"this",
"->",
"navigation",
"->",
"getHTML",
"(",
"'default'",
",",
"'default'",
",",
"array",
"(",
"'title'",
"=>",
"$",
"data",
"[",
"'site_name'",
"]",
",",
"'side'",
"=>",
"$",
"this",
"->",
"credentials",
"->",
"getUser",
"(",
")",
"->",
"email",
",",
"'inverse'",
"=>",
"$",
"this",
"->",
"inverse",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"data",
"[",
"'site_name'",
"]",
"=",
"$",
"this",
"->",
"name",
";",
"$",
"data",
"[",
"'navigation'",
"]",
"=",
"$",
"this",
"->",
"navigation",
"->",
"getHTML",
"(",
"'default'",
",",
"'default'",
",",
"array",
"(",
"'title'",
"=>",
"$",
"data",
"[",
"'site_name'",
"]",
",",
"'side'",
"=>",
"$",
"this",
"->",
"credentials",
"->",
"getUser",
"(",
")",
"->",
"email",
",",
"'inverse'",
"=>",
"$",
"this",
"->",
"inverse",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"data",
"[",
"'site_name'",
"]",
"=",
"$",
"this",
"->",
"name",
";",
"$",
"data",
"[",
"'navigation'",
"]",
"=",
"$",
"this",
"->",
"navigation",
"->",
"getHTML",
"(",
"'default'",
",",
"false",
",",
"array",
"(",
"'title'",
"=>",
"$",
"data",
"[",
"'site_name'",
"]",
",",
"'inverse'",
"=>",
"$",
"this",
"->",
"inverse",
")",
")",
";",
"}",
"return",
"parent",
"::",
"make",
"(",
"$",
"view",
",",
"$",
"data",
")",
";",
"}"
] |
Get a evaluated view contents for the given view.
@param string $view
@param array $data
@param string $type
@return \Illuminate\View\View
|
[
"Get",
"a",
"evaluated",
"view",
"contents",
"for",
"the",
"given",
"view",
"."
] |
train
|
https://github.com/GrahamDeprecated/CMS-Core/blob/5603e2bfa2fac6cf46ca3ed62d21518f2f653675/src/Classes/Viewer.php#L101-L122
|
yuncms/framework
|
src/broadcast/BaseMessage.php
|
BaseMessage.send
|
public function send(BroadcastInterface $broadcast = null)
{
if ($broadcast === null && $this->broadcast === null) {
$broadcast = Yii::$app->getBroadcast();
} elseif ($broadcast === null) {
$broadcast = $this->broadcast;
}
return $broadcast->send($this);
}
|
php
|
public function send(BroadcastInterface $broadcast = null)
{
if ($broadcast === null && $this->broadcast === null) {
$broadcast = Yii::$app->getBroadcast();
} elseif ($broadcast === null) {
$broadcast = $this->broadcast;
}
return $broadcast->send($this);
}
|
[
"public",
"function",
"send",
"(",
"BroadcastInterface",
"$",
"broadcast",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"broadcast",
"===",
"null",
"&&",
"$",
"this",
"->",
"broadcast",
"===",
"null",
")",
"{",
"$",
"broadcast",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getBroadcast",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"broadcast",
"===",
"null",
")",
"{",
"$",
"broadcast",
"=",
"$",
"this",
"->",
"broadcast",
";",
"}",
"return",
"$",
"broadcast",
"->",
"send",
"(",
"$",
"this",
")",
";",
"}"
] |
Sends this broadcast message.
@param BroadcastInterface $broadcast the broadcast that should be used to send this message.
If no broadcast is given it will first check if [[broadcast]] is set and if not,
the "broadcast" application component will be used instead.
@return bool whether this message is sent successfully.
|
[
"Sends",
"this",
"broadcast",
"message",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/broadcast/BaseMessage.php#L111-L120
|
drsdre/yii2-xmlsoccer
|
models/League.php
|
League.beforeSave
|
public function beforeSave($insert)
{
$this->latest_match = strtotime($this->latest_match);
return parent::beforeSave($insert);
}
|
php
|
public function beforeSave($insert)
{
$this->latest_match = strtotime($this->latest_match);
return parent::beforeSave($insert);
}
|
[
"public",
"function",
"beforeSave",
"(",
"$",
"insert",
")",
"{",
"$",
"this",
"->",
"latest_match",
"=",
"strtotime",
"(",
"$",
"this",
"->",
"latest_match",
")",
";",
"return",
"parent",
"::",
"beforeSave",
"(",
"$",
"insert",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/drsdre/yii2-xmlsoccer/blob/a746edee6269ed0791bac6c6165a946adc30d994/models/League.php#L98-L102
|
drsdre/yii2-xmlsoccer
|
models/League.php
|
League.afterFind
|
public function afterFind()
{
if (\Yii::$app->has('formatter')) {
$this->latest_match = \Yii::$app->formatter->asDatetime($this->latest_match);
}
return parent::afterFind();
}
|
php
|
public function afterFind()
{
if (\Yii::$app->has('formatter')) {
$this->latest_match = \Yii::$app->formatter->asDatetime($this->latest_match);
}
return parent::afterFind();
}
|
[
"public",
"function",
"afterFind",
"(",
")",
"{",
"if",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"has",
"(",
"'formatter'",
")",
")",
"{",
"$",
"this",
"->",
"latest_match",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"formatter",
"->",
"asDatetime",
"(",
"$",
"this",
"->",
"latest_match",
")",
";",
"}",
"return",
"parent",
"::",
"afterFind",
"(",
")",
";",
"}"
] |
{@inheritdoc}
@throws \yii\base\InvalidConfigException
|
[
"{"
] |
train
|
https://github.com/drsdre/yii2-xmlsoccer/blob/a746edee6269ed0791bac6c6165a946adc30d994/models/League.php#L108-L114
|
inpsyde/inpsyde-filter
|
src/WordPress/Unslash.php
|
Unslash.filter
|
public function filter( $value ) {
if ( ! is_scalar( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not scalar or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
return wp_unslash( $value );
}
|
php
|
public function filter( $value ) {
if ( ! is_scalar( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not scalar or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
return wp_unslash( $value );
}
|
[
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
"||",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"do_action",
"(",
"'inpsyde.filter.error'",
",",
"'The given value is not scalar or empty.'",
",",
"[",
"'method'",
"=>",
"__METHOD__",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"return",
"$",
"value",
";",
"}",
"return",
"wp_unslash",
"(",
"$",
"value",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/WordPress/Unslash.php#L17-L26
|
arsengoian/viper-framework
|
src/Viper/Core/Model/DB/Common/SQL.php
|
SQL.search
|
public function search(string $table, string $columns = "*", string $condition = "1",
string $key = "", string $appendix = "", string $appendixkey = "") : ?array {
$this -> normalizeSelectVals($columns, $condition);
$key = substr($this -> quote("%".$key."%"), 1, -1);
$appendixkey = substr($this -> quote($appendixkey), 1, -1);
// Find number of keys
$knum = substr_count($condition, "?");
// Find number of appendix keys
$aknum = substr_count($appendix, "?");
$values = [];
for ($i = 0; $i < $knum; $i++)
$values[] = $key;
for ($i = 0; $i < $aknum; $i++)
$values[] = $appendixkey;
return $this -> preparedStatement(
"SELECT $columns FROM $table WHERE $condition $appendix",
$values,
'DB::search'
);
}
|
php
|
public function search(string $table, string $columns = "*", string $condition = "1",
string $key = "", string $appendix = "", string $appendixkey = "") : ?array {
$this -> normalizeSelectVals($columns, $condition);
$key = substr($this -> quote("%".$key."%"), 1, -1);
$appendixkey = substr($this -> quote($appendixkey), 1, -1);
// Find number of keys
$knum = substr_count($condition, "?");
// Find number of appendix keys
$aknum = substr_count($appendix, "?");
$values = [];
for ($i = 0; $i < $knum; $i++)
$values[] = $key;
for ($i = 0; $i < $aknum; $i++)
$values[] = $appendixkey;
return $this -> preparedStatement(
"SELECT $columns FROM $table WHERE $condition $appendix",
$values,
'DB::search'
);
}
|
[
"public",
"function",
"search",
"(",
"string",
"$",
"table",
",",
"string",
"$",
"columns",
"=",
"\"*\"",
",",
"string",
"$",
"condition",
"=",
"\"1\"",
",",
"string",
"$",
"key",
"=",
"\"\"",
",",
"string",
"$",
"appendix",
"=",
"\"\"",
",",
"string",
"$",
"appendixkey",
"=",
"\"\"",
")",
":",
"?",
"array",
"{",
"$",
"this",
"->",
"normalizeSelectVals",
"(",
"$",
"columns",
",",
"$",
"condition",
")",
";",
"$",
"key",
"=",
"substr",
"(",
"$",
"this",
"->",
"quote",
"(",
"\"%\"",
".",
"$",
"key",
".",
"\"%\"",
")",
",",
"1",
",",
"-",
"1",
")",
";",
"$",
"appendixkey",
"=",
"substr",
"(",
"$",
"this",
"->",
"quote",
"(",
"$",
"appendixkey",
")",
",",
"1",
",",
"-",
"1",
")",
";",
"// Find number of keys",
"$",
"knum",
"=",
"substr_count",
"(",
"$",
"condition",
",",
"\"?\"",
")",
";",
"// Find number of appendix keys",
"$",
"aknum",
"=",
"substr_count",
"(",
"$",
"appendix",
",",
"\"?\"",
")",
";",
"$",
"values",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"knum",
";",
"$",
"i",
"++",
")",
"$",
"values",
"[",
"]",
"=",
"$",
"key",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"aknum",
";",
"$",
"i",
"++",
")",
"$",
"values",
"[",
"]",
"=",
"$",
"appendixkey",
";",
"return",
"$",
"this",
"->",
"preparedStatement",
"(",
"\"SELECT $columns FROM $table WHERE $condition $appendix\"",
",",
"$",
"values",
",",
"'DB::search'",
")",
";",
"}"
] |
TODO allow appendix keys for all
|
[
"TODO",
"allow",
"appendix",
"keys",
"for",
"all"
] |
train
|
https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Core/Model/DB/Common/SQL.php#L34-L58
|
miisieq/InfaktClient
|
src/Infakt/Mapper/BankAccountMapper.php
|
BankAccountMapper.map
|
public function map($data)
{
return (new BankAccount())
->setId((int) $data['id'])
->setBankName($data['bank_name'])
->setAccountNumber(str_replace(' ', '', $data['account_number']))
->setSwift($data['swift'] ?: null)
->setDefault($data['default']);
}
|
php
|
public function map($data)
{
return (new BankAccount())
->setId((int) $data['id'])
->setBankName($data['bank_name'])
->setAccountNumber(str_replace(' ', '', $data['account_number']))
->setSwift($data['swift'] ?: null)
->setDefault($data['default']);
}
|
[
"public",
"function",
"map",
"(",
"$",
"data",
")",
"{",
"return",
"(",
"new",
"BankAccount",
"(",
")",
")",
"->",
"setId",
"(",
"(",
"int",
")",
"$",
"data",
"[",
"'id'",
"]",
")",
"->",
"setBankName",
"(",
"$",
"data",
"[",
"'bank_name'",
"]",
")",
"->",
"setAccountNumber",
"(",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"data",
"[",
"'account_number'",
"]",
")",
")",
"->",
"setSwift",
"(",
"$",
"data",
"[",
"'swift'",
"]",
"?",
":",
"null",
")",
"->",
"setDefault",
"(",
"$",
"data",
"[",
"'default'",
"]",
")",
";",
"}"
] |
{@inheritdoc}
@param $data
@return BankAccount
|
[
"{",
"@inheritdoc",
"}"
] |
train
|
https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Mapper/BankAccountMapper.php#L18-L26
|
ixocreate/application
|
src/Http/Middleware/RootRequestWrapperMiddleware.php
|
RootRequestWrapperMiddleware.process
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$rootRequest = new RootRequest($request);
return $handler->handle($rootRequest);
}
|
php
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$rootRequest = new RootRequest($request);
return $handler->handle($rootRequest);
}
|
[
"public",
"function",
"process",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"RequestHandlerInterface",
"$",
"handler",
")",
":",
"ResponseInterface",
"{",
"$",
"rootRequest",
"=",
"new",
"RootRequest",
"(",
"$",
"request",
")",
";",
"return",
"$",
"handler",
"->",
"handle",
"(",
"$",
"rootRequest",
")",
";",
"}"
] |
Process an incoming server request and return a response, optionally delegating
response creation to a handler.
|
[
"Process",
"an",
"incoming",
"server",
"request",
"and",
"return",
"a",
"response",
"optionally",
"delegating",
"response",
"creation",
"to",
"a",
"handler",
"."
] |
train
|
https://github.com/ixocreate/application/blob/6b0ef355ecf96af63d0dd5b901b4c9a5a69daf05/src/Http/Middleware/RootRequestWrapperMiddleware.php#L24-L28
|
GrafiteInc/Mission-Control-Package
|
src/PerformanceService.php
|
PerformanceService.sendPerformance
|
public function sendPerformance()
{
$headers = [
'token' => $this->token,
];
if (is_null($this->token)) {
throw new Exception("Missing token", 1);
}
$query = $this->getPerformance();
$response = $this->curl::post($this->missionControlUrl, $headers, $query);
if ($response->code != 200) {
$this->error('Unable to message Mission Control, please confirm your token');
}
return true;
}
|
php
|
public function sendPerformance()
{
$headers = [
'token' => $this->token,
];
if (is_null($this->token)) {
throw new Exception("Missing token", 1);
}
$query = $this->getPerformance();
$response = $this->curl::post($this->missionControlUrl, $headers, $query);
if ($response->code != 200) {
$this->error('Unable to message Mission Control, please confirm your token');
}
return true;
}
|
[
"public",
"function",
"sendPerformance",
"(",
")",
"{",
"$",
"headers",
"=",
"[",
"'token'",
"=>",
"$",
"this",
"->",
"token",
",",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"token",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Missing token\"",
",",
"1",
")",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"getPerformance",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"curl",
"::",
"post",
"(",
"$",
"this",
"->",
"missionControlUrl",
",",
"$",
"headers",
",",
"$",
"query",
")",
";",
"if",
"(",
"$",
"response",
"->",
"code",
"!=",
"200",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Unable to message Mission Control, please confirm your token'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Send the exception to Mission control.
@param Exeption $exception
@return bool
|
[
"Send",
"the",
"exception",
"to",
"Mission",
"control",
"."
] |
train
|
https://github.com/GrafiteInc/Mission-Control-Package/blob/4e85f0b729329783b34e35d90abba2807899ff58/src/PerformanceService.php#L35-L54
|
GrafiteInc/Mission-Control-Package
|
src/PerformanceService.php
|
PerformanceService.getPerformance
|
public function getPerformance()
{
try {
return [
'memory' => $this->performanceAnalyzer->getMemory(),
'storage' => $this->performanceAnalyzer->getStorage(),
'cpu' => $this->performanceAnalyzer->getCpu(),
];
} catch (Exception $e) {
$this->issueService->exception($e);
}
}
|
php
|
public function getPerformance()
{
try {
return [
'memory' => $this->performanceAnalyzer->getMemory(),
'storage' => $this->performanceAnalyzer->getStorage(),
'cpu' => $this->performanceAnalyzer->getCpu(),
];
} catch (Exception $e) {
$this->issueService->exception($e);
}
}
|
[
"public",
"function",
"getPerformance",
"(",
")",
"{",
"try",
"{",
"return",
"[",
"'memory'",
"=>",
"$",
"this",
"->",
"performanceAnalyzer",
"->",
"getMemory",
"(",
")",
",",
"'storage'",
"=>",
"$",
"this",
"->",
"performanceAnalyzer",
"->",
"getStorage",
"(",
")",
",",
"'cpu'",
"=>",
"$",
"this",
"->",
"performanceAnalyzer",
"->",
"getCpu",
"(",
")",
",",
"]",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"issueService",
"->",
"exception",
"(",
"$",
"e",
")",
";",
"}",
"}"
] |
Collect data and set report details.
@return array
|
[
"Collect",
"data",
"and",
"set",
"report",
"details",
"."
] |
train
|
https://github.com/GrafiteInc/Mission-Control-Package/blob/4e85f0b729329783b34e35d90abba2807899ff58/src/PerformanceService.php#L61-L72
|
yuncms/framework
|
src/broadcast/BaseBroadcast.php
|
BaseBroadcast.createMessage
|
public function createMessage($message, $tag = null, array $attributes = []): MessageInterface
{
$config = [
'class' => $this->messageClass,
'broadcast' => $this,
'body' => $message,
'tag' => $tag,
'attributes' => $attributes
];
return Yii::createObject($config);
}
|
php
|
public function createMessage($message, $tag = null, array $attributes = []): MessageInterface
{
$config = [
'class' => $this->messageClass,
'broadcast' => $this,
'body' => $message,
'tag' => $tag,
'attributes' => $attributes
];
return Yii::createObject($config);
}
|
[
"public",
"function",
"createMessage",
"(",
"$",
"message",
",",
"$",
"tag",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
":",
"MessageInterface",
"{",
"$",
"config",
"=",
"[",
"'class'",
"=>",
"$",
"this",
"->",
"messageClass",
",",
"'broadcast'",
"=>",
"$",
"this",
",",
"'body'",
"=>",
"$",
"message",
",",
"'tag'",
"=>",
"$",
"tag",
",",
"'attributes'",
"=>",
"$",
"attributes",
"]",
";",
"return",
"Yii",
"::",
"createObject",
"(",
"$",
"config",
")",
";",
"}"
] |
Creates a new message instance and optionally composes its body content via view rendering.
@param array|object $message message payload.
@param string|array|null $tag message tag
@param array $attributes
@return MessageInterface|object message instance.
@throws \yii\base\InvalidConfigException
|
[
"Creates",
"a",
"new",
"message",
"instance",
"and",
"optionally",
"composes",
"its",
"body",
"content",
"via",
"view",
"rendering",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/broadcast/BaseBroadcast.php#L71-L81
|
yuncms/framework
|
src/broadcast/BaseBroadcast.php
|
BaseBroadcast.PublishMessage
|
public function PublishMessage($message, $tag = null, $attributes = null)
{
return $this->createMessage($message, $tag, $attributes)->send();
}
|
php
|
public function PublishMessage($message, $tag = null, $attributes = null)
{
return $this->createMessage($message, $tag, $attributes)->send();
}
|
[
"public",
"function",
"PublishMessage",
"(",
"$",
"message",
",",
"$",
"tag",
"=",
"null",
",",
"$",
"attributes",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"createMessage",
"(",
"$",
"message",
",",
"$",
"tag",
",",
"$",
"attributes",
")",
"->",
"send",
"(",
")",
";",
"}"
] |
快速推送一条消息
@param array|object $message
@param string|array|null $tag
@param array|null $attributes
@return bool
@throws \yii\base\InvalidConfigException
|
[
"快速推送一条消息"
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/broadcast/BaseBroadcast.php#L91-L94
|
yuncms/framework
|
src/broadcast/BaseBroadcast.php
|
BaseBroadcast.send
|
public function send($message)
{
if (!$this->beforeSend($message)) {
return false;
}
Yii::info('Sending broadcast :' . $message->toJson(), __METHOD__);
if ($this->useFileTransport) {
$isSuccessful = $this->saveMessage($message);
} else {
$isSuccessful = $this->sendMessage($message);
}
$this->afterSend($message, $isSuccessful);
return $isSuccessful;
}
|
php
|
public function send($message)
{
if (!$this->beforeSend($message)) {
return false;
}
Yii::info('Sending broadcast :' . $message->toJson(), __METHOD__);
if ($this->useFileTransport) {
$isSuccessful = $this->saveMessage($message);
} else {
$isSuccessful = $this->sendMessage($message);
}
$this->afterSend($message, $isSuccessful);
return $isSuccessful;
}
|
[
"public",
"function",
"send",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"beforeSend",
"(",
"$",
"message",
")",
")",
"{",
"return",
"false",
";",
"}",
"Yii",
"::",
"info",
"(",
"'Sending broadcast :'",
".",
"$",
"message",
"->",
"toJson",
"(",
")",
",",
"__METHOD__",
")",
";",
"if",
"(",
"$",
"this",
"->",
"useFileTransport",
")",
"{",
"$",
"isSuccessful",
"=",
"$",
"this",
"->",
"saveMessage",
"(",
"$",
"message",
")",
";",
"}",
"else",
"{",
"$",
"isSuccessful",
"=",
"$",
"this",
"->",
"sendMessage",
"(",
"$",
"message",
")",
";",
"}",
"$",
"this",
"->",
"afterSend",
"(",
"$",
"message",
",",
"$",
"isSuccessful",
")",
";",
"return",
"$",
"isSuccessful",
";",
"}"
] |
Sends the given broadcast message.
This method will log a message about the broadcast being sent.
If [[useFileTransport]] is true, it will save the broadcast as a file under [[fileTransportPath]].
Otherwise, it will call [[sendMessage()]] to send the broadcast to its recipient(s).
Child classes should implement [[sendMessage()]] with the actual broadcast sending logic.
@param MessageInterface $message broadcast message instance to be sent
@return bool whether the message has been sent successfully
|
[
"Sends",
"the",
"given",
"broadcast",
"message",
".",
"This",
"method",
"will",
"log",
"a",
"message",
"about",
"the",
"broadcast",
"being",
"sent",
".",
"If",
"[[",
"useFileTransport",
"]]",
"is",
"true",
"it",
"will",
"save",
"the",
"broadcast",
"as",
"a",
"file",
"under",
"[[",
"fileTransportPath",
"]]",
".",
"Otherwise",
"it",
"will",
"call",
"[[",
"sendMessage",
"()",
"]]",
"to",
"send",
"the",
"broadcast",
"to",
"its",
"recipient",
"(",
"s",
")",
".",
"Child",
"classes",
"should",
"implement",
"[[",
"sendMessage",
"()",
"]]",
"with",
"the",
"actual",
"broadcast",
"sending",
"logic",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/broadcast/BaseBroadcast.php#L105-L120
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.getEntityName
|
public function getEntityName($input) {
if (is_string($input)) {
if (array_key_exists($input,$names = $this->getEntityNames())) {
$name = $names[$input];
} elseif (mb_strpos($input,'\\') === FALSE) {
$name = \Webforge\Common\String::ucfirst($input);
} else {
$name = $input;
}
return Code::expandNamespace($name, $this->getEntitiesNamespace());
}
throw new \Psc\Exception('unbekannter Fall für getEntityName. Input ist: '.Code::varInfo($input));
}
|
php
|
public function getEntityName($input) {
if (is_string($input)) {
if (array_key_exists($input,$names = $this->getEntityNames())) {
$name = $names[$input];
} elseif (mb_strpos($input,'\\') === FALSE) {
$name = \Webforge\Common\String::ucfirst($input);
} else {
$name = $input;
}
return Code::expandNamespace($name, $this->getEntitiesNamespace());
}
throw new \Psc\Exception('unbekannter Fall für getEntityName. Input ist: '.Code::varInfo($input));
}
|
[
"public",
"function",
"getEntityName",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"input",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"input",
",",
"$",
"names",
"=",
"$",
"this",
"->",
"getEntityNames",
"(",
")",
")",
")",
"{",
"$",
"name",
"=",
"$",
"names",
"[",
"$",
"input",
"]",
";",
"}",
"elseif",
"(",
"mb_strpos",
"(",
"$",
"input",
",",
"'\\\\'",
")",
"===",
"FALSE",
")",
"{",
"$",
"name",
"=",
"\\",
"Webforge",
"\\",
"Common",
"\\",
"String",
"::",
"ucfirst",
"(",
"$",
"input",
")",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"input",
";",
"}",
"return",
"Code",
"::",
"expandNamespace",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"getEntitiesNamespace",
"(",
")",
")",
";",
"}",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"'unbekannter Fall für getEntityName. Input ist: '.",
"C",
"ode:",
":v",
"arInfo(",
"$",
"i",
"nput)",
")",
";",
"",
"}"
] |
Gibt die Klasse (den vollen Namen) eines Entities zurück
speaker => 'projectNamespace\Entities\Speaker'
oid => 'projectNamespace\Entities\OID'
Dies wird z.B. für die Umwandlung von entity-bezeichnern in URLs in echte Klassen gebraucht.
Irreguläre Namen (sowas wie OID) können in $this->getEntityNames() eingetragen werden
@param string $input kann ein Name in LowerCase sein, eine volle Klasse oder auch ein TabsContentItem2::getTabsResourceName() sein
|
[
"Gibt",
"die",
"Klasse",
"(",
"den",
"vollen",
"Namen",
")",
"eines",
"Entities",
"zurück"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L138-L153
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.getEntityMeta
|
public function getEntityMeta($entityName, $classMetadataInjection = NULL) {
$entityClass = $this->getEntityName($entityName); // normalize
// cache
if (!array_key_exists($entityClass, $this->entityMetas)) {
if ($classMetadataInjection instanceof EntityManager) {
$classMetadata = $classMetadataInjection->getClassMetadata($entityClass);
} elseif ($classMetadataInjection instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
$classMetadata = $classMetadataInjection;
} else {
$classMetadata = $this->getEntityManager($classMetadataInjection)->getClassMetadata($entityClass);
}
// erstelle ein "doofes" EntityMeta ohne viele Infos
$meta = new \Psc\CMS\EntityMeta($entityClass, $classMetadata, $entityName);
$this->entityMetas[$entityClass] = $meta;
$this->manager->dispatchEvent('Psc.Doctrine.initEntityMeta', (object) array('module'=>$this), $meta);
}
return $this->entityMetas[$entityClass];
}
|
php
|
public function getEntityMeta($entityName, $classMetadataInjection = NULL) {
$entityClass = $this->getEntityName($entityName); // normalize
// cache
if (!array_key_exists($entityClass, $this->entityMetas)) {
if ($classMetadataInjection instanceof EntityManager) {
$classMetadata = $classMetadataInjection->getClassMetadata($entityClass);
} elseif ($classMetadataInjection instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
$classMetadata = $classMetadataInjection;
} else {
$classMetadata = $this->getEntityManager($classMetadataInjection)->getClassMetadata($entityClass);
}
// erstelle ein "doofes" EntityMeta ohne viele Infos
$meta = new \Psc\CMS\EntityMeta($entityClass, $classMetadata, $entityName);
$this->entityMetas[$entityClass] = $meta;
$this->manager->dispatchEvent('Psc.Doctrine.initEntityMeta', (object) array('module'=>$this), $meta);
}
return $this->entityMetas[$entityClass];
}
|
[
"public",
"function",
"getEntityMeta",
"(",
"$",
"entityName",
",",
"$",
"classMetadataInjection",
"=",
"NULL",
")",
"{",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"getEntityName",
"(",
"$",
"entityName",
")",
";",
"// normalize",
"// cache",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"entityClass",
",",
"$",
"this",
"->",
"entityMetas",
")",
")",
"{",
"if",
"(",
"$",
"classMetadataInjection",
"instanceof",
"EntityManager",
")",
"{",
"$",
"classMetadata",
"=",
"$",
"classMetadataInjection",
"->",
"getClassMetadata",
"(",
"$",
"entityClass",
")",
";",
"}",
"elseif",
"(",
"$",
"classMetadataInjection",
"instanceof",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"Mapping",
"\\",
"ClassMetadata",
")",
"{",
"$",
"classMetadata",
"=",
"$",
"classMetadataInjection",
";",
"}",
"else",
"{",
"$",
"classMetadata",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
"$",
"classMetadataInjection",
")",
"->",
"getClassMetadata",
"(",
"$",
"entityClass",
")",
";",
"}",
"// erstelle ein \"doofes\" EntityMeta ohne viele Infos",
"$",
"meta",
"=",
"new",
"\\",
"Psc",
"\\",
"CMS",
"\\",
"EntityMeta",
"(",
"$",
"entityClass",
",",
"$",
"classMetadata",
",",
"$",
"entityName",
")",
";",
"$",
"this",
"->",
"entityMetas",
"[",
"$",
"entityClass",
"]",
"=",
"$",
"meta",
";",
"$",
"this",
"->",
"manager",
"->",
"dispatchEvent",
"(",
"'Psc.Doctrine.initEntityMeta'",
",",
"(",
"object",
")",
"array",
"(",
"'module'",
"=>",
"$",
"this",
")",
",",
"$",
"meta",
")",
";",
"}",
"return",
"$",
"this",
"->",
"entityMetas",
"[",
"$",
"entityClass",
"]",
";",
"}"
] |
Gibt ein Entity-Meta für ein Entity zurück
ein EntityMeta enthält jede Menge Labels, URLs, und weitere Infos über das Entity im CMS (in verschiedenen Contexten)
Ich habe lange überlegt, wo die "zentrale" Stelle für die EntityMetas sein soll und mich für das Modul entschieden, da es sowohl im DCPackage ist (und damit im Controller eines EntityServices)
sowohl auch in einer "Main" vorhanden sein muss (und man es damit injecten kann)
EntityMetas die hier erzeugt werden haben die ClassMetadata von Doctrine aus der übergebenen Connection bzw EntityManager
@param string|NULL|EntityManager|Doctrine\ORM\Mapping\ClassMetadata $classMetadataInjection der Manager nach dem nach der ClassMetadata gefragt wird angeben durch $con oder durch einen EntityManager, oder die ClassMetadata selbst
|
[
"Gibt",
"ein",
"Entity",
"-",
"Meta",
"für",
"ein",
"Entity",
"zurück"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L175-L196
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.bootstrap
|
public function bootstrap($bootFlags = 0x000000) {
if (!isset($this->configuration))
$this->configuration = new Configuration();
/* Custom Functions */
$this->configuration->addCustomDatetimeFunction('month', 'Psc\Doctrine\Functions\Month');
$this->configuration->addCustomDatetimeFunction('year', 'Psc\Doctrine\Functions\Year');
$this->configuration->addCustomDatetimeFunction('day', 'Psc\Doctrine\Functions\Day');
$this->configuration->addCustomStringFunction('soundex', 'Psc\Doctrine\Functions\Soundex');
/* Annotations */
// Register the ORM Annotations in the AnnotationRegistry
AnnotationRegistry::registerFile(
$this->project->dir('vendor')->getFile('doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php')
);
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('chainable');
if (!isset($this->driverChain))
$this->driverChain = new MappingDriverChain();
$this->driverChain->addDriver(
$this->getAnnotationDriver(),
$this->entitiesNamespace
);
$this->configuration->setMetadataDriverImpl($this->driverChain);
// Metadatadriver für einzelne Entities
$this->registerEntityClassesMetadataDriver(array(), 'Psc', $this->getDefaultAnnotationReader());
/* Ci-Ca-Caches */
if (($cache = $this->project->getConfiguration()->get('doctrine.cache')) != NULL) {
$this->useCache($cache);
}
$this->configuration->setMetadataCacheImpl($this->getCache());
$this->configuration->setQueryCacheImpl($this->getCache());
$this->configuration->setResultCacheImpl($this->getResultCache()); // das ist wichtig, damit dieselben abfragen pro result gecached werden
$this->configuration->setProxyDir($this->project->dir('cache')->sub('Proxies/')->create());
$this->configuration->setProxyNamespace('Proxies');
$this->configuration->setAutoGenerateProxyClasses(TRUE);
$this->registerDefaultTypes();
$this->registerCustomTypes();
$this->dispatchBootstrapped();
return $this;
}
|
php
|
public function bootstrap($bootFlags = 0x000000) {
if (!isset($this->configuration))
$this->configuration = new Configuration();
/* Custom Functions */
$this->configuration->addCustomDatetimeFunction('month', 'Psc\Doctrine\Functions\Month');
$this->configuration->addCustomDatetimeFunction('year', 'Psc\Doctrine\Functions\Year');
$this->configuration->addCustomDatetimeFunction('day', 'Psc\Doctrine\Functions\Day');
$this->configuration->addCustomStringFunction('soundex', 'Psc\Doctrine\Functions\Soundex');
/* Annotations */
// Register the ORM Annotations in the AnnotationRegistry
AnnotationRegistry::registerFile(
$this->project->dir('vendor')->getFile('doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php')
);
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('chainable');
if (!isset($this->driverChain))
$this->driverChain = new MappingDriverChain();
$this->driverChain->addDriver(
$this->getAnnotationDriver(),
$this->entitiesNamespace
);
$this->configuration->setMetadataDriverImpl($this->driverChain);
// Metadatadriver für einzelne Entities
$this->registerEntityClassesMetadataDriver(array(), 'Psc', $this->getDefaultAnnotationReader());
/* Ci-Ca-Caches */
if (($cache = $this->project->getConfiguration()->get('doctrine.cache')) != NULL) {
$this->useCache($cache);
}
$this->configuration->setMetadataCacheImpl($this->getCache());
$this->configuration->setQueryCacheImpl($this->getCache());
$this->configuration->setResultCacheImpl($this->getResultCache()); // das ist wichtig, damit dieselben abfragen pro result gecached werden
$this->configuration->setProxyDir($this->project->dir('cache')->sub('Proxies/')->create());
$this->configuration->setProxyNamespace('Proxies');
$this->configuration->setAutoGenerateProxyClasses(TRUE);
$this->registerDefaultTypes();
$this->registerCustomTypes();
$this->dispatchBootstrapped();
return $this;
}
|
[
"public",
"function",
"bootstrap",
"(",
"$",
"bootFlags",
"=",
"0x000000",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"configuration",
")",
")",
"$",
"this",
"->",
"configuration",
"=",
"new",
"Configuration",
"(",
")",
";",
"/* Custom Functions */",
"$",
"this",
"->",
"configuration",
"->",
"addCustomDatetimeFunction",
"(",
"'month'",
",",
"'Psc\\Doctrine\\Functions\\Month'",
")",
";",
"$",
"this",
"->",
"configuration",
"->",
"addCustomDatetimeFunction",
"(",
"'year'",
",",
"'Psc\\Doctrine\\Functions\\Year'",
")",
";",
"$",
"this",
"->",
"configuration",
"->",
"addCustomDatetimeFunction",
"(",
"'day'",
",",
"'Psc\\Doctrine\\Functions\\Day'",
")",
";",
"$",
"this",
"->",
"configuration",
"->",
"addCustomStringFunction",
"(",
"'soundex'",
",",
"'Psc\\Doctrine\\Functions\\Soundex'",
")",
";",
"/* Annotations */",
"// Register the ORM Annotations in the AnnotationRegistry",
"AnnotationRegistry",
"::",
"registerFile",
"(",
"$",
"this",
"->",
"project",
"->",
"dir",
"(",
"'vendor'",
")",
"->",
"getFile",
"(",
"'doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'",
")",
")",
";",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Annotations",
"\\",
"AnnotationReader",
"::",
"addGlobalIgnoredName",
"(",
"'chainable'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"driverChain",
")",
")",
"$",
"this",
"->",
"driverChain",
"=",
"new",
"MappingDriverChain",
"(",
")",
";",
"$",
"this",
"->",
"driverChain",
"->",
"addDriver",
"(",
"$",
"this",
"->",
"getAnnotationDriver",
"(",
")",
",",
"$",
"this",
"->",
"entitiesNamespace",
")",
";",
"$",
"this",
"->",
"configuration",
"->",
"setMetadataDriverImpl",
"(",
"$",
"this",
"->",
"driverChain",
")",
";",
"// Metadatadriver für einzelne Entities",
"$",
"this",
"->",
"registerEntityClassesMetadataDriver",
"(",
"array",
"(",
")",
",",
"'Psc'",
",",
"$",
"this",
"->",
"getDefaultAnnotationReader",
"(",
")",
")",
";",
"/* Ci-Ca-Caches */",
"if",
"(",
"(",
"$",
"cache",
"=",
"$",
"this",
"->",
"project",
"->",
"getConfiguration",
"(",
")",
"->",
"get",
"(",
"'doctrine.cache'",
")",
")",
"!=",
"NULL",
")",
"{",
"$",
"this",
"->",
"useCache",
"(",
"$",
"cache",
")",
";",
"}",
"$",
"this",
"->",
"configuration",
"->",
"setMetadataCacheImpl",
"(",
"$",
"this",
"->",
"getCache",
"(",
")",
")",
";",
"$",
"this",
"->",
"configuration",
"->",
"setQueryCacheImpl",
"(",
"$",
"this",
"->",
"getCache",
"(",
")",
")",
";",
"$",
"this",
"->",
"configuration",
"->",
"setResultCacheImpl",
"(",
"$",
"this",
"->",
"getResultCache",
"(",
")",
")",
";",
"// das ist wichtig, damit dieselben abfragen pro result gecached werden",
"$",
"this",
"->",
"configuration",
"->",
"setProxyDir",
"(",
"$",
"this",
"->",
"project",
"->",
"dir",
"(",
"'cache'",
")",
"->",
"sub",
"(",
"'Proxies/'",
")",
"->",
"create",
"(",
")",
")",
";",
"$",
"this",
"->",
"configuration",
"->",
"setProxyNamespace",
"(",
"'Proxies'",
")",
";",
"$",
"this",
"->",
"configuration",
"->",
"setAutoGenerateProxyClasses",
"(",
"TRUE",
")",
";",
"$",
"this",
"->",
"registerDefaultTypes",
"(",
")",
";",
"$",
"this",
"->",
"registerCustomTypes",
"(",
")",
";",
"$",
"this",
"->",
"dispatchBootstrapped",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Lädt alle für Doctrine wichtigen Klassen und Objekte
|
[
"Lädt",
"alle",
"für",
"Doctrine",
"wichtigen",
"Klassen",
"und",
"Objekte"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L204-L252
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.getConnectionOptions
|
public function getConnectionOptions($con) {
if (!isset($con)) $con = $this->getConnectionName();
$conf = $this->project->getConfiguration();
$connectionOptions = array(
'dbname' => $conf->req(array('db',$con,'database')),
'user' => $conf->req(array('db',$con,'user')),
'password' => $conf->req(array('db',$con,'password')),
'host' => $conf->req(array('db',$con,'host')),
'driver' => 'pdo_mysql',
);
return $connectionOptions;
}
|
php
|
public function getConnectionOptions($con) {
if (!isset($con)) $con = $this->getConnectionName();
$conf = $this->project->getConfiguration();
$connectionOptions = array(
'dbname' => $conf->req(array('db',$con,'database')),
'user' => $conf->req(array('db',$con,'user')),
'password' => $conf->req(array('db',$con,'password')),
'host' => $conf->req(array('db',$con,'host')),
'driver' => 'pdo_mysql',
);
return $connectionOptions;
}
|
[
"public",
"function",
"getConnectionOptions",
"(",
"$",
"con",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"con",
")",
")",
"$",
"con",
"=",
"$",
"this",
"->",
"getConnectionName",
"(",
")",
";",
"$",
"conf",
"=",
"$",
"this",
"->",
"project",
"->",
"getConfiguration",
"(",
")",
";",
"$",
"connectionOptions",
"=",
"array",
"(",
"'dbname'",
"=>",
"$",
"conf",
"->",
"req",
"(",
"array",
"(",
"'db'",
",",
"$",
"con",
",",
"'database'",
")",
")",
",",
"'user'",
"=>",
"$",
"conf",
"->",
"req",
"(",
"array",
"(",
"'db'",
",",
"$",
"con",
",",
"'user'",
")",
")",
",",
"'password'",
"=>",
"$",
"conf",
"->",
"req",
"(",
"array",
"(",
"'db'",
",",
"$",
"con",
",",
"'password'",
")",
")",
",",
"'host'",
"=>",
"$",
"conf",
"->",
"req",
"(",
"array",
"(",
"'db'",
",",
"$",
"con",
",",
"'host'",
")",
")",
",",
"'driver'",
"=>",
"'pdo_mysql'",
",",
")",
";",
"return",
"$",
"connectionOptions",
";",
"}"
] |
Gibt die Credentials + Optionen für eine Connection zurück
Credentials werden in der ProjektConfiguration eingetragen
@return array
|
[
"Gibt",
"die",
"Credentials",
"+",
"Optionen",
"für",
"eine",
"Connection",
"zurück"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L305-L318
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.registerType
|
public function registerType($class) {
$name = str_replace('\\','',$class);
\Doctrine\DBAL\Types\Type::addType($name, $class);
return $this;
}
|
php
|
public function registerType($class) {
$name = str_replace('\\','',$class);
\Doctrine\DBAL\Types\Type::addType($name, $class);
return $this;
}
|
[
"public",
"function",
"registerType",
"(",
"$",
"class",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"''",
",",
"$",
"class",
")",
";",
"\\",
"Doctrine",
"\\",
"DBAL",
"\\",
"Types",
"\\",
"Type",
"::",
"addType",
"(",
"$",
"name",
",",
"$",
"class",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Registriert einen Custom Mapping Type für Doctrine
beim Registieren wird der Name der TypeClass umgewandelt. Jeder \\ wird gelöscht und der Gesamte FQN benutzt
z. B.:
SerienLoader\Status => SerienLoaderStatus
@param $class unbedingt ohne \ davor
|
[
"Registriert",
"einen",
"Custom",
"Mapping",
"Type",
"für",
"Doctrine"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L340-L344
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.registerDefaultTypes
|
protected function registerDefaultTypes() {
foreach (array('Psc.DateTime'=>'Psc\Doctrine\DateTimeType', // legacy wegen dem .
'PscDateTime'=>'Psc\Doctrine\DateTimeType', // das ist das neue "richtige" Format
'PscDate'=>'Psc\Doctrine\DateType',
'WebforgeDateTime'=>'Webforge\Doctrine\Types\DateTimeType',
'WebforgeDate'=>'Webforge\Doctrine\Types\DateType'
) as $name => $class) {
if (!\Doctrine\DBAL\Types\Type::hasType($name)) {
\Doctrine\DBAL\Types\Type::addType($name, $class);
}
}
return $this;
}
|
php
|
protected function registerDefaultTypes() {
foreach (array('Psc.DateTime'=>'Psc\Doctrine\DateTimeType', // legacy wegen dem .
'PscDateTime'=>'Psc\Doctrine\DateTimeType', // das ist das neue "richtige" Format
'PscDate'=>'Psc\Doctrine\DateType',
'WebforgeDateTime'=>'Webforge\Doctrine\Types\DateTimeType',
'WebforgeDate'=>'Webforge\Doctrine\Types\DateType'
) as $name => $class) {
if (!\Doctrine\DBAL\Types\Type::hasType($name)) {
\Doctrine\DBAL\Types\Type::addType($name, $class);
}
}
return $this;
}
|
[
"protected",
"function",
"registerDefaultTypes",
"(",
")",
"{",
"foreach",
"(",
"array",
"(",
"'Psc.DateTime'",
"=>",
"'Psc\\Doctrine\\DateTimeType'",
",",
"// legacy wegen dem .",
"'PscDateTime'",
"=>",
"'Psc\\Doctrine\\DateTimeType'",
",",
"// das ist das neue \"richtige\" Format",
"'PscDate'",
"=>",
"'Psc\\Doctrine\\DateType'",
",",
"'WebforgeDateTime'",
"=>",
"'Webforge\\Doctrine\\Types\\DateTimeType'",
",",
"'WebforgeDate'",
"=>",
"'Webforge\\Doctrine\\Types\\DateType'",
")",
"as",
"$",
"name",
"=>",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"\\",
"Doctrine",
"\\",
"DBAL",
"\\",
"Types",
"\\",
"Type",
"::",
"hasType",
"(",
"$",
"name",
")",
")",
"{",
"\\",
"Doctrine",
"\\",
"DBAL",
"\\",
"Types",
"\\",
"Type",
"::",
"addType",
"(",
"$",
"name",
",",
"$",
"class",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Registriert die Common Custom Mapping Types (fürs Psc-CMS)
|
[
"Registriert",
"die",
"Common",
"Custom",
"Mapping",
"Types",
"(",
"fürs",
"Psc",
"-",
"CMS",
")"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L350-L362
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.registerMetadataDriver
|
public function registerMetadataDriver(\Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $driver, $driverNamespace = NULL) {
$this->driverChain->addDriver($driver, $driverNamespace);
return $this;
}
|
php
|
public function registerMetadataDriver(\Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $driver, $driverNamespace = NULL) {
$this->driverChain->addDriver($driver, $driverNamespace);
return $this;
}
|
[
"public",
"function",
"registerMetadataDriver",
"(",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Persistence",
"\\",
"Mapping",
"\\",
"Driver",
"\\",
"MappingDriver",
"$",
"driver",
",",
"$",
"driverNamespace",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"driverChain",
"->",
"addDriver",
"(",
"$",
"driver",
",",
"$",
"driverNamespace",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Fügt einen weiteren MetadataDriver hinzu
muss nach bootstrap() aufgerufen werden
MetadataDriver verwalten MetaDaten zu Entities. Dies sind die MetaDaten von Doctrine und haben mit den EntityMetas dieses Modules wenig zu tun.
in den Tests wird ein weiterer MetadataDriver (this->getEntityClassesMetadataDriver) benutzt um TestEntities zur Laufzeit laden zu können (da die Doctrine Treiber per Default alle alle alle Klassen nach Entities durchsuchen)
@param Doctrine\ORM\Mapping\Driver\Driver $driver
@param null|string $driverNamespace
|
[
"Fügt",
"einen",
"weiteren",
"MetadataDriver",
"hinzu"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L380-L383
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.registerEntityClassesMetadataDriver
|
public function registerEntityClassesMetadataDriver(Array $classes = array(), $namespace = 'Psc', \Doctrine\Common\Annotations\Reader $reader = NULL) {
if (!isset($this->entityClassesMetadataDriver)) {
if (!isset($reader)) {
$reader = $this->createAnnotationReader();
}
$this->entityClassesMetadataDriver = new \Psc\Doctrine\MetadataDriver($reader, NULL, $classes);
$this->registerMetadataDriver($this->entityClassesMetadataDriver, $namespace);
}
return $this;
}
|
php
|
public function registerEntityClassesMetadataDriver(Array $classes = array(), $namespace = 'Psc', \Doctrine\Common\Annotations\Reader $reader = NULL) {
if (!isset($this->entityClassesMetadataDriver)) {
if (!isset($reader)) {
$reader = $this->createAnnotationReader();
}
$this->entityClassesMetadataDriver = new \Psc\Doctrine\MetadataDriver($reader, NULL, $classes);
$this->registerMetadataDriver($this->entityClassesMetadataDriver, $namespace);
}
return $this;
}
|
[
"public",
"function",
"registerEntityClassesMetadataDriver",
"(",
"Array",
"$",
"classes",
"=",
"array",
"(",
")",
",",
"$",
"namespace",
"=",
"'Psc'",
",",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Annotations",
"\\",
"Reader",
"$",
"reader",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"entityClassesMetadataDriver",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"reader",
")",
")",
"{",
"$",
"reader",
"=",
"$",
"this",
"->",
"createAnnotationReader",
"(",
")",
";",
"}",
"$",
"this",
"->",
"entityClassesMetadataDriver",
"=",
"new",
"\\",
"Psc",
"\\",
"Doctrine",
"\\",
"MetadataDriver",
"(",
"$",
"reader",
",",
"NULL",
",",
"$",
"classes",
")",
";",
"$",
"this",
"->",
"registerMetadataDriver",
"(",
"$",
"this",
"->",
"entityClassesMetadataDriver",
",",
"$",
"namespace",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Erstellt den EntityClassesMetadataDriver
mehrmals aufrufen ist nicht tragisch, jedoch wird dann natürlihc $classes und $namspace sowie $reader keinen effect haben
@see getEntityClassesMetadataDriver
@chainable
|
[
"Erstellt",
"den",
"EntityClassesMetadataDriver"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L406-L416
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.createAnnotationReader
|
public function createAnnotationReader($simple = TRUE, Array $ignoredAnnotations = array()) {
if ($simple) {
$reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
$reader->addNamespace('Doctrine\ORM\Mapping');
} else {
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
}
foreach ($ignoredAnnotations as $ignore) {
$reader->addGlobalIgnoredName($ignore);
}
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, $this->getCache());
return $reader;
}
|
php
|
public function createAnnotationReader($simple = TRUE, Array $ignoredAnnotations = array()) {
if ($simple) {
$reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
$reader->addNamespace('Doctrine\ORM\Mapping');
} else {
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
}
foreach ($ignoredAnnotations as $ignore) {
$reader->addGlobalIgnoredName($ignore);
}
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, $this->getCache());
return $reader;
}
|
[
"public",
"function",
"createAnnotationReader",
"(",
"$",
"simple",
"=",
"TRUE",
",",
"Array",
"$",
"ignoredAnnotations",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"simple",
")",
"{",
"$",
"reader",
"=",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Annotations",
"\\",
"SimpleAnnotationReader",
"(",
")",
";",
"$",
"reader",
"->",
"addNamespace",
"(",
"'Doctrine\\ORM\\Mapping'",
")",
";",
"}",
"else",
"{",
"$",
"reader",
"=",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Annotations",
"\\",
"AnnotationReader",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"ignoredAnnotations",
"as",
"$",
"ignore",
")",
"{",
"$",
"reader",
"->",
"addGlobalIgnoredName",
"(",
"$",
"ignore",
")",
";",
"}",
"$",
"reader",
"=",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Annotations",
"\\",
"CachedReader",
"(",
"$",
"reader",
",",
"$",
"this",
"->",
"getCache",
"(",
")",
")",
";",
"return",
"$",
"reader",
";",
"}"
] |
Gibt einen neuen SimpleAnnotationReader zurück
der Namespace Doctrine\ORM\Mapping wird automatisch hinzugefügt
es wird der interne Cache benutzt
@return Doctrine\Common\Annotations\SimpleAnnotationReader()
|
[
"Gibt",
"einen",
"neuen",
"SimpleAnnotationReader",
"zurück"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L425-L440
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.getDefaultAnnotationReader
|
public function getDefaultAnnotationReader() {
if (!isset($this->defaultAnnotationReader)) {
$this->defaultAnnotationReader = $this->createAnnotationReader(FALSE, array('todo','TODO','compiled')); // nie simple: jetzt neu
}
return $this->defaultAnnotationReader;
}
|
php
|
public function getDefaultAnnotationReader() {
if (!isset($this->defaultAnnotationReader)) {
$this->defaultAnnotationReader = $this->createAnnotationReader(FALSE, array('todo','TODO','compiled')); // nie simple: jetzt neu
}
return $this->defaultAnnotationReader;
}
|
[
"public",
"function",
"getDefaultAnnotationReader",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"defaultAnnotationReader",
")",
")",
"{",
"$",
"this",
"->",
"defaultAnnotationReader",
"=",
"$",
"this",
"->",
"createAnnotationReader",
"(",
"FALSE",
",",
"array",
"(",
"'todo'",
",",
"'TODO'",
",",
"'compiled'",
")",
")",
";",
"// nie simple: jetzt neu",
"}",
"return",
"$",
"this",
"->",
"defaultAnnotationReader",
";",
"}"
] |
Ein (Simple-)Annotation Reader benutzt von Doctrine
@v2: AnnotationReader
|
[
"Ein",
"(",
"Simple",
"-",
")",
"Annotation",
"Reader",
"benutzt",
"von",
"Doctrine"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L447-L453
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.getAnnotationDriver
|
public function getAnnotationDriver() {
if (!isset($this->annotationDriver)) {
$this->annotationDriver = new AnnotationDriver($this->getDefaultAnnotationReader(),
array((string) $this->getEntitiesPath())
);
}
return $this->annotationDriver;
}
|
php
|
public function getAnnotationDriver() {
if (!isset($this->annotationDriver)) {
$this->annotationDriver = new AnnotationDriver($this->getDefaultAnnotationReader(),
array((string) $this->getEntitiesPath())
);
}
return $this->annotationDriver;
}
|
[
"public",
"function",
"getAnnotationDriver",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"annotationDriver",
")",
")",
"{",
"$",
"this",
"->",
"annotationDriver",
"=",
"new",
"AnnotationDriver",
"(",
"$",
"this",
"->",
"getDefaultAnnotationReader",
"(",
")",
",",
"array",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"getEntitiesPath",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"annotationDriver",
";",
"}"
] |
Der AnnotationDriver für Doctrine, Psc, Whatever
@return Doctrine\ORM\Mapping\Driver\AnnotationDriver
|
[
"Der",
"AnnotationDriver",
"für",
"Doctrine",
"Psc",
"Whatever"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L460-L468
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.getEntitiesPath
|
public function getEntitiesPath() {
if (!isset($this->entitiesPath))
$this->entitiesPath = Code::namespaceToPath($this->entitiesNamespace, $this->project->dir('lib'));
return $this->entitiesPath;
}
|
php
|
public function getEntitiesPath() {
if (!isset($this->entitiesPath))
$this->entitiesPath = Code::namespaceToPath($this->entitiesNamespace, $this->project->dir('lib'));
return $this->entitiesPath;
}
|
[
"public",
"function",
"getEntitiesPath",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"entitiesPath",
")",
")",
"$",
"this",
"->",
"entitiesPath",
"=",
"Code",
"::",
"namespaceToPath",
"(",
"$",
"this",
"->",
"entitiesNamespace",
",",
"$",
"this",
"->",
"project",
"->",
"dir",
"(",
"'lib'",
")",
")",
";",
"return",
"$",
"this",
"->",
"entitiesPath",
";",
"}"
] |
Gibt Pfad für den Namespace der Entities zurück
@return Webforge\Common\System\Dir
|
[
"Gibt",
"Pfad",
"für",
"den",
"Namespace",
"der",
"Entities",
"zurück"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L475-L480
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.getCache
|
public function getCache() {
if (!isset($this->cache))
$this->cache = new \Doctrine\Common\Cache\ArrayCache;
return $this->cache;
}
|
php
|
public function getCache() {
if (!isset($this->cache))
$this->cache = new \Doctrine\Common\Cache\ArrayCache;
return $this->cache;
}
|
[
"public",
"function",
"getCache",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cache",
")",
")",
"$",
"this",
"->",
"cache",
"=",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Cache",
"\\",
"ArrayCache",
";",
"return",
"$",
"this",
"->",
"cache",
";",
"}"
] |
Gibt den internen Cache für Queries + Meta zurück
(wenn APC irgendwann mal so richtig stabil wäre, könnte man hier in Production einen APCCache benutzen)
|
[
"Gibt",
"den",
"internen",
"Cache",
"für",
"Queries",
"+",
"Meta",
"zurück"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L502-L507
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.useCache
|
public function useCache($type = self::CACHE_APC) {
if ($type === self::CACHE_APC) {
$this->setCache(new \Doctrine\Common\Cache\ApcCache);
} else {
$this->setCache(new \Doctrine\Common\Cache\ArrayCache);
}
}
|
php
|
public function useCache($type = self::CACHE_APC) {
if ($type === self::CACHE_APC) {
$this->setCache(new \Doctrine\Common\Cache\ApcCache);
} else {
$this->setCache(new \Doctrine\Common\Cache\ArrayCache);
}
}
|
[
"public",
"function",
"useCache",
"(",
"$",
"type",
"=",
"self",
"::",
"CACHE_APC",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"self",
"::",
"CACHE_APC",
")",
"{",
"$",
"this",
"->",
"setCache",
"(",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Cache",
"\\",
"ApcCache",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setCache",
"(",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Cache",
"\\",
"ArrayCache",
")",
";",
"}",
"}"
] |
Overwrites the current cache
|
[
"Overwrites",
"the",
"current",
"cache"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L512-L518
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Module.php
|
Module.getResultCache
|
public function getResultCache() {
if (!isset($this->resultCache))
$this->resultCache = new \Doctrine\Common\Cache\ArrayCache;
return $this->resultCache;
}
|
php
|
public function getResultCache() {
if (!isset($this->resultCache))
$this->resultCache = new \Doctrine\Common\Cache\ArrayCache;
return $this->resultCache;
}
|
[
"public",
"function",
"getResultCache",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"resultCache",
")",
")",
"$",
"this",
"->",
"resultCache",
"=",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Cache",
"\\",
"ArrayCache",
";",
"return",
"$",
"this",
"->",
"resultCache",
";",
"}"
] |
Gibt den internen Cache für Results zurück
@return Doctrine\Common\Cache\Cache
|
[
"Gibt",
"den",
"internen",
"Cache",
"für",
"Results",
"zurück"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Module.php#L530-L535
|
fkooman/php-cert-parser
|
src/fkooman/X509/CertParser.php
|
CertParser.fromEncodedDer
|
public static function fromEncodedDer($encodedDerCert)
{
$pemCert = sprintf(
'-----BEGIN CERTIFICATE-----%s-----END CERTIFICATE-----',
PHP_EOL.wordwrap($encodedDerCert, 64, "\n", true).PHP_EOL
);
return new self($pemCert);
}
|
php
|
public static function fromEncodedDer($encodedDerCert)
{
$pemCert = sprintf(
'-----BEGIN CERTIFICATE-----%s-----END CERTIFICATE-----',
PHP_EOL.wordwrap($encodedDerCert, 64, "\n", true).PHP_EOL
);
return new self($pemCert);
}
|
[
"public",
"static",
"function",
"fromEncodedDer",
"(",
"$",
"encodedDerCert",
")",
"{",
"$",
"pemCert",
"=",
"sprintf",
"(",
"'-----BEGIN CERTIFICATE-----%s-----END CERTIFICATE-----'",
",",
"PHP_EOL",
".",
"wordwrap",
"(",
"$",
"encodedDerCert",
",",
"64",
",",
"\"\\n\"",
",",
"true",
")",
".",
"PHP_EOL",
")",
";",
"return",
"new",
"self",
"(",
"$",
"pemCert",
")",
";",
"}"
] |
Create a new CertParser object from the Base 64 encoded DER, i.e. a
base64_encode of a binary string.
|
[
"Create",
"a",
"new",
"CertParser",
"object",
"from",
"the",
"Base",
"64",
"encoded",
"DER",
"i",
".",
"e",
".",
"a",
"base64_encode",
"of",
"a",
"binary",
"string",
"."
] |
train
|
https://github.com/fkooman/php-cert-parser/blob/29bf69b49ee06011fb1c4f4c40cdd16a7f63e8bc/src/fkooman/X509/CertParser.php#L41-L49
|
fkooman/php-cert-parser
|
src/fkooman/X509/CertParser.php
|
CertParser.toDer
|
private function toDer()
{
$pattern = '/.*-----BEGIN CERTIFICATE-----(.*)-----END CERTIFICATE-----.*/msU';
$replacement = '${1}';
$plainPemData = preg_replace($pattern, $replacement, $this->pemCert);
if (null === $plainPemData) {
throw new RuntimeException('unable to extract the encoded DER data from the certificate');
}
// create one long string of the certificate which turns it into an
// encoded DER cert
$search = array(' ', "\t", "\n", "\r", "\0" , "\x0B");
$encodedDerCert = str_replace($search, '', $plainPemData);
return base64_decode($encodedDerCert);
}
|
php
|
private function toDer()
{
$pattern = '/.*-----BEGIN CERTIFICATE-----(.*)-----END CERTIFICATE-----.*/msU';
$replacement = '${1}';
$plainPemData = preg_replace($pattern, $replacement, $this->pemCert);
if (null === $plainPemData) {
throw new RuntimeException('unable to extract the encoded DER data from the certificate');
}
// create one long string of the certificate which turns it into an
// encoded DER cert
$search = array(' ', "\t", "\n", "\r", "\0" , "\x0B");
$encodedDerCert = str_replace($search, '', $plainPemData);
return base64_decode($encodedDerCert);
}
|
[
"private",
"function",
"toDer",
"(",
")",
"{",
"$",
"pattern",
"=",
"'/.*-----BEGIN CERTIFICATE-----(.*)-----END CERTIFICATE-----.*/msU'",
";",
"$",
"replacement",
"=",
"'${1}'",
";",
"$",
"plainPemData",
"=",
"preg_replace",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"pemCert",
")",
";",
"if",
"(",
"null",
"===",
"$",
"plainPemData",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'unable to extract the encoded DER data from the certificate'",
")",
";",
"}",
"// create one long string of the certificate which turns it into an",
"// encoded DER cert",
"$",
"search",
"=",
"array",
"(",
"' '",
",",
"\"\\t\"",
",",
"\"\\n\"",
",",
"\"\\r\"",
",",
"\"\\0\"",
",",
"\"\\x0B\"",
")",
";",
"$",
"encodedDerCert",
"=",
"str_replace",
"(",
"$",
"search",
",",
"''",
",",
"$",
"plainPemData",
")",
";",
"return",
"base64_decode",
"(",
"$",
"encodedDerCert",
")",
";",
"}"
] |
Get the DER format of the certificate.
|
[
"Get",
"the",
"DER",
"format",
"of",
"the",
"certificate",
"."
] |
train
|
https://github.com/fkooman/php-cert-parser/blob/29bf69b49ee06011fb1c4f4c40cdd16a7f63e8bc/src/fkooman/X509/CertParser.php#L105-L121
|
fkooman/php-cert-parser
|
src/fkooman/X509/CertParser.php
|
CertParser.getFingerprint
|
public function getFingerprint($alg = 'sha256')
{
if (!in_array($alg, hash_algos())) {
throw new RuntimeException(
sprintf(
'unsupported algorithm "%s"',
$alg
)
);
}
return hash($alg, $this->toDer(), true);
}
|
php
|
public function getFingerprint($alg = 'sha256')
{
if (!in_array($alg, hash_algos())) {
throw new RuntimeException(
sprintf(
'unsupported algorithm "%s"',
$alg
)
);
}
return hash($alg, $this->toDer(), true);
}
|
[
"public",
"function",
"getFingerprint",
"(",
"$",
"alg",
"=",
"'sha256'",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"alg",
",",
"hash_algos",
"(",
")",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'unsupported algorithm \"%s\"'",
",",
"$",
"alg",
")",
")",
";",
"}",
"return",
"hash",
"(",
"$",
"alg",
",",
"$",
"this",
"->",
"toDer",
"(",
")",
",",
"true",
")",
";",
"}"
] |
Get the raw fingerprint of the certificate.
@param string $alg the algorithm to use
@return string the raw fingerprint of the certificate as binary string
@see http://php.net/manual/en/function.hash-algos.php
|
[
"Get",
"the",
"raw",
"fingerprint",
"of",
"the",
"certificate",
"."
] |
train
|
https://github.com/fkooman/php-cert-parser/blob/29bf69b49ee06011fb1c4f4c40cdd16a7f63e8bc/src/fkooman/X509/CertParser.php#L132-L144
|
webforge-labs/psc-cms
|
lib/Psc/CMS/Controller/BaseFileController.php
|
BaseFileController.run
|
public function run() {
$this->trigger('run.before');
/* wir validieren die Datei */
$this->file = new File($this->getDirectory(), $this->getFileName());
$fDir = $this->file->getDirectory();
$incDir = $this->getDirectory();
if (!$this->file->exists() || !$incDir->equals($fDir) && !$fDir->isSubdirectoryOf($incDir)) { // verzeichnis darf nicht tiefer gewechselt werden, als das getDirectory()
if (!$this->file->exists()) {
throw new SystemException('Datei: '.$this->file.' wurde nicht gefunden.');
} else {
throw new SystemException('Datei: '.$this->file.' ist nicht in '.$this->getDirectory().' enthalten (security check)');
}
}
unset($fDir,$incDir); // die wollen wir nicht im scope haben
$this->file->getDirectory()->makeRelativeTo($this->getDirectory()); // das ist eher etwas kosmetik, als Sicherhheit
/* Datei includieren */
extract($this->getExtractVars());
require mb_substr((string) $this->file, 2); // schneidet das ./ oder .\ ab
$this->trigger('run.after');
return $this;
}
|
php
|
public function run() {
$this->trigger('run.before');
/* wir validieren die Datei */
$this->file = new File($this->getDirectory(), $this->getFileName());
$fDir = $this->file->getDirectory();
$incDir = $this->getDirectory();
if (!$this->file->exists() || !$incDir->equals($fDir) && !$fDir->isSubdirectoryOf($incDir)) { // verzeichnis darf nicht tiefer gewechselt werden, als das getDirectory()
if (!$this->file->exists()) {
throw new SystemException('Datei: '.$this->file.' wurde nicht gefunden.');
} else {
throw new SystemException('Datei: '.$this->file.' ist nicht in '.$this->getDirectory().' enthalten (security check)');
}
}
unset($fDir,$incDir); // die wollen wir nicht im scope haben
$this->file->getDirectory()->makeRelativeTo($this->getDirectory()); // das ist eher etwas kosmetik, als Sicherhheit
/* Datei includieren */
extract($this->getExtractVars());
require mb_substr((string) $this->file, 2); // schneidet das ./ oder .\ ab
$this->trigger('run.after');
return $this;
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"$",
"this",
"->",
"trigger",
"(",
"'run.before'",
")",
";",
"/* wir validieren die Datei */",
"$",
"this",
"->",
"file",
"=",
"new",
"File",
"(",
"$",
"this",
"->",
"getDirectory",
"(",
")",
",",
"$",
"this",
"->",
"getFileName",
"(",
")",
")",
";",
"$",
"fDir",
"=",
"$",
"this",
"->",
"file",
"->",
"getDirectory",
"(",
")",
";",
"$",
"incDir",
"=",
"$",
"this",
"->",
"getDirectory",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"file",
"->",
"exists",
"(",
")",
"||",
"!",
"$",
"incDir",
"->",
"equals",
"(",
"$",
"fDir",
")",
"&&",
"!",
"$",
"fDir",
"->",
"isSubdirectoryOf",
"(",
"$",
"incDir",
")",
")",
"{",
"// verzeichnis darf nicht tiefer gewechselt werden, als das getDirectory()",
"if",
"(",
"!",
"$",
"this",
"->",
"file",
"->",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"SystemException",
"(",
"'Datei: '",
".",
"$",
"this",
"->",
"file",
".",
"' wurde nicht gefunden.'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"SystemException",
"(",
"'Datei: '",
".",
"$",
"this",
"->",
"file",
".",
"' ist nicht in '",
".",
"$",
"this",
"->",
"getDirectory",
"(",
")",
".",
"' enthalten (security check)'",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"fDir",
",",
"$",
"incDir",
")",
";",
"// die wollen wir nicht im scope haben",
"$",
"this",
"->",
"file",
"->",
"getDirectory",
"(",
")",
"->",
"makeRelativeTo",
"(",
"$",
"this",
"->",
"getDirectory",
"(",
")",
")",
";",
"// das ist eher etwas kosmetik, als Sicherhheit",
"/* Datei includieren */",
"extract",
"(",
"$",
"this",
"->",
"getExtractVars",
"(",
")",
")",
";",
"require",
"mb_substr",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"file",
",",
"2",
")",
";",
"// schneidet das ./ oder .\\ ab",
"$",
"this",
"->",
"trigger",
"(",
"'run.after'",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Lädt die Controller Datei
macht require $this->getFileName()
getFileName darf einen relativen Pfad zu $this->getDirectory() zurückgeben
|
[
"Lädt",
"die",
"Controller",
"Datei"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/Controller/BaseFileController.php#L70-L98
|
qcubed/orm
|
src/Query/Node/Table.php
|
Table.join
|
public function join(
Builder $objBuilder,
$blnExpandSelection = false,
iCondition $objJoinCondition = null,
Clause\Select $objSelect = null
) {
$objParentNode = $this->objParentNode;
if (!$objParentNode) {
if ($this->strTableName != $objBuilder->RootTableName) {
throw new Caller('Cannot use Node for "' . $this->strTableName . '" when querying against the "' . $objBuilder->RootTableName . '" table',
3);
}
} else {
// Special case situation to allow applying a join condition on an association table.
// The condition must be testing against the primary key of the joined table.
if ($objJoinCondition &&
$this->objParentNode instanceof Association &&
$objJoinCondition->equalTables($this->objParentNode->fullAlias())
) {
$objParentNode->join($objBuilder, $blnExpandSelection, $objJoinCondition, $objSelect);
$objJoinCondition = null; // prevent passing join condition to this level
} else {
$objParentNode->join($objBuilder, $blnExpandSelection, null, $objSelect);
if ($objJoinCondition && !$objJoinCondition->equalTables($this->fullAlias())) {
throw new Caller("The join condition on the \"" . $this->strTableName . "\" table must only contain conditions for that table.");
}
}
try {
$strParentAlias = $objParentNode->fullAlias();
$strAlias = $this->fullAlias();
//$strJoinTableAlias = $strParentAlias . '__' . ($this->strAlias ? $this->strAlias : $this->strName);
$objBuilder->addJoinItem($this->strTableName, $strAlias,
$strParentAlias, $this->strName, $this->strPrimaryKey, $objJoinCondition);
if ($blnExpandSelection) {
$this->putSelectFields($objBuilder, $strAlias, $objSelect);
}
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
}
}
|
php
|
public function join(
Builder $objBuilder,
$blnExpandSelection = false,
iCondition $objJoinCondition = null,
Clause\Select $objSelect = null
) {
$objParentNode = $this->objParentNode;
if (!$objParentNode) {
if ($this->strTableName != $objBuilder->RootTableName) {
throw new Caller('Cannot use Node for "' . $this->strTableName . '" when querying against the "' . $objBuilder->RootTableName . '" table',
3);
}
} else {
// Special case situation to allow applying a join condition on an association table.
// The condition must be testing against the primary key of the joined table.
if ($objJoinCondition &&
$this->objParentNode instanceof Association &&
$objJoinCondition->equalTables($this->objParentNode->fullAlias())
) {
$objParentNode->join($objBuilder, $blnExpandSelection, $objJoinCondition, $objSelect);
$objJoinCondition = null; // prevent passing join condition to this level
} else {
$objParentNode->join($objBuilder, $blnExpandSelection, null, $objSelect);
if ($objJoinCondition && !$objJoinCondition->equalTables($this->fullAlias())) {
throw new Caller("The join condition on the \"" . $this->strTableName . "\" table must only contain conditions for that table.");
}
}
try {
$strParentAlias = $objParentNode->fullAlias();
$strAlias = $this->fullAlias();
//$strJoinTableAlias = $strParentAlias . '__' . ($this->strAlias ? $this->strAlias : $this->strName);
$objBuilder->addJoinItem($this->strTableName, $strAlias,
$strParentAlias, $this->strName, $this->strPrimaryKey, $objJoinCondition);
if ($blnExpandSelection) {
$this->putSelectFields($objBuilder, $strAlias, $objSelect);
}
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
}
}
|
[
"public",
"function",
"join",
"(",
"Builder",
"$",
"objBuilder",
",",
"$",
"blnExpandSelection",
"=",
"false",
",",
"iCondition",
"$",
"objJoinCondition",
"=",
"null",
",",
"Clause",
"\\",
"Select",
"$",
"objSelect",
"=",
"null",
")",
"{",
"$",
"objParentNode",
"=",
"$",
"this",
"->",
"objParentNode",
";",
"if",
"(",
"!",
"$",
"objParentNode",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"strTableName",
"!=",
"$",
"objBuilder",
"->",
"RootTableName",
")",
"{",
"throw",
"new",
"Caller",
"(",
"'Cannot use Node for \"'",
".",
"$",
"this",
"->",
"strTableName",
".",
"'\" when querying against the \"'",
".",
"$",
"objBuilder",
"->",
"RootTableName",
".",
"'\" table'",
",",
"3",
")",
";",
"}",
"}",
"else",
"{",
"// Special case situation to allow applying a join condition on an association table.",
"// The condition must be testing against the primary key of the joined table.",
"if",
"(",
"$",
"objJoinCondition",
"&&",
"$",
"this",
"->",
"objParentNode",
"instanceof",
"Association",
"&&",
"$",
"objJoinCondition",
"->",
"equalTables",
"(",
"$",
"this",
"->",
"objParentNode",
"->",
"fullAlias",
"(",
")",
")",
")",
"{",
"$",
"objParentNode",
"->",
"join",
"(",
"$",
"objBuilder",
",",
"$",
"blnExpandSelection",
",",
"$",
"objJoinCondition",
",",
"$",
"objSelect",
")",
";",
"$",
"objJoinCondition",
"=",
"null",
";",
"// prevent passing join condition to this level",
"}",
"else",
"{",
"$",
"objParentNode",
"->",
"join",
"(",
"$",
"objBuilder",
",",
"$",
"blnExpandSelection",
",",
"null",
",",
"$",
"objSelect",
")",
";",
"if",
"(",
"$",
"objJoinCondition",
"&&",
"!",
"$",
"objJoinCondition",
"->",
"equalTables",
"(",
"$",
"this",
"->",
"fullAlias",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Caller",
"(",
"\"The join condition on the \\\"\"",
".",
"$",
"this",
"->",
"strTableName",
".",
"\"\\\" table must only contain conditions for that table.\"",
")",
";",
"}",
"}",
"try",
"{",
"$",
"strParentAlias",
"=",
"$",
"objParentNode",
"->",
"fullAlias",
"(",
")",
";",
"$",
"strAlias",
"=",
"$",
"this",
"->",
"fullAlias",
"(",
")",
";",
"//$strJoinTableAlias = $strParentAlias . '__' . ($this->strAlias ? $this->strAlias : $this->strName);",
"$",
"objBuilder",
"->",
"addJoinItem",
"(",
"$",
"this",
"->",
"strTableName",
",",
"$",
"strAlias",
",",
"$",
"strParentAlias",
",",
"$",
"this",
"->",
"strName",
",",
"$",
"this",
"->",
"strPrimaryKey",
",",
"$",
"objJoinCondition",
")",
";",
"if",
"(",
"$",
"blnExpandSelection",
")",
"{",
"$",
"this",
"->",
"putSelectFields",
"(",
"$",
"objBuilder",
",",
"$",
"strAlias",
",",
"$",
"objSelect",
")",
";",
"}",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"}",
"}"
] |
Join the node to the query.
Otherwise, its a straightforward
one-to-one join. Conditional joins in this situation are really only useful when combined with condition
clauses that select out rows that were not joined (null FK).
@param Builder $objBuilder
@param bool $blnExpandSelection
@param iCondition|null $objJoinCondition
@param Clause\Select|null $objSelect
@throws Caller
|
[
"Join",
"the",
"node",
"to",
"the",
"query",
".",
"Otherwise",
"its",
"a",
"straightforward",
"one",
"-",
"to",
"-",
"one",
"join",
".",
"Conditional",
"joins",
"in",
"this",
"situation",
"are",
"really",
"only",
"useful",
"when",
"combined",
"with",
"condition",
"clauses",
"that",
"select",
"out",
"rows",
"that",
"were",
"not",
"joined",
"(",
"null",
"FK",
")",
"."
] |
train
|
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/Node/Table.php#L64-L109
|
krzysztofmazur/php-object-mapper
|
src/KrzysztofMazur/ObjectMapper/Mapping/Field/ValueWriter/MethodValueWriter.php
|
MethodValueWriter.writeValue
|
protected function writeValue($object, $value)
{
Reflection::getMethod(get_class($object), $this->methodName)->invokeArgs($object, [$value]);
}
|
php
|
protected function writeValue($object, $value)
{
Reflection::getMethod(get_class($object), $this->methodName)->invokeArgs($object, [$value]);
}
|
[
"protected",
"function",
"writeValue",
"(",
"$",
"object",
",",
"$",
"value",
")",
"{",
"Reflection",
"::",
"getMethod",
"(",
"get_class",
"(",
"$",
"object",
")",
",",
"$",
"this",
"->",
"methodName",
")",
"->",
"invokeArgs",
"(",
"$",
"object",
",",
"[",
"$",
"value",
"]",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/krzysztofmazur/php-object-mapper/blob/2c22acad9634cfe8e9a75d72e665d450ada8d4e3/src/KrzysztofMazur/ObjectMapper/Mapping/Field/ValueWriter/MethodValueWriter.php#L37-L40
|
arsengoian/viper-framework
|
src/Viper/Daemon/Router.php
|
Router.spawn
|
public function spawn(int $sleep) : void
{
if (isset($this -> storage['id']) && $this -> isAlive())
throw new DaemonException('It\'s alive anyway!');
$this -> actionLog('Spawning process with frequency '.$sleep);
$this -> actionLog('See shell output.');
$thisfile = __FILE__;
$thisclass = static::class;
$segments = explode('\\', $thisclass);
$thiscname = array_pop($segments);
str_replace('Router.php', "$thiscname.php", $thisfile);
$bootstrap = root().'/bootstrap.php';
$thisid = $this -> getName();
$this -> storage['id'] = $this -> platform -> newProcess($sleep, "
require \\\\\\\"$bootstrap\\\\\\\";
require \\\\\\\"$thisfile\\\\\\\";
(new $thisclass(\\\\\\\"$thisid\\\\\\\")) -> exec();
", $this -> getSuccFile(), $this -> getErrFile());
$this -> storage['sleep'] = $sleep;
$this -> store($this -> storage);
$this -> actionLog('Successful');
}
|
php
|
public function spawn(int $sleep) : void
{
if (isset($this -> storage['id']) && $this -> isAlive())
throw new DaemonException('It\'s alive anyway!');
$this -> actionLog('Spawning process with frequency '.$sleep);
$this -> actionLog('See shell output.');
$thisfile = __FILE__;
$thisclass = static::class;
$segments = explode('\\', $thisclass);
$thiscname = array_pop($segments);
str_replace('Router.php', "$thiscname.php", $thisfile);
$bootstrap = root().'/bootstrap.php';
$thisid = $this -> getName();
$this -> storage['id'] = $this -> platform -> newProcess($sleep, "
require \\\\\\\"$bootstrap\\\\\\\";
require \\\\\\\"$thisfile\\\\\\\";
(new $thisclass(\\\\\\\"$thisid\\\\\\\")) -> exec();
", $this -> getSuccFile(), $this -> getErrFile());
$this -> storage['sleep'] = $sleep;
$this -> store($this -> storage);
$this -> actionLog('Successful');
}
|
[
"public",
"function",
"spawn",
"(",
"int",
"$",
"sleep",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"storage",
"[",
"'id'",
"]",
")",
"&&",
"$",
"this",
"->",
"isAlive",
"(",
")",
")",
"throw",
"new",
"DaemonException",
"(",
"'It\\'s alive anyway!'",
")",
";",
"$",
"this",
"->",
"actionLog",
"(",
"'Spawning process with frequency '",
".",
"$",
"sleep",
")",
";",
"$",
"this",
"->",
"actionLog",
"(",
"'See shell output.'",
")",
";",
"$",
"thisfile",
"=",
"__FILE__",
";",
"$",
"thisclass",
"=",
"static",
"::",
"class",
";",
"$",
"segments",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"thisclass",
")",
";",
"$",
"thiscname",
"=",
"array_pop",
"(",
"$",
"segments",
")",
";",
"str_replace",
"(",
"'Router.php'",
",",
"\"$thiscname.php\"",
",",
"$",
"thisfile",
")",
";",
"$",
"bootstrap",
"=",
"root",
"(",
")",
".",
"'/bootstrap.php'",
";",
"$",
"thisid",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"this",
"->",
"storage",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"platform",
"->",
"newProcess",
"(",
"$",
"sleep",
",",
"\"\n require \\\\\\\\\\\\\\\"$bootstrap\\\\\\\\\\\\\\\";\n require \\\\\\\\\\\\\\\"$thisfile\\\\\\\\\\\\\\\";\n (new $thisclass(\\\\\\\\\\\\\\\"$thisid\\\\\\\\\\\\\\\")) -> exec();\n \"",
",",
"$",
"this",
"->",
"getSuccFile",
"(",
")",
",",
"$",
"this",
"->",
"getErrFile",
"(",
")",
")",
";",
"$",
"this",
"->",
"storage",
"[",
"'sleep'",
"]",
"=",
"$",
"sleep",
";",
"$",
"this",
"->",
"store",
"(",
"$",
"this",
"->",
"storage",
")",
";",
"$",
"this",
"->",
"actionLog",
"(",
"'Successful'",
")",
";",
"}"
] |
Create new daemon instance (system-dependent).
Creates a loop which keeps executing Daemon::run.
@param int $sleep in seconds
@throws DaemonException
|
[
"Create",
"new",
"daemon",
"instance",
"(",
"system",
"-",
"dependent",
")",
".",
"Creates",
"a",
"loop",
"which",
"keeps",
"executing",
"Daemon",
"::",
"run",
"."
] |
train
|
https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Daemon/Router.php#L45-L70
|
arsengoian/viper-framework
|
src/Viper/Daemon/Router.php
|
Router.restart
|
public function restart(int $sleep) : void
{
$this -> storage['sentenced'] = 'rewind';
$this -> storage['sleep'] = $sleep;
$this -> store($this -> storage);
}
|
php
|
public function restart(int $sleep) : void
{
$this -> storage['sentenced'] = 'rewind';
$this -> storage['sleep'] = $sleep;
$this -> store($this -> storage);
}
|
[
"public",
"function",
"restart",
"(",
"int",
"$",
"sleep",
")",
":",
"void",
"{",
"$",
"this",
"->",
"storage",
"[",
"'sentenced'",
"]",
"=",
"'rewind'",
";",
"$",
"this",
"->",
"storage",
"[",
"'sleep'",
"]",
"=",
"$",
"sleep",
";",
"$",
"this",
"->",
"store",
"(",
"$",
"this",
"->",
"storage",
")",
";",
"}"
] |
Gently stops daemon and starts it with new frequency
@param int $sleep
|
[
"Gently",
"stops",
"daemon",
"and",
"starts",
"it",
"with",
"new",
"frequency"
] |
train
|
https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Daemon/Router.php#L76-L81
|
arsengoian/viper-framework
|
src/Viper/Daemon/Router.php
|
Router.exec
|
public function exec() : void
{
$this -> actionLog('Script successfully entered');
$sentence = $this -> storage['sentenced'];
$response = NULL;
if (method_exists($this, $sentence))
$response = $this -> $sentence();
else $this -> errorLog('Unknown method '.$sentence);
if ($response)
$this -> actionLog('Received data: '.$response);
$this -> setMemory(memory_get_usage(TRUE));
$this -> actionLog('Script successfully completed, action: '.$sentence);
}
|
php
|
public function exec() : void
{
$this -> actionLog('Script successfully entered');
$sentence = $this -> storage['sentenced'];
$response = NULL;
if (method_exists($this, $sentence))
$response = $this -> $sentence();
else $this -> errorLog('Unknown method '.$sentence);
if ($response)
$this -> actionLog('Received data: '.$response);
$this -> setMemory(memory_get_usage(TRUE));
$this -> actionLog('Script successfully completed, action: '.$sentence);
}
|
[
"public",
"function",
"exec",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"actionLog",
"(",
"'Script successfully entered'",
")",
";",
"$",
"sentence",
"=",
"$",
"this",
"->",
"storage",
"[",
"'sentenced'",
"]",
";",
"$",
"response",
"=",
"NULL",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"sentence",
")",
")",
"$",
"response",
"=",
"$",
"this",
"->",
"$",
"sentence",
"(",
")",
";",
"else",
"$",
"this",
"->",
"errorLog",
"(",
"'Unknown method '",
".",
"$",
"sentence",
")",
";",
"if",
"(",
"$",
"response",
")",
"$",
"this",
"->",
"actionLog",
"(",
"'Received data: '",
".",
"$",
"response",
")",
";",
"$",
"this",
"->",
"setMemory",
"(",
"memory_get_usage",
"(",
"TRUE",
")",
")",
";",
"$",
"this",
"->",
"actionLog",
"(",
"'Script successfully completed, action: '",
".",
"$",
"sentence",
")",
";",
"}"
] |
Makes preparations for run method
Also stores memory used by daemon to be recovered
|
[
"Makes",
"preparations",
"for",
"run",
"method",
"Also",
"stores",
"memory",
"used",
"by",
"daemon",
"to",
"be",
"recovered"
] |
train
|
https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Daemon/Router.php#L95-L110
|
arsengoian/viper-framework
|
src/Viper/Daemon/Router.php
|
Router.route
|
public static function route(string $command, array $args) : void {
$object = new static('test');
echo "\n";
if (method_exists(static::class, $command)) {
$response = call_user_func_array([$object, $command], $args);
if ($response === NULL)
echo "SUCCESS";
else if ($response === FALSE)
echo "FALSE";
else if ($response === TRUE)
echo "TRUE";
else {
if (is_string($response))
echo $response;
else print_r($response);
}
} else echo "No such method available";
echo "\n\n";
}
|
php
|
public static function route(string $command, array $args) : void {
$object = new static('test');
echo "\n";
if (method_exists(static::class, $command)) {
$response = call_user_func_array([$object, $command], $args);
if ($response === NULL)
echo "SUCCESS";
else if ($response === FALSE)
echo "FALSE";
else if ($response === TRUE)
echo "TRUE";
else {
if (is_string($response))
echo $response;
else print_r($response);
}
} else echo "No such method available";
echo "\n\n";
}
|
[
"public",
"static",
"function",
"route",
"(",
"string",
"$",
"command",
",",
"array",
"$",
"args",
")",
":",
"void",
"{",
"$",
"object",
"=",
"new",
"static",
"(",
"'test'",
")",
";",
"echo",
"\"\\n\"",
";",
"if",
"(",
"method_exists",
"(",
"static",
"::",
"class",
",",
"$",
"command",
")",
")",
"{",
"$",
"response",
"=",
"call_user_func_array",
"(",
"[",
"$",
"object",
",",
"$",
"command",
"]",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"response",
"===",
"NULL",
")",
"echo",
"\"SUCCESS\"",
";",
"else",
"if",
"(",
"$",
"response",
"===",
"FALSE",
")",
"echo",
"\"FALSE\"",
";",
"else",
"if",
"(",
"$",
"response",
"===",
"TRUE",
")",
"echo",
"\"TRUE\"",
";",
"else",
"{",
"if",
"(",
"is_string",
"(",
"$",
"response",
")",
")",
"echo",
"$",
"response",
";",
"else",
"print_r",
"(",
"$",
"response",
")",
";",
"}",
"}",
"else",
"echo",
"\"No such method available\"",
";",
"echo",
"\"\\n\\n\"",
";",
"}"
] |
Start a command to services
@param string $command
@param array $args
|
[
"Start",
"a",
"command",
"to",
"services"
] |
train
|
https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Daemon/Router.php#L191-L209
|
ClanCats/Core
|
src/bundles/Database/Handler.php
|
Handler._init
|
public static function _init()
{
if ( \ClanCats::in_development() )
{
// add a hook to the main resposne
\CCEvent::mind( 'response.output', function( $output ) {
if ( strpos( $output, '</body>' ) === false )
{
return $output;
}
$table = \UI\Table::create( array(
'style' => array(
'width' => '100%',
),
'cellpadding' => '5',
'class' => 'table debug-table debug-table-db',
));
$table->header( array( '#', 'query' ) );
foreach( static::log() as $key => $item )
{
$table->row( array(
$key+1,
$item
));
}
return str_replace( '</body>', $table."\n</body>", $output );
});
}
}
|
php
|
public static function _init()
{
if ( \ClanCats::in_development() )
{
// add a hook to the main resposne
\CCEvent::mind( 'response.output', function( $output ) {
if ( strpos( $output, '</body>' ) === false )
{
return $output;
}
$table = \UI\Table::create( array(
'style' => array(
'width' => '100%',
),
'cellpadding' => '5',
'class' => 'table debug-table debug-table-db',
));
$table->header( array( '#', 'query' ) );
foreach( static::log() as $key => $item )
{
$table->row( array(
$key+1,
$item
));
}
return str_replace( '</body>', $table."\n</body>", $output );
});
}
}
|
[
"public",
"static",
"function",
"_init",
"(",
")",
"{",
"if",
"(",
"\\",
"ClanCats",
"::",
"in_development",
"(",
")",
")",
"{",
"// add a hook to the main resposne",
"\\",
"CCEvent",
"::",
"mind",
"(",
"'response.output'",
",",
"function",
"(",
"$",
"output",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"output",
",",
"'</body>'",
")",
"===",
"false",
")",
"{",
"return",
"$",
"output",
";",
"}",
"$",
"table",
"=",
"\\",
"UI",
"\\",
"Table",
"::",
"create",
"(",
"array",
"(",
"'style'",
"=>",
"array",
"(",
"'width'",
"=>",
"'100%'",
",",
")",
",",
"'cellpadding'",
"=>",
"'5'",
",",
"'class'",
"=>",
"'table debug-table debug-table-db'",
",",
")",
")",
";",
"$",
"table",
"->",
"header",
"(",
"array",
"(",
"'#'",
",",
"'query'",
")",
")",
";",
"foreach",
"(",
"static",
"::",
"log",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"table",
"->",
"row",
"(",
"array",
"(",
"$",
"key",
"+",
"1",
",",
"$",
"item",
")",
")",
";",
"}",
"return",
"str_replace",
"(",
"'</body>'",
",",
"$",
"table",
".",
"\"\\n</body>\"",
",",
"$",
"output",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Static init
When we are in development then we append the qurey log to body
@codeCoverageIgnore
@return void
|
[
"Static",
"init",
"When",
"we",
"are",
"in",
"development",
"then",
"we",
"append",
"the",
"qurey",
"log",
"to",
"body"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Handler.php#L43-L76
|
ClanCats/Core
|
src/bundles/Database/Handler.php
|
Handler.connect
|
protected function connect( $name )
{
if ( $this->_connected )
{
return true;
}
// check if the name is an array. This way we can
// pass the configuration directly. We need this
// to create for example an handler without having
// the configuration in the database conf file.
if ( is_array( $name ) )
{
$config = $name;
}
else
{
$config = \CCConfig::create( 'database' )->get( $name );
// check for an alias. If you set a string
// in your config file we use the config
// with the passed key.
if ( is_string( $config ) )
{
$config = \CCConfig::create( 'database' )->get( $config );
}
}
// Setup the driver class. We simply use name
// from the confif file and make the first letter
// capital. example: Handler_Mysql, Handler_Sqlite etc.
$driver_class = __NAMESPACE__."\\Handler_".ucfirst( $config['driver'] );
if ( !class_exists( $driver_class ) )
{
throw new Exception( "DB\\Handler::connect - The driver (".$driver_class.") is invalid." );
}
$this->set_driver( $driver_class );
// setup the builder the same way as the handler.
$driver_class = __NAMESPACE__."\\Builder_".ucfirst( $config['driver'] );
if ( !class_exists( $driver_class ) )
{
throw new Exception( "DB\\Handler::connect - The builder (".$driver_class.") is invalid." );
}
$this->set_builder( $driver_class );
// finally try to connect the driver with the databse
if ( $this->driver()->connect( $config ) )
{
return $this->_connected = true;
}
return $this->_connected = false;
}
|
php
|
protected function connect( $name )
{
if ( $this->_connected )
{
return true;
}
// check if the name is an array. This way we can
// pass the configuration directly. We need this
// to create for example an handler without having
// the configuration in the database conf file.
if ( is_array( $name ) )
{
$config = $name;
}
else
{
$config = \CCConfig::create( 'database' )->get( $name );
// check for an alias. If you set a string
// in your config file we use the config
// with the passed key.
if ( is_string( $config ) )
{
$config = \CCConfig::create( 'database' )->get( $config );
}
}
// Setup the driver class. We simply use name
// from the confif file and make the first letter
// capital. example: Handler_Mysql, Handler_Sqlite etc.
$driver_class = __NAMESPACE__."\\Handler_".ucfirst( $config['driver'] );
if ( !class_exists( $driver_class ) )
{
throw new Exception( "DB\\Handler::connect - The driver (".$driver_class.") is invalid." );
}
$this->set_driver( $driver_class );
// setup the builder the same way as the handler.
$driver_class = __NAMESPACE__."\\Builder_".ucfirst( $config['driver'] );
if ( !class_exists( $driver_class ) )
{
throw new Exception( "DB\\Handler::connect - The builder (".$driver_class.") is invalid." );
}
$this->set_builder( $driver_class );
// finally try to connect the driver with the databse
if ( $this->driver()->connect( $config ) )
{
return $this->_connected = true;
}
return $this->_connected = false;
}
|
[
"protected",
"function",
"connect",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_connected",
")",
"{",
"return",
"true",
";",
"}",
"// check if the name is an array. This way we can",
"// pass the configuration directly. We need this ",
"// to create for example an handler without having",
"// the configuration in the database conf file.",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"config",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"config",
"=",
"\\",
"CCConfig",
"::",
"create",
"(",
"'database'",
")",
"->",
"get",
"(",
"$",
"name",
")",
";",
"// check for an alias. If you set a string ",
"// in your config file we use the config ",
"// with the passed key.",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"\\",
"CCConfig",
"::",
"create",
"(",
"'database'",
")",
"->",
"get",
"(",
"$",
"config",
")",
";",
"}",
"}",
"// Setup the driver class. We simply use name ",
"// from the confif file and make the first letter ",
"// capital. example: Handler_Mysql, Handler_Sqlite etc.",
"$",
"driver_class",
"=",
"__NAMESPACE__",
".",
"\"\\\\Handler_\"",
".",
"ucfirst",
"(",
"$",
"config",
"[",
"'driver'",
"]",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"driver_class",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"DB\\\\Handler::connect - The driver (\"",
".",
"$",
"driver_class",
".",
"\") is invalid.\"",
")",
";",
"}",
"$",
"this",
"->",
"set_driver",
"(",
"$",
"driver_class",
")",
";",
"// setup the builder the same way as the handler.",
"$",
"driver_class",
"=",
"__NAMESPACE__",
".",
"\"\\\\Builder_\"",
".",
"ucfirst",
"(",
"$",
"config",
"[",
"'driver'",
"]",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"driver_class",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"DB\\\\Handler::connect - The builder (\"",
".",
"$",
"driver_class",
".",
"\") is invalid.\"",
")",
";",
"}",
"$",
"this",
"->",
"set_builder",
"(",
"$",
"driver_class",
")",
";",
"// finally try to connect the driver with the databse",
"if",
"(",
"$",
"this",
"->",
"driver",
"(",
")",
"->",
"connect",
"(",
"$",
"config",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_connected",
"=",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"_connected",
"=",
"false",
";",
"}"
] |
Try to etablish a connetion to the database. Also assign the connection
and query builder to the current DB driver.
@param string|array $name When passing an array it will be uesed as configuration.
@return void
|
[
"Try",
"to",
"etablish",
"a",
"connetion",
"to",
"the",
"database",
".",
"Also",
"assign",
"the",
"connection",
"and",
"query",
"builder",
"to",
"the",
"current",
"DB",
"driver",
"."
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Handler.php#L218-L275
|
ClanCats/Core
|
src/bundles/Database/Handler.php
|
Handler.statement
|
public function statement( $query, $params = array() )
{
// we alway prepare the query even if we dont have parameters
$sth = $this->driver()->connection()->prepare( $query );
// because we set pdo the throw exception on db errors
// we catch them here to throw our own exception.
try
{
$sth->execute( $params );
}
catch ( \PDOException $e )
{
throw new Exception( "DB\\Handler - PDOException: {$e->getMessage()} \n Query: {$query}" );
}
// In development we alway log the query into an array.
if ( \ClanCats::in_development() )
{
$keys = array();
foreach ( $params as $key => $value )
{
if ( is_string( $key ) )
{
$keys[] = '/:'.$key.'/';
} else {
$keys[] = '/[?]/';
}
}
static::$_query_log[] = preg_replace( $keys, $params, $query, 1 );
}
return $sth;
}
|
php
|
public function statement( $query, $params = array() )
{
// we alway prepare the query even if we dont have parameters
$sth = $this->driver()->connection()->prepare( $query );
// because we set pdo the throw exception on db errors
// we catch them here to throw our own exception.
try
{
$sth->execute( $params );
}
catch ( \PDOException $e )
{
throw new Exception( "DB\\Handler - PDOException: {$e->getMessage()} \n Query: {$query}" );
}
// In development we alway log the query into an array.
if ( \ClanCats::in_development() )
{
$keys = array();
foreach ( $params as $key => $value )
{
if ( is_string( $key ) )
{
$keys[] = '/:'.$key.'/';
} else {
$keys[] = '/[?]/';
}
}
static::$_query_log[] = preg_replace( $keys, $params, $query, 1 );
}
return $sth;
}
|
[
"public",
"function",
"statement",
"(",
"$",
"query",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"// we alway prepare the query even if we dont have parameters",
"$",
"sth",
"=",
"$",
"this",
"->",
"driver",
"(",
")",
"->",
"connection",
"(",
")",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"// because we set pdo the throw exception on db errors",
"// we catch them here to throw our own exception.",
"try",
"{",
"$",
"sth",
"->",
"execute",
"(",
"$",
"params",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"DB\\\\Handler - PDOException: {$e->getMessage()} \\n Query: {$query}\"",
")",
";",
"}",
"// In development we alway log the query into an array.",
"if",
"(",
"\\",
"ClanCats",
"::",
"in_development",
"(",
")",
")",
"{",
"$",
"keys",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"'/:'",
".",
"$",
"key",
".",
"'/'",
";",
"}",
"else",
"{",
"$",
"keys",
"[",
"]",
"=",
"'/[?]/'",
";",
"}",
"}",
"static",
"::",
"$",
"_query_log",
"[",
"]",
"=",
"preg_replace",
"(",
"$",
"keys",
",",
"$",
"params",
",",
"$",
"query",
",",
"1",
")",
";",
"}",
"return",
"$",
"sth",
";",
"}"
] |
Run the query and return the PDO statement
@param string $query
@param array $params
@return array
|
[
"Run",
"the",
"query",
"and",
"return",
"the",
"PDO",
"statement"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Handler.php#L294-L329
|
ClanCats/Core
|
src/bundles/Database/Handler.php
|
Handler.fetch
|
public function fetch( $query, $params = array(), $arguments = array( 'obj' ) )
{
$sth = $this->statement( $query, $params );
$args = null;
foreach( $arguments as $argument )
{
$args |= constant( "\PDO::FETCH_".strtoupper( $argument ) );
}
return $sth->fetchAll( $args );
}
|
php
|
public function fetch( $query, $params = array(), $arguments = array( 'obj' ) )
{
$sth = $this->statement( $query, $params );
$args = null;
foreach( $arguments as $argument )
{
$args |= constant( "\PDO::FETCH_".strtoupper( $argument ) );
}
return $sth->fetchAll( $args );
}
|
[
"public",
"function",
"fetch",
"(",
"$",
"query",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"arguments",
"=",
"array",
"(",
"'obj'",
")",
")",
"{",
"$",
"sth",
"=",
"$",
"this",
"->",
"statement",
"(",
"$",
"query",
",",
"$",
"params",
")",
";",
"$",
"args",
"=",
"null",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"argument",
")",
"{",
"$",
"args",
"|=",
"constant",
"(",
"\"\\PDO::FETCH_\"",
".",
"strtoupper",
"(",
"$",
"argument",
")",
")",
";",
"}",
"return",
"$",
"sth",
"->",
"fetchAll",
"(",
"$",
"args",
")",
";",
"}"
] |
Run the query and fetch the results
You can pass arguments on the third parameter.
These parameter are just the normal PDO ones but in short.
obj = \PDO::FETCH_OBJ
assoc = \PDO::FETCH_ASSOC
@param string $query
@param array $params
@return array
|
[
"Run",
"the",
"query",
"and",
"fetch",
"the",
"results"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Handler.php#L344-L356
|
ClanCats/Core
|
src/bundles/Database/Handler.php
|
Handler.run
|
public function run( $query, $params = array() )
{
$sth = $this->statement( $query, $params );
$type = strtolower( substr( $query, 0, strpos( $query, ' ' ) ) );
switch ( $type )
{
case 'update':
case 'delete':
return $sth->rowCount();
break;
case 'insert':
return $this->driver()->connection()->lastInsertId();
break;
}
return $sth;
}
|
php
|
public function run( $query, $params = array() )
{
$sth = $this->statement( $query, $params );
$type = strtolower( substr( $query, 0, strpos( $query, ' ' ) ) );
switch ( $type )
{
case 'update':
case 'delete':
return $sth->rowCount();
break;
case 'insert':
return $this->driver()->connection()->lastInsertId();
break;
}
return $sth;
}
|
[
"public",
"function",
"run",
"(",
"$",
"query",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sth",
"=",
"$",
"this",
"->",
"statement",
"(",
"$",
"query",
",",
"$",
"params",
")",
";",
"$",
"type",
"=",
"strtolower",
"(",
"substr",
"(",
"$",
"query",
",",
"0",
",",
"strpos",
"(",
"$",
"query",
",",
"' '",
")",
")",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'update'",
":",
"case",
"'delete'",
":",
"return",
"$",
"sth",
"->",
"rowCount",
"(",
")",
";",
"break",
";",
"case",
"'insert'",
":",
"return",
"$",
"this",
"->",
"driver",
"(",
")",
"->",
"connection",
"(",
")",
"->",
"lastInsertId",
"(",
")",
";",
"break",
";",
"}",
"return",
"$",
"sth",
";",
"}"
] |
Run the query and get the correct response
INSERT -> last id
UPDATE -> affected rows
DELETE -> affected rows
etc...
@param string $query
@param array $params
@return array
|
[
"Run",
"the",
"query",
"and",
"get",
"the",
"correct",
"response"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Handler.php#L370-L389
|
rayrutjes/domain-foundation
|
src/Command/Bus/SimpleCommandBus.php
|
SimpleCommandBus.dispatch
|
public function dispatch(Command $command, CommandCallback $callback = null)
{
$command = $this->intercept($command);
$handler = $this->handlerRegistry->findCommandHandlerFor($command);
$this->unitOfWork->start();
$interceptorChain = new DefaultInterceptorChain($command, $this->unitOfWork, $handler, ...$this->handlerInterceptors);
try {
$result = $interceptorChain->proceed();
if (null !== $callback) {
$callback->onSuccess($result);
}
} catch (\Exception $exception) {
$this->unitOfWork->rollback($exception);
if (null !== $callback) {
$callback->onFailure($exception);
}
throw $exception;
}
$this->unitOfWork->commit();
return $result;
}
|
php
|
public function dispatch(Command $command, CommandCallback $callback = null)
{
$command = $this->intercept($command);
$handler = $this->handlerRegistry->findCommandHandlerFor($command);
$this->unitOfWork->start();
$interceptorChain = new DefaultInterceptorChain($command, $this->unitOfWork, $handler, ...$this->handlerInterceptors);
try {
$result = $interceptorChain->proceed();
if (null !== $callback) {
$callback->onSuccess($result);
}
} catch (\Exception $exception) {
$this->unitOfWork->rollback($exception);
if (null !== $callback) {
$callback->onFailure($exception);
}
throw $exception;
}
$this->unitOfWork->commit();
return $result;
}
|
[
"public",
"function",
"dispatch",
"(",
"Command",
"$",
"command",
",",
"CommandCallback",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"intercept",
"(",
"$",
"command",
")",
";",
"$",
"handler",
"=",
"$",
"this",
"->",
"handlerRegistry",
"->",
"findCommandHandlerFor",
"(",
"$",
"command",
")",
";",
"$",
"this",
"->",
"unitOfWork",
"->",
"start",
"(",
")",
";",
"$",
"interceptorChain",
"=",
"new",
"DefaultInterceptorChain",
"(",
"$",
"command",
",",
"$",
"this",
"->",
"unitOfWork",
",",
"$",
"handler",
",",
"...",
"$",
"this",
"->",
"handlerInterceptors",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"interceptorChain",
"->",
"proceed",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"callback",
")",
"{",
"$",
"callback",
"->",
"onSuccess",
"(",
"$",
"result",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"unitOfWork",
"->",
"rollback",
"(",
"$",
"exception",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"callback",
")",
"{",
"$",
"callback",
"->",
"onFailure",
"(",
"$",
"exception",
")",
";",
"}",
"throw",
"$",
"exception",
";",
"}",
"$",
"this",
"->",
"unitOfWork",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
@param Command $command
@param CommandCallback $callback
@throws \Exception
|
[
"@param",
"Command",
"$command",
"@param",
"CommandCallback",
"$callback"
] |
train
|
https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/Command/Bus/SimpleCommandBus.php#L51-L77
|
rayrutjes/domain-foundation
|
src/Command/Bus/SimpleCommandBus.php
|
SimpleCommandBus.intercept
|
private function intercept(Command $command)
{
foreach ($this->dispatchInterceptors as $dispatchInterceptor) {
$command = $dispatchInterceptor->handle($command);
}
return $command;
}
|
php
|
private function intercept(Command $command)
{
foreach ($this->dispatchInterceptors as $dispatchInterceptor) {
$command = $dispatchInterceptor->handle($command);
}
return $command;
}
|
[
"private",
"function",
"intercept",
"(",
"Command",
"$",
"command",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dispatchInterceptors",
"as",
"$",
"dispatchInterceptor",
")",
"{",
"$",
"command",
"=",
"$",
"dispatchInterceptor",
"->",
"handle",
"(",
"$",
"command",
")",
";",
"}",
"return",
"$",
"command",
";",
"}"
] |
@param Command $command
@return Command
|
[
"@param",
"Command",
"$command"
] |
train
|
https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/Command/Bus/SimpleCommandBus.php#L84-L91
|
vench/venus-fw
|
src/vsapp/Request.php
|
Request.get
|
public function get($name) {
$query = $this->queryAll();
return isset($query[$name]) ? $query[$name] : null;
}
|
php
|
public function get($name) {
$query = $this->queryAll();
return isset($query[$name]) ? $query[$name] : null;
}
|
[
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"queryAll",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"query",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"query",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] |
Get value from GET params
@param string $name
@return mixed
|
[
"Get",
"value",
"from",
"GET",
"params"
] |
train
|
https://github.com/vench/venus-fw/blob/9075ab6062551c022d145ac20640438074d5cb85/src/vsapp/Request.php#L43-L46
|
CakeCMS/Core
|
src/Toolbar/ToolbarItem.php
|
ToolbarItem.fetchId
|
public function fetchId($type, $name)
{
return Inflector::dasherize($this->_parent->getName()) . '-' . Str::slug($type);
}
|
php
|
public function fetchId($type, $name)
{
return Inflector::dasherize($this->_parent->getName()) . '-' . Str::slug($type);
}
|
[
"public",
"function",
"fetchId",
"(",
"$",
"type",
",",
"$",
"name",
")",
"{",
"return",
"Inflector",
"::",
"dasherize",
"(",
"$",
"this",
"->",
"_parent",
"->",
"getName",
"(",
")",
")",
".",
"'-'",
".",
"Str",
"::",
"slug",
"(",
"$",
"type",
")",
";",
"}"
] |
Fetch button id.
@param string $type
@param string $name
@return string
@SuppressWarnings("unused")
|
[
"Fetch",
"button",
"id",
"."
] |
train
|
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Toolbar/ToolbarItem.php#L64-L67
|
CakeCMS/Core
|
src/Toolbar/ToolbarItem.php
|
ToolbarItem.render
|
public function render(&$node)
{
$id = call_user_func_array([&$this, 'fetchId'], $node);
$output = call_user_func_array([&$this, 'fetchItem'], $node);
list ($source) = $node;
list ($plugin) = pluginSplit($source);
$options = [
'id' => $id,
'output' => $output,
'class' => $node['class'],
];
$element = 'Toolbar/wrapper';
if ($plugin !== null) {
$element = $plugin . '.' . $element;
}
return $this->_view->element($element, $options);
}
|
php
|
public function render(&$node)
{
$id = call_user_func_array([&$this, 'fetchId'], $node);
$output = call_user_func_array([&$this, 'fetchItem'], $node);
list ($source) = $node;
list ($plugin) = pluginSplit($source);
$options = [
'id' => $id,
'output' => $output,
'class' => $node['class'],
];
$element = 'Toolbar/wrapper';
if ($plugin !== null) {
$element = $plugin . '.' . $element;
}
return $this->_view->element($element, $options);
}
|
[
"public",
"function",
"render",
"(",
"&",
"$",
"node",
")",
"{",
"$",
"id",
"=",
"call_user_func_array",
"(",
"[",
"&",
"$",
"this",
",",
"'fetchId'",
"]",
",",
"$",
"node",
")",
";",
"$",
"output",
"=",
"call_user_func_array",
"(",
"[",
"&",
"$",
"this",
",",
"'fetchItem'",
"]",
",",
"$",
"node",
")",
";",
"list",
"(",
"$",
"source",
")",
"=",
"$",
"node",
";",
"list",
"(",
"$",
"plugin",
")",
"=",
"pluginSplit",
"(",
"$",
"source",
")",
";",
"$",
"options",
"=",
"[",
"'id'",
"=>",
"$",
"id",
",",
"'output'",
"=>",
"$",
"output",
",",
"'class'",
"=>",
"$",
"node",
"[",
"'class'",
"]",
",",
"]",
";",
"$",
"element",
"=",
"'Toolbar/wrapper'",
";",
"if",
"(",
"$",
"plugin",
"!==",
"null",
")",
"{",
"$",
"element",
"=",
"$",
"plugin",
".",
"'.'",
".",
"$",
"element",
";",
"}",
"return",
"$",
"this",
"->",
"_view",
"->",
"element",
"(",
"$",
"element",
",",
"$",
"options",
")",
";",
"}"
] |
Render toolbar html.
@param array $node
@return string
|
[
"Render",
"toolbar",
"html",
"."
] |
train
|
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Toolbar/ToolbarItem.php#L82-L101
|
helthe/Chronos
|
Field/AbstractField.php
|
AbstractField.matches
|
public function matches(\DateTime $date)
{
if ('*' === $this->value) {
return true;
}
$dateValue = $this->getFieldValueFromDate($date);
$values = $this->getValueArray();
$found = false;
foreach ($values as $value) {
if ($found) {
break;
}
if ($dateValue == $value) {
$found = true;
} elseif (strpos($value, '/') !== false) {
$found = $this->isInIncrementsOfRange($value, $dateValue);
} elseif (strpos($value, '-') !== false) {
$found = $this->isInRange($value, $dateValue);
}
}
return $found;
}
|
php
|
public function matches(\DateTime $date)
{
if ('*' === $this->value) {
return true;
}
$dateValue = $this->getFieldValueFromDate($date);
$values = $this->getValueArray();
$found = false;
foreach ($values as $value) {
if ($found) {
break;
}
if ($dateValue == $value) {
$found = true;
} elseif (strpos($value, '/') !== false) {
$found = $this->isInIncrementsOfRange($value, $dateValue);
} elseif (strpos($value, '-') !== false) {
$found = $this->isInRange($value, $dateValue);
}
}
return $found;
}
|
[
"public",
"function",
"matches",
"(",
"\\",
"DateTime",
"$",
"date",
")",
"{",
"if",
"(",
"'*'",
"===",
"$",
"this",
"->",
"value",
")",
"{",
"return",
"true",
";",
"}",
"$",
"dateValue",
"=",
"$",
"this",
"->",
"getFieldValueFromDate",
"(",
"$",
"date",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"getValueArray",
"(",
")",
";",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"found",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"dateValue",
"==",
"$",
"value",
")",
"{",
"$",
"found",
"=",
"true",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"value",
",",
"'/'",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"isInIncrementsOfRange",
"(",
"$",
"value",
",",
"$",
"dateValue",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"value",
",",
"'-'",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"isInRange",
"(",
"$",
"value",
",",
"$",
"dateValue",
")",
";",
"}",
"}",
"return",
"$",
"found",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Field/AbstractField.php#L59-L84
|
helthe/Chronos
|
Field/AbstractField.php
|
AbstractField.isInIncrementsOfRange
|
protected function isInIncrementsOfRange($increments, $value)
{
$incrementsParts = explode('/', $increments);
if ('*' === $incrementsParts[0]) {
return (int) $value % $incrementsParts[1] === 0;
}
if (!$this->isInRange($incrementsParts[0], $value)) {
return false;
}
$rangeParts = explode('-', $incrementsParts[0]);
for ($i = $rangeParts[0]; $i <= $rangeParts[1]; $i += $incrementsParts[1]) {
if ($i == $value) {
return true;
}
}
return false;
}
|
php
|
protected function isInIncrementsOfRange($increments, $value)
{
$incrementsParts = explode('/', $increments);
if ('*' === $incrementsParts[0]) {
return (int) $value % $incrementsParts[1] === 0;
}
if (!$this->isInRange($incrementsParts[0], $value)) {
return false;
}
$rangeParts = explode('-', $incrementsParts[0]);
for ($i = $rangeParts[0]; $i <= $rangeParts[1]; $i += $incrementsParts[1]) {
if ($i == $value) {
return true;
}
}
return false;
}
|
[
"protected",
"function",
"isInIncrementsOfRange",
"(",
"$",
"increments",
",",
"$",
"value",
")",
"{",
"$",
"incrementsParts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"increments",
")",
";",
"if",
"(",
"'*'",
"===",
"$",
"incrementsParts",
"[",
"0",
"]",
")",
"{",
"return",
"(",
"int",
")",
"$",
"value",
"%",
"$",
"incrementsParts",
"[",
"1",
"]",
"===",
"0",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isInRange",
"(",
"$",
"incrementsParts",
"[",
"0",
"]",
",",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"rangeParts",
"=",
"explode",
"(",
"'-'",
",",
"$",
"incrementsParts",
"[",
"0",
"]",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"rangeParts",
"[",
"0",
"]",
";",
"$",
"i",
"<=",
"$",
"rangeParts",
"[",
"1",
"]",
";",
"$",
"i",
"+=",
"$",
"incrementsParts",
"[",
"1",
"]",
")",
"{",
"if",
"(",
"$",
"i",
"==",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks if the given value is in the given increments of range.
@param string $increments
@param string $value
@return Boolean
|
[
"Checks",
"if",
"the",
"given",
"value",
"is",
"in",
"the",
"given",
"increments",
"of",
"range",
"."
] |
train
|
https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Field/AbstractField.php#L134-L155
|
helthe/Chronos
|
Field/AbstractField.php
|
AbstractField.isInRange
|
protected function isInRange($range, $value)
{
$parts = explode('-', $range);
return $value >= $parts[0] && $value <= $parts[1];
}
|
php
|
protected function isInRange($range, $value)
{
$parts = explode('-', $range);
return $value >= $parts[0] && $value <= $parts[1];
}
|
[
"protected",
"function",
"isInRange",
"(",
"$",
"range",
",",
"$",
"value",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'-'",
",",
"$",
"range",
")",
";",
"return",
"$",
"value",
">=",
"$",
"parts",
"[",
"0",
"]",
"&&",
"$",
"value",
"<=",
"$",
"parts",
"[",
"1",
"]",
";",
"}"
] |
Checks if the given value is in the given range.
@param string $range
@param string $value
@return Boolean
|
[
"Checks",
"if",
"the",
"given",
"value",
"is",
"in",
"the",
"given",
"range",
"."
] |
train
|
https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Field/AbstractField.php#L165-L170
|
vench/venus-fw
|
src/vsapp/controller/ApiController.php
|
ApiController.actionFac
|
public function actionFac($n) {
$f = function($v) use(&$f){
if($v <= 0) {
return 1;
}
return $v -- * $f( $v );
};
return ['input' => $n, 'output' => $f($n)];
}
|
php
|
public function actionFac($n) {
$f = function($v) use(&$f){
if($v <= 0) {
return 1;
}
return $v -- * $f( $v );
};
return ['input' => $n, 'output' => $f($n)];
}
|
[
"public",
"function",
"actionFac",
"(",
"$",
"n",
")",
"{",
"$",
"f",
"=",
"function",
"(",
"$",
"v",
")",
"use",
"(",
"&",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"v",
"<=",
"0",
")",
"{",
"return",
"1",
";",
"}",
"return",
"$",
"v",
"--",
"*",
"$",
"f",
"(",
"$",
"v",
")",
";",
"}",
";",
"return",
"[",
"'input'",
"=>",
"$",
"n",
",",
"'output'",
"=>",
"$",
"f",
"(",
"$",
"n",
")",
"]",
";",
"}"
] |
Factorialis
try /api/fac?n=4
@proxy_exec \vsapp\proxy\filters\controller\JSONResult
@proxy_exec \vsapp\proxy\filters\controller\RequestMethod {"types": ["GET"]}
@proxy_exec \vsapp\proxy\filters\arg\Filter {"rules": [[["0"], ["int"]]]}
@proxy_exec \vsapp\proxy\filters\arg\Validator {"rules": [[["0"], ["int"]]]}
|
[
"Factorialis",
"try",
"/",
"api",
"/",
"fac?n",
"=",
"4"
] |
train
|
https://github.com/vench/venus-fw/blob/9075ab6062551c022d145ac20640438074d5cb85/src/vsapp/controller/ApiController.php#L63-L73
|
yuncms/framework
|
src/filesystem/Cache.php
|
Cache.load
|
public function load()
{
$contents = $this->cache->get($this->key);
if ($contents !== false) {
$this->setFromStorage($contents);
}
}
|
php
|
public function load()
{
$contents = $this->cache->get($this->key);
if ($contents !== false) {
$this->setFromStorage($contents);
}
}
|
[
"public",
"function",
"load",
"(",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"this",
"->",
"key",
")",
";",
"if",
"(",
"$",
"contents",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"setFromStorage",
"(",
"$",
"contents",
")",
";",
"}",
"}"
] |
Load the cache.
|
[
"Load",
"the",
"cache",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/filesystem/Cache.php#L57-L64
|
yuncms/framework
|
src/filesystem/Cache.php
|
Cache.save
|
public function save()
{
$contents = $this->getForStorage();
if (!is_null($this->expire)) {
$this->cache->set($this->key, $contents, $this->expire);
} else {
$this->cache->set($this->key, $contents);
}
}
|
php
|
public function save()
{
$contents = $this->getForStorage();
if (!is_null($this->expire)) {
$this->cache->set($this->key, $contents, $this->expire);
} else {
$this->cache->set($this->key, $contents);
}
}
|
[
"public",
"function",
"save",
"(",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"getForStorage",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"expire",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"this",
"->",
"key",
",",
"$",
"contents",
",",
"$",
"this",
"->",
"expire",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"this",
"->",
"key",
",",
"$",
"contents",
")",
";",
"}",
"}"
] |
Persist the cache.
|
[
"Persist",
"the",
"cache",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/filesystem/Cache.php#L69-L78
|
spiral-modules/scaffolder
|
source/Scaffolder/Commands/Database/Traits/SourceDeclarationTrait.php
|
SourceDeclarationTrait.sourceDeclaration
|
private function sourceDeclaration(string $name, string $type, string $model): SourceDeclaration
{
return new SourceDeclaration(
$this->getConfig()->className('source', $name),
$type,
$model
);
}
|
php
|
private function sourceDeclaration(string $name, string $type, string $model): SourceDeclaration
{
return new SourceDeclaration(
$this->getConfig()->className('source', $name),
$type,
$model
);
}
|
[
"private",
"function",
"sourceDeclaration",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"type",
",",
"string",
"$",
"model",
")",
":",
"SourceDeclaration",
"{",
"return",
"new",
"SourceDeclaration",
"(",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"className",
"(",
"'source'",
",",
"$",
"name",
")",
",",
"$",
"type",
",",
"$",
"model",
")",
";",
"}"
] |
@param string $name
@param string $type
@param string $model
@return \Spiral\Scaffolder\Declarations\Database\SourceDeclaration
|
[
"@param",
"string",
"$name",
"@param",
"string",
"$type",
"@param",
"string",
"$model"
] |
train
|
https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Commands/Database/Traits/SourceDeclarationTrait.php#L22-L29
|
whisller/IrcBotBundle
|
EventListener/Plugins/Commands/HelpCommandListener.php
|
HelpCommandListener.onCommand
|
public function onCommand(BotCommandFoundEvent $event)
{
$this->sendMessage(array($event->getNickname()), 'IrcBotBundle (https://github.com/whisller/IrcBotBundle)');
$this->sendMessage(array($event->getNickname()), 'Available commands:');
$this->commandsHolder->rewind();
while ($this->commandsHolder->valid()) {
$current = $this->commandsHolder->current();
if (isset($current[0]['command'])) {
$msg = $this->commandPrefix.' '.$current[0]['command'].(isset($current[0]['arguments'])? ' '.$current[0]['arguments'] : '').(isset($current[0]['help']) ? ' : '.$current[0]['help']:'');
$this->sendMessage(array($event->getNickname()), $msg);
}
$this->commandsHolder->next();
}
}
|
php
|
public function onCommand(BotCommandFoundEvent $event)
{
$this->sendMessage(array($event->getNickname()), 'IrcBotBundle (https://github.com/whisller/IrcBotBundle)');
$this->sendMessage(array($event->getNickname()), 'Available commands:');
$this->commandsHolder->rewind();
while ($this->commandsHolder->valid()) {
$current = $this->commandsHolder->current();
if (isset($current[0]['command'])) {
$msg = $this->commandPrefix.' '.$current[0]['command'].(isset($current[0]['arguments'])? ' '.$current[0]['arguments'] : '').(isset($current[0]['help']) ? ' : '.$current[0]['help']:'');
$this->sendMessage(array($event->getNickname()), $msg);
}
$this->commandsHolder->next();
}
}
|
[
"public",
"function",
"onCommand",
"(",
"BotCommandFoundEvent",
"$",
"event",
")",
"{",
"$",
"this",
"->",
"sendMessage",
"(",
"array",
"(",
"$",
"event",
"->",
"getNickname",
"(",
")",
")",
",",
"'IrcBotBundle (https://github.com/whisller/IrcBotBundle)'",
")",
";",
"$",
"this",
"->",
"sendMessage",
"(",
"array",
"(",
"$",
"event",
"->",
"getNickname",
"(",
")",
")",
",",
"'Available commands:'",
")",
";",
"$",
"this",
"->",
"commandsHolder",
"->",
"rewind",
"(",
")",
";",
"while",
"(",
"$",
"this",
"->",
"commandsHolder",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"commandsHolder",
"->",
"current",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"current",
"[",
"0",
"]",
"[",
"'command'",
"]",
")",
")",
"{",
"$",
"msg",
"=",
"$",
"this",
"->",
"commandPrefix",
".",
"' '",
".",
"$",
"current",
"[",
"0",
"]",
"[",
"'command'",
"]",
".",
"(",
"isset",
"(",
"$",
"current",
"[",
"0",
"]",
"[",
"'arguments'",
"]",
")",
"?",
"' '",
".",
"$",
"current",
"[",
"0",
"]",
"[",
"'arguments'",
"]",
":",
"''",
")",
".",
"(",
"isset",
"(",
"$",
"current",
"[",
"0",
"]",
"[",
"'help'",
"]",
")",
"?",
"' : '",
".",
"$",
"current",
"[",
"0",
"]",
"[",
"'help'",
"]",
":",
"''",
")",
";",
"$",
"this",
"->",
"sendMessage",
"(",
"array",
"(",
"$",
"event",
"->",
"getNickname",
"(",
")",
")",
",",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"commandsHolder",
"->",
"next",
"(",
")",
";",
"}",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/whisller/IrcBotBundle/blob/d8bcafc1599cbbc7756b0a59f51ee988a2de0f2e/EventListener/Plugins/Commands/HelpCommandListener.php#L37-L53
|
lmammino/e-foundation
|
src/Cart/Model/CartItemAdjustment.php
|
CartItemAdjustment.setAdjustable
|
public function setAdjustable(AdjustableInterface $adjustable = null)
{
$this->adjustable = $this->cartItem = $adjustable;
return $this;
}
|
php
|
public function setAdjustable(AdjustableInterface $adjustable = null)
{
$this->adjustable = $this->cartItem = $adjustable;
return $this;
}
|
[
"public",
"function",
"setAdjustable",
"(",
"AdjustableInterface",
"$",
"adjustable",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"adjustable",
"=",
"$",
"this",
"->",
"cartItem",
"=",
"$",
"adjustable",
";",
"return",
"$",
"this",
";",
"}"
] |
{@inheritDoc}
|
[
"{"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Cart/Model/CartItemAdjustment.php#L39-L44
|
barebone-php/barebone-core
|
lib/Log.php
|
Log.instance
|
public static function instance()
{
if (null === self::$_instance) {
$logger = new Monolog(Config::read('app.id'));
$file_handler = new StreamHandler(self::getFilepath());
$logger->pushHandler($file_handler);
self::$_instance = $logger;
}
return self::$_instance;
}
|
php
|
public static function instance()
{
if (null === self::$_instance) {
$logger = new Monolog(Config::read('app.id'));
$file_handler = new StreamHandler(self::getFilepath());
$logger->pushHandler($file_handler);
self::$_instance = $logger;
}
return self::$_instance;
}
|
[
"public",
"static",
"function",
"instance",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"self",
"::",
"$",
"_instance",
")",
"{",
"$",
"logger",
"=",
"new",
"Monolog",
"(",
"Config",
"::",
"read",
"(",
"'app.id'",
")",
")",
";",
"$",
"file_handler",
"=",
"new",
"StreamHandler",
"(",
"self",
"::",
"getFilepath",
"(",
")",
")",
";",
"$",
"logger",
"->",
"pushHandler",
"(",
"$",
"file_handler",
")",
";",
"self",
"::",
"$",
"_instance",
"=",
"$",
"logger",
";",
"}",
"return",
"self",
"::",
"$",
"_instance",
";",
"}"
] |
Instantiate Monolog
@return Monolog
|
[
"Instantiate",
"Monolog"
] |
train
|
https://github.com/barebone-php/barebone-core/blob/7fda3a62d5fa103cdc4d2d34e1adf8f3ccbfe2bc/lib/Log.php#L46-L56
|
steeffeen/FancyManiaLinks
|
FML/Script/Features/PlayerProfile.php
|
PlayerProfile.setControl
|
public function setControl(Control $control)
{
$control->checkId();
if ($control instanceof Scriptable) {
$control->setScriptEvents(true);
}
$this->control = $control;
return $this;
}
|
php
|
public function setControl(Control $control)
{
$control->checkId();
if ($control instanceof Scriptable) {
$control->setScriptEvents(true);
}
$this->control = $control;
return $this;
}
|
[
"public",
"function",
"setControl",
"(",
"Control",
"$",
"control",
")",
"{",
"$",
"control",
"->",
"checkId",
"(",
")",
";",
"if",
"(",
"$",
"control",
"instanceof",
"Scriptable",
")",
"{",
"$",
"control",
"->",
"setScriptEvents",
"(",
"true",
")",
";",
"}",
"$",
"this",
"->",
"control",
"=",
"$",
"control",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the Profile Control
@api
@param Control $control Profile Control
@return static
|
[
"Set",
"the",
"Profile",
"Control"
] |
train
|
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/PlayerProfile.php#L99-L107
|
steeffeen/FancyManiaLinks
|
FML/Script/Features/PlayerProfile.php
|
PlayerProfile.getScriptText
|
protected function getScriptText()
{
$login = Builder::escapeText($this->login);
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId());
return "
if (Event.Control.ControlId == {$controlId}) {
ShowProfile({$login});
}";
}
// Other events
return "
ShowProfile({$login});";
}
|
php
|
protected function getScriptText()
{
$login = Builder::escapeText($this->login);
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId());
return "
if (Event.Control.ControlId == {$controlId}) {
ShowProfile({$login});
}";
}
// Other events
return "
ShowProfile({$login});";
}
|
[
"protected",
"function",
"getScriptText",
"(",
")",
"{",
"$",
"login",
"=",
"Builder",
"::",
"escapeText",
"(",
"$",
"this",
"->",
"login",
")",
";",
"if",
"(",
"$",
"this",
"->",
"control",
")",
"{",
"// Control event",
"$",
"controlId",
"=",
"Builder",
"::",
"escapeText",
"(",
"$",
"this",
"->",
"control",
"->",
"getId",
"(",
")",
")",
";",
"return",
"\"\nif (Event.Control.ControlId == {$controlId}) {\n\tShowProfile({$login});\n}\"",
";",
"}",
"// Other events",
"return",
"\"\nShowProfile({$login});\"",
";",
"}"
] |
Get the script text
@return string
|
[
"Get",
"the",
"script",
"text"
] |
train
|
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/PlayerProfile.php#L147-L163
|
fond-of/spryker-brand
|
src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php
|
BrandRepository.getBrandCollection
|
public function getBrandCollection(BrandCollectionTransfer $brandCollectionTransfer): BrandCollectionTransfer
{
$brandQuery = $this->getFactory()
->createBrandQuery();
$brandQuery = $this->applyFilterToQuery($brandQuery, $brandCollectionTransfer->getFilter());
$brandQuery = $this->applyPagination($brandQuery, $brandCollectionTransfer->getPagination());
$brandQuery->setFormatter(ArrayFormatter::class);
$this->hydrateBrandListWithBrands($brandCollectionTransfer, $brandQuery->find()->getData());
return $brandCollectionTransfer;
}
|
php
|
public function getBrandCollection(BrandCollectionTransfer $brandCollectionTransfer): BrandCollectionTransfer
{
$brandQuery = $this->getFactory()
->createBrandQuery();
$brandQuery = $this->applyFilterToQuery($brandQuery, $brandCollectionTransfer->getFilter());
$brandQuery = $this->applyPagination($brandQuery, $brandCollectionTransfer->getPagination());
$brandQuery->setFormatter(ArrayFormatter::class);
$this->hydrateBrandListWithBrands($brandCollectionTransfer, $brandQuery->find()->getData());
return $brandCollectionTransfer;
}
|
[
"public",
"function",
"getBrandCollection",
"(",
"BrandCollectionTransfer",
"$",
"brandCollectionTransfer",
")",
":",
"BrandCollectionTransfer",
"{",
"$",
"brandQuery",
"=",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"createBrandQuery",
"(",
")",
";",
"$",
"brandQuery",
"=",
"$",
"this",
"->",
"applyFilterToQuery",
"(",
"$",
"brandQuery",
",",
"$",
"brandCollectionTransfer",
"->",
"getFilter",
"(",
")",
")",
";",
"$",
"brandQuery",
"=",
"$",
"this",
"->",
"applyPagination",
"(",
"$",
"brandQuery",
",",
"$",
"brandCollectionTransfer",
"->",
"getPagination",
"(",
")",
")",
";",
"$",
"brandQuery",
"->",
"setFormatter",
"(",
"ArrayFormatter",
"::",
"class",
")",
";",
"$",
"this",
"->",
"hydrateBrandListWithBrands",
"(",
"$",
"brandCollectionTransfer",
",",
"$",
"brandQuery",
"->",
"find",
"(",
")",
"->",
"getData",
"(",
")",
")",
";",
"return",
"$",
"brandCollectionTransfer",
";",
"}"
] |
@param \Generated\Shared\Transfer\BrandCollectionTransfer $brandCollectionTransfer
@return \Generated\Shared\Transfer\BrandCollectionTransfer
|
[
"@param",
"\\",
"Generated",
"\\",
"Shared",
"\\",
"Transfer",
"\\",
"BrandCollectionTransfer",
"$brandCollectionTransfer"
] |
train
|
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php#L26-L37
|
fond-of/spryker-brand
|
src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php
|
BrandRepository.findBrandByName
|
public function findBrandByName(string $name): ?BrandTransfer
{
$spyBrand = $this->getFactory()
->createBrandQuery()
->filterByName($name)
->findOne();
if ($spyBrand === null) {
return null;
}
$brand = (new BrandTransfer())->fromArray(
$spyBrand->toArray(),
true
);
return $brand;
}
|
php
|
public function findBrandByName(string $name): ?BrandTransfer
{
$spyBrand = $this->getFactory()
->createBrandQuery()
->filterByName($name)
->findOne();
if ($spyBrand === null) {
return null;
}
$brand = (new BrandTransfer())->fromArray(
$spyBrand->toArray(),
true
);
return $brand;
}
|
[
"public",
"function",
"findBrandByName",
"(",
"string",
"$",
"name",
")",
":",
"?",
"BrandTransfer",
"{",
"$",
"spyBrand",
"=",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"createBrandQuery",
"(",
")",
"->",
"filterByName",
"(",
"$",
"name",
")",
"->",
"findOne",
"(",
")",
";",
"if",
"(",
"$",
"spyBrand",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"brand",
"=",
"(",
"new",
"BrandTransfer",
"(",
")",
")",
"->",
"fromArray",
"(",
"$",
"spyBrand",
"->",
"toArray",
"(",
")",
",",
"true",
")",
";",
"return",
"$",
"brand",
";",
"}"
] |
@param string $name
@return \Generated\Shared\Transfer\BrandTransfer|null
|
[
"@param",
"string",
"$name"
] |
train
|
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php#L44-L61
|
fond-of/spryker-brand
|
src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php
|
BrandRepository.applyFilterToQuery
|
protected function applyFilterToQuery(FosBrandQuery $fosBrandQuery, ?FilterTransfer $filterTransfer): FosBrandQuery
{
$criteria = new Criteria();
if ($filterTransfer !== null) {
$criteria = (new PropelFilterCriteria($filterTransfer))
->toCriteria();
}
$fosBrandQuery->mergeWith($criteria);
return $fosBrandQuery;
}
|
php
|
protected function applyFilterToQuery(FosBrandQuery $fosBrandQuery, ?FilterTransfer $filterTransfer): FosBrandQuery
{
$criteria = new Criteria();
if ($filterTransfer !== null) {
$criteria = (new PropelFilterCriteria($filterTransfer))
->toCriteria();
}
$fosBrandQuery->mergeWith($criteria);
return $fosBrandQuery;
}
|
[
"protected",
"function",
"applyFilterToQuery",
"(",
"FosBrandQuery",
"$",
"fosBrandQuery",
",",
"?",
"FilterTransfer",
"$",
"filterTransfer",
")",
":",
"FosBrandQuery",
"{",
"$",
"criteria",
"=",
"new",
"Criteria",
"(",
")",
";",
"if",
"(",
"$",
"filterTransfer",
"!==",
"null",
")",
"{",
"$",
"criteria",
"=",
"(",
"new",
"PropelFilterCriteria",
"(",
"$",
"filterTransfer",
")",
")",
"->",
"toCriteria",
"(",
")",
";",
"}",
"$",
"fosBrandQuery",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"return",
"$",
"fosBrandQuery",
";",
"}"
] |
@param \Orm\Zed\Brand\Persistence\FosBrandQuery $fosBrandQuery
@param \Generated\Shared\Transfer\FilterTransfer|null $filterTransfer
@return \Orm\Zed\Brand\Persistence\FosBrandQuery
|
[
"@param",
"\\",
"Orm",
"\\",
"Zed",
"\\",
"Brand",
"\\",
"Persistence",
"\\",
"FosBrandQuery",
"$fosBrandQuery",
"@param",
"\\",
"Generated",
"\\",
"Shared",
"\\",
"Transfer",
"\\",
"FilterTransfer|null",
"$filterTransfer"
] |
train
|
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php#L69-L80
|
fond-of/spryker-brand
|
src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php
|
BrandRepository.applyPagination
|
protected function applyPagination(FosBrandQuery $fosBrandQuery, ?PaginationTransfer $paginationTransfer = null): FosBrandQuery
{
if (empty($paginationTransfer)) {
return $fosBrandQuery;
}
$page = $paginationTransfer
->requirePage()
->getPage();
$maxPerPage = $paginationTransfer
->requireMaxPerPage()
->getMaxPerPage();
$paginationModel = $fosBrandQuery->paginate($page, $maxPerPage);
$paginationTransfer->setNbResults($paginationModel->getNbResults());
$paginationTransfer->setFirstIndex($paginationModel->getFirstIndex());
$paginationTransfer->setLastIndex($paginationModel->getLastIndex());
$paginationTransfer->setFirstPage($paginationModel->getFirstPage());
$paginationTransfer->setLastPage($paginationModel->getLastPage());
$paginationTransfer->setNextPage($paginationModel->getNextPage());
$paginationTransfer->setPreviousPage($paginationModel->getPreviousPage());
return $paginationModel->getQuery();
}
|
php
|
protected function applyPagination(FosBrandQuery $fosBrandQuery, ?PaginationTransfer $paginationTransfer = null): FosBrandQuery
{
if (empty($paginationTransfer)) {
return $fosBrandQuery;
}
$page = $paginationTransfer
->requirePage()
->getPage();
$maxPerPage = $paginationTransfer
->requireMaxPerPage()
->getMaxPerPage();
$paginationModel = $fosBrandQuery->paginate($page, $maxPerPage);
$paginationTransfer->setNbResults($paginationModel->getNbResults());
$paginationTransfer->setFirstIndex($paginationModel->getFirstIndex());
$paginationTransfer->setLastIndex($paginationModel->getLastIndex());
$paginationTransfer->setFirstPage($paginationModel->getFirstPage());
$paginationTransfer->setLastPage($paginationModel->getLastPage());
$paginationTransfer->setNextPage($paginationModel->getNextPage());
$paginationTransfer->setPreviousPage($paginationModel->getPreviousPage());
return $paginationModel->getQuery();
}
|
[
"protected",
"function",
"applyPagination",
"(",
"FosBrandQuery",
"$",
"fosBrandQuery",
",",
"?",
"PaginationTransfer",
"$",
"paginationTransfer",
"=",
"null",
")",
":",
"FosBrandQuery",
"{",
"if",
"(",
"empty",
"(",
"$",
"paginationTransfer",
")",
")",
"{",
"return",
"$",
"fosBrandQuery",
";",
"}",
"$",
"page",
"=",
"$",
"paginationTransfer",
"->",
"requirePage",
"(",
")",
"->",
"getPage",
"(",
")",
";",
"$",
"maxPerPage",
"=",
"$",
"paginationTransfer",
"->",
"requireMaxPerPage",
"(",
")",
"->",
"getMaxPerPage",
"(",
")",
";",
"$",
"paginationModel",
"=",
"$",
"fosBrandQuery",
"->",
"paginate",
"(",
"$",
"page",
",",
"$",
"maxPerPage",
")",
";",
"$",
"paginationTransfer",
"->",
"setNbResults",
"(",
"$",
"paginationModel",
"->",
"getNbResults",
"(",
")",
")",
";",
"$",
"paginationTransfer",
"->",
"setFirstIndex",
"(",
"$",
"paginationModel",
"->",
"getFirstIndex",
"(",
")",
")",
";",
"$",
"paginationTransfer",
"->",
"setLastIndex",
"(",
"$",
"paginationModel",
"->",
"getLastIndex",
"(",
")",
")",
";",
"$",
"paginationTransfer",
"->",
"setFirstPage",
"(",
"$",
"paginationModel",
"->",
"getFirstPage",
"(",
")",
")",
";",
"$",
"paginationTransfer",
"->",
"setLastPage",
"(",
"$",
"paginationModel",
"->",
"getLastPage",
"(",
")",
")",
";",
"$",
"paginationTransfer",
"->",
"setNextPage",
"(",
"$",
"paginationModel",
"->",
"getNextPage",
"(",
")",
")",
";",
"$",
"paginationTransfer",
"->",
"setPreviousPage",
"(",
"$",
"paginationModel",
"->",
"getPreviousPage",
"(",
")",
")",
";",
"return",
"$",
"paginationModel",
"->",
"getQuery",
"(",
")",
";",
"}"
] |
@param \Orm\Zed\Brand\Persistence\FosBrandQuery $fosBrandQuery
@param \Generated\Shared\Transfer\PaginationTransfer|null $paginationTransfer
@return \Orm\Zed\Brand\Persistence\FosBrandQuery
|
[
"@param",
"\\",
"Orm",
"\\",
"Zed",
"\\",
"Brand",
"\\",
"Persistence",
"\\",
"FosBrandQuery",
"$fosBrandQuery",
"@param",
"\\",
"Generated",
"\\",
"Shared",
"\\",
"Transfer",
"\\",
"PaginationTransfer|null",
"$paginationTransfer"
] |
train
|
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php#L88-L113
|
fond-of/spryker-brand
|
src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php
|
BrandRepository.hydrateBrandListWithBrands
|
protected function hydrateBrandListWithBrands(BrandCollectionTransfer $brandListTransfer, array $brands): void
{
$brandCollection = new ArrayObject();
foreach ($brands as $brand) {
$brandCollection->append(
$this->getFactory()
->createBrandMapper()
->mapBrandEntityToBrand($brand)
);
}
$brandListTransfer->setBrands($brandCollection);
}
|
php
|
protected function hydrateBrandListWithBrands(BrandCollectionTransfer $brandListTransfer, array $brands): void
{
$brandCollection = new ArrayObject();
foreach ($brands as $brand) {
$brandCollection->append(
$this->getFactory()
->createBrandMapper()
->mapBrandEntityToBrand($brand)
);
}
$brandListTransfer->setBrands($brandCollection);
}
|
[
"protected",
"function",
"hydrateBrandListWithBrands",
"(",
"BrandCollectionTransfer",
"$",
"brandListTransfer",
",",
"array",
"$",
"brands",
")",
":",
"void",
"{",
"$",
"brandCollection",
"=",
"new",
"ArrayObject",
"(",
")",
";",
"foreach",
"(",
"$",
"brands",
"as",
"$",
"brand",
")",
"{",
"$",
"brandCollection",
"->",
"append",
"(",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"createBrandMapper",
"(",
")",
"->",
"mapBrandEntityToBrand",
"(",
"$",
"brand",
")",
")",
";",
"}",
"$",
"brandListTransfer",
"->",
"setBrands",
"(",
"$",
"brandCollection",
")",
";",
"}"
] |
@param \Generated\Shared\Transfer\BrandCollectionTransfer $brandListTransfer
@param array $brands
@return void
|
[
"@param",
"\\",
"Generated",
"\\",
"Shared",
"\\",
"Transfer",
"\\",
"BrandCollectionTransfer",
"$brandListTransfer",
"@param",
"array",
"$brands"
] |
train
|
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php#L121-L134
|
fond-of/spryker-brand
|
src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php
|
BrandRepository.getActiveBrands
|
public function getActiveBrands(): BrandCollectionTransfer
{
$query = $this->getFactory()
->createBrandQuery()
->filterByIsActive(true);
$brandEntityCollectionTransfer = $this->buildQueryFromCriteria($query)->find();
return $this->getFactory()->createBrandMapper()->mapCollectionTransfer($brandEntityCollectionTransfer);
}
|
php
|
public function getActiveBrands(): BrandCollectionTransfer
{
$query = $this->getFactory()
->createBrandQuery()
->filterByIsActive(true);
$brandEntityCollectionTransfer = $this->buildQueryFromCriteria($query)->find();
return $this->getFactory()->createBrandMapper()->mapCollectionTransfer($brandEntityCollectionTransfer);
}
|
[
"public",
"function",
"getActiveBrands",
"(",
")",
":",
"BrandCollectionTransfer",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"createBrandQuery",
"(",
")",
"->",
"filterByIsActive",
"(",
"true",
")",
";",
"$",
"brandEntityCollectionTransfer",
"=",
"$",
"this",
"->",
"buildQueryFromCriteria",
"(",
"$",
"query",
")",
"->",
"find",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"createBrandMapper",
"(",
")",
"->",
"mapCollectionTransfer",
"(",
"$",
"brandEntityCollectionTransfer",
")",
";",
"}"
] |
@throws
@return \Generated\Shared\Transfer\BrandCollectionTransfer
|
[
"@throws"
] |
train
|
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Persistence/BrandRepository.php#L141-L150
|
xinix-technology/norm
|
src/Norm/Cursor/SQLServerCursor.php
|
SQLServerCursor.count
|
public function count($foundOnly = false)
{
$data = array();
$sql = $this->connection->getDialect()->grammarCount($this, $foundOnly, $data);
$statement = $this->connection->prepare($sql,$data);
$count_data = mssql_query($statement,$this->connection->getRaw());
$count = mssql_num_rows($count_data);
mssql_free_result($count_data);
return intval($count);
}
|
php
|
public function count($foundOnly = false)
{
$data = array();
$sql = $this->connection->getDialect()->grammarCount($this, $foundOnly, $data);
$statement = $this->connection->prepare($sql,$data);
$count_data = mssql_query($statement,$this->connection->getRaw());
$count = mssql_num_rows($count_data);
mssql_free_result($count_data);
return intval($count);
}
|
[
"public",
"function",
"count",
"(",
"$",
"foundOnly",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"connection",
"->",
"getDialect",
"(",
")",
"->",
"grammarCount",
"(",
"$",
"this",
",",
"$",
"foundOnly",
",",
"$",
"data",
")",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"sql",
",",
"$",
"data",
")",
";",
"$",
"count_data",
"=",
"mssql_query",
"(",
"$",
"statement",
",",
"$",
"this",
"->",
"connection",
"->",
"getRaw",
"(",
")",
")",
";",
"$",
"count",
"=",
"mssql_num_rows",
"(",
"$",
"count_data",
")",
";",
"mssql_free_result",
"(",
"$",
"count_data",
")",
";",
"return",
"intval",
"(",
"$",
"count",
")",
";",
"}"
] |
{@inheritDoc}
|
[
"{"
] |
train
|
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/SQLServerCursor.php#L44-L59
|
xinix-technology/norm
|
src/Norm/Cursor/SQLServerCursor.php
|
SQLServerCursor.getStatement
|
public function getStatement($type = null)
{
// $this->buffer = array();
// $this->next = false;
$sql = "SELECT * FROM [{$this->collection->getName()}]";
$wheres = array();
$data = array();
foreach ($this->criteria as $key => $value) {
$wheres[] = $a= $this->connection->getDialect()->grammarExpression(
$key,
$value,
$this->collection,
$data
);
}
if (!empty($wheres)) {
$sql .= ' WHERE '.implode(' AND ', $wheres);
}
if (isset($this->sorts)) {
$sorts = array();
foreach ($this->sorts as $key => $value) {
if ($value == 1) {
$op = ' ASC';
} else {
$op = ' DESC';
}
$sorts[] = $key.$op;
}
if (!empty($sorts)) {
$sql .= ' ORDER BY '.implode(',', $sorts);
}
}else{
$sql .= ' ORDER BY ID';
}
if (isset($this->limit) || isset($this->skip)) {
$sql .= ' OFFSET '.($this->skip ?: 0).' ROWS FETCH NEXT '. ($this->limit ?: -1) .' ROWS ONLY';
// $sql .= ' LIMIT '.($this->limit ?: -1).' OFFSET '.($this->skip ?: 0);
}
$query = $this->connection->prepare($sql,$data);
$statement = mssql_query($query);
$this->rows = array();
while ($row = mssql_fetch_assoc($statement)) {
$this->rows[] = $row;
}
mssql_free_result($statement);
$this->index = -1;
}
|
php
|
public function getStatement($type = null)
{
// $this->buffer = array();
// $this->next = false;
$sql = "SELECT * FROM [{$this->collection->getName()}]";
$wheres = array();
$data = array();
foreach ($this->criteria as $key => $value) {
$wheres[] = $a= $this->connection->getDialect()->grammarExpression(
$key,
$value,
$this->collection,
$data
);
}
if (!empty($wheres)) {
$sql .= ' WHERE '.implode(' AND ', $wheres);
}
if (isset($this->sorts)) {
$sorts = array();
foreach ($this->sorts as $key => $value) {
if ($value == 1) {
$op = ' ASC';
} else {
$op = ' DESC';
}
$sorts[] = $key.$op;
}
if (!empty($sorts)) {
$sql .= ' ORDER BY '.implode(',', $sorts);
}
}else{
$sql .= ' ORDER BY ID';
}
if (isset($this->limit) || isset($this->skip)) {
$sql .= ' OFFSET '.($this->skip ?: 0).' ROWS FETCH NEXT '. ($this->limit ?: -1) .' ROWS ONLY';
// $sql .= ' LIMIT '.($this->limit ?: -1).' OFFSET '.($this->skip ?: 0);
}
$query = $this->connection->prepare($sql,$data);
$statement = mssql_query($query);
$this->rows = array();
while ($row = mssql_fetch_assoc($statement)) {
$this->rows[] = $row;
}
mssql_free_result($statement);
$this->index = -1;
}
|
[
"public",
"function",
"getStatement",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"// $this->buffer = array();",
"// $this->next = false;",
"$",
"sql",
"=",
"\"SELECT * FROM [{$this->collection->getName()}]\"",
";",
"$",
"wheres",
"=",
"array",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"criteria",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"wheres",
"[",
"]",
"=",
"$",
"a",
"=",
"$",
"this",
"->",
"connection",
"->",
"getDialect",
"(",
")",
"->",
"grammarExpression",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"collection",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"wheres",
")",
")",
"{",
"$",
"sql",
".=",
"' WHERE '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"wheres",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"sorts",
")",
")",
"{",
"$",
"sorts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"sorts",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"op",
"=",
"' ASC'",
";",
"}",
"else",
"{",
"$",
"op",
"=",
"' DESC'",
";",
"}",
"$",
"sorts",
"[",
"]",
"=",
"$",
"key",
".",
"$",
"op",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"sorts",
")",
")",
"{",
"$",
"sql",
".=",
"' ORDER BY '",
".",
"implode",
"(",
"','",
",",
"$",
"sorts",
")",
";",
"}",
"}",
"else",
"{",
"$",
"sql",
".=",
"' ORDER BY ID'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"limit",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"skip",
")",
")",
"{",
"$",
"sql",
".=",
"' OFFSET '",
".",
"(",
"$",
"this",
"->",
"skip",
"?",
":",
"0",
")",
".",
"' ROWS FETCH NEXT '",
".",
"(",
"$",
"this",
"->",
"limit",
"?",
":",
"-",
"1",
")",
".",
"' ROWS ONLY'",
";",
"// $sql .= ' LIMIT '.($this->limit ?: -1).' OFFSET '.($this->skip ?: 0);",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"sql",
",",
"$",
"data",
")",
";",
"$",
"statement",
"=",
"mssql_query",
"(",
"$",
"query",
")",
";",
"$",
"this",
"->",
"rows",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"mssql_fetch_assoc",
"(",
"$",
"statement",
")",
")",
"{",
"$",
"this",
"->",
"rows",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"mssql_free_result",
"(",
"$",
"statement",
")",
";",
"$",
"this",
"->",
"index",
"=",
"-",
"1",
";",
"}"
] |
Get query statement of current cursor.
@param mixed $type
@return \PDOStatement
|
[
"Get",
"query",
"statement",
"of",
"current",
"cursor",
"."
] |
train
|
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/SQLServerCursor.php#L140-L206
|
xinix-technology/norm
|
src/Norm/Cursor/SQLServerCursor.php
|
SQLServerCursor.distinct
|
public function distinct($key)
{
$sql = $this->connection->getDialect()->grammarDistinct($this,$key);
$statement = $this->connection->getRaw()->prepare($sql);
$statement->execute(array());
$result = array();
while($row = $statement->fetch(\PDO::FETCH_ASSOC)){
$result[] = $row[$key];
}
return $result;
}
|
php
|
public function distinct($key)
{
$sql = $this->connection->getDialect()->grammarDistinct($this,$key);
$statement = $this->connection->getRaw()->prepare($sql);
$statement->execute(array());
$result = array();
while($row = $statement->fetch(\PDO::FETCH_ASSOC)){
$result[] = $row[$key];
}
return $result;
}
|
[
"public",
"function",
"distinct",
"(",
"$",
"key",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"connection",
"->",
"getDialect",
"(",
")",
"->",
"grammarDistinct",
"(",
"$",
"this",
",",
"$",
"key",
")",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"connection",
"->",
"getRaw",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"array",
"(",
")",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"row",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
{@inheritDoc}
|
[
"{"
] |
train
|
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/SQLServerCursor.php#L211-L223
|
Double-Opt-in/php-client-api
|
src/Security/SlowAES/cryptoHelpers.php
|
cryptoHelpers.toHex
|
public static function toHex($args){
if(func_num_args() != 1 || !is_array($args)){
$args = func_get_args();
}
$ret = '';
for($i = 0; $i < count($args) ;$i++)
$ret .= sprintf('%02x', $args[$i]);
return $ret;
}
|
php
|
public static function toHex($args){
if(func_num_args() != 1 || !is_array($args)){
$args = func_get_args();
}
$ret = '';
for($i = 0; $i < count($args) ;$i++)
$ret .= sprintf('%02x', $args[$i]);
return $ret;
}
|
[
"public",
"static",
"function",
"toHex",
"(",
"$",
"args",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"!=",
"1",
"||",
"!",
"is_array",
"(",
"$",
"args",
")",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"}",
"$",
"ret",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"args",
")",
";",
"$",
"i",
"++",
")",
"$",
"ret",
".=",
"sprintf",
"(",
"'%02x'",
",",
"$",
"args",
"[",
"$",
"i",
"]",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
convert a number array to a hex string
|
[
"convert",
"a",
"number",
"array",
"to",
"a",
"hex",
"string"
] |
train
|
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Security/SlowAES/cryptoHelpers.php#L34-L42
|
Double-Opt-in/php-client-api
|
src/Security/SlowAES/cryptoHelpers.php
|
cryptoHelpers.toNumbers
|
public static function toNumbers($s){
$ret = array();
for($i=0; $i<strlen($s); $i+=2){
$ret[] = hexdec(substr($s, $i, 2));
}
return $ret;
}
|
php
|
public static function toNumbers($s){
$ret = array();
for($i=0; $i<strlen($s); $i+=2){
$ret[] = hexdec(substr($s, $i, 2));
}
return $ret;
}
|
[
"public",
"static",
"function",
"toNumbers",
"(",
"$",
"s",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"s",
")",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"s",
",",
"$",
"i",
",",
"2",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
convert a hex string to a number array
|
[
"convert",
"a",
"hex",
"string",
"to",
"a",
"number",
"array"
] |
train
|
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Security/SlowAES/cryptoHelpers.php#L45-L51
|
Double-Opt-in/php-client-api
|
src/Security/SlowAES/cryptoHelpers.php
|
cryptoHelpers.getRandom
|
public static function getRandom($min,$max){
if($min === null)
$min = 0;
if($max === null)
$max = 1;
return mt_rand($min, $max);
}
|
php
|
public static function getRandom($min,$max){
if($min === null)
$min = 0;
if($max === null)
$max = 1;
return mt_rand($min, $max);
}
|
[
"public",
"static",
"function",
"getRandom",
"(",
"$",
"min",
",",
"$",
"max",
")",
"{",
"if",
"(",
"$",
"min",
"===",
"null",
")",
"$",
"min",
"=",
"0",
";",
"if",
"(",
"$",
"max",
"===",
"null",
")",
"$",
"max",
"=",
"1",
";",
"return",
"mt_rand",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}"
] |
get a random number in the range [min,max]
|
[
"get",
"a",
"random",
"number",
"in",
"the",
"range",
"[",
"min",
"max",
"]"
] |
train
|
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Security/SlowAES/cryptoHelpers.php#L54-L60
|
phpmob/changmin
|
src/PhpMob/WidgetBundle/Controller/WidgetController.php
|
WidgetController.renderAction
|
public function renderAction(Request $request)
{
$twig = $this->get('twig');
$widget = $request->get('widget', []);
$widgetName = null;
if (!$notFound = empty($widget['name'])) {
$widgetName = $this->get('phpmob.widget.registry')->getWidgetClass($widget['name']);
$notFound = !$twig->hasExtension($widgetName);
}
if ($notFound) {
// show empty response?
throw new NotFoundHttpException(sprintf("Not found widget: %s", $widgetName));
}
/** @var WidgetInterface $widgetExtension */
$widgetExtension = $twig->getExtension($widgetName);
if (!$widgetExtension instanceof WidgetInterface) {
// again! show an empty?
throw new NotFoundHttpException(sprintf("Invalid widget type: %s", $widgetName));
}
$options = isset($widget['options']) ? $widget['options'] : [];
$options['visibility'] = 'away';
// convert data type
array_walk_recursive($options, function (&$value) {
if (in_array(strtolower($value), ['true', 'false'])) {
$value = strtolower($value) === 'true' ? true : false;
}
if (is_numeric($value)) {
$value = (int) $value;
}
});
return new Response($widgetExtension->render($twig, $options));
}
|
php
|
public function renderAction(Request $request)
{
$twig = $this->get('twig');
$widget = $request->get('widget', []);
$widgetName = null;
if (!$notFound = empty($widget['name'])) {
$widgetName = $this->get('phpmob.widget.registry')->getWidgetClass($widget['name']);
$notFound = !$twig->hasExtension($widgetName);
}
if ($notFound) {
// show empty response?
throw new NotFoundHttpException(sprintf("Not found widget: %s", $widgetName));
}
/** @var WidgetInterface $widgetExtension */
$widgetExtension = $twig->getExtension($widgetName);
if (!$widgetExtension instanceof WidgetInterface) {
// again! show an empty?
throw new NotFoundHttpException(sprintf("Invalid widget type: %s", $widgetName));
}
$options = isset($widget['options']) ? $widget['options'] : [];
$options['visibility'] = 'away';
// convert data type
array_walk_recursive($options, function (&$value) {
if (in_array(strtolower($value), ['true', 'false'])) {
$value = strtolower($value) === 'true' ? true : false;
}
if (is_numeric($value)) {
$value = (int) $value;
}
});
return new Response($widgetExtension->render($twig, $options));
}
|
[
"public",
"function",
"renderAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"twig",
"=",
"$",
"this",
"->",
"get",
"(",
"'twig'",
")",
";",
"$",
"widget",
"=",
"$",
"request",
"->",
"get",
"(",
"'widget'",
",",
"[",
"]",
")",
";",
"$",
"widgetName",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"notFound",
"=",
"empty",
"(",
"$",
"widget",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"widgetName",
"=",
"$",
"this",
"->",
"get",
"(",
"'phpmob.widget.registry'",
")",
"->",
"getWidgetClass",
"(",
"$",
"widget",
"[",
"'name'",
"]",
")",
";",
"$",
"notFound",
"=",
"!",
"$",
"twig",
"->",
"hasExtension",
"(",
"$",
"widgetName",
")",
";",
"}",
"if",
"(",
"$",
"notFound",
")",
"{",
"// show empty response?",
"throw",
"new",
"NotFoundHttpException",
"(",
"sprintf",
"(",
"\"Not found widget: %s\"",
",",
"$",
"widgetName",
")",
")",
";",
"}",
"/** @var WidgetInterface $widgetExtension */",
"$",
"widgetExtension",
"=",
"$",
"twig",
"->",
"getExtension",
"(",
"$",
"widgetName",
")",
";",
"if",
"(",
"!",
"$",
"widgetExtension",
"instanceof",
"WidgetInterface",
")",
"{",
"// again! show an empty?",
"throw",
"new",
"NotFoundHttpException",
"(",
"sprintf",
"(",
"\"Invalid widget type: %s\"",
",",
"$",
"widgetName",
")",
")",
";",
"}",
"$",
"options",
"=",
"isset",
"(",
"$",
"widget",
"[",
"'options'",
"]",
")",
"?",
"$",
"widget",
"[",
"'options'",
"]",
":",
"[",
"]",
";",
"$",
"options",
"[",
"'visibility'",
"]",
"=",
"'away'",
";",
"// convert data type",
"array_walk_recursive",
"(",
"$",
"options",
",",
"function",
"(",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"value",
")",
",",
"[",
"'true'",
",",
"'false'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"strtolower",
"(",
"$",
"value",
")",
"===",
"'true'",
"?",
"true",
":",
"false",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"}",
"}",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"widgetExtension",
"->",
"render",
"(",
"$",
"twig",
",",
"$",
"options",
")",
")",
";",
"}"
] |
@param Request $request
@return Response
|
[
"@param",
"Request",
"$request"
] |
train
|
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/WidgetBundle/Controller/WidgetController.php#L32-L71
|
yuncms/framework
|
src/user/models/SettingsForm.php
|
SettingsForm.save
|
public function save()
{
if ($this->validate()) {
$this->user->scenario = 'settings';
$this->user->username = $this->username;
$this->user->nickname = $this->nickname;
$this->user->password = $this->new_password;
if ($this->email == $this->user->email && $this->user->unconfirmed_email != null) {
$this->user->unconfirmed_email = null;
} elseif ($this->email != $this->user->email) {
switch (Yii::$app->settings->get('emailChangeStrategy','user')) {
case UserSettings::STRATEGY_INSECURE:
$this->insecureEmailChange();
break;
case UserSettings::STRATEGY_DEFAULT:
$this->defaultEmailChange();
break;
case UserSettings::STRATEGY_SECURE:
$this->secureEmailChange();
break;
default:
throw new \OutOfBoundsException('Invalid email changing strategy');
}
}
return $this->user->save();
}
return false;
}
|
php
|
public function save()
{
if ($this->validate()) {
$this->user->scenario = 'settings';
$this->user->username = $this->username;
$this->user->nickname = $this->nickname;
$this->user->password = $this->new_password;
if ($this->email == $this->user->email && $this->user->unconfirmed_email != null) {
$this->user->unconfirmed_email = null;
} elseif ($this->email != $this->user->email) {
switch (Yii::$app->settings->get('emailChangeStrategy','user')) {
case UserSettings::STRATEGY_INSECURE:
$this->insecureEmailChange();
break;
case UserSettings::STRATEGY_DEFAULT:
$this->defaultEmailChange();
break;
case UserSettings::STRATEGY_SECURE:
$this->secureEmailChange();
break;
default:
throw new \OutOfBoundsException('Invalid email changing strategy');
}
}
return $this->user->save();
}
return false;
}
|
[
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"$",
"this",
"->",
"user",
"->",
"scenario",
"=",
"'settings'",
";",
"$",
"this",
"->",
"user",
"->",
"username",
"=",
"$",
"this",
"->",
"username",
";",
"$",
"this",
"->",
"user",
"->",
"nickname",
"=",
"$",
"this",
"->",
"nickname",
";",
"$",
"this",
"->",
"user",
"->",
"password",
"=",
"$",
"this",
"->",
"new_password",
";",
"if",
"(",
"$",
"this",
"->",
"email",
"==",
"$",
"this",
"->",
"user",
"->",
"email",
"&&",
"$",
"this",
"->",
"user",
"->",
"unconfirmed_email",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"user",
"->",
"unconfirmed_email",
"=",
"null",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"email",
"!=",
"$",
"this",
"->",
"user",
"->",
"email",
")",
"{",
"switch",
"(",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"'emailChangeStrategy'",
",",
"'user'",
")",
")",
"{",
"case",
"UserSettings",
"::",
"STRATEGY_INSECURE",
":",
"$",
"this",
"->",
"insecureEmailChange",
"(",
")",
";",
"break",
";",
"case",
"UserSettings",
"::",
"STRATEGY_DEFAULT",
":",
"$",
"this",
"->",
"defaultEmailChange",
"(",
")",
";",
"break",
";",
"case",
"UserSettings",
"::",
"STRATEGY_SECURE",
":",
"$",
"this",
"->",
"secureEmailChange",
"(",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"'Invalid email changing strategy'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"user",
"->",
"save",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Saves new account settings.
@return boolean
|
[
"Saves",
"new",
"account",
"settings",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/SettingsForm.php#L132-L159
|
yuncms/framework
|
src/user/models/SettingsForm.php
|
SettingsForm.insecureEmailChange
|
protected function insecureEmailChange()
{
$this->user->email = $this->email;
Yii::$app->session->setFlash('success', Yii::t('yuncms', 'Your email address has been changed'));
}
|
php
|
protected function insecureEmailChange()
{
$this->user->email = $this->email;
Yii::$app->session->setFlash('success', Yii::t('yuncms', 'Your email address has been changed'));
}
|
[
"protected",
"function",
"insecureEmailChange",
"(",
")",
"{",
"$",
"this",
"->",
"user",
"->",
"email",
"=",
"$",
"this",
"->",
"email",
";",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'success'",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Your email address has been changed'",
")",
")",
";",
"}"
] |
Changes user's email address to given without any confirmation.
|
[
"Changes",
"user",
"s",
"email",
"address",
"to",
"given",
"without",
"any",
"confirmation",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/SettingsForm.php#L164-L168
|
yuncms/framework
|
src/user/models/SettingsForm.php
|
SettingsForm.defaultEmailChange
|
protected function defaultEmailChange()
{
$this->user->unconfirmed_email = $this->email;
/** @var UserToken $token */
$token = new UserToken(['user_id' => $this->user->id, 'type' => UserToken::TYPE_CONFIRM_NEW_EMAIL]);
$token->save(false);
Yii::$app->sendMail($this->user->unconfirmed_email, Yii::t('yuncms', 'Confirm email change on {0}', Yii::$app->name), 'user/reconfirmation', ['user' => $this->user, 'token' => $token]);
Yii::$app->session->setFlash('info', Yii::t('yuncms', 'A confirmation message has been sent to your new email address'));
}
|
php
|
protected function defaultEmailChange()
{
$this->user->unconfirmed_email = $this->email;
/** @var UserToken $token */
$token = new UserToken(['user_id' => $this->user->id, 'type' => UserToken::TYPE_CONFIRM_NEW_EMAIL]);
$token->save(false);
Yii::$app->sendMail($this->user->unconfirmed_email, Yii::t('yuncms', 'Confirm email change on {0}', Yii::$app->name), 'user/reconfirmation', ['user' => $this->user, 'token' => $token]);
Yii::$app->session->setFlash('info', Yii::t('yuncms', 'A confirmation message has been sent to your new email address'));
}
|
[
"protected",
"function",
"defaultEmailChange",
"(",
")",
"{",
"$",
"this",
"->",
"user",
"->",
"unconfirmed_email",
"=",
"$",
"this",
"->",
"email",
";",
"/** @var UserToken $token */",
"$",
"token",
"=",
"new",
"UserToken",
"(",
"[",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"id",
",",
"'type'",
"=>",
"UserToken",
"::",
"TYPE_CONFIRM_NEW_EMAIL",
"]",
")",
";",
"$",
"token",
"->",
"save",
"(",
"false",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"sendMail",
"(",
"$",
"this",
"->",
"user",
"->",
"unconfirmed_email",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Confirm email change on {0}'",
",",
"Yii",
"::",
"$",
"app",
"->",
"name",
")",
",",
"'user/reconfirmation'",
",",
"[",
"'user'",
"=>",
"$",
"this",
"->",
"user",
",",
"'token'",
"=>",
"$",
"token",
"]",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'info'",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'A confirmation message has been sent to your new email address'",
")",
")",
";",
"}"
] |
Sends a confirmation message to user's email address with link to confirm changing of email.
|
[
"Sends",
"a",
"confirmation",
"message",
"to",
"user",
"s",
"email",
"address",
"with",
"link",
"to",
"confirm",
"changing",
"of",
"email",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/SettingsForm.php#L173-L181
|
yuncms/framework
|
src/user/models/SettingsForm.php
|
SettingsForm.secureEmailChange
|
protected function secureEmailChange()
{
$this->defaultEmailChange();
/** @var UserToken $token */
$token = new UserToken(['user_id' => $this->user->id, 'type' => UserToken::TYPE_CONFIRM_OLD_EMAIL]);
$token->save(false);
Yii::$app->sendMail($this->user->email, Yii::t('yuncms', 'Confirm email change on {0}', Yii::$app->name), 'user/reconfirmation', ['user' => $this->user, 'token' => $token]);
// unset flags if they exist
$this->user->flags &= ~User::NEW_EMAIL_CONFIRMED;
$this->user->flags &= ~User::OLD_EMAIL_CONFIRMED;
$this->user->save(false);
Yii::$app->session->setFlash('info', Yii::t('yuncms', 'We have sent confirmation links to both old and new email addresses. You must click both links to complete your request'));
}
|
php
|
protected function secureEmailChange()
{
$this->defaultEmailChange();
/** @var UserToken $token */
$token = new UserToken(['user_id' => $this->user->id, 'type' => UserToken::TYPE_CONFIRM_OLD_EMAIL]);
$token->save(false);
Yii::$app->sendMail($this->user->email, Yii::t('yuncms', 'Confirm email change on {0}', Yii::$app->name), 'user/reconfirmation', ['user' => $this->user, 'token' => $token]);
// unset flags if they exist
$this->user->flags &= ~User::NEW_EMAIL_CONFIRMED;
$this->user->flags &= ~User::OLD_EMAIL_CONFIRMED;
$this->user->save(false);
Yii::$app->session->setFlash('info', Yii::t('yuncms', 'We have sent confirmation links to both old and new email addresses. You must click both links to complete your request'));
}
|
[
"protected",
"function",
"secureEmailChange",
"(",
")",
"{",
"$",
"this",
"->",
"defaultEmailChange",
"(",
")",
";",
"/** @var UserToken $token */",
"$",
"token",
"=",
"new",
"UserToken",
"(",
"[",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"id",
",",
"'type'",
"=>",
"UserToken",
"::",
"TYPE_CONFIRM_OLD_EMAIL",
"]",
")",
";",
"$",
"token",
"->",
"save",
"(",
"false",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"sendMail",
"(",
"$",
"this",
"->",
"user",
"->",
"email",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Confirm email change on {0}'",
",",
"Yii",
"::",
"$",
"app",
"->",
"name",
")",
",",
"'user/reconfirmation'",
",",
"[",
"'user'",
"=>",
"$",
"this",
"->",
"user",
",",
"'token'",
"=>",
"$",
"token",
"]",
")",
";",
"// unset flags if they exist",
"$",
"this",
"->",
"user",
"->",
"flags",
"&=",
"~",
"User",
"::",
"NEW_EMAIL_CONFIRMED",
";",
"$",
"this",
"->",
"user",
"->",
"flags",
"&=",
"~",
"User",
"::",
"OLD_EMAIL_CONFIRMED",
";",
"$",
"this",
"->",
"user",
"->",
"save",
"(",
"false",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'info'",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'We have sent confirmation links to both old and new email addresses. You must click both links to complete your request'",
")",
")",
";",
"}"
] |
Sends a confirmation message to both old and new email addresses with link to confirm changing of email.
|
[
"Sends",
"a",
"confirmation",
"message",
"to",
"both",
"old",
"and",
"new",
"email",
"addresses",
"with",
"link",
"to",
"confirm",
"changing",
"of",
"email",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/SettingsForm.php#L186-L198
|
amostajo/wordpress-plugin-core
|
src/psr4/Config.php
|
Config.get
|
public function get( $key, $sub = null )
{
if ( empty( $sub ) ) $sub = $this->raw;
$keys = explode( '.', $key );
if ( empty( $keys ) ) return;
if ( array_key_exists( $keys[0], $sub ) ) {
if ( count( $keys ) == 1 ) {
return $sub[$keys[0]];
} else if ( is_array( $sub[$keys[0]] ) ) {
$sub = $sub[$keys[0]];
unset( $keys[0] );
return $this->get( implode( '.', $keys), $sub );
}
}
return;
}
|
php
|
public function get( $key, $sub = null )
{
if ( empty( $sub ) ) $sub = $this->raw;
$keys = explode( '.', $key );
if ( empty( $keys ) ) return;
if ( array_key_exists( $keys[0], $sub ) ) {
if ( count( $keys ) == 1 ) {
return $sub[$keys[0]];
} else if ( is_array( $sub[$keys[0]] ) ) {
$sub = $sub[$keys[0]];
unset( $keys[0] );
return $this->get( implode( '.', $keys), $sub );
}
}
return;
}
|
[
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"sub",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sub",
")",
")",
"$",
"sub",
"=",
"$",
"this",
"->",
"raw",
";",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"keys",
")",
")",
"return",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"keys",
"[",
"0",
"]",
",",
"$",
"sub",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"keys",
")",
"==",
"1",
")",
"{",
"return",
"$",
"sub",
"[",
"$",
"keys",
"[",
"0",
"]",
"]",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"sub",
"[",
"$",
"keys",
"[",
"0",
"]",
"]",
")",
")",
"{",
"$",
"sub",
"=",
"$",
"sub",
"[",
"$",
"keys",
"[",
"0",
"]",
"]",
";",
"unset",
"(",
"$",
"keys",
"[",
"0",
"]",
")",
";",
"return",
"$",
"this",
"->",
"get",
"(",
"implode",
"(",
"'.'",
",",
"$",
"keys",
")",
",",
"$",
"sub",
")",
";",
"}",
"}",
"return",
";",
"}"
] |
Returns value stored in given key.
Can acces multidimenssional array values with a DOT(.)
i.e. paypal.client_id
@since 1.0
@param string $key Key.
@param string $sub Child array
@return mixed
|
[
"Returns",
"value",
"stored",
"in",
"given",
"key",
".",
"Can",
"acces",
"multidimenssional",
"array",
"values",
"with",
"a",
"DOT",
"(",
".",
")",
"i",
".",
"e",
".",
"paypal",
".",
"client_id",
"@since",
"1",
".",
"0"
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Config.php#L45-L62
|
AndreyKluev/yii2-shop-basket
|
behaviors/BasketProductBehavior.php
|
BasketProductBehavior.isInBasket
|
public function isInBasket($idComponent = 'basket')
{
return Yii::$app->get($idComponent)->basket->isProductInBasket($this->getHash());
}
|
php
|
public function isInBasket($idComponent = 'basket')
{
return Yii::$app->get($idComponent)->basket->isProductInBasket($this->getHash());
}
|
[
"public",
"function",
"isInBasket",
"(",
"$",
"idComponent",
"=",
"'basket'",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"get",
"(",
"$",
"idComponent",
")",
"->",
"basket",
"->",
"isProductInBasket",
"(",
"$",
"this",
"->",
"getHash",
"(",
")",
")",
";",
"}"
] |
Проверяет добавлен ли товар в корзину '$idComponent'
@param $idComponent
@return mixed
@throws \yii\base\InvalidConfigException
|
[
"Проверяет",
"добавлен",
"ли",
"товар",
"в",
"корзину",
"$idComponent"
] |
train
|
https://github.com/AndreyKluev/yii2-shop-basket/blob/3bc529fd576a18403096f911112d5337cb5b1069/behaviors/BasketProductBehavior.php#L51-L54
|
dunkelfrosch/phpcoverfish
|
src/PHPCoverFish/Validator/ValidatorMethodName.php
|
ValidatorMethodName.getMapping
|
public function getMapping(CoverFishPHPUnitFile $phpUnitFile)
{
$method = $this->getResult()['method'];
$classFQN = $phpUnitFile->getCoversDefaultClass();
$class = $this->coverFishHelper->getClassNameFromClassFQN($classFQN);
$mappingOptions = array(
'coverToken' => $this->coversToken,
'coverMethod' => $method,
'coverAccessor' => null,
'coverClass' => $class,
'coverClassFQN' => $classFQN,
'validatorMatch' => $this->getValidationTag(),
'validatorClass' => get_class($this)
);
return $this->setMapping($mappingOptions);
}
|
php
|
public function getMapping(CoverFishPHPUnitFile $phpUnitFile)
{
$method = $this->getResult()['method'];
$classFQN = $phpUnitFile->getCoversDefaultClass();
$class = $this->coverFishHelper->getClassNameFromClassFQN($classFQN);
$mappingOptions = array(
'coverToken' => $this->coversToken,
'coverMethod' => $method,
'coverAccessor' => null,
'coverClass' => $class,
'coverClassFQN' => $classFQN,
'validatorMatch' => $this->getValidationTag(),
'validatorClass' => get_class($this)
);
return $this->setMapping($mappingOptions);
}
|
[
"public",
"function",
"getMapping",
"(",
"CoverFishPHPUnitFile",
"$",
"phpUnitFile",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"getResult",
"(",
")",
"[",
"'method'",
"]",
";",
"$",
"classFQN",
"=",
"$",
"phpUnitFile",
"->",
"getCoversDefaultClass",
"(",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"coverFishHelper",
"->",
"getClassNameFromClassFQN",
"(",
"$",
"classFQN",
")",
";",
"$",
"mappingOptions",
"=",
"array",
"(",
"'coverToken'",
"=>",
"$",
"this",
"->",
"coversToken",
",",
"'coverMethod'",
"=>",
"$",
"method",
",",
"'coverAccessor'",
"=>",
"null",
",",
"'coverClass'",
"=>",
"$",
"class",
",",
"'coverClassFQN'",
"=>",
"$",
"classFQN",
",",
"'validatorMatch'",
"=>",
"$",
"this",
"->",
"getValidationTag",
"(",
")",
",",
"'validatorClass'",
"=>",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"return",
"$",
"this",
"->",
"setMapping",
"(",
"$",
"mappingOptions",
")",
";",
"}"
] |
@param CoverFishPHPUnitFile $phpUnitFile
@return array
|
[
"@param",
"CoverFishPHPUnitFile",
"$phpUnitFile"
] |
train
|
https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Validator/ValidatorMethodName.php#L54-L71
|
askupasoftware/amarkal
|
Extensions/WordPress/Options/Section.php
|
Section.is_current_section
|
public function is_current_section()
{
if( !isset( $this->active ) )
{
$this->active = filter_input(INPUT_GET, 'section') == $this->get_slug();
}
return $this->active;
}
|
php
|
public function is_current_section()
{
if( !isset( $this->active ) )
{
$this->active = filter_input(INPUT_GET, 'section') == $this->get_slug();
}
return $this->active;
}
|
[
"public",
"function",
"is_current_section",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"active",
")",
")",
"{",
"$",
"this",
"->",
"active",
"=",
"filter_input",
"(",
"INPUT_GET",
",",
"'section'",
")",
"==",
"$",
"this",
"->",
"get_slug",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"active",
";",
"}"
] |
Check if this is the current section.
@return boolean True if this is the currently active section.
|
[
"Check",
"if",
"this",
"is",
"the",
"current",
"section",
"."
] |
train
|
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Extensions/WordPress/Options/Section.php#L95-L102
|
askupasoftware/amarkal
|
Extensions/WordPress/Options/Section.php
|
Section.get_fields
|
public function get_fields()
{
if( !isset( $this->fields ) )
{
if( !$this->has_sub_sections() )
{
$this->fields = $this->model['fields'];
}
else
{
$this->fields = array();
foreach( $this->model['subsections'] as $subsection )
{
foreach( $subsection['fields'] as $field )
{
$field->subsection = \Amarkal\Common\Tools::strtoslug( $subsection['title'] );
}
$this->fields = array_merge( $this->fields, $subsection['fields'] );
}
}
}
return $this->fields;
}
|
php
|
public function get_fields()
{
if( !isset( $this->fields ) )
{
if( !$this->has_sub_sections() )
{
$this->fields = $this->model['fields'];
}
else
{
$this->fields = array();
foreach( $this->model['subsections'] as $subsection )
{
foreach( $subsection['fields'] as $field )
{
$field->subsection = \Amarkal\Common\Tools::strtoslug( $subsection['title'] );
}
$this->fields = array_merge( $this->fields, $subsection['fields'] );
}
}
}
return $this->fields;
}
|
[
"public",
"function",
"get_fields",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fields",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has_sub_sections",
"(",
")",
")",
"{",
"$",
"this",
"->",
"fields",
"=",
"$",
"this",
"->",
"model",
"[",
"'fields'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"model",
"[",
"'subsections'",
"]",
"as",
"$",
"subsection",
")",
"{",
"foreach",
"(",
"$",
"subsection",
"[",
"'fields'",
"]",
"as",
"$",
"field",
")",
"{",
"$",
"field",
"->",
"subsection",
"=",
"\\",
"Amarkal",
"\\",
"Common",
"\\",
"Tools",
"::",
"strtoslug",
"(",
"$",
"subsection",
"[",
"'title'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"fields",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"fields",
",",
"$",
"subsection",
"[",
"'fields'",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"fields",
";",
"}"
] |
Get the array of fields for this section.
If this section has subsections, the returning array will consist of
all fields from all subsections.
@return array
|
[
"Get",
"the",
"array",
"of",
"fields",
"for",
"this",
"section",
".",
"If",
"this",
"section",
"has",
"subsections",
"the",
"returning",
"array",
"will",
"consist",
"of",
"all",
"fields",
"from",
"all",
"subsections",
"."
] |
train
|
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Extensions/WordPress/Options/Section.php#L121-L143
|
iocaste/microservice-foundation
|
src/Http/Middleware/TranslatorMiddleware.php
|
TranslatorMiddleware.handle
|
public function handle($request, Closure $next)
{
$lang = app('request')->get('lang');
if (! $lang) {
$lang = app('request')->segment(1);
}
if (! \in_array($lang, config('microservice.enabled_languages'), true)) {
$lang = env('DEFAULT_LOCALE', 'ru');
}
if (app('translator')->getLocale() !== $lang) {
app('translator')->setLocale($lang);
}
return $next($request);
}
|
php
|
public function handle($request, Closure $next)
{
$lang = app('request')->get('lang');
if (! $lang) {
$lang = app('request')->segment(1);
}
if (! \in_array($lang, config('microservice.enabled_languages'), true)) {
$lang = env('DEFAULT_LOCALE', 'ru');
}
if (app('translator')->getLocale() !== $lang) {
app('translator')->setLocale($lang);
}
return $next($request);
}
|
[
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"$",
"lang",
"=",
"app",
"(",
"'request'",
")",
"->",
"get",
"(",
"'lang'",
")",
";",
"if",
"(",
"!",
"$",
"lang",
")",
"{",
"$",
"lang",
"=",
"app",
"(",
"'request'",
")",
"->",
"segment",
"(",
"1",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"lang",
",",
"config",
"(",
"'microservice.enabled_languages'",
")",
",",
"true",
")",
")",
"{",
"$",
"lang",
"=",
"env",
"(",
"'DEFAULT_LOCALE'",
",",
"'ru'",
")",
";",
"}",
"if",
"(",
"app",
"(",
"'translator'",
")",
"->",
"getLocale",
"(",
")",
"!==",
"$",
"lang",
")",
"{",
"app",
"(",
"'translator'",
")",
"->",
"setLocale",
"(",
"$",
"lang",
")",
";",
"}",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}"
] |
Run the request filter.
@param $request
@param Closure $next
@return \Illuminate\Http\JsonResponse|mixed
|
[
"Run",
"the",
"request",
"filter",
"."
] |
train
|
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Middleware/TranslatorMiddleware.php#L17-L34
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.