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
|
---|---|---|---|---|---|---|---|---|---|---|
stubbles/stubbles-webapp-core
|
src/main/php/routing/api/Resource.php
|
Resource.jsonSerialize
|
public function jsonSerialize(): array
{
return [
'name' => $this->name,
'methods' => $this->requestMethods,
'description' => $this->annotations->description(),
'produces' => $this->mimeTypes,
'responses' => $this->annotations->statusCodes(),
'headers' => $this->annotations->headers(),
'parameters' => $this->annotations->parameters(),
'auth' => $this->authConstraint,
'_links' => $this->links
];
}
|
php
|
public function jsonSerialize(): array
{
return [
'name' => $this->name,
'methods' => $this->requestMethods,
'description' => $this->annotations->description(),
'produces' => $this->mimeTypes,
'responses' => $this->annotations->statusCodes(),
'headers' => $this->annotations->headers(),
'parameters' => $this->annotations->parameters(),
'auth' => $this->authConstraint,
'_links' => $this->links
];
}
|
[
"public",
"function",
"jsonSerialize",
"(",
")",
":",
"array",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'methods'",
"=>",
"$",
"this",
"->",
"requestMethods",
",",
"'description'",
"=>",
"$",
"this",
"->",
"annotations",
"->",
"description",
"(",
")",
",",
"'produces'",
"=>",
"$",
"this",
"->",
"mimeTypes",
",",
"'responses'",
"=>",
"$",
"this",
"->",
"annotations",
"->",
"statusCodes",
"(",
")",
",",
"'headers'",
"=>",
"$",
"this",
"->",
"annotations",
"->",
"headers",
"(",
")",
",",
"'parameters'",
"=>",
"$",
"this",
"->",
"annotations",
"->",
"parameters",
"(",
")",
",",
"'auth'",
"=>",
"$",
"this",
"->",
"authConstraint",
",",
"'_links'",
"=>",
"$",
"this",
"->",
"links",
"]",
";",
"}"
] |
returns proper representation which can be serialized to JSON
@return array
@XmlIgnore
|
[
"returns",
"proper",
"representation",
"which",
"can",
"be",
"serialized",
"to",
"JSON"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/api/Resource.php#L253-L266
|
jelix/version
|
lib/VersionComparator.php
|
VersionComparator.compare
|
public static function compare(Version $version1, Version $version2)
{
if ($version1->toString() == $version2->toString()) {
return 0;
}
$v1 = $version1->getVersionArray();
$v2 = $version2->getVersionArray();
if (count($v1) > count($v2)) {
$v2 = array_pad($v2, count($v1), 0);
} elseif (count($v1) < count($v2)) {
$v1 = array_pad($v1, count($v2), 0);
}
// version comparison
foreach ($v1 as $k => $v) {
if ($v == $v2[$k]) {
continue;
}
if ($v < $v2[$k]) {
return -1;
} else {
return 1;
}
}
// stability comparison
$s1 = $version1->getStabilityVersion();
$s2 = $version2->getStabilityVersion();
if (count($s1) > count($s2)) {
$s2 = array_pad($s2, count($s1), '');
} elseif (count($s1) < count($s2)) {
$s1 = array_pad($s1, count($s2), '');
}
foreach ($s1 as $k => $v) {
if ($v == '*' || $s2[$k] == '*') {
return 0;
}
if ($v === $s2[$k]) {
continue;
}
if ($v === '') {
if (!is_numeric($s2[$k])) {
return 1;
} else {
$v = '0';
}
} elseif ($s2[$k] === '') {
if (!is_numeric($v)) {
return -1;
} else {
$s2[$k] = '0';
}
}
if (is_numeric($v)) {
if (is_numeric($s2[$k])) {
$v1 = intval($v);
$v2 = intval($s2[$k]);
if ($v1 == $v2) {
continue;
}
if ($v1 < $v2) {
return -1;
}
return 1;
} else {
return -1;
}
} elseif (is_numeric($s2[$k])) {
return -1;
} else {
if ($v == 'dev' || $v == 'pre') {
$v = 'aaaaaaaaaa';
}
$v2 = $s2[$k];
if ($v2 == 'dev' || $v2 == 'pre') {
$v2 = 'aaaaaaaaaa';
}
$r = strcmp($v, $v2);
if ($r > 0) {
return 1;
} elseif ($r < 0) {
return -1;
}
}
}
$sv1 = $version1->getSecondaryVersion();
$sv2 = $version2->getSecondaryVersion();
if (($sv1 instanceof Version) || ($sv2 instanceof Version)) {
if (($sv1 instanceof Version) && ($sv2 instanceof Version)) {
return self::compare($sv1, $sv2);
}
else if ($sv1 instanceof Version) {
return 1;
}
else if ($sv2 instanceof Version) {
return -1;
}
}
return 0;
}
|
php
|
public static function compare(Version $version1, Version $version2)
{
if ($version1->toString() == $version2->toString()) {
return 0;
}
$v1 = $version1->getVersionArray();
$v2 = $version2->getVersionArray();
if (count($v1) > count($v2)) {
$v2 = array_pad($v2, count($v1), 0);
} elseif (count($v1) < count($v2)) {
$v1 = array_pad($v1, count($v2), 0);
}
// version comparison
foreach ($v1 as $k => $v) {
if ($v == $v2[$k]) {
continue;
}
if ($v < $v2[$k]) {
return -1;
} else {
return 1;
}
}
// stability comparison
$s1 = $version1->getStabilityVersion();
$s2 = $version2->getStabilityVersion();
if (count($s1) > count($s2)) {
$s2 = array_pad($s2, count($s1), '');
} elseif (count($s1) < count($s2)) {
$s1 = array_pad($s1, count($s2), '');
}
foreach ($s1 as $k => $v) {
if ($v == '*' || $s2[$k] == '*') {
return 0;
}
if ($v === $s2[$k]) {
continue;
}
if ($v === '') {
if (!is_numeric($s2[$k])) {
return 1;
} else {
$v = '0';
}
} elseif ($s2[$k] === '') {
if (!is_numeric($v)) {
return -1;
} else {
$s2[$k] = '0';
}
}
if (is_numeric($v)) {
if (is_numeric($s2[$k])) {
$v1 = intval($v);
$v2 = intval($s2[$k]);
if ($v1 == $v2) {
continue;
}
if ($v1 < $v2) {
return -1;
}
return 1;
} else {
return -1;
}
} elseif (is_numeric($s2[$k])) {
return -1;
} else {
if ($v == 'dev' || $v == 'pre') {
$v = 'aaaaaaaaaa';
}
$v2 = $s2[$k];
if ($v2 == 'dev' || $v2 == 'pre') {
$v2 = 'aaaaaaaaaa';
}
$r = strcmp($v, $v2);
if ($r > 0) {
return 1;
} elseif ($r < 0) {
return -1;
}
}
}
$sv1 = $version1->getSecondaryVersion();
$sv2 = $version2->getSecondaryVersion();
if (($sv1 instanceof Version) || ($sv2 instanceof Version)) {
if (($sv1 instanceof Version) && ($sv2 instanceof Version)) {
return self::compare($sv1, $sv2);
}
else if ($sv1 instanceof Version) {
return 1;
}
else if ($sv2 instanceof Version) {
return -1;
}
}
return 0;
}
|
[
"public",
"static",
"function",
"compare",
"(",
"Version",
"$",
"version1",
",",
"Version",
"$",
"version2",
")",
"{",
"if",
"(",
"$",
"version1",
"->",
"toString",
"(",
")",
"==",
"$",
"version2",
"->",
"toString",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"$",
"v1",
"=",
"$",
"version1",
"->",
"getVersionArray",
"(",
")",
";",
"$",
"v2",
"=",
"$",
"version2",
"->",
"getVersionArray",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"v1",
")",
">",
"count",
"(",
"$",
"v2",
")",
")",
"{",
"$",
"v2",
"=",
"array_pad",
"(",
"$",
"v2",
",",
"count",
"(",
"$",
"v1",
")",
",",
"0",
")",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"v1",
")",
"<",
"count",
"(",
"$",
"v2",
")",
")",
"{",
"$",
"v1",
"=",
"array_pad",
"(",
"$",
"v1",
",",
"count",
"(",
"$",
"v2",
")",
",",
"0",
")",
";",
"}",
"// version comparison",
"foreach",
"(",
"$",
"v1",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"==",
"$",
"v2",
"[",
"$",
"k",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"v",
"<",
"$",
"v2",
"[",
"$",
"k",
"]",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"1",
";",
"}",
"}",
"// stability comparison",
"$",
"s1",
"=",
"$",
"version1",
"->",
"getStabilityVersion",
"(",
")",
";",
"$",
"s2",
"=",
"$",
"version2",
"->",
"getStabilityVersion",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"s1",
")",
">",
"count",
"(",
"$",
"s2",
")",
")",
"{",
"$",
"s2",
"=",
"array_pad",
"(",
"$",
"s2",
",",
"count",
"(",
"$",
"s1",
")",
",",
"''",
")",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"s1",
")",
"<",
"count",
"(",
"$",
"s2",
")",
")",
"{",
"$",
"s1",
"=",
"array_pad",
"(",
"$",
"s1",
",",
"count",
"(",
"$",
"s2",
")",
",",
"''",
")",
";",
"}",
"foreach",
"(",
"$",
"s1",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"==",
"'*'",
"||",
"$",
"s2",
"[",
"$",
"k",
"]",
"==",
"'*'",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"v",
"===",
"$",
"s2",
"[",
"$",
"k",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"v",
"===",
"''",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"s2",
"[",
"$",
"k",
"]",
")",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"$",
"v",
"=",
"'0'",
";",
"}",
"}",
"elseif",
"(",
"$",
"s2",
"[",
"$",
"k",
"]",
"===",
"''",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"v",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"$",
"s2",
"[",
"$",
"k",
"]",
"=",
"'0'",
";",
"}",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"v",
")",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"s2",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"v1",
"=",
"intval",
"(",
"$",
"v",
")",
";",
"$",
"v2",
"=",
"intval",
"(",
"$",
"s2",
"[",
"$",
"k",
"]",
")",
";",
"if",
"(",
"$",
"v1",
"==",
"$",
"v2",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"v1",
"<",
"$",
"v2",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"1",
";",
"}",
"else",
"{",
"return",
"-",
"1",
";",
"}",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"s2",
"[",
"$",
"k",
"]",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"v",
"==",
"'dev'",
"||",
"$",
"v",
"==",
"'pre'",
")",
"{",
"$",
"v",
"=",
"'aaaaaaaaaa'",
";",
"}",
"$",
"v2",
"=",
"$",
"s2",
"[",
"$",
"k",
"]",
";",
"if",
"(",
"$",
"v2",
"==",
"'dev'",
"||",
"$",
"v2",
"==",
"'pre'",
")",
"{",
"$",
"v2",
"=",
"'aaaaaaaaaa'",
";",
"}",
"$",
"r",
"=",
"strcmp",
"(",
"$",
"v",
",",
"$",
"v2",
")",
";",
"if",
"(",
"$",
"r",
">",
"0",
")",
"{",
"return",
"1",
";",
"}",
"elseif",
"(",
"$",
"r",
"<",
"0",
")",
"{",
"return",
"-",
"1",
";",
"}",
"}",
"}",
"$",
"sv1",
"=",
"$",
"version1",
"->",
"getSecondaryVersion",
"(",
")",
";",
"$",
"sv2",
"=",
"$",
"version2",
"->",
"getSecondaryVersion",
"(",
")",
";",
"if",
"(",
"(",
"$",
"sv1",
"instanceof",
"Version",
")",
"||",
"(",
"$",
"sv2",
"instanceof",
"Version",
")",
")",
"{",
"if",
"(",
"(",
"$",
"sv1",
"instanceof",
"Version",
")",
"&&",
"(",
"$",
"sv2",
"instanceof",
"Version",
")",
")",
"{",
"return",
"self",
"::",
"compare",
"(",
"$",
"sv1",
",",
"$",
"sv2",
")",
";",
"}",
"else",
"if",
"(",
"$",
"sv1",
"instanceof",
"Version",
")",
"{",
"return",
"1",
";",
"}",
"else",
"if",
"(",
"$",
"sv2",
"instanceof",
"Version",
")",
"{",
"return",
"-",
"1",
";",
"}",
"}",
"return",
"0",
";",
"}"
] |
Compare two version objects.
@return int
- 0 if versions are equals
- -1 if $version1 is lower than $version2
- 1 if $version1 is higher than $version2
|
[
"Compare",
"two",
"version",
"objects",
"."
] |
train
|
https://github.com/jelix/version/blob/1bdcea2beb7943f347fb453e3106702a460d51c2/lib/VersionComparator.php#L28-L131
|
jelix/version
|
lib/VersionComparator.php
|
VersionComparator.compareVersion
|
public static function compareVersion($version1, $version2)
{
if ($version1 == $version2) {
return 0;
}
$v1 = Parser::parse($version1);
$v2 = Parser::parse($version2);
return self::compare($v1, $v2);
}
|
php
|
public static function compareVersion($version1, $version2)
{
if ($version1 == $version2) {
return 0;
}
$v1 = Parser::parse($version1);
$v2 = Parser::parse($version2);
return self::compare($v1, $v2);
}
|
[
"public",
"static",
"function",
"compareVersion",
"(",
"$",
"version1",
",",
"$",
"version2",
")",
"{",
"if",
"(",
"$",
"version1",
"==",
"$",
"version2",
")",
"{",
"return",
"0",
";",
"}",
"$",
"v1",
"=",
"Parser",
"::",
"parse",
"(",
"$",
"version1",
")",
";",
"$",
"v2",
"=",
"Parser",
"::",
"parse",
"(",
"$",
"version2",
")",
";",
"return",
"self",
"::",
"compare",
"(",
"$",
"v1",
",",
"$",
"v2",
")",
";",
"}"
] |
Compare two version as string.
It supports wildcard in one of the version
@param string $version1
@param string $version2
@return int 0 if equal, -1 if $version1 < $version2, 1 if $version1 > $version2
|
[
"Compare",
"two",
"version",
"as",
"string",
"."
] |
train
|
https://github.com/jelix/version/blob/1bdcea2beb7943f347fb453e3106702a460d51c2/lib/VersionComparator.php#L143-L153
|
jelix/version
|
lib/VersionComparator.php
|
VersionComparator.serializeVersion
|
public static function serializeVersion($version, $starReplacement = 0, $pad = 4)
{
$vers = explode('.', $version);
$r = '/^([0-9]+)([a-zA-Z]*|pre|-?dev)([0-9]*)(pre|-?dev)?$/';
$sver = '';
foreach ($vers as $k => $v) {
if ($v == '*') {
--$k;
break;
}
$pm = preg_match($r, $v, $m);
if ($pm) {
self::normalizeVersionNumber($m);
$m[1] = str_pad($m[1], ($k > 1 ? 10 : 3), '0', STR_PAD_LEFT);
$m[2] = substr($m[2], 0, 1); // alpha/beta
$m[3] = ($m[3] == '' ? '99' : str_pad($m[3], 2, '0', STR_PAD_LEFT)); // alpha/beta number
$m[4] = ($m[4] == 'dev' ? 'd' : 'z');
if ($k) {
$sver .= '.';
}
$sver .= $m[1].$m[2].$m[3].$m[4];
} else {
throw new \Exception("version number '" . $version . "' cannot be serialized");
}
}
for ($i = $k + 1; $i < $pad; ++$i) {
if ($i > 0) {
$sver .= '.';
}
if ($starReplacement > 0) {
$sver .= ($i > 1 ? '9999999999' : '999').'z99z';
} else {
$sver .= ($i > 1 ? '0000000000' : '000').'a00a';
}
}
return $sver;
}
|
php
|
public static function serializeVersion($version, $starReplacement = 0, $pad = 4)
{
$vers = explode('.', $version);
$r = '/^([0-9]+)([a-zA-Z]*|pre|-?dev)([0-9]*)(pre|-?dev)?$/';
$sver = '';
foreach ($vers as $k => $v) {
if ($v == '*') {
--$k;
break;
}
$pm = preg_match($r, $v, $m);
if ($pm) {
self::normalizeVersionNumber($m);
$m[1] = str_pad($m[1], ($k > 1 ? 10 : 3), '0', STR_PAD_LEFT);
$m[2] = substr($m[2], 0, 1); // alpha/beta
$m[3] = ($m[3] == '' ? '99' : str_pad($m[3], 2, '0', STR_PAD_LEFT)); // alpha/beta number
$m[4] = ($m[4] == 'dev' ? 'd' : 'z');
if ($k) {
$sver .= '.';
}
$sver .= $m[1].$m[2].$m[3].$m[4];
} else {
throw new \Exception("version number '" . $version . "' cannot be serialized");
}
}
for ($i = $k + 1; $i < $pad; ++$i) {
if ($i > 0) {
$sver .= '.';
}
if ($starReplacement > 0) {
$sver .= ($i > 1 ? '9999999999' : '999').'z99z';
} else {
$sver .= ($i > 1 ? '0000000000' : '000').'a00a';
}
}
return $sver;
}
|
[
"public",
"static",
"function",
"serializeVersion",
"(",
"$",
"version",
",",
"$",
"starReplacement",
"=",
"0",
",",
"$",
"pad",
"=",
"4",
")",
"{",
"$",
"vers",
"=",
"explode",
"(",
"'.'",
",",
"$",
"version",
")",
";",
"$",
"r",
"=",
"'/^([0-9]+)([a-zA-Z]*|pre|-?dev)([0-9]*)(pre|-?dev)?$/'",
";",
"$",
"sver",
"=",
"''",
";",
"foreach",
"(",
"$",
"vers",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"==",
"'*'",
")",
"{",
"--",
"$",
"k",
";",
"break",
";",
"}",
"$",
"pm",
"=",
"preg_match",
"(",
"$",
"r",
",",
"$",
"v",
",",
"$",
"m",
")",
";",
"if",
"(",
"$",
"pm",
")",
"{",
"self",
"::",
"normalizeVersionNumber",
"(",
"$",
"m",
")",
";",
"$",
"m",
"[",
"1",
"]",
"=",
"str_pad",
"(",
"$",
"m",
"[",
"1",
"]",
",",
"(",
"$",
"k",
">",
"1",
"?",
"10",
":",
"3",
")",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"$",
"m",
"[",
"2",
"]",
"=",
"substr",
"(",
"$",
"m",
"[",
"2",
"]",
",",
"0",
",",
"1",
")",
";",
"// alpha/beta",
"$",
"m",
"[",
"3",
"]",
"=",
"(",
"$",
"m",
"[",
"3",
"]",
"==",
"''",
"?",
"'99'",
":",
"str_pad",
"(",
"$",
"m",
"[",
"3",
"]",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
")",
";",
"// alpha/beta number",
"$",
"m",
"[",
"4",
"]",
"=",
"(",
"$",
"m",
"[",
"4",
"]",
"==",
"'dev'",
"?",
"'d'",
":",
"'z'",
")",
";",
"if",
"(",
"$",
"k",
")",
"{",
"$",
"sver",
".=",
"'.'",
";",
"}",
"$",
"sver",
".=",
"$",
"m",
"[",
"1",
"]",
".",
"$",
"m",
"[",
"2",
"]",
".",
"$",
"m",
"[",
"3",
"]",
".",
"$",
"m",
"[",
"4",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"version number '\"",
".",
"$",
"version",
".",
"\"' cannot be serialized\"",
")",
";",
"}",
"}",
"for",
"(",
"$",
"i",
"=",
"$",
"k",
"+",
"1",
";",
"$",
"i",
"<",
"$",
"pad",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"i",
">",
"0",
")",
"{",
"$",
"sver",
".=",
"'.'",
";",
"}",
"if",
"(",
"$",
"starReplacement",
">",
"0",
")",
"{",
"$",
"sver",
".=",
"(",
"$",
"i",
">",
"1",
"?",
"'9999999999'",
":",
"'999'",
")",
".",
"'z99z'",
";",
"}",
"else",
"{",
"$",
"sver",
".=",
"(",
"$",
"i",
">",
"1",
"?",
"'0000000000'",
":",
"'000'",
")",
".",
"'a00a'",
";",
"}",
"}",
"return",
"$",
"sver",
";",
"}"
] |
create a string representing a version number in a manner that it could
be easily to be compared with an other serialized version. useful to
do comparison in a database for example.
It doesn't support all version notation. Use serializeVersion2 instead.
@param int $starReplacement 1 if it should replace by max value, 0 for min value
@deprecated
|
[
"create",
"a",
"string",
"representing",
"a",
"version",
"number",
"in",
"a",
"manner",
"that",
"it",
"could",
"be",
"easily",
"to",
"be",
"compared",
"with",
"an",
"other",
"serialized",
"version",
".",
"useful",
"to",
"do",
"comparison",
"in",
"a",
"database",
"for",
"example",
"."
] |
train
|
https://github.com/jelix/version/blob/1bdcea2beb7943f347fb453e3106702a460d51c2/lib/VersionComparator.php#L191-L231
|
jelix/version
|
lib/VersionComparator.php
|
VersionComparator.serializeVersion2
|
public static function serializeVersion2($version, $starReplacement = 0, $maxpad = 10)
{
// remove meta data
$vers = explode('+', $version, 2);
$version = $vers[0];
// remove secondary version
$allVersions = preg_split('/(-|:)([0-9]+)($|\.|-)/', $version, 2, PREG_SPLIT_DELIM_CAPTURE);
$version = $allVersions[0];
$version = preg_replace("/([0-9])([a-z])/i", "\\1-\\2", $version);
$version = preg_replace("/([a-z])([0-9])/i", "\\1.\\2", $version);
$extensions = explode('-', $version, 3);
$serial = '';
$extensions = array_pad($extensions, 3, '0');
foreach ($extensions as $ext) {
$currentUnstable = 'z';
$vers = explode('.', $ext);
$vers = array_pad($vers, 5, "0");
foreach($vers as $k => $v) {
$pad = ($k > 1 ? $maxpad : 3);
if ($v == '*') {
if ($starReplacement > 0) {
$vers[$k] = $currentUnstable.($k > 1 ? '9999999999' : '999');
} else {
$vers[$k] = $currentUnstable.($k > 1 ? '0000000000' : '000');
}
}
else if (is_numeric($v)) {
$vers[$k] = $currentUnstable.str_pad($v, $pad, '0', STR_PAD_LEFT);
}
else if ($v == 'dev' || $v == 'pre') {
$currentUnstable = '_';
$vers[$k] = '_'.str_pad('', $pad, '0');
}
else {
$currentUnstable = strtolower(substr($v, 0, 1));
$vers[$k] = $currentUnstable.str_repeat('0', $pad);
}
}
if ($serial) {
$serial .= '-';
}
$serial .= implode('', $vers);
}
return $serial;
}
|
php
|
public static function serializeVersion2($version, $starReplacement = 0, $maxpad = 10)
{
// remove meta data
$vers = explode('+', $version, 2);
$version = $vers[0];
// remove secondary version
$allVersions = preg_split('/(-|:)([0-9]+)($|\.|-)/', $version, 2, PREG_SPLIT_DELIM_CAPTURE);
$version = $allVersions[0];
$version = preg_replace("/([0-9])([a-z])/i", "\\1-\\2", $version);
$version = preg_replace("/([a-z])([0-9])/i", "\\1.\\2", $version);
$extensions = explode('-', $version, 3);
$serial = '';
$extensions = array_pad($extensions, 3, '0');
foreach ($extensions as $ext) {
$currentUnstable = 'z';
$vers = explode('.', $ext);
$vers = array_pad($vers, 5, "0");
foreach($vers as $k => $v) {
$pad = ($k > 1 ? $maxpad : 3);
if ($v == '*') {
if ($starReplacement > 0) {
$vers[$k] = $currentUnstable.($k > 1 ? '9999999999' : '999');
} else {
$vers[$k] = $currentUnstable.($k > 1 ? '0000000000' : '000');
}
}
else if (is_numeric($v)) {
$vers[$k] = $currentUnstable.str_pad($v, $pad, '0', STR_PAD_LEFT);
}
else if ($v == 'dev' || $v == 'pre') {
$currentUnstable = '_';
$vers[$k] = '_'.str_pad('', $pad, '0');
}
else {
$currentUnstable = strtolower(substr($v, 0, 1));
$vers[$k] = $currentUnstable.str_repeat('0', $pad);
}
}
if ($serial) {
$serial .= '-';
}
$serial .= implode('', $vers);
}
return $serial;
}
|
[
"public",
"static",
"function",
"serializeVersion2",
"(",
"$",
"version",
",",
"$",
"starReplacement",
"=",
"0",
",",
"$",
"maxpad",
"=",
"10",
")",
"{",
"// remove meta data",
"$",
"vers",
"=",
"explode",
"(",
"'+'",
",",
"$",
"version",
",",
"2",
")",
";",
"$",
"version",
"=",
"$",
"vers",
"[",
"0",
"]",
";",
"// remove secondary version",
"$",
"allVersions",
"=",
"preg_split",
"(",
"'/(-|:)([0-9]+)($|\\.|-)/'",
",",
"$",
"version",
",",
"2",
",",
"PREG_SPLIT_DELIM_CAPTURE",
")",
";",
"$",
"version",
"=",
"$",
"allVersions",
"[",
"0",
"]",
";",
"$",
"version",
"=",
"preg_replace",
"(",
"\"/([0-9])([a-z])/i\"",
",",
"\"\\\\1-\\\\2\"",
",",
"$",
"version",
")",
";",
"$",
"version",
"=",
"preg_replace",
"(",
"\"/([a-z])([0-9])/i\"",
",",
"\"\\\\1.\\\\2\"",
",",
"$",
"version",
")",
";",
"$",
"extensions",
"=",
"explode",
"(",
"'-'",
",",
"$",
"version",
",",
"3",
")",
";",
"$",
"serial",
"=",
"''",
";",
"$",
"extensions",
"=",
"array_pad",
"(",
"$",
"extensions",
",",
"3",
",",
"'0'",
")",
";",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"ext",
")",
"{",
"$",
"currentUnstable",
"=",
"'z'",
";",
"$",
"vers",
"=",
"explode",
"(",
"'.'",
",",
"$",
"ext",
")",
";",
"$",
"vers",
"=",
"array_pad",
"(",
"$",
"vers",
",",
"5",
",",
"\"0\"",
")",
";",
"foreach",
"(",
"$",
"vers",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"pad",
"=",
"(",
"$",
"k",
">",
"1",
"?",
"$",
"maxpad",
":",
"3",
")",
";",
"if",
"(",
"$",
"v",
"==",
"'*'",
")",
"{",
"if",
"(",
"$",
"starReplacement",
">",
"0",
")",
"{",
"$",
"vers",
"[",
"$",
"k",
"]",
"=",
"$",
"currentUnstable",
".",
"(",
"$",
"k",
">",
"1",
"?",
"'9999999999'",
":",
"'999'",
")",
";",
"}",
"else",
"{",
"$",
"vers",
"[",
"$",
"k",
"]",
"=",
"$",
"currentUnstable",
".",
"(",
"$",
"k",
">",
"1",
"?",
"'0000000000'",
":",
"'000'",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"$",
"v",
")",
")",
"{",
"$",
"vers",
"[",
"$",
"k",
"]",
"=",
"$",
"currentUnstable",
".",
"str_pad",
"(",
"$",
"v",
",",
"$",
"pad",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"else",
"if",
"(",
"$",
"v",
"==",
"'dev'",
"||",
"$",
"v",
"==",
"'pre'",
")",
"{",
"$",
"currentUnstable",
"=",
"'_'",
";",
"$",
"vers",
"[",
"$",
"k",
"]",
"=",
"'_'",
".",
"str_pad",
"(",
"''",
",",
"$",
"pad",
",",
"'0'",
")",
";",
"}",
"else",
"{",
"$",
"currentUnstable",
"=",
"strtolower",
"(",
"substr",
"(",
"$",
"v",
",",
"0",
",",
"1",
")",
")",
";",
"$",
"vers",
"[",
"$",
"k",
"]",
"=",
"$",
"currentUnstable",
".",
"str_repeat",
"(",
"'0'",
",",
"$",
"pad",
")",
";",
"}",
"}",
"if",
"(",
"$",
"serial",
")",
"{",
"$",
"serial",
".=",
"'-'",
";",
"}",
"$",
"serial",
".=",
"implode",
"(",
"''",
",",
"$",
"vers",
")",
";",
"}",
"return",
"$",
"serial",
";",
"}"
] |
create a string representing a version number in a manner that it could
be easily to be compared with an other serialized version. useful to
do comparison in a database for example.
It does not serialize secondary versions, so you should serialize them separatly.
@param string $version
@param int $starReplacement 1 if it should replace '*' by max value, 0 for min value
|
[
"create",
"a",
"string",
"representing",
"a",
"version",
"number",
"in",
"a",
"manner",
"that",
"it",
"could",
"be",
"easily",
"to",
"be",
"compared",
"with",
"an",
"other",
"serialized",
"version",
".",
"useful",
"to",
"do",
"comparison",
"in",
"a",
"database",
"for",
"example",
"."
] |
train
|
https://github.com/jelix/version/blob/1bdcea2beb7943f347fb453e3106702a460d51c2/lib/VersionComparator.php#L243-L290
|
jelix/version
|
lib/VersionComparator.php
|
VersionComparator.compareVersionRange
|
public static function compareVersionRange($version, $range)
{
if ($range == '' || $version == '') {
return true;
}
if (is_string($version)) {
$v1 = Parser::parse($version);
}
else {
$v1 = $version;
}
if ($v1->toString(true, false) == $range) {
return true;
}
$expression = self::compileRange($range);
return $expression->compare($v1);
}
|
php
|
public static function compareVersionRange($version, $range)
{
if ($range == '' || $version == '') {
return true;
}
if (is_string($version)) {
$v1 = Parser::parse($version);
}
else {
$v1 = $version;
}
if ($v1->toString(true, false) == $range) {
return true;
}
$expression = self::compileRange($range);
return $expression->compare($v1);
}
|
[
"public",
"static",
"function",
"compareVersionRange",
"(",
"$",
"version",
",",
"$",
"range",
")",
"{",
"if",
"(",
"$",
"range",
"==",
"''",
"||",
"$",
"version",
"==",
"''",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"version",
")",
")",
"{",
"$",
"v1",
"=",
"Parser",
"::",
"parse",
"(",
"$",
"version",
")",
";",
"}",
"else",
"{",
"$",
"v1",
"=",
"$",
"version",
";",
"}",
"if",
"(",
"$",
"v1",
"->",
"toString",
"(",
"true",
",",
"false",
")",
"==",
"$",
"range",
")",
"{",
"return",
"true",
";",
"}",
"$",
"expression",
"=",
"self",
"::",
"compileRange",
"(",
"$",
"range",
")",
";",
"return",
"$",
"expression",
"->",
"compare",
"(",
"$",
"v1",
")",
";",
"}"
] |
Compare a version with a given range.
It does not compare with secondary version.
@param string|Version $version a version number
@param string $range a version expression respecting Composer range syntax
@return bool true if the given version match the given range
|
[
"Compare",
"a",
"version",
"with",
"a",
"given",
"range",
"."
] |
train
|
https://github.com/jelix/version/blob/1bdcea2beb7943f347fb453e3106702a460d51c2/lib/VersionComparator.php#L302-L323
|
FrenchFrogs/framework
|
src/Validator/Validator.php
|
Validator.addRule
|
public function addRule($index, $method = null, ...$params)
{
$this->rules[$index] = [$method, $params];
return $this;
}
|
php
|
public function addRule($index, $method = null, ...$params)
{
$this->rules[$index] = [$method, $params];
return $this;
}
|
[
"public",
"function",
"addRule",
"(",
"$",
"index",
",",
"$",
"method",
"=",
"null",
",",
"...",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"rules",
"[",
"$",
"index",
"]",
"=",
"[",
"$",
"method",
",",
"$",
"params",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a single rule to the rules container
@param $index
@param $rule
@return $this
|
[
"Add",
"a",
"single",
"rule",
"to",
"the",
"rules",
"container"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Validator/Validator.php#L74-L78
|
FrenchFrogs/framework
|
src/Validator/Validator.php
|
Validator.getRule
|
public function getRule($index)
{
if (!$this->hasRule($index)) {
throw new \Exception('Rule not found: ' . $index);
}
return $this->rules[$index];
}
|
php
|
public function getRule($index)
{
if (!$this->hasRule($index)) {
throw new \Exception('Rule not found: ' . $index);
}
return $this->rules[$index];
}
|
[
"public",
"function",
"getRule",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRule",
"(",
"$",
"index",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Rule not found: '",
".",
"$",
"index",
")",
";",
"}",
"return",
"$",
"this",
"->",
"rules",
"[",
"$",
"index",
"]",
";",
"}"
] |
Return the rule $index from the rules container
@return mixed Callable | string
|
[
"Return",
"the",
"rule",
"$index",
"from",
"the",
"rules",
"container"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Validator/Validator.php#L123-L130
|
FrenchFrogs/framework
|
src/Validator/Validator.php
|
Validator.getMessage
|
public function getMessage($index)
{
if (!$this->hasMessage($index)) {
throw new \Exception('Message not found : ' . $index);
}
return $this->messages[$index];
}
|
php
|
public function getMessage($index)
{
if (!$this->hasMessage($index)) {
throw new \Exception('Message not found : ' . $index);
}
return $this->messages[$index];
}
|
[
"public",
"function",
"getMessage",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasMessage",
"(",
"$",
"index",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Message not found : '",
".",
"$",
"index",
")",
";",
"}",
"return",
"$",
"this",
"->",
"messages",
"[",
"$",
"index",
"]",
";",
"}"
] |
Return the messages $index from the messages container
@return mixed Callable | string
|
[
"Return",
"the",
"messages",
"$index",
"from",
"the",
"messages",
"container"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Validator/Validator.php#L213-L220
|
FrenchFrogs/framework
|
src/Validator/Validator.php
|
Validator.getError
|
public function getError($index)
{
if (!$this->hasError($index)) {
throw new \Exception('Error not found : ' . $index);
}
return $this->errors[$index];
}
|
php
|
public function getError($index)
{
if (!$this->hasError($index)) {
throw new \Exception('Error not found : ' . $index);
}
return $this->errors[$index];
}
|
[
"public",
"function",
"getError",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasError",
"(",
"$",
"index",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Error not found : '",
".",
"$",
"index",
")",
";",
"}",
"return",
"$",
"this",
"->",
"errors",
"[",
"$",
"index",
"]",
";",
"}"
] |
Return the error $index from the errors container
@return mixed Callable | string
|
[
"Return",
"the",
"error",
"$index",
"from",
"the",
"errors",
"container"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Validator/Validator.php#L302-L309
|
FrenchFrogs/framework
|
src/Validator/Validator.php
|
Validator.formatError
|
public function formatError($index, $params)
{
$pattern = $this->hasMessage($index) ? $this->getMessage($index) : static::MESSAGE_DEFAULT_PATTERN;
return vsprintf($pattern, $params);
}
|
php
|
public function formatError($index, $params)
{
$pattern = $this->hasMessage($index) ? $this->getMessage($index) : static::MESSAGE_DEFAULT_PATTERN;
return vsprintf($pattern, $params);
}
|
[
"public",
"function",
"formatError",
"(",
"$",
"index",
",",
"$",
"params",
")",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"hasMessage",
"(",
"$",
"index",
")",
"?",
"$",
"this",
"->",
"getMessage",
"(",
"$",
"index",
")",
":",
"static",
"::",
"MESSAGE_DEFAULT_PATTERN",
";",
"return",
"vsprintf",
"(",
"$",
"pattern",
",",
"$",
"params",
")",
";",
"}"
] |
Format an error
@param $index
@param $params
@return string
@throws \Exception
|
[
"Format",
"an",
"error"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Validator/Validator.php#L331-L336
|
FrenchFrogs/framework
|
src/Validator/Validator.php
|
Validator.valid
|
public function valid($value)
{
foreach($this->getRules() as $index => $rule) {
// check for required
if (in_array($value, ['', null]) && !$this->hasRule('required')) {
continue;
}
// extract params
list($method, $params) = $rule;
// If method is null, we use the index as the method name
$method = is_null($method) ? $index : $method;
// Build the params
array_unshift($params, $value);
// If it's a anonymous function
if (!is_string($method) && is_callable($method)) {
if (!call_user_func_array($method, $params)) {
$this->addError($index, $this->formatError($index, $params));
}
} else {// if it's a local method
if (!method_exists($this, $method)) {
throw new \Exception('Method "'. $method .'" not found for validator : ' . $index);
}
if (!call_user_func_array([$this, $method], $params)) {
$this->addError($index, $this->formatError($index, $params));
}
}
}
return $this;
}
|
php
|
public function valid($value)
{
foreach($this->getRules() as $index => $rule) {
// check for required
if (in_array($value, ['', null]) && !$this->hasRule('required')) {
continue;
}
// extract params
list($method, $params) = $rule;
// If method is null, we use the index as the method name
$method = is_null($method) ? $index : $method;
// Build the params
array_unshift($params, $value);
// If it's a anonymous function
if (!is_string($method) && is_callable($method)) {
if (!call_user_func_array($method, $params)) {
$this->addError($index, $this->formatError($index, $params));
}
} else {// if it's a local method
if (!method_exists($this, $method)) {
throw new \Exception('Method "'. $method .'" not found for validator : ' . $index);
}
if (!call_user_func_array([$this, $method], $params)) {
$this->addError($index, $this->formatError($index, $params));
}
}
}
return $this;
}
|
[
"public",
"function",
"valid",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getRules",
"(",
")",
"as",
"$",
"index",
"=>",
"$",
"rule",
")",
"{",
"// check for required",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"[",
"''",
",",
"null",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"hasRule",
"(",
"'required'",
")",
")",
"{",
"continue",
";",
"}",
"// extract params",
"list",
"(",
"$",
"method",
",",
"$",
"params",
")",
"=",
"$",
"rule",
";",
"// If method is null, we use the index as the method name",
"$",
"method",
"=",
"is_null",
"(",
"$",
"method",
")",
"?",
"$",
"index",
":",
"$",
"method",
";",
"// Build the params",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"value",
")",
";",
"// If it's a anonymous function",
"if",
"(",
"!",
"is_string",
"(",
"$",
"method",
")",
"&&",
"is_callable",
"(",
"$",
"method",
")",
")",
"{",
"if",
"(",
"!",
"call_user_func_array",
"(",
"$",
"method",
",",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"formatError",
"(",
"$",
"index",
",",
"$",
"params",
")",
")",
";",
"}",
"}",
"else",
"{",
"// if it's a local method",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Method \"'",
".",
"$",
"method",
".",
"'\" not found for validator : '",
".",
"$",
"index",
")",
";",
"}",
"if",
"(",
"!",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
",",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"formatError",
"(",
"$",
"index",
",",
"$",
"params",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Valid the element
@param $value
@return $this
|
[
"Valid",
"the",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Validator/Validator.php#L345-L384
|
FrenchFrogs/framework
|
src/Validator/Validator.php
|
Validator.required
|
public function required($value)
{
if(!$this->hasMessage('required')){
$this->addMessage('required', 'This value is required');
}
if (is_null($value) || $value == '') {
return false;
}
return true;
}
|
php
|
public function required($value)
{
if(!$this->hasMessage('required')){
$this->addMessage('required', 'This value is required');
}
if (is_null($value) || $value == '') {
return false;
}
return true;
}
|
[
"public",
"function",
"required",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasMessage",
"(",
"'required'",
")",
")",
"{",
"$",
"this",
"->",
"addMessage",
"(",
"'required'",
",",
"'This value is required'",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"==",
"''",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Return FALSE if value is null or empty string
@param $value
@return bool
|
[
"Return",
"FALSE",
"if",
"value",
"is",
"null",
"or",
"empty",
"string"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Validator/Validator.php#L432-L444
|
FrenchFrogs/framework
|
src/Validator/Validator.php
|
Validator.laravel
|
public function laravel($value, $validationString, $messages = [])
{
//create validator
$validator = \Validator::make(['laravel' => $value], ['laravel' => $validationString]);
$validator->setCustomMessages($this->getMessages());
// error message management
if ($validator->fails() && !$this->hasMessage('laravel')) {
$message = '';
foreach ( $validator->errors()->get('laravel') as $m) {
$message .= $m . ' ';
}
$this->addMessage('laravel', $message);
}
// return validation
return $validator->valid();
}
|
php
|
public function laravel($value, $validationString, $messages = [])
{
//create validator
$validator = \Validator::make(['laravel' => $value], ['laravel' => $validationString]);
$validator->setCustomMessages($this->getMessages());
// error message management
if ($validator->fails() && !$this->hasMessage('laravel')) {
$message = '';
foreach ( $validator->errors()->get('laravel') as $m) {
$message .= $m . ' ';
}
$this->addMessage('laravel', $message);
}
// return validation
return $validator->valid();
}
|
[
"public",
"function",
"laravel",
"(",
"$",
"value",
",",
"$",
"validationString",
",",
"$",
"messages",
"=",
"[",
"]",
")",
"{",
"//create validator",
"$",
"validator",
"=",
"\\",
"Validator",
"::",
"make",
"(",
"[",
"'laravel'",
"=>",
"$",
"value",
"]",
",",
"[",
"'laravel'",
"=>",
"$",
"validationString",
"]",
")",
";",
"$",
"validator",
"->",
"setCustomMessages",
"(",
"$",
"this",
"->",
"getMessages",
"(",
")",
")",
";",
"// error message management",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"hasMessage",
"(",
"'laravel'",
")",
")",
"{",
"$",
"message",
"=",
"''",
";",
"foreach",
"(",
"$",
"validator",
"->",
"errors",
"(",
")",
"->",
"get",
"(",
"'laravel'",
")",
"as",
"$",
"m",
")",
"{",
"$",
"message",
".=",
"$",
"m",
".",
"' '",
";",
"}",
"$",
"this",
"->",
"addMessage",
"(",
"'laravel'",
",",
"$",
"message",
")",
";",
"}",
"// return validation",
"return",
"$",
"validator",
"->",
"valid",
"(",
")",
";",
"}"
] |
Return true if the value is correct with a laravel validator string
@param $value
@param $validationString
@param $messages
@return array
|
[
"Return",
"true",
"if",
"the",
"value",
"is",
"correct",
"with",
"a",
"laravel",
"validator",
"string"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Validator/Validator.php#L520-L537
|
comodojo/dispatcher.framework
|
src/Comodojo/Dispatcher/Cache/ServerCache.php
|
ServerCache.read
|
public function read(
Request $request,
Response $response
) {
if ($this->bypass === true) {
return false;
}
$name = self::getCacheName($request);
$cache_object = $this->getCache()
->setNamespace(self::$cache_namespace)
->get($name);
if (is_null($cache_object)) {
return false;
}
$response->import($cache_object);
return true;
}
|
php
|
public function read(
Request $request,
Response $response
) {
if ($this->bypass === true) {
return false;
}
$name = self::getCacheName($request);
$cache_object = $this->getCache()
->setNamespace(self::$cache_namespace)
->get($name);
if (is_null($cache_object)) {
return false;
}
$response->import($cache_object);
return true;
}
|
[
"public",
"function",
"read",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bypass",
"===",
"true",
")",
"{",
"return",
"false",
";",
"}",
"$",
"name",
"=",
"self",
"::",
"getCacheName",
"(",
"$",
"request",
")",
";",
"$",
"cache_object",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"setNamespace",
"(",
"self",
"::",
"$",
"cache_namespace",
")",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"cache_object",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"response",
"->",
"import",
"(",
"$",
"cache_object",
")",
";",
"return",
"true",
";",
"}"
] |
Read the cached response starting from the request definition (if any)
@param Request $request
The request model
@param Response $response
The response object that will be hydrated in case of success
@return bool
|
[
"Read",
"the",
"cached",
"response",
"starting",
"from",
"the",
"request",
"definition",
"(",
"if",
"any",
")"
] |
train
|
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Cache/ServerCache.php#L67-L88
|
comodojo/dispatcher.framework
|
src/Comodojo/Dispatcher/Cache/ServerCache.php
|
ServerCache.dump
|
public function dump(
Request $request,
Response $response,
Route $route
) {
if ( $this->bypass === true ) {
return false;
}
$cache = strtoupper($route->getParameter('cache'));
$ttl = $route->getParameter('ttl');
$name = self::getCacheName($request);
$method = (string)$request->getMethod();
$status = $response->getStatus()->get();
if (
($cache == 'SERVER' || $cache == 'BOTH') &&
in_array($method, self::$cachable_methods) &&
in_array($status, self::$cachable_statuses)
) {
$this->getCache()
->setNamespace(self::$cache_namespace)
->set(
$name,
$response->export(),
$ttl === null ? self::DEFAULTTTL : intval($ttl)
);
return true;
}
return false;
}
|
php
|
public function dump(
Request $request,
Response $response,
Route $route
) {
if ( $this->bypass === true ) {
return false;
}
$cache = strtoupper($route->getParameter('cache'));
$ttl = $route->getParameter('ttl');
$name = self::getCacheName($request);
$method = (string)$request->getMethod();
$status = $response->getStatus()->get();
if (
($cache == 'SERVER' || $cache == 'BOTH') &&
in_array($method, self::$cachable_methods) &&
in_array($status, self::$cachable_statuses)
) {
$this->getCache()
->setNamespace(self::$cache_namespace)
->set(
$name,
$response->export(),
$ttl === null ? self::DEFAULTTTL : intval($ttl)
);
return true;
}
return false;
}
|
[
"public",
"function",
"dump",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
",",
"Route",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bypass",
"===",
"true",
")",
"{",
"return",
"false",
";",
"}",
"$",
"cache",
"=",
"strtoupper",
"(",
"$",
"route",
"->",
"getParameter",
"(",
"'cache'",
")",
")",
";",
"$",
"ttl",
"=",
"$",
"route",
"->",
"getParameter",
"(",
"'ttl'",
")",
";",
"$",
"name",
"=",
"self",
"::",
"getCacheName",
"(",
"$",
"request",
")",
";",
"$",
"method",
"=",
"(",
"string",
")",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"$",
"status",
"=",
"$",
"response",
"->",
"getStatus",
"(",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"(",
"$",
"cache",
"==",
"'SERVER'",
"||",
"$",
"cache",
"==",
"'BOTH'",
")",
"&&",
"in_array",
"(",
"$",
"method",
",",
"self",
"::",
"$",
"cachable_methods",
")",
"&&",
"in_array",
"(",
"$",
"status",
",",
"self",
"::",
"$",
"cachable_statuses",
")",
")",
"{",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"setNamespace",
"(",
"self",
"::",
"$",
"cache_namespace",
")",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"response",
"->",
"export",
"(",
")",
",",
"$",
"ttl",
"===",
"null",
"?",
"self",
"::",
"DEFAULTTTL",
":",
"intval",
"(",
"$",
"ttl",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Dump the full request object in the cache
@param Request $request
The request model (to extract cache definition)
@param Response $response
The response object that will be cached
@param Route $route
The route model (to extract cache parameters)
@return bool
|
[
"Dump",
"the",
"full",
"request",
"object",
"in",
"the",
"cache"
] |
train
|
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Cache/ServerCache.php#L101-L134
|
comodojo/dispatcher.framework
|
src/Comodojo/Dispatcher/Cache/ServerCache.php
|
ServerCache.getCacheName
|
private static function getCacheName(Request $request) {
return md5((string)$request->getMethod().(string)$request->getUri());
}
|
php
|
private static function getCacheName(Request $request) {
return md5((string)$request->getMethod().(string)$request->getUri());
}
|
[
"private",
"static",
"function",
"getCacheName",
"(",
"Request",
"$",
"request",
")",
"{",
"return",
"md5",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"getMethod",
"(",
")",
".",
"(",
"string",
")",
"$",
"request",
"->",
"getUri",
"(",
")",
")",
";",
"}"
] |
Extract and compute the cache object name
@param Request $request
The request model
@return string
|
[
"Extract",
"and",
"compute",
"the",
"cache",
"object",
"name"
] |
train
|
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Cache/ServerCache.php#L155-L159
|
czim/laravel-pxlcms
|
src/Generator/Writer/Model/Steps/StubReplaceDocBlock.php
|
StubReplaceDocBlock.getDocBlockReplace
|
protected function getDocBlockReplace()
{
// For now, docblocks will only contain the ide-helper content
if ( ! $this->isDocBlockRequired()) return '';
$rows = $this->collectDocBlockPropertyRows();
if ( ! count($rows)) return '';
$replace = "/**\n"
. $this->getDocBlockIntro();
foreach ($rows as $row) {
$replace .= ' * '
. "@{$row['tag']} "
. "{$row['type']} "
. "{$row['name']}\n";
}
$replace .= " */\n";
return $replace;
}
|
php
|
protected function getDocBlockReplace()
{
// For now, docblocks will only contain the ide-helper content
if ( ! $this->isDocBlockRequired()) return '';
$rows = $this->collectDocBlockPropertyRows();
if ( ! count($rows)) return '';
$replace = "/**\n"
. $this->getDocBlockIntro();
foreach ($rows as $row) {
$replace .= ' * '
. "@{$row['tag']} "
. "{$row['type']} "
. "{$row['name']}\n";
}
$replace .= " */\n";
return $replace;
}
|
[
"protected",
"function",
"getDocBlockReplace",
"(",
")",
"{",
"// For now, docblocks will only contain the ide-helper content",
"if",
"(",
"!",
"$",
"this",
"->",
"isDocBlockRequired",
"(",
")",
")",
"return",
"''",
";",
"$",
"rows",
"=",
"$",
"this",
"->",
"collectDocBlockPropertyRows",
"(",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"rows",
")",
")",
"return",
"''",
";",
"$",
"replace",
"=",
"\"/**\\n\"",
".",
"$",
"this",
"->",
"getDocBlockIntro",
"(",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"replace",
".=",
"' * '",
".",
"\"@{$row['tag']} \"",
".",
"\"{$row['type']} \"",
".",
"\"{$row['name']}\\n\"",
";",
"}",
"$",
"replace",
".=",
"\" */\\n\"",
";",
"return",
"$",
"replace",
";",
"}"
] |
Returns the replacement for the docblock placeholder
@return string
|
[
"Returns",
"the",
"replacement",
"for",
"the",
"docblock",
"placeholder"
] |
train
|
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Writer/Model/Steps/StubReplaceDocBlock.php#L27-L52
|
pipelinersales/pipeliner-php-sdk
|
src/PipelinerSales/ApiClient/EntityCollectionIterator.php
|
EntityCollectionIterator.dataAvailable
|
public function dataAvailable()
{
return ($this->position >= $this->collection->getStartIndex() and
$this->position <= $this->collection->getEndIndex());
}
|
php
|
public function dataAvailable()
{
return ($this->position >= $this->collection->getStartIndex() and
$this->position <= $this->collection->getEndIndex());
}
|
[
"public",
"function",
"dataAvailable",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"position",
">=",
"$",
"this",
"->",
"collection",
"->",
"getStartIndex",
"(",
")",
"and",
"$",
"this",
"->",
"position",
"<=",
"$",
"this",
"->",
"collection",
"->",
"getEndIndex",
"(",
")",
")",
";",
"}"
] |
True if data for the current position has been loaded from the server and is
locally available.
@return boolean
|
[
"True",
"if",
"data",
"for",
"the",
"current",
"position",
"has",
"been",
"loaded",
"from",
"the",
"server",
"and",
"is",
"locally",
"available",
"."
] |
train
|
https://github.com/pipelinersales/pipeliner-php-sdk/blob/a020149ffde815be17634542010814cf854c3d5f/src/PipelinerSales/ApiClient/EntityCollectionIterator.php#L84-L88
|
pipelinersales/pipeliner-php-sdk
|
src/PipelinerSales/ApiClient/EntityCollectionIterator.php
|
EntityCollectionIterator.nextDataAvailable
|
public function nextDataAvailable()
{
return ($this->position+1 >= $this->collection->getStartIndex() and
$this->position+1 <= $this->collection->getEndIndex());
}
|
php
|
public function nextDataAvailable()
{
return ($this->position+1 >= $this->collection->getStartIndex() and
$this->position+1 <= $this->collection->getEndIndex());
}
|
[
"public",
"function",
"nextDataAvailable",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"position",
"+",
"1",
">=",
"$",
"this",
"->",
"collection",
"->",
"getStartIndex",
"(",
")",
"and",
"$",
"this",
"->",
"position",
"+",
"1",
"<=",
"$",
"this",
"->",
"collection",
"->",
"getEndIndex",
"(",
")",
")",
";",
"}"
] |
True if data for the next position has been loaded from the server and is
locally available. This is useful in foreach loops to determine whether the
next iteration will issue a HTTP request.
@return boolean
|
[
"True",
"if",
"data",
"for",
"the",
"next",
"position",
"has",
"been",
"loaded",
"from",
"the",
"server",
"and",
"is",
"locally",
"available",
".",
"This",
"is",
"useful",
"in",
"foreach",
"loops",
"to",
"determine",
"whether",
"the",
"next",
"iteration",
"will",
"issue",
"a",
"HTTP",
"request",
"."
] |
train
|
https://github.com/pipelinersales/pipeliner-php-sdk/blob/a020149ffde815be17634542010814cf854c3d5f/src/PipelinerSales/ApiClient/EntityCollectionIterator.php#L96-L100
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.aggregate
|
public function aggregate(array $pipeline, array $options = [])
{
if (array_key_exists('pipeline', $options)) {
throw new InvalidArgumentException('Option "pipeline" is not allowed, use $pipeline argument.');
}
return $this->executeCommand(
['aggregate' => $this->collectionName],
['pipeline' => $pipeline] + $options
);
}
|
php
|
public function aggregate(array $pipeline, array $options = [])
{
if (array_key_exists('pipeline', $options)) {
throw new InvalidArgumentException('Option "pipeline" is not allowed, use $pipeline argument.');
}
return $this->executeCommand(
['aggregate' => $this->collectionName],
['pipeline' => $pipeline] + $options
);
}
|
[
"public",
"function",
"aggregate",
"(",
"array",
"$",
"pipeline",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'pipeline'",
",",
"$",
"options",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Option \"pipeline\" is not allowed, use $pipeline argument.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"executeCommand",
"(",
"[",
"'aggregate'",
"=>",
"$",
"this",
"->",
"collectionName",
"]",
",",
"[",
"'pipeline'",
"=>",
"$",
"pipeline",
"]",
"+",
"$",
"options",
")",
";",
"}"
] |
@param array $pipeline
@param array $options
@return Cursor
|
[
"@param",
"array",
"$pipeline",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L99-L109
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.bulkWrite
|
public function bulkWrite($requests, array $options = [])
{
if (isset($options['writeConcern'])) {
if (!$options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentException(
sprintf(
'Option "writeConcern" is expected to be "%s", "%s" given.',
WriteConcern::class,
\Tequila\MongoDB\getType($options['writeConcern'])
)
);
}
$writeConcern = $options['writeConcern'];
unset($options['writeConcern']);
} else {
$writeConcern = $this->writeConcern;
}
$bulkWrite = new BulkWrite($requests, $options);
return $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite, $writeConcern);
}
|
php
|
public function bulkWrite($requests, array $options = [])
{
if (isset($options['writeConcern'])) {
if (!$options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentException(
sprintf(
'Option "writeConcern" is expected to be "%s", "%s" given.',
WriteConcern::class,
\Tequila\MongoDB\getType($options['writeConcern'])
)
);
}
$writeConcern = $options['writeConcern'];
unset($options['writeConcern']);
} else {
$writeConcern = $this->writeConcern;
}
$bulkWrite = new BulkWrite($requests, $options);
return $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite, $writeConcern);
}
|
[
"public",
"function",
"bulkWrite",
"(",
"$",
"requests",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"$",
"options",
"[",
"'writeConcern'",
"]",
"instanceof",
"WriteConcern",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Option \"writeConcern\" is expected to be \"%s\", \"%s\" given.'",
",",
"WriteConcern",
"::",
"class",
",",
"\\",
"Tequila",
"\\",
"MongoDB",
"\\",
"getType",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
")",
")",
";",
"}",
"$",
"writeConcern",
"=",
"$",
"options",
"[",
"'writeConcern'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"writeConcern",
"=",
"$",
"this",
"->",
"writeConcern",
";",
"}",
"$",
"bulkWrite",
"=",
"new",
"BulkWrite",
"(",
"$",
"requests",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"manager",
"->",
"executeBulkWrite",
"(",
"$",
"this",
"->",
"getNamespace",
"(",
")",
",",
"$",
"bulkWrite",
",",
"$",
"writeConcern",
")",
";",
"}"
] |
@param WriteModelInterface[]|\Traversable $requests
@param array $options
@return WriteResult
|
[
"@param",
"WriteModelInterface",
"[]",
"|",
"\\",
"Traversable",
"$requests",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L117-L139
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.count
|
public function count(array $filter = [], array $options = [])
{
$cursor = $this->executeCommand(
['count' => $this->collectionName, 'query' => (object) $filter],
$options
);
$result = $cursor->current();
if (!isset($result['n'])) {
throw new UnexpectedResultException('Command "count" did not return expected "n" field.');
}
return (int) $result['n'];
}
|
php
|
public function count(array $filter = [], array $options = [])
{
$cursor = $this->executeCommand(
['count' => $this->collectionName, 'query' => (object) $filter],
$options
);
$result = $cursor->current();
if (!isset($result['n'])) {
throw new UnexpectedResultException('Command "count" did not return expected "n" field.');
}
return (int) $result['n'];
}
|
[
"public",
"function",
"count",
"(",
"array",
"$",
"filter",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"cursor",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"[",
"'count'",
"=>",
"$",
"this",
"->",
"collectionName",
",",
"'query'",
"=>",
"(",
"object",
")",
"$",
"filter",
"]",
",",
"$",
"options",
")",
";",
"$",
"result",
"=",
"$",
"cursor",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"'n'",
"]",
")",
")",
"{",
"throw",
"new",
"UnexpectedResultException",
"(",
"'Command \"count\" did not return expected \"n\" field.'",
")",
";",
"}",
"return",
"(",
"int",
")",
"$",
"result",
"[",
"'n'",
"]",
";",
"}"
] |
@param array $filter
@param array $options
@return int
|
[
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L147-L160
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.createIndex
|
public function createIndex(array $key, array $options = [])
{
$commandOptions = [];
if (isset($options['writeConcern'])) {
$commandOptions['writeConcern'] = $options['writeConcern'];
unset($options['writeConcern']);
}
$index = new Index($key, $options);
return current($this->createIndexes([$index], $commandOptions));
}
|
php
|
public function createIndex(array $key, array $options = [])
{
$commandOptions = [];
if (isset($options['writeConcern'])) {
$commandOptions['writeConcern'] = $options['writeConcern'];
unset($options['writeConcern']);
}
$index = new Index($key, $options);
return current($this->createIndexes([$index], $commandOptions));
}
|
[
"public",
"function",
"createIndex",
"(",
"array",
"$",
"key",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"commandOptions",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
")",
"{",
"$",
"commandOptions",
"[",
"'writeConcern'",
"]",
"=",
"$",
"options",
"[",
"'writeConcern'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
";",
"}",
"$",
"index",
"=",
"new",
"Index",
"(",
"$",
"key",
",",
"$",
"options",
")",
";",
"return",
"current",
"(",
"$",
"this",
"->",
"createIndexes",
"(",
"[",
"$",
"index",
"]",
",",
"$",
"commandOptions",
")",
")",
";",
"}"
] |
@param array $key
@param array $options
@return string
|
[
"@param",
"array",
"$key",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L168-L178
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.createIndexes
|
public function createIndexes(array $indexes, array $options = [])
{
if (empty($indexes)) {
throw new InvalidArgumentException('$indexes array cannot be empty.');
}
$compiledIndexes = array_map(function (Index $index) {
return $index->toArray();
}, $indexes);
$this->executeCommand(
['createIndexes' => $this->collectionName, 'indexes' => $compiledIndexes],
$options
);
return array_map(function (Index $index) {
return $index->getName();
}, $indexes);
}
|
php
|
public function createIndexes(array $indexes, array $options = [])
{
if (empty($indexes)) {
throw new InvalidArgumentException('$indexes array cannot be empty.');
}
$compiledIndexes = array_map(function (Index $index) {
return $index->toArray();
}, $indexes);
$this->executeCommand(
['createIndexes' => $this->collectionName, 'indexes' => $compiledIndexes],
$options
);
return array_map(function (Index $index) {
return $index->getName();
}, $indexes);
}
|
[
"public",
"function",
"createIndexes",
"(",
"array",
"$",
"indexes",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"indexes",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$indexes array cannot be empty.'",
")",
";",
"}",
"$",
"compiledIndexes",
"=",
"array_map",
"(",
"function",
"(",
"Index",
"$",
"index",
")",
"{",
"return",
"$",
"index",
"->",
"toArray",
"(",
")",
";",
"}",
",",
"$",
"indexes",
")",
";",
"$",
"this",
"->",
"executeCommand",
"(",
"[",
"'createIndexes'",
"=>",
"$",
"this",
"->",
"collectionName",
",",
"'indexes'",
"=>",
"$",
"compiledIndexes",
"]",
",",
"$",
"options",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"Index",
"$",
"index",
")",
"{",
"return",
"$",
"index",
"->",
"getName",
"(",
")",
";",
"}",
",",
"$",
"indexes",
")",
";",
"}"
] |
@param Index[] $indexes
@param array $options
@return \string[]
|
[
"@param",
"Index",
"[]",
"$indexes",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L186-L204
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.deleteMany
|
public function deleteMany(array $filter, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new DeleteMany($filter, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new DeleteResult($bulkWriteResult);
}
|
php
|
public function deleteMany(array $filter, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new DeleteMany($filter, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new DeleteResult($bulkWriteResult);
}
|
[
"public",
"function",
"deleteMany",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"bulkOptions",
",",
"$",
"options",
")",
"=",
"self",
"::",
"extractBulkWriteOptions",
"(",
"$",
"options",
")",
";",
"$",
"model",
"=",
"new",
"DeleteMany",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"$",
"bulkWriteResult",
"=",
"$",
"this",
"->",
"bulkWrite",
"(",
"[",
"$",
"model",
"]",
",",
"$",
"bulkOptions",
")",
";",
"return",
"new",
"DeleteResult",
"(",
"$",
"bulkWriteResult",
")",
";",
"}"
] |
@param array $filter
@param array $options
@return DeleteResult
|
[
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L212-L219
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.deleteOne
|
public function deleteOne(array $filter, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new DeleteOne($filter, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new DeleteResult($bulkWriteResult);
}
|
php
|
public function deleteOne(array $filter, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new DeleteOne($filter, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new DeleteResult($bulkWriteResult);
}
|
[
"public",
"function",
"deleteOne",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"bulkOptions",
",",
"$",
"options",
")",
"=",
"self",
"::",
"extractBulkWriteOptions",
"(",
"$",
"options",
")",
";",
"$",
"model",
"=",
"new",
"DeleteOne",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"$",
"bulkWriteResult",
"=",
"$",
"this",
"->",
"bulkWrite",
"(",
"[",
"$",
"model",
"]",
",",
"$",
"bulkOptions",
")",
";",
"return",
"new",
"DeleteResult",
"(",
"$",
"bulkWriteResult",
")",
";",
"}"
] |
@param array $filter
@param array $options
@return DeleteResult
|
[
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L227-L234
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.distinct
|
public function distinct($fieldName, array $filter = [], array $options = [])
{
if (!is_string($fieldName)) {
throw new InvalidArgumentException('$fieldName must be a string.');
}
if (!$fieldName) {
throw new InvalidArgumentException('$fieldName cannot be empty.');
}
$command = ['distinct' => $this->collectionName, 'key' => $fieldName];
if ($filter) {
$command['query'] = (object) $filter;
}
$options['typeMap'] = [];
$cursor = $this->executeCommand($command, $options);
$result = $cursor->current();
if (!isset($result->values)) {
throw new UnexpectedResultException(
'Command "distinct" did not return expected "values" array.'
);
}
return $result->values;
}
|
php
|
public function distinct($fieldName, array $filter = [], array $options = [])
{
if (!is_string($fieldName)) {
throw new InvalidArgumentException('$fieldName must be a string.');
}
if (!$fieldName) {
throw new InvalidArgumentException('$fieldName cannot be empty.');
}
$command = ['distinct' => $this->collectionName, 'key' => $fieldName];
if ($filter) {
$command['query'] = (object) $filter;
}
$options['typeMap'] = [];
$cursor = $this->executeCommand($command, $options);
$result = $cursor->current();
if (!isset($result->values)) {
throw new UnexpectedResultException(
'Command "distinct" did not return expected "values" array.'
);
}
return $result->values;
}
|
[
"public",
"function",
"distinct",
"(",
"$",
"fieldName",
",",
"array",
"$",
"filter",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"fieldName",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$fieldName must be a string.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"fieldName",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$fieldName cannot be empty.'",
")",
";",
"}",
"$",
"command",
"=",
"[",
"'distinct'",
"=>",
"$",
"this",
"->",
"collectionName",
",",
"'key'",
"=>",
"$",
"fieldName",
"]",
";",
"if",
"(",
"$",
"filter",
")",
"{",
"$",
"command",
"[",
"'query'",
"]",
"=",
"(",
"object",
")",
"$",
"filter",
";",
"}",
"$",
"options",
"[",
"'typeMap'",
"]",
"=",
"[",
"]",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"$",
"command",
",",
"$",
"options",
")",
";",
"$",
"result",
"=",
"$",
"cursor",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"->",
"values",
")",
")",
"{",
"throw",
"new",
"UnexpectedResultException",
"(",
"'Command \"distinct\" did not return expected \"values\" array.'",
")",
";",
"}",
"return",
"$",
"result",
"->",
"values",
";",
"}"
] |
@param string $fieldName
@param array $filter
@param array $options
@return array
|
[
"@param",
"string",
"$fieldName",
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L243-L269
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.drop
|
public function drop(array $options = [])
{
try {
$cursor = $this->executeCommand(['drop' => $this->collectionName], $options);
} catch (MongoDBRuntimeException $e) {
if ('ns not found' === $e->getMessage()) {
return ['ok' => 0, 'errmsg' => $e->getMessage()];
}
throw $e;
}
return $cursor->current();
}
|
php
|
public function drop(array $options = [])
{
try {
$cursor = $this->executeCommand(['drop' => $this->collectionName], $options);
} catch (MongoDBRuntimeException $e) {
if ('ns not found' === $e->getMessage()) {
return ['ok' => 0, 'errmsg' => $e->getMessage()];
}
throw $e;
}
return $cursor->current();
}
|
[
"public",
"function",
"drop",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"$",
"cursor",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"[",
"'drop'",
"=>",
"$",
"this",
"->",
"collectionName",
"]",
",",
"$",
"options",
")",
";",
"}",
"catch",
"(",
"MongoDBRuntimeException",
"$",
"e",
")",
"{",
"if",
"(",
"'ns not found'",
"===",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
"{",
"return",
"[",
"'ok'",
"=>",
"0",
",",
"'errmsg'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"cursor",
"->",
"current",
"(",
")",
";",
"}"
] |
@param array $options
@return array
|
[
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L276-L289
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.dropIndexes
|
public function dropIndexes(array $options = [])
{
$command = [
'dropIndexes' => $this->collectionName,
'index' => '*',
];
$cursor = $this->executeCommand($command, $options);
return $cursor->current();
}
|
php
|
public function dropIndexes(array $options = [])
{
$command = [
'dropIndexes' => $this->collectionName,
'index' => '*',
];
$cursor = $this->executeCommand($command, $options);
return $cursor->current();
}
|
[
"public",
"function",
"dropIndexes",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"command",
"=",
"[",
"'dropIndexes'",
"=>",
"$",
"this",
"->",
"collectionName",
",",
"'index'",
"=>",
"'*'",
",",
"]",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"$",
"command",
",",
"$",
"options",
")",
";",
"return",
"$",
"cursor",
"->",
"current",
"(",
")",
";",
"}"
] |
@param array $options
@return array
|
[
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L296-L305
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.dropIndex
|
public function dropIndex($indexName, array $options = [])
{
if ('*' === $indexName) {
throw new InvalidArgumentException(
'Invalid $indexName "*", use dropIndexes() method to delete all indexes.'
);
}
$command = [
'dropIndexes' => $this->collectionName,
'index' => $indexName,
];
$cursor = $this->executeCommand($command, $options);
return $cursor->current();
}
|
php
|
public function dropIndex($indexName, array $options = [])
{
if ('*' === $indexName) {
throw new InvalidArgumentException(
'Invalid $indexName "*", use dropIndexes() method to delete all indexes.'
);
}
$command = [
'dropIndexes' => $this->collectionName,
'index' => $indexName,
];
$cursor = $this->executeCommand($command, $options);
return $cursor->current();
}
|
[
"public",
"function",
"dropIndex",
"(",
"$",
"indexName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"'*'",
"===",
"$",
"indexName",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid $indexName \"*\", use dropIndexes() method to delete all indexes.'",
")",
";",
"}",
"$",
"command",
"=",
"[",
"'dropIndexes'",
"=>",
"$",
"this",
"->",
"collectionName",
",",
"'index'",
"=>",
"$",
"indexName",
",",
"]",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"$",
"command",
",",
"$",
"options",
")",
";",
"return",
"$",
"cursor",
"->",
"current",
"(",
")",
";",
"}"
] |
@param string $indexName
@param array $options
@return array
|
[
"@param",
"string",
"$indexName",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L313-L329
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.find
|
public function find(array $filter = [], array $options = [])
{
$options += ['typeMap' => $this->typeMap];
$options = QueryOptionsResolver::resolveStatic($options);
$typeMap = $options['typeMap'];
unset($options['typeMap']);
if (isset($options['readPreference'])) {
$readPreference = $options['readPreference'];
unset($options['readPreference']);
} else {
$readPreference = $this->readPreference;
}
$query = new Query($filter, $options);
$query->setDefaultReadConcern($this->readConcern);
$cursor = $this->manager->executeQuery(
$this->getNamespace(),
$query,
$readPreference
);
$cursor->setTypeMap($typeMap);
return $cursor;
}
|
php
|
public function find(array $filter = [], array $options = [])
{
$options += ['typeMap' => $this->typeMap];
$options = QueryOptionsResolver::resolveStatic($options);
$typeMap = $options['typeMap'];
unset($options['typeMap']);
if (isset($options['readPreference'])) {
$readPreference = $options['readPreference'];
unset($options['readPreference']);
} else {
$readPreference = $this->readPreference;
}
$query = new Query($filter, $options);
$query->setDefaultReadConcern($this->readConcern);
$cursor = $this->manager->executeQuery(
$this->getNamespace(),
$query,
$readPreference
);
$cursor->setTypeMap($typeMap);
return $cursor;
}
|
[
"public",
"function",
"find",
"(",
"array",
"$",
"filter",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'typeMap'",
"=>",
"$",
"this",
"->",
"typeMap",
"]",
";",
"$",
"options",
"=",
"QueryOptionsResolver",
"::",
"resolveStatic",
"(",
"$",
"options",
")",
";",
"$",
"typeMap",
"=",
"$",
"options",
"[",
"'typeMap'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'typeMap'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
")",
"{",
"$",
"readPreference",
"=",
"$",
"options",
"[",
"'readPreference'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"readPreference",
"=",
"$",
"this",
"->",
"readPreference",
";",
"}",
"$",
"query",
"=",
"new",
"Query",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"$",
"query",
"->",
"setDefaultReadConcern",
"(",
"$",
"this",
"->",
"readConcern",
")",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"manager",
"->",
"executeQuery",
"(",
"$",
"this",
"->",
"getNamespace",
"(",
")",
",",
"$",
"query",
",",
"$",
"readPreference",
")",
";",
"$",
"cursor",
"->",
"setTypeMap",
"(",
"$",
"typeMap",
")",
";",
"return",
"$",
"cursor",
";",
"}"
] |
@param array $filter
@param array $options
@return QueryCursor
|
[
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L337-L363
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.findOne
|
public function findOne(array $filter = [], array $options = [])
{
$cursor = $this->find($filter, ['limit' => 1] + $options);
return ($document = $cursor->current()) ? $document : null;
}
|
php
|
public function findOne(array $filter = [], array $options = [])
{
$cursor = $this->find($filter, ['limit' => 1] + $options);
return ($document = $cursor->current()) ? $document : null;
}
|
[
"public",
"function",
"findOne",
"(",
"array",
"$",
"filter",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"cursor",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"filter",
",",
"[",
"'limit'",
"=>",
"1",
"]",
"+",
"$",
"options",
")",
";",
"return",
"(",
"$",
"document",
"=",
"$",
"cursor",
"->",
"current",
"(",
")",
")",
"?",
"$",
"document",
":",
"null",
";",
"}"
] |
@param array $filter
@param array $options
@return array|Unserializable|null
|
[
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L371-L376
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.findOneAndDelete
|
public function findOneAndDelete(array $filter, array $options = [])
{
$options = ['remove' => true] + FindOneAndDeleteResolver::resolveStatic($options);
return $this->findAndModify($filter, $options);
}
|
php
|
public function findOneAndDelete(array $filter, array $options = [])
{
$options = ['remove' => true] + FindOneAndDeleteResolver::resolveStatic($options);
return $this->findAndModify($filter, $options);
}
|
[
"public",
"function",
"findOneAndDelete",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"[",
"'remove'",
"=>",
"true",
"]",
"+",
"FindOneAndDeleteResolver",
"::",
"resolveStatic",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"findAndModify",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"}"
] |
@param array $filter
@param array $options
@return array|Unserializable|null
|
[
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L384-L389
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.findOneAndReplace
|
public function findOneAndReplace(array $filter, $replacement, array $options = [])
{
if (!is_array($replacement) && !is_object($replacement)) {
throw new InvalidArgumentException(
sprintf(
'$replacement must be an array or an object, "%s" given.',
\Tequila\MongoDB\getType($replacement)
)
);
}
try {
ensureValidDocument($replacement);
} catch (InvalidArgumentException $e) {
throw new InvalidArgumentException(
sprintf('Invalid $replacement document: %s', $e->getMessage())
);
}
$options = ['update' => (object) $replacement] + FindOneAndUpdateResolver::resolveStatic($options);
return $this->findAndModify($filter, $options);
}
|
php
|
public function findOneAndReplace(array $filter, $replacement, array $options = [])
{
if (!is_array($replacement) && !is_object($replacement)) {
throw new InvalidArgumentException(
sprintf(
'$replacement must be an array or an object, "%s" given.',
\Tequila\MongoDB\getType($replacement)
)
);
}
try {
ensureValidDocument($replacement);
} catch (InvalidArgumentException $e) {
throw new InvalidArgumentException(
sprintf('Invalid $replacement document: %s', $e->getMessage())
);
}
$options = ['update' => (object) $replacement] + FindOneAndUpdateResolver::resolveStatic($options);
return $this->findAndModify($filter, $options);
}
|
[
"public",
"function",
"findOneAndReplace",
"(",
"array",
"$",
"filter",
",",
"$",
"replacement",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"replacement",
")",
"&&",
"!",
"is_object",
"(",
"$",
"replacement",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'$replacement must be an array or an object, \"%s\" given.'",
",",
"\\",
"Tequila",
"\\",
"MongoDB",
"\\",
"getType",
"(",
"$",
"replacement",
")",
")",
")",
";",
"}",
"try",
"{",
"ensureValidDocument",
"(",
"$",
"replacement",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid $replacement document: %s'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"$",
"options",
"=",
"[",
"'update'",
"=>",
"(",
"object",
")",
"$",
"replacement",
"]",
"+",
"FindOneAndUpdateResolver",
"::",
"resolveStatic",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"findAndModify",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"}"
] |
@param array $filter
@param array|object $replacement
@param array $options
@return array|Unserializable|null
|
[
"@param",
"array",
"$filter",
"@param",
"array|object",
"$replacement",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L398-L420
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.findOneAndUpdate
|
public function findOneAndUpdate(array $filter, array $update, array $options = [])
{
\Tequila\MongoDB\ensureValidUpdate($update);
$options = ['update' => (object) $update] + FindOneAndUpdateResolver::resolveStatic($options);
return $this->findAndModify($filter, $options);
}
|
php
|
public function findOneAndUpdate(array $filter, array $update, array $options = [])
{
\Tequila\MongoDB\ensureValidUpdate($update);
$options = ['update' => (object) $update] + FindOneAndUpdateResolver::resolveStatic($options);
return $this->findAndModify($filter, $options);
}
|
[
"public",
"function",
"findOneAndUpdate",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"update",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"\\",
"Tequila",
"\\",
"MongoDB",
"\\",
"ensureValidUpdate",
"(",
"$",
"update",
")",
";",
"$",
"options",
"=",
"[",
"'update'",
"=>",
"(",
"object",
")",
"$",
"update",
"]",
"+",
"FindOneAndUpdateResolver",
"::",
"resolveStatic",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"findAndModify",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"}"
] |
@param array $filter
@param $update
@param array $options
@return array|Unserializable|null
|
[
"@param",
"array",
"$filter",
"@param",
"$update",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L429-L436
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.insertMany
|
public function insertMany($documents, array $options = [])
{
$writeModel = new InsertMany($documents);
$bulkWriteResult = $this->bulkWrite([$writeModel], $options);
return new InsertManyResult($bulkWriteResult);
}
|
php
|
public function insertMany($documents, array $options = [])
{
$writeModel = new InsertMany($documents);
$bulkWriteResult = $this->bulkWrite([$writeModel], $options);
return new InsertManyResult($bulkWriteResult);
}
|
[
"public",
"function",
"insertMany",
"(",
"$",
"documents",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"writeModel",
"=",
"new",
"InsertMany",
"(",
"$",
"documents",
")",
";",
"$",
"bulkWriteResult",
"=",
"$",
"this",
"->",
"bulkWrite",
"(",
"[",
"$",
"writeModel",
"]",
",",
"$",
"options",
")",
";",
"return",
"new",
"InsertManyResult",
"(",
"$",
"bulkWriteResult",
")",
";",
"}"
] |
@param array|\Traversable $documents
@param array $options
@return InsertManyResult
|
[
"@param",
"array|",
"\\",
"Traversable",
"$documents",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L468-L474
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.insertOne
|
public function insertOne($document, array $options = [])
{
$model = new InsertOne($document);
$bulkWriteResult = $this->bulkWrite([$model], $options);
return new InsertOneResult($bulkWriteResult);
}
|
php
|
public function insertOne($document, array $options = [])
{
$model = new InsertOne($document);
$bulkWriteResult = $this->bulkWrite([$model], $options);
return new InsertOneResult($bulkWriteResult);
}
|
[
"public",
"function",
"insertOne",
"(",
"$",
"document",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"model",
"=",
"new",
"InsertOne",
"(",
"$",
"document",
")",
";",
"$",
"bulkWriteResult",
"=",
"$",
"this",
"->",
"bulkWrite",
"(",
"[",
"$",
"model",
"]",
",",
"$",
"options",
")",
";",
"return",
"new",
"InsertOneResult",
"(",
"$",
"bulkWriteResult",
")",
";",
"}"
] |
@param array|object $document
@param array $options
@return InsertOneResult
|
[
"@param",
"array|object",
"$document",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L482-L488
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.replaceOne
|
public function replaceOne(array $filter, $replacement, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new ReplaceOne($filter, $replacement, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new UpdateResult($bulkWriteResult);
}
|
php
|
public function replaceOne(array $filter, $replacement, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new ReplaceOne($filter, $replacement, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new UpdateResult($bulkWriteResult);
}
|
[
"public",
"function",
"replaceOne",
"(",
"array",
"$",
"filter",
",",
"$",
"replacement",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"bulkOptions",
",",
"$",
"options",
")",
"=",
"self",
"::",
"extractBulkWriteOptions",
"(",
"$",
"options",
")",
";",
"$",
"model",
"=",
"new",
"ReplaceOne",
"(",
"$",
"filter",
",",
"$",
"replacement",
",",
"$",
"options",
")",
";",
"$",
"bulkWriteResult",
"=",
"$",
"this",
"->",
"bulkWrite",
"(",
"[",
"$",
"model",
"]",
",",
"$",
"bulkOptions",
")",
";",
"return",
"new",
"UpdateResult",
"(",
"$",
"bulkWriteResult",
")",
";",
"}"
] |
@param array|object $filter
@param array|object $replacement
@param array $options
@return UpdateResult
|
[
"@param",
"array|object",
"$filter",
"@param",
"array|object",
"$replacement",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L513-L521
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.updateMany
|
public function updateMany(array $filter, $update, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new UpdateMany($filter, $update, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new UpdateResult($bulkWriteResult);
}
|
php
|
public function updateMany(array $filter, $update, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new UpdateMany($filter, $update, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new UpdateResult($bulkWriteResult);
}
|
[
"public",
"function",
"updateMany",
"(",
"array",
"$",
"filter",
",",
"$",
"update",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"bulkOptions",
",",
"$",
"options",
")",
"=",
"self",
"::",
"extractBulkWriteOptions",
"(",
"$",
"options",
")",
";",
"$",
"model",
"=",
"new",
"UpdateMany",
"(",
"$",
"filter",
",",
"$",
"update",
",",
"$",
"options",
")",
";",
"$",
"bulkWriteResult",
"=",
"$",
"this",
"->",
"bulkWrite",
"(",
"[",
"$",
"model",
"]",
",",
"$",
"bulkOptions",
")",
";",
"return",
"new",
"UpdateResult",
"(",
"$",
"bulkWriteResult",
")",
";",
"}"
] |
@param array $filter
@param array|object $update
@param array $options
@return UpdateResult
|
[
"@param",
"array",
"$filter",
"@param",
"array|object",
"$update",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L530-L538
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.updateOne
|
public function updateOne(array $filter, $update, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new UpdateOne($filter, $update, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new UpdateResult($bulkWriteResult);
}
|
php
|
public function updateOne(array $filter, $update, array $options = [])
{
list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
$model = new UpdateOne($filter, $update, $options);
$bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);
return new UpdateResult($bulkWriteResult);
}
|
[
"public",
"function",
"updateOne",
"(",
"array",
"$",
"filter",
",",
"$",
"update",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"bulkOptions",
",",
"$",
"options",
")",
"=",
"self",
"::",
"extractBulkWriteOptions",
"(",
"$",
"options",
")",
";",
"$",
"model",
"=",
"new",
"UpdateOne",
"(",
"$",
"filter",
",",
"$",
"update",
",",
"$",
"options",
")",
";",
"$",
"bulkWriteResult",
"=",
"$",
"this",
"->",
"bulkWrite",
"(",
"[",
"$",
"model",
"]",
",",
"$",
"bulkOptions",
")",
";",
"return",
"new",
"UpdateResult",
"(",
"$",
"bulkWriteResult",
")",
";",
"}"
] |
@param array $filter
@param array|object $update
@param array $options
@return UpdateResult
|
[
"@param",
"array",
"$filter",
"@param",
"array|object",
"$update",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L547-L555
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.extractBulkWriteOptions
|
private static function extractBulkWriteOptions(array $options)
{
$definedBulkOptions = ['bypassDocumentValidation', 'ordered', 'writeConcern'];
$bulkWriteOptions = array_intersect_key($options, array_flip($definedBulkOptions));
$operationOptions = array_diff_key($options, $bulkWriteOptions);
return [$bulkWriteOptions, $operationOptions];
}
|
php
|
private static function extractBulkWriteOptions(array $options)
{
$definedBulkOptions = ['bypassDocumentValidation', 'ordered', 'writeConcern'];
$bulkWriteOptions = array_intersect_key($options, array_flip($definedBulkOptions));
$operationOptions = array_diff_key($options, $bulkWriteOptions);
return [$bulkWriteOptions, $operationOptions];
}
|
[
"private",
"static",
"function",
"extractBulkWriteOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"definedBulkOptions",
"=",
"[",
"'bypassDocumentValidation'",
",",
"'ordered'",
",",
"'writeConcern'",
"]",
";",
"$",
"bulkWriteOptions",
"=",
"array_intersect_key",
"(",
"$",
"options",
",",
"array_flip",
"(",
"$",
"definedBulkOptions",
")",
")",
";",
"$",
"operationOptions",
"=",
"array_diff_key",
"(",
"$",
"options",
",",
"$",
"bulkWriteOptions",
")",
";",
"return",
"[",
"$",
"bulkWriteOptions",
",",
"$",
"operationOptions",
"]",
";",
"}"
] |
@param array $options
@return array
|
[
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L562-L569
|
tequila/mongodb-php-lib
|
src/Collection.php
|
Collection.findAndModify
|
private function findAndModify(array $filter, array $options)
{
$command = [
'findAndModify' => $this->collectionName,
'query' => (object) $filter,
];
$options += ['typeMap' => $this->typeMap];
$typeMap = $options['typeMap'];
unset($options['typeMap']);
$cursor = $this->executeCommand($command, $options);
$result = $cursor->current();
if (!array_key_exists('value', $result)) {
throw new UnexpectedResultException(
'Command "findAndModify" did not return expected "value" document.'
);
}
$result = $result['value'];
return \Tequila\MongoDB\applyTypeMap($result, $typeMap);
}
|
php
|
private function findAndModify(array $filter, array $options)
{
$command = [
'findAndModify' => $this->collectionName,
'query' => (object) $filter,
];
$options += ['typeMap' => $this->typeMap];
$typeMap = $options['typeMap'];
unset($options['typeMap']);
$cursor = $this->executeCommand($command, $options);
$result = $cursor->current();
if (!array_key_exists('value', $result)) {
throw new UnexpectedResultException(
'Command "findAndModify" did not return expected "value" document.'
);
}
$result = $result['value'];
return \Tequila\MongoDB\applyTypeMap($result, $typeMap);
}
|
[
"private",
"function",
"findAndModify",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"options",
")",
"{",
"$",
"command",
"=",
"[",
"'findAndModify'",
"=>",
"$",
"this",
"->",
"collectionName",
",",
"'query'",
"=>",
"(",
"object",
")",
"$",
"filter",
",",
"]",
";",
"$",
"options",
"+=",
"[",
"'typeMap'",
"=>",
"$",
"this",
"->",
"typeMap",
"]",
";",
"$",
"typeMap",
"=",
"$",
"options",
"[",
"'typeMap'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'typeMap'",
"]",
")",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"$",
"command",
",",
"$",
"options",
")",
";",
"$",
"result",
"=",
"$",
"cursor",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'value'",
",",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"UnexpectedResultException",
"(",
"'Command \"findAndModify\" did not return expected \"value\" document.'",
")",
";",
"}",
"$",
"result",
"=",
"$",
"result",
"[",
"'value'",
"]",
";",
"return",
"\\",
"Tequila",
"\\",
"MongoDB",
"\\",
"applyTypeMap",
"(",
"$",
"result",
",",
"$",
"typeMap",
")",
";",
"}"
] |
@param array $filter
@param array $options
@return array|Unserializable|object|null
|
[
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Collection.php#L577-L600
|
czim/laravel-pxlcms
|
src/Relations/BelongsToMany.php
|
BelongsToMany.save
|
public function save(Model $model, array $joining = [], $touch = true)
{
if (empty($joining) && $this->fromFieldId) {
$joining = [ static::$fromFieldKey => $this->fromFieldId ];
}
return parent::save($model, $joining, $touch);
}
|
php
|
public function save(Model $model, array $joining = [], $touch = true)
{
if (empty($joining) && $this->fromFieldId) {
$joining = [ static::$fromFieldKey => $this->fromFieldId ];
}
return parent::save($model, $joining, $touch);
}
|
[
"public",
"function",
"save",
"(",
"Model",
"$",
"model",
",",
"array",
"$",
"joining",
"=",
"[",
"]",
",",
"$",
"touch",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"joining",
")",
"&&",
"$",
"this",
"->",
"fromFieldId",
")",
"{",
"$",
"joining",
"=",
"[",
"static",
"::",
"$",
"fromFieldKey",
"=>",
"$",
"this",
"->",
"fromFieldId",
"]",
";",
"}",
"return",
"parent",
"::",
"save",
"(",
"$",
"model",
",",
"$",
"joining",
",",
"$",
"touch",
")",
";",
"}"
] |
Save a new model and attach it to the parent model.
This makes sure we add the from_field_id to the 'pivot' table
@param \Illuminate\Database\Eloquent\Model $model
@param array $joining
@param bool $touch
@return \Illuminate\Database\Eloquent\Model
|
[
"Save",
"a",
"new",
"model",
"and",
"attach",
"it",
"to",
"the",
"parent",
"model",
"."
] |
train
|
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Relations/BelongsToMany.php#L67-L74
|
czim/laravel-pxlcms
|
src/Relations/BelongsToMany.php
|
BelongsToMany.attacher
|
protected function attacher($key, $value, $attributes, $timed)
{
if (empty($attributes)) {
$attributes = [ static::$fromFieldKey => $this->fromFieldId ];
}
return parent::attacher($key, $value, $attributes, $timed);
}
|
php
|
protected function attacher($key, $value, $attributes, $timed)
{
if (empty($attributes)) {
$attributes = [ static::$fromFieldKey => $this->fromFieldId ];
}
return parent::attacher($key, $value, $attributes, $timed);
}
|
[
"protected",
"function",
"attacher",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"attributes",
",",
"$",
"timed",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"attributes",
"=",
"[",
"static",
"::",
"$",
"fromFieldKey",
"=>",
"$",
"this",
"->",
"fromFieldId",
"]",
";",
"}",
"return",
"parent",
"::",
"attacher",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"attributes",
",",
"$",
"timed",
")",
";",
"}"
] |
Create a full attachment record payload.
This includes the from_field_id in the attachment payload
@param int $key
@param mixed $value
@param array $attributes
@param bool $timed
@return array
|
[
"Create",
"a",
"full",
"attachment",
"record",
"payload",
"."
] |
train
|
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Relations/BelongsToMany.php#L87-L94
|
Teamsisu/contao-mm-frontendInput
|
src/Teamsisu/MetaModelsFrontendInput/DataContainer/Field/Collection.php
|
Collection.getItem
|
public function getItem()
{
// Implicitly call first when not within "while ($obj->next())" scope.
if ($this->intCursor < 0) {
$this->first();
}
// Beyond bounds? return null.
if (!$this->valid()) {
return null;
}
return $this->items[$this->intCursor];
}
|
php
|
public function getItem()
{
// Implicitly call first when not within "while ($obj->next())" scope.
if ($this->intCursor < 0) {
$this->first();
}
// Beyond bounds? return null.
if (!$this->valid()) {
return null;
}
return $this->items[$this->intCursor];
}
|
[
"public",
"function",
"getItem",
"(",
")",
"{",
"// Implicitly call first when not within \"while ($obj->next())\" scope.",
"if",
"(",
"$",
"this",
"->",
"intCursor",
"<",
"0",
")",
"{",
"$",
"this",
"->",
"first",
"(",
")",
";",
"}",
"// Beyond bounds? return null.",
"if",
"(",
"!",
"$",
"this",
"->",
"valid",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"items",
"[",
"$",
"this",
"->",
"intCursor",
"]",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/Teamsisu/contao-mm-frontendInput/blob/ab92e61c24644f1e61265304b6a35e505007d021/src/Teamsisu/MetaModelsFrontendInput/DataContainer/Field/Collection.php#L151-L164
|
foothing/laravel-repository
|
src/Foothing/Repository/Operators/AbstractOperator.php
|
AbstractOperator.guessField
|
public function guessField($field) {
// Explode by ".", only two allowed kind of values:
// - a string like "name"
// - a string like "relation.name"
$chunks = explode(".", $field);
$count = count($chunks);
// Chunk 0 is empty, this is a malformed input.
if ($count == 1 && ! $chunks[0]) {
throw new \Exception("Field is empty.");
}
// Malformed input again, probably in the form ".foo".
elseif ($count == 2 && (! $chunks[0] || !$chunks[1])) {
throw new \Exception("Field is empty or broken.");
}
// Only one chunk: assume field is an actual table column.
elseif ($count == 1) {
return $field;
}
// Two chunks: assume this is a nested field.
elseif ($count == 2) {
return new NestedField($chunks[0], $chunks[1]);
}
else {
throw new \Exception("Field has a bad format (3 or more tokens).");
}
}
|
php
|
public function guessField($field) {
// Explode by ".", only two allowed kind of values:
// - a string like "name"
// - a string like "relation.name"
$chunks = explode(".", $field);
$count = count($chunks);
// Chunk 0 is empty, this is a malformed input.
if ($count == 1 && ! $chunks[0]) {
throw new \Exception("Field is empty.");
}
// Malformed input again, probably in the form ".foo".
elseif ($count == 2 && (! $chunks[0] || !$chunks[1])) {
throw new \Exception("Field is empty or broken.");
}
// Only one chunk: assume field is an actual table column.
elseif ($count == 1) {
return $field;
}
// Two chunks: assume this is a nested field.
elseif ($count == 2) {
return new NestedField($chunks[0], $chunks[1]);
}
else {
throw new \Exception("Field has a bad format (3 or more tokens).");
}
}
|
[
"public",
"function",
"guessField",
"(",
"$",
"field",
")",
"{",
"// Explode by \".\", only two allowed kind of values:",
"// - a string like \"name\"",
"// - a string like \"relation.name\"",
"$",
"chunks",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"field",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"chunks",
")",
";",
"// Chunk 0 is empty, this is a malformed input.",
"if",
"(",
"$",
"count",
"==",
"1",
"&&",
"!",
"$",
"chunks",
"[",
"0",
"]",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Field is empty.\"",
")",
";",
"}",
"// Malformed input again, probably in the form \".foo\".",
"elseif",
"(",
"$",
"count",
"==",
"2",
"&&",
"(",
"!",
"$",
"chunks",
"[",
"0",
"]",
"||",
"!",
"$",
"chunks",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Field is empty or broken.\"",
")",
";",
"}",
"// Only one chunk: assume field is an actual table column.",
"elseif",
"(",
"$",
"count",
"==",
"1",
")",
"{",
"return",
"$",
"field",
";",
"}",
"// Two chunks: assume this is a nested field.",
"elseif",
"(",
"$",
"count",
"==",
"2",
")",
"{",
"return",
"new",
"NestedField",
"(",
"$",
"chunks",
"[",
"0",
"]",
",",
"$",
"chunks",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Field has a bad format (3 or more tokens).\"",
")",
";",
"}",
"}"
] |
Guess the criteria field name. If $field is a string, it
is returned as-is. If it contains "." this method will
try to split in "relation.field" format and return
a NestedField object. Any other case will raise an
Exception.
@param string $field
The criteria->field.
@return NestedField|string
@throws \Exception
|
[
"Guess",
"the",
"criteria",
"field",
"name",
".",
"If",
"$field",
"is",
"a",
"string",
"it",
"is",
"returned",
"as",
"-",
"is",
".",
"If",
"it",
"contains",
".",
"this",
"method",
"will",
"try",
"to",
"split",
"in",
"relation",
".",
"field",
"format",
"and",
"return",
"a",
"NestedField",
"object",
".",
"Any",
"other",
"case",
"will",
"raise",
"an",
"Exception",
"."
] |
train
|
https://github.com/foothing/laravel-repository/blob/a2e329acb26a08d9f260c66534b0d4f42e2adff5/src/Foothing/Repository/Operators/AbstractOperator.php#L43-L73
|
baleen/cli
|
src/CommandBus/Repository/ListMessage.php
|
ListMessage.configure
|
public static function configure(Command $command)
{
$command->setName('migrations:list')
->setDescription('Prints version IDs for all available migrations ordered incrementally.')
->addOption(
'newest-first',
null,
InputOption::VALUE_NONE,
'Sort list in reverse order (newest first)'
);
}
|
php
|
public static function configure(Command $command)
{
$command->setName('migrations:list')
->setDescription('Prints version IDs for all available migrations ordered incrementally.')
->addOption(
'newest-first',
null,
InputOption::VALUE_NONE,
'Sort list in reverse order (newest first)'
);
}
|
[
"public",
"static",
"function",
"configure",
"(",
"Command",
"$",
"command",
")",
"{",
"$",
"command",
"->",
"setName",
"(",
"'migrations:list'",
")",
"->",
"setDescription",
"(",
"'Prints version IDs for all available migrations ordered incrementally.'",
")",
"->",
"addOption",
"(",
"'newest-first'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_NONE",
",",
"'Sort list in reverse order (newest first)'",
")",
";",
"}"
] |
configure.
@param Command $command
|
[
"configure",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Repository/ListMessage.php#L38-L48
|
discophp/framework
|
core/classes/Session.class.php
|
Session.in
|
public function in($k){
if(is_array($k) && count(array_intersect(array_keys($_SESSION),$k))>0){
return true;
}//if
return isset($_SESSION[$k]);
}
|
php
|
public function in($k){
if(is_array($k) && count(array_intersect(array_keys($_SESSION),$k))>0){
return true;
}//if
return isset($_SESSION[$k]);
}
|
[
"public",
"function",
"in",
"(",
"$",
"k",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"k",
")",
"&&",
"count",
"(",
"array_intersect",
"(",
"array_keys",
"(",
"$",
"_SESSION",
")",
",",
"$",
"k",
")",
")",
">",
"0",
")",
"{",
"return",
"true",
";",
"}",
"//if",
"return",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"k",
"]",
")",
";",
"}"
] |
Does the session have a value for the key(s)?
@param string|array $k The key(s) to check for in the session.
@return boolean Whether the key is in the session.
|
[
"Does",
"the",
"session",
"have",
"a",
"value",
"for",
"the",
"key",
"(",
"s",
")",
"?"
] |
train
|
https://github.com/discophp/framework/blob/40ff3ea5225810534195494dc6c21083da4d1356/core/classes/Session.class.php#L85-L93
|
discophp/framework
|
core/classes/Session.class.php
|
Session.getFlash
|
public function getFlash($key){
if(!isset($this->flash[$key])){
return false;
}//if
return $this->flash[$key];
}
|
php
|
public function getFlash($key){
if(!isset($this->flash[$key])){
return false;
}//if
return $this->flash[$key];
}
|
[
"public",
"function",
"getFlash",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"flash",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"//if",
"return",
"$",
"this",
"->",
"flash",
"[",
"$",
"key",
"]",
";",
"}"
] |
Get a piece of flash data.
@param string $key The flash data key.
@return false|mixed False if not set.
|
[
"Get",
"a",
"piece",
"of",
"flash",
"data",
"."
] |
train
|
https://github.com/discophp/framework/blob/40ff3ea5225810534195494dc6c21083da4d1356/core/classes/Session.class.php#L275-L283
|
discophp/framework
|
core/classes/Session.class.php
|
Session.getComplexFlash
|
public function getComplexFlash($key){
if(!isset($this->flash[$key])){
return false;
}//if
return unserialize($this->flash[$key]);
}
|
php
|
public function getComplexFlash($key){
if(!isset($this->flash[$key])){
return false;
}//if
return unserialize($this->flash[$key]);
}
|
[
"public",
"function",
"getComplexFlash",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"flash",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"//if",
"return",
"unserialize",
"(",
"$",
"this",
"->",
"flash",
"[",
"$",
"key",
"]",
")",
";",
"}"
] |
Get a piece of flash data.
@param string $key The flash data key.
@return false|mixed False if not set.
|
[
"Get",
"a",
"piece",
"of",
"flash",
"data",
"."
] |
train
|
https://github.com/discophp/framework/blob/40ff3ea5225810534195494dc6c21083da4d1356/core/classes/Session.class.php#L332-L340
|
stubbles/stubbles-webapp-core
|
src/main/php/session/WebSession.php
|
WebSession.hasValue
|
public function hasValue(string $key): bool
{
if (!$this->isValid()) {
return false;
}
return $this->storage->hasValue($key);
}
|
php
|
public function hasValue(string $key): bool
{
if (!$this->isValid()) {
return false;
}
return $this->storage->hasValue($key);
}
|
[
"public",
"function",
"hasValue",
"(",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"storage",
"->",
"hasValue",
"(",
"$",
"key",
")",
";",
"}"
] |
checks whether a value associated with key exists
@param string $key key where value is stored under
@return bool
|
[
"checks",
"whether",
"a",
"value",
"associated",
"with",
"key",
"exists"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/session/WebSession.php#L169-L176
|
stubbles/stubbles-webapp-core
|
src/main/php/session/WebSession.php
|
WebSession.value
|
public function value(string $key, $default = null)
{
if (!$this->isValid()) {
throw new \LogicException('Session is in an invalid state.');
}
if ($this->storage->hasValue($key)) {
return $this->storage->value($key);
}
return $default;
}
|
php
|
public function value(string $key, $default = null)
{
if (!$this->isValid()) {
throw new \LogicException('Session is in an invalid state.');
}
if ($this->storage->hasValue($key)) {
return $this->storage->value($key);
}
return $default;
}
|
[
"public",
"function",
"value",
"(",
"string",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Session is in an invalid state.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"storage",
"->",
"hasValue",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"storage",
"->",
"value",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
returns a value associated with the key or the default value
@param string $key key where value is stored under
@param mixed $default optional return this if no data is associated with $key
@return mixed
@throws \LogicException
|
[
"returns",
"a",
"value",
"associated",
"with",
"the",
"key",
"or",
"the",
"default",
"value"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/session/WebSession.php#L186-L197
|
stubbles/stubbles-webapp-core
|
src/main/php/session/WebSession.php
|
WebSession.putValue
|
public function putValue(string $key, $value): Session
{
if (!$this->isValid()) {
throw new \LogicException('Session is in an invalid state.');
}
$this->storage->putValue($key, $value);
return $this;
}
|
php
|
public function putValue(string $key, $value): Session
{
if (!$this->isValid()) {
throw new \LogicException('Session is in an invalid state.');
}
$this->storage->putValue($key, $value);
return $this;
}
|
[
"public",
"function",
"putValue",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"Session",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Session is in an invalid state.'",
")",
";",
"}",
"$",
"this",
"->",
"storage",
"->",
"putValue",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
stores a value associated with the key
@param string $key key to store value under
@param mixed $value data to store
@return \stubbles\webapp\session\Session
@throws \LogicException
|
[
"stores",
"a",
"value",
"associated",
"with",
"the",
"key"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/session/WebSession.php#L207-L215
|
blast-project/CoreBundle
|
src/Dashboard/DashboardSonataBlock.php
|
DashboardSonataBlock.execute
|
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$dashboardBlocks = $this->registry->getRegistredBlocks();
return $this->renderResponse($blockContext->getTemplate(), array(
'block_context' => $blockContext,
'block' => $blockContext->getBlock(),
'dashboard_blocks' => $dashboardBlocks ?: [],
), $response);
}
|
php
|
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$dashboardBlocks = $this->registry->getRegistredBlocks();
return $this->renderResponse($blockContext->getTemplate(), array(
'block_context' => $blockContext,
'block' => $blockContext->getBlock(),
'dashboard_blocks' => $dashboardBlocks ?: [],
), $response);
}
|
[
"public",
"function",
"execute",
"(",
"BlockContextInterface",
"$",
"blockContext",
",",
"Response",
"$",
"response",
"=",
"null",
")",
"{",
"$",
"dashboardBlocks",
"=",
"$",
"this",
"->",
"registry",
"->",
"getRegistredBlocks",
"(",
")",
";",
"return",
"$",
"this",
"->",
"renderResponse",
"(",
"$",
"blockContext",
"->",
"getTemplate",
"(",
")",
",",
"array",
"(",
"'block_context'",
"=>",
"$",
"blockContext",
",",
"'block'",
"=>",
"$",
"blockContext",
"->",
"getBlock",
"(",
")",
",",
"'dashboard_blocks'",
"=>",
"$",
"dashboardBlocks",
"?",
":",
"[",
"]",
",",
")",
",",
"$",
"response",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Dashboard/DashboardSonataBlock.php#L42-L51
|
huasituo/hstcms
|
src/Model/ManageMenuModel.php
|
ManageMenuModel.verifyMenuConfig
|
static function verifyMenuConfig($menus)
{
$menus = hstcms_hook('s_manage_menu', $menus, true);
$_menus = [];
foreach ($menus as $key => $menu)
{
if($menu['level'] == 1) {
$_menus[$key] = ['id'=>$key, 'name'=>$menu['name'], 'icon'=>$menu['icon'], 'parent'=>$menu['parent']];
} else {
if($menu['level'] == 2 && !$menu['url']) {
$_menus[$menu['parent']]['items'][$key] = ['id'=>$key, 'name'=>$menu['name'], 'parent'=>$menu['parent']];
} else if($menu['level'] == 3) {
if(!preg_match('|^http://|', $menu['url'])) {
$menu['url'] = route($menu['url']);
}
$_menus[$menu['parent']]['items'][$menu['parents']]['items'][$key] = ['id'=>$key, 'name'=>$menu['name'], 'parent'=>$menu['parent'], 'url'=>$menu['url']];
} else {
if(!preg_match('|^http://|', $menu['url'])) {
$menu['url'] = route($menu['url']);
}
$_menus[$menu['parent']]['items'][$key] = ['id'=>$key, 'name'=>$menu['name'], 'parent'=>$menu['parent'], 'url'=>$menu['url']];
}
}
}
return $_menus;
}
|
php
|
static function verifyMenuConfig($menus)
{
$menus = hstcms_hook('s_manage_menu', $menus, true);
$_menus = [];
foreach ($menus as $key => $menu)
{
if($menu['level'] == 1) {
$_menus[$key] = ['id'=>$key, 'name'=>$menu['name'], 'icon'=>$menu['icon'], 'parent'=>$menu['parent']];
} else {
if($menu['level'] == 2 && !$menu['url']) {
$_menus[$menu['parent']]['items'][$key] = ['id'=>$key, 'name'=>$menu['name'], 'parent'=>$menu['parent']];
} else if($menu['level'] == 3) {
if(!preg_match('|^http://|', $menu['url'])) {
$menu['url'] = route($menu['url']);
}
$_menus[$menu['parent']]['items'][$menu['parents']]['items'][$key] = ['id'=>$key, 'name'=>$menu['name'], 'parent'=>$menu['parent'], 'url'=>$menu['url']];
} else {
if(!preg_match('|^http://|', $menu['url'])) {
$menu['url'] = route($menu['url']);
}
$_menus[$menu['parent']]['items'][$key] = ['id'=>$key, 'name'=>$menu['name'], 'parent'=>$menu['parent'], 'url'=>$menu['url']];
}
}
}
return $_menus;
}
|
[
"static",
"function",
"verifyMenuConfig",
"(",
"$",
"menus",
")",
"{",
"$",
"menus",
"=",
"hstcms_hook",
"(",
"'s_manage_menu'",
",",
"$",
"menus",
",",
"true",
")",
";",
"$",
"_menus",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"menus",
"as",
"$",
"key",
"=>",
"$",
"menu",
")",
"{",
"if",
"(",
"$",
"menu",
"[",
"'level'",
"]",
"==",
"1",
")",
"{",
"$",
"_menus",
"[",
"$",
"key",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"key",
",",
"'name'",
"=>",
"$",
"menu",
"[",
"'name'",
"]",
",",
"'icon'",
"=>",
"$",
"menu",
"[",
"'icon'",
"]",
",",
"'parent'",
"=>",
"$",
"menu",
"[",
"'parent'",
"]",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"menu",
"[",
"'level'",
"]",
"==",
"2",
"&&",
"!",
"$",
"menu",
"[",
"'url'",
"]",
")",
"{",
"$",
"_menus",
"[",
"$",
"menu",
"[",
"'parent'",
"]",
"]",
"[",
"'items'",
"]",
"[",
"$",
"key",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"key",
",",
"'name'",
"=>",
"$",
"menu",
"[",
"'name'",
"]",
",",
"'parent'",
"=>",
"$",
"menu",
"[",
"'parent'",
"]",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"menu",
"[",
"'level'",
"]",
"==",
"3",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'|^http://|'",
",",
"$",
"menu",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"menu",
"[",
"'url'",
"]",
"=",
"route",
"(",
"$",
"menu",
"[",
"'url'",
"]",
")",
";",
"}",
"$",
"_menus",
"[",
"$",
"menu",
"[",
"'parent'",
"]",
"]",
"[",
"'items'",
"]",
"[",
"$",
"menu",
"[",
"'parents'",
"]",
"]",
"[",
"'items'",
"]",
"[",
"$",
"key",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"key",
",",
"'name'",
"=>",
"$",
"menu",
"[",
"'name'",
"]",
",",
"'parent'",
"=>",
"$",
"menu",
"[",
"'parent'",
"]",
",",
"'url'",
"=>",
"$",
"menu",
"[",
"'url'",
"]",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'|^http://|'",
",",
"$",
"menu",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"menu",
"[",
"'url'",
"]",
"=",
"route",
"(",
"$",
"menu",
"[",
"'url'",
"]",
")",
";",
"}",
"$",
"_menus",
"[",
"$",
"menu",
"[",
"'parent'",
"]",
"]",
"[",
"'items'",
"]",
"[",
"$",
"key",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"key",
",",
"'name'",
"=>",
"$",
"menu",
"[",
"'name'",
"]",
",",
"'parent'",
"=>",
"$",
"menu",
"[",
"'parent'",
"]",
",",
"'url'",
"=>",
"$",
"menu",
"[",
"'url'",
"]",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"_menus",
";",
"}"
] |
递归的方式调用,将复合的节点设置合并为单节点设置方式
@param array $menus
@return array
|
[
"递归的方式调用",
"将复合的节点设置合并为单节点设置方式"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Model/ManageMenuModel.php#L152-L177
|
huasituo/hstcms
|
src/Model/ManageMenuModel.php
|
ManageMenuModel.getMenu
|
static function getMenu($users = [])
{
$menuTables = self::getAll();
if ($users && $users['gid'] !== '99') {
$roleAuths = CommonRoleModel::getInfo($users['gid']);
$auths = isset($roleAuths['auths']) ? $roleAuths['auths'] : array();
foreach ($menuTables as $key => $value) {
if(isset($value['items']) && $value['items']) {
foreach ($value['items'] as $k => $val) {
if(isset($val['items']) && $val['items']) {
foreach ($val['items'] as $ks => $v) {
if (isset($v['url']) && !in_array($ks, (array) $auths)) {
unset($menuTables[$key]['items'][$k]['items'][$ks]);
}
}
} else if (isset($val['url']) && !in_array($k, (array) $auths)) {
unset($menuTables[$key]['items'][$k]);
}
}
} else {
unset($menuTables[$key]);
}
}
}
foreach ($menuTables as $key => $value) {
if (isset($value['items']) && empty($value['items'])) {
unset($menuTables[$key]);
} else if (isset($value['items']) && !$value['items']) {
unset($menuTables[$key]);
} else {
if(isset($value['items']) && $value['items']) {
foreach ($value['items'] as $k => $val) {
if (isset($val['items']) && empty($val['items'])) {
unset($menuTables[$key]['items'][$k]);
} else if ((!isset($val['items']) || !$val['items']) && !isset($val['url'])) {
unset($menuTables[$key]['items'][$k]);
}
}
}
}
}
foreach ($menuTables as $key => $value) {
if ((isset($value['items']) && empty($value['items'])) || (!isset($value['items']) || !$value['items'])) {
unset($menuTables[$key]);
}
}
return $menuTables;
}
|
php
|
static function getMenu($users = [])
{
$menuTables = self::getAll();
if ($users && $users['gid'] !== '99') {
$roleAuths = CommonRoleModel::getInfo($users['gid']);
$auths = isset($roleAuths['auths']) ? $roleAuths['auths'] : array();
foreach ($menuTables as $key => $value) {
if(isset($value['items']) && $value['items']) {
foreach ($value['items'] as $k => $val) {
if(isset($val['items']) && $val['items']) {
foreach ($val['items'] as $ks => $v) {
if (isset($v['url']) && !in_array($ks, (array) $auths)) {
unset($menuTables[$key]['items'][$k]['items'][$ks]);
}
}
} else if (isset($val['url']) && !in_array($k, (array) $auths)) {
unset($menuTables[$key]['items'][$k]);
}
}
} else {
unset($menuTables[$key]);
}
}
}
foreach ($menuTables as $key => $value) {
if (isset($value['items']) && empty($value['items'])) {
unset($menuTables[$key]);
} else if (isset($value['items']) && !$value['items']) {
unset($menuTables[$key]);
} else {
if(isset($value['items']) && $value['items']) {
foreach ($value['items'] as $k => $val) {
if (isset($val['items']) && empty($val['items'])) {
unset($menuTables[$key]['items'][$k]);
} else if ((!isset($val['items']) || !$val['items']) && !isset($val['url'])) {
unset($menuTables[$key]['items'][$k]);
}
}
}
}
}
foreach ($menuTables as $key => $value) {
if ((isset($value['items']) && empty($value['items'])) || (!isset($value['items']) || !$value['items'])) {
unset($menuTables[$key]);
}
}
return $menuTables;
}
|
[
"static",
"function",
"getMenu",
"(",
"$",
"users",
"=",
"[",
"]",
")",
"{",
"$",
"menuTables",
"=",
"self",
"::",
"getAll",
"(",
")",
";",
"if",
"(",
"$",
"users",
"&&",
"$",
"users",
"[",
"'gid'",
"]",
"!==",
"'99'",
")",
"{",
"$",
"roleAuths",
"=",
"CommonRoleModel",
"::",
"getInfo",
"(",
"$",
"users",
"[",
"'gid'",
"]",
")",
";",
"$",
"auths",
"=",
"isset",
"(",
"$",
"roleAuths",
"[",
"'auths'",
"]",
")",
"?",
"$",
"roleAuths",
"[",
"'auths'",
"]",
":",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"menuTables",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'items'",
"]",
")",
"&&",
"$",
"value",
"[",
"'items'",
"]",
")",
"{",
"foreach",
"(",
"$",
"value",
"[",
"'items'",
"]",
"as",
"$",
"k",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"val",
"[",
"'items'",
"]",
")",
"&&",
"$",
"val",
"[",
"'items'",
"]",
")",
"{",
"foreach",
"(",
"$",
"val",
"[",
"'items'",
"]",
"as",
"$",
"ks",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"v",
"[",
"'url'",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"ks",
",",
"(",
"array",
")",
"$",
"auths",
")",
")",
"{",
"unset",
"(",
"$",
"menuTables",
"[",
"$",
"key",
"]",
"[",
"'items'",
"]",
"[",
"$",
"k",
"]",
"[",
"'items'",
"]",
"[",
"$",
"ks",
"]",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"val",
"[",
"'url'",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"k",
",",
"(",
"array",
")",
"$",
"auths",
")",
")",
"{",
"unset",
"(",
"$",
"menuTables",
"[",
"$",
"key",
"]",
"[",
"'items'",
"]",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"unset",
"(",
"$",
"menuTables",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"menuTables",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'items'",
"]",
")",
"&&",
"empty",
"(",
"$",
"value",
"[",
"'items'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"menuTables",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'items'",
"]",
")",
"&&",
"!",
"$",
"value",
"[",
"'items'",
"]",
")",
"{",
"unset",
"(",
"$",
"menuTables",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'items'",
"]",
")",
"&&",
"$",
"value",
"[",
"'items'",
"]",
")",
"{",
"foreach",
"(",
"$",
"value",
"[",
"'items'",
"]",
"as",
"$",
"k",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"val",
"[",
"'items'",
"]",
")",
"&&",
"empty",
"(",
"$",
"val",
"[",
"'items'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"menuTables",
"[",
"$",
"key",
"]",
"[",
"'items'",
"]",
"[",
"$",
"k",
"]",
")",
";",
"}",
"else",
"if",
"(",
"(",
"!",
"isset",
"(",
"$",
"val",
"[",
"'items'",
"]",
")",
"||",
"!",
"$",
"val",
"[",
"'items'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"val",
"[",
"'url'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"menuTables",
"[",
"$",
"key",
"]",
"[",
"'items'",
"]",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"}",
"}",
"}",
"foreach",
"(",
"$",
"menuTables",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"isset",
"(",
"$",
"value",
"[",
"'items'",
"]",
")",
"&&",
"empty",
"(",
"$",
"value",
"[",
"'items'",
"]",
")",
")",
"||",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'items'",
"]",
")",
"||",
"!",
"$",
"value",
"[",
"'items'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"menuTables",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"menuTables",
";",
"}"
] |
======================================================================================================
|
[
"======================================================================================================"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Model/ManageMenuModel.php#L180-L227
|
sulu/SuluSalesShippingBundle
|
src/Sulu/Bundle/Sales/OrderBundle/Api/Order.php
|
Order.getDeliveryCostFormatted
|
public function getDeliveryCostFormatted($locale = null)
{
$formatter = $this->getFormatter($locale);
return $formatter->format((float)$this->entity->getDeliveryCost());
}
|
php
|
public function getDeliveryCostFormatted($locale = null)
{
$formatter = $this->getFormatter($locale);
return $formatter->format((float)$this->entity->getDeliveryCost());
}
|
[
"public",
"function",
"getDeliveryCostFormatted",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
"$",
"locale",
")",
";",
"return",
"$",
"formatter",
"->",
"format",
"(",
"(",
"float",
")",
"$",
"this",
"->",
"entity",
"->",
"getDeliveryCost",
"(",
")",
")",
";",
"}"
] |
@VirtualProperty
@SerializedName("deliveryCostFormatted")
@Groups({"Default","cart"})
@return string
|
[
"@VirtualProperty",
"@SerializedName",
"(",
"deliveryCostFormatted",
")",
"@Groups",
"(",
"{",
"Default",
"cart",
"}",
")"
] |
train
|
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Api/Order.php#L928-L933
|
sauls/helpers
|
src/Operation/StringOperation/TruncateHtml.php
|
TruncateHtml.setTruncateOperationMethod
|
public function setTruncateOperationMethod(string $truncateOperationMethod): void
{
if (!in_array($truncateOperationMethod, $this->truncateOperationMethods)) {
throw new \InvalidArgumentException(\sprintf('`%s` truncate operation method is not supported.',
$truncateOperationMethod));
}
$this->truncateOperationMethod = $truncateOperationMethod;
}
|
php
|
public function setTruncateOperationMethod(string $truncateOperationMethod): void
{
if (!in_array($truncateOperationMethod, $this->truncateOperationMethods)) {
throw new \InvalidArgumentException(\sprintf('`%s` truncate operation method is not supported.',
$truncateOperationMethod));
}
$this->truncateOperationMethod = $truncateOperationMethod;
}
|
[
"public",
"function",
"setTruncateOperationMethod",
"(",
"string",
"$",
"truncateOperationMethod",
")",
":",
"void",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"truncateOperationMethod",
",",
"$",
"this",
"->",
"truncateOperationMethods",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\\",
"sprintf",
"(",
"'`%s` truncate operation method is not supported.'",
",",
"$",
"truncateOperationMethod",
")",
")",
";",
"}",
"$",
"this",
"->",
"truncateOperationMethod",
"=",
"$",
"truncateOperationMethod",
";",
"}"
] |
@param string $truncateOperationMethod
@return TruncateHtml
|
[
"@param",
"string",
"$truncateOperationMethod"
] |
train
|
https://github.com/sauls/helpers/blob/de7dd250eb70ff10bada18acab8c7d8f27fad385/src/Operation/StringOperation/TruncateHtml.php#L161-L169
|
crossjoin/Css
|
src/Crossjoin/Css/Format/Rule/TraitConditions.php
|
TraitConditions.setConditions
|
public function setConditions($conditions)
{
$this->conditions = [];
if (!is_array($conditions)) {
$conditions = [$conditions];
}
foreach ($conditions as $condition) {
$this->addCondition($condition);
}
return $this;
}
|
php
|
public function setConditions($conditions)
{
$this->conditions = [];
if (!is_array($conditions)) {
$conditions = [$conditions];
}
foreach ($conditions as $condition) {
$this->addCondition($condition);
}
return $this;
}
|
[
"public",
"function",
"setConditions",
"(",
"$",
"conditions",
")",
"{",
"$",
"this",
"->",
"conditions",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"conditions",
"=",
"[",
"$",
"conditions",
"]",
";",
"}",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"condition",
")",
"{",
"$",
"this",
"->",
"addCondition",
"(",
"$",
"condition",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the conditions.
@param ConditionAbstract[]|ConditionAbstract $conditions
@return $this
|
[
"Sets",
"the",
"conditions",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/TraitConditions.php#L17-L28
|
gbprod/elastica-provider-bundle
|
src/ElasticaProviderBundle/Command/ProvideCommand.php
|
ProvideCommand.execute
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$client = $this->getClient($input->getOption('client'));
$index = $input->getArgument('index');
$type = $input->getArgument('type');
$alias = (null !== $index) ? $input->getOption('alias') : null; // alias usage only if index is set
$output->writeln(sprintf(
'<info>Providing <comment>%s/%s</comment> for client <comment>%s</comment></info>',
$index ?: '*',
$type ?: '*',
$input->getOption('client')
));
$this->initializeProgress($output);
$this->handler->handle($client, $index, $type, $alias);
}
|
php
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$client = $this->getClient($input->getOption('client'));
$index = $input->getArgument('index');
$type = $input->getArgument('type');
$alias = (null !== $index) ? $input->getOption('alias') : null; // alias usage only if index is set
$output->writeln(sprintf(
'<info>Providing <comment>%s/%s</comment> for client <comment>%s</comment></info>',
$index ?: '*',
$type ?: '*',
$input->getOption('client')
));
$this->initializeProgress($output);
$this->handler->handle($client, $index, $type, $alias);
}
|
[
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"client",
"=",
"$",
"this",
"->",
"getClient",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'client'",
")",
")",
";",
"$",
"index",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'index'",
")",
";",
"$",
"type",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'type'",
")",
";",
"$",
"alias",
"=",
"(",
"null",
"!==",
"$",
"index",
")",
"?",
"$",
"input",
"->",
"getOption",
"(",
"'alias'",
")",
":",
"null",
";",
"// alias usage only if index is set",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>Providing <comment>%s/%s</comment> for client <comment>%s</comment></info>'",
",",
"$",
"index",
"?",
":",
"'*'",
",",
"$",
"type",
"?",
":",
"'*'",
",",
"$",
"input",
"->",
"getOption",
"(",
"'client'",
")",
")",
")",
";",
"$",
"this",
"->",
"initializeProgress",
"(",
"$",
"output",
")",
";",
"$",
"this",
"->",
"handler",
"->",
"handle",
"(",
"$",
"client",
",",
"$",
"index",
",",
"$",
"type",
",",
"$",
"alias",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/gbprod/elastica-provider-bundle/blob/ee1e2ca78651d570b7400049bf81d8405fc744fc/src/ElasticaProviderBundle/Command/ProvideCommand.php#L63-L81
|
gbprod/elastica-provider-bundle
|
src/ElasticaProviderBundle/Command/ProvideCommand.php
|
ProvideCommand.getClient
|
private function getClient($clientName)
{
$clientName = $clientName ?: 'gbprod.elastica_provider.default_client';
$client = $this->getContainer()
->get($clientName, ContainerInterface::NULL_ON_INVALID_REFERENCE)
;
if (!$client) {
throw new \InvalidArgumentException(sprintf(
'No client "%s" found',
$clientName
));
}
return $client;
}
|
php
|
private function getClient($clientName)
{
$clientName = $clientName ?: 'gbprod.elastica_provider.default_client';
$client = $this->getContainer()
->get($clientName, ContainerInterface::NULL_ON_INVALID_REFERENCE)
;
if (!$client) {
throw new \InvalidArgumentException(sprintf(
'No client "%s" found',
$clientName
));
}
return $client;
}
|
[
"private",
"function",
"getClient",
"(",
"$",
"clientName",
")",
"{",
"$",
"clientName",
"=",
"$",
"clientName",
"?",
":",
"'gbprod.elastica_provider.default_client'",
";",
"$",
"client",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"$",
"clientName",
",",
"ContainerInterface",
"::",
"NULL_ON_INVALID_REFERENCE",
")",
";",
"if",
"(",
"!",
"$",
"client",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No client \"%s\" found'",
",",
"$",
"clientName",
")",
")",
";",
"}",
"return",
"$",
"client",
";",
"}"
] |
@param string $clientName
@return Client
|
[
"@param",
"string",
"$clientName"
] |
train
|
https://github.com/gbprod/elastica-provider-bundle/blob/ee1e2ca78651d570b7400049bf81d8405fc744fc/src/ElasticaProviderBundle/Command/ProvideCommand.php#L88-L104
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.listSources
|
public static function listSources(DataSift_User $user, $page = 1, $perPage = 25, $sourceType = false)
{
try {
$params = array(
'page' => $page,
'per_page' => $perPage,
);
if ($sourceType !== false) {
$params['source_type'] = $sourceType;
}
$res = $user->post(
'source/get',
$params
);
$retval = array('count' => $res['count'], 'sources' => array());
foreach ($res['sources'] as $source) {
$retval['sources'][] = new self($user, $source);
}
return $retval;
} catch (DataSift_Exception_APIError $e) {
switch ($e->getCode()) {
case 400:
// Missing or invalid parameters
throw new DataSift_Exception_InvalidData($e->getMessage());
default:
throw new DataSift_Exception_APIError(
'Unexpected APIError code: ' . $e->getCode() . ' [' . $e->getMessage() . ']'
);
}
}
}
|
php
|
public static function listSources(DataSift_User $user, $page = 1, $perPage = 25, $sourceType = false)
{
try {
$params = array(
'page' => $page,
'per_page' => $perPage,
);
if ($sourceType !== false) {
$params['source_type'] = $sourceType;
}
$res = $user->post(
'source/get',
$params
);
$retval = array('count' => $res['count'], 'sources' => array());
foreach ($res['sources'] as $source) {
$retval['sources'][] = new self($user, $source);
}
return $retval;
} catch (DataSift_Exception_APIError $e) {
switch ($e->getCode()) {
case 400:
// Missing or invalid parameters
throw new DataSift_Exception_InvalidData($e->getMessage());
default:
throw new DataSift_Exception_APIError(
'Unexpected APIError code: ' . $e->getCode() . ' [' . $e->getMessage() . ']'
);
}
}
}
|
[
"public",
"static",
"function",
"listSources",
"(",
"DataSift_User",
"$",
"user",
",",
"$",
"page",
"=",
"1",
",",
"$",
"perPage",
"=",
"25",
",",
"$",
"sourceType",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"params",
"=",
"array",
"(",
"'page'",
"=>",
"$",
"page",
",",
"'per_page'",
"=>",
"$",
"perPage",
",",
")",
";",
"if",
"(",
"$",
"sourceType",
"!==",
"false",
")",
"{",
"$",
"params",
"[",
"'source_type'",
"]",
"=",
"$",
"sourceType",
";",
"}",
"$",
"res",
"=",
"$",
"user",
"->",
"post",
"(",
"'source/get'",
",",
"$",
"params",
")",
";",
"$",
"retval",
"=",
"array",
"(",
"'count'",
"=>",
"$",
"res",
"[",
"'count'",
"]",
",",
"'sources'",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"res",
"[",
"'sources'",
"]",
"as",
"$",
"source",
")",
"{",
"$",
"retval",
"[",
"'sources'",
"]",
"[",
"]",
"=",
"new",
"self",
"(",
"$",
"user",
",",
"$",
"source",
")",
";",
"}",
"return",
"$",
"retval",
";",
"}",
"catch",
"(",
"DataSift_Exception_APIError",
"$",
"e",
")",
"{",
"switch",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
"{",
"case",
"400",
":",
"// Missing or invalid parameters",
"throw",
"new",
"DataSift_Exception_InvalidData",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"default",
":",
"throw",
"new",
"DataSift_Exception_APIError",
"(",
"'Unexpected APIError code: '",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' ['",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"']'",
")",
";",
"}",
"}",
"}"
] |
Gets a page of Sources where each page contains up to $perPage items.
@param DataSift_User $user The user making the request.
@param integer $page The page number to fetch.
@param integer $perPage The number of items per page.
@param string|false $sourceType The type of source to filter by; false for no filter
@return array An array containing the number of sources returned in 'count'
and a list of DataSift_Sources in 'sources'
@throws DataSift_Exception_InvalidData
@throws DataSift_Exception_APIError
|
[
"Gets",
"a",
"page",
"of",
"Sources",
"where",
"each",
"page",
"contains",
"up",
"to",
"$perPage",
"items",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L56-L92
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.get
|
public static function get(DataSift_User $user, $id)
{
$params = array('id' => $id);
return new self($user, $user->post('source/get', $params));
}
|
php
|
public static function get(DataSift_User $user, $id)
{
$params = array('id' => $id);
return new self($user, $user->post('source/get', $params));
}
|
[
"public",
"static",
"function",
"get",
"(",
"DataSift_User",
"$",
"user",
",",
"$",
"id",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
";",
"return",
"new",
"self",
"(",
"$",
"user",
",",
"$",
"user",
"->",
"post",
"(",
"'source/get'",
",",
"$",
"params",
")",
")",
";",
"}"
] |
Gets a single DataSift_Source object by ID
@param DataSift_User $user The user making the request.
@param string $id The id of the Source to fetch
@return DataSift_Source
@throws DataSift_Exception_APIError
@throws DataSift_Exception_AccessDenied
|
[
"Gets",
"a",
"single",
"DataSift_Source",
"object",
"by",
"ID"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L105-L109
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.addAuth
|
public function addAuth(array $auth, $validate = false)
{
$response = $this->getUser()->post(
'source/auth/add',
array('id' => $this->getId(), 'auth' => $auth, 'validate' => $validate)
);
$this->auth = $response['auth'];
}
|
php
|
public function addAuth(array $auth, $validate = false)
{
$response = $this->getUser()->post(
'source/auth/add',
array('id' => $this->getId(), 'auth' => $auth, 'validate' => $validate)
);
$this->auth = $response['auth'];
}
|
[
"public",
"function",
"addAuth",
"(",
"array",
"$",
"auth",
",",
"$",
"validate",
"=",
"false",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"post",
"(",
"'source/auth/add'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'auth'",
"=>",
"$",
"auth",
",",
"'validate'",
"=>",
"$",
"validate",
")",
")",
";",
"$",
"this",
"->",
"auth",
"=",
"$",
"response",
"[",
"'auth'",
"]",
";",
"}"
] |
Adds authorization credentials for this DataSift_Source using the auth/add
@param array $auth An array of authorization credentials, appropriate to
the Source type
|
[
"Adds",
"authorization",
"credentials",
"for",
"this",
"DataSift_Source",
"using",
"the",
"auth",
"/",
"add"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L305-L313
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.removeAuth
|
public function removeAuth(array $authIds)
{
$response = $this->getUser()->post(
'source/auth/remove',
array('id' => $this->getId(), 'auth_ids' => $authIds)
);
$this->auth = $response['auth'];
}
|
php
|
public function removeAuth(array $authIds)
{
$response = $this->getUser()->post(
'source/auth/remove',
array('id' => $this->getId(), 'auth_ids' => $authIds)
);
$this->auth = $response['auth'];
}
|
[
"public",
"function",
"removeAuth",
"(",
"array",
"$",
"authIds",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"post",
"(",
"'source/auth/remove'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'auth_ids'",
"=>",
"$",
"authIds",
")",
")",
";",
"$",
"this",
"->",
"auth",
"=",
"$",
"response",
"[",
"'auth'",
"]",
";",
"}"
] |
Removes authorization credentials for this DataSift_Source using the auth/remove
@param array $authIds An array of authorization IDs to be removed
|
[
"Removes",
"authorization",
"credentials",
"for",
"this",
"DataSift_Source",
"using",
"the",
"auth",
"/",
"remove"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L320-L328
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.addResource
|
public function addResource(array $resources, $validate = false)
{
$response = $this->getUser()->post(
'source/resource/add',
array('id' => $this->getId(), 'resources' => $resources, 'validate' => $validate)
);
$this->resources = $response['resources'];
}
|
php
|
public function addResource(array $resources, $validate = false)
{
$response = $this->getUser()->post(
'source/resource/add',
array('id' => $this->getId(), 'resources' => $resources, 'validate' => $validate)
);
$this->resources = $response['resources'];
}
|
[
"public",
"function",
"addResource",
"(",
"array",
"$",
"resources",
",",
"$",
"validate",
"=",
"false",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"post",
"(",
"'source/resource/add'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'resources'",
"=>",
"$",
"resources",
",",
"'validate'",
"=>",
"$",
"validate",
")",
")",
";",
"$",
"this",
"->",
"resources",
"=",
"$",
"response",
"[",
"'resources'",
"]",
";",
"}"
] |
Adds resources for this DataSift_Source using the resource/add
@param array $resources An array of authorization credentials, appropriate to
the Source type
@param boolean validate Validate the resource
|
[
"Adds",
"resources",
"for",
"this",
"DataSift_Source",
"using",
"the",
"resource",
"/",
"add"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L358-L366
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.removeResource
|
public function removeResource(array $resourceIds)
{
$response = $this->getUser()->post(
'source/resource/remove',
array('id' => $this->getId(), 'resource_ids' => $resourceIds)
);
$this->resources = $response['resources'];
}
|
php
|
public function removeResource(array $resourceIds)
{
$response = $this->getUser()->post(
'source/resource/remove',
array('id' => $this->getId(), 'resource_ids' => $resourceIds)
);
$this->resources = $response['resources'];
}
|
[
"public",
"function",
"removeResource",
"(",
"array",
"$",
"resourceIds",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"post",
"(",
"'source/resource/remove'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'resource_ids'",
"=>",
"$",
"resourceIds",
")",
")",
";",
"$",
"this",
"->",
"resources",
"=",
"$",
"response",
"[",
"'resources'",
"]",
";",
"}"
] |
Removes resources for this DataSift_Source using the resource/remove
@param array $resourceIds An array of resource IDs to be removed
|
[
"Removes",
"resources",
"for",
"this",
"DataSift_Source",
"using",
"the",
"resource",
"/",
"remove"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L373-L381
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.save
|
public function save($validate = true)
{
if ($this->getValidate() != $validate) {
$this->setValidate($validate);
}
$endpoint = ($this->getId() ? 'source/update' : 'source/create');
$this->fromArray($this->getUser()->post($endpoint, $this->toArray()));
return $this;
}
|
php
|
public function save($validate = true)
{
if ($this->getValidate() != $validate) {
$this->setValidate($validate);
}
$endpoint = ($this->getId() ? 'source/update' : 'source/create');
$this->fromArray($this->getUser()->post($endpoint, $this->toArray()));
return $this;
}
|
[
"public",
"function",
"save",
"(",
"$",
"validate",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getValidate",
"(",
")",
"!=",
"$",
"validate",
")",
"{",
"$",
"this",
"->",
"setValidate",
"(",
"$",
"validate",
")",
";",
"}",
"$",
"endpoint",
"=",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
"?",
"'source/update'",
":",
"'source/create'",
")",
";",
"$",
"this",
"->",
"fromArray",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"post",
"(",
"$",
"endpoint",
",",
"$",
"this",
"->",
"toArray",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Save this Source
@param boolean $validate
@return DataSift_Source
@throws DataSift_Exception_APIError
@throws DataSift_Exception_AccessDenied
|
[
"Save",
"this",
"Source"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L453-L463
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.delete
|
public function delete()
{
$this->getUser()->post('source/delete', array('id' => $this->getId()));
$this->setStatus(self::STATUS_DELETED);
return $this;
}
|
php
|
public function delete()
{
$this->getUser()->post('source/delete', array('id' => $this->getId()));
$this->setStatus(self::STATUS_DELETED);
return $this;
}
|
[
"public",
"function",
"delete",
"(",
")",
"{",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"post",
"(",
"'source/delete'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"setStatus",
"(",
"self",
"::",
"STATUS_DELETED",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Delete this Source.
@return DataSift_Source
@throws DataSift_Exception_APIError
@throws DataSift_Exception_AccessDenied
|
[
"Delete",
"this",
"Source",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L501-L507
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.getLogs
|
public function getLogs($page = 1, $perPage = 20)
{
return $this->getUser()->post(
'source/log',
array('id' => $this->getId(), 'page' => $page, 'per_page' => $perPage)
);
}
|
php
|
public function getLogs($page = 1, $perPage = 20)
{
return $this->getUser()->post(
'source/log',
array('id' => $this->getId(), 'page' => $page, 'per_page' => $perPage)
);
}
|
[
"public",
"function",
"getLogs",
"(",
"$",
"page",
"=",
"1",
",",
"$",
"perPage",
"=",
"20",
")",
"{",
"return",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"post",
"(",
"'source/log'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'page'",
"=>",
"$",
"page",
",",
"'per_page'",
"=>",
"$",
"perPage",
")",
")",
";",
"}"
] |
Returns the logs for this source
@return array
@param integer $page
@param integer $perPage
|
[
"Returns",
"the",
"logs",
"for",
"this",
"source"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L518-L524
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.fromArray
|
public function fromArray(array $data)
{
$map = array(
'id' => 'setId',
'name' => 'setName',
'source_type' => 'setSourceType',
'status' => 'setStatus',
'parameters' => 'setParameters',
'auth' => 'setAuth',
'resources' => 'setResources',
'created_at' => 'setCreatedAt',
'validate' => 'setValidate'
);
foreach ($map as $key => $setter) {
if (isset($data[$key])) {
$this->$setter($data[$key]);
}
}
return $this;
}
|
php
|
public function fromArray(array $data)
{
$map = array(
'id' => 'setId',
'name' => 'setName',
'source_type' => 'setSourceType',
'status' => 'setStatus',
'parameters' => 'setParameters',
'auth' => 'setAuth',
'resources' => 'setResources',
'created_at' => 'setCreatedAt',
'validate' => 'setValidate'
);
foreach ($map as $key => $setter) {
if (isset($data[$key])) {
$this->$setter($data[$key]);
}
}
return $this;
}
|
[
"public",
"function",
"fromArray",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"map",
"=",
"array",
"(",
"'id'",
"=>",
"'setId'",
",",
"'name'",
"=>",
"'setName'",
",",
"'source_type'",
"=>",
"'setSourceType'",
",",
"'status'",
"=>",
"'setStatus'",
",",
"'parameters'",
"=>",
"'setParameters'",
",",
"'auth'",
"=>",
"'setAuth'",
",",
"'resources'",
"=>",
"'setResources'",
",",
"'created_at'",
"=>",
"'setCreatedAt'",
",",
"'validate'",
"=>",
"'setValidate'",
")",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"key",
"=>",
"$",
"setter",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"$",
"setter",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Hydrates this Source from an array of API responses
@param array $data
@return DataSift_Source
|
[
"Hydrates",
"this",
"Source",
"from",
"an",
"array",
"of",
"API",
"responses"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L533-L554
|
datasift/datasift-php
|
lib/DataSift/Source.php
|
DataSift_Source.toArray
|
public function toArray()
{
$data = array();
$map = array(
'id' => 'getId',
'name' => 'getName',
'source_type' => 'getSourceType',
'status' => 'getStatus',
'parameters' => 'getParameters',
'auth' => 'getAuth',
'resources' => 'getResources',
'created_at' => 'getCreatedAt',
'validate' => 'getValidate'
);
foreach ($map as $key => $getter) {
$data[$key] = $this->$getter();
}
foreach (array('auth', 'resources', 'parameters') as $key) {
if (isset($data[$key])) {
$data[$key] = json_encode($data[$key]);
}
}
return $data;
}
|
php
|
public function toArray()
{
$data = array();
$map = array(
'id' => 'getId',
'name' => 'getName',
'source_type' => 'getSourceType',
'status' => 'getStatus',
'parameters' => 'getParameters',
'auth' => 'getAuth',
'resources' => 'getResources',
'created_at' => 'getCreatedAt',
'validate' => 'getValidate'
);
foreach ($map as $key => $getter) {
$data[$key] = $this->$getter();
}
foreach (array('auth', 'resources', 'parameters') as $key) {
if (isset($data[$key])) {
$data[$key] = json_encode($data[$key]);
}
}
return $data;
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"map",
"=",
"array",
"(",
"'id'",
"=>",
"'getId'",
",",
"'name'",
"=>",
"'getName'",
",",
"'source_type'",
"=>",
"'getSourceType'",
",",
"'status'",
"=>",
"'getStatus'",
",",
"'parameters'",
"=>",
"'getParameters'",
",",
"'auth'",
"=>",
"'getAuth'",
",",
"'resources'",
"=>",
"'getResources'",
",",
"'created_at'",
"=>",
"'getCreatedAt'",
",",
"'validate'",
"=>",
"'getValidate'",
")",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"key",
"=>",
"$",
"getter",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
";",
"}",
"foreach",
"(",
"array",
"(",
"'auth'",
",",
"'resources'",
",",
"'parameters'",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"json_encode",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Converts this Source to an array suitable for transmission to the API
@return array
|
[
"Converts",
"this",
"Source",
"to",
"an",
"array",
"suitable",
"for",
"transmission",
"to",
"the",
"API"
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Source.php#L561-L587
|
fuelphp/display
|
src/Parser/Handlebars.php
|
Handlebars.setupEngine
|
protected function setupEngine()
{
$this->engine = new HandlebarsEngine;
$loader = new HandlebarsLoader($this->viewManager);
$partialLoader = new HandlebarsLoader($this->viewManager);
$partialLoader->setPrefix('_');
$this->engine->setLoader($loader);
$this->engine->setPartialsLoader($partialLoader);
}
|
php
|
protected function setupEngine()
{
$this->engine = new HandlebarsEngine;
$loader = new HandlebarsLoader($this->viewManager);
$partialLoader = new HandlebarsLoader($this->viewManager);
$partialLoader->setPrefix('_');
$this->engine->setLoader($loader);
$this->engine->setPartialsLoader($partialLoader);
}
|
[
"protected",
"function",
"setupEngine",
"(",
")",
"{",
"$",
"this",
"->",
"engine",
"=",
"new",
"HandlebarsEngine",
";",
"$",
"loader",
"=",
"new",
"HandlebarsLoader",
"(",
"$",
"this",
"->",
"viewManager",
")",
";",
"$",
"partialLoader",
"=",
"new",
"HandlebarsLoader",
"(",
"$",
"this",
"->",
"viewManager",
")",
";",
"$",
"partialLoader",
"->",
"setPrefix",
"(",
"'_'",
")",
";",
"$",
"this",
"->",
"engine",
"->",
"setLoader",
"(",
"$",
"loader",
")",
";",
"$",
"this",
"->",
"engine",
"->",
"setPartialsLoader",
"(",
"$",
"partialLoader",
")",
";",
"}"
] |
Sets HandlebarsEngine up
|
[
"Sets",
"HandlebarsEngine",
"up"
] |
train
|
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/Parser/Handlebars.php#L51-L62
|
movoin/one-swoole
|
src/Swoole/Commands/RunCommand.php
|
RunCommand.configure
|
protected function configure()
{
$this
->setName('server:run')
->addArgument('cmd', InputArgument::REQUIRED, 'Server command')
->addArgument('server', InputArgument::REQUIRED, 'Server process name')
->setHidden(true)
;
}
|
php
|
protected function configure()
{
$this
->setName('server:run')
->addArgument('cmd', InputArgument::REQUIRED, 'Server command')
->addArgument('server', InputArgument::REQUIRED, 'Server process name')
->setHidden(true)
;
}
|
[
"protected",
"function",
"configure",
"(",
")",
"{",
"$",
"this",
"->",
"setName",
"(",
"'server:run'",
")",
"->",
"addArgument",
"(",
"'cmd'",
",",
"InputArgument",
"::",
"REQUIRED",
",",
"'Server command'",
")",
"->",
"addArgument",
"(",
"'server'",
",",
"InputArgument",
"::",
"REQUIRED",
",",
"'Server process name'",
")",
"->",
"setHidden",
"(",
"true",
")",
";",
"}"
] |
配置命令
|
[
"配置命令"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Commands/RunCommand.php#L28-L36
|
movoin/one-swoole
|
src/Swoole/Commands/RunCommand.php
|
RunCommand.execute
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$cmd = $input->getArgument('cmd');
$process = $input->getArgument('server');
$server = new Server(
Config::get('name'),
$process
);
$server->$cmd();
}
|
php
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$cmd = $input->getArgument('cmd');
$process = $input->getArgument('server');
$server = new Server(
Config::get('name'),
$process
);
$server->$cmd();
}
|
[
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"cmd",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'cmd'",
")",
";",
"$",
"process",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'server'",
")",
";",
"$",
"server",
"=",
"new",
"Server",
"(",
"Config",
"::",
"get",
"(",
"'name'",
")",
",",
"$",
"process",
")",
";",
"$",
"server",
"->",
"$",
"cmd",
"(",
")",
";",
"}"
] |
执行命令
@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
|
[
"执行命令"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Commands/RunCommand.php#L44-L55
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Map/LoginLogTableMap.php
|
LoginLogTableMap.buildTableMap
|
public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(LoginLogTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(LoginLogTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new LoginLogTableMap());
}
}
|
php
|
public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(LoginLogTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(LoginLogTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new LoginLogTableMap());
}
}
|
[
"public",
"static",
"function",
"buildTableMap",
"(",
")",
"{",
"$",
"dbMap",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getDatabaseMap",
"(",
"LoginLogTableMap",
"::",
"DATABASE_NAME",
")",
";",
"if",
"(",
"!",
"$",
"dbMap",
"->",
"hasTable",
"(",
"LoginLogTableMap",
"::",
"TABLE_NAME",
")",
")",
"{",
"$",
"dbMap",
"->",
"addTableObject",
"(",
"new",
"LoginLogTableMap",
"(",
")",
")",
";",
"}",
"}"
] |
Add a TableMap instance to the database for this tableMap class.
|
[
"Add",
"a",
"TableMap",
"instance",
"to",
"the",
"database",
"for",
"this",
"tableMap",
"class",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Map/LoginLogTableMap.php#L374-L380
|
goblindegook/Syllables
|
src/Template/Loader.php
|
Loader.filter
|
public function filter( $template ) {
$this->_prepare_filter();
return $this->_should_load_template() ? $this->_get_template( $template ) : $template;
}
|
php
|
public function filter( $template ) {
$this->_prepare_filter();
return $this->_should_load_template() ? $this->_get_template( $template ) : $template;
}
|
[
"public",
"function",
"filter",
"(",
"$",
"template",
")",
"{",
"$",
"this",
"->",
"_prepare_filter",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_should_load_template",
"(",
")",
"?",
"$",
"this",
"->",
"_get_template",
"(",
"$",
"template",
")",
":",
"$",
"template",
";",
"}"
] |
Filters a template file path and replaces it with a template provided by the
plugin.
@param string $template Full path to the default template file.
@return string Filtered full path to template file
@access public
@see http://codex.wordpress.org/Plugin_API/Filter_Reference/template_include
|
[
"Filters",
"a",
"template",
"file",
"path",
"and",
"replaces",
"it",
"with",
"a",
"template",
"provided",
"by",
"the",
"plugin",
"."
] |
train
|
https://github.com/goblindegook/Syllables/blob/1a98cd15e37595a85b242242f88fee38c4e36acc/src/Template/Loader.php#L57-L60
|
goblindegook/Syllables
|
src/Template/Loader.php
|
Loader._get_template
|
private function _get_template( $fallback = '' ) {
$templates = $this->_templates();
foreach ( $templates as $template ) {
if ( file_exists( $template ) ) {
return $template;
}
}
return $fallback;
}
|
php
|
private function _get_template( $fallback = '' ) {
$templates = $this->_templates();
foreach ( $templates as $template ) {
if ( file_exists( $template ) ) {
return $template;
}
}
return $fallback;
}
|
[
"private",
"function",
"_get_template",
"(",
"$",
"fallback",
"=",
"''",
")",
"{",
"$",
"templates",
"=",
"$",
"this",
"->",
"_templates",
"(",
")",
";",
"foreach",
"(",
"$",
"templates",
"as",
"$",
"template",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"template",
")",
")",
"{",
"return",
"$",
"template",
";",
"}",
"}",
"return",
"$",
"fallback",
";",
"}"
] |
Returns the first valid template out of a list of candidates, otherwise
picks the fallback provided (if any).
@param string $fallback Fallback template (defaults to empty).
@return string Valid template or empty string.
@codeCoverageIgnore
|
[
"Returns",
"the",
"first",
"valid",
"template",
"out",
"of",
"a",
"list",
"of",
"candidates",
"otherwise",
"picks",
"the",
"fallback",
"provided",
"(",
"if",
"any",
")",
"."
] |
train
|
https://github.com/goblindegook/Syllables/blob/1a98cd15e37595a85b242242f88fee38c4e36acc/src/Template/Loader.php#L71-L81
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Console/Commands/CustomPostTypeMakeCommand.php
|
CustomPostTypeMakeCommand.replaceClass
|
protected function replaceClass($stub, $name)
{
$stub = parent::replaceClass($stub, $name);
$type = basename(str_replace('\\', '/', strtolower($name)));
if ($this->option('type')) {
$type = $this->option('type');
}
return str_replace('dummy_type', $type, $stub);
}
|
php
|
protected function replaceClass($stub, $name)
{
$stub = parent::replaceClass($stub, $name);
$type = basename(str_replace('\\', '/', strtolower($name)));
if ($this->option('type')) {
$type = $this->option('type');
}
return str_replace('dummy_type', $type, $stub);
}
|
[
"protected",
"function",
"replaceClass",
"(",
"$",
"stub",
",",
"$",
"name",
")",
"{",
"$",
"stub",
"=",
"parent",
"::",
"replaceClass",
"(",
"$",
"stub",
",",
"$",
"name",
")",
";",
"$",
"type",
"=",
"basename",
"(",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"strtolower",
"(",
"$",
"name",
")",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'type'",
")",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"option",
"(",
"'type'",
")",
";",
"}",
"return",
"str_replace",
"(",
"'dummy_type'",
",",
"$",
"type",
",",
"$",
"stub",
")",
";",
"}"
] |
Replace the class name for the given stub.
@param string $stub
@param string $name
@return string
|
[
"Replace",
"the",
"class",
"name",
"for",
"the",
"given",
"stub",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Console/Commands/CustomPostTypeMakeCommand.php#L39-L49
|
mayoturis/properties-ini
|
src/RepositoryFactory.php
|
RepositoryFactory.make
|
public static function make($filePath) {
$variableProcessor = new VariableProcessor();
$fileSaver = new FileSaver($variableProcessor);
$fileLoader = new FileLoader($variableProcessor);
return new Repository($fileLoader, $fileSaver, $filePath);
}
|
php
|
public static function make($filePath) {
$variableProcessor = new VariableProcessor();
$fileSaver = new FileSaver($variableProcessor);
$fileLoader = new FileLoader($variableProcessor);
return new Repository($fileLoader, $fileSaver, $filePath);
}
|
[
"public",
"static",
"function",
"make",
"(",
"$",
"filePath",
")",
"{",
"$",
"variableProcessor",
"=",
"new",
"VariableProcessor",
"(",
")",
";",
"$",
"fileSaver",
"=",
"new",
"FileSaver",
"(",
"$",
"variableProcessor",
")",
";",
"$",
"fileLoader",
"=",
"new",
"FileLoader",
"(",
"$",
"variableProcessor",
")",
";",
"return",
"new",
"Repository",
"(",
"$",
"fileLoader",
",",
"$",
"fileSaver",
",",
"$",
"filePath",
")",
";",
"}"
] |
Create repository instance
@param string $filePath File where configuration is stored
@return Repository
|
[
"Create",
"repository",
"instance"
] |
train
|
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/RepositoryFactory.php#L11-L18
|
blackprism/serializer
|
src/Blackprism/Serializer/Configuration/Blackhole.php
|
Blackhole.attributeUseObject
|
public function attributeUseObject(
string $attribute,
Value\ClassName $className,
string $setter,
string $getter
): ObjectInterface {
return $this;
}
|
php
|
public function attributeUseObject(
string $attribute,
Value\ClassName $className,
string $setter,
string $getter
): ObjectInterface {
return $this;
}
|
[
"public",
"function",
"attributeUseObject",
"(",
"string",
"$",
"attribute",
",",
"Value",
"\\",
"ClassName",
"$",
"className",
",",
"string",
"$",
"setter",
",",
"string",
"$",
"getter",
")",
":",
"ObjectInterface",
"{",
"return",
"$",
"this",
";",
"}"
] |
@param string $attribute
@param Value\ClassName $className
@param string $setter
@param string $getter
@return ObjectInterface
|
[
"@param",
"string",
"$attribute",
"@param",
"Value",
"\\",
"ClassName",
"$className",
"@param",
"string",
"$setter",
"@param",
"string",
"$getter"
] |
train
|
https://github.com/blackprism/serializer/blob/f5bd6ebeec802d2ad747daba7c9211b252ee4776/src/Blackprism/Serializer/Configuration/Blackhole.php#L52-L59
|
blackprism/serializer
|
src/Blackprism/Serializer/Configuration/Blackhole.php
|
Blackhole.attributeUseHandler
|
public function attributeUseHandler(
string $attribute,
Type\HandlerDeserializerInterface $deserialize,
Type\HandlerSerializerInterface $serialize
): ObjectInterface {
return $this;
}
|
php
|
public function attributeUseHandler(
string $attribute,
Type\HandlerDeserializerInterface $deserialize,
Type\HandlerSerializerInterface $serialize
): ObjectInterface {
return $this;
}
|
[
"public",
"function",
"attributeUseHandler",
"(",
"string",
"$",
"attribute",
",",
"Type",
"\\",
"HandlerDeserializerInterface",
"$",
"deserialize",
",",
"Type",
"\\",
"HandlerSerializerInterface",
"$",
"serialize",
")",
":",
"ObjectInterface",
"{",
"return",
"$",
"this",
";",
"}"
] |
@param string $attribute
@param Type\HandlerDeserializerInterface $deserialize
@param Type\HandlerSerializerInterface $serialize
@return ObjectInterface
|
[
"@param",
"string",
"$attribute",
"@param",
"Type",
"\\",
"HandlerDeserializerInterface",
"$deserialize",
"@param",
"Type",
"\\",
"HandlerSerializerInterface",
"$serialize"
] |
train
|
https://github.com/blackprism/serializer/blob/f5bd6ebeec802d2ad747daba7c9211b252ee4776/src/Blackprism/Serializer/Configuration/Blackhole.php#L112-L118
|
gdbots/pbjx-bundle-php
|
src/EventListener/EnvelopeListener.php
|
EnvelopeListener.redactErrorMessage
|
private function redactErrorMessage(Envelope $envelope, Request $request): string
{
try {
$code = Code::create($envelope->get('code'))->getName();
} catch (\Throwable $e) {
$code = $envelope->get('code');
}
return sprintf('Your message could not be handled (Code:%s).', $code);
}
|
php
|
private function redactErrorMessage(Envelope $envelope, Request $request): string
{
try {
$code = Code::create($envelope->get('code'))->getName();
} catch (\Throwable $e) {
$code = $envelope->get('code');
}
return sprintf('Your message could not be handled (Code:%s).', $code);
}
|
[
"private",
"function",
"redactErrorMessage",
"(",
"Envelope",
"$",
"envelope",
",",
"Request",
"$",
"request",
")",
":",
"string",
"{",
"try",
"{",
"$",
"code",
"=",
"Code",
"::",
"create",
"(",
"$",
"envelope",
"->",
"get",
"(",
"'code'",
")",
")",
"->",
"getName",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"code",
"=",
"$",
"envelope",
"->",
"get",
"(",
"'code'",
")",
";",
"}",
"return",
"sprintf",
"(",
"'Your message could not be handled (Code:%s).'",
",",
"$",
"code",
")",
";",
"}"
] |
It's generally not safe to render exception messages to the outside world.
So when we're pushing an error to the outside world (http, not console)
we'll replace the message with something generic.
@param Envelope $envelope
@param Request $request
@return string
|
[
"It",
"s",
"generally",
"not",
"safe",
"to",
"render",
"exception",
"messages",
"to",
"the",
"outside",
"world",
".",
"So",
"when",
"we",
"re",
"pushing",
"an",
"error",
"to",
"the",
"outside",
"world",
"(",
"http",
"not",
"console",
")",
"we",
"ll",
"replace",
"the",
"message",
"with",
"something",
"generic",
"."
] |
train
|
https://github.com/gdbots/pbjx-bundle-php/blob/f3c0088583879fc92f13247a0752634bd8696eac/src/EventListener/EnvelopeListener.php#L104-L113
|
EcomDev/magento-psr6-bridge
|
src/Model/CacheType.php
|
CacheType._getFrontend
|
protected function _getFrontend()
{
// @codingStandardsIgnoreEnd
$frontend = parent::_getFrontend();
if ($frontend === null) {
$frontend = $this->frontendPool->get(self::CACHE_TYPE);
}
return $frontend;
}
|
php
|
protected function _getFrontend()
{
// @codingStandardsIgnoreEnd
$frontend = parent::_getFrontend();
if ($frontend === null) {
$frontend = $this->frontendPool->get(self::CACHE_TYPE);
}
return $frontend;
}
|
[
"protected",
"function",
"_getFrontend",
"(",
")",
"{",
"// @codingStandardsIgnoreEnd",
"$",
"frontend",
"=",
"parent",
"::",
"_getFrontend",
"(",
")",
";",
"if",
"(",
"$",
"frontend",
"===",
"null",
")",
"{",
"$",
"frontend",
"=",
"$",
"this",
"->",
"frontendPool",
"->",
"get",
"(",
"self",
"::",
"CACHE_TYPE",
")",
";",
"}",
"return",
"$",
"frontend",
";",
"}"
] |
Returns a frontend on a first call to frontend interface methods
@SuppressWarnings(PHPMD.CamelCaseMethodName)
@return FrontendInterface
|
[
"Returns",
"a",
"frontend",
"on",
"a",
"first",
"call",
"to",
"frontend",
"interface",
"methods"
] |
train
|
https://github.com/EcomDev/magento-psr6-bridge/blob/405c5b455f239fe8dc1b710df5fe9438f09d4715/src/Model/CacheType.php#L71-L81
|
darkwebdesign/doctrine-unit-testing
|
src/Mocks/EntityPersisterMock.php
|
EntityPersisterMock.addInsert
|
public function addInsert($entity)
{
$this->inserts[] = $entity;
if ( ! is_null($this->mockIdGeneratorType) && $this->mockIdGeneratorType == ClassMetadata::GENERATOR_TYPE_IDENTITY
|| $this->class->isIdGeneratorIdentity()) {
$id = $this->identityColumnValueCounter++;
$this->postInsertIds[] = [
'generatedId' => $id,
'entity' => $entity,
];
return $id;
}
return null;
}
|
php
|
public function addInsert($entity)
{
$this->inserts[] = $entity;
if ( ! is_null($this->mockIdGeneratorType) && $this->mockIdGeneratorType == ClassMetadata::GENERATOR_TYPE_IDENTITY
|| $this->class->isIdGeneratorIdentity()) {
$id = $this->identityColumnValueCounter++;
$this->postInsertIds[] = [
'generatedId' => $id,
'entity' => $entity,
];
return $id;
}
return null;
}
|
[
"public",
"function",
"addInsert",
"(",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"inserts",
"[",
"]",
"=",
"$",
"entity",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"mockIdGeneratorType",
")",
"&&",
"$",
"this",
"->",
"mockIdGeneratorType",
"==",
"ClassMetadata",
"::",
"GENERATOR_TYPE_IDENTITY",
"||",
"$",
"this",
"->",
"class",
"->",
"isIdGeneratorIdentity",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"identityColumnValueCounter",
"++",
";",
"$",
"this",
"->",
"postInsertIds",
"[",
"]",
"=",
"[",
"'generatedId'",
"=>",
"$",
"id",
",",
"'entity'",
"=>",
"$",
"entity",
",",
"]",
";",
"return",
"$",
"id",
";",
"}",
"return",
"null",
";",
"}"
] |
@param object $entity
@return mixed
|
[
"@param",
"object",
"$entity"
] |
train
|
https://github.com/darkwebdesign/doctrine-unit-testing/blob/0daf50359563bc0679925e573a7105d6cd57168a/src/Mocks/EntityPersisterMock.php#L54-L67
|
jan-dolata/crude-crud
|
src/Engine/CrudeSetupTrait/CustomActions.php
|
CustomActions.setCustomActions
|
public function setCustomActions($name, $data = null)
{
$actions = is_array($name) ? $name : [$name => $data];
foreach ($actions as $key => $value) {
$this->customActions[$key] = $value;
}
return $this;
}
|
php
|
public function setCustomActions($name, $data = null)
{
$actions = is_array($name) ? $name : [$name => $data];
foreach ($actions as $key => $value) {
$this->customActions[$key] = $value;
}
return $this;
}
|
[
"public",
"function",
"setCustomActions",
"(",
"$",
"name",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"actions",
"=",
"is_array",
"(",
"$",
"name",
")",
"?",
"$",
"name",
":",
"[",
"$",
"name",
"=>",
"$",
"data",
"]",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"customActions",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the Custom actions.
@param string|array $name
@param array $data = null
@return self
|
[
"Sets",
"the",
"Custom",
"actions",
"."
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/CrudeSetupTrait/CustomActions.php#L32-L41
|
FrenchFrogs/framework
|
src/Table/Column/Strainer/Strainerable.php
|
Strainerable.setStrainerSelect
|
public function setStrainerSelect($options = [], $callable = null, $attr = [])
{
// if callable is a string , it's a field
if (is_string($callable) || $callable instanceof Expression) {
$field = $callable;
$callable = null;
}
// create the strainer
$strainer = new Select($this, $options, $callable, $attr);
//if a fields is set, we configure the strainer
if (isset($field)) {
$strainer->setField($field);
}
return $this->setStrainer($strainer);
}
|
php
|
public function setStrainerSelect($options = [], $callable = null, $attr = [])
{
// if callable is a string , it's a field
if (is_string($callable) || $callable instanceof Expression) {
$field = $callable;
$callable = null;
}
// create the strainer
$strainer = new Select($this, $options, $callable, $attr);
//if a fields is set, we configure the strainer
if (isset($field)) {
$strainer->setField($field);
}
return $this->setStrainer($strainer);
}
|
[
"public",
"function",
"setStrainerSelect",
"(",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"callable",
"=",
"null",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"// if callable is a string , it's a field",
"if",
"(",
"is_string",
"(",
"$",
"callable",
")",
"||",
"$",
"callable",
"instanceof",
"Expression",
")",
"{",
"$",
"field",
"=",
"$",
"callable",
";",
"$",
"callable",
"=",
"null",
";",
"}",
"// create the strainer",
"$",
"strainer",
"=",
"new",
"Select",
"(",
"$",
"this",
",",
"$",
"options",
",",
"$",
"callable",
",",
"$",
"attr",
")",
";",
"//if a fields is set, we configure the strainer",
"if",
"(",
"isset",
"(",
"$",
"field",
")",
")",
"{",
"$",
"strainer",
"->",
"setField",
"(",
"$",
"field",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setStrainer",
"(",
"$",
"strainer",
")",
";",
"}"
] |
Set Strainer as a select form element
@param array $options
@param array $attr
@return \FrenchFrogs\Table\Column\Strainer\Strainerable
|
[
"Set",
"Strainer",
"as",
"a",
"select",
"form",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Strainer/Strainerable.php#L69-L88
|
FrenchFrogs/framework
|
src/Table/Column/Strainer/Strainerable.php
|
Strainerable.setStrainerBoolean
|
public function setStrainerBoolean($callable = null, $attr = [])
{
// if callable is a string , it's a field
if (is_string($callable) || $callable instanceof Expression) {
$field = $callable;
$callable = null;
}
// create the strainer
$strainer = new Boolean($this, $callable, $attr);
//if a fields is set, we configure the strainer
if (isset($field)) {
$strainer->setField($field);
}
return $this->setStrainer($strainer);
}
|
php
|
public function setStrainerBoolean($callable = null, $attr = [])
{
// if callable is a string , it's a field
if (is_string($callable) || $callable instanceof Expression) {
$field = $callable;
$callable = null;
}
// create the strainer
$strainer = new Boolean($this, $callable, $attr);
//if a fields is set, we configure the strainer
if (isset($field)) {
$strainer->setField($field);
}
return $this->setStrainer($strainer);
}
|
[
"public",
"function",
"setStrainerBoolean",
"(",
"$",
"callable",
"=",
"null",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"// if callable is a string , it's a field",
"if",
"(",
"is_string",
"(",
"$",
"callable",
")",
"||",
"$",
"callable",
"instanceof",
"Expression",
")",
"{",
"$",
"field",
"=",
"$",
"callable",
";",
"$",
"callable",
"=",
"null",
";",
"}",
"// create the strainer",
"$",
"strainer",
"=",
"new",
"Boolean",
"(",
"$",
"this",
",",
"$",
"callable",
",",
"$",
"attr",
")",
";",
"//if a fields is set, we configure the strainer",
"if",
"(",
"isset",
"(",
"$",
"field",
")",
")",
"{",
"$",
"strainer",
"->",
"setField",
"(",
"$",
"field",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setStrainer",
"(",
"$",
"strainer",
")",
";",
"}"
] |
Set strainer as a Boolean
@param null $callable
@param array $attr
@return $this
|
[
"Set",
"strainer",
"as",
"a",
"Boolean"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Strainer/Strainerable.php#L118-L135
|
FrenchFrogs/framework
|
src/Table/Column/Strainer/Strainerable.php
|
Strainerable.setStrainerDateRange
|
public function setStrainerDateRange($callable = null, $attr = [])
{
// if callable is a string , it's a field
if (is_string($callable) || $callable instanceof Expression) {
$field = $callable;
$callable = null;
}
// create the strainer
$strainer = new DateRange($this, $callable, $attr);
//if a fields is set, we configure the strainer
if (isset($field)) {
$strainer->setField($field);
}
return $this->setStrainer($strainer);
}
|
php
|
public function setStrainerDateRange($callable = null, $attr = [])
{
// if callable is a string , it's a field
if (is_string($callable) || $callable instanceof Expression) {
$field = $callable;
$callable = null;
}
// create the strainer
$strainer = new DateRange($this, $callable, $attr);
//if a fields is set, we configure the strainer
if (isset($field)) {
$strainer->setField($field);
}
return $this->setStrainer($strainer);
}
|
[
"public",
"function",
"setStrainerDateRange",
"(",
"$",
"callable",
"=",
"null",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"// if callable is a string , it's a field",
"if",
"(",
"is_string",
"(",
"$",
"callable",
")",
"||",
"$",
"callable",
"instanceof",
"Expression",
")",
"{",
"$",
"field",
"=",
"$",
"callable",
";",
"$",
"callable",
"=",
"null",
";",
"}",
"// create the strainer",
"$",
"strainer",
"=",
"new",
"DateRange",
"(",
"$",
"this",
",",
"$",
"callable",
",",
"$",
"attr",
")",
";",
"//if a fields is set, we configure the strainer",
"if",
"(",
"isset",
"(",
"$",
"field",
")",
")",
"{",
"$",
"strainer",
"->",
"setField",
"(",
"$",
"field",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setStrainer",
"(",
"$",
"strainer",
")",
";",
"}"
] |
Set a strainer as date from to
@param null $callable
@param array $attr
@return $this
|
[
"Set",
"a",
"strainer",
"as",
"date",
"from",
"to"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Strainer/Strainerable.php#L145-L163
|
movoin/one-swoole
|
src/Swoole/Commands/StatusCommand.php
|
StatusCommand.execute
|
protected function execute(InputInterface $input, OutputInterface $output)
{
// 读取所有服务
$servers = array_keys(Config::get('server', []));
// 当前服务
$server = $input->getArgument('server');
if ($server !== null && ! isset($servers[$server])) {
$this->error('查看状态失败, 未找到 [' . $server . '] 服务');
return 0;
} elseif ($server === null && $servers === []) {
$this->error('查看状态失败, 未定义任何服务');
return 0;
}
// {{
$this->title('服务运行状态');
// }}
if ($server !== null) {
$servers = (array) $server;
}
unset($server);
$runner = new Runner;
try {
foreach ($servers as $server) {
$this->showStatus($runner, $server);
$this->wait();
}
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
$this->newLine();
return 0;
}
|
php
|
protected function execute(InputInterface $input, OutputInterface $output)
{
// 读取所有服务
$servers = array_keys(Config::get('server', []));
// 当前服务
$server = $input->getArgument('server');
if ($server !== null && ! isset($servers[$server])) {
$this->error('查看状态失败, 未找到 [' . $server . '] 服务');
return 0;
} elseif ($server === null && $servers === []) {
$this->error('查看状态失败, 未定义任何服务');
return 0;
}
// {{
$this->title('服务运行状态');
// }}
if ($server !== null) {
$servers = (array) $server;
}
unset($server);
$runner = new Runner;
try {
foreach ($servers as $server) {
$this->showStatus($runner, $server);
$this->wait();
}
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
$this->newLine();
return 0;
}
|
[
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"// 读取所有服务",
"$",
"servers",
"=",
"array_keys",
"(",
"Config",
"::",
"get",
"(",
"'server'",
",",
"[",
"]",
")",
")",
";",
"// 当前服务",
"$",
"server",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'server'",
")",
";",
"if",
"(",
"$",
"server",
"!==",
"null",
"&&",
"!",
"isset",
"(",
"$",
"servers",
"[",
"$",
"server",
"]",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'查看状态失败, 未找到 [' . $server . '] 服务",
")",
"",
"",
"",
"",
"",
"",
"return",
"0",
";",
"}",
"elseif",
"(",
"$",
"server",
"===",
"null",
"&&",
"$",
"servers",
"===",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'查看状态失败, 未定义任何服务');",
"",
"",
"return",
"0",
";",
"}",
"// {{",
"$",
"this",
"->",
"title",
"(",
"'服务运行状态');",
"",
"",
"// }}",
"if",
"(",
"$",
"server",
"!==",
"null",
")",
"{",
"$",
"servers",
"=",
"(",
"array",
")",
"$",
"server",
";",
"}",
"unset",
"(",
"$",
"server",
")",
";",
"$",
"runner",
"=",
"new",
"Runner",
";",
"try",
"{",
"foreach",
"(",
"$",
"servers",
"as",
"$",
"server",
")",
"{",
"$",
"this",
"->",
"showStatus",
"(",
"$",
"runner",
",",
"$",
"server",
")",
";",
"$",
"this",
"->",
"wait",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"fail",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"return",
"0",
";",
"}"
] |
执行命令
@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
|
[
"执行命令"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Commands/StatusCommand.php#L43-L82
|
movoin/one-swoole
|
src/Swoole/Commands/StatusCommand.php
|
StatusCommand.showStatus
|
protected function showStatus(Runner $runner, string $server)
{
$status = $runner->isRunning($server);
$this->status(
sprintf('<label>%s</> 服务', strtoupper($server)),
$status ? '<success>运行中</>' : '<failure>已关闭</>',
$status ? 'success' : 'failure',
$status ? '√' : '×'
);
}
|
php
|
protected function showStatus(Runner $runner, string $server)
{
$status = $runner->isRunning($server);
$this->status(
sprintf('<label>%s</> 服务', strtoupper($server)),
$status ? '<success>运行中</>' : '<failure>已关闭</>',
$status ? 'success' : 'failure',
$status ? '√' : '×'
);
}
|
[
"protected",
"function",
"showStatus",
"(",
"Runner",
"$",
"runner",
",",
"string",
"$",
"server",
")",
"{",
"$",
"status",
"=",
"$",
"runner",
"->",
"isRunning",
"(",
"$",
"server",
")",
";",
"$",
"this",
"->",
"status",
"(",
"sprintf",
"(",
"'<label>%s</> 服务', st",
"r",
"oupper($se",
"r",
"v",
"er)),",
"",
"",
"",
"$",
"status",
"?",
"'<success>运行中</>' : '<f",
"i",
"ure>已关闭</>',",
"",
"$",
"status",
"?",
"'success'",
":",
"'failure'",
",",
"$",
"status",
"?",
"'√' :",
"'",
"'",
")",
";",
"}"
] |
显示运行状态
@param \One\Console\Runner $runner
@param string $server
|
[
"显示运行状态"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Commands/StatusCommand.php#L90-L100
|
pageon/SlackWebhookMonolog
|
src/Slack/EmojiIcon.php
|
EmojiIcon.setEmoji
|
private function setEmoji($emoji)
{
// remove the whitespace
$emoji = trim($emoji);
$emojiValidationRegex = '_^:[\w-+]+:$_iuS';
if (!preg_match($emojiValidationRegex, $emoji)) {
throw new InvalidEmojiException(
sprintf(
'The emoji: "%s" is not a valid emoji.
An emoji should always be a string starting and ending with ":".',
$emoji
),
400
);
}
$this->emoji = $emoji;
return $this;
}
|
php
|
private function setEmoji($emoji)
{
// remove the whitespace
$emoji = trim($emoji);
$emojiValidationRegex = '_^:[\w-+]+:$_iuS';
if (!preg_match($emojiValidationRegex, $emoji)) {
throw new InvalidEmojiException(
sprintf(
'The emoji: "%s" is not a valid emoji.
An emoji should always be a string starting and ending with ":".',
$emoji
),
400
);
}
$this->emoji = $emoji;
return $this;
}
|
[
"private",
"function",
"setEmoji",
"(",
"$",
"emoji",
")",
"{",
"// remove the whitespace",
"$",
"emoji",
"=",
"trim",
"(",
"$",
"emoji",
")",
";",
"$",
"emojiValidationRegex",
"=",
"'_^:[\\w-+]+:$_iuS'",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"emojiValidationRegex",
",",
"$",
"emoji",
")",
")",
"{",
"throw",
"new",
"InvalidEmojiException",
"(",
"sprintf",
"(",
"'The emoji: \"%s\" is not a valid emoji.\n An emoji should always be a string starting and ending with \":\".'",
",",
"$",
"emoji",
")",
",",
"400",
")",
";",
"}",
"$",
"this",
"->",
"emoji",
"=",
"$",
"emoji",
";",
"return",
"$",
"this",
";",
"}"
] |
This will set the emoji if it is valid.
@param string $emoji
@throws InvalidEmojiException Thrown when the emoji is not valid
@return $this
|
[
"This",
"will",
"set",
"the",
"emoji",
"if",
"it",
"is",
"valid",
"."
] |
train
|
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/Slack/EmojiIcon.php#L40-L59
|
FrenchFrogs/framework
|
src/Container/Javascript.php
|
Javascript.encode
|
protected function encode($var)
{
$functions = [];
// on force un niveau supérieur
$var = [$var];
// bind toutes les functions
array_walk_recursive($var, function(&$item, $key) use (&$functions){
if (substr($item,0,8) == 'function') {
$index = '###___' . count($functions) . '___###';
$functions['"' . $index . '"'] = $item;
$item = $index;
}
});
// Encodage
$var = json_encode($var[0], JSON_PRETTY_PRINT );
// Rebind des functions
$var = str_replace(array_keys($functions), array_values($functions), $var);
return $var;
}
|
php
|
protected function encode($var)
{
$functions = [];
// on force un niveau supérieur
$var = [$var];
// bind toutes les functions
array_walk_recursive($var, function(&$item, $key) use (&$functions){
if (substr($item,0,8) == 'function') {
$index = '###___' . count($functions) . '___###';
$functions['"' . $index . '"'] = $item;
$item = $index;
}
});
// Encodage
$var = json_encode($var[0], JSON_PRETTY_PRINT );
// Rebind des functions
$var = str_replace(array_keys($functions), array_values($functions), $var);
return $var;
}
|
[
"protected",
"function",
"encode",
"(",
"$",
"var",
")",
"{",
"$",
"functions",
"=",
"[",
"]",
";",
"// on force un niveau supérieur",
"$",
"var",
"=",
"[",
"$",
"var",
"]",
";",
"// bind toutes les functions",
"array_walk_recursive",
"(",
"$",
"var",
",",
"function",
"(",
"&",
"$",
"item",
",",
"$",
"key",
")",
"use",
"(",
"&",
"$",
"functions",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"item",
",",
"0",
",",
"8",
")",
"==",
"'function'",
")",
"{",
"$",
"index",
"=",
"'###___'",
".",
"count",
"(",
"$",
"functions",
")",
".",
"'___###'",
";",
"$",
"functions",
"[",
"'\"'",
".",
"$",
"index",
".",
"'\"'",
"]",
"=",
"$",
"item",
";",
"$",
"item",
"=",
"$",
"index",
";",
"}",
"}",
")",
";",
"// Encodage",
"$",
"var",
"=",
"json_encode",
"(",
"$",
"var",
"[",
"0",
"]",
",",
"JSON_PRETTY_PRINT",
")",
";",
"// Rebind des functions",
"$",
"var",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"functions",
")",
",",
"array_values",
"(",
"$",
"functions",
")",
",",
"$",
"var",
")",
";",
"return",
"$",
"var",
";",
"}"
] |
Ecnode un paramètre js
@param $var
@return mixed
|
[
"Ecnode",
"un",
"paramètre",
"js"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Container/Javascript.php#L41-L65
|
FrenchFrogs/framework
|
src/Container/Javascript.php
|
Javascript.build
|
public function build($selector, $function, ...$params)
{
$attributes = [];
foreach($params as $p) {
$attributes[] = $this->encode($p);
}
//n concatenation du json
$attributes = implode(',', $attributes);
// gestion des functions
$attributes = preg_replace('#\"(function\([^\{]+{.*\})\",#', '$1,', $attributes);
return sprintf('$("%s").%s(%s);', $selector, $function, $attributes);
}
|
php
|
public function build($selector, $function, ...$params)
{
$attributes = [];
foreach($params as $p) {
$attributes[] = $this->encode($p);
}
//n concatenation du json
$attributes = implode(',', $attributes);
// gestion des functions
$attributes = preg_replace('#\"(function\([^\{]+{.*\})\",#', '$1,', $attributes);
return sprintf('$("%s").%s(%s);', $selector, $function, $attributes);
}
|
[
"public",
"function",
"build",
"(",
"$",
"selector",
",",
"$",
"function",
",",
"...",
"$",
"params",
")",
"{",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"p",
")",
"{",
"$",
"attributes",
"[",
"]",
"=",
"$",
"this",
"->",
"encode",
"(",
"$",
"p",
")",
";",
"}",
"//n concatenation du json",
"$",
"attributes",
"=",
"implode",
"(",
"','",
",",
"$",
"attributes",
")",
";",
"// gestion des functions",
"$",
"attributes",
"=",
"preg_replace",
"(",
"'#\\\"(function\\([^\\{]+{.*\\})\\\",#'",
",",
"'$1,'",
",",
"$",
"attributes",
")",
";",
"return",
"sprintf",
"(",
"'$(\"%s\").%s(%s);'",
",",
"$",
"selector",
",",
"$",
"function",
",",
"$",
"attributes",
")",
";",
"}"
] |
Build a jquery call javascript code
@param $selector
@param $function
@param ...$params
@return string
|
[
"Build",
"a",
"jquery",
"call",
"javascript",
"code"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Container/Javascript.php#L75-L91
|
FrenchFrogs/framework
|
src/Container/Javascript.php
|
Javascript.appendJs
|
public function appendJs($selector, $function, ...$params)
{
array_unshift($params, $selector, $function);
$this->append([static::TYPE_INLINE, call_user_func_array([$this, 'build'], $params)]);
return $this;
}
|
php
|
public function appendJs($selector, $function, ...$params)
{
array_unshift($params, $selector, $function);
$this->append([static::TYPE_INLINE, call_user_func_array([$this, 'build'], $params)]);
return $this;
}
|
[
"public",
"function",
"appendJs",
"(",
"$",
"selector",
",",
"$",
"function",
",",
"...",
"$",
"params",
")",
"{",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"selector",
",",
"$",
"function",
")",
";",
"$",
"this",
"->",
"append",
"(",
"[",
"static",
"::",
"TYPE_INLINE",
",",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'build'",
"]",
",",
"$",
"params",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Append build javascript to $container attribute
@param $selector
@param $function
@param ...$params
@return $this
|
[
"Append",
"build",
"javascript",
"to",
"$container",
"attribute"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Container/Javascript.php#L101-L106
|
FrenchFrogs/framework
|
src/Container/Javascript.php
|
Javascript.prependJs
|
public function prependJs($selector, $function, ...$params)
{
array_unshift($params, $selector, $function);
$this->append([static::TYPE_INLINE, call_user_func_array([$this, 'build'], $params)]);
return $this;
}
|
php
|
public function prependJs($selector, $function, ...$params)
{
array_unshift($params, $selector, $function);
$this->append([static::TYPE_INLINE, call_user_func_array([$this, 'build'], $params)]);
return $this;
}
|
[
"public",
"function",
"prependJs",
"(",
"$",
"selector",
",",
"$",
"function",
",",
"...",
"$",
"params",
")",
"{",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"selector",
",",
"$",
"function",
")",
";",
"$",
"this",
"->",
"append",
"(",
"[",
"static",
"::",
"TYPE_INLINE",
",",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'build'",
"]",
",",
"$",
"params",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Prepend build javascript to $container attribute
@param $selector
@param $function
@param ...$params
@return $this
|
[
"Prepend",
"build",
"javascript",
"to",
"$container",
"attribute"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Container/Javascript.php#L116-L121
|
FrenchFrogs/framework
|
src/Container/Javascript.php
|
Javascript.warning
|
public function warning($body = '', $title = '')
{
$body = empty($body) ? configurator()->get('toastr.warning.default') : $body;
$this->append([static::TYPE_INLINE, sprintf('toastr.warning("%s", "%s");', $body, $title)]);
return $this;
}
|
php
|
public function warning($body = '', $title = '')
{
$body = empty($body) ? configurator()->get('toastr.warning.default') : $body;
$this->append([static::TYPE_INLINE, sprintf('toastr.warning("%s", "%s");', $body, $title)]);
return $this;
}
|
[
"public",
"function",
"warning",
"(",
"$",
"body",
"=",
"''",
",",
"$",
"title",
"=",
"''",
")",
"{",
"$",
"body",
"=",
"empty",
"(",
"$",
"body",
")",
"?",
"configurator",
"(",
")",
"->",
"get",
"(",
"'toastr.warning.default'",
")",
":",
"$",
"body",
";",
"$",
"this",
"->",
"append",
"(",
"[",
"static",
"::",
"TYPE_INLINE",
",",
"sprintf",
"(",
"'toastr.warning(\"%s\", \"%s\");'",
",",
"$",
"body",
",",
"$",
"title",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add toastr warning message
@param $body
@param string $title
@return $this
|
[
"Add",
"toastr",
"warning",
"message"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Container/Javascript.php#L155-L160
|
fuzz-productions/laravel-api-data
|
src/Eloquent/Model.php
|
Model.setAttribute
|
public function setAttribute($key, $value)
{
// First we will check for the presence of a mutator for the set operation
// which simply lets the developers tweak the attribute as it is set on
// the model, such as "json_encoding" an listing of data for storage.
if ($this->hasSetMutator($key)) {
$method = 'set' . Str::studly($key) . 'Attribute';
return $this->{$method}($value);
}
// If an attribute is listed as a "date", we'll convert it from a DateTime
// instance into a form proper for storage on the database tables using
// the connection grammar's date format. We will auto set the values.
elseif (in_array($key, $this->getDates()) && $value) {
$value = $this->fromDateTime($value);
}
// Only set if the user can currently access
if ($this->console_mode || $this->modify_authorizer->canAccess($key)) {
if ($this->isJsonCastable($key) && ! is_null($value)) {
$value = json_encode($value);
}
$this->attributes[$key] = $value;
}
}
|
php
|
public function setAttribute($key, $value)
{
// First we will check for the presence of a mutator for the set operation
// which simply lets the developers tweak the attribute as it is set on
// the model, such as "json_encoding" an listing of data for storage.
if ($this->hasSetMutator($key)) {
$method = 'set' . Str::studly($key) . 'Attribute';
return $this->{$method}($value);
}
// If an attribute is listed as a "date", we'll convert it from a DateTime
// instance into a form proper for storage on the database tables using
// the connection grammar's date format. We will auto set the values.
elseif (in_array($key, $this->getDates()) && $value) {
$value = $this->fromDateTime($value);
}
// Only set if the user can currently access
if ($this->console_mode || $this->modify_authorizer->canAccess($key)) {
if ($this->isJsonCastable($key) && ! is_null($value)) {
$value = json_encode($value);
}
$this->attributes[$key] = $value;
}
}
|
[
"public",
"function",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"// First we will check for the presence of a mutator for the set operation",
"// which simply lets the developers tweak the attribute as it is set on",
"// the model, such as \"json_encoding\" an listing of data for storage.",
"if",
"(",
"$",
"this",
"->",
"hasSetMutator",
"(",
"$",
"key",
")",
")",
"{",
"$",
"method",
"=",
"'set'",
".",
"Str",
"::",
"studly",
"(",
"$",
"key",
")",
".",
"'Attribute'",
";",
"return",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"value",
")",
";",
"}",
"// If an attribute is listed as a \"date\", we'll convert it from a DateTime",
"// instance into a form proper for storage on the database tables using",
"// the connection grammar's date format. We will auto set the values.",
"elseif",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"getDates",
"(",
")",
")",
"&&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"fromDateTime",
"(",
"$",
"value",
")",
";",
"}",
"// Only set if the user can currently access",
"if",
"(",
"$",
"this",
"->",
"console_mode",
"||",
"$",
"this",
"->",
"modify_authorizer",
"->",
"canAccess",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isJsonCastable",
"(",
"$",
"key",
")",
"&&",
"!",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"json_encode",
"(",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] |
Set a given attribute on the model.
@param string $key
@param mixed $value
@return mixed
|
[
"Set",
"a",
"given",
"attribute",
"on",
"the",
"model",
"."
] |
train
|
https://github.com/fuzz-productions/laravel-api-data/blob/25e181860d2f269b3b212195944c2bca95b411bb/src/Eloquent/Model.php#L91-L117
|
fuzz-productions/laravel-api-data
|
src/Eloquent/Model.php
|
Model.accessibleAttributesToArray
|
public function accessibleAttributesToArray()
{
$filtered = [];
$attributes = $this->attributesToArray();
foreach ($attributes as $key => $attribute) {
$accessible = $this->access_authorizer->canAccess($key);
if ($accessible) {
$filtered[$key] = $attribute;
}
}
return array_merge($filtered, $this->accessibleRelationsToArray());
}
|
php
|
public function accessibleAttributesToArray()
{
$filtered = [];
$attributes = $this->attributesToArray();
foreach ($attributes as $key => $attribute) {
$accessible = $this->access_authorizer->canAccess($key);
if ($accessible) {
$filtered[$key] = $attribute;
}
}
return array_merge($filtered, $this->accessibleRelationsToArray());
}
|
[
"public",
"function",
"accessibleAttributesToArray",
"(",
")",
"{",
"$",
"filtered",
"=",
"[",
"]",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"attributesToArray",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"attribute",
")",
"{",
"$",
"accessible",
"=",
"$",
"this",
"->",
"access_authorizer",
"->",
"canAccess",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"accessible",
")",
"{",
"$",
"filtered",
"[",
"$",
"key",
"]",
"=",
"$",
"attribute",
";",
"}",
"}",
"return",
"array_merge",
"(",
"$",
"filtered",
",",
"$",
"this",
"->",
"accessibleRelationsToArray",
"(",
")",
")",
";",
"}"
] |
Filter attributes which can and can't be accessed by the user
@return array
|
[
"Filter",
"attributes",
"which",
"can",
"and",
"can",
"t",
"be",
"accessed",
"by",
"the",
"user"
] |
train
|
https://github.com/fuzz-productions/laravel-api-data/blob/25e181860d2f269b3b212195944c2bca95b411bb/src/Eloquent/Model.php#L124-L138
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.