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
|
---|---|---|---|---|---|---|---|---|---|---|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.filter
|
public function filter($value)
{
//translitere specific chars
$value = $this->transliterateCzech($value);
$value = $this->transliterateSlovak($value);
$value = $this->transliterateRussian($value);
$value = $this->transliterateGerman($value);
$value = $this->transliterateFrench($value);
$value = $this->transliterateHungarian($value);
$value = $this->transliteratePolish($value);
$value = $this->transliterateDanish($value);
$value = $this->transliterateCroatian($value);
//split string to single characters
$characters = mb_split("~(.)~", $value);
$return = '';
foreach ($characters as $character) {
/* maybe should contain also //IGNORE */
$converted = iconv("utf-8", "ASCII//TRANSLIT", $character);
//if character was converted, strip out wrong marks
if ($character !== $converted) {
$return .= preg_replace('~["\'^]+~', '', $converted);
} else {
$return .= $converted;
}
}
return $return;
}
|
php
|
public function filter($value)
{
//translitere specific chars
$value = $this->transliterateCzech($value);
$value = $this->transliterateSlovak($value);
$value = $this->transliterateRussian($value);
$value = $this->transliterateGerman($value);
$value = $this->transliterateFrench($value);
$value = $this->transliterateHungarian($value);
$value = $this->transliteratePolish($value);
$value = $this->transliterateDanish($value);
$value = $this->transliterateCroatian($value);
//split string to single characters
$characters = mb_split("~(.)~", $value);
$return = '';
foreach ($characters as $character) {
/* maybe should contain also //IGNORE */
$converted = iconv("utf-8", "ASCII//TRANSLIT", $character);
//if character was converted, strip out wrong marks
if ($character !== $converted) {
$return .= preg_replace('~["\'^]+~', '', $converted);
} else {
$return .= $converted;
}
}
return $return;
}
|
[
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"//translitere specific chars",
"$",
"value",
"=",
"$",
"this",
"->",
"transliterateCzech",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"transliterateSlovak",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"transliterateRussian",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"transliterateGerman",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"transliterateFrench",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"transliterateHungarian",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"transliteratePolish",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"transliterateDanish",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"transliterateCroatian",
"(",
"$",
"value",
")",
";",
"//split string to single characters",
"$",
"characters",
"=",
"mb_split",
"(",
"\"~(.)~\"",
",",
"$",
"value",
")",
";",
"$",
"return",
"=",
"''",
";",
"foreach",
"(",
"$",
"characters",
"as",
"$",
"character",
")",
"{",
"/* maybe should contain also //IGNORE */",
"$",
"converted",
"=",
"iconv",
"(",
"\"utf-8\"",
",",
"\"ASCII//TRANSLIT\"",
",",
"$",
"character",
")",
";",
"//if character was converted, strip out wrong marks",
"if",
"(",
"$",
"character",
"!==",
"$",
"converted",
")",
"{",
"$",
"return",
".=",
"preg_replace",
"(",
"'~[\"\\'^]+~'",
",",
"''",
",",
"$",
"converted",
")",
";",
"}",
"else",
"{",
"$",
"return",
".=",
"$",
"converted",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] |
Defined by Zend_Filter_Interface
Returns $value translitered to ASCII
@param string $value
@return string
|
[
"Defined",
"by",
"Zend_Filter_Interface"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L37-L66
|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.transliterateRussian
|
private function transliterateRussian($s)
{
$table = array(
"А" => "A",
"Б" => "B",
"В" => "V",
"Г" => "G",
"Д" => "D",
"Є" => "E",
"Е" => "JE",
"Ё" => "JO",
"Ж" => "ZH",
"З" => "Z",
"И" => "I",
"Й" => "J",
"К" => "K",
"Л" => "L",
"М" => "M",
"Н" => "N",
"О" => "O",
"П" => "P",
"Р" => "R",
"С" => "S",
"Т" => "T",
"У" => "U",
"Ф" => "F",
"Х" => "KH",
"Ц" => "TS",
"Ч" => "CH",
"Ш" => "SH",
"Щ" => "SHCH",
"Ъ" => "",
"Ы" => "Y",
"Ь" => "",
"Э" => "E",
"Ю" => "JU",
"Я" => "JA",
"Ґ" => "G",
"Ї" => "I",
"а" => "a",
"б" => "b",
"в" => "v",
"г" => "g",
"д" => "d",
"є" => "e",
"е" => "je",
"ё" => "jo",
"ж" => "zh",
"з" => "z",
"и" => "i",
"й" => "j",
"к" => "k",
"л" => "l",
"м" => "m",
"н" => "n",
"о" => "o",
"п" => "p",
"р" => "r",
"с" => "s",
"т" => "t",
"у" => "u",
"ф" => "f",
"х" => "kh",
"ц" => "ts",
"ч" => "ch",
"ш" => "sh",
"щ" => "shch",
"ъ" => "",
"ы" => "y",
"ь" => "",
"э" => "e",
"ю" => "ju",
"я" => "ja",
"ґ" => "g",
"ї" => "i"
);
return strtr($s, $table);
}
|
php
|
private function transliterateRussian($s)
{
$table = array(
"А" => "A",
"Б" => "B",
"В" => "V",
"Г" => "G",
"Д" => "D",
"Є" => "E",
"Е" => "JE",
"Ё" => "JO",
"Ж" => "ZH",
"З" => "Z",
"И" => "I",
"Й" => "J",
"К" => "K",
"Л" => "L",
"М" => "M",
"Н" => "N",
"О" => "O",
"П" => "P",
"Р" => "R",
"С" => "S",
"Т" => "T",
"У" => "U",
"Ф" => "F",
"Х" => "KH",
"Ц" => "TS",
"Ч" => "CH",
"Ш" => "SH",
"Щ" => "SHCH",
"Ъ" => "",
"Ы" => "Y",
"Ь" => "",
"Э" => "E",
"Ю" => "JU",
"Я" => "JA",
"Ґ" => "G",
"Ї" => "I",
"а" => "a",
"б" => "b",
"в" => "v",
"г" => "g",
"д" => "d",
"є" => "e",
"е" => "je",
"ё" => "jo",
"ж" => "zh",
"з" => "z",
"и" => "i",
"й" => "j",
"к" => "k",
"л" => "l",
"м" => "m",
"н" => "n",
"о" => "o",
"п" => "p",
"р" => "r",
"с" => "s",
"т" => "t",
"у" => "u",
"ф" => "f",
"х" => "kh",
"ц" => "ts",
"ч" => "ch",
"ш" => "sh",
"щ" => "shch",
"ъ" => "",
"ы" => "y",
"ь" => "",
"э" => "e",
"ю" => "ju",
"я" => "ja",
"ґ" => "g",
"ї" => "i"
);
return strtr($s, $table);
}
|
[
"private",
"function",
"transliterateRussian",
"(",
"$",
"s",
")",
"{",
"$",
"table",
"=",
"array",
"(",
"\"А\" ",
"> ",
"A\",",
"",
"\"Б\" ",
"> ",
"B\",",
"",
"\"В\" ",
"> ",
"V\",",
"",
"\"Г\" ",
"> ",
"G\",",
"",
"\"Д\" ",
"> ",
"D\",",
"",
"\"Є\" ",
"> ",
"E\",",
"",
"\"Е\" ",
"> ",
"JE\",",
"",
"\"Ё\" ",
"> ",
"JO\",",
"",
"\"Ж\" ",
"> ",
"ZH\",",
"",
"\"З\" ",
"> ",
"Z\",",
"",
"\"И\" ",
"> ",
"I\",",
"",
"\"Й\" ",
"> ",
"J\",",
"",
"\"К\" ",
"> ",
"K\",",
"",
"\"Л\" ",
"> ",
"L\",",
"",
"\"М\" ",
"> ",
"M\",",
"",
"\"Н\" ",
"> ",
"N\",",
"",
"\"О\" ",
"> ",
"O\",",
"",
"\"П\" ",
"> ",
"P\",",
"",
"\"Р\" ",
"> ",
"R\",",
"",
"\"С\" ",
"> ",
"S\",",
"",
"\"Т\" ",
"> ",
"T\",",
"",
"\"У\" ",
"> ",
"U\",",
"",
"\"Ф\" ",
"> ",
"F\",",
"",
"\"Х\" ",
"> ",
"KH\",",
"",
"\"Ц\" ",
"> ",
"TS\",",
"",
"\"Ч\" ",
"> ",
"CH\",",
"",
"\"Ш\" ",
"> ",
"SH\",",
"",
"\"Щ\" ",
"> ",
"SHCH\",",
"",
"\"Ъ\" ",
"> ",
"\",",
"",
"\"Ы\" ",
"> ",
"Y\",",
"",
"\"Ь\" ",
"> ",
"\",",
"",
"\"Э\" ",
"> ",
"E\",",
"",
"\"Ю\" ",
"> ",
"JU\",",
"",
"\"Я\" ",
"> ",
"JA\",",
"",
"\"Ґ\" ",
"> ",
"G\",",
"",
"\"Ї\" ",
"> ",
"I\",",
"",
"\"а\" ",
"> ",
"a\",",
"",
"\"б\" ",
"> ",
"b\",",
"",
"\"в\" ",
"> ",
"v\",",
"",
"\"г\" ",
"> ",
"g\",",
"",
"\"д\" ",
"> ",
"d\",",
"",
"\"є\" ",
"> ",
"e\",",
"",
"\"е\" ",
"> ",
"je\",",
"",
"\"ё\" ",
"> ",
"jo\",",
"",
"\"ж\" ",
"> ",
"zh\",",
"",
"\"з\" ",
"> ",
"z\",",
"",
"\"и\" ",
"> ",
"i\",",
"",
"\"й\" ",
"> ",
"j\",",
"",
"\"к\" ",
"> ",
"k\",",
"",
"\"л\" ",
"> ",
"l\",",
"",
"\"м\" ",
"> ",
"m\",",
"",
"\"н\" ",
"> ",
"n\",",
"",
"\"о\" ",
"> ",
"o\",",
"",
"\"п\" ",
"> ",
"p\",",
"",
"\"р\" ",
"> ",
"r\",",
"",
"\"с\" ",
"> ",
"s\",",
"",
"\"т\" ",
"> ",
"t\",",
"",
"\"у\" ",
"> ",
"u\",",
"",
"\"ф\" ",
"> ",
"f\",",
"",
"\"х\" ",
"> ",
"kh\",",
"",
"\"ц\" ",
"> ",
"ts\",",
"",
"\"ч\" ",
"> ",
"ch\",",
"",
"\"ш\" ",
"> ",
"sh\",",
"",
"\"щ\" ",
"> ",
"shch\",",
"",
"\"ъ\" ",
"> ",
"\",",
"",
"\"ы\" ",
"> ",
"y\",",
"",
"\"ь\" ",
"> ",
"\",",
"",
"\"э\" ",
"> ",
"e\",",
"",
"\"ю\" ",
"> ",
"ju\",",
"",
"\"я\" ",
"> ",
"ja\",",
"",
"\"ґ\" ",
"> ",
"g\",",
"",
"\"ї\" ",
"> ",
"i\"",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"$",
"table",
")",
";",
"}"
] |
Transliterate Russian chars (Cyrillic)
@param string $s
@return string
|
[
"Transliterate",
"Russian",
"chars",
"(",
"Cyrillic",
")"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L74-L151
|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.transliterateCzech
|
private function transliterateCzech($s)
{
$table = array(
'á' => 'a',
'č' => 'c',
'ď' => 'd',
'é' => 'e',
'ě' => 'e',
'í' => 'i',
'ň' => 'n',
'ó' => 'o',
'ř' => 'r',
'š' => 's',
'ť' => 't',
'ú' => 'u',
'ů' => 'u',
'ý' => 'y',
'ž' => 'z',
'Á' => 'A',
'Č' => 'C',
'Ď' => 'D',
'É' => 'E',
'Ě' => 'E',
'Í' => 'I',
'Ň' => 'N',
'Ó' => 'O',
'Ř' => 'R',
'Š' => 'S',
'Ť' => 'T',
'Ú' => 'U',
'Ů' => 'U',
'Ý' => 'Y',
'Ž' => 'Z',
);
return strtr($s, $table);
}
|
php
|
private function transliterateCzech($s)
{
$table = array(
'á' => 'a',
'č' => 'c',
'ď' => 'd',
'é' => 'e',
'ě' => 'e',
'í' => 'i',
'ň' => 'n',
'ó' => 'o',
'ř' => 'r',
'š' => 's',
'ť' => 't',
'ú' => 'u',
'ů' => 'u',
'ý' => 'y',
'ž' => 'z',
'Á' => 'A',
'Č' => 'C',
'Ď' => 'D',
'É' => 'E',
'Ě' => 'E',
'Í' => 'I',
'Ň' => 'N',
'Ó' => 'O',
'Ř' => 'R',
'Š' => 'S',
'Ť' => 'T',
'Ú' => 'U',
'Ů' => 'U',
'Ý' => 'Y',
'Ž' => 'Z',
);
return strtr($s, $table);
}
|
[
"private",
"function",
"transliterateCzech",
"(",
"$",
"s",
")",
"{",
"$",
"table",
"=",
"array",
"(",
"'á' ",
"> ",
"a',",
"",
"'č' ",
"> ",
"c',",
"",
"'ď' ",
"> ",
"d',",
"",
"'é' ",
"> ",
"e',",
"",
"'ě' ",
"> ",
"e',",
"",
"'í' ",
"> ",
"i',",
"",
"'ň' ",
"> ",
"n',",
"",
"'ó' ",
"> ",
"o',",
"",
"'ř' ",
"> ",
"r',",
"",
"'š' ",
"> ",
"s',",
"",
"'ť' ",
"> ",
"t',",
"",
"'ú' ",
"> ",
"u',",
"",
"'ů' ",
"> ",
"u',",
"",
"'ý' ",
"> ",
"y',",
"",
"'ž' ",
"> ",
"z',",
"",
"'Á' ",
"> ",
"A',",
"",
"'Č' ",
"> ",
"C',",
"",
"'Ď' ",
"> ",
"D',",
"",
"'É' ",
"> ",
"E',",
"",
"'Ě' ",
"> ",
"E',",
"",
"'Í' ",
"> ",
"I',",
"",
"'Ň' ",
"> ",
"N',",
"",
"'Ó' ",
"> ",
"O',",
"",
"'Ř' ",
"> ",
"R',",
"",
"'Š' ",
"> ",
"S',",
"",
"'Ť' ",
"> ",
"T',",
"",
"'Ú' ",
"> ",
"U',",
"",
"'Ů' ",
"> ",
"U',",
"",
"'Ý' ",
"> ",
"Y',",
"",
"'Ž' ",
"> ",
"Z',",
"",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"$",
"table",
")",
";",
"}"
] |
Transliterate Czech chars
@param string $s
@return string
|
[
"Transliterate",
"Czech",
"chars"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L159-L194
|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.transliterateGerman
|
private function transliterateGerman($s)
{
$table = array(
//'ä' => 'ae', //messes up with slovak -> they have ä -> a
'ë' => 'e',
'ï' => 'i',
'ö' => 'oe',
'ü' => 'ue',
'Ä' => 'Ae',
'Ë' => 'E',
'Ï' => 'I',
'Ö' => 'Oe',
'Ü' => 'Ue',
'ß' => 'ss',
);
return strtr($s, $table);
}
|
php
|
private function transliterateGerman($s)
{
$table = array(
//'ä' => 'ae', //messes up with slovak -> they have ä -> a
'ë' => 'e',
'ï' => 'i',
'ö' => 'oe',
'ü' => 'ue',
'Ä' => 'Ae',
'Ë' => 'E',
'Ï' => 'I',
'Ö' => 'Oe',
'Ü' => 'Ue',
'ß' => 'ss',
);
return strtr($s, $table);
}
|
[
"private",
"function",
"transliterateGerman",
"(",
"$",
"s",
")",
"{",
"$",
"table",
"=",
"array",
"(",
"//'ä' => 'ae', //messes up with slovak -> they have ä -> a",
"'ë' ",
"> ",
"e',",
"",
"'ï' ",
"> ",
"i',",
"",
"'ö' ",
"> ",
"oe',",
"",
"'ü' ",
"> ",
"ue',",
"",
"'Ä' ",
"> ",
"Ae',",
"",
"'Ë' ",
"> ",
"E',",
"",
"'Ï' ",
"> ",
"I',",
"",
"'Ö' ",
"> ",
"Oe',",
"",
"'Ü' ",
"> ",
"Ue',",
"",
"'ß' ",
"> ",
"ss',",
"",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"$",
"table",
")",
";",
"}"
] |
Transliterate German chars
@param string $s
@return string
|
[
"Transliterate",
"German",
"chars"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L202-L218
|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.transliterateHungarian
|
private function transliterateHungarian($s)
{
$table = array(
'á' => 'a',
'é' => 'e',
'í' => 'i',
'ó' => 'o',
'ö' => 'o',
'ő' => 'o',
'ú' => 'u',
'ü' => 'u',
'ű' => 'u',
);
return strtr($s, $table);
}
|
php
|
private function transliterateHungarian($s)
{
$table = array(
'á' => 'a',
'é' => 'e',
'í' => 'i',
'ó' => 'o',
'ö' => 'o',
'ő' => 'o',
'ú' => 'u',
'ü' => 'u',
'ű' => 'u',
);
return strtr($s, $table);
}
|
[
"private",
"function",
"transliterateHungarian",
"(",
"$",
"s",
")",
"{",
"$",
"table",
"=",
"array",
"(",
"'á' ",
"> ",
"a',",
"",
"'é' ",
"> ",
"e',",
"",
"'í' ",
"> ",
"i',",
"",
"'ó' ",
"> ",
"o',",
"",
"'ö' ",
"> ",
"o',",
"",
"'ő' ",
"> ",
"o',",
"",
"'ú' ",
"> ",
"u',",
"",
"'ü' ",
"> ",
"u',",
"",
"'ű' ",
"> ",
"u',",
"",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"$",
"table",
")",
";",
"}"
] |
Transliterate Hungarian chars
@param string $s
@return string
|
[
"Transliterate",
"Hungarian",
"chars"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L254-L268
|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.transliteratePolish
|
private function transliteratePolish($s)
{
$table = array(
'ą' => 'a',
'ę' => 'e',
'ó' => 'o',
'ć' => 'c',
'ł' => 'l',
'ń' => 'n',
'ś' => 's',
'ż' => 'z',
'ź' => 'z',
'Ó' => 'O',
'Ć' => 'C',
'Ł' => 'L',
'Ś' => 'S',
'Ż' => 'Z',
'Ź' => 'Z'
);
return strtr($s, $table);
}
|
php
|
private function transliteratePolish($s)
{
$table = array(
'ą' => 'a',
'ę' => 'e',
'ó' => 'o',
'ć' => 'c',
'ł' => 'l',
'ń' => 'n',
'ś' => 's',
'ż' => 'z',
'ź' => 'z',
'Ó' => 'O',
'Ć' => 'C',
'Ł' => 'L',
'Ś' => 'S',
'Ż' => 'Z',
'Ź' => 'Z'
);
return strtr($s, $table);
}
|
[
"private",
"function",
"transliteratePolish",
"(",
"$",
"s",
")",
"{",
"$",
"table",
"=",
"array",
"(",
"'ą' ",
"> ",
"a',",
"",
"'ę' ",
"> ",
"e',",
"",
"'ó' ",
"> ",
"o',",
"",
"'ć' ",
"> ",
"c',",
"",
"'ł' ",
"> ",
"l',",
"",
"'ń' ",
"> ",
"n',",
"",
"'ś' ",
"> ",
"s',",
"",
"'ż' ",
"> ",
"z',",
"",
"'ź' ",
"> ",
"z',",
"",
"'Ó' ",
"> ",
"O',",
"",
"'Ć' ",
"> ",
"C',",
"",
"'Ł' ",
"> ",
"L',",
"",
"'Ś' ",
"> ",
"S',",
"",
"'Ż' ",
"> ",
"Z',",
"",
"'Ź' ",
"> ",
"Z'",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"$",
"table",
")",
";",
"}"
] |
Transliterate Polish chars
@param string $s
@return string
|
[
"Transliterate",
"Polish",
"chars"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L276-L296
|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.transliterateDanish
|
private function transliterateDanish($s)
{
$table = array(
'æ' => 'ae',
'ø' => 'oe',
'å' => 'aa',
'Æ' => 'Ae',
'Ø' => 'Oe',
'Å' => 'Aa'
);
return strtr($s, $table);
}
|
php
|
private function transliterateDanish($s)
{
$table = array(
'æ' => 'ae',
'ø' => 'oe',
'å' => 'aa',
'Æ' => 'Ae',
'Ø' => 'Oe',
'Å' => 'Aa'
);
return strtr($s, $table);
}
|
[
"private",
"function",
"transliterateDanish",
"(",
"$",
"s",
")",
"{",
"$",
"table",
"=",
"array",
"(",
"'æ' ",
"> ",
"ae',",
"",
"'ø' ",
"> ",
"oe',",
"",
"'å' ",
"> ",
"aa',",
"",
"'Æ' ",
"> ",
"Ae',",
"",
"'Ø' ",
"> ",
"Oe',",
"",
"'Å' ",
"> ",
"Aa'",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"$",
"table",
")",
";",
"}"
] |
Transliterate Danish chars
@param string $s
@return string
|
[
"Transliterate",
"Danish",
"chars"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L304-L315
|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.transliterateCroatian
|
private function transliterateCroatian($s)
{
$table = array(
'Č' => 'C',
'Ć' => 'C',
'Ž' => 'Z',
'Š' => 'S',
'Đ' => 'D',
'č' => 'c',
'ć' => 'c',
'ž' => 'z',
'š' => 's',
'đ' => 'd',
);
return strtr($s, $table);
}
|
php
|
private function transliterateCroatian($s)
{
$table = array(
'Č' => 'C',
'Ć' => 'C',
'Ž' => 'Z',
'Š' => 'S',
'Đ' => 'D',
'č' => 'c',
'ć' => 'c',
'ž' => 'z',
'š' => 's',
'đ' => 'd',
);
return strtr($s, $table);
}
|
[
"private",
"function",
"transliterateCroatian",
"(",
"$",
"s",
")",
"{",
"$",
"table",
"=",
"array",
"(",
"'Č' ",
"> ",
"C',",
"",
"'Ć' ",
"> ",
"C',",
"",
"'Ž' ",
"> ",
"Z',",
"",
"'Š' ",
"> ",
"S',",
"",
"'Đ' ",
"> ",
"D',",
"",
"'č' ",
"> ",
"c',",
"",
"'ć' ",
"> ",
"c',",
"",
"'ž' ",
"> ",
"z',",
"",
"'š' ",
"> ",
"s',",
"",
"'đ' ",
"> ",
"d',",
"",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"$",
"table",
")",
";",
"}"
] |
Transliterate Croatian chars
@param string $s
@return string
|
[
"Transliterate",
"Croatian",
"chars"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L323-L338
|
gregorybesson/PlaygroundCore
|
src/Filter/Transliteration.php
|
Transliteration.transliterateSlovak
|
private function transliterateSlovak($s)
{
$table = array(
'á' => 'a',
'Á' => 'A',
'ä' => 'a',
'Ä' => 'A',
'č' => 'c',
'Č' => 'C',
'ď' => 'd',
'Ď' => 'D',
'é' => 'e',
'É' => 'E',
'í' => 'i',
'Í' => 'I',
'ĺ' => 'l',
'Ĺ' => 'L',
'ľ' => 'l',
'Ľ' => 'L',
'ň' => 'n',
'Ň' => 'N',
'ó' => 'o',
'Ó' => 'O',
'ô' => 'o',
'Ô' => 'O',
'ŕ' => 'r',
'Ŕ' => 'R',
'š' => 's',
'Š' => 'S',
'ť' => 't',
'Ť' => 'T',
'ú' => 'u',
'Ú' => 'U',
'Ý' => 'Y',
'ý' => 'y',
'ž' => 'z',
'Ž' => 'Z',
);
return strtr($s, $table);
}
|
php
|
private function transliterateSlovak($s)
{
$table = array(
'á' => 'a',
'Á' => 'A',
'ä' => 'a',
'Ä' => 'A',
'č' => 'c',
'Č' => 'C',
'ď' => 'd',
'Ď' => 'D',
'é' => 'e',
'É' => 'E',
'í' => 'i',
'Í' => 'I',
'ĺ' => 'l',
'Ĺ' => 'L',
'ľ' => 'l',
'Ľ' => 'L',
'ň' => 'n',
'Ň' => 'N',
'ó' => 'o',
'Ó' => 'O',
'ô' => 'o',
'Ô' => 'O',
'ŕ' => 'r',
'Ŕ' => 'R',
'š' => 's',
'Š' => 'S',
'ť' => 't',
'Ť' => 'T',
'ú' => 'u',
'Ú' => 'U',
'Ý' => 'Y',
'ý' => 'y',
'ž' => 'z',
'Ž' => 'Z',
);
return strtr($s, $table);
}
|
[
"private",
"function",
"transliterateSlovak",
"(",
"$",
"s",
")",
"{",
"$",
"table",
"=",
"array",
"(",
"'á' ",
"> ",
"a',",
"",
"'Á' ",
"> ",
"A',",
"",
"'ä' ",
"> ",
"a',",
"",
"'Ä' ",
"> ",
"A',",
"",
"'č' ",
"> ",
"c',",
"",
"'Č' ",
"> ",
"C',",
"",
"'ď' ",
"> ",
"d',",
"",
"'Ď' ",
"> ",
"D',",
"",
"'é' ",
"> ",
"e',",
"",
"'É' ",
"> ",
"E',",
"",
"'í' ",
"> ",
"i',",
"",
"'Í' ",
"> ",
"I',",
"",
"'ĺ' ",
"> ",
"l',",
"",
"'Ĺ' ",
"> ",
"L',",
"",
"'ľ' ",
"> ",
"l',",
"",
"'Ľ' ",
"> ",
"L',",
"",
"'ň' ",
"> ",
"n',",
"",
"'Ň' ",
"> ",
"N',",
"",
"'ó' ",
"> ",
"o',",
"",
"'Ó' ",
"> ",
"O',",
"",
"'ô' ",
"> ",
"o',",
"",
"'Ô' ",
"> ",
"O',",
"",
"'ŕ' ",
"> ",
"r',",
"",
"'Ŕ' ",
"> ",
"R',",
"",
"'š' ",
"> ",
"s',",
"",
"'Š' ",
"> ",
"S',",
"",
"'ť' ",
"> ",
"t',",
"",
"'Ť' ",
"> ",
"T',",
"",
"'ú' ",
"> ",
"u',",
"",
"'Ú' ",
"> ",
"U',",
"",
"'Ý' ",
"> ",
"Y',",
"",
"'ý' ",
"> ",
"y',",
"",
"'ž' ",
"> ",
"z',",
"",
"'Ž' ",
"> ",
"Z',",
"",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"$",
"table",
")",
";",
"}"
] |
Transliterate Slovak chars
@param string $s
@return string
|
[
"Transliterate",
"Slovak",
"chars"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Transliteration.php#L346-L385
|
huasituo/hstcms
|
src/Providers/MiddlewareServiceProvider.php
|
MiddlewareServiceProvider.register
|
public function register()
{
$this->app->singleton('manage.request.log', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\RequestLog($app['hstcms']);
});
$this->app->singleton('manage.auth.check', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\CheckAuth($app['hstcms']);
});
$this->app->singleton('api.service', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\ApiService($app['hstcms']);
});
$this->app->singleton('module.service', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\ModuleService($app['hstcms']);
});
$this->app->singleton('check.site.status', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\CheckSiteStatus($app['hstcms']);
});
// $this->app->singleton('module.api.service', function ($app) {
// return new \Huasituo\Hstcms\Http\Middleware\ModuleApiService($app['hstcms']);
// });
// $this->app->singleton('module.openapi.service', function ($app) {
// return new \Huasituo\Hstcms\Http\Middleware\ModuleOpenApiService($app['hstcms']);
// });
}
|
php
|
public function register()
{
$this->app->singleton('manage.request.log', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\RequestLog($app['hstcms']);
});
$this->app->singleton('manage.auth.check', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\CheckAuth($app['hstcms']);
});
$this->app->singleton('api.service', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\ApiService($app['hstcms']);
});
$this->app->singleton('module.service', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\ModuleService($app['hstcms']);
});
$this->app->singleton('check.site.status', function ($app) {
return new \Huasituo\Hstcms\Http\Middleware\CheckSiteStatus($app['hstcms']);
});
// $this->app->singleton('module.api.service', function ($app) {
// return new \Huasituo\Hstcms\Http\Middleware\ModuleApiService($app['hstcms']);
// });
// $this->app->singleton('module.openapi.service', function ($app) {
// return new \Huasituo\Hstcms\Http\Middleware\ModuleOpenApiService($app['hstcms']);
// });
}
|
[
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'manage.request.log'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Huasituo",
"\\",
"Hstcms",
"\\",
"Http",
"\\",
"Middleware",
"\\",
"RequestLog",
"(",
"$",
"app",
"[",
"'hstcms'",
"]",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'manage.auth.check'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Huasituo",
"\\",
"Hstcms",
"\\",
"Http",
"\\",
"Middleware",
"\\",
"CheckAuth",
"(",
"$",
"app",
"[",
"'hstcms'",
"]",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'api.service'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Huasituo",
"\\",
"Hstcms",
"\\",
"Http",
"\\",
"Middleware",
"\\",
"ApiService",
"(",
"$",
"app",
"[",
"'hstcms'",
"]",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'module.service'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Huasituo",
"\\",
"Hstcms",
"\\",
"Http",
"\\",
"Middleware",
"\\",
"ModuleService",
"(",
"$",
"app",
"[",
"'hstcms'",
"]",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'check.site.status'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Huasituo",
"\\",
"Hstcms",
"\\",
"Http",
"\\",
"Middleware",
"\\",
"CheckSiteStatus",
"(",
"$",
"app",
"[",
"'hstcms'",
"]",
")",
";",
"}",
")",
";",
"// $this->app->singleton('module.api.service', function ($app) {",
"// return new \\Huasituo\\Hstcms\\Http\\Middleware\\ModuleApiService($app['hstcms']);",
"// });",
"// $this->app->singleton('module.openapi.service', function ($app) {",
"// return new \\Huasituo\\Hstcms\\Http\\Middleware\\ModuleOpenApiService($app['hstcms']);",
"// });",
"}"
] |
Register the application services.
|
[
"Register",
"the",
"application",
"services",
"."
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Providers/MiddlewareServiceProvider.php#L24-L47
|
edmondscommerce/behat-faker-context
|
src/FakerContext.php
|
FakerContext.fillForm
|
protected function fillForm(Element\NodeElement $form)
{
$inputs = $form->findAll('css', 'input[type="text"]');
foreach ($inputs as $i)
{
/** @var Element\NodeElement $i */
if ($i->isVisible())
{
if ($i->hasAttribute('name'))
{
$name = $i->getAttribute('name');
$value = $this->getFakerValue($name);
}
else
{
$value = $this->faker()->text();
}
$i->setValue($value);
}
}
$passwords = $form->findAll('css', 'input[type="password"]');
$password = $this->faker()->password;
foreach ($passwords as $p)
{
if ($p->isVisible())
{
$p->setValue($password);
}
}
$selects = $form->findAll('css', 'select');
foreach ($selects as $s)
{
/** @var Element\NodeElement $s */
if ($s->isVisible())
{
$s->selectOption($s->find('css', 'option')->getAttribute('name'));
}
}
$checkboxes = $form->findAll('css', 'checkbox');
foreach ($checkboxes as $c)
{
/** @var Element\NodeElement $c */
if ($c->isVisible())
{
$c->check();
}
}
$radios = $form->findAll('css', 'input[type="radio"]');
$radio_names = array();
foreach ($radios as $r)
{
/** @var Element\NodeElement $r */
if ($r->isVisible())
{
if ($r->hasAttribute('name'))
{
$name = $r->getAttribute('name');
if (!isset($radio_names[$name]))
{
$radio_names[$name] = true;
$r->click();
}
}
}
}
}
|
php
|
protected function fillForm(Element\NodeElement $form)
{
$inputs = $form->findAll('css', 'input[type="text"]');
foreach ($inputs as $i)
{
/** @var Element\NodeElement $i */
if ($i->isVisible())
{
if ($i->hasAttribute('name'))
{
$name = $i->getAttribute('name');
$value = $this->getFakerValue($name);
}
else
{
$value = $this->faker()->text();
}
$i->setValue($value);
}
}
$passwords = $form->findAll('css', 'input[type="password"]');
$password = $this->faker()->password;
foreach ($passwords as $p)
{
if ($p->isVisible())
{
$p->setValue($password);
}
}
$selects = $form->findAll('css', 'select');
foreach ($selects as $s)
{
/** @var Element\NodeElement $s */
if ($s->isVisible())
{
$s->selectOption($s->find('css', 'option')->getAttribute('name'));
}
}
$checkboxes = $form->findAll('css', 'checkbox');
foreach ($checkboxes as $c)
{
/** @var Element\NodeElement $c */
if ($c->isVisible())
{
$c->check();
}
}
$radios = $form->findAll('css', 'input[type="radio"]');
$radio_names = array();
foreach ($radios as $r)
{
/** @var Element\NodeElement $r */
if ($r->isVisible())
{
if ($r->hasAttribute('name'))
{
$name = $r->getAttribute('name');
if (!isset($radio_names[$name]))
{
$radio_names[$name] = true;
$r->click();
}
}
}
}
}
|
[
"protected",
"function",
"fillForm",
"(",
"Element",
"\\",
"NodeElement",
"$",
"form",
")",
"{",
"$",
"inputs",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'input[type=\"text\"]'",
")",
";",
"foreach",
"(",
"$",
"inputs",
"as",
"$",
"i",
")",
"{",
"/** @var Element\\NodeElement $i */",
"if",
"(",
"$",
"i",
"->",
"isVisible",
"(",
")",
")",
"{",
"if",
"(",
"$",
"i",
"->",
"hasAttribute",
"(",
"'name'",
")",
")",
"{",
"$",
"name",
"=",
"$",
"i",
"->",
"getAttribute",
"(",
"'name'",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getFakerValue",
"(",
"$",
"name",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"faker",
"(",
")",
"->",
"text",
"(",
")",
";",
"}",
"$",
"i",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"}",
"}",
"$",
"passwords",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'input[type=\"password\"]'",
")",
";",
"$",
"password",
"=",
"$",
"this",
"->",
"faker",
"(",
")",
"->",
"password",
";",
"foreach",
"(",
"$",
"passwords",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"$",
"p",
"->",
"isVisible",
"(",
")",
")",
"{",
"$",
"p",
"->",
"setValue",
"(",
"$",
"password",
")",
";",
"}",
"}",
"$",
"selects",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'select'",
")",
";",
"foreach",
"(",
"$",
"selects",
"as",
"$",
"s",
")",
"{",
"/** @var Element\\NodeElement $s */",
"if",
"(",
"$",
"s",
"->",
"isVisible",
"(",
")",
")",
"{",
"$",
"s",
"->",
"selectOption",
"(",
"$",
"s",
"->",
"find",
"(",
"'css'",
",",
"'option'",
")",
"->",
"getAttribute",
"(",
"'name'",
")",
")",
";",
"}",
"}",
"$",
"checkboxes",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'checkbox'",
")",
";",
"foreach",
"(",
"$",
"checkboxes",
"as",
"$",
"c",
")",
"{",
"/** @var Element\\NodeElement $c */",
"if",
"(",
"$",
"c",
"->",
"isVisible",
"(",
")",
")",
"{",
"$",
"c",
"->",
"check",
"(",
")",
";",
"}",
"}",
"$",
"radios",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'input[type=\"radio\"]'",
")",
";",
"$",
"radio_names",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"radios",
"as",
"$",
"r",
")",
"{",
"/** @var Element\\NodeElement $r */",
"if",
"(",
"$",
"r",
"->",
"isVisible",
"(",
")",
")",
"{",
"if",
"(",
"$",
"r",
"->",
"hasAttribute",
"(",
"'name'",
")",
")",
"{",
"$",
"name",
"=",
"$",
"r",
"->",
"getAttribute",
"(",
"'name'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"radio_names",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"radio_names",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"$",
"r",
"->",
"click",
"(",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Fuzz fill all form fields with random data
@param Element\NodeElement $form
|
[
"Fuzz",
"fill",
"all",
"form",
"fields",
"with",
"random",
"data"
] |
train
|
https://github.com/edmondscommerce/behat-faker-context/blob/7c616daf7a8bab9093a1b8a3c608d644a929f715/src/FakerContext.php#L63-L135
|
Srokap/code_review
|
classes/CodeReview/CodeFixer.php
|
CodeFixer.getBasicFunctionRenames
|
public function getBasicFunctionRenames($maxVersion = '') {
$data = array(
'1.7' => array(
'elgg_validate_action_url' => 'elgg_add_action_tokens_to_url',
'menu_item' => 'make_register_object',
'extend_view' => 'elgg_extend_view',
'get_views' => 'elgg_get_views',
),
'1.8' => array(
'register_elgg_event_handler' => 'elgg_register_event_handler',
'unregister_elgg_event_handler' => 'elgg_unregister_event_handler',
'trigger_elgg_event' => 'elgg_trigger_event',
'register_plugin_hook' => 'elgg_register_plugin_hook_handler',
'unregister_plugin_hook' => 'elgg_unregister_plugin_hook_handler',
'trigger_plugin_hook' => 'elgg_trigger_plugin_hook',
'friendly_title' => 'elgg_get_friendly_title',
'friendly_time' => 'elgg_view_friendly_time',
'page_owner' => 'elgg_get_page_owner_guid',
'page_owner_entity' => 'elgg_get_page_owner_entity',
'set_page_owner' => 'elgg_set_page_owner_guid',
'set_context' => 'elgg_set_context',
'get_context' => 'elgg_get_context',
'get_plugin_name' => 'elgg_get_calling_plugin_id',
'is_plugin_enabled' => 'elgg_is_active_plugin',
'set_user_validation_status' => 'elgg_set_user_validation_status',
'get_loggedin_user' => 'elgg_get_logged_in_user_entity',
'get_loggedin_userid' => 'elgg_get_logged_in_user_guid',
'isloggedin' => 'elgg_is_logged_in',
'isadminloggedin' => 'elgg_is_admin_logged_in',
'load_plugins' => '_elgg_load_plugins',
'set_plugin_usersetting' => 'elgg_set_plugin_user_setting',
'clear_plugin_usersetting' => 'elgg_unset_plugin_user_setting',
'get_plugin_usersetting' => 'elgg_get_plugin_user_setting',
'set_plugin_setting' => 'elgg_set_plugin_setting',
'get_plugin_setting' => 'elgg_get_plugin_setting',
'clear_plugin_setting' => 'elgg_unset_plugin_setting',
'clear_all_plugin_settings' => 'elgg_unset_all_plugin_settings',
'set_view_location' => 'elgg_set_view_location',
'get_metadata' => 'elgg_get_metadata_from_id',
'get_annotation' => 'elgg_get_annotation_from_id',
'register_page_handler' => 'elgg_register_page_handler',
'unregister_page_handler' => 'elgg_unregister_page_handler',
'register_entity_type' => 'elgg_register_entity_type',
'elgg_view_register_simplecache' => 'elgg_register_simplecache_view',
'elgg_view_regenerate_simplecache' => 'elgg_regenerate_simplecache',
'elgg_view_enable_simplecache' => 'elgg_enable_simplecache',
'elgg_view_disable_simplecache' => 'elgg_disable_simplecache',
'remove_widget_type' => 'elgg_unregister_widget_type',
'widget_type_exists' => 'elgg_is_widget_type',
'get_widget_types' => 'elgg_get_widget_types',
'display_widget' => 'elgg_view_entity',
'invalidate_cache_for_entity' => '_elgg_invalidate_cache_for_entity',
'cache_entity' => '_elgg_cache_entity',
'retrieve_cached_entity' => '_elgg_retrieve_cached_entity',
),
'1.9' => array(
'setup_db_connections' => '_elgg_services()->db->setupConnections',
'get_db_link' => '_elgg_services()->db->getLink',
'get_db_error' => 'mysql_error',
'execute_delayed_query' => '_elgg_services()->db->registerDelayedQuery',
'elgg_regenerate_simplecache' => 'elgg_invalidate_simplecache',
'elgg_get_filepath_cache' => 'elgg_get_system_cache',
'elgg_filepath_cache_reset' => 'elgg_reset_system_cache',
'elgg_filepath_cache_save' => 'elgg_save_system_cache',
'elgg_filepath_cache_load' => 'elgg_load_system_cache',
'elgg_enable_filepath_cache' => 'elgg_enable_system_cache',
'elgg_disable_filepath_cache' => 'elgg_disable_system_cache',
'unregister_entity_type' => 'elgg_unregister_entity_type',
'autop' => 'elgg_autop',
'xml_to_object' => 'new ElggXMLElement',
'unregister_notification_handler' => 'elgg_unregister_notification_method',
),
'1.10' => array(
'file_get_general_file_type' => 'elgg_get_file_simple_type',
'file_get_simple_type' => 'elgg_get_file_simple_type',
),
);
$result = array();
foreach ($data as $version => $rows) {
if (!$maxVersion || version_compare($version, $maxVersion, '<=')) {
$result = array_merge($result, $rows);
}
}
return $result;
}
|
php
|
public function getBasicFunctionRenames($maxVersion = '') {
$data = array(
'1.7' => array(
'elgg_validate_action_url' => 'elgg_add_action_tokens_to_url',
'menu_item' => 'make_register_object',
'extend_view' => 'elgg_extend_view',
'get_views' => 'elgg_get_views',
),
'1.8' => array(
'register_elgg_event_handler' => 'elgg_register_event_handler',
'unregister_elgg_event_handler' => 'elgg_unregister_event_handler',
'trigger_elgg_event' => 'elgg_trigger_event',
'register_plugin_hook' => 'elgg_register_plugin_hook_handler',
'unregister_plugin_hook' => 'elgg_unregister_plugin_hook_handler',
'trigger_plugin_hook' => 'elgg_trigger_plugin_hook',
'friendly_title' => 'elgg_get_friendly_title',
'friendly_time' => 'elgg_view_friendly_time',
'page_owner' => 'elgg_get_page_owner_guid',
'page_owner_entity' => 'elgg_get_page_owner_entity',
'set_page_owner' => 'elgg_set_page_owner_guid',
'set_context' => 'elgg_set_context',
'get_context' => 'elgg_get_context',
'get_plugin_name' => 'elgg_get_calling_plugin_id',
'is_plugin_enabled' => 'elgg_is_active_plugin',
'set_user_validation_status' => 'elgg_set_user_validation_status',
'get_loggedin_user' => 'elgg_get_logged_in_user_entity',
'get_loggedin_userid' => 'elgg_get_logged_in_user_guid',
'isloggedin' => 'elgg_is_logged_in',
'isadminloggedin' => 'elgg_is_admin_logged_in',
'load_plugins' => '_elgg_load_plugins',
'set_plugin_usersetting' => 'elgg_set_plugin_user_setting',
'clear_plugin_usersetting' => 'elgg_unset_plugin_user_setting',
'get_plugin_usersetting' => 'elgg_get_plugin_user_setting',
'set_plugin_setting' => 'elgg_set_plugin_setting',
'get_plugin_setting' => 'elgg_get_plugin_setting',
'clear_plugin_setting' => 'elgg_unset_plugin_setting',
'clear_all_plugin_settings' => 'elgg_unset_all_plugin_settings',
'set_view_location' => 'elgg_set_view_location',
'get_metadata' => 'elgg_get_metadata_from_id',
'get_annotation' => 'elgg_get_annotation_from_id',
'register_page_handler' => 'elgg_register_page_handler',
'unregister_page_handler' => 'elgg_unregister_page_handler',
'register_entity_type' => 'elgg_register_entity_type',
'elgg_view_register_simplecache' => 'elgg_register_simplecache_view',
'elgg_view_regenerate_simplecache' => 'elgg_regenerate_simplecache',
'elgg_view_enable_simplecache' => 'elgg_enable_simplecache',
'elgg_view_disable_simplecache' => 'elgg_disable_simplecache',
'remove_widget_type' => 'elgg_unregister_widget_type',
'widget_type_exists' => 'elgg_is_widget_type',
'get_widget_types' => 'elgg_get_widget_types',
'display_widget' => 'elgg_view_entity',
'invalidate_cache_for_entity' => '_elgg_invalidate_cache_for_entity',
'cache_entity' => '_elgg_cache_entity',
'retrieve_cached_entity' => '_elgg_retrieve_cached_entity',
),
'1.9' => array(
'setup_db_connections' => '_elgg_services()->db->setupConnections',
'get_db_link' => '_elgg_services()->db->getLink',
'get_db_error' => 'mysql_error',
'execute_delayed_query' => '_elgg_services()->db->registerDelayedQuery',
'elgg_regenerate_simplecache' => 'elgg_invalidate_simplecache',
'elgg_get_filepath_cache' => 'elgg_get_system_cache',
'elgg_filepath_cache_reset' => 'elgg_reset_system_cache',
'elgg_filepath_cache_save' => 'elgg_save_system_cache',
'elgg_filepath_cache_load' => 'elgg_load_system_cache',
'elgg_enable_filepath_cache' => 'elgg_enable_system_cache',
'elgg_disable_filepath_cache' => 'elgg_disable_system_cache',
'unregister_entity_type' => 'elgg_unregister_entity_type',
'autop' => 'elgg_autop',
'xml_to_object' => 'new ElggXMLElement',
'unregister_notification_handler' => 'elgg_unregister_notification_method',
),
'1.10' => array(
'file_get_general_file_type' => 'elgg_get_file_simple_type',
'file_get_simple_type' => 'elgg_get_file_simple_type',
),
);
$result = array();
foreach ($data as $version => $rows) {
if (!$maxVersion || version_compare($version, $maxVersion, '<=')) {
$result = array_merge($result, $rows);
}
}
return $result;
}
|
[
"public",
"function",
"getBasicFunctionRenames",
"(",
"$",
"maxVersion",
"=",
"''",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"'1.7'",
"=>",
"array",
"(",
"'elgg_validate_action_url'",
"=>",
"'elgg_add_action_tokens_to_url'",
",",
"'menu_item'",
"=>",
"'make_register_object'",
",",
"'extend_view'",
"=>",
"'elgg_extend_view'",
",",
"'get_views'",
"=>",
"'elgg_get_views'",
",",
")",
",",
"'1.8'",
"=>",
"array",
"(",
"'register_elgg_event_handler'",
"=>",
"'elgg_register_event_handler'",
",",
"'unregister_elgg_event_handler'",
"=>",
"'elgg_unregister_event_handler'",
",",
"'trigger_elgg_event'",
"=>",
"'elgg_trigger_event'",
",",
"'register_plugin_hook'",
"=>",
"'elgg_register_plugin_hook_handler'",
",",
"'unregister_plugin_hook'",
"=>",
"'elgg_unregister_plugin_hook_handler'",
",",
"'trigger_plugin_hook'",
"=>",
"'elgg_trigger_plugin_hook'",
",",
"'friendly_title'",
"=>",
"'elgg_get_friendly_title'",
",",
"'friendly_time'",
"=>",
"'elgg_view_friendly_time'",
",",
"'page_owner'",
"=>",
"'elgg_get_page_owner_guid'",
",",
"'page_owner_entity'",
"=>",
"'elgg_get_page_owner_entity'",
",",
"'set_page_owner'",
"=>",
"'elgg_set_page_owner_guid'",
",",
"'set_context'",
"=>",
"'elgg_set_context'",
",",
"'get_context'",
"=>",
"'elgg_get_context'",
",",
"'get_plugin_name'",
"=>",
"'elgg_get_calling_plugin_id'",
",",
"'is_plugin_enabled'",
"=>",
"'elgg_is_active_plugin'",
",",
"'set_user_validation_status'",
"=>",
"'elgg_set_user_validation_status'",
",",
"'get_loggedin_user'",
"=>",
"'elgg_get_logged_in_user_entity'",
",",
"'get_loggedin_userid'",
"=>",
"'elgg_get_logged_in_user_guid'",
",",
"'isloggedin'",
"=>",
"'elgg_is_logged_in'",
",",
"'isadminloggedin'",
"=>",
"'elgg_is_admin_logged_in'",
",",
"'load_plugins'",
"=>",
"'_elgg_load_plugins'",
",",
"'set_plugin_usersetting'",
"=>",
"'elgg_set_plugin_user_setting'",
",",
"'clear_plugin_usersetting'",
"=>",
"'elgg_unset_plugin_user_setting'",
",",
"'get_plugin_usersetting'",
"=>",
"'elgg_get_plugin_user_setting'",
",",
"'set_plugin_setting'",
"=>",
"'elgg_set_plugin_setting'",
",",
"'get_plugin_setting'",
"=>",
"'elgg_get_plugin_setting'",
",",
"'clear_plugin_setting'",
"=>",
"'elgg_unset_plugin_setting'",
",",
"'clear_all_plugin_settings'",
"=>",
"'elgg_unset_all_plugin_settings'",
",",
"'set_view_location'",
"=>",
"'elgg_set_view_location'",
",",
"'get_metadata'",
"=>",
"'elgg_get_metadata_from_id'",
",",
"'get_annotation'",
"=>",
"'elgg_get_annotation_from_id'",
",",
"'register_page_handler'",
"=>",
"'elgg_register_page_handler'",
",",
"'unregister_page_handler'",
"=>",
"'elgg_unregister_page_handler'",
",",
"'register_entity_type'",
"=>",
"'elgg_register_entity_type'",
",",
"'elgg_view_register_simplecache'",
"=>",
"'elgg_register_simplecache_view'",
",",
"'elgg_view_regenerate_simplecache'",
"=>",
"'elgg_regenerate_simplecache'",
",",
"'elgg_view_enable_simplecache'",
"=>",
"'elgg_enable_simplecache'",
",",
"'elgg_view_disable_simplecache'",
"=>",
"'elgg_disable_simplecache'",
",",
"'remove_widget_type'",
"=>",
"'elgg_unregister_widget_type'",
",",
"'widget_type_exists'",
"=>",
"'elgg_is_widget_type'",
",",
"'get_widget_types'",
"=>",
"'elgg_get_widget_types'",
",",
"'display_widget'",
"=>",
"'elgg_view_entity'",
",",
"'invalidate_cache_for_entity'",
"=>",
"'_elgg_invalidate_cache_for_entity'",
",",
"'cache_entity'",
"=>",
"'_elgg_cache_entity'",
",",
"'retrieve_cached_entity'",
"=>",
"'_elgg_retrieve_cached_entity'",
",",
")",
",",
"'1.9'",
"=>",
"array",
"(",
"'setup_db_connections'",
"=>",
"'_elgg_services()->db->setupConnections'",
",",
"'get_db_link'",
"=>",
"'_elgg_services()->db->getLink'",
",",
"'get_db_error'",
"=>",
"'mysql_error'",
",",
"'execute_delayed_query'",
"=>",
"'_elgg_services()->db->registerDelayedQuery'",
",",
"'elgg_regenerate_simplecache'",
"=>",
"'elgg_invalidate_simplecache'",
",",
"'elgg_get_filepath_cache'",
"=>",
"'elgg_get_system_cache'",
",",
"'elgg_filepath_cache_reset'",
"=>",
"'elgg_reset_system_cache'",
",",
"'elgg_filepath_cache_save'",
"=>",
"'elgg_save_system_cache'",
",",
"'elgg_filepath_cache_load'",
"=>",
"'elgg_load_system_cache'",
",",
"'elgg_enable_filepath_cache'",
"=>",
"'elgg_enable_system_cache'",
",",
"'elgg_disable_filepath_cache'",
"=>",
"'elgg_disable_system_cache'",
",",
"'unregister_entity_type'",
"=>",
"'elgg_unregister_entity_type'",
",",
"'autop'",
"=>",
"'elgg_autop'",
",",
"'xml_to_object'",
"=>",
"'new ElggXMLElement'",
",",
"'unregister_notification_handler'",
"=>",
"'elgg_unregister_notification_method'",
",",
")",
",",
"'1.10'",
"=>",
"array",
"(",
"'file_get_general_file_type'",
"=>",
"'elgg_get_file_simple_type'",
",",
"'file_get_simple_type'",
"=>",
"'elgg_get_file_simple_type'",
",",
")",
",",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"version",
"=>",
"$",
"rows",
")",
"{",
"if",
"(",
"!",
"$",
"maxVersion",
"||",
"version_compare",
"(",
"$",
"version",
",",
"$",
"maxVersion",
",",
"'<='",
")",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"rows",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Just basic function renames from A to B
@param string $maxVersion Maximum Elgg version to support
@return array
|
[
"Just",
"basic",
"function",
"renames",
"from",
"A",
"to",
"B"
] |
train
|
https://github.com/Srokap/code_review/blob/c79c619f99279cf15713b118ae19b0ef017db362/classes/CodeReview/CodeFixer.php#L12-L97
|
bdunogier/xmlrpcbundle
|
XmlRpc/Handler/Ext/ResponseGenerator.php
|
ResponseGenerator.fromException
|
public function fromException( Exception $exception )
{
return $this->generateResponse(
xmlrpc_encode_request(
null,
array(
'faultCode' => $exception->getCode(),
'faultString' => $exception->getMessage()
)
)
);
}
|
php
|
public function fromException( Exception $exception )
{
return $this->generateResponse(
xmlrpc_encode_request(
null,
array(
'faultCode' => $exception->getCode(),
'faultString' => $exception->getMessage()
)
)
);
}
|
[
"public",
"function",
"fromException",
"(",
"Exception",
"$",
"exception",
")",
"{",
"return",
"$",
"this",
"->",
"generateResponse",
"(",
"xmlrpc_encode_request",
"(",
"null",
",",
"array",
"(",
"'faultCode'",
"=>",
"$",
"exception",
"->",
"getCode",
"(",
")",
",",
"'faultString'",
"=>",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
")",
")",
";",
"}"
] |
Generates an XMLRPC HTTP response for the Exception $e
@param \Exception $e
@return \Symfony\Component\HttpFoundation\Response
|
[
"Generates",
"an",
"XMLRPC",
"HTTP",
"response",
"for",
"the",
"Exception",
"$e"
] |
train
|
https://github.com/bdunogier/xmlrpcbundle/blob/9a3d59609131d438d259b3ae2c113bb4b813a16b/XmlRpc/Handler/Ext/ResponseGenerator.php#L31-L42
|
bdunogier/xmlrpcbundle
|
XmlRpc/Handler/Ext/ResponseGenerator.php
|
ResponseGenerator.fixUpTypes
|
protected function fixUpTypes( $response )
{
if ( is_array( $response ) )
{
foreach ( $response as &$value )
{
$value = $this->fixUpTypes( $value );
}
}
if ( $response instanceof DateTime )
{
$response = $response->format( "Ymd\TH:i:s" );
xmlrpc_set_type( $response, 'datetime' );
}
return $response;
}
|
php
|
protected function fixUpTypes( $response )
{
if ( is_array( $response ) )
{
foreach ( $response as &$value )
{
$value = $this->fixUpTypes( $value );
}
}
if ( $response instanceof DateTime )
{
$response = $response->format( "Ymd\TH:i:s" );
xmlrpc_set_type( $response, 'datetime' );
}
return $response;
}
|
[
"protected",
"function",
"fixUpTypes",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"response",
")",
")",
"{",
"foreach",
"(",
"$",
"response",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"fixUpTypes",
"(",
"$",
"value",
")",
";",
"}",
"}",
"if",
"(",
"$",
"response",
"instanceof",
"DateTime",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"format",
"(",
"\"Ymd\\TH:i:s\"",
")",
";",
"xmlrpc_set_type",
"(",
"$",
"response",
",",
"'datetime'",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Fixes up
|
[
"Fixes",
"up"
] |
train
|
https://github.com/bdunogier/xmlrpcbundle/blob/9a3d59609131d438d259b3ae2c113bb4b813a16b/XmlRpc/Handler/Ext/ResponseGenerator.php#L64-L81
|
sulu/SuluSalesShippingBundle
|
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderEmailManager.php
|
OrderEmailManager.sendConfirmationEmail
|
public function sendConfirmationEmail(
$recipient,
ApiOrderInterface $apiOrder,
$templatePath,
ContactInterface $customerContact = null
) {
if (empty($recipient)) {
$this->writeLog('No recipient specified.');
return false;
}
$tmplData = array(
'order' => $apiOrder,
'contact' => $customerContact,
);
return $this->sendOrderMail($recipient, $templatePath, $tmplData, $apiOrder);
}
|
php
|
public function sendConfirmationEmail(
$recipient,
ApiOrderInterface $apiOrder,
$templatePath,
ContactInterface $customerContact = null
) {
if (empty($recipient)) {
$this->writeLog('No recipient specified.');
return false;
}
$tmplData = array(
'order' => $apiOrder,
'contact' => $customerContact,
);
return $this->sendOrderMail($recipient, $templatePath, $tmplData, $apiOrder);
}
|
[
"public",
"function",
"sendConfirmationEmail",
"(",
"$",
"recipient",
",",
"ApiOrderInterface",
"$",
"apiOrder",
",",
"$",
"templatePath",
",",
"ContactInterface",
"$",
"customerContact",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"recipient",
")",
")",
"{",
"$",
"this",
"->",
"writeLog",
"(",
"'No recipient specified.'",
")",
";",
"return",
"false",
";",
"}",
"$",
"tmplData",
"=",
"array",
"(",
"'order'",
"=>",
"$",
"apiOrder",
",",
"'contact'",
"=>",
"$",
"customerContact",
",",
")",
";",
"return",
"$",
"this",
"->",
"sendOrderMail",
"(",
"$",
"recipient",
",",
"$",
"templatePath",
",",
"$",
"tmplData",
",",
"$",
"apiOrder",
")",
";",
"}"
] |
@param string $recipient The email-address of the customer
@param ApiOrderInterface $apiOrder
@param string $templatePath Template to render
@param ContactInterface|null $customerContact
@return bool
|
[
"@param",
"string",
"$recipient",
"The",
"email",
"-",
"address",
"of",
"the",
"customer",
"@param",
"ApiOrderInterface",
"$apiOrder",
"@param",
"string",
"$templatePath",
"Template",
"to",
"render",
"@param",
"ContactInterface|null",
"$customerContact"
] |
train
|
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderEmailManager.php#L151-L169
|
sulu/SuluSalesShippingBundle
|
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderEmailManager.php
|
OrderEmailManager.sendOrderMail
|
public function sendOrderMail(
$recipient,
$templatePath,
$data = array(),
ApiOrderInterface $apiOrder = null,
$blindCopyRecipients = array()
) {
$tmplData = array_merge(
$data,
array(
'footerTxt' => $this->templateFooterTxtPath,
'footerHtml' => $this->templateFooterHtmlPath,
)
);
$template = $this->twig->loadTemplate($templatePath);
$subject = $template->renderBlock('subject', $tmplData);
$emailBodyText = $template->renderBlock('body_text', $tmplData);
$emailBodyHtml = $template->renderBlock('body_html', $tmplData);
/** @var \Swift_Message $message */
$message = \Swift_Message::newInstance()
->setSubject($subject)
->setFrom($this->emailFrom)
->setTo($recipient)
->setBody($emailBodyText, 'text/plain')
->addPart($emailBodyHtml, 'text/html');
// add blind copy recipients
foreach ($blindCopyRecipients as $bcc) {
$message->addBcc($bcc);
}
// add pdf if order is supplied
if ($apiOrder) {
$pdf = $this->pdfManager->createOrderConfirmation($apiOrder);
$pdfFileName = $this->pdfManager->getPdfName($apiOrder);
// now send mail
$attachment = \Swift_Attachment::newInstance()
->setFilename($pdfFileName)
->setContentType('application/pdf')
->setBody($pdf);
$message->attach($attachment);
}
$failedRecipients = array();
$this->mailer->send($message, $failedRecipients);
if (count($failedRecipients) > 0) {
$this->writeLog('Could not send mail to the following recipients: ' . join(', ', $failedRecipients));
return false;
}
return true;
}
|
php
|
public function sendOrderMail(
$recipient,
$templatePath,
$data = array(),
ApiOrderInterface $apiOrder = null,
$blindCopyRecipients = array()
) {
$tmplData = array_merge(
$data,
array(
'footerTxt' => $this->templateFooterTxtPath,
'footerHtml' => $this->templateFooterHtmlPath,
)
);
$template = $this->twig->loadTemplate($templatePath);
$subject = $template->renderBlock('subject', $tmplData);
$emailBodyText = $template->renderBlock('body_text', $tmplData);
$emailBodyHtml = $template->renderBlock('body_html', $tmplData);
/** @var \Swift_Message $message */
$message = \Swift_Message::newInstance()
->setSubject($subject)
->setFrom($this->emailFrom)
->setTo($recipient)
->setBody($emailBodyText, 'text/plain')
->addPart($emailBodyHtml, 'text/html');
// add blind copy recipients
foreach ($blindCopyRecipients as $bcc) {
$message->addBcc($bcc);
}
// add pdf if order is supplied
if ($apiOrder) {
$pdf = $this->pdfManager->createOrderConfirmation($apiOrder);
$pdfFileName = $this->pdfManager->getPdfName($apiOrder);
// now send mail
$attachment = \Swift_Attachment::newInstance()
->setFilename($pdfFileName)
->setContentType('application/pdf')
->setBody($pdf);
$message->attach($attachment);
}
$failedRecipients = array();
$this->mailer->send($message, $failedRecipients);
if (count($failedRecipients) > 0) {
$this->writeLog('Could not send mail to the following recipients: ' . join(', ', $failedRecipients));
return false;
}
return true;
}
|
[
"public",
"function",
"sendOrderMail",
"(",
"$",
"recipient",
",",
"$",
"templatePath",
",",
"$",
"data",
"=",
"array",
"(",
")",
",",
"ApiOrderInterface",
"$",
"apiOrder",
"=",
"null",
",",
"$",
"blindCopyRecipients",
"=",
"array",
"(",
")",
")",
"{",
"$",
"tmplData",
"=",
"array_merge",
"(",
"$",
"data",
",",
"array",
"(",
"'footerTxt'",
"=>",
"$",
"this",
"->",
"templateFooterTxtPath",
",",
"'footerHtml'",
"=>",
"$",
"this",
"->",
"templateFooterHtmlPath",
",",
")",
")",
";",
"$",
"template",
"=",
"$",
"this",
"->",
"twig",
"->",
"loadTemplate",
"(",
"$",
"templatePath",
")",
";",
"$",
"subject",
"=",
"$",
"template",
"->",
"renderBlock",
"(",
"'subject'",
",",
"$",
"tmplData",
")",
";",
"$",
"emailBodyText",
"=",
"$",
"template",
"->",
"renderBlock",
"(",
"'body_text'",
",",
"$",
"tmplData",
")",
";",
"$",
"emailBodyHtml",
"=",
"$",
"template",
"->",
"renderBlock",
"(",
"'body_html'",
",",
"$",
"tmplData",
")",
";",
"/** @var \\Swift_Message $message */",
"$",
"message",
"=",
"\\",
"Swift_Message",
"::",
"newInstance",
"(",
")",
"->",
"setSubject",
"(",
"$",
"subject",
")",
"->",
"setFrom",
"(",
"$",
"this",
"->",
"emailFrom",
")",
"->",
"setTo",
"(",
"$",
"recipient",
")",
"->",
"setBody",
"(",
"$",
"emailBodyText",
",",
"'text/plain'",
")",
"->",
"addPart",
"(",
"$",
"emailBodyHtml",
",",
"'text/html'",
")",
";",
"// add blind copy recipients",
"foreach",
"(",
"$",
"blindCopyRecipients",
"as",
"$",
"bcc",
")",
"{",
"$",
"message",
"->",
"addBcc",
"(",
"$",
"bcc",
")",
";",
"}",
"// add pdf if order is supplied",
"if",
"(",
"$",
"apiOrder",
")",
"{",
"$",
"pdf",
"=",
"$",
"this",
"->",
"pdfManager",
"->",
"createOrderConfirmation",
"(",
"$",
"apiOrder",
")",
";",
"$",
"pdfFileName",
"=",
"$",
"this",
"->",
"pdfManager",
"->",
"getPdfName",
"(",
"$",
"apiOrder",
")",
";",
"// now send mail",
"$",
"attachment",
"=",
"\\",
"Swift_Attachment",
"::",
"newInstance",
"(",
")",
"->",
"setFilename",
"(",
"$",
"pdfFileName",
")",
"->",
"setContentType",
"(",
"'application/pdf'",
")",
"->",
"setBody",
"(",
"$",
"pdf",
")",
";",
"$",
"message",
"->",
"attach",
"(",
"$",
"attachment",
")",
";",
"}",
"$",
"failedRecipients",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"mailer",
"->",
"send",
"(",
"$",
"message",
",",
"$",
"failedRecipients",
")",
";",
"if",
"(",
"count",
"(",
"$",
"failedRecipients",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"writeLog",
"(",
"'Could not send mail to the following recipients: '",
".",
"join",
"(",
"', '",
",",
"$",
"failedRecipients",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Sends an email
@param string $recipient
@param string $templatePath
@param array $data
@param ApiOrderInterface $apiOrder
@param array $blindCopyRecipients Recipients to send bcc
@return bool
|
[
"Sends",
"an",
"email"
] |
train
|
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderEmailManager.php#L182-L238
|
tequila/mongodb-php-lib
|
src/Index.php
|
Index.generateIndexName
|
public static function generateIndexName(array $key)
{
$nameParts = [];
foreach ($key as $fieldName => $direction) {
$nameParts[] = $fieldName;
$nameParts[] = (string) $direction;
}
return implode('_', $nameParts);
}
|
php
|
public static function generateIndexName(array $key)
{
$nameParts = [];
foreach ($key as $fieldName => $direction) {
$nameParts[] = $fieldName;
$nameParts[] = (string) $direction;
}
return implode('_', $nameParts);
}
|
[
"public",
"static",
"function",
"generateIndexName",
"(",
"array",
"$",
"key",
")",
"{",
"$",
"nameParts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"key",
"as",
"$",
"fieldName",
"=>",
"$",
"direction",
")",
"{",
"$",
"nameParts",
"[",
"]",
"=",
"$",
"fieldName",
";",
"$",
"nameParts",
"[",
"]",
"=",
"(",
"string",
")",
"$",
"direction",
";",
"}",
"return",
"implode",
"(",
"'_'",
",",
"$",
"nameParts",
")",
";",
"}"
] |
@param array $key
@return string
|
[
"@param",
"array",
"$key"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Index.php#L85-L94
|
GokulSrinivas/Sangria
|
src/Sangria/IMAPAuth.php
|
IMAPAuth.tauth
|
public static function tauth($user_name, $user_pass)
{
$imap_server_address=__SANGRIA_IMAP_SERVER_ADDR__;
$imap_port=__SANGRIA_IMAP_SERVER_PORT__;
try
{
$imap_stream = \fsockopen($imap_server_address,$imap_port);
if ( !$imap_stream )
{
return false;
}
$server_info = \fgets ($imap_stream, 1024);
$query = 'b221 ' . 'LOGIN "' . $user_name . '" "' .$user_pass . "\"\r\n";
$read = \fputs ($imap_stream, $query);
$response = \fgets ($imap_stream, 1024);
$query = 'b222 ' . 'LOGOUT';
$read = \fputs ($imap_stream, $query);
\fclose($imap_stream);
\strtok($response, " ");
$result = \strtok(" ");
if($result == "OK")
return true;
else
return false;
}
catch(SangriaException $e)
{
echo $e->getMessage();
return false;
}
}
|
php
|
public static function tauth($user_name, $user_pass)
{
$imap_server_address=__SANGRIA_IMAP_SERVER_ADDR__;
$imap_port=__SANGRIA_IMAP_SERVER_PORT__;
try
{
$imap_stream = \fsockopen($imap_server_address,$imap_port);
if ( !$imap_stream )
{
return false;
}
$server_info = \fgets ($imap_stream, 1024);
$query = 'b221 ' . 'LOGIN "' . $user_name . '" "' .$user_pass . "\"\r\n";
$read = \fputs ($imap_stream, $query);
$response = \fgets ($imap_stream, 1024);
$query = 'b222 ' . 'LOGOUT';
$read = \fputs ($imap_stream, $query);
\fclose($imap_stream);
\strtok($response, " ");
$result = \strtok(" ");
if($result == "OK")
return true;
else
return false;
}
catch(SangriaException $e)
{
echo $e->getMessage();
return false;
}
}
|
[
"public",
"static",
"function",
"tauth",
"(",
"$",
"user_name",
",",
"$",
"user_pass",
")",
"{",
"$",
"imap_server_address",
"=",
"__SANGRIA_IMAP_SERVER_ADDR__",
";",
"$",
"imap_port",
"=",
"__SANGRIA_IMAP_SERVER_PORT__",
";",
"try",
"{",
"$",
"imap_stream",
"=",
"\\",
"fsockopen",
"(",
"$",
"imap_server_address",
",",
"$",
"imap_port",
")",
";",
"if",
"(",
"!",
"$",
"imap_stream",
")",
"{",
"return",
"false",
";",
"}",
"$",
"server_info",
"=",
"\\",
"fgets",
"(",
"$",
"imap_stream",
",",
"1024",
")",
";",
"$",
"query",
"=",
"'b221 '",
".",
"'LOGIN \"'",
".",
"$",
"user_name",
".",
"'\" \"'",
".",
"$",
"user_pass",
".",
"\"\\\"\\r\\n\"",
";",
"$",
"read",
"=",
"\\",
"fputs",
"(",
"$",
"imap_stream",
",",
"$",
"query",
")",
";",
"$",
"response",
"=",
"\\",
"fgets",
"(",
"$",
"imap_stream",
",",
"1024",
")",
";",
"$",
"query",
"=",
"'b222 '",
".",
"'LOGOUT'",
";",
"$",
"read",
"=",
"\\",
"fputs",
"(",
"$",
"imap_stream",
",",
"$",
"query",
")",
";",
"\\",
"fclose",
"(",
"$",
"imap_stream",
")",
";",
"\\",
"strtok",
"(",
"$",
"response",
",",
"\" \"",
")",
";",
"$",
"result",
"=",
"\\",
"strtok",
"(",
"\" \"",
")",
";",
"if",
"(",
"$",
"result",
"==",
"\"OK\"",
")",
"return",
"true",
";",
"else",
"return",
"false",
";",
"}",
"catch",
"(",
"SangriaException",
"$",
"e",
")",
"{",
"echo",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"return",
"false",
";",
"}",
"}"
] |
[tauth Tries to authenticate by telnet]
@param string $user_name [User name]
@param string $user_pass [Password]
@return boolean [true if authenticated, false otherwise]
|
[
"[",
"tauth",
"Tries",
"to",
"authenticate",
"by",
"telnet",
"]"
] |
train
|
https://github.com/GokulSrinivas/Sangria/blob/e69076655da30ef74b9b6f4a7b7317b3d37d5710/src/Sangria/IMAPAuth.php#L25-L62
|
GokulSrinivas/Sangria
|
src/Sangria/IMAPAuth.php
|
IMAPAuth.auth
|
public static function auth($user_name,$user_pass,$imap_option = "/imap/ssl/novalidate-cert",$imap_retries = 0)
{
$imap_server_address = __SANGRIA_IMAP_SERVER_ADDR__;
$imap_port = __SANGRIA_IMAP_SERVER_PORT__;
try
{
$mbox = \imap_open("{".$imap_server_address.":".$imap_port.$imap_option."}", $user_name, $user_pass,0,$imap_retries);
if($mbox)
{
\imap_close($mbox);
return true;
}
else
{
return false;
}
}
catch(SangriaException $e)
{
echo $e->getMessage();
return false;
}
}
|
php
|
public static function auth($user_name,$user_pass,$imap_option = "/imap/ssl/novalidate-cert",$imap_retries = 0)
{
$imap_server_address = __SANGRIA_IMAP_SERVER_ADDR__;
$imap_port = __SANGRIA_IMAP_SERVER_PORT__;
try
{
$mbox = \imap_open("{".$imap_server_address.":".$imap_port.$imap_option."}", $user_name, $user_pass,0,$imap_retries);
if($mbox)
{
\imap_close($mbox);
return true;
}
else
{
return false;
}
}
catch(SangriaException $e)
{
echo $e->getMessage();
return false;
}
}
|
[
"public",
"static",
"function",
"auth",
"(",
"$",
"user_name",
",",
"$",
"user_pass",
",",
"$",
"imap_option",
"=",
"\"/imap/ssl/novalidate-cert\"",
",",
"$",
"imap_retries",
"=",
"0",
")",
"{",
"$",
"imap_server_address",
"=",
"__SANGRIA_IMAP_SERVER_ADDR__",
";",
"$",
"imap_port",
"=",
"__SANGRIA_IMAP_SERVER_PORT__",
";",
"try",
"{",
"$",
"mbox",
"=",
"\\",
"imap_open",
"(",
"\"{\"",
".",
"$",
"imap_server_address",
".",
"\":\"",
".",
"$",
"imap_port",
".",
"$",
"imap_option",
".",
"\"}\"",
",",
"$",
"user_name",
",",
"$",
"user_pass",
",",
"0",
",",
"$",
"imap_retries",
")",
";",
"if",
"(",
"$",
"mbox",
")",
"{",
"\\",
"imap_close",
"(",
"$",
"mbox",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"catch",
"(",
"SangriaException",
"$",
"e",
")",
"{",
"echo",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"return",
"false",
";",
"}",
"}"
] |
[auth Authentication via]
@param string $user_name [username]
@param string $user_pass [password]
@param string $imap_option [options as given in php.net]
@param integer $imap_retries [number of retries]
@return boolean [true if authenticated, false otherwise]
|
[
"[",
"auth",
"Authentication",
"via",
"]"
] |
train
|
https://github.com/GokulSrinivas/Sangria/blob/e69076655da30ef74b9b6f4a7b7317b3d37d5710/src/Sangria/IMAPAuth.php#L72-L97
|
esperecyan/dictionary-php
|
src/parser/AbstractParser.php
|
AbstractParser.logInconvertibleError
|
protected function logInconvertibleError(
string $line,
\esperecyan\dictionary_php\exception\SyntaxException $exception = null
) {
$this->logger->error(
// TRANSLATORS: %s は例外メッセージ。空文字列の場合もある。
sprintf(_('以下の行は汎用辞書のお題に変換できません: %s'), $exception ? $exception->getMessage() : '')
. "\n> " . str_replace("\n", "\n> ", $line),
$exception ? ['exception' => $exception] : []
);
}
|
php
|
protected function logInconvertibleError(
string $line,
\esperecyan\dictionary_php\exception\SyntaxException $exception = null
) {
$this->logger->error(
// TRANSLATORS: %s は例外メッセージ。空文字列の場合もある。
sprintf(_('以下の行は汎用辞書のお題に変換できません: %s'), $exception ? $exception->getMessage() : '')
. "\n> " . str_replace("\n", "\n> ", $line),
$exception ? ['exception' => $exception] : []
);
}
|
[
"protected",
"function",
"logInconvertibleError",
"(",
"string",
"$",
"line",
",",
"\\",
"esperecyan",
"\\",
"dictionary_php",
"\\",
"exception",
"\\",
"SyntaxException",
"$",
"exception",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"// TRANSLATORS: %s は例外メッセージ。空文字列の場合もある。",
"sprintf",
"(",
"_",
"(",
"'以下の行は汎用辞書のお題に変換できません: %s'), $exception ? $exception->getMessage()",
" ",
":",
"'",
"')",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
".",
"\"\\n> \"",
".",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\\n> \"",
",",
"$",
"line",
")",
",",
"$",
"exception",
"?",
"[",
"'exception'",
"=>",
"$",
"exception",
"]",
":",
"[",
"]",
")",
";",
"}"
] |
汎用辞書に変換できないお題があったことを、「error」レベルで記録します。
@param string $line
@param \esperecyan\dictionary_php\exception\SyntaxException $exception
|
[
"汎用辞書に変換できないお題があったことを、「error」レベルで記録します。"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/parser/AbstractParser.php#L36-L46
|
esperecyan/dictionary-php
|
src/parser/AbstractParser.php
|
AbstractParser.generateRegard
|
protected function generateRegard(): string
{
$unique = $this->eliminateDuplicateCharacters($this->unity($this->wholeText));
foreach (self::FREQUENT_REGARDS as $i => $regard) {
if (preg_match("/$regard/u", $unique) === 1) {
return $i === 0 ? '' : $regard;
}
}
return '[' . preg_quote($unique, '/') . ']';
}
|
php
|
protected function generateRegard(): string
{
$unique = $this->eliminateDuplicateCharacters($this->unity($this->wholeText));
foreach (self::FREQUENT_REGARDS as $i => $regard) {
if (preg_match("/$regard/u", $unique) === 1) {
return $i === 0 ? '' : $regard;
}
}
return '[' . preg_quote($unique, '/') . ']';
}
|
[
"protected",
"function",
"generateRegard",
"(",
")",
":",
"string",
"{",
"$",
"unique",
"=",
"$",
"this",
"->",
"eliminateDuplicateCharacters",
"(",
"$",
"this",
"->",
"unity",
"(",
"$",
"this",
"->",
"wholeText",
")",
")",
";",
"foreach",
"(",
"self",
"::",
"FREQUENT_REGARDS",
"as",
"$",
"i",
"=>",
"$",
"regard",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/$regard/u\"",
",",
"$",
"unique",
")",
"===",
"1",
")",
"{",
"return",
"$",
"i",
"===",
"0",
"?",
"''",
":",
"$",
"regard",
";",
"}",
"}",
"return",
"'['",
".",
"preg_quote",
"(",
"$",
"unique",
",",
"'/'",
")",
".",
"']'",
";",
"}"
] |
$wholeText から @regard メタフィールドの内容を生成します。
@return string 既定値になる場合は空文字列を返します。
|
[
"$wholeText",
"から"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/parser/AbstractParser.php#L52-L61
|
esperecyan/dictionary-php
|
src/parser/AbstractParser.php
|
AbstractParser.unity
|
protected function unity(string $input): string
{
return strtr(mb_convert_kana(strtolower($input), 'c', 'UTF-8'), self::EQUIVALENT);
}
|
php
|
protected function unity(string $input): string
{
return strtr(mb_convert_kana(strtolower($input), 'c', 'UTF-8'), self::EQUIVALENT);
}
|
[
"protected",
"function",
"unity",
"(",
"string",
"$",
"input",
")",
":",
"string",
"{",
"return",
"strtr",
"(",
"mb_convert_kana",
"(",
"strtolower",
"(",
"$",
"input",
")",
",",
"'c'",
",",
"'UTF-8'",
")",
",",
"self",
"::",
"EQUIVALENT",
")",
";",
"}"
] |
ASCII小文字化、カタカナをひらがな化などを行います。
|
[
"ASCII小文字化、カタカナをひらがな化などを行います。"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/parser/AbstractParser.php#L66-L69
|
blackprism/serializer
|
src/Blackprism/Serializer/Configuration.php
|
Configuration.addConfigurationObject
|
public function addConfigurationObject(ClassName $className, ObjectInterface $configurationObject): self
{
$this->objects[$className->getIdentifier()] = $configurationObject;
return $this;
}
|
php
|
public function addConfigurationObject(ClassName $className, ObjectInterface $configurationObject): self
{
$this->objects[$className->getIdentifier()] = $configurationObject;
return $this;
}
|
[
"public",
"function",
"addConfigurationObject",
"(",
"ClassName",
"$",
"className",
",",
"ObjectInterface",
"$",
"configurationObject",
")",
":",
"self",
"{",
"$",
"this",
"->",
"objects",
"[",
"$",
"className",
"->",
"getIdentifier",
"(",
")",
"]",
"=",
"$",
"configurationObject",
";",
"return",
"$",
"this",
";",
"}"
] |
@param ClassName $className
@param ObjectInterface $configurationObject
@return Configuration
|
[
"@param",
"ClassName",
"$className",
"@param",
"ObjectInterface",
"$configurationObject"
] |
train
|
https://github.com/blackprism/serializer/blob/f5bd6ebeec802d2ad747daba7c9211b252ee4776/src/Blackprism/Serializer/Configuration.php#L61-L66
|
blackprism/serializer
|
src/Blackprism/Serializer/Configuration.php
|
Configuration.addConfigurationObjectWithIdentifier
|
public function addConfigurationObjectWithIdentifier(
ClassName $className,
ObjectInterface $configurationObject,
$identifier
): self {
$this->identifiers[$identifier] = $configurationObject;
$this->objects[$className->getIdentifier()] = $configurationObject;
return $this;
}
|
php
|
public function addConfigurationObjectWithIdentifier(
ClassName $className,
ObjectInterface $configurationObject,
$identifier
): self {
$this->identifiers[$identifier] = $configurationObject;
$this->objects[$className->getIdentifier()] = $configurationObject;
return $this;
}
|
[
"public",
"function",
"addConfigurationObjectWithIdentifier",
"(",
"ClassName",
"$",
"className",
",",
"ObjectInterface",
"$",
"configurationObject",
",",
"$",
"identifier",
")",
":",
"self",
"{",
"$",
"this",
"->",
"identifiers",
"[",
"$",
"identifier",
"]",
"=",
"$",
"configurationObject",
";",
"$",
"this",
"->",
"objects",
"[",
"$",
"className",
"->",
"getIdentifier",
"(",
")",
"]",
"=",
"$",
"configurationObject",
";",
"return",
"$",
"this",
";",
"}"
] |
@param ClassName $className
@param ObjectInterface $configurationObject
@param string $identifier
@return Configuration
|
[
"@param",
"ClassName",
"$className",
"@param",
"ObjectInterface",
"$configurationObject",
"@param",
"string",
"$identifier"
] |
train
|
https://github.com/blackprism/serializer/blob/f5bd6ebeec802d2ad747daba7c9211b252ee4776/src/Blackprism/Serializer/Configuration.php#L75-L84
|
blackprism/serializer
|
src/Blackprism/Serializer/Configuration.php
|
Configuration.getConfigurationObjectForClass
|
public function getConfigurationObjectForClass(ClassName $className): ObjectInterface
{
if (isset($this->objects[$className->getIdentifier()]) === true) {
return $this->objects[$className->getIdentifier()];
}
return new Blackhole();
}
|
php
|
public function getConfigurationObjectForClass(ClassName $className): ObjectInterface
{
if (isset($this->objects[$className->getIdentifier()]) === true) {
return $this->objects[$className->getIdentifier()];
}
return new Blackhole();
}
|
[
"public",
"function",
"getConfigurationObjectForClass",
"(",
"ClassName",
"$",
"className",
")",
":",
"ObjectInterface",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"className",
"->",
"getIdentifier",
"(",
")",
"]",
")",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"objects",
"[",
"$",
"className",
"->",
"getIdentifier",
"(",
")",
"]",
";",
"}",
"return",
"new",
"Blackhole",
"(",
")",
";",
"}"
] |
@param ClassName $className
@return ObjectInterface
|
[
"@param",
"ClassName",
"$className"
] |
train
|
https://github.com/blackprism/serializer/blob/f5bd6ebeec802d2ad747daba7c9211b252ee4776/src/Blackprism/Serializer/Configuration.php#L91-L98
|
blackprism/serializer
|
src/Blackprism/Serializer/Configuration.php
|
Configuration.getConfigurationObjectForIdentifier
|
public function getConfigurationObjectForIdentifier(string $identifier): ObjectInterface
{
if (isset($this->identifiers[$identifier]) === true) {
return $this->identifiers[$identifier];
}
return new Blackhole();
}
|
php
|
public function getConfigurationObjectForIdentifier(string $identifier): ObjectInterface
{
if (isset($this->identifiers[$identifier]) === true) {
return $this->identifiers[$identifier];
}
return new Blackhole();
}
|
[
"public",
"function",
"getConfigurationObjectForIdentifier",
"(",
"string",
"$",
"identifier",
")",
":",
"ObjectInterface",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"identifiers",
"[",
"$",
"identifier",
"]",
")",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"identifiers",
"[",
"$",
"identifier",
"]",
";",
"}",
"return",
"new",
"Blackhole",
"(",
")",
";",
"}"
] |
@param string $identifier
@return ObjectInterface
|
[
"@param",
"string",
"$identifier"
] |
train
|
https://github.com/blackprism/serializer/blob/f5bd6ebeec802d2ad747daba7c9211b252ee4776/src/Blackprism/Serializer/Configuration.php#L105-L112
|
bocharsky-bw/FileNamingResolver
|
src/NamingStrategy/AbstractHashNamingStrategy.php
|
AbstractHashNamingStrategy.provideNameByHash
|
public function provideNameByHash(FileInfo $srcFileInfo, $hash)
{
$pathSuffixParts = array();
for ($i = 0; $i < $this->partCount; $i++) {
$pathSuffixParts[] = substr($hash, $i * $this->partLength, $this->partLength);
}
if ($this->shouldFullFilenameBeKept) {
$name = $hash;
} else {
$name = substr($hash, $i * $this->partLength);
}
$pathSuffix = implode(FileInfo::SEPARATOR_DIRECTORY, $pathSuffixParts);
$dstFileInfo = $srcFileInfo
->changeBasename($name)
->changePath($srcFileInfo->getPath().FileInfo::SEPARATOR_DIRECTORY.$pathSuffix)
;
return $dstFileInfo;
}
|
php
|
public function provideNameByHash(FileInfo $srcFileInfo, $hash)
{
$pathSuffixParts = array();
for ($i = 0; $i < $this->partCount; $i++) {
$pathSuffixParts[] = substr($hash, $i * $this->partLength, $this->partLength);
}
if ($this->shouldFullFilenameBeKept) {
$name = $hash;
} else {
$name = substr($hash, $i * $this->partLength);
}
$pathSuffix = implode(FileInfo::SEPARATOR_DIRECTORY, $pathSuffixParts);
$dstFileInfo = $srcFileInfo
->changeBasename($name)
->changePath($srcFileInfo->getPath().FileInfo::SEPARATOR_DIRECTORY.$pathSuffix)
;
return $dstFileInfo;
}
|
[
"public",
"function",
"provideNameByHash",
"(",
"FileInfo",
"$",
"srcFileInfo",
",",
"$",
"hash",
")",
"{",
"$",
"pathSuffixParts",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"partCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"pathSuffixParts",
"[",
"]",
"=",
"substr",
"(",
"$",
"hash",
",",
"$",
"i",
"*",
"$",
"this",
"->",
"partLength",
",",
"$",
"this",
"->",
"partLength",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"shouldFullFilenameBeKept",
")",
"{",
"$",
"name",
"=",
"$",
"hash",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"hash",
",",
"$",
"i",
"*",
"$",
"this",
"->",
"partLength",
")",
";",
"}",
"$",
"pathSuffix",
"=",
"implode",
"(",
"FileInfo",
"::",
"SEPARATOR_DIRECTORY",
",",
"$",
"pathSuffixParts",
")",
";",
"$",
"dstFileInfo",
"=",
"$",
"srcFileInfo",
"->",
"changeBasename",
"(",
"$",
"name",
")",
"->",
"changePath",
"(",
"$",
"srcFileInfo",
"->",
"getPath",
"(",
")",
".",
"FileInfo",
"::",
"SEPARATOR_DIRECTORY",
".",
"$",
"pathSuffix",
")",
";",
"return",
"$",
"dstFileInfo",
";",
"}"
] |
@param FileInfo $srcFileInfo
@param string $hash
@return FileInfo
|
[
"@param",
"FileInfo",
"$srcFileInfo",
"@param",
"string",
"$hash"
] |
train
|
https://github.com/bocharsky-bw/FileNamingResolver/blob/0a0fe86fee0e7acf1ab43a84c1abd51954ce2fbe/src/NamingStrategy/AbstractHashNamingStrategy.php#L55-L73
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/TokenAwareUser.php
|
TokenAwareUser.createToken
|
public function createToken(string $tokenSalt): Token
{
$this->setToken(Token::create($this, $tokenSalt));
return $this->token();
}
|
php
|
public function createToken(string $tokenSalt): Token
{
$this->setToken(Token::create($this, $tokenSalt));
return $this->token();
}
|
[
"public",
"function",
"createToken",
"(",
"string",
"$",
"tokenSalt",
")",
":",
"Token",
"{",
"$",
"this",
"->",
"setToken",
"(",
"Token",
"::",
"create",
"(",
"$",
"this",
",",
"$",
"tokenSalt",
")",
")",
";",
"return",
"$",
"this",
"->",
"token",
"(",
")",
";",
"}"
] |
creates new token for the user with given token salt
The token is already stored in the user afterwards, any further request
to token() will yield the same token.
@param string $tokenSalt
@return \stubbles\webapp\auth\Token
|
[
"creates",
"new",
"token",
"for",
"the",
"user",
"with",
"given",
"token",
"salt"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/TokenAwareUser.php#L47-L51
|
drpdigital/json-api-parser
|
src/ResourceResolver.php
|
ResourceResolver.bindFetcher
|
public function bindFetcher($fetcherKey, $relationshipName, $callback = null)
{
if ($callback !== null) {
$this->fetcherRelationships[$fetcherKey][] = $relationshipName;
}
$callback = $callback ?: $relationshipName;
$this->fetchers[$fetcherKey] = $callback;
}
|
php
|
public function bindFetcher($fetcherKey, $relationshipName, $callback = null)
{
if ($callback !== null) {
$this->fetcherRelationships[$fetcherKey][] = $relationshipName;
}
$callback = $callback ?: $relationshipName;
$this->fetchers[$fetcherKey] = $callback;
}
|
[
"public",
"function",
"bindFetcher",
"(",
"$",
"fetcherKey",
",",
"$",
"relationshipName",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"callback",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"fetcherRelationships",
"[",
"$",
"fetcherKey",
"]",
"[",
"]",
"=",
"$",
"relationshipName",
";",
"}",
"$",
"callback",
"=",
"$",
"callback",
"?",
":",
"$",
"relationshipName",
";",
"$",
"this",
"->",
"fetchers",
"[",
"$",
"fetcherKey",
"]",
"=",
"$",
"callback",
";",
"}"
] |
Adds the callback to fetch a resolved relationship for a parameter on a resolver.
@param string $fetcherKey
@param string|callable $relationshipName
@param callable|string $callback
@return void
|
[
"Adds",
"the",
"callback",
"to",
"fetch",
"a",
"resolved",
"relationship",
"for",
"a",
"parameter",
"on",
"a",
"resolver",
"."
] |
train
|
https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L109-L118
|
drpdigital/json-api-parser
|
src/ResourceResolver.php
|
ResourceResolver.buildParametersForResolver
|
protected function buildParametersForResolver($resolver, array $parents, array $defaultParameters)
{
$reflector = $this->getCallReflector($resolver);
$parameters = $reflector->getParameters();
$defaultParameters = array_reverse($defaultParameters);
return array_map(function (\ReflectionParameter $parameter) use (&$defaultParameters, $parents) {
$parameterClass = $parameter->getClass();
// If the parameter doesn't have a class then it isn't type hinted
// and thus no need for dependency injection.
if ($parameterClass === null) {
return array_pop($defaultParameters);
}
$fetched = $this->findFetchedResource($parameter, $parameterClass);
if ($fetched !== null) {
return $fetched;
}
// If the parameter asks for a dependency then check parents first
// and then fallback to the application IOC
$parent = $this->findParent($parameterClass, $parents);
if ($parent !== null) {
return $parent;
}
foreach ($this->customParameterResolvers as $parameterResolver) {
$resolved = $this->callResolver(
$parameterResolver,
[
$parameter,
Arr::get($this->resource, 'id'),
Arr::get($this->resource, 'type'),
]
);
if ($resolved !== null) {
return $resolved;
}
}
if ($this->container->has($parameterClass->getName())) {
return $this->container->get($parameterClass->getName());
}
return null;
}, $parameters);
}
|
php
|
protected function buildParametersForResolver($resolver, array $parents, array $defaultParameters)
{
$reflector = $this->getCallReflector($resolver);
$parameters = $reflector->getParameters();
$defaultParameters = array_reverse($defaultParameters);
return array_map(function (\ReflectionParameter $parameter) use (&$defaultParameters, $parents) {
$parameterClass = $parameter->getClass();
// If the parameter doesn't have a class then it isn't type hinted
// and thus no need for dependency injection.
if ($parameterClass === null) {
return array_pop($defaultParameters);
}
$fetched = $this->findFetchedResource($parameter, $parameterClass);
if ($fetched !== null) {
return $fetched;
}
// If the parameter asks for a dependency then check parents first
// and then fallback to the application IOC
$parent = $this->findParent($parameterClass, $parents);
if ($parent !== null) {
return $parent;
}
foreach ($this->customParameterResolvers as $parameterResolver) {
$resolved = $this->callResolver(
$parameterResolver,
[
$parameter,
Arr::get($this->resource, 'id'),
Arr::get($this->resource, 'type'),
]
);
if ($resolved !== null) {
return $resolved;
}
}
if ($this->container->has($parameterClass->getName())) {
return $this->container->get($parameterClass->getName());
}
return null;
}, $parameters);
}
|
[
"protected",
"function",
"buildParametersForResolver",
"(",
"$",
"resolver",
",",
"array",
"$",
"parents",
",",
"array",
"$",
"defaultParameters",
")",
"{",
"$",
"reflector",
"=",
"$",
"this",
"->",
"getCallReflector",
"(",
"$",
"resolver",
")",
";",
"$",
"parameters",
"=",
"$",
"reflector",
"->",
"getParameters",
"(",
")",
";",
"$",
"defaultParameters",
"=",
"array_reverse",
"(",
"$",
"defaultParameters",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"\\",
"ReflectionParameter",
"$",
"parameter",
")",
"use",
"(",
"&",
"$",
"defaultParameters",
",",
"$",
"parents",
")",
"{",
"$",
"parameterClass",
"=",
"$",
"parameter",
"->",
"getClass",
"(",
")",
";",
"// If the parameter doesn't have a class then it isn't type hinted",
"// and thus no need for dependency injection.",
"if",
"(",
"$",
"parameterClass",
"===",
"null",
")",
"{",
"return",
"array_pop",
"(",
"$",
"defaultParameters",
")",
";",
"}",
"$",
"fetched",
"=",
"$",
"this",
"->",
"findFetchedResource",
"(",
"$",
"parameter",
",",
"$",
"parameterClass",
")",
";",
"if",
"(",
"$",
"fetched",
"!==",
"null",
")",
"{",
"return",
"$",
"fetched",
";",
"}",
"// If the parameter asks for a dependency then check parents first",
"// and then fallback to the application IOC",
"$",
"parent",
"=",
"$",
"this",
"->",
"findParent",
"(",
"$",
"parameterClass",
",",
"$",
"parents",
")",
";",
"if",
"(",
"$",
"parent",
"!==",
"null",
")",
"{",
"return",
"$",
"parent",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"customParameterResolvers",
"as",
"$",
"parameterResolver",
")",
"{",
"$",
"resolved",
"=",
"$",
"this",
"->",
"callResolver",
"(",
"$",
"parameterResolver",
",",
"[",
"$",
"parameter",
",",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"resource",
",",
"'id'",
")",
",",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"resource",
",",
"'type'",
")",
",",
"]",
")",
";",
"if",
"(",
"$",
"resolved",
"!==",
"null",
")",
"{",
"return",
"$",
"resolved",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"parameterClass",
"->",
"getName",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"parameterClass",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}",
",",
"$",
"parameters",
")",
";",
"}"
] |
Build the parameters needed for the function given
@param callable|string $resolver
@param array $parents
@param array $defaultParameters
@return array
@throws \Psr\Container\NotFoundExceptionInterface
@throws \Psr\Container\ContainerExceptionInterface
@throws \ReflectionException
|
[
"Build",
"the",
"parameters",
"needed",
"for",
"the",
"function",
"given"
] |
train
|
https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L205-L256
|
drpdigital/json-api-parser
|
src/ResourceResolver.php
|
ResourceResolver.findParent
|
protected function findParent(\ReflectionClass $class, $parents)
{
$parents = array_reverse($parents);
foreach (array_reverse($parents) as $parent) {
if ($class->getName() === get_class($parent)) {
return $parent;
}
}
foreach (array_reverse($parents) as $parent) {
if ($class->isInstance($parent)) {
return $parent;
}
}
return null;
}
|
php
|
protected function findParent(\ReflectionClass $class, $parents)
{
$parents = array_reverse($parents);
foreach (array_reverse($parents) as $parent) {
if ($class->getName() === get_class($parent)) {
return $parent;
}
}
foreach (array_reverse($parents) as $parent) {
if ($class->isInstance($parent)) {
return $parent;
}
}
return null;
}
|
[
"protected",
"function",
"findParent",
"(",
"\\",
"ReflectionClass",
"$",
"class",
",",
"$",
"parents",
")",
"{",
"$",
"parents",
"=",
"array_reverse",
"(",
"$",
"parents",
")",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"parents",
")",
"as",
"$",
"parent",
")",
"{",
"if",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
"===",
"get_class",
"(",
"$",
"parent",
")",
")",
"{",
"return",
"$",
"parent",
";",
"}",
"}",
"foreach",
"(",
"array_reverse",
"(",
"$",
"parents",
")",
"as",
"$",
"parent",
")",
"{",
"if",
"(",
"$",
"class",
"->",
"isInstance",
"(",
"$",
"parent",
")",
")",
"{",
"return",
"$",
"parent",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Try to find a parent that matches the class
@param \ReflectionClass $class
@param array $parents
@return mixed|null
|
[
"Try",
"to",
"find",
"a",
"parent",
"that",
"matches",
"the",
"class"
] |
train
|
https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L285-L302
|
drpdigital/json-api-parser
|
src/ResourceResolver.php
|
ResourceResolver.getResolverForType
|
private function getResolverForType($type)
{
$resolver = Arr::get($this->resolvers, $type);
if ($resolver !== null) {
return $resolver;
}
$parts = explode('.', $type);
if (count($parts) > 1) {
array_shift($parts);
return $this->getResolverForType(implode('.', $parts));
}
return null;
}
|
php
|
private function getResolverForType($type)
{
$resolver = Arr::get($this->resolvers, $type);
if ($resolver !== null) {
return $resolver;
}
$parts = explode('.', $type);
if (count($parts) > 1) {
array_shift($parts);
return $this->getResolverForType(implode('.', $parts));
}
return null;
}
|
[
"private",
"function",
"getResolverForType",
"(",
"$",
"type",
")",
"{",
"$",
"resolver",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"resolvers",
",",
"$",
"type",
")",
";",
"if",
"(",
"$",
"resolver",
"!==",
"null",
")",
"{",
"return",
"$",
"resolver",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"type",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"1",
")",
"{",
"array_shift",
"(",
"$",
"parts",
")",
";",
"return",
"$",
"this",
"->",
"getResolverForType",
"(",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Find the resolver for the type given
Fallback the specificity of the type until we find a match. For example
if a type of customer.products.customer_product is passed we first check
for that, then products.customer_product and then customer_product.
@param string $type
@return mixed
|
[
"Find",
"the",
"resolver",
"for",
"the",
"type",
"given"
] |
train
|
https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L314-L330
|
drpdigital/json-api-parser
|
src/ResourceResolver.php
|
ResourceResolver.remove
|
public function remove($resolverType)
{
$resolverType = Arr::wrap($resolverType);
foreach ($resolverType as $type) {
unset($this->resolvers[$type]);
}
}
|
php
|
public function remove($resolverType)
{
$resolverType = Arr::wrap($resolverType);
foreach ($resolverType as $type) {
unset($this->resolvers[$type]);
}
}
|
[
"public",
"function",
"remove",
"(",
"$",
"resolverType",
")",
"{",
"$",
"resolverType",
"=",
"Arr",
"::",
"wrap",
"(",
"$",
"resolverType",
")",
";",
"foreach",
"(",
"$",
"resolverType",
"as",
"$",
"type",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"resolvers",
"[",
"$",
"type",
"]",
")",
";",
"}",
"}"
] |
Remove a resolver(s)
@param string|array $resolverType
@return void
|
[
"Remove",
"a",
"resolver",
"(",
"s",
")"
] |
train
|
https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L338-L345
|
drpdigital/json-api-parser
|
src/ResourceResolver.php
|
ResourceResolver.callResolver
|
protected function callResolver($resolver, $parameters)
{
if (is_string($resolver)) {
return call_user_func_array($resolver, $parameters);
}
if (count($parameters) === 0) {
return $resolver();
}
if (count($parameters) === 1) {
return $resolver($parameters[0]);
}
if (count($parameters) === 2) {
return $resolver($parameters[0], $parameters[1]);
}
if (count($parameters) === 3) {
return $resolver($parameters[0], $parameters[1], $parameters[2]);
}
if (count($parameters) === 4) {
return $resolver($parameters[0], $parameters[1], $parameters[2], $parameters[3]);
}
return call_user_func_array($resolver, $parameters);
}
|
php
|
protected function callResolver($resolver, $parameters)
{
if (is_string($resolver)) {
return call_user_func_array($resolver, $parameters);
}
if (count($parameters) === 0) {
return $resolver();
}
if (count($parameters) === 1) {
return $resolver($parameters[0]);
}
if (count($parameters) === 2) {
return $resolver($parameters[0], $parameters[1]);
}
if (count($parameters) === 3) {
return $resolver($parameters[0], $parameters[1], $parameters[2]);
}
if (count($parameters) === 4) {
return $resolver($parameters[0], $parameters[1], $parameters[2], $parameters[3]);
}
return call_user_func_array($resolver, $parameters);
}
|
[
"protected",
"function",
"callResolver",
"(",
"$",
"resolver",
",",
"$",
"parameters",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"resolver",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"resolver",
",",
"$",
"parameters",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"0",
")",
"{",
"return",
"$",
"resolver",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"1",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parameters",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"2",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parameters",
"[",
"0",
"]",
",",
"$",
"parameters",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"3",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parameters",
"[",
"0",
"]",
",",
"$",
"parameters",
"[",
"1",
"]",
",",
"$",
"parameters",
"[",
"2",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"4",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parameters",
"[",
"0",
"]",
",",
"$",
"parameters",
"[",
"1",
"]",
",",
"$",
"parameters",
"[",
"2",
"]",
",",
"$",
"parameters",
"[",
"3",
"]",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"$",
"resolver",
",",
"$",
"parameters",
")",
";",
"}"
] |
Call the resolver with the given parameters.
@param callable $resolver
@param array $parameters
@return mixed
|
[
"Call",
"the",
"resolver",
"with",
"the",
"given",
"parameters",
"."
] |
train
|
https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L354-L381
|
drpdigital/json-api-parser
|
src/ResourceResolver.php
|
ResourceResolver.recordFetchedRelationship
|
protected function recordFetchedRelationship(RelationshipResource $relationship)
{
$this->fetchedRelationships[] = $this->resource['type'] .
'.' . $relationship->getName() .
'.' . $relationship->getType();
}
|
php
|
protected function recordFetchedRelationship(RelationshipResource $relationship)
{
$this->fetchedRelationships[] = $this->resource['type'] .
'.' . $relationship->getName() .
'.' . $relationship->getType();
}
|
[
"protected",
"function",
"recordFetchedRelationship",
"(",
"RelationshipResource",
"$",
"relationship",
")",
"{",
"$",
"this",
"->",
"fetchedRelationships",
"[",
"]",
"=",
"$",
"this",
"->",
"resource",
"[",
"'type'",
"]",
".",
"'.'",
".",
"$",
"relationship",
"->",
"getName",
"(",
")",
".",
"'.'",
".",
"$",
"relationship",
"->",
"getType",
"(",
")",
";",
"}"
] |
Save that a resource has been fetched.
@param \Drp\JsonApiParser\RelationshipResource $relationship
@return void
|
[
"Save",
"that",
"a",
"resource",
"has",
"been",
"fetched",
"."
] |
train
|
https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L447-L452
|
mayoturis/properties-ini
|
src/Repository.php
|
Repository.set
|
public function set($key, $value) {
$this->loadIfNeeded();
$this->array[$key] = $value;
$this->saver->save($this->fileName, $this->array, $this->fileMap);
}
|
php
|
public function set($key, $value) {
$this->loadIfNeeded();
$this->array[$key] = $value;
$this->saver->save($this->fileName, $this->array, $this->fileMap);
}
|
[
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"loadIfNeeded",
"(",
")",
";",
"$",
"this",
"->",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"saver",
"->",
"save",
"(",
"$",
"this",
"->",
"fileName",
",",
"$",
"this",
"->",
"array",
",",
"$",
"this",
"->",
"fileMap",
")",
";",
"}"
] |
Set a given configuration value and save file
@param string $key
@param mixed $value
@return void
|
[
"Set",
"a",
"given",
"configuration",
"value",
"and",
"save",
"file"
] |
train
|
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/Repository.php#L44-L50
|
mayoturis/properties-ini
|
src/Repository.php
|
Repository.setAll
|
public function setAll($array) {
$this->array = $array;
$this->fileMap = null;
$this->saver->save($this->fileName, $this->array, $this->fileMap);
}
|
php
|
public function setAll($array) {
$this->array = $array;
$this->fileMap = null;
$this->saver->save($this->fileName, $this->array, $this->fileMap);
}
|
[
"public",
"function",
"setAll",
"(",
"$",
"array",
")",
"{",
"$",
"this",
"->",
"array",
"=",
"$",
"array",
";",
"$",
"this",
"->",
"fileMap",
"=",
"null",
";",
"$",
"this",
"->",
"saver",
"->",
"save",
"(",
"$",
"this",
"->",
"fileName",
",",
"$",
"this",
"->",
"array",
",",
"$",
"this",
"->",
"fileMap",
")",
";",
"}"
] |
Change all configuration values and save file
@param array $array Associative array with key and value
@return void
|
[
"Change",
"all",
"configuration",
"values",
"and",
"save",
"file"
] |
train
|
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/Repository.php#L58-L63
|
mayoturis/properties-ini
|
src/Repository.php
|
Repository.get
|
public function get($key, $default = null) {
$this->loadIfNeeded();
return isset($this->array[$key]) ? $this->array[$key] : $default;
}
|
php
|
public function get($key, $default = null) {
$this->loadIfNeeded();
return isset($this->array[$key]) ? $this->array[$key] : $default;
}
|
[
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"loadIfNeeded",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"array",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"array",
"[",
"$",
"key",
"]",
":",
"$",
"default",
";",
"}"
] |
Return configuration value
@param string $key
@param string|null $default
@return mixed
|
[
"Return",
"configuration",
"value"
] |
train
|
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/Repository.php#L72-L76
|
stubbles/stubbles-webapp-core
|
src/main/php/response/mimetypes/PassThrough.php
|
PassThrough.serialize
|
public function serialize($resource, OutputStream $out): OutputStream
{
$out->write((string) $resource);
return $out;
}
|
php
|
public function serialize($resource, OutputStream $out): OutputStream
{
$out->write((string) $resource);
return $out;
}
|
[
"public",
"function",
"serialize",
"(",
"$",
"resource",
",",
"OutputStream",
"$",
"out",
")",
":",
"OutputStream",
"{",
"$",
"out",
"->",
"write",
"(",
"(",
"string",
")",
"$",
"resource",
")",
";",
"return",
"$",
"out",
";",
"}"
] |
serializes resource to output stream
@param mixed $resource
@param \stubbles\streams\OutputStream $out
@return \stubbles\streams\OutputStream
|
[
"serializes",
"resource",
"to",
"output",
"stream"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/response/mimetypes/PassThrough.php#L37-L41
|
huasituo/hstcms
|
src/Database/Migrations/2016_11_23_152536_create_sms_code_table.php
|
CreateSmsCodeTable.up
|
public function up()
{
//
Schema::create('sms_code', function (Blueprint $table)
{
$table->string('mobile', 30)->default('')->comment(hst_lang('hstcms::public.mobile'));
$table->string('type', 30)->default('')->comment(hst_lang('hstcms::public.type'));
$table->string('code', 30)->default('')->comment(hst_lang('hstcms::public.code'));
$table->string('number', 30)->default('')->comment(hst_lang('hstcms::public.type'));
$table->integer('expired_time')->nullable()->comment();
$table->integer('create_time')->nullable()->comment(hst_lang('hstcms::public.times'));
$table->unique(['mobile','type']);
});
}
|
php
|
public function up()
{
//
Schema::create('sms_code', function (Blueprint $table)
{
$table->string('mobile', 30)->default('')->comment(hst_lang('hstcms::public.mobile'));
$table->string('type', 30)->default('')->comment(hst_lang('hstcms::public.type'));
$table->string('code', 30)->default('')->comment(hst_lang('hstcms::public.code'));
$table->string('number', 30)->default('')->comment(hst_lang('hstcms::public.type'));
$table->integer('expired_time')->nullable()->comment();
$table->integer('create_time')->nullable()->comment(hst_lang('hstcms::public.times'));
$table->unique(['mobile','type']);
});
}
|
[
"public",
"function",
"up",
"(",
")",
"{",
"//",
"Schema",
"::",
"create",
"(",
"'sms_code'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"string",
"(",
"'mobile'",
",",
"30",
")",
"->",
"default",
"(",
"''",
")",
"->",
"comment",
"(",
"hst_lang",
"(",
"'hstcms::public.mobile'",
")",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'type'",
",",
"30",
")",
"->",
"default",
"(",
"''",
")",
"->",
"comment",
"(",
"hst_lang",
"(",
"'hstcms::public.type'",
")",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'code'",
",",
"30",
")",
"->",
"default",
"(",
"''",
")",
"->",
"comment",
"(",
"hst_lang",
"(",
"'hstcms::public.code'",
")",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'number'",
",",
"30",
")",
"->",
"default",
"(",
"''",
")",
"->",
"comment",
"(",
"hst_lang",
"(",
"'hstcms::public.type'",
")",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'expired_time'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'create_time'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
"hst_lang",
"(",
"'hstcms::public.times'",
")",
")",
";",
"$",
"table",
"->",
"unique",
"(",
"[",
"'mobile'",
",",
"'type'",
"]",
")",
";",
"}",
")",
";",
"}"
] |
Run the migrations.
@return void
|
[
"Run",
"the",
"migrations",
"."
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Database/Migrations/2016_11_23_152536_create_sms_code_table.php#L18-L31
|
esperecyan/dictionary-php
|
src/validator/SpecificsValidator.php
|
SpecificsValidator.parse
|
protected function parse(string $urlencoded): array
{
$specifics = [];
foreach (new URLSearchParams($urlencoded) as $name => $value) {
$specifics[$name][] = $value;
}
return $specifics;
}
|
php
|
protected function parse(string $urlencoded): array
{
$specifics = [];
foreach (new URLSearchParams($urlencoded) as $name => $value) {
$specifics[$name][] = $value;
}
return $specifics;
}
|
[
"protected",
"function",
"parse",
"(",
"string",
"$",
"urlencoded",
")",
":",
"array",
"{",
"$",
"specifics",
"=",
"[",
"]",
";",
"foreach",
"(",
"new",
"URLSearchParams",
"(",
"$",
"urlencoded",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"specifics",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"specifics",
";",
"}"
] |
フィールドを解析し、同名の値の配列を値に持つ連想配列として返します。
@param string $urlencoded
@return string[][]
|
[
"フィールドを解析し、同名の値の配列を値に持つ連想配列として返します。"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/validator/SpecificsValidator.php#L22-L29
|
tonicospinelli/class-generation
|
src/ClassGeneration/ArgumentCollection.php
|
ArgumentCollection.add
|
public function add($argument)
{
if (!$argument instanceof ArgumentInterface) {
throw new \InvalidArgumentException(
'This Argument must be a instance of \ClassGeneration\ArgumentInterface'
);
}
if ($argument->getName() === null) {
$argument->setName('param' . ($this->count() + 1));
}
parent::offsetSet($argument->getName(), $argument);
return true;
}
|
php
|
public function add($argument)
{
if (!$argument instanceof ArgumentInterface) {
throw new \InvalidArgumentException(
'This Argument must be a instance of \ClassGeneration\ArgumentInterface'
);
}
if ($argument->getName() === null) {
$argument->setName('param' . ($this->count() + 1));
}
parent::offsetSet($argument->getName(), $argument);
return true;
}
|
[
"public",
"function",
"add",
"(",
"$",
"argument",
")",
"{",
"if",
"(",
"!",
"$",
"argument",
"instanceof",
"ArgumentInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'This Argument must be a instance of \\ClassGeneration\\ArgumentInterface'",
")",
";",
"}",
"if",
"(",
"$",
"argument",
"->",
"getName",
"(",
")",
"===",
"null",
")",
"{",
"$",
"argument",
"->",
"setName",
"(",
"'param'",
".",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"+",
"1",
")",
")",
";",
"}",
"parent",
"::",
"offsetSet",
"(",
"$",
"argument",
"->",
"getName",
"(",
")",
",",
"$",
"argument",
")",
";",
"return",
"true",
";",
"}"
] |
Add a Argument on collection.<br />
The index is a argument name, then will replace
if exist a index with the same name.
@param ArgumentInterface $argument
@throws \InvalidArgumentException
@return boolean
|
[
"Add",
"a",
"Argument",
"on",
"collection",
".",
"<br",
"/",
">",
"The",
"index",
"is",
"a",
"argument",
"name",
"then",
"will",
"replace",
"if",
"exist",
"a",
"index",
"with",
"the",
"same",
"name",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/ArgumentCollection.php#L33-L47
|
tonicospinelli/class-generation
|
src/ClassGeneration/ArgumentCollection.php
|
ArgumentCollection.toString
|
public function toString()
{
$arguments = $this->getIterator();
$params = array();
$optionals = array();
foreach ($arguments as $argument) {
if ($argument->isOptional()) {
$optionals[] = $argument->toString();
} else {
$params[] = $argument->toString();
}
}
return implode(', ', array_merge($params, $optionals));
}
|
php
|
public function toString()
{
$arguments = $this->getIterator();
$params = array();
$optionals = array();
foreach ($arguments as $argument) {
if ($argument->isOptional()) {
$optionals[] = $argument->toString();
} else {
$params[] = $argument->toString();
}
}
return implode(', ', array_merge($params, $optionals));
}
|
[
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"optionals",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"argument",
")",
"{",
"if",
"(",
"$",
"argument",
"->",
"isOptional",
"(",
")",
")",
"{",
"$",
"optionals",
"[",
"]",
"=",
"$",
"argument",
"->",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"argument",
"->",
"toString",
"(",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"', '",
",",
"array_merge",
"(",
"$",
"params",
",",
"$",
"optionals",
")",
")",
";",
"}"
] |
Returns the arguments in string.
@return string
|
[
"Returns",
"the",
"arguments",
"in",
"string",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/ArgumentCollection.php#L62-L76
|
tonicospinelli/class-generation
|
src/ClassGeneration/ArgumentCollection.php
|
ArgumentCollection.removeByName
|
public function removeByName($argumentName)
{
$removedList = new self();
$list = $this->getIterator();
foreach ($list as $index => $argument) {
if (($argumentName instanceof Argument && $argumentName->getName() != $argument->getName())
|| (is_string($argumentName) && $argument->getName() !== $argumentName)
) {
continue;
}
$removedList->add(clone $argument);
$this->remove($index);
}
return $removedList;
}
|
php
|
public function removeByName($argumentName)
{
$removedList = new self();
$list = $this->getIterator();
foreach ($list as $index => $argument) {
if (($argumentName instanceof Argument && $argumentName->getName() != $argument->getName())
|| (is_string($argumentName) && $argument->getName() !== $argumentName)
) {
continue;
}
$removedList->add(clone $argument);
$this->remove($index);
}
return $removedList;
}
|
[
"public",
"function",
"removeByName",
"(",
"$",
"argumentName",
")",
"{",
"$",
"removedList",
"=",
"new",
"self",
"(",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"index",
"=>",
"$",
"argument",
")",
"{",
"if",
"(",
"(",
"$",
"argumentName",
"instanceof",
"Argument",
"&&",
"$",
"argumentName",
"->",
"getName",
"(",
")",
"!=",
"$",
"argument",
"->",
"getName",
"(",
")",
")",
"||",
"(",
"is_string",
"(",
"$",
"argumentName",
")",
"&&",
"$",
"argument",
"->",
"getName",
"(",
")",
"!==",
"$",
"argumentName",
")",
")",
"{",
"continue",
";",
"}",
"$",
"removedList",
"->",
"add",
"(",
"clone",
"$",
"argument",
")",
";",
"$",
"this",
"->",
"remove",
"(",
"$",
"index",
")",
";",
"}",
"return",
"$",
"removedList",
";",
"}"
] |
Removes tags by name.
@param string|array|Argument $argumentName
@return \ClassGeneration\ArgumentCollection
|
[
"Removes",
"tags",
"by",
"name",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/ArgumentCollection.php#L85-L100
|
vincentchalamon/VinceCmsSonataAdminBundle
|
Form/Type/MetaGroupType.php
|
MetaGroupType.buildForm
|
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addViewTransformer(new MetaTransformer($this->repository, $this->class));
$list = $this->repository->findAll();
$groups = array();
foreach ($list as $meta) {
/** @var Meta $meta */
if (!isset($groups[$meta->getGroup()])) {
$groups[$meta->getGroup()] = array();
}
$groups[$meta->getGroup()][] = $meta;
}
foreach ($groups as $name => $metas) {
$builder->add($name ?: 'general', 'meta', array(
'label' => $name,
'metas' => $metas,
)
);
}
}
|
php
|
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addViewTransformer(new MetaTransformer($this->repository, $this->class));
$list = $this->repository->findAll();
$groups = array();
foreach ($list as $meta) {
/** @var Meta $meta */
if (!isset($groups[$meta->getGroup()])) {
$groups[$meta->getGroup()] = array();
}
$groups[$meta->getGroup()][] = $meta;
}
foreach ($groups as $name => $metas) {
$builder->add($name ?: 'general', 'meta', array(
'label' => $name,
'metas' => $metas,
)
);
}
}
|
[
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"builder",
"->",
"addViewTransformer",
"(",
"new",
"MetaTransformer",
"(",
"$",
"this",
"->",
"repository",
",",
"$",
"this",
"->",
"class",
")",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"repository",
"->",
"findAll",
"(",
")",
";",
"$",
"groups",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"meta",
")",
"{",
"/** @var Meta $meta */",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
"[",
"$",
"meta",
"->",
"getGroup",
"(",
")",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"$",
"meta",
"->",
"getGroup",
"(",
")",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"groups",
"[",
"$",
"meta",
"->",
"getGroup",
"(",
")",
"]",
"[",
"]",
"=",
"$",
"meta",
";",
"}",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"name",
"=>",
"$",
"metas",
")",
"{",
"$",
"builder",
"->",
"add",
"(",
"$",
"name",
"?",
":",
"'general'",
",",
"'meta'",
",",
"array",
"(",
"'label'",
"=>",
"$",
"name",
",",
"'metas'",
"=>",
"$",
"metas",
",",
")",
")",
";",
"}",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Form/Type/MetaGroupType.php#L75-L94
|
acasademont/wurfl
|
WURFL/CapabilitiesHolder.php
|
WURFL_CapabilitiesHolder.getCapability
|
public function getCapability($capabilityName)
{
if (isset($this->_device->capabilities[$capabilityName])) {
return $this->_device->capabilities[$capabilityName];
}
$key = $this->_device->id . "_" . $capabilityName;
$capabilityValue = $this->_cacheProvider->get($key);
if (empty($capabilityValue)) {
$capabilityValue = $this->_deviceRepository->getCapabilityForDevice($this->_device->fallBack, $capabilityName);
// save it in cache
$this->_cacheProvider->put($key, $capabilityValue);
}
// prevent useless gets when retrieving the same capability from this device again
//$this->_device->capabilities[$capabilityName] = $capabilityValue;
return $capabilityValue;
}
|
php
|
public function getCapability($capabilityName)
{
if (isset($this->_device->capabilities[$capabilityName])) {
return $this->_device->capabilities[$capabilityName];
}
$key = $this->_device->id . "_" . $capabilityName;
$capabilityValue = $this->_cacheProvider->get($key);
if (empty($capabilityValue)) {
$capabilityValue = $this->_deviceRepository->getCapabilityForDevice($this->_device->fallBack, $capabilityName);
// save it in cache
$this->_cacheProvider->put($key, $capabilityValue);
}
// prevent useless gets when retrieving the same capability from this device again
//$this->_device->capabilities[$capabilityName] = $capabilityValue;
return $capabilityValue;
}
|
[
"public",
"function",
"getCapability",
"(",
"$",
"capabilityName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_device",
"->",
"capabilities",
"[",
"$",
"capabilityName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_device",
"->",
"capabilities",
"[",
"$",
"capabilityName",
"]",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"_device",
"->",
"id",
".",
"\"_\"",
".",
"$",
"capabilityName",
";",
"$",
"capabilityValue",
"=",
"$",
"this",
"->",
"_cacheProvider",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"capabilityValue",
")",
")",
"{",
"$",
"capabilityValue",
"=",
"$",
"this",
"->",
"_deviceRepository",
"->",
"getCapabilityForDevice",
"(",
"$",
"this",
"->",
"_device",
"->",
"fallBack",
",",
"$",
"capabilityName",
")",
";",
"// save it in cache",
"$",
"this",
"->",
"_cacheProvider",
"->",
"put",
"(",
"$",
"key",
",",
"$",
"capabilityValue",
")",
";",
"}",
"// prevent useless gets when retrieving the same capability from this device again",
"//$this->_device->capabilities[$capabilityName] = $capabilityValue;",
"return",
"$",
"capabilityValue",
";",
"}"
] |
Returns the value of a given capability name
@param string $capabilityName
@return string Capability value
@throws WURFLException if the value of the $capability name is illegal
|
[
"Returns",
"the",
"value",
"of",
"a",
"given",
"capability",
"name"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/CapabilitiesHolder.php#L56-L74
|
Wonail/wocenter
|
helpers/SecurityHelper.php
|
SecurityHelper.markEmail
|
public static function markEmail($str): string
{
list($first, $second) = explode('@', $str);
$a = strlen($first) - 3;
return preg_replace('|(?<=.{1})(.{' . $a . '}).*?|', str_pad('', $a, '*'), $first, 1) . '@' . $second;
}
|
php
|
public static function markEmail($str): string
{
list($first, $second) = explode('@', $str);
$a = strlen($first) - 3;
return preg_replace('|(?<=.{1})(.{' . $a . '}).*?|', str_pad('', $a, '*'), $first, 1) . '@' . $second;
}
|
[
"public",
"static",
"function",
"markEmail",
"(",
"$",
"str",
")",
":",
"string",
"{",
"list",
"(",
"$",
"first",
",",
"$",
"second",
")",
"=",
"explode",
"(",
"'@'",
",",
"$",
"str",
")",
";",
"$",
"a",
"=",
"strlen",
"(",
"$",
"first",
")",
"-",
"3",
";",
"return",
"preg_replace",
"(",
"'|(?<=.{1})(.{'",
".",
"$",
"a",
".",
"'}).*?|'",
",",
"str_pad",
"(",
"''",
",",
"$",
"a",
",",
"'*'",
")",
",",
"$",
"first",
",",
"1",
")",
".",
"'@'",
".",
"$",
"second",
";",
"}"
] |
保密邮箱地址
@param string $str 邮箱地址
@return string
|
[
"保密邮箱地址"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/SecurityHelper.php#L20-L26
|
Wonail/wocenter
|
helpers/SecurityHelper.php
|
SecurityHelper.markString
|
public static function markString($str): string
{
$str_len = strlen($str);
$start = 6 < $str_len ? intval($str_len / 5) : $str_len - 4;
$end = $str_len - $start * 3;
return preg_replace('|(?<=.{' . $start . '})(.{' . $end . '}).*?|', str_pad('', $end, '*'), $str, 1);
}
|
php
|
public static function markString($str): string
{
$str_len = strlen($str);
$start = 6 < $str_len ? intval($str_len / 5) : $str_len - 4;
$end = $str_len - $start * 3;
return preg_replace('|(?<=.{' . $start . '})(.{' . $end . '}).*?|', str_pad('', $end, '*'), $str, 1);
}
|
[
"public",
"static",
"function",
"markString",
"(",
"$",
"str",
")",
":",
"string",
"{",
"$",
"str_len",
"=",
"strlen",
"(",
"$",
"str",
")",
";",
"$",
"start",
"=",
"6",
"<",
"$",
"str_len",
"?",
"intval",
"(",
"$",
"str_len",
"/",
"5",
")",
":",
"$",
"str_len",
"-",
"4",
";",
"$",
"end",
"=",
"$",
"str_len",
"-",
"$",
"start",
"*",
"3",
";",
"return",
"preg_replace",
"(",
"'|(?<=.{'",
".",
"$",
"start",
".",
"'})(.{'",
".",
"$",
"end",
".",
"'}).*?|'",
",",
"str_pad",
"(",
"''",
",",
"$",
"end",
",",
"'*'",
")",
",",
"$",
"str",
",",
"1",
")",
";",
"}"
] |
保密字符串
@param string $str
@return string
|
[
"保密字符串"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/SecurityHelper.php#L51-L58
|
Wonail/wocenter
|
helpers/SecurityHelper.php
|
SecurityHelper.decrypt
|
public static function decrypt($data = '', $key = ''): string
{
$key = md5(empty($key) ? \Yii::$app->getRequest()->cookieValidationKey : $key);
$data = str_replace(['-', '_'], ['+', '/'], $data);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
$data = base64_decode($data);
$expire = substr($data, 0, 10);
$data = substr($data, 10);
if ($expire > 0 && $expire < time()) {
return '';
}
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = $str = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) {
$x = 0;
}
$char .= substr($key, $x, 1);
$x++;
}
for ($i = 0; $i < $len; $i++) {
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
} else {
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
return base64_decode($str);
}
|
php
|
public static function decrypt($data = '', $key = ''): string
{
$key = md5(empty($key) ? \Yii::$app->getRequest()->cookieValidationKey : $key);
$data = str_replace(['-', '_'], ['+', '/'], $data);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
$data = base64_decode($data);
$expire = substr($data, 0, 10);
$data = substr($data, 10);
if ($expire > 0 && $expire < time()) {
return '';
}
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = $str = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) {
$x = 0;
}
$char .= substr($key, $x, 1);
$x++;
}
for ($i = 0; $i < $len; $i++) {
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
} else {
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
return base64_decode($str);
}
|
[
"public",
"static",
"function",
"decrypt",
"(",
"$",
"data",
"=",
"''",
",",
"$",
"key",
"=",
"''",
")",
":",
"string",
"{",
"$",
"key",
"=",
"md5",
"(",
"empty",
"(",
"$",
"key",
")",
"?",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"cookieValidationKey",
":",
"$",
"key",
")",
";",
"$",
"data",
"=",
"str_replace",
"(",
"[",
"'-'",
",",
"'_'",
"]",
",",
"[",
"'+'",
",",
"'/'",
"]",
",",
"$",
"data",
")",
";",
"$",
"mod4",
"=",
"strlen",
"(",
"$",
"data",
")",
"%",
"4",
";",
"if",
"(",
"$",
"mod4",
")",
"{",
"$",
"data",
".=",
"substr",
"(",
"'===='",
",",
"$",
"mod4",
")",
";",
"}",
"$",
"data",
"=",
"base64_decode",
"(",
"$",
"data",
")",
";",
"$",
"expire",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"10",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"10",
")",
";",
"if",
"(",
"$",
"expire",
">",
"0",
"&&",
"$",
"expire",
"<",
"time",
"(",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"x",
"=",
"0",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"data",
")",
";",
"$",
"l",
"=",
"strlen",
"(",
"$",
"key",
")",
";",
"$",
"char",
"=",
"$",
"str",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"x",
"==",
"$",
"l",
")",
"{",
"$",
"x",
"=",
"0",
";",
"}",
"$",
"char",
".=",
"substr",
"(",
"$",
"key",
",",
"$",
"x",
",",
"1",
")",
";",
"$",
"x",
"++",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"ord",
"(",
"substr",
"(",
"$",
"data",
",",
"$",
"i",
",",
"1",
")",
")",
"<",
"ord",
"(",
"substr",
"(",
"$",
"char",
",",
"$",
"i",
",",
"1",
")",
")",
")",
"{",
"$",
"str",
".=",
"chr",
"(",
"(",
"ord",
"(",
"substr",
"(",
"$",
"data",
",",
"$",
"i",
",",
"1",
")",
")",
"+",
"256",
")",
"-",
"ord",
"(",
"substr",
"(",
"$",
"char",
",",
"$",
"i",
",",
"1",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"str",
".=",
"chr",
"(",
"ord",
"(",
"substr",
"(",
"$",
"data",
",",
"$",
"i",
",",
"1",
")",
")",
"-",
"ord",
"(",
"substr",
"(",
"$",
"char",
",",
"$",
"i",
",",
"1",
")",
")",
")",
";",
"}",
"}",
"return",
"base64_decode",
"(",
"$",
"str",
")",
";",
"}"
] |
系统解密方法
@param string $data 要解密的字符串
@param string $key 加密密钥
@return string
|
[
"系统解密方法"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/SecurityHelper.php#L79-L116
|
Wonail/wocenter
|
helpers/SecurityHelper.php
|
SecurityHelper.encrypt
|
public static function encrypt($data = '', $key = '', $expire = 0): string
{
$key = md5(empty($key) ? \Yii::$app->getRequest()->cookieValidationKey : $key);
$data = base64_encode($data);
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) {
$x = 0;
}
$char .= substr($key, $x, 1);
$x++;
}
$str = sprintf('%010d', $expire ? $expire + time() : 0);
for ($i = 0; $i < $len; $i++) {
$str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1))) % 256);
}
return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($str));
}
|
php
|
public static function encrypt($data = '', $key = '', $expire = 0): string
{
$key = md5(empty($key) ? \Yii::$app->getRequest()->cookieValidationKey : $key);
$data = base64_encode($data);
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) {
$x = 0;
}
$char .= substr($key, $x, 1);
$x++;
}
$str = sprintf('%010d', $expire ? $expire + time() : 0);
for ($i = 0; $i < $len; $i++) {
$str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1))) % 256);
}
return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($str));
}
|
[
"public",
"static",
"function",
"encrypt",
"(",
"$",
"data",
"=",
"''",
",",
"$",
"key",
"=",
"''",
",",
"$",
"expire",
"=",
"0",
")",
":",
"string",
"{",
"$",
"key",
"=",
"md5",
"(",
"empty",
"(",
"$",
"key",
")",
"?",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"cookieValidationKey",
":",
"$",
"key",
")",
";",
"$",
"data",
"=",
"base64_encode",
"(",
"$",
"data",
")",
";",
"$",
"x",
"=",
"0",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"data",
")",
";",
"$",
"l",
"=",
"strlen",
"(",
"$",
"key",
")",
";",
"$",
"char",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"x",
"==",
"$",
"l",
")",
"{",
"$",
"x",
"=",
"0",
";",
"}",
"$",
"char",
".=",
"substr",
"(",
"$",
"key",
",",
"$",
"x",
",",
"1",
")",
";",
"$",
"x",
"++",
";",
"}",
"$",
"str",
"=",
"sprintf",
"(",
"'%010d'",
",",
"$",
"expire",
"?",
"$",
"expire",
"+",
"time",
"(",
")",
":",
"0",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"$",
"str",
".=",
"chr",
"(",
"ord",
"(",
"substr",
"(",
"$",
"data",
",",
"$",
"i",
",",
"1",
")",
")",
"+",
"(",
"ord",
"(",
"substr",
"(",
"$",
"char",
",",
"$",
"i",
",",
"1",
")",
")",
")",
"%",
"256",
")",
";",
"}",
"return",
"str_replace",
"(",
"[",
"'+'",
",",
"'/'",
",",
"'='",
"]",
",",
"[",
"'-'",
",",
"'_'",
",",
"''",
"]",
",",
"base64_encode",
"(",
"$",
"str",
")",
")",
";",
"}"
] |
系统加密方法
@param string $data 要加密的字符串
@param string $key 加密密钥
@param integer $expire 过期时间 单位 秒
@return string
|
[
"系统加密方法"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/SecurityHelper.php#L127-L151
|
datasift/datasift-php
|
lib/DataSift/Account/Identity/Limit.php
|
DataSift_Account_Identity_Limit.getAll
|
public function getAll($service, $page = 1, $perPage = 25)
{
$params = array(
'page' => $page,
'per_page' => $perPage
);
return $this->_user->get('account/identity/limit/' . $service, $params);
}
|
php
|
public function getAll($service, $page = 1, $perPage = 25)
{
$params = array(
'page' => $page,
'per_page' => $perPage
);
return $this->_user->get('account/identity/limit/' . $service, $params);
}
|
[
"public",
"function",
"getAll",
"(",
"$",
"service",
",",
"$",
"page",
"=",
"1",
",",
"$",
"perPage",
"=",
"25",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'page'",
"=>",
"$",
"page",
",",
"'per_page'",
"=>",
"$",
"perPage",
")",
";",
"return",
"$",
"this",
"->",
"_user",
"->",
"get",
"(",
"'account/identity/limit/'",
".",
"$",
"service",
",",
"$",
"params",
")",
";",
"}"
] |
Get all the limits for a service
@param string $service
@param integer $page
@param integer $per_page
@return mixed
|
[
"Get",
"all",
"the",
"limits",
"for",
"a",
"service"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity/Limit.php#L50-L58
|
datasift/datasift-php
|
lib/DataSift/Account/Identity/Limit.php
|
DataSift_Account_Identity_Limit.create
|
public function create($identity, $service, $total_allowance = false, $analyze_queries = false)
{
$params = array(
'service' => $service,
);
if ($total_allowance) {
$params['total_allowance'] = $total_allowance;
}
if ($analyze_queries) {
$params['analyze_queries'] = $analyze_queries;
}
return $this->_user->post('account/identity/' . $identity . '/limit', $params);
}
|
php
|
public function create($identity, $service, $total_allowance = false, $analyze_queries = false)
{
$params = array(
'service' => $service,
);
if ($total_allowance) {
$params['total_allowance'] = $total_allowance;
}
if ($analyze_queries) {
$params['analyze_queries'] = $analyze_queries;
}
return $this->_user->post('account/identity/' . $identity . '/limit', $params);
}
|
[
"public",
"function",
"create",
"(",
"$",
"identity",
",",
"$",
"service",
",",
"$",
"total_allowance",
"=",
"false",
",",
"$",
"analyze_queries",
"=",
"false",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'service'",
"=>",
"$",
"service",
",",
")",
";",
"if",
"(",
"$",
"total_allowance",
")",
"{",
"$",
"params",
"[",
"'total_allowance'",
"]",
"=",
"$",
"total_allowance",
";",
"}",
"if",
"(",
"$",
"analyze_queries",
")",
"{",
"$",
"params",
"[",
"'analyze_queries'",
"]",
"=",
"$",
"analyze_queries",
";",
"}",
"return",
"$",
"this",
"->",
"_user",
"->",
"post",
"(",
"'account/identity/'",
".",
"$",
"identity",
".",
"'/limit'",
",",
"$",
"params",
")",
";",
"}"
] |
Create a limit for a service
@param string $identity
@param string $service
@param integer $total_allowance
@param integer $analyze_queries
@return mixed
|
[
"Create",
"a",
"limit",
"for",
"a",
"service"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity/Limit.php#L70-L85
|
datasift/datasift-php
|
lib/DataSift/Account/Identity/Limit.php
|
DataSift_Account_Identity_Limit.update
|
public function update($identity, $service, $total_allowance = false, $analyze_queries = false)
{
$params = array();
if ($total_allowance) {
$params['total_allowance'] = $total_allowance;
}
if ($analyze_queries) {
$params['analyze_queries'] = $analyze_queries;
}
return $response = $this->_user->put('account/identity/' . $identity . '/limit/' . $service, $params);
}
|
php
|
public function update($identity, $service, $total_allowance = false, $analyze_queries = false)
{
$params = array();
if ($total_allowance) {
$params['total_allowance'] = $total_allowance;
}
if ($analyze_queries) {
$params['analyze_queries'] = $analyze_queries;
}
return $response = $this->_user->put('account/identity/' . $identity . '/limit/' . $service, $params);
}
|
[
"public",
"function",
"update",
"(",
"$",
"identity",
",",
"$",
"service",
",",
"$",
"total_allowance",
"=",
"false",
",",
"$",
"analyze_queries",
"=",
"false",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"total_allowance",
")",
"{",
"$",
"params",
"[",
"'total_allowance'",
"]",
"=",
"$",
"total_allowance",
";",
"}",
"if",
"(",
"$",
"analyze_queries",
")",
"{",
"$",
"params",
"[",
"'analyze_queries'",
"]",
"=",
"$",
"analyze_queries",
";",
"}",
"return",
"$",
"response",
"=",
"$",
"this",
"->",
"_user",
"->",
"put",
"(",
"'account/identity/'",
".",
"$",
"identity",
".",
"'/limit/'",
".",
"$",
"service",
",",
"$",
"params",
")",
";",
"}"
] |
Update the limit for an service
@param string $identity
@param string $service
@param integer $total_allowance
@param integer $analyze_queries
@return mixed
|
[
"Update",
"the",
"limit",
"for",
"an",
"service"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity/Limit.php#L97-L109
|
datasift/datasift-php
|
lib/DataSift/Account/Identity.php
|
DataSift_Account_Identity.getAll
|
public function getAll($label = null, $page = 1, $perPage = 25)
{
$params = array(
'page' => $page,
'per_page' => $perPage
);
if ($label !== null) {
$params['label'] = $label;
}
return $this->_user->get('account/identity', $params);
}
|
php
|
public function getAll($label = null, $page = 1, $perPage = 25)
{
$params = array(
'page' => $page,
'per_page' => $perPage
);
if ($label !== null) {
$params['label'] = $label;
}
return $this->_user->get('account/identity', $params);
}
|
[
"public",
"function",
"getAll",
"(",
"$",
"label",
"=",
"null",
",",
"$",
"page",
"=",
"1",
",",
"$",
"perPage",
"=",
"25",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'page'",
"=>",
"$",
"page",
",",
"'per_page'",
"=>",
"$",
"perPage",
")",
";",
"if",
"(",
"$",
"label",
"!==",
"null",
")",
"{",
"$",
"params",
"[",
"'label'",
"]",
"=",
"$",
"label",
";",
"}",
"return",
"$",
"this",
"->",
"_user",
"->",
"get",
"(",
"'account/identity'",
",",
"$",
"params",
")",
";",
"}"
] |
Gets all the identities
@param string $label
@param integer $page
@param integer $perPage
@return mixed
|
[
"Gets",
"all",
"the",
"identities"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity.php#L49-L61
|
datasift/datasift-php
|
lib/DataSift/Account/Identity.php
|
DataSift_Account_Identity.create
|
public function create($label, $master = false, $status = 'active')
{
$params = array(
'label' => $label,
'master' => $master,
'status' => $status
);
return $this->_user->post('account/identity', $params);
}
|
php
|
public function create($label, $master = false, $status = 'active')
{
$params = array(
'label' => $label,
'master' => $master,
'status' => $status
);
return $this->_user->post('account/identity', $params);
}
|
[
"public",
"function",
"create",
"(",
"$",
"label",
",",
"$",
"master",
"=",
"false",
",",
"$",
"status",
"=",
"'active'",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'label'",
"=>",
"$",
"label",
",",
"'master'",
"=>",
"$",
"master",
",",
"'status'",
"=>",
"$",
"status",
")",
";",
"return",
"$",
"this",
"->",
"_user",
"->",
"post",
"(",
"'account/identity'",
",",
"$",
"params",
")",
";",
"}"
] |
Creates an identity
@param string $label
@param string $master
@param string $status
@return mixed
|
[
"Creates",
"an",
"identity"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity.php#L72-L82
|
datasift/datasift-php
|
lib/DataSift/Account/Identity.php
|
DataSift_Account_Identity.update
|
public function update($identity, $label = null, $master = null, $status = null)
{
$params = array();
if (! is_null($label)) {
$params['label'] = $label;
}
if (! is_null($master)) {
$params['master'] = $master;
}
if (! is_null($status)) {
$params['status'] = $status;
}
return $this->_user->put('account/identity/' . $identity, $params);
}
|
php
|
public function update($identity, $label = null, $master = null, $status = null)
{
$params = array();
if (! is_null($label)) {
$params['label'] = $label;
}
if (! is_null($master)) {
$params['master'] = $master;
}
if (! is_null($status)) {
$params['status'] = $status;
}
return $this->_user->put('account/identity/' . $identity, $params);
}
|
[
"public",
"function",
"update",
"(",
"$",
"identity",
",",
"$",
"label",
"=",
"null",
",",
"$",
"master",
"=",
"null",
",",
"$",
"status",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"label",
")",
")",
"{",
"$",
"params",
"[",
"'label'",
"]",
"=",
"$",
"label",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"master",
")",
")",
"{",
"$",
"params",
"[",
"'master'",
"]",
"=",
"$",
"master",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"status",
")",
")",
"{",
"$",
"params",
"[",
"'status'",
"]",
"=",
"$",
"status",
";",
"}",
"return",
"$",
"this",
"->",
"_user",
"->",
"put",
"(",
"'account/identity/'",
".",
"$",
"identity",
",",
"$",
"params",
")",
";",
"}"
] |
Updates an identity
@param string $identity
@param string $master
@param string $label
@param string $status
@return mixed
|
[
"Updates",
"an",
"identity"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity.php#L94-L109
|
tonicospinelli/class-generation
|
src/ClassGeneration/Argument.php
|
Argument.hasType
|
public function hasType()
{
return (!is_null($this->type) || !empty($this->type))
&& !in_array(mb_strtolower($this->type), $this->primitiveTypes);
}
|
php
|
public function hasType()
{
return (!is_null($this->type) || !empty($this->type))
&& !in_array(mb_strtolower($this->type), $this->primitiveTypes);
}
|
[
"public",
"function",
"hasType",
"(",
")",
"{",
"return",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"type",
")",
"||",
"!",
"empty",
"(",
"$",
"this",
"->",
"type",
")",
")",
"&&",
"!",
"in_array",
"(",
"mb_strtolower",
"(",
"$",
"this",
"->",
"type",
")",
",",
"$",
"this",
"->",
"primitiveTypes",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/Argument.php#L149-L154
|
tonicospinelli/class-generation
|
src/ClassGeneration/Argument.php
|
Argument.toString
|
public function toString()
{
$type = '';
if ($this->hasType()) {
$type = $this->getType() . ' ';
}
$value = '';
if ($this->isOptional()) {
$value = ' = ' . var_export($this->getValue(), true);
}
$argument = trim(
$type
. $this->getNameFormatted()
. $value
);
return $argument;
}
|
php
|
public function toString()
{
$type = '';
if ($this->hasType()) {
$type = $this->getType() . ' ';
}
$value = '';
if ($this->isOptional()) {
$value = ' = ' . var_export($this->getValue(), true);
}
$argument = trim(
$type
. $this->getNameFormatted()
. $value
);
return $argument;
}
|
[
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"type",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"hasType",
"(",
")",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
".",
"' '",
";",
"}",
"$",
"value",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"isOptional",
"(",
")",
")",
"{",
"$",
"value",
"=",
"' = '",
".",
"var_export",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
",",
"true",
")",
";",
"}",
"$",
"argument",
"=",
"trim",
"(",
"$",
"type",
".",
"$",
"this",
"->",
"getNameFormatted",
"(",
")",
".",
"$",
"value",
")",
";",
"return",
"$",
"argument",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/Argument.php#L187-L204
|
tonicospinelli/class-generation
|
src/ClassGeneration/Argument.php
|
Argument.createFromProperty
|
public static function createFromProperty(PropertyInterface $property)
{
$argument = new self();
$argument
->setName($property->getName())
->setType($property->getType());
return $argument;
}
|
php
|
public static function createFromProperty(PropertyInterface $property)
{
$argument = new self();
$argument
->setName($property->getName())
->setType($property->getType());
return $argument;
}
|
[
"public",
"static",
"function",
"createFromProperty",
"(",
"PropertyInterface",
"$",
"property",
")",
"{",
"$",
"argument",
"=",
"new",
"self",
"(",
")",
";",
"$",
"argument",
"->",
"setName",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
"->",
"setType",
"(",
"$",
"property",
"->",
"getType",
"(",
")",
")",
";",
"return",
"$",
"argument",
";",
"}"
] |
Creates Argument from Property Object.
@param PropertyInterface $property
@return Argument
|
[
"Creates",
"Argument",
"from",
"Property",
"Object",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/Argument.php#L213-L221
|
crossjoin/Css
|
src/Crossjoin/Css/Reader/HtmlString.php
|
HtmlString.getCssContent
|
protected function getCssContent()
{
$styleString = "";
if (class_exists("\\DOMDocument")) {
$doc = new \DOMDocument();
$doc->loadHTML($this->getHtmlContent());
// Extract styles from the HTML file
foreach($doc->getElementsByTagName('style') as $styleNode) {
$styleString .= $styleNode->nodeValue . "\r\n";
}
} else {
throw new \RuntimeException("Required extension 'dom' seems to be missing.");
}
return $styleString;
}
|
php
|
protected function getCssContent()
{
$styleString = "";
if (class_exists("\\DOMDocument")) {
$doc = new \DOMDocument();
$doc->loadHTML($this->getHtmlContent());
// Extract styles from the HTML file
foreach($doc->getElementsByTagName('style') as $styleNode) {
$styleString .= $styleNode->nodeValue . "\r\n";
}
} else {
throw new \RuntimeException("Required extension 'dom' seems to be missing.");
}
return $styleString;
}
|
[
"protected",
"function",
"getCssContent",
"(",
")",
"{",
"$",
"styleString",
"=",
"\"\"",
";",
"if",
"(",
"class_exists",
"(",
"\"\\\\DOMDocument\"",
")",
")",
"{",
"$",
"doc",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"doc",
"->",
"loadHTML",
"(",
"$",
"this",
"->",
"getHtmlContent",
"(",
")",
")",
";",
"// Extract styles from the HTML file",
"foreach",
"(",
"$",
"doc",
"->",
"getElementsByTagName",
"(",
"'style'",
")",
"as",
"$",
"styleNode",
")",
"{",
"$",
"styleString",
".=",
"$",
"styleNode",
"->",
"nodeValue",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Required extension 'dom' seems to be missing.\"",
")",
";",
"}",
"return",
"$",
"styleString",
";",
"}"
] |
Gets the CSS content extracted from the HTML source content.
@return string
|
[
"Gets",
"the",
"CSS",
"content",
"extracted",
"from",
"the",
"HTML",
"source",
"content",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Reader/HtmlString.php#L54-L71
|
iter8-au/builder
|
src/Builder/Traits/BuilderFilesTrait.php
|
BuilderFilesTrait.getCacheName
|
public function getCacheName(): string
{
if (null === $this->cacheName) {
$this->cacheName = sprintf(
'%s/%s.xlsx',
$this->cacheDir,
md5(microtime() . random_int(0, mt_getrandmax()))
);
}
return $this->cacheName;
}
|
php
|
public function getCacheName(): string
{
if (null === $this->cacheName) {
$this->cacheName = sprintf(
'%s/%s.xlsx',
$this->cacheDir,
md5(microtime() . random_int(0, mt_getrandmax()))
);
}
return $this->cacheName;
}
|
[
"public",
"function",
"getCacheName",
"(",
")",
":",
"string",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"cacheName",
")",
"{",
"$",
"this",
"->",
"cacheName",
"=",
"sprintf",
"(",
"'%s/%s.xlsx'",
",",
"$",
"this",
"->",
"cacheDir",
",",
"md5",
"(",
"microtime",
"(",
")",
".",
"random_int",
"(",
"0",
",",
"mt_getrandmax",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cacheName",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Traits/BuilderFilesTrait.php#L36-L47
|
corllete/silex-mongodb-provider
|
src/Provider/MongoDBServiceProvider.php
|
MongoDBServiceProvider.register
|
public function register(Container $app)
{
$ns = $this->namespace;
$mns = $this->multiNamespace;
$app[$ns.'.default_options'] = isset($app[$ns.'.default_options']) ? $app[$ns.'.default_options'] : [];
$app[$ns.'.default_options'] += self::$defaultOptions;
$app[$ns.'.factory'] = $app->protect(
function (array $options = []) use ($app, $ns) {
$options += $app[$ns.'.default_options'];
$options += self::$defaultOptions;
if (empty($options['uri']) && !empty($options['host'])) {
$options['uri'] = $this->assembleUri(
$options['host'],
$options['port'],
$options['database'],
$options['username'],
$options['password']
);
}
return new Client($options['uri'], $options['uri_options'], $options['driver_options']);
}
);
$app[$mns.'.options.init'] = $app->protect(
function () use ($app, $ns, $mns) {
static $done = false;
if ($done) {
return;
}
$done = true;
if (isset($app[$ns.'.options']) && isset($app[$mns.'.options'])) {
throw new \LogicException("Illegal configuration - choose either single or multi connection setup", 1);
}
if (!isset($app[$mns.'.options'])) {
$singleOptions = isset($app[$ns.'.options']) ? $app[$ns.'.options'] : [];
$singleOptions += $app[$ns.'.default_options'];
$app[$mns.'.options'] = [
'default' => $singleOptions,
];
}
if (isset($app[$mns.'.options']['default'])) {
$app[$mns.'.default'] = 'default';
} elseif (!isset($app[$mns.'.default'])) {
$tmp = $app[$mns.'.options'];
reset($tmp);
$app[$mns.'.default'] = key($tmp);
}
}
);
$app[$mns] = function ($app) use ($ns, $mns) {
$app[$mns.'.options.init']();
$mongos = new Container();
foreach ($app[$mns.'.options'] as $name => $options) {
$mongos[$name] = function () use ($app, $options, $ns) {
return $app[$ns.'.factory']($options);
};
}
if (!isset($mongos['default'])) {
$mongos['default'] = $mongos[$app[$mns.'.default']];
}
return $mongos;
};
$app[$ns] = function ($app) use ($mns) {
$dbs = $app[$mns];
return $dbs[$app[$mns.'.default']];
};
}
|
php
|
public function register(Container $app)
{
$ns = $this->namespace;
$mns = $this->multiNamespace;
$app[$ns.'.default_options'] = isset($app[$ns.'.default_options']) ? $app[$ns.'.default_options'] : [];
$app[$ns.'.default_options'] += self::$defaultOptions;
$app[$ns.'.factory'] = $app->protect(
function (array $options = []) use ($app, $ns) {
$options += $app[$ns.'.default_options'];
$options += self::$defaultOptions;
if (empty($options['uri']) && !empty($options['host'])) {
$options['uri'] = $this->assembleUri(
$options['host'],
$options['port'],
$options['database'],
$options['username'],
$options['password']
);
}
return new Client($options['uri'], $options['uri_options'], $options['driver_options']);
}
);
$app[$mns.'.options.init'] = $app->protect(
function () use ($app, $ns, $mns) {
static $done = false;
if ($done) {
return;
}
$done = true;
if (isset($app[$ns.'.options']) && isset($app[$mns.'.options'])) {
throw new \LogicException("Illegal configuration - choose either single or multi connection setup", 1);
}
if (!isset($app[$mns.'.options'])) {
$singleOptions = isset($app[$ns.'.options']) ? $app[$ns.'.options'] : [];
$singleOptions += $app[$ns.'.default_options'];
$app[$mns.'.options'] = [
'default' => $singleOptions,
];
}
if (isset($app[$mns.'.options']['default'])) {
$app[$mns.'.default'] = 'default';
} elseif (!isset($app[$mns.'.default'])) {
$tmp = $app[$mns.'.options'];
reset($tmp);
$app[$mns.'.default'] = key($tmp);
}
}
);
$app[$mns] = function ($app) use ($ns, $mns) {
$app[$mns.'.options.init']();
$mongos = new Container();
foreach ($app[$mns.'.options'] as $name => $options) {
$mongos[$name] = function () use ($app, $options, $ns) {
return $app[$ns.'.factory']($options);
};
}
if (!isset($mongos['default'])) {
$mongos['default'] = $mongos[$app[$mns.'.default']];
}
return $mongos;
};
$app[$ns] = function ($app) use ($mns) {
$dbs = $app[$mns];
return $dbs[$app[$mns.'.default']];
};
}
|
[
"public",
"function",
"register",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"ns",
"=",
"$",
"this",
"->",
"namespace",
";",
"$",
"mns",
"=",
"$",
"this",
"->",
"multiNamespace",
";",
"$",
"app",
"[",
"$",
"ns",
".",
"'.default_options'",
"]",
"=",
"isset",
"(",
"$",
"app",
"[",
"$",
"ns",
".",
"'.default_options'",
"]",
")",
"?",
"$",
"app",
"[",
"$",
"ns",
".",
"'.default_options'",
"]",
":",
"[",
"]",
";",
"$",
"app",
"[",
"$",
"ns",
".",
"'.default_options'",
"]",
"+=",
"self",
"::",
"$",
"defaultOptions",
";",
"$",
"app",
"[",
"$",
"ns",
".",
"'.factory'",
"]",
"=",
"$",
"app",
"->",
"protect",
"(",
"function",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"use",
"(",
"$",
"app",
",",
"$",
"ns",
")",
"{",
"$",
"options",
"+=",
"$",
"app",
"[",
"$",
"ns",
".",
"'.default_options'",
"]",
";",
"$",
"options",
"+=",
"self",
"::",
"$",
"defaultOptions",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'uri'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'host'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'uri'",
"]",
"=",
"$",
"this",
"->",
"assembleUri",
"(",
"$",
"options",
"[",
"'host'",
"]",
",",
"$",
"options",
"[",
"'port'",
"]",
",",
"$",
"options",
"[",
"'database'",
"]",
",",
"$",
"options",
"[",
"'username'",
"]",
",",
"$",
"options",
"[",
"'password'",
"]",
")",
";",
"}",
"return",
"new",
"Client",
"(",
"$",
"options",
"[",
"'uri'",
"]",
",",
"$",
"options",
"[",
"'uri_options'",
"]",
",",
"$",
"options",
"[",
"'driver_options'",
"]",
")",
";",
"}",
")",
";",
"$",
"app",
"[",
"$",
"mns",
".",
"'.options.init'",
"]",
"=",
"$",
"app",
"->",
"protect",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
",",
"$",
"ns",
",",
"$",
"mns",
")",
"{",
"static",
"$",
"done",
"=",
"false",
";",
"if",
"(",
"$",
"done",
")",
"{",
"return",
";",
"}",
"$",
"done",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"app",
"[",
"$",
"ns",
".",
"'.options'",
"]",
")",
"&&",
"isset",
"(",
"$",
"app",
"[",
"$",
"mns",
".",
"'.options'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Illegal configuration - choose either single or multi connection setup\"",
",",
"1",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"app",
"[",
"$",
"mns",
".",
"'.options'",
"]",
")",
")",
"{",
"$",
"singleOptions",
"=",
"isset",
"(",
"$",
"app",
"[",
"$",
"ns",
".",
"'.options'",
"]",
")",
"?",
"$",
"app",
"[",
"$",
"ns",
".",
"'.options'",
"]",
":",
"[",
"]",
";",
"$",
"singleOptions",
"+=",
"$",
"app",
"[",
"$",
"ns",
".",
"'.default_options'",
"]",
";",
"$",
"app",
"[",
"$",
"mns",
".",
"'.options'",
"]",
"=",
"[",
"'default'",
"=>",
"$",
"singleOptions",
",",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"app",
"[",
"$",
"mns",
".",
"'.options'",
"]",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"app",
"[",
"$",
"mns",
".",
"'.default'",
"]",
"=",
"'default'",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"app",
"[",
"$",
"mns",
".",
"'.default'",
"]",
")",
")",
"{",
"$",
"tmp",
"=",
"$",
"app",
"[",
"$",
"mns",
".",
"'.options'",
"]",
";",
"reset",
"(",
"$",
"tmp",
")",
";",
"$",
"app",
"[",
"$",
"mns",
".",
"'.default'",
"]",
"=",
"key",
"(",
"$",
"tmp",
")",
";",
"}",
"}",
")",
";",
"$",
"app",
"[",
"$",
"mns",
"]",
"=",
"function",
"(",
"$",
"app",
")",
"use",
"(",
"$",
"ns",
",",
"$",
"mns",
")",
"{",
"$",
"app",
"[",
"$",
"mns",
".",
"'.options.init'",
"]",
"(",
")",
";",
"$",
"mongos",
"=",
"new",
"Container",
"(",
")",
";",
"foreach",
"(",
"$",
"app",
"[",
"$",
"mns",
".",
"'.options'",
"]",
"as",
"$",
"name",
"=>",
"$",
"options",
")",
"{",
"$",
"mongos",
"[",
"$",
"name",
"]",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"app",
",",
"$",
"options",
",",
"$",
"ns",
")",
"{",
"return",
"$",
"app",
"[",
"$",
"ns",
".",
"'.factory'",
"]",
"(",
"$",
"options",
")",
";",
"}",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mongos",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"mongos",
"[",
"'default'",
"]",
"=",
"$",
"mongos",
"[",
"$",
"app",
"[",
"$",
"mns",
".",
"'.default'",
"]",
"]",
";",
"}",
"return",
"$",
"mongos",
";",
"}",
";",
"$",
"app",
"[",
"$",
"ns",
"]",
"=",
"function",
"(",
"$",
"app",
")",
"use",
"(",
"$",
"mns",
")",
"{",
"$",
"dbs",
"=",
"$",
"app",
"[",
"$",
"mns",
"]",
";",
"return",
"$",
"dbs",
"[",
"$",
"app",
"[",
"$",
"mns",
".",
"'.default'",
"]",
"]",
";",
"}",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/corllete/silex-mongodb-provider/blob/1e5b1a6aab1657eb3964caefe0c8604629587c47/src/Provider/MongoDBServiceProvider.php#L77-L160
|
corllete/silex-mongodb-provider
|
src/Provider/MongoDBServiceProvider.php
|
MongoDBServiceProvider.assembleUri
|
private function assembleUri($host, $port, $db = null, $username = null, $password = null)
{
if (!empty($db)) {
$db = '/'.$db;
}
$cred = '';
if ($username !== null && $password !== null) {
$cred = sprintf('%s:%s@', rawurlencode($username), rawurlencode($password));
}
return sprintf('mongodb://%s%s:%s%s', $cred, $host, $port, $db.'');
}
|
php
|
private function assembleUri($host, $port, $db = null, $username = null, $password = null)
{
if (!empty($db)) {
$db = '/'.$db;
}
$cred = '';
if ($username !== null && $password !== null) {
$cred = sprintf('%s:%s@', rawurlencode($username), rawurlencode($password));
}
return sprintf('mongodb://%s%s:%s%s', $cred, $host, $port, $db.'');
}
|
[
"private",
"function",
"assembleUri",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"db",
"=",
"null",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"db",
")",
")",
"{",
"$",
"db",
"=",
"'/'",
".",
"$",
"db",
";",
"}",
"$",
"cred",
"=",
"''",
";",
"if",
"(",
"$",
"username",
"!==",
"null",
"&&",
"$",
"password",
"!==",
"null",
")",
"{",
"$",
"cred",
"=",
"sprintf",
"(",
"'%s:%s@'",
",",
"rawurlencode",
"(",
"$",
"username",
")",
",",
"rawurlencode",
"(",
"$",
"password",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"'mongodb://%s%s:%s%s'",
",",
"$",
"cred",
",",
"$",
"host",
",",
"$",
"port",
",",
"$",
"db",
".",
"''",
")",
";",
"}"
] |
@link http://php.net/manual/en/mongodb-driver-manager.construct.php
@param string $host
@param string $port
@param string|null $db
@param string|null $username
@param string|null $password
@return string
|
[
"@link",
"http",
":",
"//",
"php",
".",
"net",
"/",
"manual",
"/",
"en",
"/",
"mongodb",
"-",
"driver",
"-",
"manager",
".",
"construct",
".",
"php"
] |
train
|
https://github.com/corllete/silex-mongodb-provider/blob/1e5b1a6aab1657eb3964caefe0c8604629587c47/src/Provider/MongoDBServiceProvider.php#L172-L184
|
rozdol/bi
|
src/Utils/Crypt.php
|
Crypt.create_hash
|
function create_hash($password)
{
// format: algorithm:iterations:salt:hash
//$salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTES, MCRYPT_DEV_URANDOM));
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv), 0, 16);
$salt = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
return PBKDF2_HASH_ALGORITHM . ":" . PBKDF2_ITERATIONS . ":" . $salt . ":" .
base64_encode($this->pbkdf2(
PBKDF2_HASH_ALGORITHM,
$password,
$salt,
PBKDF2_ITERATIONS,
PBKDF2_HASH_BYTES,
true
));
}
|
php
|
function create_hash($password)
{
// format: algorithm:iterations:salt:hash
//$salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTES, MCRYPT_DEV_URANDOM));
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv), 0, 16);
$salt = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
return PBKDF2_HASH_ALGORITHM . ":" . PBKDF2_ITERATIONS . ":" . $salt . ":" .
base64_encode($this->pbkdf2(
PBKDF2_HASH_ALGORITHM,
$password,
$salt,
PBKDF2_ITERATIONS,
PBKDF2_HASH_BYTES,
true
));
}
|
[
"function",
"create_hash",
"(",
"$",
"password",
")",
"{",
"// format: algorithm:iterations:salt:hash",
"//$salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTES, MCRYPT_DEV_URANDOM));",
"$",
"encrypt_method",
"=",
"\"AES-256-CBC\"",
";",
"$",
"key",
"=",
"hash",
"(",
"'sha256'",
",",
"$",
"secret_key",
")",
";",
"$",
"iv",
"=",
"substr",
"(",
"hash",
"(",
"'sha256'",
",",
"$",
"secret_iv",
")",
",",
"0",
",",
"16",
")",
";",
"$",
"salt",
"=",
"base64_encode",
"(",
"openssl_encrypt",
"(",
"$",
"string",
",",
"$",
"encrypt_method",
",",
"$",
"key",
",",
"0",
",",
"$",
"iv",
")",
")",
";",
"return",
"PBKDF2_HASH_ALGORITHM",
".",
"\":\"",
".",
"PBKDF2_ITERATIONS",
".",
"\":\"",
".",
"$",
"salt",
".",
"\":\"",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"pbkdf2",
"(",
"PBKDF2_HASH_ALGORITHM",
",",
"$",
"password",
",",
"$",
"salt",
",",
"PBKDF2_ITERATIONS",
",",
"PBKDF2_HASH_BYTES",
",",
"true",
")",
")",
";",
"}"
] |
These constants may be changed without breaking existing hashes.
|
[
"These",
"constants",
"may",
"be",
"changed",
"without",
"breaking",
"existing",
"hashes",
"."
] |
train
|
https://github.com/rozdol/bi/blob/f63d6b219cc4a7bb25b1865905a2a888ce6ce855/src/Utils/Crypt.php#L43-L63
|
rozdol/bi
|
src/Utils/Crypt.php
|
Crypt.slow_equals
|
function slow_equals($a, $b)
{
$diff = strlen($a) ^ strlen($b);
for ($i = 0; $i < strlen($a) && $i < strlen($b); $i++) {
$diff |= ord($a[$i]) ^ ord($b[$i]);
}
return $diff === 0;
}
|
php
|
function slow_equals($a, $b)
{
$diff = strlen($a) ^ strlen($b);
for ($i = 0; $i < strlen($a) && $i < strlen($b); $i++) {
$diff |= ord($a[$i]) ^ ord($b[$i]);
}
return $diff === 0;
}
|
[
"function",
"slow_equals",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"diff",
"=",
"strlen",
"(",
"$",
"a",
")",
"^",
"strlen",
"(",
"$",
"b",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"a",
")",
"&&",
"$",
"i",
"<",
"strlen",
"(",
"$",
"b",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"diff",
"|=",
"ord",
"(",
"$",
"a",
"[",
"$",
"i",
"]",
")",
"^",
"ord",
"(",
"$",
"b",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"$",
"diff",
"===",
"0",
";",
"}"
] |
Compares two strings $a and $b in length-constant time.
|
[
"Compares",
"two",
"strings",
"$a",
"and",
"$b",
"in",
"length",
"-",
"constant",
"time",
"."
] |
train
|
https://github.com/rozdol/bi/blob/f63d6b219cc4a7bb25b1865905a2a888ce6ce855/src/Utils/Crypt.php#L86-L93
|
rozdol/bi
|
src/Utils/Crypt.php
|
Crypt.pbkdf2
|
function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
$algorithm = strtolower($algorithm);
if (!in_array($algorithm, hash_algos(), true)) {
die('PBKDF2 ERROR: Invalid hash algorithm.');
}
if ($count <= 0 || $key_length <= 0) {
die('PBKDF2 ERROR: Invalid parameters.');
}
$hash_length = strlen(hash($algorithm, "", true));
$block_count = ceil($key_length / $hash_length);
$output = "";
for ($i = 1; $i <= $block_count; $i++) {
// $i encoded as 4 bytes, big endian.
$last = $salt . pack("N", $i);
// first iteration
$last = $xorsum = hash_hmac($algorithm, $last, $password, true);
// perform the other $count - 1 iterations
for ($j = 1; $j < $count; $j++) {
$xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
}
$output .= $xorsum;
}
if ($raw_output) {
return substr($output, 0, $key_length);
} else {
return bin2hex(substr($output, 0, $key_length));
}
}
|
php
|
function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
$algorithm = strtolower($algorithm);
if (!in_array($algorithm, hash_algos(), true)) {
die('PBKDF2 ERROR: Invalid hash algorithm.');
}
if ($count <= 0 || $key_length <= 0) {
die('PBKDF2 ERROR: Invalid parameters.');
}
$hash_length = strlen(hash($algorithm, "", true));
$block_count = ceil($key_length / $hash_length);
$output = "";
for ($i = 1; $i <= $block_count; $i++) {
// $i encoded as 4 bytes, big endian.
$last = $salt . pack("N", $i);
// first iteration
$last = $xorsum = hash_hmac($algorithm, $last, $password, true);
// perform the other $count - 1 iterations
for ($j = 1; $j < $count; $j++) {
$xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
}
$output .= $xorsum;
}
if ($raw_output) {
return substr($output, 0, $key_length);
} else {
return bin2hex(substr($output, 0, $key_length));
}
}
|
[
"function",
"pbkdf2",
"(",
"$",
"algorithm",
",",
"$",
"password",
",",
"$",
"salt",
",",
"$",
"count",
",",
"$",
"key_length",
",",
"$",
"raw_output",
"=",
"false",
")",
"{",
"$",
"algorithm",
"=",
"strtolower",
"(",
"$",
"algorithm",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"algorithm",
",",
"hash_algos",
"(",
")",
",",
"true",
")",
")",
"{",
"die",
"(",
"'PBKDF2 ERROR: Invalid hash algorithm.'",
")",
";",
"}",
"if",
"(",
"$",
"count",
"<=",
"0",
"||",
"$",
"key_length",
"<=",
"0",
")",
"{",
"die",
"(",
"'PBKDF2 ERROR: Invalid parameters.'",
")",
";",
"}",
"$",
"hash_length",
"=",
"strlen",
"(",
"hash",
"(",
"$",
"algorithm",
",",
"\"\"",
",",
"true",
")",
")",
";",
"$",
"block_count",
"=",
"ceil",
"(",
"$",
"key_length",
"/",
"$",
"hash_length",
")",
";",
"$",
"output",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"block_count",
";",
"$",
"i",
"++",
")",
"{",
"// $i encoded as 4 bytes, big endian.",
"$",
"last",
"=",
"$",
"salt",
".",
"pack",
"(",
"\"N\"",
",",
"$",
"i",
")",
";",
"// first iteration",
"$",
"last",
"=",
"$",
"xorsum",
"=",
"hash_hmac",
"(",
"$",
"algorithm",
",",
"$",
"last",
",",
"$",
"password",
",",
"true",
")",
";",
"// perform the other $count - 1 iterations",
"for",
"(",
"$",
"j",
"=",
"1",
";",
"$",
"j",
"<",
"$",
"count",
";",
"$",
"j",
"++",
")",
"{",
"$",
"xorsum",
"^=",
"(",
"$",
"last",
"=",
"hash_hmac",
"(",
"$",
"algorithm",
",",
"$",
"last",
",",
"$",
"password",
",",
"true",
")",
")",
";",
"}",
"$",
"output",
".=",
"$",
"xorsum",
";",
"}",
"if",
"(",
"$",
"raw_output",
")",
"{",
"return",
"substr",
"(",
"$",
"output",
",",
"0",
",",
"$",
"key_length",
")",
";",
"}",
"else",
"{",
"return",
"bin2hex",
"(",
"substr",
"(",
"$",
"output",
",",
"0",
",",
"$",
"key_length",
")",
")",
";",
"}",
"}"
] |
/*
PBKDF2 key derivation function as defined by RSA's PKCS #5: https://www.ietf.org/rfc/rfc2898.txt
$algorithm - The hash algorithm to use. Recommended: SHA256
$password - The password.
$salt - A salt that is unique to the password.
$count - Iteration count. Higher is better, but slower. Recommended: At least 1000.
$key_length - The length of the derived key in bytes.
$raw_output - If true, the key is returned in raw binary format. Hex encoded otherwise.
Returns: A $key_length-byte key derived from the password and salt.
Test vectors can be found here: https://www.ietf.org/rfc/rfc6070.txt
This implementation of PBKDF2 was originally created by https://defuse.ca
With improvements by http://www.variations-of-shadow.com
|
[
"/",
"*",
"PBKDF2",
"key",
"derivation",
"function",
"as",
"defined",
"by",
"RSA",
"s",
"PKCS",
"#5",
":",
"https",
":",
"//",
"www",
".",
"ietf",
".",
"org",
"/",
"rfc",
"/",
"rfc2898",
".",
"txt",
"$algorithm",
"-",
"The",
"hash",
"algorithm",
"to",
"use",
".",
"Recommended",
":",
"SHA256",
"$password",
"-",
"The",
"password",
".",
"$salt",
"-",
"A",
"salt",
"that",
"is",
"unique",
"to",
"the",
"password",
".",
"$count",
"-",
"Iteration",
"count",
".",
"Higher",
"is",
"better",
"but",
"slower",
".",
"Recommended",
":",
"At",
"least",
"1000",
".",
"$key_length",
"-",
"The",
"length",
"of",
"the",
"derived",
"key",
"in",
"bytes",
".",
"$raw_output",
"-",
"If",
"true",
"the",
"key",
"is",
"returned",
"in",
"raw",
"binary",
"format",
".",
"Hex",
"encoded",
"otherwise",
".",
"Returns",
":",
"A",
"$key_length",
"-",
"byte",
"key",
"derived",
"from",
"the",
"password",
"and",
"salt",
"."
] |
train
|
https://github.com/rozdol/bi/blob/f63d6b219cc4a7bb25b1865905a2a888ce6ce855/src/Utils/Crypt.php#L110-L141
|
jelix/version
|
lib/Version.php
|
Version.getNextTailVersion
|
public function getNextTailVersion()
{
if (count($this->stabilityVersion) && $this->stabilityVersion[0] != 'stable') {
return implode('.', $this->version);
}
$v = $this->version;
$last = count($v) - 1;
if ($v[$last] !== '*') {
++$v[$last];
}
return implode('.', $v);
}
|
php
|
public function getNextTailVersion()
{
if (count($this->stabilityVersion) && $this->stabilityVersion[0] != 'stable') {
return implode('.', $this->version);
}
$v = $this->version;
$last = count($v) - 1;
if ($v[$last] !== '*') {
++$v[$last];
}
return implode('.', $v);
}
|
[
"public",
"function",
"getNextTailVersion",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"stabilityVersion",
")",
"&&",
"$",
"this",
"->",
"stabilityVersion",
"[",
"0",
"]",
"!=",
"'stable'",
")",
"{",
"return",
"implode",
"(",
"'.'",
",",
"$",
"this",
"->",
"version",
")",
";",
"}",
"$",
"v",
"=",
"$",
"this",
"->",
"version",
";",
"$",
"last",
"=",
"count",
"(",
"$",
"v",
")",
"-",
"1",
";",
"if",
"(",
"$",
"v",
"[",
"$",
"last",
"]",
"!==",
"'*'",
")",
"{",
"++",
"$",
"v",
"[",
"$",
"last",
"]",
";",
"}",
"return",
"implode",
"(",
"'.'",
",",
"$",
"v",
")",
";",
"}"
] |
returns the next version, by incrementing the last
number, whatever it is.
If the version has a stability information (alpha, beta etc..),
it returns only the version without stability version.
@return string the next version
|
[
"returns",
"the",
"next",
"version",
"by",
"incrementing",
"the",
"last",
"number",
"whatever",
"it",
"is",
".",
"If",
"the",
"version",
"has",
"a",
"stability",
"information",
"(",
"alpha",
"beta",
"etc",
"..",
")",
"it",
"returns",
"only",
"the",
"version",
"without",
"stability",
"version",
"."
] |
train
|
https://github.com/jelix/version/blob/1bdcea2beb7943f347fb453e3106702a460d51c2/lib/Version.php#L229-L241
|
cronario/cronario
|
src/Logger/Journal.php
|
Journal.log
|
public function log($level, $message, array $context = array())
{
if (!in_array($level, $this->journalRecord)) {
return null;
}
$line = sprintf("%s: %s %s %s",
$this->getCurrentDate(),
str_repeat('. ', $this->levelToPoints[$level]),
$message,
'[ ' . implode(' ; ', $context) . ' ]'
) . PHP_EOL;
file_put_contents($this->getJournalPath(), $line, FILE_APPEND);
return null;
}
|
php
|
public function log($level, $message, array $context = array())
{
if (!in_array($level, $this->journalRecord)) {
return null;
}
$line = sprintf("%s: %s %s %s",
$this->getCurrentDate(),
str_repeat('. ', $this->levelToPoints[$level]),
$message,
'[ ' . implode(' ; ', $context) . ' ]'
) . PHP_EOL;
file_put_contents($this->getJournalPath(), $line, FILE_APPEND);
return null;
}
|
[
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"level",
",",
"$",
"this",
"->",
"journalRecord",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"line",
"=",
"sprintf",
"(",
"\"%s: %s %s %s\"",
",",
"$",
"this",
"->",
"getCurrentDate",
"(",
")",
",",
"str_repeat",
"(",
"'. '",
",",
"$",
"this",
"->",
"levelToPoints",
"[",
"$",
"level",
"]",
")",
",",
"$",
"message",
",",
"'[ '",
".",
"implode",
"(",
"' ; '",
",",
"$",
"context",
")",
".",
"' ]'",
")",
".",
"PHP_EOL",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"getJournalPath",
"(",
")",
",",
"$",
"line",
",",
"FILE_APPEND",
")",
";",
"return",
"null",
";",
"}"
] |
@param mixed $level
@param string $message
@param array $context
@return null
|
[
"@param",
"mixed",
"$level",
"@param",
"string",
"$message",
"@param",
"array",
"$context"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Logger/Journal.php#L30-L47
|
phpmob/twig-modify-bundle
|
Twig/TokenParser.php
|
TokenParser.parse
|
public function parse(Twig_Token $token)
{
$lineNumber = $token->getLine();
$type = strtolower($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue());
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(
function (Twig_Token $token) {
return $token->test('end'.$this->tagName);
},
true
);
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
if ($this->enabled) {
return new Node($body, [], $lineNumber, $this->getTag(), $this->minifier, $type);
}
return $body;
}
|
php
|
public function parse(Twig_Token $token)
{
$lineNumber = $token->getLine();
$type = strtolower($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue());
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(
function (Twig_Token $token) {
return $token->test('end'.$this->tagName);
},
true
);
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
if ($this->enabled) {
return new Node($body, [], $lineNumber, $this->getTag(), $this->minifier, $type);
}
return $body;
}
|
[
"public",
"function",
"parse",
"(",
"Twig_Token",
"$",
"token",
")",
"{",
"$",
"lineNumber",
"=",
"$",
"token",
"->",
"getLine",
"(",
")",
";",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
"->",
"expect",
"(",
"Twig_Token",
"::",
"NAME_TYPE",
")",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
"->",
"expect",
"(",
"Twig_Token",
"::",
"BLOCK_END_TYPE",
")",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"parser",
"->",
"subparse",
"(",
"function",
"(",
"Twig_Token",
"$",
"token",
")",
"{",
"return",
"$",
"token",
"->",
"test",
"(",
"'end'",
".",
"$",
"this",
"->",
"tagName",
")",
";",
"}",
",",
"true",
")",
";",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
"->",
"expect",
"(",
"Twig_Token",
"::",
"BLOCK_END_TYPE",
")",
";",
"if",
"(",
"$",
"this",
"->",
"enabled",
")",
"{",
"return",
"new",
"Node",
"(",
"$",
"body",
",",
"[",
"]",
",",
"$",
"lineNumber",
",",
"$",
"this",
"->",
"getTag",
"(",
")",
",",
"$",
"this",
"->",
"minifier",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"body",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/phpmob/twig-modify-bundle/blob/30b70ca3ea7b902f2f29c8457cd4f8da45b1d29e/Twig/TokenParser.php#L52-L74
|
acasademont/wurfl
|
WURFL/WURFLManager.php
|
WURFL_WURFLManager.getDeviceForRequest
|
public function getDeviceForRequest(WURFL_Request_GenericRequest $request)
{
if (!isset($request)) {
throw new Exception("The request parameter must be set.");
}
WURFL_Handlers_Utils::reset();
return $this->_wurflService->getDeviceForRequest($request);
}
|
php
|
public function getDeviceForRequest(WURFL_Request_GenericRequest $request)
{
if (!isset($request)) {
throw new Exception("The request parameter must be set.");
}
WURFL_Handlers_Utils::reset();
return $this->_wurflService->getDeviceForRequest($request);
}
|
[
"public",
"function",
"getDeviceForRequest",
"(",
"WURFL_Request_GenericRequest",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"request",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"The request parameter must be set.\"",
")",
";",
"}",
"WURFL_Handlers_Utils",
"::",
"reset",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_wurflService",
"->",
"getDeviceForRequest",
"(",
"$",
"request",
")",
";",
"}"
] |
Return a device the given WURFL_Request_GenericRequest request(user-agent..)
@param WURFL_Request_GenericRequest $request
@return WURFL_CustomDevice device
@throws Exception if the $request parameter is not set
|
[
"Return",
"a",
"device",
"the",
"given",
"WURFL_Request_GenericRequest",
"request",
"(",
"user",
"-",
"agent",
"..",
")"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/WURFLManager.php#L87-L94
|
acasademont/wurfl
|
WURFL/WURFLManager.php
|
WURFL_WURFLManager.getDeviceForHttpRequest
|
public function getDeviceForHttpRequest($httpRequest, $override_sideloaded_browser_ua = true)
{
if (!isset($httpRequest)) {
throw new Exception("The $httpRequest parameter must be set.");
}
$request = $this->_requestFactory->createRequest($httpRequest, $override_sideloaded_browser_ua);
return $this->getDeviceForRequest($request);
}
|
php
|
public function getDeviceForHttpRequest($httpRequest, $override_sideloaded_browser_ua = true)
{
if (!isset($httpRequest)) {
throw new Exception("The $httpRequest parameter must be set.");
}
$request = $this->_requestFactory->createRequest($httpRequest, $override_sideloaded_browser_ua);
return $this->getDeviceForRequest($request);
}
|
[
"public",
"function",
"getDeviceForHttpRequest",
"(",
"$",
"httpRequest",
",",
"$",
"override_sideloaded_browser_ua",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"httpRequest",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"The $httpRequest parameter must be set.\"",
")",
";",
"}",
"$",
"request",
"=",
"$",
"this",
"->",
"_requestFactory",
"->",
"createRequest",
"(",
"$",
"httpRequest",
",",
"$",
"override_sideloaded_browser_ua",
")",
";",
"return",
"$",
"this",
"->",
"getDeviceForRequest",
"(",
"$",
"request",
")",
";",
"}"
] |
Return a device for the given http request(user-agent..)
@param array $httpRequest HTTP Request array (normally $_SERVER)
@param bool $override_sideloaded_browser_ua
@return WURFL_CustomDevice device
@throws Exception if $httpRequest is not set
|
[
"Return",
"a",
"device",
"for",
"the",
"given",
"http",
"request",
"(",
"user",
"-",
"agent",
"..",
")"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/WURFLManager.php#L104-L111
|
acasademont/wurfl
|
WURFL/WURFLManager.php
|
WURFL_WURFLManager.getDeviceForUserAgent
|
public function getDeviceForUserAgent($userAgent)
{
if (!isset($userAgent)) {
$userAgent = '';
}
$request = $this->_requestFactory->createRequestForUserAgent($userAgent);
return $this->getDeviceForRequest($request);
}
|
php
|
public function getDeviceForUserAgent($userAgent)
{
if (!isset($userAgent)) {
$userAgent = '';
}
$request = $this->_requestFactory->createRequestForUserAgent($userAgent);
return $this->getDeviceForRequest($request);
}
|
[
"public",
"function",
"getDeviceForUserAgent",
"(",
"$",
"userAgent",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"userAgent",
")",
")",
"{",
"$",
"userAgent",
"=",
"''",
";",
"}",
"$",
"request",
"=",
"$",
"this",
"->",
"_requestFactory",
"->",
"createRequestForUserAgent",
"(",
"$",
"userAgent",
")",
";",
"return",
"$",
"this",
"->",
"getDeviceForRequest",
"(",
"$",
"request",
")",
";",
"}"
] |
Returns a device for the given user-agent
@param string $userAgent
@return WURFL_CustomDevice device
@throws Exception if $userAgent is not set
|
[
"Returns",
"a",
"device",
"for",
"the",
"given",
"user",
"-",
"agent"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/WURFLManager.php#L120-L128
|
cronario/cronario
|
src/Facade.php
|
Facade.addProducer
|
public static function addProducer(Producer $producer)
{
$appId = $producer->getAppId();
if (array_key_exists($appId, static::$producers)) {
throw new Exception\FacadeException("Producer with {$appId} already exists!");
}
static::$producers[$appId] = $producer;
return true;
}
|
php
|
public static function addProducer(Producer $producer)
{
$appId = $producer->getAppId();
if (array_key_exists($appId, static::$producers)) {
throw new Exception\FacadeException("Producer with {$appId} already exists!");
}
static::$producers[$appId] = $producer;
return true;
}
|
[
"public",
"static",
"function",
"addProducer",
"(",
"Producer",
"$",
"producer",
")",
"{",
"$",
"appId",
"=",
"$",
"producer",
"->",
"getAppId",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"appId",
",",
"static",
"::",
"$",
"producers",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FacadeException",
"(",
"\"Producer with {$appId} already exists!\"",
")",
";",
"}",
"static",
"::",
"$",
"producers",
"[",
"$",
"appId",
"]",
"=",
"$",
"producer",
";",
"return",
"true",
";",
"}"
] |
Add producer to facade
@param Producer $producer
@return boolean
@throws Exception\FacadeException
|
[
"Add",
"producer",
"to",
"facade"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L34-L45
|
cronario/cronario
|
src/Facade.php
|
Facade.addBuilder
|
public static function addBuilder($appId, $builderFunction)
{
if (array_key_exists($appId, static::$builders)) {
throw new Exception\FacadeException("Builder with {$appId} already exists!");
}
if (!is_callable($builderFunction)) {
throw new Exception\FacadeException("Builder function for {$appId} is not callable!");
}
static::$builders[$appId] = $builderFunction;
return true;
}
|
php
|
public static function addBuilder($appId, $builderFunction)
{
if (array_key_exists($appId, static::$builders)) {
throw new Exception\FacadeException("Builder with {$appId} already exists!");
}
if (!is_callable($builderFunction)) {
throw new Exception\FacadeException("Builder function for {$appId} is not callable!");
}
static::$builders[$appId] = $builderFunction;
return true;
}
|
[
"public",
"static",
"function",
"addBuilder",
"(",
"$",
"appId",
",",
"$",
"builderFunction",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"appId",
",",
"static",
"::",
"$",
"builders",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FacadeException",
"(",
"\"Builder with {$appId} already exists!\"",
")",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"builderFunction",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FacadeException",
"(",
"\"Builder function for {$appId} is not callable!\"",
")",
";",
"}",
"static",
"::",
"$",
"builders",
"[",
"$",
"appId",
"]",
"=",
"$",
"builderFunction",
";",
"return",
"true",
";",
"}"
] |
Add Builder to facade builder scope
@param $appId
@param $builderFunction
@return boolean
@throws Exception\FacadeException
|
[
"Add",
"Builder",
"to",
"facade",
"builder",
"scope"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L56-L69
|
cronario/cronario
|
src/Facade.php
|
Facade.getProducer
|
public static function getProducer($appId = Producer::DEFAULT_APP_ID)
{
if (null === $appId) {
$appId = Producer::DEFAULT_APP_ID;
}
if (!array_key_exists($appId, static::$producers)) {
if (array_key_exists($appId, static::$builders)) {
$func = static::$builders[$appId];
static::addProducer($func($appId));
unset(static::$builders[$appId]);
return static::getProducer($appId);
}
throw new Exception\FacadeException("Producer with appId: '{$appId}' not exists yet!");
}
return static::$producers[$appId];
}
|
php
|
public static function getProducer($appId = Producer::DEFAULT_APP_ID)
{
if (null === $appId) {
$appId = Producer::DEFAULT_APP_ID;
}
if (!array_key_exists($appId, static::$producers)) {
if (array_key_exists($appId, static::$builders)) {
$func = static::$builders[$appId];
static::addProducer($func($appId));
unset(static::$builders[$appId]);
return static::getProducer($appId);
}
throw new Exception\FacadeException("Producer with appId: '{$appId}' not exists yet!");
}
return static::$producers[$appId];
}
|
[
"public",
"static",
"function",
"getProducer",
"(",
"$",
"appId",
"=",
"Producer",
"::",
"DEFAULT_APP_ID",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"appId",
")",
"{",
"$",
"appId",
"=",
"Producer",
"::",
"DEFAULT_APP_ID",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"appId",
",",
"static",
"::",
"$",
"producers",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"appId",
",",
"static",
"::",
"$",
"builders",
")",
")",
"{",
"$",
"func",
"=",
"static",
"::",
"$",
"builders",
"[",
"$",
"appId",
"]",
";",
"static",
"::",
"addProducer",
"(",
"$",
"func",
"(",
"$",
"appId",
")",
")",
";",
"unset",
"(",
"static",
"::",
"$",
"builders",
"[",
"$",
"appId",
"]",
")",
";",
"return",
"static",
"::",
"getProducer",
"(",
"$",
"appId",
")",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"FacadeException",
"(",
"\"Producer with appId: '{$appId}' not exists yet!\"",
")",
";",
"}",
"return",
"static",
"::",
"$",
"producers",
"[",
"$",
"appId",
"]",
";",
"}"
] |
Get producer by id
@param string $appId
@return Producer|null
@throws Exception\FacadeException
|
[
"Get",
"producer",
"by",
"id"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L79-L99
|
cronario/cronario
|
src/Facade.php
|
Facade.getProducersStats
|
public static function getProducersStats()
{
$producersStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$producersStats[$appId] = $producer->getStats();
}
return $producersStats;
}
|
php
|
public static function getProducersStats()
{
$producersStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$producersStats[$appId] = $producer->getStats();
}
return $producersStats;
}
|
[
"public",
"static",
"function",
"getProducersStats",
"(",
")",
"{",
"$",
"producersStats",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"producers",
"as",
"$",
"appId",
"=>",
"$",
"producer",
")",
"{",
"/** @var $producer Producer */",
"$",
"producersStats",
"[",
"$",
"appId",
"]",
"=",
"$",
"producer",
"->",
"getStats",
"(",
")",
";",
"}",
"return",
"$",
"producersStats",
";",
"}"
] |
Get producer statistic
@return array
|
[
"Get",
"producer",
"statistic"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L134-L143
|
cronario/cronario
|
src/Facade.php
|
Facade.getQueuesStats
|
public static function getQueuesStats()
{
$queuesStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$queuesStats[$appId] = $producer->getQueue()->getStats();
}
return $queuesStats;
}
|
php
|
public static function getQueuesStats()
{
$queuesStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$queuesStats[$appId] = $producer->getQueue()->getStats();
}
return $queuesStats;
}
|
[
"public",
"static",
"function",
"getQueuesStats",
"(",
")",
"{",
"$",
"queuesStats",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"producers",
"as",
"$",
"appId",
"=>",
"$",
"producer",
")",
"{",
"/** @var $producer Producer */",
"$",
"queuesStats",
"[",
"$",
"appId",
"]",
"=",
"$",
"producer",
"->",
"getQueue",
"(",
")",
"->",
"getStats",
"(",
")",
";",
"}",
"return",
"$",
"queuesStats",
";",
"}"
] |
Get queues statistic
@return array
|
[
"Get",
"queues",
"statistic"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L150-L159
|
cronario/cronario
|
src/Facade.php
|
Facade.getJobsReserved
|
public static function getJobsReserved()
{
$jobsReserved = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$jobsReserved[$appId] = $producer->getQueue()->getJobReserved();
}
return $jobsReserved;
}
|
php
|
public static function getJobsReserved()
{
$jobsReserved = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$jobsReserved[$appId] = $producer->getQueue()->getJobReserved();
}
return $jobsReserved;
}
|
[
"public",
"static",
"function",
"getJobsReserved",
"(",
")",
"{",
"$",
"jobsReserved",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"producers",
"as",
"$",
"appId",
"=>",
"$",
"producer",
")",
"{",
"/** @var $producer Producer */",
"$",
"jobsReserved",
"[",
"$",
"appId",
"]",
"=",
"$",
"producer",
"->",
"getQueue",
"(",
")",
"->",
"getJobReserved",
"(",
")",
";",
"}",
"return",
"$",
"jobsReserved",
";",
"}"
] |
Get all reserved jobs
@return array
|
[
"Get",
"all",
"reserved",
"jobs"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L166-L175
|
cronario/cronario
|
src/Facade.php
|
Facade.getManagersStats
|
public static function getManagersStats()
{
$managersStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$redis = $producer->getRedis();
$keys = [
'stat' => $redis->keys(Manager::REDIS_NS_STATS . '*'),
'live' => $redis->keys(Manager::REDIS_NS_LIVE . '*')
];
foreach ($keys as $type => $statsKeys) {
foreach ($statsKeys as $statsKey) {
$parse = Manager::parseManagerStatKey($statsKey);
if ($appId != $parse['appId']) {
continue;
}
$statsItemData = $redis->hgetall($statsKey);
$statsItemData['workerClass'] = $parse['workerClass'];
$statsItemData['appId'] = $parse['appId'];
$managersStats[$parse['appId']][$type][] = $statsItemData;
}
}
}
return $managersStats;
}
|
php
|
public static function getManagersStats()
{
$managersStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$redis = $producer->getRedis();
$keys = [
'stat' => $redis->keys(Manager::REDIS_NS_STATS . '*'),
'live' => $redis->keys(Manager::REDIS_NS_LIVE . '*')
];
foreach ($keys as $type => $statsKeys) {
foreach ($statsKeys as $statsKey) {
$parse = Manager::parseManagerStatKey($statsKey);
if ($appId != $parse['appId']) {
continue;
}
$statsItemData = $redis->hgetall($statsKey);
$statsItemData['workerClass'] = $parse['workerClass'];
$statsItemData['appId'] = $parse['appId'];
$managersStats[$parse['appId']][$type][] = $statsItemData;
}
}
}
return $managersStats;
}
|
[
"public",
"static",
"function",
"getManagersStats",
"(",
")",
"{",
"$",
"managersStats",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"producers",
"as",
"$",
"appId",
"=>",
"$",
"producer",
")",
"{",
"/** @var $producer Producer */",
"$",
"redis",
"=",
"$",
"producer",
"->",
"getRedis",
"(",
")",
";",
"$",
"keys",
"=",
"[",
"'stat'",
"=>",
"$",
"redis",
"->",
"keys",
"(",
"Manager",
"::",
"REDIS_NS_STATS",
".",
"'*'",
")",
",",
"'live'",
"=>",
"$",
"redis",
"->",
"keys",
"(",
"Manager",
"::",
"REDIS_NS_LIVE",
".",
"'*'",
")",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"type",
"=>",
"$",
"statsKeys",
")",
"{",
"foreach",
"(",
"$",
"statsKeys",
"as",
"$",
"statsKey",
")",
"{",
"$",
"parse",
"=",
"Manager",
"::",
"parseManagerStatKey",
"(",
"$",
"statsKey",
")",
";",
"if",
"(",
"$",
"appId",
"!=",
"$",
"parse",
"[",
"'appId'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"statsItemData",
"=",
"$",
"redis",
"->",
"hgetall",
"(",
"$",
"statsKey",
")",
";",
"$",
"statsItemData",
"[",
"'workerClass'",
"]",
"=",
"$",
"parse",
"[",
"'workerClass'",
"]",
";",
"$",
"statsItemData",
"[",
"'appId'",
"]",
"=",
"$",
"parse",
"[",
"'appId'",
"]",
";",
"$",
"managersStats",
"[",
"$",
"parse",
"[",
"'appId'",
"]",
"]",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"statsItemData",
";",
"}",
"}",
"}",
"return",
"$",
"managersStats",
";",
"}"
] |
Get all managers statistic
@return array
|
[
"Get",
"all",
"managers",
"statistic"
] |
train
|
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L183-L213
|
FrenchFrogs/framework
|
src/Form/Renderer/Bootstrap.php
|
Bootstrap.link
|
public function link(Form\Element\Link $element)
{
$html = '<label>' . $element->getLabel() . '</label>';
$html .= '<p>' . html('a', ['href' => $element->getValue(), 'target' => '_blank'], $element->getValue()) . '</p>';
$class = Style::FORM_GROUP_CLASS;
$html = html('div', compact('class'), $html);
return $html;
}
|
php
|
public function link(Form\Element\Link $element)
{
$html = '<label>' . $element->getLabel() . '</label>';
$html .= '<p>' . html('a', ['href' => $element->getValue(), 'target' => '_blank'], $element->getValue()) . '</p>';
$class = Style::FORM_GROUP_CLASS;
$html = html('div', compact('class'), $html);
return $html;
}
|
[
"public",
"function",
"link",
"(",
"Form",
"\\",
"Element",
"\\",
"Link",
"$",
"element",
")",
"{",
"$",
"html",
"=",
"'<label>'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"'</label>'",
";",
"$",
"html",
".=",
"'<p>'",
".",
"html",
"(",
"'a'",
",",
"[",
"'href'",
"=>",
"$",
"element",
"->",
"getValue",
"(",
")",
",",
"'target'",
"=>",
"'_blank'",
"]",
",",
"$",
"element",
"->",
"getValue",
"(",
")",
")",
".",
"'</p>'",
";",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
";",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Render a link element
@param \FrenchFrogs\Form\Element\Link $element
@return string
|
[
"Render",
"a",
"link",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Bootstrap.php#L274-L284
|
FrenchFrogs/framework
|
src/Form/Renderer/Bootstrap.php
|
Bootstrap.date
|
public function date(Form\Element\Date $element)
{
// Error
if($hasError = !$element->getValidator()->isValid()){
$element->removeAttribute('data-trigger');//Si il y avait un popoover au départ on le surcharge par un tooltip
if(empty($element->getAttribute('data-placement'))){$element->addAttribute('data-placement','bottom');}
$message = '';
foreach($element->getValidator()->getErrors() as $error){
$message .= $error . ' ';
}
$element->addAttribute('data-original-title',$message);
$element->addAttribute('data-toggle', 'tooltip');
}
$element->addClass('date-picker');
// rendu principal
$element->addClass(Style::FORM_ELEMENT_CONTROL);
$label = '';
$element->addAttribute('value', $element->getDisplayValue());
if ($element->getForm()->hasLabel()) {
$label = '<label for="' . $element->getName() . '">' . $element->getLabel() . ($element->hasRule('required') ? ' *' : '') . '</label>';
}
$html = $label . html('input', $element->getAttributes());
$class = Style::FORM_GROUP_CLASS;
if ($hasError) {
$class .= ' ' .Style::FORM_GROUP_ERROR;
}
$html = html('div', compact('class'), $html);
return $html;
}
|
php
|
public function date(Form\Element\Date $element)
{
// Error
if($hasError = !$element->getValidator()->isValid()){
$element->removeAttribute('data-trigger');//Si il y avait un popoover au départ on le surcharge par un tooltip
if(empty($element->getAttribute('data-placement'))){$element->addAttribute('data-placement','bottom');}
$message = '';
foreach($element->getValidator()->getErrors() as $error){
$message .= $error . ' ';
}
$element->addAttribute('data-original-title',$message);
$element->addAttribute('data-toggle', 'tooltip');
}
$element->addClass('date-picker');
// rendu principal
$element->addClass(Style::FORM_ELEMENT_CONTROL);
$label = '';
$element->addAttribute('value', $element->getDisplayValue());
if ($element->getForm()->hasLabel()) {
$label = '<label for="' . $element->getName() . '">' . $element->getLabel() . ($element->hasRule('required') ? ' *' : '') . '</label>';
}
$html = $label . html('input', $element->getAttributes());
$class = Style::FORM_GROUP_CLASS;
if ($hasError) {
$class .= ' ' .Style::FORM_GROUP_ERROR;
}
$html = html('div', compact('class'), $html);
return $html;
}
|
[
"public",
"function",
"date",
"(",
"Form",
"\\",
"Element",
"\\",
"Date",
"$",
"element",
")",
"{",
"// Error",
"if",
"(",
"$",
"hasError",
"=",
"!",
"$",
"element",
"->",
"getValidator",
"(",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"element",
"->",
"removeAttribute",
"(",
"'data-trigger'",
")",
";",
"//Si il y avait un popoover au départ on le surcharge par un tooltip",
"if",
"(",
"empty",
"(",
"$",
"element",
"->",
"getAttribute",
"(",
"'data-placement'",
")",
")",
")",
"{",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-placement'",
",",
"'bottom'",
")",
";",
"}",
"$",
"message",
"=",
"''",
";",
"foreach",
"(",
"$",
"element",
"->",
"getValidator",
"(",
")",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"message",
".=",
"$",
"error",
".",
"' '",
";",
"}",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-original-title'",
",",
"$",
"message",
")",
";",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-toggle'",
",",
"'tooltip'",
")",
";",
"}",
"$",
"element",
"->",
"addClass",
"(",
"'date-picker'",
")",
";",
"// rendu principal",
"$",
"element",
"->",
"addClass",
"(",
"Style",
"::",
"FORM_ELEMENT_CONTROL",
")",
";",
"$",
"label",
"=",
"''",
";",
"$",
"element",
"->",
"addAttribute",
"(",
"'value'",
",",
"$",
"element",
"->",
"getDisplayValue",
"(",
")",
")",
";",
"if",
"(",
"$",
"element",
"->",
"getForm",
"(",
")",
"->",
"hasLabel",
"(",
")",
")",
"{",
"$",
"label",
"=",
"'<label for=\"'",
".",
"$",
"element",
"->",
"getName",
"(",
")",
".",
"'\">'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"(",
"$",
"element",
"->",
"hasRule",
"(",
"'required'",
")",
"?",
"' *'",
":",
"''",
")",
".",
"'</label>'",
";",
"}",
"$",
"html",
"=",
"$",
"label",
".",
"html",
"(",
"'input'",
",",
"$",
"element",
"->",
"getAttributes",
"(",
")",
")",
";",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
";",
"if",
"(",
"$",
"hasError",
")",
"{",
"$",
"class",
".=",
"' '",
".",
"Style",
"::",
"FORM_GROUP_ERROR",
";",
"}",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Render a date element
@param \FrenchFrogs\Form\Element\Date $element
@return string
|
[
"Render",
"a",
"date",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Bootstrap.php#L465-L499
|
dengyongbin/loopeer-lib
|
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php
|
PushUtils.getDayTimestamp
|
public static function getDayTimestamp($now = null, $offset = 8) {
$now = $now === null ? time() : $now;
$gtm0 = $now - ($now % 86400); // GTM 0
$dayline = ($now - $gtm0) / 3600;
// 时差跨天
if ($dayline + $offset > 23) {
return $gtm0 + 86400 + $offset * 3600 * - 1;
} else {
return $gtm0 + $offset * 3600 * - 1;
}
}
|
php
|
public static function getDayTimestamp($now = null, $offset = 8) {
$now = $now === null ? time() : $now;
$gtm0 = $now - ($now % 86400); // GTM 0
$dayline = ($now - $gtm0) / 3600;
// 时差跨天
if ($dayline + $offset > 23) {
return $gtm0 + 86400 + $offset * 3600 * - 1;
} else {
return $gtm0 + $offset * 3600 * - 1;
}
}
|
[
"public",
"static",
"function",
"getDayTimestamp",
"(",
"$",
"now",
"=",
"null",
",",
"$",
"offset",
"=",
"8",
")",
"{",
"$",
"now",
"=",
"$",
"now",
"===",
"null",
"?",
"time",
"(",
")",
":",
"$",
"now",
";",
"$",
"gtm0",
"=",
"$",
"now",
"-",
"(",
"$",
"now",
"%",
"86400",
")",
";",
"// GTM 0",
"$",
"dayline",
"=",
"(",
"$",
"now",
"-",
"$",
"gtm0",
")",
"/",
"3600",
";",
"// 时差跨天",
"if",
"(",
"$",
"dayline",
"+",
"$",
"offset",
">",
"23",
")",
"{",
"return",
"$",
"gtm0",
"+",
"86400",
"+",
"$",
"offset",
"*",
"3600",
"*",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"$",
"gtm0",
"+",
"$",
"offset",
"*",
"3600",
"*",
"-",
"1",
";",
"}",
"}"
] |
get the timestamp at current dat start
NOTE: the result start at the timezone (GTM +8) 00:00:00, not the GTM 0.
@param
{number} offset, offset of timezone;
@return number
|
[
"get",
"the",
"timestamp",
"at",
"current",
"dat",
"start"
] |
train
|
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php#L29-L42
|
dengyongbin/loopeer-lib
|
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php
|
PushUtils.getHourTimestamp
|
public static function getHourTimestamp($now = null) {
$now = $now === null ? time() : $now;
$diff = $now % 3600; // 1 * 60 * 60;
return $now - $diff;
}
|
php
|
public static function getHourTimestamp($now = null) {
$now = $now === null ? time() : $now;
$diff = $now % 3600; // 1 * 60 * 60;
return $now - $diff;
}
|
[
"public",
"static",
"function",
"getHourTimestamp",
"(",
"$",
"now",
"=",
"null",
")",
"{",
"$",
"now",
"=",
"$",
"now",
"===",
"null",
"?",
"time",
"(",
")",
":",
"$",
"now",
";",
"$",
"diff",
"=",
"$",
"now",
"%",
"3600",
";",
"// 1 * 60 * 60;",
"return",
"$",
"now",
"-",
"$",
"diff",
";",
"}"
] |
get the timestamp at current hour start
@param int $num 指定时间
@return number
|
[
"get",
"the",
"timestamp",
"at",
"current",
"hour",
"start"
] |
train
|
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php#L48-L52
|
dengyongbin/loopeer-lib
|
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php
|
PushUtils.getMinuteTimestamp
|
public static function getMinuteTimestamp($now = null) {
$now = $now === null ? time() : $now;
$diff = $now % 60;
return $now - $diff;
}
|
php
|
public static function getMinuteTimestamp($now = null) {
$now = $now === null ? time() : $now;
$diff = $now % 60;
return $now - $diff;
}
|
[
"public",
"static",
"function",
"getMinuteTimestamp",
"(",
"$",
"now",
"=",
"null",
")",
"{",
"$",
"now",
"=",
"$",
"now",
"===",
"null",
"?",
"time",
"(",
")",
":",
"$",
"now",
";",
"$",
"diff",
"=",
"$",
"now",
"%",
"60",
";",
"return",
"$",
"now",
"-",
"$",
"diff",
";",
"}"
] |
get the timestamp at current minute start
@param int $num 指定时间
@return number
|
[
"get",
"the",
"timestamp",
"at",
"current",
"minute",
"start"
] |
train
|
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php#L58-L62
|
bfitech/zapcore
|
src/Common.php
|
Common.exec
|
final public static function exec(string $cmd, array $args=[]) {
foreach ($args as $key => $val)
$args[$key] = escapeshellarg($val);
$cmd = vsprintf($cmd, $args);
exec($cmd, $output, $retcode);
if ($retcode !== 0)
return false;
return $output;
}
|
php
|
final public static function exec(string $cmd, array $args=[]) {
foreach ($args as $key => $val)
$args[$key] = escapeshellarg($val);
$cmd = vsprintf($cmd, $args);
exec($cmd, $output, $retcode);
if ($retcode !== 0)
return false;
return $output;
}
|
[
"final",
"public",
"static",
"function",
"exec",
"(",
"string",
"$",
"cmd",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"$",
"args",
"[",
"$",
"key",
"]",
"=",
"escapeshellarg",
"(",
"$",
"val",
")",
";",
"$",
"cmd",
"=",
"vsprintf",
"(",
"$",
"cmd",
",",
"$",
"args",
")",
";",
"exec",
"(",
"$",
"cmd",
",",
"$",
"output",
",",
"$",
"retcode",
")",
";",
"if",
"(",
"$",
"retcode",
"!==",
"0",
")",
"return",
"false",
";",
"return",
"$",
"output",
";",
"}"
] |
Execute arbitrary shell commands. Use with care.
@param string $cmd Command with '%s' as parameter placeholders.
@param array $args List of parameters to replace the
placeholders in command.
@return bool|array False on failure, stdout lines otherwise.
|
[
"Execute",
"arbitrary",
"shell",
"commands",
".",
"Use",
"with",
"care",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L28-L36
|
bfitech/zapcore
|
src/Common.php
|
Common.get_mimetype
|
final public static function get_mimetype(
string $fname, string $path_to_file=null
) {
if (null === $mime = self::_mime_extension($fname))
return self::_mime_magic($fname, $path_to_file);
return $mime;
}
|
php
|
final public static function get_mimetype(
string $fname, string $path_to_file=null
) {
if (null === $mime = self::_mime_extension($fname))
return self::_mime_magic($fname, $path_to_file);
return $mime;
}
|
[
"final",
"public",
"static",
"function",
"get_mimetype",
"(",
"string",
"$",
"fname",
",",
"string",
"$",
"path_to_file",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"mime",
"=",
"self",
"::",
"_mime_extension",
"(",
"$",
"fname",
")",
")",
"return",
"self",
"::",
"_mime_magic",
"(",
"$",
"fname",
",",
"$",
"path_to_file",
")",
";",
"return",
"$",
"mime",
";",
"}"
] |
Find a mime type.
@param string $fname The file name.
@param string $path_to_file Path to `file`. Useful if
you have it outside PATH.
@return string The MIME type or application/octet-stream.
|
[
"Find",
"a",
"mime",
"type",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L46-L53
|
bfitech/zapcore
|
src/Common.php
|
Common._mime_extension
|
private static function _mime_extension(string $fname) {
$pinfo = pathinfo($fname);
// @codeCoverageIgnoreStart
if (!isset($pinfo['extension']))
return null;
// @codeCoverageIgnoreEnd
# Because these things are magically ambiguous, we'll
# resort to extension.
switch (strtolower($pinfo['extension'])) {
case 'css':
return 'text/css';
case 'js':
return 'application/javascript';
case 'json':
return 'application/json';
case 'htm':
case 'html':
# always assume UTF-8
return 'text/html; charset=utf-8';
}
return null;
}
|
php
|
private static function _mime_extension(string $fname) {
$pinfo = pathinfo($fname);
// @codeCoverageIgnoreStart
if (!isset($pinfo['extension']))
return null;
// @codeCoverageIgnoreEnd
# Because these things are magically ambiguous, we'll
# resort to extension.
switch (strtolower($pinfo['extension'])) {
case 'css':
return 'text/css';
case 'js':
return 'application/javascript';
case 'json':
return 'application/json';
case 'htm':
case 'html':
# always assume UTF-8
return 'text/html; charset=utf-8';
}
return null;
}
|
[
"private",
"static",
"function",
"_mime_extension",
"(",
"string",
"$",
"fname",
")",
"{",
"$",
"pinfo",
"=",
"pathinfo",
"(",
"$",
"fname",
")",
";",
"// @codeCoverageIgnoreStart",
"if",
"(",
"!",
"isset",
"(",
"$",
"pinfo",
"[",
"'extension'",
"]",
")",
")",
"return",
"null",
";",
"// @codeCoverageIgnoreEnd",
"# Because these things are magically ambiguous, we'll",
"# resort to extension.",
"switch",
"(",
"strtolower",
"(",
"$",
"pinfo",
"[",
"'extension'",
"]",
")",
")",
"{",
"case",
"'css'",
":",
"return",
"'text/css'",
";",
"case",
"'js'",
":",
"return",
"'application/javascript'",
";",
"case",
"'json'",
":",
"return",
"'application/json'",
";",
"case",
"'htm'",
":",
"case",
"'html'",
":",
"# always assume UTF-8",
"return",
"'text/html; charset=utf-8'",
";",
"}",
"return",
"null",
";",
"}"
] |
Get MIME by extension.
Useful for serving typical text files that don't have unique
magic numbers.
|
[
"Get",
"MIME",
"by",
"extension",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L61-L82
|
bfitech/zapcore
|
src/Common.php
|
Common._mime_magic
|
private static function _mime_magic(
string $fname, string $path_to_file=null
) {
# with builtin
if (
function_exists('mime_content_type') &&
($mime = @mime_content_type($fname)) &&
$mime != 'application/octet-stream'
)
return $mime;
# with `file`, skip coverage because `file` is usually
# not available on CI
// @codeCoverageIgnoreStart
if ($path_to_file && is_executable($path_to_file)) {
$bin = $path_to_file;
} elseif (!($bin = self::exec("bash -c 'type -p file'")[0])) {
return 'application/octet-stream';
}
if (
($mimes = self::exec('%s -bip %s', [$bin, $fname])) &&
preg_match('!^[a-z0-9\-]+/!i', $mimes[0])
)
return $mimes[0];
# giving up
return 'application/octet-stream';
// @codeCoverageIgnoreEnd
}
|
php
|
private static function _mime_magic(
string $fname, string $path_to_file=null
) {
# with builtin
if (
function_exists('mime_content_type') &&
($mime = @mime_content_type($fname)) &&
$mime != 'application/octet-stream'
)
return $mime;
# with `file`, skip coverage because `file` is usually
# not available on CI
// @codeCoverageIgnoreStart
if ($path_to_file && is_executable($path_to_file)) {
$bin = $path_to_file;
} elseif (!($bin = self::exec("bash -c 'type -p file'")[0])) {
return 'application/octet-stream';
}
if (
($mimes = self::exec('%s -bip %s', [$bin, $fname])) &&
preg_match('!^[a-z0-9\-]+/!i', $mimes[0])
)
return $mimes[0];
# giving up
return 'application/octet-stream';
// @codeCoverageIgnoreEnd
}
|
[
"private",
"static",
"function",
"_mime_magic",
"(",
"string",
"$",
"fname",
",",
"string",
"$",
"path_to_file",
"=",
"null",
")",
"{",
"# with builtin",
"if",
"(",
"function_exists",
"(",
"'mime_content_type'",
")",
"&&",
"(",
"$",
"mime",
"=",
"@",
"mime_content_type",
"(",
"$",
"fname",
")",
")",
"&&",
"$",
"mime",
"!=",
"'application/octet-stream'",
")",
"return",
"$",
"mime",
";",
"# with `file`, skip coverage because `file` is usually",
"# not available on CI",
"// @codeCoverageIgnoreStart",
"if",
"(",
"$",
"path_to_file",
"&&",
"is_executable",
"(",
"$",
"path_to_file",
")",
")",
"{",
"$",
"bin",
"=",
"$",
"path_to_file",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"bin",
"=",
"self",
"::",
"exec",
"(",
"\"bash -c 'type -p file'\"",
")",
"[",
"0",
"]",
")",
")",
"{",
"return",
"'application/octet-stream'",
";",
"}",
"if",
"(",
"(",
"$",
"mimes",
"=",
"self",
"::",
"exec",
"(",
"'%s -bip %s'",
",",
"[",
"$",
"bin",
",",
"$",
"fname",
"]",
")",
")",
"&&",
"preg_match",
"(",
"'!^[a-z0-9\\-]+/!i'",
",",
"$",
"mimes",
"[",
"0",
"]",
")",
")",
"return",
"$",
"mimes",
"[",
"0",
"]",
";",
"# giving up",
"return",
"'application/octet-stream'",
";",
"// @codeCoverageIgnoreEnd",
"}"
] |
Get MIME type with `mime_content_type` or `file`.
|
[
"Get",
"MIME",
"type",
"with",
"mime_content_type",
"or",
"file",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L87-L116
|
bfitech/zapcore
|
src/Common.php
|
Common.http_client
|
public static function http_client(array $kwargs) {
$url = $method = null;
$headers = $get = $post = $custom_opts = [];
$expect_json = false;
extract(self::extract_kwargs($kwargs, [
'url' => null,
'method' => 'GET',
'headers'=> [],
'get' => [],
'post' => [],
'custom_opts' => [],
'expect_json' => false,
]));
if (!$url)
throw new CommonError("URL not set.");
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CONNECTTIMEOUT => 16,
CURLOPT_TIMEOUT => 16,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 8,
CURLOPT_HEADER => false,
];
foreach ($custom_opts as $key => $val)
$opts[$key] = $val;
$conn = curl_init();
foreach ($opts as $key => $val)
curl_setopt($conn, $key, $val);
if ($headers)
curl_setopt($conn, CURLOPT_HTTPHEADER, $headers);
if ($get) {
$url .= strpos($url, '?') !== false ? '&' : '?';
$url .= http_build_query($get);
}
curl_setopt($conn, CURLOPT_URL, $url);
if (is_array($post))
$post = http_build_query($post);
switch ($method) {
case 'GET':
break;
case 'HEAD':
case 'OPTIONS':
curl_setopt($conn, CURLOPT_NOBODY, true);
curl_setopt($conn, CURLOPT_HEADER, true);
break;
case 'POST':
case 'PUT':
case 'DELETE':
case 'PATCH':
case 'TRACE':
curl_setopt($conn, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($conn, CURLOPT_POSTFIELDS, $post);
break;
default:
# CONNECT etc. are not supported ... yet?
return [-1, null];
}
$body = curl_exec($conn);
$info = curl_getinfo($conn);
curl_close($conn);
if (in_array($method, ['HEAD', 'OPTIONS']))
return [$info['http_code'], $body];
if ($expect_json)
$body = @json_decode($body, true);
return [$info['http_code'], $body];
}
|
php
|
public static function http_client(array $kwargs) {
$url = $method = null;
$headers = $get = $post = $custom_opts = [];
$expect_json = false;
extract(self::extract_kwargs($kwargs, [
'url' => null,
'method' => 'GET',
'headers'=> [],
'get' => [],
'post' => [],
'custom_opts' => [],
'expect_json' => false,
]));
if (!$url)
throw new CommonError("URL not set.");
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CONNECTTIMEOUT => 16,
CURLOPT_TIMEOUT => 16,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 8,
CURLOPT_HEADER => false,
];
foreach ($custom_opts as $key => $val)
$opts[$key] = $val;
$conn = curl_init();
foreach ($opts as $key => $val)
curl_setopt($conn, $key, $val);
if ($headers)
curl_setopt($conn, CURLOPT_HTTPHEADER, $headers);
if ($get) {
$url .= strpos($url, '?') !== false ? '&' : '?';
$url .= http_build_query($get);
}
curl_setopt($conn, CURLOPT_URL, $url);
if (is_array($post))
$post = http_build_query($post);
switch ($method) {
case 'GET':
break;
case 'HEAD':
case 'OPTIONS':
curl_setopt($conn, CURLOPT_NOBODY, true);
curl_setopt($conn, CURLOPT_HEADER, true);
break;
case 'POST':
case 'PUT':
case 'DELETE':
case 'PATCH':
case 'TRACE':
curl_setopt($conn, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($conn, CURLOPT_POSTFIELDS, $post);
break;
default:
# CONNECT etc. are not supported ... yet?
return [-1, null];
}
$body = curl_exec($conn);
$info = curl_getinfo($conn);
curl_close($conn);
if (in_array($method, ['HEAD', 'OPTIONS']))
return [$info['http_code'], $body];
if ($expect_json)
$body = @json_decode($body, true);
return [$info['http_code'], $body];
}
|
[
"public",
"static",
"function",
"http_client",
"(",
"array",
"$",
"kwargs",
")",
"{",
"$",
"url",
"=",
"$",
"method",
"=",
"null",
";",
"$",
"headers",
"=",
"$",
"get",
"=",
"$",
"post",
"=",
"$",
"custom_opts",
"=",
"[",
"]",
";",
"$",
"expect_json",
"=",
"false",
";",
"extract",
"(",
"self",
"::",
"extract_kwargs",
"(",
"$",
"kwargs",
",",
"[",
"'url'",
"=>",
"null",
",",
"'method'",
"=>",
"'GET'",
",",
"'headers'",
"=>",
"[",
"]",
",",
"'get'",
"=>",
"[",
"]",
",",
"'post'",
"=>",
"[",
"]",
",",
"'custom_opts'",
"=>",
"[",
"]",
",",
"'expect_json'",
"=>",
"false",
",",
"]",
")",
")",
";",
"if",
"(",
"!",
"$",
"url",
")",
"throw",
"new",
"CommonError",
"(",
"\"URL not set.\"",
")",
";",
"$",
"opts",
"=",
"[",
"CURLOPT_RETURNTRANSFER",
"=>",
"true",
",",
"CURLOPT_SSL_VERIFYPEER",
"=>",
"true",
",",
"CURLOPT_CONNECTTIMEOUT",
"=>",
"16",
",",
"CURLOPT_TIMEOUT",
"=>",
"16",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"true",
",",
"CURLOPT_MAXREDIRS",
"=>",
"8",
",",
"CURLOPT_HEADER",
"=>",
"false",
",",
"]",
";",
"foreach",
"(",
"$",
"custom_opts",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"$",
"opts",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"$",
"conn",
"=",
"curl_init",
"(",
")",
";",
"foreach",
"(",
"$",
"opts",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"curl_setopt",
"(",
"$",
"conn",
",",
"$",
"key",
",",
"$",
"val",
")",
";",
"if",
"(",
"$",
"headers",
")",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"if",
"(",
"$",
"get",
")",
"{",
"$",
"url",
".=",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
"!==",
"false",
"?",
"'&'",
":",
"'?'",
";",
"$",
"url",
".=",
"http_build_query",
"(",
"$",
"get",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"post",
")",
")",
"$",
"post",
"=",
"http_build_query",
"(",
"$",
"post",
")",
";",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'GET'",
":",
"break",
";",
"case",
"'HEAD'",
":",
"case",
"'OPTIONS'",
":",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_NOBODY",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_HEADER",
",",
"true",
")",
";",
"break",
";",
"case",
"'POST'",
":",
"case",
"'PUT'",
":",
"case",
"'DELETE'",
":",
"case",
"'PATCH'",
":",
"case",
"'TRACE'",
":",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"post",
")",
";",
"break",
";",
"default",
":",
"# CONNECT etc. are not supported ... yet?",
"return",
"[",
"-",
"1",
",",
"null",
"]",
";",
"}",
"$",
"body",
"=",
"curl_exec",
"(",
"$",
"conn",
")",
";",
"$",
"info",
"=",
"curl_getinfo",
"(",
"$",
"conn",
")",
";",
"curl_close",
"(",
"$",
"conn",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"method",
",",
"[",
"'HEAD'",
",",
"'OPTIONS'",
"]",
")",
")",
"return",
"[",
"$",
"info",
"[",
"'http_code'",
"]",
",",
"$",
"body",
"]",
";",
"if",
"(",
"$",
"expect_json",
")",
"$",
"body",
"=",
"@",
"json_decode",
"(",
"$",
"body",
",",
"true",
")",
";",
"return",
"[",
"$",
"info",
"[",
"'http_code'",
"]",
",",
"$",
"body",
"]",
";",
"}"
] |
cURL-based HTTP client.
@param array $kwargs Dict with key-value:
- `url` : (string) the URL
- `method` : (string) HTTP request method
- `headers` : (array) optional request headers, useful for
setting MIME type, user agent, etc.
- `get` : (dict) query string will be built off of
this; leave empty if you already have
query string in URL, unless you have to
- `post` : (dict|string) POST, PUT, or other request
body; if it's a string, it won't be formatted
as a query string
- `custom_opts` :
(dict) custom cURL options to add or override
defaults
- `expect_json` :
(bool) JSON-decode response if true, whether
server honors `Accept: application/json`
request header or not; response data is null
if response body is not valid JSON
@return array A list of the form `[HTTP code, response body]`.
HTTP code is -1 for invalid method, 0 for failing connection,
and any of standard code for successful connection.
@if TRUE
@codeCoverageIgnore
@SuppressWarnings(PHPMD.CyclomaticComplexity)
@SuppressWarnings(PHPMD.NPathComplexity)
@endif
|
[
"cURL",
"-",
"based",
"HTTP",
"client",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L150-L225
|
bfitech/zapcore
|
src/Common.php
|
Common.check_dict
|
final public static function check_dict(
array $array, array $keys, bool $trim=false
) {
$checked = [];
foreach ($keys as $key) {
if (!isset($array[$key]))
return false;
$val = $array[$key];
if ($trim) {
if (!is_string($val))
return false;
$val = trim($val);
if (!$val)
return false;
}
$checked[$key] = $val;
}
return $checked;
}
|
php
|
final public static function check_dict(
array $array, array $keys, bool $trim=false
) {
$checked = [];
foreach ($keys as $key) {
if (!isset($array[$key]))
return false;
$val = $array[$key];
if ($trim) {
if (!is_string($val))
return false;
$val = trim($val);
if (!$val)
return false;
}
$checked[$key] = $val;
}
return $checked;
}
|
[
"final",
"public",
"static",
"function",
"check_dict",
"(",
"array",
"$",
"array",
",",
"array",
"$",
"keys",
",",
"bool",
"$",
"trim",
"=",
"false",
")",
"{",
"$",
"checked",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
"return",
"false",
";",
"$",
"val",
"=",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"trim",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"val",
")",
")",
"return",
"false",
";",
"$",
"val",
"=",
"trim",
"(",
"$",
"val",
")",
";",
"if",
"(",
"!",
"$",
"val",
")",
"return",
"false",
";",
"}",
"$",
"checked",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"checked",
";",
"}"
] |
Check if a dict contains all necessary keys.
@param array $array Dict to verify.
@param array $keys List of keys to verify against.
@param bool $trim Whether it should treat everything as string
and trim the values and drop keys of those with empty values.
@return bool|array False on failure, filtered dict otherwise.
|
[
"Check",
"if",
"a",
"dict",
"contains",
"all",
"necessary",
"keys",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L236-L254
|
bfitech/zapcore
|
src/Common.php
|
Common.check_idict
|
final public static function check_idict(
array $array, array $keys, bool $trim=false
) {
if (false === $array = self::check_dict($array, $keys, $trim))
return false;
foreach ($array as $val) {
if (!is_numeric($val) && !is_string($val))
return false;
}
return $array;
}
|
php
|
final public static function check_idict(
array $array, array $keys, bool $trim=false
) {
if (false === $array = self::check_dict($array, $keys, $trim))
return false;
foreach ($array as $val) {
if (!is_numeric($val) && !is_string($val))
return false;
}
return $array;
}
|
[
"final",
"public",
"static",
"function",
"check_idict",
"(",
"array",
"$",
"array",
",",
"array",
"$",
"keys",
",",
"bool",
"$",
"trim",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"array",
"=",
"self",
"::",
"check_dict",
"(",
"$",
"array",
",",
"$",
"keys",
",",
"$",
"trim",
")",
")",
"return",
"false",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"val",
")",
"&&",
"!",
"is_string",
"(",
"$",
"val",
")",
")",
"return",
"false",
";",
"}",
"return",
"$",
"array",
";",
"}"
] |
Check if a dict contains all necessary keys with elements being
immutables, i.e. numeric or string.
@param array $array Dict to verify.
@param array $keys List of keys to verify against.
@param bool $trim Whether it should treat everything as string
and trim the values and drop keys of those with empty values.
@return bool|array False on failure, filtered dict otherwise.
|
[
"Check",
"if",
"a",
"dict",
"contains",
"all",
"necessary",
"keys",
"with",
"elements",
"being",
"immutables",
"i",
".",
"e",
".",
"numeric",
"or",
"string",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L266-L276
|
bfitech/zapcore
|
src/Common.php
|
Common.extract_kwargs
|
final public static function extract_kwargs(
array $input_array, array $init_array
) {
foreach (array_keys($init_array) as $key) {
if (isset($input_array[$key]))
$init_array[$key] = $input_array[$key];
}
return $init_array;
}
|
php
|
final public static function extract_kwargs(
array $input_array, array $init_array
) {
foreach (array_keys($init_array) as $key) {
if (isset($input_array[$key]))
$init_array[$key] = $input_array[$key];
}
return $init_array;
}
|
[
"final",
"public",
"static",
"function",
"extract_kwargs",
"(",
"array",
"$",
"input_array",
",",
"array",
"$",
"init_array",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"init_array",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"input_array",
"[",
"$",
"key",
"]",
")",
")",
"$",
"init_array",
"[",
"$",
"key",
"]",
"=",
"$",
"input_array",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"init_array",
";",
"}"
] |
Initiate a kwargs array for safe extraction.
This will remove keys not available in $init_array instead
of filling in holes in input array.
@param array $input_array Input array, typically first
parameter in a method.
@param array $init_array Fallback array when input array
is not complete, of the form: `key => default value`.
@return array A complete array ready to be extract()ed.
|
[
"Initiate",
"a",
"kwargs",
"array",
"for",
"safe",
"extraction",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L290-L298
|
tonicospinelli/class-generation
|
src/ClassGeneration/Visibility.php
|
Visibility.isValid
|
public static function isValid($visibility)
{
switch ($visibility) {
case Visibility::TYPE_PRIVATE:
case Visibility::TYPE_PROTECTED:
case Visibility::TYPE_PUBLIC:
return true;
}
throw new \InvalidArgumentException('The ' . $visibility . ' is not allowed');
}
|
php
|
public static function isValid($visibility)
{
switch ($visibility) {
case Visibility::TYPE_PRIVATE:
case Visibility::TYPE_PROTECTED:
case Visibility::TYPE_PUBLIC:
return true;
}
throw new \InvalidArgumentException('The ' . $visibility . ' is not allowed');
}
|
[
"public",
"static",
"function",
"isValid",
"(",
"$",
"visibility",
")",
"{",
"switch",
"(",
"$",
"visibility",
")",
"{",
"case",
"Visibility",
"::",
"TYPE_PRIVATE",
":",
"case",
"Visibility",
"::",
"TYPE_PROTECTED",
":",
"case",
"Visibility",
"::",
"TYPE_PUBLIC",
":",
"return",
"true",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The '",
".",
"$",
"visibility",
".",
"' is not allowed'",
")",
";",
"}"
] |
Validate visiblity.
@param string $visibility
@throws \InvalidArgumentException
@return bool
|
[
"Validate",
"visiblity",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/Visibility.php#L34-L43
|
ua1-labs/firebug
|
Fire/Bug/Panel/Debugger.php
|
Debugger.render
|
public function render() {
if (!$this->_enableXDebugOverlay) {
ini_set('xdebug.overload_var_dump', 'off');
}
$debuggerCount = count($this->_debuggers);
$this->setName(str_replace('{count}', '{' . $debuggerCount . '}', self::NAME));
parent::render();
}
|
php
|
public function render() {
if (!$this->_enableXDebugOverlay) {
ini_set('xdebug.overload_var_dump', 'off');
}
$debuggerCount = count($this->_debuggers);
$this->setName(str_replace('{count}', '{' . $debuggerCount . '}', self::NAME));
parent::render();
}
|
[
"public",
"function",
"render",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_enableXDebugOverlay",
")",
"{",
"ini_set",
"(",
"'xdebug.overload_var_dump'",
",",
"'off'",
")",
";",
"}",
"$",
"debuggerCount",
"=",
"count",
"(",
"$",
"this",
"->",
"_debuggers",
")",
";",
"$",
"this",
"->",
"setName",
"(",
"str_replace",
"(",
"'{count}'",
",",
"'{'",
".",
"$",
"debuggerCount",
".",
"'}'",
",",
"self",
"::",
"NAME",
")",
")",
";",
"parent",
"::",
"render",
"(",
")",
";",
"}"
] |
Renders the panel HTML.
@return void
|
[
"Renders",
"the",
"panel",
"HTML",
"."
] |
train
|
https://github.com/ua1-labs/firebug/blob/70a45b2c0bbf64978641eb07e5f3cddfc1951162/Fire/Bug/Panel/Debugger.php#L89-L96
|
BugBuster1701/banner
|
classes/BannerCheckHelper.php
|
BannerCheckHelper.checkExtensions
|
public function checkExtensions($strContent, $strTemplate)
{
if ($strTemplate == 'be_main')
{
if (!is_array($_SESSION["TL_INFO"]))
{
$_SESSION["TL_INFO"] = array();
}
// required extensions
$arrRequiredExtensions = array(
'Bot Detection' => 'botdetection'/*,
'xls_export' => 'xls_export'*/
);
// check for required extensions
foreach ($arrRequiredExtensions as $key => $val)
{
if (!in_array($val, $this->Config->getActiveModules()))
{
$_SESSION["TL_INFO"] = array_merge($_SESSION["TL_INFO"], array($val => 'Please install the required extension <strong>' . $key . '</strong>'));
}
else
{
if (is_array($_SESSION["TL_INFO"]) && key_exists($val, $_SESSION["TL_INFO"]))
{
unset($_SESSION["TL_INFO"][$val]);
}
}
}
}
return $strContent;
}
|
php
|
public function checkExtensions($strContent, $strTemplate)
{
if ($strTemplate == 'be_main')
{
if (!is_array($_SESSION["TL_INFO"]))
{
$_SESSION["TL_INFO"] = array();
}
// required extensions
$arrRequiredExtensions = array(
'Bot Detection' => 'botdetection'/*,
'xls_export' => 'xls_export'*/
);
// check for required extensions
foreach ($arrRequiredExtensions as $key => $val)
{
if (!in_array($val, $this->Config->getActiveModules()))
{
$_SESSION["TL_INFO"] = array_merge($_SESSION["TL_INFO"], array($val => 'Please install the required extension <strong>' . $key . '</strong>'));
}
else
{
if (is_array($_SESSION["TL_INFO"]) && key_exists($val, $_SESSION["TL_INFO"]))
{
unset($_SESSION["TL_INFO"][$val]);
}
}
}
}
return $strContent;
}
|
[
"public",
"function",
"checkExtensions",
"(",
"$",
"strContent",
",",
"$",
"strTemplate",
")",
"{",
"if",
"(",
"$",
"strTemplate",
"==",
"'be_main'",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"_SESSION",
"[",
"\"TL_INFO\"",
"]",
")",
")",
"{",
"$",
"_SESSION",
"[",
"\"TL_INFO\"",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// required extensions",
"$",
"arrRequiredExtensions",
"=",
"array",
"(",
"'Bot Detection'",
"=>",
"'botdetection'",
"/*,\n \t\t'xls_export' => 'xls_export'*/",
")",
";",
"// check for required extensions",
"foreach",
"(",
"$",
"arrRequiredExtensions",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"val",
",",
"$",
"this",
"->",
"Config",
"->",
"getActiveModules",
"(",
")",
")",
")",
"{",
"$",
"_SESSION",
"[",
"\"TL_INFO\"",
"]",
"=",
"array_merge",
"(",
"$",
"_SESSION",
"[",
"\"TL_INFO\"",
"]",
",",
"array",
"(",
"$",
"val",
"=>",
"'Please install the required extension <strong>'",
".",
"$",
"key",
".",
"'</strong>'",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"_SESSION",
"[",
"\"TL_INFO\"",
"]",
")",
"&&",
"key_exists",
"(",
"$",
"val",
",",
"$",
"_SESSION",
"[",
"\"TL_INFO\"",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"\"TL_INFO\"",
"]",
"[",
"$",
"val",
"]",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"strContent",
";",
"}"
] |
Hook: Check the required extensions and files for Banner
@param string $strContent
@param string $strTemplate
@return string
|
[
"Hook",
":",
"Check",
"the",
"required",
"extensions",
"and",
"files",
"for",
"Banner"
] |
train
|
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerCheckHelper.php#L68-L102
|
bocharsky-bw/FileNamingResolver
|
src/FileNamingResolver.php
|
FileNamingResolver.resolve
|
public function resolve(FileInfo $srcFileInfo)
{
$dstFileInfo = $this->namingStrategy->provideName($srcFileInfo);
if (!$dstFileInfo instanceof FileInfo) {
throw new \RuntimeException(
sprintf(
'Specified naming strategy should return an instance of "%s" class',
'\FileNamingResolver\FileInfo'
)
);
}
return $dstFileInfo;
}
|
php
|
public function resolve(FileInfo $srcFileInfo)
{
$dstFileInfo = $this->namingStrategy->provideName($srcFileInfo);
if (!$dstFileInfo instanceof FileInfo) {
throw new \RuntimeException(
sprintf(
'Specified naming strategy should return an instance of "%s" class',
'\FileNamingResolver\FileInfo'
)
);
}
return $dstFileInfo;
}
|
[
"public",
"function",
"resolve",
"(",
"FileInfo",
"$",
"srcFileInfo",
")",
"{",
"$",
"dstFileInfo",
"=",
"$",
"this",
"->",
"namingStrategy",
"->",
"provideName",
"(",
"$",
"srcFileInfo",
")",
";",
"if",
"(",
"!",
"$",
"dstFileInfo",
"instanceof",
"FileInfo",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Specified naming strategy should return an instance of \"%s\" class'",
",",
"'\\FileNamingResolver\\FileInfo'",
")",
")",
";",
"}",
"return",
"$",
"dstFileInfo",
";",
"}"
] |
@param FileInfo $srcFileInfo The source FileInfo
@return FileInfo The destination FileInfo
@throws \RuntimeException If specified naming strategy returns not FileNamingResolver\FileInfo instance
|
[
"@param",
"FileInfo",
"$srcFileInfo",
"The",
"source",
"FileInfo"
] |
train
|
https://github.com/bocharsky-bw/FileNamingResolver/blob/0a0fe86fee0e7acf1ab43a84c1abd51954ce2fbe/src/FileNamingResolver.php#L32-L45
|
blast-project/CoreBundle
|
src/Controller/CRUDController.php
|
CRUDController.generateEntityCodeAction
|
public function generateEntityCodeAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
if ($id) {
$subject = $this->admin->getObject($id);
if (!$subject) {
$error = sprintf('unable to find the object with id : %s', $id);
return new JsonResponse(['error' => $error]);
}
try {
$this->admin->checkAccess('edit', $subject); // TODO: is it necessary ? (we are not editing the entity)
} catch (Exception $exc) {
$error = $exc->getMessage();
return new JsonResponse(['error' => $error]);
}
} else {
$subject = $this->admin->getNewInstance();
}
$this->admin->setSubject($subject);
$form = $this->admin->getForm();
$form->setData($subject);
$form->submit($request->request->get($form->getName()));
$entity = $form->getData();
$field = $request->query->get('field', 'code');
$registry = $this->get('blast_core.code_generators');
$generator = $registry::getCodeGenerator(get_class($entity), $field);
try {
$code = $generator::generate($entity);
return new JsonResponse(['code' => $code]);
} catch (\Exception $exc) {
$error = $this->get('translator')->trans($exc->getMessage());
return new JsonResponse(['error' => $error, 'generator' => get_class($generator)]);
}
}
|
php
|
public function generateEntityCodeAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
if ($id) {
$subject = $this->admin->getObject($id);
if (!$subject) {
$error = sprintf('unable to find the object with id : %s', $id);
return new JsonResponse(['error' => $error]);
}
try {
$this->admin->checkAccess('edit', $subject); // TODO: is it necessary ? (we are not editing the entity)
} catch (Exception $exc) {
$error = $exc->getMessage();
return new JsonResponse(['error' => $error]);
}
} else {
$subject = $this->admin->getNewInstance();
}
$this->admin->setSubject($subject);
$form = $this->admin->getForm();
$form->setData($subject);
$form->submit($request->request->get($form->getName()));
$entity = $form->getData();
$field = $request->query->get('field', 'code');
$registry = $this->get('blast_core.code_generators');
$generator = $registry::getCodeGenerator(get_class($entity), $field);
try {
$code = $generator::generate($entity);
return new JsonResponse(['code' => $code]);
} catch (\Exception $exc) {
$error = $this->get('translator')->trans($exc->getMessage());
return new JsonResponse(['error' => $error, 'generator' => get_class($generator)]);
}
}
|
[
"public",
"function",
"generateEntityCodeAction",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"id",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getIdParameter",
"(",
")",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"subject",
"=",
"$",
"this",
"->",
"admin",
"->",
"getObject",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"subject",
")",
"{",
"$",
"error",
"=",
"sprintf",
"(",
"'unable to find the object with id : %s'",
",",
"$",
"id",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'error'",
"=>",
"$",
"error",
"]",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'edit'",
",",
"$",
"subject",
")",
";",
"// TODO: is it necessary ? (we are not editing the entity)",
"}",
"catch",
"(",
"Exception",
"$",
"exc",
")",
"{",
"$",
"error",
"=",
"$",
"exc",
"->",
"getMessage",
"(",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'error'",
"=>",
"$",
"error",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"subject",
"=",
"$",
"this",
"->",
"admin",
"->",
"getNewInstance",
"(",
")",
";",
"}",
"$",
"this",
"->",
"admin",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"admin",
"->",
"getForm",
"(",
")",
";",
"$",
"form",
"->",
"setData",
"(",
"$",
"subject",
")",
";",
"$",
"form",
"->",
"submit",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"$",
"form",
"->",
"getName",
"(",
")",
")",
")",
";",
"$",
"entity",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"$",
"field",
"=",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'field'",
",",
"'code'",
")",
";",
"$",
"registry",
"=",
"$",
"this",
"->",
"get",
"(",
"'blast_core.code_generators'",
")",
";",
"$",
"generator",
"=",
"$",
"registry",
"::",
"getCodeGenerator",
"(",
"get_class",
"(",
"$",
"entity",
")",
",",
"$",
"field",
")",
";",
"try",
"{",
"$",
"code",
"=",
"$",
"generator",
"::",
"generate",
"(",
"$",
"entity",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'code'",
"=>",
"$",
"code",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exc",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'error'",
"=>",
"$",
"error",
",",
"'generator'",
"=>",
"get_class",
"(",
"$",
"generator",
")",
"]",
")",
";",
"}",
"}"
] |
Generate Entity Code action.
@param int|string|null $id
@return JsonResponse
|
[
"Generate",
"Entity",
"Code",
"action",
"."
] |
train
|
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Controller/CRUDController.php#L174-L216
|
baleen/cli
|
src/CommandBus/Config/StatusHandler.php
|
StatusHandler.handle
|
public function handle(StatusMessage $message)
{
$this->message = $message;
$this->output = $message->getOutput();
$output = $this->output;
$repository = $message->getRepository();
$storage = $message->getStorage();
$availableMigrations = $repository->fetchAll();
$migratedVersions = $storage->fetchAll();
$migratedVersions->sortWith($message->getComparator());
$headVersion = $migratedVersions->last();
$currentMessage = $headVersion ?
"Current version: <comment>{$headVersion->getId()}</comment>" :
'Nothing has been migrated yet.';
$output->writeln($currentMessage);
$diff = array_diff($availableMigrations->toArray(), $migratedVersions->toArray());
$pendingCount = count($diff);
if ($pendingCount > 0) {
$executable = defined('MIGRATIONS_EXECUTABLE') ? MIGRATIONS_EXECUTABLE . ' ' : '';
$output->writeln([
"Your database is out-of-date by $pendingCount versions, and can be migrated.",
sprintf(
' (use "<comment>%smigrate</comment>" to execute all migrations)',
$executable
),
''
]);
if ($headVersion) {
list($beforeHead, $afterHead) = $this->splitDiff($diff, $message->getComparator(), $headVersion);
} else {
$beforeHead = [];
$afterHead = $diff;
}
$this->printDiff(
$beforeHead,
[
'Old migrations still pending:',
sprintf(" (use \"<comment>{$executable}migrate HEAD</comment>\" to migrate them)", $executable),
],
self::STYLE_COMMENT
);
$this->printDiff($afterHead, ['New migrations:'], self::STYLE_INFO);
} else {
$output->writeln('Your database is up-to-date.');
}
}
|
php
|
public function handle(StatusMessage $message)
{
$this->message = $message;
$this->output = $message->getOutput();
$output = $this->output;
$repository = $message->getRepository();
$storage = $message->getStorage();
$availableMigrations = $repository->fetchAll();
$migratedVersions = $storage->fetchAll();
$migratedVersions->sortWith($message->getComparator());
$headVersion = $migratedVersions->last();
$currentMessage = $headVersion ?
"Current version: <comment>{$headVersion->getId()}</comment>" :
'Nothing has been migrated yet.';
$output->writeln($currentMessage);
$diff = array_diff($availableMigrations->toArray(), $migratedVersions->toArray());
$pendingCount = count($diff);
if ($pendingCount > 0) {
$executable = defined('MIGRATIONS_EXECUTABLE') ? MIGRATIONS_EXECUTABLE . ' ' : '';
$output->writeln([
"Your database is out-of-date by $pendingCount versions, and can be migrated.",
sprintf(
' (use "<comment>%smigrate</comment>" to execute all migrations)',
$executable
),
''
]);
if ($headVersion) {
list($beforeHead, $afterHead) = $this->splitDiff($diff, $message->getComparator(), $headVersion);
} else {
$beforeHead = [];
$afterHead = $diff;
}
$this->printDiff(
$beforeHead,
[
'Old migrations still pending:',
sprintf(" (use \"<comment>{$executable}migrate HEAD</comment>\" to migrate them)", $executable),
],
self::STYLE_COMMENT
);
$this->printDiff($afterHead, ['New migrations:'], self::STYLE_INFO);
} else {
$output->writeln('Your database is up-to-date.');
}
}
|
[
"public",
"function",
"handle",
"(",
"StatusMessage",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"message",
"=",
"$",
"message",
";",
"$",
"this",
"->",
"output",
"=",
"$",
"message",
"->",
"getOutput",
"(",
")",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"output",
";",
"$",
"repository",
"=",
"$",
"message",
"->",
"getRepository",
"(",
")",
";",
"$",
"storage",
"=",
"$",
"message",
"->",
"getStorage",
"(",
")",
";",
"$",
"availableMigrations",
"=",
"$",
"repository",
"->",
"fetchAll",
"(",
")",
";",
"$",
"migratedVersions",
"=",
"$",
"storage",
"->",
"fetchAll",
"(",
")",
";",
"$",
"migratedVersions",
"->",
"sortWith",
"(",
"$",
"message",
"->",
"getComparator",
"(",
")",
")",
";",
"$",
"headVersion",
"=",
"$",
"migratedVersions",
"->",
"last",
"(",
")",
";",
"$",
"currentMessage",
"=",
"$",
"headVersion",
"?",
"\"Current version: <comment>{$headVersion->getId()}</comment>\"",
":",
"'Nothing has been migrated yet.'",
";",
"$",
"output",
"->",
"writeln",
"(",
"$",
"currentMessage",
")",
";",
"$",
"diff",
"=",
"array_diff",
"(",
"$",
"availableMigrations",
"->",
"toArray",
"(",
")",
",",
"$",
"migratedVersions",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"pendingCount",
"=",
"count",
"(",
"$",
"diff",
")",
";",
"if",
"(",
"$",
"pendingCount",
">",
"0",
")",
"{",
"$",
"executable",
"=",
"defined",
"(",
"'MIGRATIONS_EXECUTABLE'",
")",
"?",
"MIGRATIONS_EXECUTABLE",
".",
"' '",
":",
"''",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"\"Your database is out-of-date by $pendingCount versions, and can be migrated.\"",
",",
"sprintf",
"(",
"' (use \"<comment>%smigrate</comment>\" to execute all migrations)'",
",",
"$",
"executable",
")",
",",
"''",
"]",
")",
";",
"if",
"(",
"$",
"headVersion",
")",
"{",
"list",
"(",
"$",
"beforeHead",
",",
"$",
"afterHead",
")",
"=",
"$",
"this",
"->",
"splitDiff",
"(",
"$",
"diff",
",",
"$",
"message",
"->",
"getComparator",
"(",
")",
",",
"$",
"headVersion",
")",
";",
"}",
"else",
"{",
"$",
"beforeHead",
"=",
"[",
"]",
";",
"$",
"afterHead",
"=",
"$",
"diff",
";",
"}",
"$",
"this",
"->",
"printDiff",
"(",
"$",
"beforeHead",
",",
"[",
"'Old migrations still pending:'",
",",
"sprintf",
"(",
"\" (use \\\"<comment>{$executable}migrate HEAD</comment>\\\" to migrate them)\"",
",",
"$",
"executable",
")",
",",
"]",
",",
"self",
"::",
"STYLE_COMMENT",
")",
";",
"$",
"this",
"->",
"printDiff",
"(",
"$",
"afterHead",
",",
"[",
"'New migrations:'",
"]",
",",
"self",
"::",
"STYLE_INFO",
")",
";",
"}",
"else",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Your database is up-to-date.'",
")",
";",
"}",
"}"
] |
Handles a StatusMessage, which prints the status of the migrations system in a developer-friendly format
(inspired by "git status").
@param StatusMessage $message
|
[
"Handles",
"a",
"StatusMessage",
"which",
"prints",
"the",
"status",
"of",
"the",
"migrations",
"system",
"in",
"a",
"developer",
"-",
"friendly",
"format",
"(",
"inspired",
"by",
"git",
"status",
")",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Config/StatusHandler.php#L47-L99
|
baleen/cli
|
src/CommandBus/Config/StatusHandler.php
|
StatusHandler.printPendingVersion
|
protected function printPendingVersion(Version $version, $style)
{
/** @var Version $version */
$id = $version->getId();
$reflectionClass = new \ReflectionClass($version->getMigration());
$absolutePath = $reflectionClass->getFileName();
$fileName = $absolutePath ? $this->getRelativePath(getcwd(), $absolutePath) : '';
$this->output->writeln("\t<$style>[$id] $fileName</$style>");
}
|
php
|
protected function printPendingVersion(Version $version, $style)
{
/** @var Version $version */
$id = $version->getId();
$reflectionClass = new \ReflectionClass($version->getMigration());
$absolutePath = $reflectionClass->getFileName();
$fileName = $absolutePath ? $this->getRelativePath(getcwd(), $absolutePath) : '';
$this->output->writeln("\t<$style>[$id] $fileName</$style>");
}
|
[
"protected",
"function",
"printPendingVersion",
"(",
"Version",
"$",
"version",
",",
"$",
"style",
")",
"{",
"/** @var Version $version */",
"$",
"id",
"=",
"$",
"version",
"->",
"getId",
"(",
")",
";",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"version",
"->",
"getMigration",
"(",
")",
")",
";",
"$",
"absolutePath",
"=",
"$",
"reflectionClass",
"->",
"getFileName",
"(",
")",
";",
"$",
"fileName",
"=",
"$",
"absolutePath",
"?",
"$",
"this",
"->",
"getRelativePath",
"(",
"getcwd",
"(",
")",
",",
"$",
"absolutePath",
")",
":",
"''",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"\\t<$style>[$id] $fileName</$style>\"",
")",
";",
"}"
] |
Formats and prints a pending version with the given style.
@param Version $version The Version to print.
@param string $style One of the STYLE_* constants.
|
[
"Formats",
"and",
"prints",
"a",
"pending",
"version",
"with",
"the",
"given",
"style",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Config/StatusHandler.php#L107-L115
|
baleen/cli
|
src/CommandBus/Config/StatusHandler.php
|
StatusHandler.printDiff
|
protected function printDiff(array $versions, $message, $style = self::STYLE_INFO)
{
if (empty($versions)) {
return;
}
$this->output->writeln($message);
$this->output->writeln('');
foreach ($versions as $version) {
$this->printPendingVersion($version, $style);
}
// if there was at least one version in the array
$this->output->writeln('');
}
|
php
|
protected function printDiff(array $versions, $message, $style = self::STYLE_INFO)
{
if (empty($versions)) {
return;
}
$this->output->writeln($message);
$this->output->writeln('');
foreach ($versions as $version) {
$this->printPendingVersion($version, $style);
}
// if there was at least one version in the array
$this->output->writeln('');
}
|
[
"protected",
"function",
"printDiff",
"(",
"array",
"$",
"versions",
",",
"$",
"message",
",",
"$",
"style",
"=",
"self",
"::",
"STYLE_INFO",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"versions",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"version",
")",
"{",
"$",
"this",
"->",
"printPendingVersion",
"(",
"$",
"version",
",",
"$",
"style",
")",
";",
"}",
"// if there was at least one version in the array",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"}"
] |
Prints an array (group) of Versions all with the given style. If the array is empty then it prints nothing.
@param array $versions
@param string|string[] $message Message(s) to print before the group of versions.
@param string $style One of the STYLE_* constants.
|
[
"Prints",
"an",
"array",
"(",
"group",
")",
"of",
"Versions",
"all",
"with",
"the",
"given",
"style",
".",
"If",
"the",
"array",
"is",
"empty",
"then",
"it",
"prints",
"nothing",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Config/StatusHandler.php#L165-L179
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.