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
|
---|---|---|---|---|---|---|---|---|---|---|
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
|
src/App/Normalizer/Component/TypeDocNormalizer.php
|
TypeDocNormalizer.appendNumberMinMax
|
protected function appendNumberMinMax(NumberDoc $doc, array $paramDocMinMax) : array
{
$paramDocMinMax = $this->appendIfValueNotNull('minimum', $doc->getMin(), $paramDocMinMax);
$paramDocMinMax = $this->appendIf(
($doc->getMin() && false === $doc->isInclusiveMin()),
'exclusiveMinimum',
true,
$paramDocMinMax
);
$paramDocMinMax = $this->appendIfValueNotNull('maximum', $doc->getMax(), $paramDocMinMax);
$paramDocMinMax = $this->appendIf(
($doc->getMax() && false === $doc->isInclusiveMax()),
'exclusiveMaximum',
true,
$paramDocMinMax
);
return $paramDocMinMax;
}
|
php
|
protected function appendNumberMinMax(NumberDoc $doc, array $paramDocMinMax) : array
{
$paramDocMinMax = $this->appendIfValueNotNull('minimum', $doc->getMin(), $paramDocMinMax);
$paramDocMinMax = $this->appendIf(
($doc->getMin() && false === $doc->isInclusiveMin()),
'exclusiveMinimum',
true,
$paramDocMinMax
);
$paramDocMinMax = $this->appendIfValueNotNull('maximum', $doc->getMax(), $paramDocMinMax);
$paramDocMinMax = $this->appendIf(
($doc->getMax() && false === $doc->isInclusiveMax()),
'exclusiveMaximum',
true,
$paramDocMinMax
);
return $paramDocMinMax;
}
|
[
"protected",
"function",
"appendNumberMinMax",
"(",
"NumberDoc",
"$",
"doc",
",",
"array",
"$",
"paramDocMinMax",
")",
":",
"array",
"{",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'minimum'",
",",
"$",
"doc",
"->",
"getMin",
"(",
")",
",",
"$",
"paramDocMinMax",
")",
";",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIf",
"(",
"(",
"$",
"doc",
"->",
"getMin",
"(",
")",
"&&",
"false",
"===",
"$",
"doc",
"->",
"isInclusiveMin",
"(",
")",
")",
",",
"'exclusiveMinimum'",
",",
"true",
",",
"$",
"paramDocMinMax",
")",
";",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'maximum'",
",",
"$",
"doc",
"->",
"getMax",
"(",
")",
",",
"$",
"paramDocMinMax",
")",
";",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIf",
"(",
"(",
"$",
"doc",
"->",
"getMax",
"(",
")",
"&&",
"false",
"===",
"$",
"doc",
"->",
"isInclusiveMax",
"(",
")",
")",
",",
"'exclusiveMaximum'",
",",
"true",
",",
"$",
"paramDocMinMax",
")",
";",
"return",
"$",
"paramDocMinMax",
";",
"}"
] |
@param NumberDoc $doc
@param array $paramDocMinMax
@return array
|
[
"@param",
"NumberDoc",
"$doc",
"@param",
"array",
"$paramDocMinMax"
] |
train
|
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/src/App/Normalizer/Component/TypeDocNormalizer.php#L191-L209
|
withfatpanda/illuminate-wordpress
|
src/Support/Concerns/BuildsErrorResponses.php
|
BuildsErrorResponses.buildErrorResponse
|
public function buildErrorResponse(\Exception $e)
{
$response = [
'type' => get_class($e),
'code' => $e->getCode(),
'message' => $e->getMessage(),
'data' => [
'status' => 500
]
];
if ($e instanceof ModelNotFoundException) {
$response['data']['status'] = 404;
}
if ($e instanceof HttpException) {
$response['data']['status'] = $e->getStatusCode();
}
if ($e instanceof ValidationException) {
$response['data']['errors'] = $e->messages();
}
if ($this->isDebugMode()) {
$response['line'] = $e->getLine();
$response['file'] = $e->getFile();
$response['trace'] = $e->getTraceAsString();
}
return $response;
}
|
php
|
public function buildErrorResponse(\Exception $e)
{
$response = [
'type' => get_class($e),
'code' => $e->getCode(),
'message' => $e->getMessage(),
'data' => [
'status' => 500
]
];
if ($e instanceof ModelNotFoundException) {
$response['data']['status'] = 404;
}
if ($e instanceof HttpException) {
$response['data']['status'] = $e->getStatusCode();
}
if ($e instanceof ValidationException) {
$response['data']['errors'] = $e->messages();
}
if ($this->isDebugMode()) {
$response['line'] = $e->getLine();
$response['file'] = $e->getFile();
$response['trace'] = $e->getTraceAsString();
}
return $response;
}
|
[
"public",
"function",
"buildErrorResponse",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"[",
"'type'",
"=>",
"get_class",
"(",
"$",
"e",
")",
",",
"'code'",
"=>",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'data'",
"=>",
"[",
"'status'",
"=>",
"500",
"]",
"]",
";",
"if",
"(",
"$",
"e",
"instanceof",
"ModelNotFoundException",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'status'",
"]",
"=",
"404",
";",
"}",
"if",
"(",
"$",
"e",
"instanceof",
"HttpException",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'status'",
"]",
"=",
"$",
"e",
"->",
"getStatusCode",
"(",
")",
";",
"}",
"if",
"(",
"$",
"e",
"instanceof",
"ValidationException",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'errors'",
"]",
"=",
"$",
"e",
"->",
"messages",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isDebugMode",
"(",
")",
")",
"{",
"$",
"response",
"[",
"'line'",
"]",
"=",
"$",
"e",
"->",
"getLine",
"(",
")",
";",
"$",
"response",
"[",
"'file'",
"]",
"=",
"$",
"e",
"->",
"getFile",
"(",
")",
";",
"$",
"response",
"[",
"'trace'",
"]",
"=",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Given an Exception, build a data package suitable for reporting
the error to the client.
@param Exception The exception
@return array
|
[
"Given",
"an",
"Exception",
"build",
"a",
"data",
"package",
"suitable",
"for",
"reporting",
"the",
"error",
"to",
"the",
"client",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/Support/Concerns/BuildsErrorResponses.php#L16-L46
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveCoreStats
|
public function retrieveCoreStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22CoreStats%22]");
$coreStats = json_decode($data);
return $coreStats;
}
|
php
|
public function retrieveCoreStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22CoreStats%22]");
$coreStats = json_decode($data);
return $coreStats;
}
|
[
"public",
"function",
"retrieveCoreStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22CoreStats%22]\"",
")",
";",
"$",
"coreStats",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"coreStats",
";",
"}"
] |
Retrieve Core Stats
@access public
@return object JSON
|
[
"Retrieve",
"Core",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L81-L86
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveBadPlayerStats
|
public function retrieveBadPlayerStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22BadPlayerStats%22]");
$badPlayerStats = json_decode($data);
return $badPlayerStats;
}
|
php
|
public function retrieveBadPlayerStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22BadPlayerStats%22]");
$badPlayerStats = json_decode($data);
return $badPlayerStats;
}
|
[
"public",
"function",
"retrieveBadPlayerStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22BadPlayerStats%22]\"",
")",
";",
"$",
"badPlayerStats",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"badPlayerStats",
";",
"}"
] |
Retrieve Bad Player Stats
@access public
@return object JSON
|
[
"Retrieve",
"Bad",
"Player",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L94-L99
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveVehicleStats
|
public function retrieveVehicleStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22VehicleStats%22]");
$vehicleStats = json_decode($data);
return $vehicleStats;
}
|
php
|
public function retrieveVehicleStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22VehicleStats%22]");
$vehicleStats = json_decode($data);
return $vehicleStats;
}
|
[
"public",
"function",
"retrieveVehicleStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22VehicleStats%22]\"",
")",
";",
"$",
"vehicleStats",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"vehicleStats",
";",
"}"
] |
Retrieve Vehicle Stats
@access public
@return object JSON
|
[
"Retrieve",
"Vehicle",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L107-L112
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveMapStats
|
public function retrieveMapStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22MapStats%22]");
$mapStats = json_decode($data);
return $mapStats;
}
|
php
|
public function retrieveMapStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22MapStats%22]");
$mapStats = json_decode($data);
return $mapStats;
}
|
[
"public",
"function",
"retrieveMapStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22MapStats%22]\"",
")",
";",
"$",
"mapStats",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"mapStats",
";",
"}"
] |
Retrieve Map Stats
@access public
@return object JSON
|
[
"Retrieve",
"Map",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L120-L125
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveGameModeMapStats
|
public function retrieveGameModeMapStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22GameModeMapStats%22]");
$gameModeMapStats = json_decode($data);
return $gameModeMapStats;
}
|
php
|
public function retrieveGameModeMapStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22GameModeMapStats%22]");
$gameModeMapStats = json_decode($data);
return $gameModeMapStats;
}
|
[
"public",
"function",
"retrieveGameModeMapStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22GameModeMapStats%22]\"",
")",
";",
"$",
"gameModeMapStats",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"gameModeMapStats",
";",
"}"
] |
Retrieve Game Mode Map Stats
@access public
@return object JSON
|
[
"Retrieve",
"Game",
"Mode",
"Map",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L133-L138
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveWeaponStats
|
public function retrieveWeaponStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22WeaponStats%22]");
$weapons = json_decode($data);
return $weapons;
}
|
php
|
public function retrieveWeaponStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22WeaponStats%22]");
$weapons = json_decode($data);
return $weapons;
}
|
[
"public",
"function",
"retrieveWeaponStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22WeaponStats%22]\"",
")",
";",
"$",
"weapons",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"weapons",
";",
"}"
] |
Retrieve Weapon Stats
@access public
@return object JSON
|
[
"Retrieve",
"Weapon",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L146-L151
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveGameModeStats
|
public function retrieveGameModeStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22GameModeStats%22]");
$gameModeStats = json_decode($data);
return $gameModeStats;
}
|
php
|
public function retrieveGameModeStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22GameModeStats%22]");
$gameModeStats = json_decode($data);
return $gameModeStats;
}
|
[
"public",
"function",
"retrieveGameModeStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22GameModeStats%22]\"",
")",
";",
"$",
"gameModeStats",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"gameModeStats",
";",
"}"
] |
Retrieve Game Mode Stats
@access public
@return object JSON
|
[
"Retrieve",
"Game",
"Mode",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L159-L164
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveRushMapStats
|
public function retrieveRushMapStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22RushMapStats%22]&_?=1351945928776");
$rushMapStats = json_decode($data);
return $rushMapStats;
}
|
php
|
public function retrieveRushMapStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22RushMapStats%22]&_?=1351945928776");
$rushMapStats = json_decode($data);
return $rushMapStats;
}
|
[
"public",
"function",
"retrieveRushMapStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22RushMapStats%22]&_?=1351945928776\"",
")",
";",
"$",
"rushMapStats",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"rushMapStats",
";",
"}"
] |
Retrieve Rush Map Stats
@access public
@return object JSON
|
[
"Retrieve",
"Rush",
"Map",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L172-L177
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveGameEventStats
|
public function retrieveGameEventStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22GameEventStats%22]");
$gameEventStats = json_decode($data);
return $gameEventStats;
}
|
php
|
public function retrieveGameEventStats ()
{
$data = file_get_contents("http://battlefield.play4free.com/en/profile/stats/" .$this->_profileID. "/" .$this->_soldierID. "?g=[%22GameEventStats%22]");
$gameEventStats = json_decode($data);
return $gameEventStats;
}
|
[
"public",
"function",
"retrieveGameEventStats",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"\"http://battlefield.play4free.com/en/profile/stats/\"",
".",
"$",
"this",
"->",
"_profileID",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_soldierID",
".",
"\"?g=[%22GameEventStats%22]\"",
")",
";",
"$",
"gameEventStats",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"$",
"gameEventStats",
";",
"}"
] |
Retrieve Game Event Stats
@access public
@return object JSON
|
[
"Retrieve",
"Game",
"Event",
"Stats"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L185-L190
|
piqus/bfp4f-rcon
|
src/T4G/BFP4F/Rcon/Stats.php
|
Stats.retrieveLoadout
|
public function retrieveLoadout ()
{
$data = file_get_contents('http://battlefield.play4free.com/pl/profile/loadout/' .$this->_profileID. '/' .$this->_soldierID);
$loadout = json_decode($data, true);
return $loadout;
}
|
php
|
public function retrieveLoadout ()
{
$data = file_get_contents('http://battlefield.play4free.com/pl/profile/loadout/' .$this->_profileID. '/' .$this->_soldierID);
$loadout = json_decode($data, true);
return $loadout;
}
|
[
"public",
"function",
"retrieveLoadout",
"(",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"'http://battlefield.play4free.com/pl/profile/loadout/'",
".",
"$",
"this",
"->",
"_profileID",
".",
"'/'",
".",
"$",
"this",
"->",
"_soldierID",
")",
";",
"$",
"loadout",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"return",
"$",
"loadout",
";",
"}"
] |
Retrieve Loadout
@access public
@return object JSON
|
[
"Retrieve",
"Loadout"
] |
train
|
https://github.com/piqus/bfp4f-rcon/blob/8e94587bc93c686e5a025a54645aed7c701811e6/src/T4G/BFP4F/Rcon/Stats.php#L198-L203
|
dragosprotung/stc-core
|
src/Date/DateInterval.php
|
DateInterval.totalSeconds
|
public function totalSeconds() : int
{
return $this->days * 86400 + $this->h * 3600 + $this->i * 60 + $this->s;
}
|
php
|
public function totalSeconds() : int
{
return $this->days * 86400 + $this->h * 3600 + $this->i * 60 + $this->s;
}
|
[
"public",
"function",
"totalSeconds",
"(",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"days",
"*",
"86400",
"+",
"$",
"this",
"->",
"h",
"*",
"3600",
"+",
"$",
"this",
"->",
"i",
"*",
"60",
"+",
"$",
"this",
"->",
"s",
";",
"}"
] |
Get the total number of seconds from the DateInterval.
@return integer
|
[
"Get",
"the",
"total",
"number",
"of",
"seconds",
"from",
"the",
"DateInterval",
"."
] |
train
|
https://github.com/dragosprotung/stc-core/blob/9783e3414294f4ee555a1d538d2807269deeb9e7/src/Date/DateInterval.php#L17-L20
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/ProtectedResource.php
|
ProtectedResource.negotiateMimeType
|
public function negotiateMimeType(Request $request, Response $response): bool
{
return $this->actualResource->negotiateMimeType($request, $response);
}
|
php
|
public function negotiateMimeType(Request $request, Response $response): bool
{
return $this->actualResource->negotiateMimeType($request, $response);
}
|
[
"public",
"function",
"negotiateMimeType",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"actualResource",
"->",
"negotiateMimeType",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] |
negotiates proper mime type for given request
@param \stubbles\webapp\Request $request
@param \stubbles\webapp\Response $response response to send
@return bool
@since 6.0.0
|
[
"negotiates",
"proper",
"mime",
"type",
"for",
"given",
"request"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/ProtectedResource.php#L99-L102
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/ProtectedResource.php
|
ProtectedResource.applyPreInterceptors
|
public function applyPreInterceptors(Request $request, Response $response): bool
{
if ($this->isAuthorized($request, $response)) {
return $this->actualResource->applyPreInterceptors($request, $response);
}
return true;
}
|
php
|
public function applyPreInterceptors(Request $request, Response $response): bool
{
if ($this->isAuthorized($request, $response)) {
return $this->actualResource->applyPreInterceptors($request, $response);
}
return true;
}
|
[
"public",
"function",
"applyPreInterceptors",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"isAuthorized",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
"{",
"return",
"$",
"this",
"->",
"actualResource",
"->",
"applyPreInterceptors",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
apply pre interceptors
Pre interceptors for actual resource are only applied when request is
authorized.
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@return bool
|
[
"apply",
"pre",
"interceptors"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/ProtectedResource.php#L124-L131
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/ProtectedResource.php
|
ProtectedResource.isAuthorized
|
private function isAuthorized(Request $request, Response $response): bool
{
$this->authorized = false;
$user = $this->authenticate($request, $response);
if (null !== $user && $this->authConstraint->requiresRoles()) {
$roles = $this->roles($response, $user);
if (null !== $roles && $this->authConstraint->satisfiedByRoles($roles)) {
$request->associate(new Identity($user, $roles));
$this->authorized = true;
} elseif (null !== $roles) {
$this->error = $response->forbidden();
}
} elseif (null !== $user) {
$request->associate(new Identity($user, Roles::none()));
$this->authorized = true;
}
return $this->authorized;
}
|
php
|
private function isAuthorized(Request $request, Response $response): bool
{
$this->authorized = false;
$user = $this->authenticate($request, $response);
if (null !== $user && $this->authConstraint->requiresRoles()) {
$roles = $this->roles($response, $user);
if (null !== $roles && $this->authConstraint->satisfiedByRoles($roles)) {
$request->associate(new Identity($user, $roles));
$this->authorized = true;
} elseif (null !== $roles) {
$this->error = $response->forbidden();
}
} elseif (null !== $user) {
$request->associate(new Identity($user, Roles::none()));
$this->authorized = true;
}
return $this->authorized;
}
|
[
"private",
"function",
"isAuthorized",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"authorized",
"=",
"false",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"authenticate",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"user",
"&&",
"$",
"this",
"->",
"authConstraint",
"->",
"requiresRoles",
"(",
")",
")",
"{",
"$",
"roles",
"=",
"$",
"this",
"->",
"roles",
"(",
"$",
"response",
",",
"$",
"user",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"roles",
"&&",
"$",
"this",
"->",
"authConstraint",
"->",
"satisfiedByRoles",
"(",
"$",
"roles",
")",
")",
"{",
"$",
"request",
"->",
"associate",
"(",
"new",
"Identity",
"(",
"$",
"user",
",",
"$",
"roles",
")",
")",
";",
"$",
"this",
"->",
"authorized",
"=",
"true",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"roles",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"$",
"response",
"->",
"forbidden",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"user",
")",
"{",
"$",
"request",
"->",
"associate",
"(",
"new",
"Identity",
"(",
"$",
"user",
",",
"Roles",
"::",
"none",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"authorized",
"=",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"authorized",
";",
"}"
] |
checks if request is authorized
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@return bool
|
[
"checks",
"if",
"request",
"is",
"authorized"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/ProtectedResource.php#L140-L158
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/ProtectedResource.php
|
ProtectedResource.authenticate
|
private function authenticate(Request $request, Response $response)
{
$authenticationProvider = $this->injector->getInstance(AuthenticationProvider::class);
try {
$user = $authenticationProvider->authenticate($request);
if (null == $user && $this->authConstraint->loginAllowed()) {
$response->redirect($authenticationProvider->loginUri($request));
} elseif (null == $user) {
// TODO should become 401 Unauthorized
// see https://github.com/stubbles/stubbles-webapp-core/issues/73
$this->error = $response->forbidden();
return null;
}
return $user;
} catch (AuthProviderException $ahe) {
$this->handleAuthProviderException($ahe, $response);
return null;
}
}
|
php
|
private function authenticate(Request $request, Response $response)
{
$authenticationProvider = $this->injector->getInstance(AuthenticationProvider::class);
try {
$user = $authenticationProvider->authenticate($request);
if (null == $user && $this->authConstraint->loginAllowed()) {
$response->redirect($authenticationProvider->loginUri($request));
} elseif (null == $user) {
// TODO should become 401 Unauthorized
// see https://github.com/stubbles/stubbles-webapp-core/issues/73
$this->error = $response->forbidden();
return null;
}
return $user;
} catch (AuthProviderException $ahe) {
$this->handleAuthProviderException($ahe, $response);
return null;
}
}
|
[
"private",
"function",
"authenticate",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"authenticationProvider",
"=",
"$",
"this",
"->",
"injector",
"->",
"getInstance",
"(",
"AuthenticationProvider",
"::",
"class",
")",
";",
"try",
"{",
"$",
"user",
"=",
"$",
"authenticationProvider",
"->",
"authenticate",
"(",
"$",
"request",
")",
";",
"if",
"(",
"null",
"==",
"$",
"user",
"&&",
"$",
"this",
"->",
"authConstraint",
"->",
"loginAllowed",
"(",
")",
")",
"{",
"$",
"response",
"->",
"redirect",
"(",
"$",
"authenticationProvider",
"->",
"loginUri",
"(",
"$",
"request",
")",
")",
";",
"}",
"elseif",
"(",
"null",
"==",
"$",
"user",
")",
"{",
"// TODO should become 401 Unauthorized",
"// see https://github.com/stubbles/stubbles-webapp-core/issues/73",
"$",
"this",
"->",
"error",
"=",
"$",
"response",
"->",
"forbidden",
"(",
")",
";",
"return",
"null",
";",
"}",
"return",
"$",
"user",
";",
"}",
"catch",
"(",
"AuthProviderException",
"$",
"ahe",
")",
"{",
"$",
"this",
"->",
"handleAuthProviderException",
"(",
"$",
"ahe",
",",
"$",
"response",
")",
";",
"return",
"null",
";",
"}",
"}"
] |
checks whether request is authenticated
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@return \stubbles\webapp\auth\User|null
|
[
"checks",
"whether",
"request",
"is",
"authenticated"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/ProtectedResource.php#L167-L186
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/ProtectedResource.php
|
ProtectedResource.roles
|
private function roles(Response $response, User $user)
{
try {
return $this->injector->getInstance(AuthorizationProvider::class)
->roles($user);
} catch (AuthProviderException $ahe) {
$this->handleAuthProviderException($ahe, $response);
return null;
}
}
|
php
|
private function roles(Response $response, User $user)
{
try {
return $this->injector->getInstance(AuthorizationProvider::class)
->roles($user);
} catch (AuthProviderException $ahe) {
$this->handleAuthProviderException($ahe, $response);
return null;
}
}
|
[
"private",
"function",
"roles",
"(",
"Response",
"$",
"response",
",",
"User",
"$",
"user",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"injector",
"->",
"getInstance",
"(",
"AuthorizationProvider",
"::",
"class",
")",
"->",
"roles",
"(",
"$",
"user",
")",
";",
"}",
"catch",
"(",
"AuthProviderException",
"$",
"ahe",
")",
"{",
"$",
"this",
"->",
"handleAuthProviderException",
"(",
"$",
"ahe",
",",
"$",
"response",
")",
";",
"return",
"null",
";",
"}",
"}"
] |
checks whether expected role is given
@param \stubbles\webapp\Response $response response to send
@param \stubbles\webapp\auth\User $user
@return \stubbles\webapp\auth\Roles|null
|
[
"checks",
"whether",
"expected",
"role",
"is",
"given"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/ProtectedResource.php#L195-L204
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/ProtectedResource.php
|
ProtectedResource.handleAuthProviderException
|
private function handleAuthProviderException(AuthProviderException $ahe, Response $response)
{
if ($ahe->isInternal()) {
$this->error = $response->internalServerError($ahe);
} else {
$response->setStatusCode($ahe->getCode());
$this->error = new Error($ahe->getMessage());
}
}
|
php
|
private function handleAuthProviderException(AuthProviderException $ahe, Response $response)
{
if ($ahe->isInternal()) {
$this->error = $response->internalServerError($ahe);
} else {
$response->setStatusCode($ahe->getCode());
$this->error = new Error($ahe->getMessage());
}
}
|
[
"private",
"function",
"handleAuthProviderException",
"(",
"AuthProviderException",
"$",
"ahe",
",",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"ahe",
"->",
"isInternal",
"(",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"$",
"response",
"->",
"internalServerError",
"(",
"$",
"ahe",
")",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"setStatusCode",
"(",
"$",
"ahe",
"->",
"getCode",
"(",
")",
")",
";",
"$",
"this",
"->",
"error",
"=",
"new",
"Error",
"(",
"$",
"ahe",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
sets proper response status code depending on exception
@param \stubbles\webapp\auth\AuthProviderException $ahe
@param \stubbles\webapp\Response $response
|
[
"sets",
"proper",
"response",
"status",
"code",
"depending",
"on",
"exception"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/ProtectedResource.php#L212-L220
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/ProtectedResource.php
|
ProtectedResource.resolve
|
public function resolve(Request $request, Response $response)
{
if ($this->authorized) {
return $this->actualResource->resolve($request, $response);
}
return $this->error;
}
|
php
|
public function resolve(Request $request, Response $response)
{
if ($this->authorized) {
return $this->actualResource->resolve($request, $response);
}
return $this->error;
}
|
[
"public",
"function",
"resolve",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"authorized",
")",
"{",
"return",
"$",
"this",
"->",
"actualResource",
"->",
"resolve",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"return",
"$",
"this",
"->",
"error",
";",
"}"
] |
creates processor instance
Resolving of actual resource is only done when request is authorized.
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@return mixed
|
[
"creates",
"processor",
"instance"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/ProtectedResource.php#L231-L238
|
stubbles/stubbles-webapp-core
|
src/main/php/auth/ProtectedResource.php
|
ProtectedResource.applyPostInterceptors
|
public function applyPostInterceptors(Request $request, Response $response): bool
{
return $this->actualResource->applyPostInterceptors($request, $response);
}
|
php
|
public function applyPostInterceptors(Request $request, Response $response): bool
{
return $this->actualResource->applyPostInterceptors($request, $response);
}
|
[
"public",
"function",
"applyPostInterceptors",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"actualResource",
"->",
"applyPostInterceptors",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] |
apply post interceptors
Post interceptors of actual resource are applied independent of whether
request was authorized or not.
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@return bool
|
[
"apply",
"post",
"interceptors"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/ProtectedResource.php#L250-L253
|
delboy1978uk/form
|
src/Field/FieldAbstract.php
|
FieldAbstract.isValid
|
public function isValid()
{
$this->errorMessages = [];
$this->validatorCollection->rewind();
while ($this->validatorCollection->valid()) {
$this->checkForErrors($this->validatorCollection->current());
$this->validatorCollection->next();
}
$count = count($this->errorMessages);
return $count == 0;
}
|
php
|
public function isValid()
{
$this->errorMessages = [];
$this->validatorCollection->rewind();
while ($this->validatorCollection->valid()) {
$this->checkForErrors($this->validatorCollection->current());
$this->validatorCollection->next();
}
$count = count($this->errorMessages);
return $count == 0;
}
|
[
"public",
"function",
"isValid",
"(",
")",
"{",
"$",
"this",
"->",
"errorMessages",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"validatorCollection",
"->",
"rewind",
"(",
")",
";",
"while",
"(",
"$",
"this",
"->",
"validatorCollection",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"checkForErrors",
"(",
"$",
"this",
"->",
"validatorCollection",
"->",
"current",
"(",
")",
")",
";",
"$",
"this",
"->",
"validatorCollection",
"->",
"next",
"(",
")",
";",
"}",
"$",
"count",
"=",
"count",
"(",
"$",
"this",
"->",
"errorMessages",
")",
";",
"return",
"$",
"count",
"==",
"0",
";",
"}"
] |
Runs the checkForErrors method for each field, which adds to errorMessages if invalid
@return bool
@throws Exception If validation of $value is impossible
|
[
"Runs",
"the",
"checkForErrors",
"method",
"for",
"each",
"field",
"which",
"adds",
"to",
"errorMessages",
"if",
"invalid"
] |
train
|
https://github.com/delboy1978uk/form/blob/fbbb042d95deef4603a19edf08c0497f720398a6/src/Field/FieldAbstract.php#L184-L194
|
ekyna/GlsUniBox
|
Api/Client.php
|
Client.send
|
public function send(Request $request)
{
$request->configure($this->config);
$httpClient = new \GuzzleHttp\Client();
$r = $httpClient->request('POST', $this->getUrl(), [
'body' => \GuzzleHttp\Psr7\stream_for((string) $request),
]);
return Response::create($r->getBody()->getContents());
}
|
php
|
public function send(Request $request)
{
$request->configure($this->config);
$httpClient = new \GuzzleHttp\Client();
$r = $httpClient->request('POST', $this->getUrl(), [
'body' => \GuzzleHttp\Psr7\stream_for((string) $request),
]);
return Response::create($r->getBody()->getContents());
}
|
[
"public",
"function",
"send",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"request",
"->",
"configure",
"(",
"$",
"this",
"->",
"config",
")",
";",
"$",
"httpClient",
"=",
"new",
"\\",
"GuzzleHttp",
"\\",
"Client",
"(",
")",
";",
"$",
"r",
"=",
"$",
"httpClient",
"->",
"request",
"(",
"'POST'",
",",
"$",
"this",
"->",
"getUrl",
"(",
")",
",",
"[",
"'body'",
"=>",
"\\",
"GuzzleHttp",
"\\",
"Psr7",
"\\",
"stream_for",
"(",
"(",
"string",
")",
"$",
"request",
")",
",",
"]",
")",
";",
"return",
"Response",
"::",
"create",
"(",
"$",
"r",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
")",
";",
"}"
] |
Sends the request.
@param Request $request
@return Response
|
[
"Sends",
"the",
"request",
"."
] |
train
|
https://github.com/ekyna/GlsUniBox/blob/b474271ba355c3917074422306dc64abf09584d0/Api/Client.php#L67-L78
|
ekyna/GlsUniBox
|
Api/Client.php
|
Client.getUrl
|
private function getUrl()
{
if ($this->mode === static::MODE_PROD) {
$url = static::URL_PROD;
} elseif ($this->mode === static::MODE_CONSIGNMENT) {
$url = static::URL_CONSIGNMENT;
} else {
$url = static::URL_TEST;
}
return 'http' . ($this->secured ? 's' : '') . '://' . $url;
}
|
php
|
private function getUrl()
{
if ($this->mode === static::MODE_PROD) {
$url = static::URL_PROD;
} elseif ($this->mode === static::MODE_CONSIGNMENT) {
$url = static::URL_CONSIGNMENT;
} else {
$url = static::URL_TEST;
}
return 'http' . ($this->secured ? 's' : '') . '://' . $url;
}
|
[
"private",
"function",
"getUrl",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"mode",
"===",
"static",
"::",
"MODE_PROD",
")",
"{",
"$",
"url",
"=",
"static",
"::",
"URL_PROD",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"mode",
"===",
"static",
"::",
"MODE_CONSIGNMENT",
")",
"{",
"$",
"url",
"=",
"static",
"::",
"URL_CONSIGNMENT",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"static",
"::",
"URL_TEST",
";",
"}",
"return",
"'http'",
".",
"(",
"$",
"this",
"->",
"secured",
"?",
"'s'",
":",
"''",
")",
".",
"'://'",
".",
"$",
"url",
";",
"}"
] |
Returns the endpoint url.
@return string
|
[
"Returns",
"the",
"endpoint",
"url",
"."
] |
train
|
https://github.com/ekyna/GlsUniBox/blob/b474271ba355c3917074422306dc64abf09584d0/Api/Client.php#L85-L96
|
movoin/one-swoole
|
src/Support/Collection.php
|
Collection.replace
|
public function replace(array $items = [])
{
$this->items = [];
foreach ($items as $key => $item) {
$this->set($key, $item);
}
}
|
php
|
public function replace(array $items = [])
{
$this->items = [];
foreach ($items as $key => $item) {
$this->set($key, $item);
}
}
|
[
"public",
"function",
"replace",
"(",
"array",
"$",
"items",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"item",
")",
";",
"}",
"}"
] |
替换所有数据
@param array $items
|
[
"替换所有数据"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Collection.php#L71-L78
|
movoin/one-swoole
|
src/Support/Collection.php
|
Collection.update
|
public function update(array $items = [])
{
foreach ($items as $key => $item) {
$this->set($key, $item);
}
}
|
php
|
public function update(array $items = [])
{
foreach ($items as $key => $item) {
$this->set($key, $item);
}
}
|
[
"public",
"function",
"update",
"(",
"array",
"$",
"items",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"item",
")",
";",
"}",
"}"
] |
更新数据
@param array $items
|
[
"更新数据"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Collection.php#L85-L90
|
movoin/one-swoole
|
src/Support/Collection.php
|
Collection.get
|
public function get(string $key, $default = null)
{
return ($value = $this->offsetGet($key)) === null ? $default : $value;
}
|
php
|
public function get(string $key, $default = null)
{
return ($value = $this->offsetGet($key)) === null ? $default : $value;
}
|
[
"public",
"function",
"get",
"(",
"string",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"return",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"key",
")",
")",
"===",
"null",
"?",
"$",
"default",
":",
"$",
"value",
";",
"}"
] |
返回指定数据项
@param string $key
@param mixed $default
@return mixed
|
[
"返回指定数据项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Collection.php#L161-L164
|
movoin/one-swoole
|
src/Support/Collection.php
|
Collection.getByValue
|
public function getByValue(string $key, $value)
{
return array_filter($this->items, function ($val) use ($key, $value) {
return $val[$this->normalizeKey($key)] === $value;
});
}
|
php
|
public function getByValue(string $key, $value)
{
return array_filter($this->items, function ($val) use ($key, $value) {
return $val[$this->normalizeKey($key)] === $value;
});
}
|
[
"public",
"function",
"getByValue",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"items",
",",
"function",
"(",
"$",
"val",
")",
"use",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"return",
"$",
"val",
"[",
"$",
"this",
"->",
"normalizeKey",
"(",
"$",
"key",
")",
"]",
"===",
"$",
"value",
";",
"}",
")",
";",
"}"
] |
返回与指定键名的值相符的数据
@param string $key
@param mixed $value
@return mixed
|
[
"返回与指定键名的值相符的数据"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Collection.php#L174-L179
|
movoin/one-swoole
|
src/Support/Collection.php
|
Collection.normalizeValue
|
public function normalizeValue($item)
{
if (is_array($item)) {
$normalized = [];
foreach ($item as $key => $value) {
$key = $this->recursive ? $this->normalizeKey($key) : $key;
if (is_array($value)) {
$normalized[$key] = $this->normalizeValue($value);
} elseif ($value instanceof \stdClass) {
$normalized[$key] = $this->normalizeValue(
Arr::convertFromStdClass($value)
);
} else {
$normalized[$key] = $value;
}
}
} elseif ($item instanceof \stdClass) {
$normalized = $this->normalizeValue(
Arr::convertFromStdClass($item)
);
} else {
$normalized = $item;
}
return $normalized;
}
|
php
|
public function normalizeValue($item)
{
if (is_array($item)) {
$normalized = [];
foreach ($item as $key => $value) {
$key = $this->recursive ? $this->normalizeKey($key) : $key;
if (is_array($value)) {
$normalized[$key] = $this->normalizeValue($value);
} elseif ($value instanceof \stdClass) {
$normalized[$key] = $this->normalizeValue(
Arr::convertFromStdClass($value)
);
} else {
$normalized[$key] = $value;
}
}
} elseif ($item instanceof \stdClass) {
$normalized = $this->normalizeValue(
Arr::convertFromStdClass($item)
);
} else {
$normalized = $item;
}
return $normalized;
}
|
[
"public",
"function",
"normalizeValue",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"$",
"normalized",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"item",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"recursive",
"?",
"$",
"this",
"->",
"normalizeKey",
"(",
"$",
"key",
")",
":",
"$",
"key",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"normalized",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"normalizeValue",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"\\",
"stdClass",
")",
"{",
"$",
"normalized",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"normalizeValue",
"(",
"Arr",
"::",
"convertFromStdClass",
"(",
"$",
"value",
")",
")",
";",
"}",
"else",
"{",
"$",
"normalized",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"item",
"instanceof",
"\\",
"stdClass",
")",
"{",
"$",
"normalized",
"=",
"$",
"this",
"->",
"normalizeValue",
"(",
"Arr",
"::",
"convertFromStdClass",
"(",
"$",
"item",
")",
")",
";",
"}",
"else",
"{",
"$",
"normalized",
"=",
"$",
"item",
";",
"}",
"return",
"$",
"normalized",
";",
"}"
] |
标准化键值
@param mixed $item
@return mixed
|
[
"标准化键值"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Collection.php#L263-L290
|
movoin/one-swoole
|
src/Support/Collection.php
|
Collection.offsetSet
|
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->items[] = $this->normalizeValue($value);
} else {
$this->items[$this->normalizeKey($offset)] = $this->normalizeValue($value);
}
}
|
php
|
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->items[] = $this->normalizeValue($value);
} else {
$this->items[$this->normalizeKey($offset)] = $this->normalizeValue($value);
}
}
|
[
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"offset",
")",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"]",
"=",
"$",
"this",
"->",
"normalizeValue",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"items",
"[",
"$",
"this",
"->",
"normalizeKey",
"(",
"$",
"offset",
")",
"]",
"=",
"$",
"this",
"->",
"normalizeValue",
"(",
"$",
"value",
")",
";",
"}",
"}"
] |
设置数据项
@param mixed $offset
@param mixed $value
|
[
"设置数据项"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Support/Collection.php#L298-L305
|
tjbp/laravel-verify-emails
|
src/Auth/Console/MakeVerifyEmailsCommand.php
|
MakeVerifyEmailsCommand.fire
|
public function fire()
{
$this->createDirectories();
$this->exportViews();
$this->info('Installed EmailController.');
copy(__DIR__.'/stubs/make/controllers/EmailController.stub', app_path('Http/Controllers/Auth/EmailController.php'));
$this->info('Updated routes file.');
file_put_contents(
app_path('Http/routes.php'),
file_get_contents(__DIR__.'/stubs/make/routes.stub'),
FILE_APPEND
);
$this->info('Added language lines.');
copy(__DIR__.'/stubs/make/lang/en/verify_emails.stub', base_path('resources/lang/en/verify_emails.php'));
$this->comment('Email verification scaffolding generated successfully!');
}
|
php
|
public function fire()
{
$this->createDirectories();
$this->exportViews();
$this->info('Installed EmailController.');
copy(__DIR__.'/stubs/make/controllers/EmailController.stub', app_path('Http/Controllers/Auth/EmailController.php'));
$this->info('Updated routes file.');
file_put_contents(
app_path('Http/routes.php'),
file_get_contents(__DIR__.'/stubs/make/routes.stub'),
FILE_APPEND
);
$this->info('Added language lines.');
copy(__DIR__.'/stubs/make/lang/en/verify_emails.stub', base_path('resources/lang/en/verify_emails.php'));
$this->comment('Email verification scaffolding generated successfully!');
}
|
[
"public",
"function",
"fire",
"(",
")",
"{",
"$",
"this",
"->",
"createDirectories",
"(",
")",
";",
"$",
"this",
"->",
"exportViews",
"(",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Installed EmailController.'",
")",
";",
"copy",
"(",
"__DIR__",
".",
"'/stubs/make/controllers/EmailController.stub'",
",",
"app_path",
"(",
"'Http/Controllers/Auth/EmailController.php'",
")",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Updated routes file.'",
")",
";",
"file_put_contents",
"(",
"app_path",
"(",
"'Http/routes.php'",
")",
",",
"file_get_contents",
"(",
"__DIR__",
".",
"'/stubs/make/routes.stub'",
")",
",",
"FILE_APPEND",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Added language lines.'",
")",
";",
"copy",
"(",
"__DIR__",
".",
"'/stubs/make/lang/en/verify_emails.stub'",
",",
"base_path",
"(",
"'resources/lang/en/verify_emails.php'",
")",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'Email verification scaffolding generated successfully!'",
")",
";",
"}"
] |
Execute the console command.
@return void
|
[
"Execute",
"the",
"console",
"command",
"."
] |
train
|
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Auth/Console/MakeVerifyEmailsCommand.php#L38-L61
|
tjbp/laravel-verify-emails
|
src/Auth/Console/MakeVerifyEmailsCommand.php
|
MakeVerifyEmailsCommand.createDirectories
|
protected function createDirectories()
{
if (! is_dir(base_path('resources/views/auth/verify-emails'))) {
mkdir(base_path('resources/views/auth/verify-emails'), 0755, true);
}
if (! is_dir(base_path('resources/views/auth/emails'))) {
mkdir(base_path('resources/views/auth/emails'), 0755, true);
}
}
|
php
|
protected function createDirectories()
{
if (! is_dir(base_path('resources/views/auth/verify-emails'))) {
mkdir(base_path('resources/views/auth/verify-emails'), 0755, true);
}
if (! is_dir(base_path('resources/views/auth/emails'))) {
mkdir(base_path('resources/views/auth/emails'), 0755, true);
}
}
|
[
"protected",
"function",
"createDirectories",
"(",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"base_path",
"(",
"'resources/views/auth/verify-emails'",
")",
")",
")",
"{",
"mkdir",
"(",
"base_path",
"(",
"'resources/views/auth/verify-emails'",
")",
",",
"0755",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"base_path",
"(",
"'resources/views/auth/emails'",
")",
")",
")",
"{",
"mkdir",
"(",
"base_path",
"(",
"'resources/views/auth/emails'",
")",
",",
"0755",
",",
"true",
")",
";",
"}",
"}"
] |
Create the directories for the files.
@return void
|
[
"Create",
"the",
"directories",
"for",
"the",
"files",
"."
] |
train
|
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Auth/Console/MakeVerifyEmailsCommand.php#L68-L77
|
tjbp/laravel-verify-emails
|
src/Auth/Console/MakeVerifyEmailsCommand.php
|
MakeVerifyEmailsCommand.exportViews
|
protected function exportViews()
{
foreach ($this->views as $key => $value) {
$path = base_path('resources/views/'.$value);
$this->line('<info>Created View:</info> '.$path);
copy(__DIR__.'/stubs/make/views/'.$key, $path);
}
}
|
php
|
protected function exportViews()
{
foreach ($this->views as $key => $value) {
$path = base_path('resources/views/'.$value);
$this->line('<info>Created View:</info> '.$path);
copy(__DIR__.'/stubs/make/views/'.$key, $path);
}
}
|
[
"protected",
"function",
"exportViews",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"views",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"path",
"=",
"base_path",
"(",
"'resources/views/'",
".",
"$",
"value",
")",
";",
"$",
"this",
"->",
"line",
"(",
"'<info>Created View:</info> '",
".",
"$",
"path",
")",
";",
"copy",
"(",
"__DIR__",
".",
"'/stubs/make/views/'",
".",
"$",
"key",
",",
"$",
"path",
")",
";",
"}",
"}"
] |
Export the authentication views.
@return void
|
[
"Export",
"the",
"authentication",
"views",
"."
] |
train
|
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Auth/Console/MakeVerifyEmailsCommand.php#L84-L93
|
marmelab/phpcr-api
|
src/PHPCRAPI/PHPCR/AbstractCollection.php
|
AbstractCollection.remove
|
public function remove($name)
{
if (!array_key_exists($name, $this->items)) {
throw new CollectionUnknownKeyException(sprintf('Item name=%s does not exist in collection',$name));
}
unset($this->items[$name]);
return true;
}
|
php
|
public function remove($name)
{
if (!array_key_exists($name, $this->items)) {
throw new CollectionUnknownKeyException(sprintf('Item name=%s does not exist in collection',$name));
}
unset($this->items[$name]);
return true;
}
|
[
"public",
"function",
"remove",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"items",
")",
")",
"{",
"throw",
"new",
"CollectionUnknownKeyException",
"(",
"sprintf",
"(",
"'Item name=%s does not exist in collection'",
",",
"$",
"name",
")",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
";",
"return",
"true",
";",
"}"
] |
Remove an item from the collection
@param string $name The name of the item
@return boolean Returns true in case of success
@throws CollectionUnknownKeyException if the item does not exist in the collection
@api
|
[
"Remove",
"an",
"item",
"from",
"the",
"collection"
] |
train
|
https://github.com/marmelab/phpcr-api/blob/372149e27d45babe142d0546894362fce987729b/src/PHPCRAPI/PHPCR/AbstractCollection.php#L57-L66
|
marmelab/phpcr-api
|
src/PHPCRAPI/PHPCR/AbstractCollection.php
|
AbstractCollection.get
|
public function get($name)
{
if (!array_key_exists($name, $this->items)) {
throw new CollectionUnknownKeyException(sprintf('Item name=%s does not exist in collection',$name));
}
return $this->items[$name];
}
|
php
|
public function get($name)
{
if (!array_key_exists($name, $this->items)) {
throw new CollectionUnknownKeyException(sprintf('Item name=%s does not exist in collection',$name));
}
return $this->items[$name];
}
|
[
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"items",
")",
")",
"{",
"throw",
"new",
"CollectionUnknownKeyException",
"(",
"sprintf",
"(",
"'Item name=%s does not exist in collection'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
";",
"}"
] |
Get an item from the collection
@param string $name The name of the item
@return Repository The found item
@throws CollectionUnknownKeyException if the item does not exist in the collection
@api
|
[
"Get",
"an",
"item",
"from",
"the",
"collection"
] |
train
|
https://github.com/marmelab/phpcr-api/blob/372149e27d45babe142d0546894362fce987729b/src/PHPCRAPI/PHPCR/AbstractCollection.php#L79-L86
|
movoin/one-swoole
|
src/Protocol/Message/Cookies.php
|
Cookies.toArray
|
public function toArray(): array
{
$cookies = [];
foreach ($this->responseCookies as $key => $cookie) {
$cookie['expires'] = is_string($cookie['expires']) ?
strtotime($cookie['expires']) :
(int) $cookie['expires'];
$cookies[] = ['key' => $key] + $cookie;
}
return $cookies;
}
|
php
|
public function toArray(): array
{
$cookies = [];
foreach ($this->responseCookies as $key => $cookie) {
$cookie['expires'] = is_string($cookie['expires']) ?
strtotime($cookie['expires']) :
(int) $cookie['expires'];
$cookies[] = ['key' => $key] + $cookie;
}
return $cookies;
}
|
[
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"$",
"cookies",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"responseCookies",
"as",
"$",
"key",
"=>",
"$",
"cookie",
")",
"{",
"$",
"cookie",
"[",
"'expires'",
"]",
"=",
"is_string",
"(",
"$",
"cookie",
"[",
"'expires'",
"]",
")",
"?",
"strtotime",
"(",
"$",
"cookie",
"[",
"'expires'",
"]",
")",
":",
"(",
"int",
")",
"$",
"cookie",
"[",
"'expires'",
"]",
";",
"$",
"cookies",
"[",
"]",
"=",
"[",
"'key'",
"=>",
"$",
"key",
"]",
"+",
"$",
"cookie",
";",
"}",
"return",
"$",
"cookies",
";",
"}"
] |
获得 Cookies 数组
@return array
|
[
"获得",
"Cookies",
"数组"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Cookies.php#L98-L111
|
Srokap/code_review
|
classes/CodeReview/Analyzer.php
|
Analyzer.processFile
|
public function processFile($filePath, $functions) {
$result = array(
'problems' => array(),
'fixes' => array(),
);
$phpTokens = new PhpFileParser($filePath);
$changes = 0;
foreach ($phpTokens as $key => $row) {
// get non trivial tokens
if (is_array($row)) {
list($token, $functionName, $lineNumber) = $row;
$originalFunctionName = $functionName;
// prepare normalized version of function name for matching
$functionName = strtolower($functionName);
// check for function call
if ($token == T_STRING
&& !$phpTokens->isEqualToToken(T_OBJECT_OPERATOR, $key-1) //not method
&& !$phpTokens->isEqualToToken(T_DOUBLE_COLON, $key-1) //not static method
&& !$phpTokens->isEqualToToken(T_FUNCTION, $key-2) //not definition
) {
// mark function as called
if (function_exists($functionName) && !in_array($functionName, $this->calledFunctions)) {
$this->calledFunctions[] = $functionName;
}
// is it function we're looking for
if (isset($functions[$functionName])) {
$definingFunctionName = $phpTokens->getDefiningFunctionName($key);
//we're skipping deprecated calls that are in deprecated function itself
if (!$definingFunctionName || !isset($functions[strtolower($definingFunctionName)])) {
$result['problems'][] = array($functions[$functionName], $originalFunctionName, $lineNumber);
}
//do instant replacement
if ($this->fixProblems && isset($this->instantReplacements[$functionName])) {
$phpTokens[$key] = array(T_STRING, $this->instantReplacements[$functionName]);
$result['fixes'][] = array($originalFunctionName, $this->instantReplacements[$functionName], $lineNumber);
$changes++;
}
}
}
}
}
if ($changes) {
try {
$phpTokens->exportPhp($filePath);
} catch (\CodeReview\IOException $e) {
echo '*** Error: ' . $e->getMessage() . " ***\n";
}
}
unset($phpTokens);
return $result;
}
|
php
|
public function processFile($filePath, $functions) {
$result = array(
'problems' => array(),
'fixes' => array(),
);
$phpTokens = new PhpFileParser($filePath);
$changes = 0;
foreach ($phpTokens as $key => $row) {
// get non trivial tokens
if (is_array($row)) {
list($token, $functionName, $lineNumber) = $row;
$originalFunctionName = $functionName;
// prepare normalized version of function name for matching
$functionName = strtolower($functionName);
// check for function call
if ($token == T_STRING
&& !$phpTokens->isEqualToToken(T_OBJECT_OPERATOR, $key-1) //not method
&& !$phpTokens->isEqualToToken(T_DOUBLE_COLON, $key-1) //not static method
&& !$phpTokens->isEqualToToken(T_FUNCTION, $key-2) //not definition
) {
// mark function as called
if (function_exists($functionName) && !in_array($functionName, $this->calledFunctions)) {
$this->calledFunctions[] = $functionName;
}
// is it function we're looking for
if (isset($functions[$functionName])) {
$definingFunctionName = $phpTokens->getDefiningFunctionName($key);
//we're skipping deprecated calls that are in deprecated function itself
if (!$definingFunctionName || !isset($functions[strtolower($definingFunctionName)])) {
$result['problems'][] = array($functions[$functionName], $originalFunctionName, $lineNumber);
}
//do instant replacement
if ($this->fixProblems && isset($this->instantReplacements[$functionName])) {
$phpTokens[$key] = array(T_STRING, $this->instantReplacements[$functionName]);
$result['fixes'][] = array($originalFunctionName, $this->instantReplacements[$functionName], $lineNumber);
$changes++;
}
}
}
}
}
if ($changes) {
try {
$phpTokens->exportPhp($filePath);
} catch (\CodeReview\IOException $e) {
echo '*** Error: ' . $e->getMessage() . " ***\n";
}
}
unset($phpTokens);
return $result;
}
|
[
"public",
"function",
"processFile",
"(",
"$",
"filePath",
",",
"$",
"functions",
")",
"{",
"$",
"result",
"=",
"array",
"(",
"'problems'",
"=>",
"array",
"(",
")",
",",
"'fixes'",
"=>",
"array",
"(",
")",
",",
")",
";",
"$",
"phpTokens",
"=",
"new",
"PhpFileParser",
"(",
"$",
"filePath",
")",
";",
"$",
"changes",
"=",
"0",
";",
"foreach",
"(",
"$",
"phpTokens",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"// get non trivial tokens",
"if",
"(",
"is_array",
"(",
"$",
"row",
")",
")",
"{",
"list",
"(",
"$",
"token",
",",
"$",
"functionName",
",",
"$",
"lineNumber",
")",
"=",
"$",
"row",
";",
"$",
"originalFunctionName",
"=",
"$",
"functionName",
";",
"// prepare normalized version of function name for matching",
"$",
"functionName",
"=",
"strtolower",
"(",
"$",
"functionName",
")",
";",
"// check for function call",
"if",
"(",
"$",
"token",
"==",
"T_STRING",
"&&",
"!",
"$",
"phpTokens",
"->",
"isEqualToToken",
"(",
"T_OBJECT_OPERATOR",
",",
"$",
"key",
"-",
"1",
")",
"//not method",
"&&",
"!",
"$",
"phpTokens",
"->",
"isEqualToToken",
"(",
"T_DOUBLE_COLON",
",",
"$",
"key",
"-",
"1",
")",
"//not static method",
"&&",
"!",
"$",
"phpTokens",
"->",
"isEqualToToken",
"(",
"T_FUNCTION",
",",
"$",
"key",
"-",
"2",
")",
"//not definition",
")",
"{",
"// mark function as called",
"if",
"(",
"function_exists",
"(",
"$",
"functionName",
")",
"&&",
"!",
"in_array",
"(",
"$",
"functionName",
",",
"$",
"this",
"->",
"calledFunctions",
")",
")",
"{",
"$",
"this",
"->",
"calledFunctions",
"[",
"]",
"=",
"$",
"functionName",
";",
"}",
"// is it function we're looking for",
"if",
"(",
"isset",
"(",
"$",
"functions",
"[",
"$",
"functionName",
"]",
")",
")",
"{",
"$",
"definingFunctionName",
"=",
"$",
"phpTokens",
"->",
"getDefiningFunctionName",
"(",
"$",
"key",
")",
";",
"//we're skipping deprecated calls that are in deprecated function itself",
"if",
"(",
"!",
"$",
"definingFunctionName",
"||",
"!",
"isset",
"(",
"$",
"functions",
"[",
"strtolower",
"(",
"$",
"definingFunctionName",
")",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'problems'",
"]",
"[",
"]",
"=",
"array",
"(",
"$",
"functions",
"[",
"$",
"functionName",
"]",
",",
"$",
"originalFunctionName",
",",
"$",
"lineNumber",
")",
";",
"}",
"//do instant replacement",
"if",
"(",
"$",
"this",
"->",
"fixProblems",
"&&",
"isset",
"(",
"$",
"this",
"->",
"instantReplacements",
"[",
"$",
"functionName",
"]",
")",
")",
"{",
"$",
"phpTokens",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"T_STRING",
",",
"$",
"this",
"->",
"instantReplacements",
"[",
"$",
"functionName",
"]",
")",
";",
"$",
"result",
"[",
"'fixes'",
"]",
"[",
"]",
"=",
"array",
"(",
"$",
"originalFunctionName",
",",
"$",
"this",
"->",
"instantReplacements",
"[",
"$",
"functionName",
"]",
",",
"$",
"lineNumber",
")",
";",
"$",
"changes",
"++",
";",
"}",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"changes",
")",
"{",
"try",
"{",
"$",
"phpTokens",
"->",
"exportPhp",
"(",
"$",
"filePath",
")",
";",
"}",
"catch",
"(",
"\\",
"CodeReview",
"\\",
"IOException",
"$",
"e",
")",
"{",
"echo",
"'*** Error: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"\" ***\\n\"",
";",
"}",
"}",
"unset",
"(",
"$",
"phpTokens",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Find function calls and extract
@param string $filePath
@param array $functions
@return array
|
[
"Find",
"function",
"calls",
"and",
"extract"
] |
train
|
https://github.com/Srokap/code_review/blob/c79c619f99279cf15713b118ae19b0ef017db362/classes/CodeReview/Analyzer.php#L224-L278
|
vardius/list-bundle
|
View/Renderer.php
|
Renderer.renderView
|
public function renderView(string $view, array $params = []):string
{
$template = null;
if ($this->templating->exists($this->getTemplateName())) {
$template = $this->getTemplateName();
}
$viewPath = $view;
if ($template === null && $viewPath) {
$templateDir = $viewPath . $this->getTemplateName() . $this->templateEngine;
if ($this->templating->exists($templateDir)) {
$template = $templateDir;
}
}
if ($template === null) {
$templateDir = self::TEMPLATE_DIR . $this->getTemplateName() . $this->templateEngine;
if ($this->templating->exists($templateDir)) {
$template = $templateDir;
}
}
if ($template === null) {
throw new ResourceNotFoundException('Vardius\Bundle\ListBundle\View\Renderer: Wrong template path');
}
return $this->templating->render($template, $params);
}
|
php
|
public function renderView(string $view, array $params = []):string
{
$template = null;
if ($this->templating->exists($this->getTemplateName())) {
$template = $this->getTemplateName();
}
$viewPath = $view;
if ($template === null && $viewPath) {
$templateDir = $viewPath . $this->getTemplateName() . $this->templateEngine;
if ($this->templating->exists($templateDir)) {
$template = $templateDir;
}
}
if ($template === null) {
$templateDir = self::TEMPLATE_DIR . $this->getTemplateName() . $this->templateEngine;
if ($this->templating->exists($templateDir)) {
$template = $templateDir;
}
}
if ($template === null) {
throw new ResourceNotFoundException('Vardius\Bundle\ListBundle\View\Renderer: Wrong template path');
}
return $this->templating->render($template, $params);
}
|
[
"public",
"function",
"renderView",
"(",
"string",
"$",
"view",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"template",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"templating",
"->",
"exists",
"(",
"$",
"this",
"->",
"getTemplateName",
"(",
")",
")",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"getTemplateName",
"(",
")",
";",
"}",
"$",
"viewPath",
"=",
"$",
"view",
";",
"if",
"(",
"$",
"template",
"===",
"null",
"&&",
"$",
"viewPath",
")",
"{",
"$",
"templateDir",
"=",
"$",
"viewPath",
".",
"$",
"this",
"->",
"getTemplateName",
"(",
")",
".",
"$",
"this",
"->",
"templateEngine",
";",
"if",
"(",
"$",
"this",
"->",
"templating",
"->",
"exists",
"(",
"$",
"templateDir",
")",
")",
"{",
"$",
"template",
"=",
"$",
"templateDir",
";",
"}",
"}",
"if",
"(",
"$",
"template",
"===",
"null",
")",
"{",
"$",
"templateDir",
"=",
"self",
"::",
"TEMPLATE_DIR",
".",
"$",
"this",
"->",
"getTemplateName",
"(",
")",
".",
"$",
"this",
"->",
"templateEngine",
";",
"if",
"(",
"$",
"this",
"->",
"templating",
"->",
"exists",
"(",
"$",
"templateDir",
")",
")",
"{",
"$",
"template",
"=",
"$",
"templateDir",
";",
"}",
"}",
"if",
"(",
"$",
"template",
"===",
"null",
")",
"{",
"throw",
"new",
"ResourceNotFoundException",
"(",
"'Vardius\\Bundle\\ListBundle\\View\\Renderer: Wrong template path'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"templating",
"->",
"render",
"(",
"$",
"template",
",",
"$",
"params",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vardius/list-bundle/blob/70d3079ce22eed7dad7c467fee532aa2f18c68c9/View/Renderer.php#L41-L68
|
faustbrian/Laravel-Countries
|
src/Console/Commands/SeedTimezones.php
|
SeedTimezones.handle
|
public function handle()
{
foreach ($this->getModel()->all() as $country) {
$timezones = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country->cca2);
foreach ($timezones as $timezone) {
$country->timezones()->create([
'name' => $timezone,
'offset_gmt' => $this->offsetGmt($timezone),
'offset_hours' => $this->offsetHours($timezone),
'offset_seconds' => $this->offsetSeconds($timezone),
]);
}
}
$this->getOutput()->writeln('<info>Seeded:</info> Countries > Timezones');
}
|
php
|
public function handle()
{
foreach ($this->getModel()->all() as $country) {
$timezones = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country->cca2);
foreach ($timezones as $timezone) {
$country->timezones()->create([
'name' => $timezone,
'offset_gmt' => $this->offsetGmt($timezone),
'offset_hours' => $this->offsetHours($timezone),
'offset_seconds' => $this->offsetSeconds($timezone),
]);
}
}
$this->getOutput()->writeln('<info>Seeded:</info> Countries > Timezones');
}
|
[
"public",
"function",
"handle",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"all",
"(",
")",
"as",
"$",
"country",
")",
"{",
"$",
"timezones",
"=",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
"DateTimeZone",
"::",
"PER_COUNTRY",
",",
"$",
"country",
"->",
"cca2",
")",
";",
"foreach",
"(",
"$",
"timezones",
"as",
"$",
"timezone",
")",
"{",
"$",
"country",
"->",
"timezones",
"(",
")",
"->",
"create",
"(",
"[",
"'name'",
"=>",
"$",
"timezone",
",",
"'offset_gmt'",
"=>",
"$",
"this",
"->",
"offsetGmt",
"(",
"$",
"timezone",
")",
",",
"'offset_hours'",
"=>",
"$",
"this",
"->",
"offsetHours",
"(",
"$",
"timezone",
")",
",",
"'offset_seconds'",
"=>",
"$",
"this",
"->",
"offsetSeconds",
"(",
"$",
"timezone",
")",
",",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"getOutput",
"(",
")",
"->",
"writeln",
"(",
"'<info>Seeded:</info> Countries > Timezones'",
")",
";",
"}"
] |
Execute the console command.
@return mixed
|
[
"Execute",
"the",
"console",
"command",
"."
] |
train
|
https://github.com/faustbrian/Laravel-Countries/blob/3d72301acd37e7f351d9b991dba41807ab68362b/src/Console/Commands/SeedTimezones.php#L42-L58
|
faustbrian/Laravel-Countries
|
src/Console/Commands/SeedTimezones.php
|
SeedTimezones.offsetGmt
|
private function offsetGmt(string $timezone): string
{
$offset = $this->offsetSeconds($timezone);
$offset = gmdate('H:i', (int) $offset);
return 'GMT'.($offset < 0 ? $offset : '+'.$offset);
}
|
php
|
private function offsetGmt(string $timezone): string
{
$offset = $this->offsetSeconds($timezone);
$offset = gmdate('H:i', (int) $offset);
return 'GMT'.($offset < 0 ? $offset : '+'.$offset);
}
|
[
"private",
"function",
"offsetGmt",
"(",
"string",
"$",
"timezone",
")",
":",
"string",
"{",
"$",
"offset",
"=",
"$",
"this",
"->",
"offsetSeconds",
"(",
"$",
"timezone",
")",
";",
"$",
"offset",
"=",
"gmdate",
"(",
"'H:i'",
",",
"(",
"int",
")",
"$",
"offset",
")",
";",
"return",
"'GMT'",
".",
"(",
"$",
"offset",
"<",
"0",
"?",
"$",
"offset",
":",
"'+'",
".",
"$",
"offset",
")",
";",
"}"
] |
[offsetGmt description].
@param string $timezone
@return string
|
[
"[",
"offsetGmt",
"description",
"]",
"."
] |
train
|
https://github.com/faustbrian/Laravel-Countries/blob/3d72301acd37e7f351d9b991dba41807ab68362b/src/Console/Commands/SeedTimezones.php#L67-L73
|
faustbrian/Laravel-Countries
|
src/Console/Commands/SeedTimezones.php
|
SeedTimezones.offsetSeconds
|
private function offsetSeconds(string $timezone): float
{
$dtz = new DateTimeZone($timezone);
return $dtz->getOffset(new DateTime('now', $dtz));
}
|
php
|
private function offsetSeconds(string $timezone): float
{
$dtz = new DateTimeZone($timezone);
return $dtz->getOffset(new DateTime('now', $dtz));
}
|
[
"private",
"function",
"offsetSeconds",
"(",
"string",
"$",
"timezone",
")",
":",
"float",
"{",
"$",
"dtz",
"=",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
";",
"return",
"$",
"dtz",
"->",
"getOffset",
"(",
"new",
"DateTime",
"(",
"'now'",
",",
"$",
"dtz",
")",
")",
";",
"}"
] |
[offsetSeconds description].
@param string $timezone
@return int
|
[
"[",
"offsetSeconds",
"description",
"]",
"."
] |
train
|
https://github.com/faustbrian/Laravel-Countries/blob/3d72301acd37e7f351d9b991dba41807ab68362b/src/Console/Commands/SeedTimezones.php#L94-L99
|
pageon/SlackWebhookMonolog
|
src/Slack/Channel.php
|
Channel.setName
|
private function setName($name)
{
// names should be lowercase so we just enforce this without further validation
$name = trim(mb_strtolower($name, 'UTF8'));
if (!preg_match('_^[#@][\w-]{1,21}$_', $name)) {
throw new InvalidChannelException(
'Channel names must be all lowercase.
The name should start with "#" for a channel or "@" for an account
They cannot be longer than 21 characters and can only contain letters, numbers, hyphens, and underscores.',
400
);
}
$this->name = $name;
}
|
php
|
private function setName($name)
{
// names should be lowercase so we just enforce this without further validation
$name = trim(mb_strtolower($name, 'UTF8'));
if (!preg_match('_^[#@][\w-]{1,21}$_', $name)) {
throw new InvalidChannelException(
'Channel names must be all lowercase.
The name should start with "#" for a channel or "@" for an account
They cannot be longer than 21 characters and can only contain letters, numbers, hyphens, and underscores.',
400
);
}
$this->name = $name;
}
|
[
"private",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"// names should be lowercase so we just enforce this without further validation",
"$",
"name",
"=",
"trim",
"(",
"mb_strtolower",
"(",
"$",
"name",
",",
"'UTF8'",
")",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'_^[#@][\\w-]{1,21}$_'",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidChannelException",
"(",
"'Channel names must be all lowercase.\n The name should start with \"#\" for a channel or \"@\" for an account\n They cannot be longer than 21 characters and can only contain letters, numbers, hyphens, and underscores.'",
",",
"400",
")",
";",
"}",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"}"
] |
@param string $name
@return self
|
[
"@param",
"string",
"$name"
] |
train
|
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/Slack/Channel.php#L33-L48
|
FrenchFrogs/framework
|
src/Form/Renderer/Inline.php
|
Inline.hidden
|
public function hidden(Form\Element\Hidden $element)
{
$html = html('input', $element->getAttributes());
return $html;
}
|
php
|
public function hidden(Form\Element\Hidden $element)
{
$html = html('input', $element->getAttributes());
return $html;
}
|
[
"public",
"function",
"hidden",
"(",
"Form",
"\\",
"Element",
"\\",
"Hidden",
"$",
"element",
")",
"{",
"$",
"html",
"=",
"html",
"(",
"'input'",
",",
"$",
"element",
"->",
"getAttributes",
"(",
")",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
render hidden input
@param \FrenchFrogs\Form\Element\Hidden $element
@return string
|
[
"render",
"hidden",
"input"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Inline.php#L314-L318
|
FrenchFrogs/framework
|
src/Form/Renderer/Inline.php
|
Inline.label
|
public function label(Form\Element\Label $element)
{
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9"><p class="form-control-static">' . $element->getValue() . '</p></div>';
$class = Style::FORM_GROUP_CLASS . ' row';
return html('div', compact('class'), $html);
}
|
php
|
public function label(Form\Element\Label $element)
{
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9"><p class="form-control-static">' . $element->getValue() . '</p></div>';
$class = Style::FORM_GROUP_CLASS . ' row';
return html('div', compact('class'), $html);
}
|
[
"public",
"function",
"label",
"(",
"Form",
"\\",
"Element",
"\\",
"Label",
"$",
"element",
")",
"{",
"$",
"html",
"=",
"'<label class=\"col-md-3 control-label\">'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"'</label>'",
";",
"$",
"html",
".=",
"'<div class=\"col-md-9\"><p class=\"form-control-static\">'",
".",
"$",
"element",
"->",
"getValue",
"(",
")",
".",
"'</p></div>'",
";",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
".",
"' row'",
";",
"return",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"}"
] |
Render Label iunput
@param \FrenchFrogs\Form\Element\Label $element
@return string
|
[
"Render",
"Label",
"iunput"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Inline.php#L327-L334
|
FrenchFrogs/framework
|
src/Form/Renderer/Inline.php
|
Inline.label_date
|
public function label_date(Form\Element\LabelDate $element)
{
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9"><p class="form-control-static">' . $element->getDisplayValue() . '</p></div>';
$class = Style::FORM_GROUP_CLASS . ' row';
return html('div', compact('class'), $html);
}
|
php
|
public function label_date(Form\Element\LabelDate $element)
{
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9"><p class="form-control-static">' . $element->getDisplayValue() . '</p></div>';
$class = Style::FORM_GROUP_CLASS . ' row';
return html('div', compact('class'), $html);
}
|
[
"public",
"function",
"label_date",
"(",
"Form",
"\\",
"Element",
"\\",
"LabelDate",
"$",
"element",
")",
"{",
"$",
"html",
"=",
"'<label class=\"col-md-3 control-label\">'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"'</label>'",
";",
"$",
"html",
".=",
"'<div class=\"col-md-9\"><p class=\"form-control-static\">'",
".",
"$",
"element",
"->",
"getDisplayValue",
"(",
")",
".",
"'</p></div>'",
";",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
".",
"' row'",
";",
"return",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"}"
] |
Render Label Date
@param \FrenchFrogs\Form\Element\LabelDate $element
@return string
|
[
"Render",
"Label",
"Date"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Inline.php#L342-L349
|
FrenchFrogs/framework
|
src/Form/Renderer/Inline.php
|
Inline.pre
|
public function pre(Form\Element\Pre $element)
{
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9"><pre>' . $element->getValue() . '</pre></div>';
$class = Style::FORM_GROUP_CLASS . ' row';
return html('div', compact('class'), $html);
}
|
php
|
public function pre(Form\Element\Pre $element)
{
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9"><pre>' . $element->getValue() . '</pre></div>';
$class = Style::FORM_GROUP_CLASS . ' row';
return html('div', compact('class'), $html);
}
|
[
"public",
"function",
"pre",
"(",
"Form",
"\\",
"Element",
"\\",
"Pre",
"$",
"element",
")",
"{",
"$",
"html",
"=",
"'<label class=\"col-md-3 control-label\">'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"'</label>'",
";",
"$",
"html",
".=",
"'<div class=\"col-md-9\"><pre>'",
".",
"$",
"element",
"->",
"getValue",
"(",
")",
".",
"'</pre></div>'",
";",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
".",
"' row'",
";",
"return",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"}"
] |
Render Label iunput
@param \FrenchFrogs\Form\Element\Label $element
@return string
|
[
"Render",
"Label",
"iunput"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Inline.php#L358-L365
|
FrenchFrogs/framework
|
src/Form/Renderer/Inline.php
|
Inline.image
|
public function image(Form\Element\Image $element)
{
$element->addStyle('object-fit', 'cover !important;');
$element->addAttribute('src', $element->getValue());
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9"><p class="form-control-static">' . html('img', $element->getAttributes()) . '</p></div>';
$class = Style::FORM_GROUP_CLASS . ' row';
return html('div', compact('class'), $html);
}
|
php
|
public function image(Form\Element\Image $element)
{
$element->addStyle('object-fit', 'cover !important;');
$element->addAttribute('src', $element->getValue());
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9"><p class="form-control-static">' . html('img', $element->getAttributes()) . '</p></div>';
$class = Style::FORM_GROUP_CLASS . ' row';
return html('div', compact('class'), $html);
}
|
[
"public",
"function",
"image",
"(",
"Form",
"\\",
"Element",
"\\",
"Image",
"$",
"element",
")",
"{",
"$",
"element",
"->",
"addStyle",
"(",
"'object-fit'",
",",
"'cover !important;'",
")",
";",
"$",
"element",
"->",
"addAttribute",
"(",
"'src'",
",",
"$",
"element",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"html",
"=",
"'<label class=\"col-md-3 control-label\">'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"'</label>'",
";",
"$",
"html",
".=",
"'<div class=\"col-md-9\"><p class=\"form-control-static\">'",
".",
"html",
"(",
"'img'",
",",
"$",
"element",
"->",
"getAttributes",
"(",
")",
")",
".",
"'</p></div>'",
";",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
".",
"' row'",
";",
"return",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"}"
] |
Render Image input
@param \FrenchFrogs\Form\Element\Label $element
@return string
|
[
"Render",
"Image",
"input"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Inline.php#L374-L385
|
FrenchFrogs/framework
|
src/Form/Renderer/Inline.php
|
Inline.button
|
public function button(Form\Element\Button $element)
{
//@todo prendre en compte les option et les size
$element->addClass('btn btn-default');
$element->addAttribute('id', $element->getName());
$html = '<div class="form-group">';
$html .= '<label class="col-md-3 control-label"> </label>';
$html .= '<div class="col-md-9">' . html('button', $element->getAttributes(), $element->getLabel()) . '</div>';
$html .= '</div>';
return $html;
}
|
php
|
public function button(Form\Element\Button $element)
{
//@todo prendre en compte les option et les size
$element->addClass('btn btn-default');
$element->addAttribute('id', $element->getName());
$html = '<div class="form-group">';
$html .= '<label class="col-md-3 control-label"> </label>';
$html .= '<div class="col-md-9">' . html('button', $element->getAttributes(), $element->getLabel()) . '</div>';
$html .= '</div>';
return $html;
}
|
[
"public",
"function",
"button",
"(",
"Form",
"\\",
"Element",
"\\",
"Button",
"$",
"element",
")",
"{",
"//@todo prendre en compte les option et les size",
"$",
"element",
"->",
"addClass",
"(",
"'btn btn-default'",
")",
";",
"$",
"element",
"->",
"addAttribute",
"(",
"'id'",
",",
"$",
"element",
"->",
"getName",
"(",
")",
")",
";",
"$",
"html",
"=",
"'<div class=\"form-group\">'",
";",
"$",
"html",
".=",
"'<label class=\"col-md-3 control-label\"> </label>'",
";",
"$",
"html",
".=",
"'<div class=\"col-md-9\">'",
".",
"html",
"(",
"'button'",
",",
"$",
"element",
"->",
"getAttributes",
"(",
")",
",",
"$",
"element",
"->",
"getLabel",
"(",
")",
")",
".",
"'</div>'",
";",
"$",
"html",
".=",
"'</div>'",
";",
"return",
"$",
"html",
";",
"}"
] |
rende a button element
@param \FrenchFrogs\Form\Element\Button $element
@return string
|
[
"rende",
"a",
"button",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Inline.php#L410-L421
|
FrenchFrogs/framework
|
src/Form/Renderer/Inline.php
|
Inline.content
|
public function content(Form\Element\Content $element)
{
if ($element->isFullWith()) {
$html = '<div class="col-md-12">' . $element->getValue() . '</div>';
} else {
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9">' . $element->getValue() . '</div>';
}
$class = Style::FORM_GROUP_CLASS;
return html('div', compact('class'), $html);
}
|
php
|
public function content(Form\Element\Content $element)
{
if ($element->isFullWith()) {
$html = '<div class="col-md-12">' . $element->getValue() . '</div>';
} else {
$html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
$html .= '<div class="col-md-9">' . $element->getValue() . '</div>';
}
$class = Style::FORM_GROUP_CLASS;
return html('div', compact('class'), $html);
}
|
[
"public",
"function",
"content",
"(",
"Form",
"\\",
"Element",
"\\",
"Content",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"isFullWith",
"(",
")",
")",
"{",
"$",
"html",
"=",
"'<div class=\"col-md-12\">'",
".",
"$",
"element",
"->",
"getValue",
"(",
")",
".",
"'</div>'",
";",
"}",
"else",
"{",
"$",
"html",
"=",
"'<label class=\"col-md-3 control-label\">'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"'</label>'",
";",
"$",
"html",
".=",
"'<div class=\"col-md-9\">'",
".",
"$",
"element",
"->",
"getValue",
"(",
")",
".",
"'</div>'",
";",
"}",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
";",
"return",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"}"
] |
Render content
@param \FrenchFrogs\Form\Element\Content $element
@return string
|
[
"Render",
"content"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Inline.php#L446-L458
|
FrenchFrogs/framework
|
src/Form/Renderer/Inline.php
|
Inline.date_range
|
public function date_range(Form\Element\DateRange $element)
{
// CLASS
$class = Style::FORM_GROUP_CLASS;
// ERROR
if($hasError = !$element->getValidator()->isValid()){
if(empty($element->getAttribute('data-placement'))){$element->addAttribute('data-placement','bottom');}
$message = '';
foreach($element->getValidator()->getErrors() as $error){
$message .= $error . ' ';
}
$element->addAttribute('data-original-title',$message);
$element->addAttribute('data-toggle', 'tooltip');
$class .= ' ' .Style::FORM_GROUP_ERROR;
}
// LABEL
$label = '';
if ($element->getForm()->hasLabel()) {
$label = '<label for="' . $element->getName() . '" class="col-md-3 control-label">' . $element->getLabel() . ($element->hasRule('required') ? ' *' : '') . '</label>';
}
$html = html('input', ['type' => 'text', 'class' => Style::FORM_ELEMENT_CONTROL, 'name' => $element->getFrom()]);
$html .= '<span class="input-group-addon"> => </span>';
$html .= html('input', ['type' => 'text', 'class' => Style::FORM_ELEMENT_CONTROL, 'name' => $element->getTo()]);
$html = html('div', [
'class' => 'input-group input-large date-picker daterange input-daterange',
'data-date-format' => configurator()->get('form.element.date.formatjs')
], $html);
// DESCRIPTION
if ($element->hasDescription()) {
$html .= html('span', ['class' => 'help-block'], $element->getDescription());
}
// FINAL CONTAINER
$html = html('div', ['class' => 'col-md-9'], $html);
return html('div', compact('class'), $label . $html);
}
|
php
|
public function date_range(Form\Element\DateRange $element)
{
// CLASS
$class = Style::FORM_GROUP_CLASS;
// ERROR
if($hasError = !$element->getValidator()->isValid()){
if(empty($element->getAttribute('data-placement'))){$element->addAttribute('data-placement','bottom');}
$message = '';
foreach($element->getValidator()->getErrors() as $error){
$message .= $error . ' ';
}
$element->addAttribute('data-original-title',$message);
$element->addAttribute('data-toggle', 'tooltip');
$class .= ' ' .Style::FORM_GROUP_ERROR;
}
// LABEL
$label = '';
if ($element->getForm()->hasLabel()) {
$label = '<label for="' . $element->getName() . '" class="col-md-3 control-label">' . $element->getLabel() . ($element->hasRule('required') ? ' *' : '') . '</label>';
}
$html = html('input', ['type' => 'text', 'class' => Style::FORM_ELEMENT_CONTROL, 'name' => $element->getFrom()]);
$html .= '<span class="input-group-addon"> => </span>';
$html .= html('input', ['type' => 'text', 'class' => Style::FORM_ELEMENT_CONTROL, 'name' => $element->getTo()]);
$html = html('div', [
'class' => 'input-group input-large date-picker daterange input-daterange',
'data-date-format' => configurator()->get('form.element.date.formatjs')
], $html);
// DESCRIPTION
if ($element->hasDescription()) {
$html .= html('span', ['class' => 'help-block'], $element->getDescription());
}
// FINAL CONTAINER
$html = html('div', ['class' => 'col-md-9'], $html);
return html('div', compact('class'), $label . $html);
}
|
[
"public",
"function",
"date_range",
"(",
"Form",
"\\",
"Element",
"\\",
"DateRange",
"$",
"element",
")",
"{",
"// CLASS",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
";",
"// ERROR",
"if",
"(",
"$",
"hasError",
"=",
"!",
"$",
"element",
"->",
"getValidator",
"(",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"element",
"->",
"getAttribute",
"(",
"'data-placement'",
")",
")",
")",
"{",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-placement'",
",",
"'bottom'",
")",
";",
"}",
"$",
"message",
"=",
"''",
";",
"foreach",
"(",
"$",
"element",
"->",
"getValidator",
"(",
")",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"message",
".=",
"$",
"error",
".",
"' '",
";",
"}",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-original-title'",
",",
"$",
"message",
")",
";",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-toggle'",
",",
"'tooltip'",
")",
";",
"$",
"class",
".=",
"' '",
".",
"Style",
"::",
"FORM_GROUP_ERROR",
";",
"}",
"// LABEL",
"$",
"label",
"=",
"''",
";",
"if",
"(",
"$",
"element",
"->",
"getForm",
"(",
")",
"->",
"hasLabel",
"(",
")",
")",
"{",
"$",
"label",
"=",
"'<label for=\"'",
".",
"$",
"element",
"->",
"getName",
"(",
")",
".",
"'\" class=\"col-md-3 control-label\">'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"(",
"$",
"element",
"->",
"hasRule",
"(",
"'required'",
")",
"?",
"' *'",
":",
"''",
")",
".",
"'</label>'",
";",
"}",
"$",
"html",
"=",
"html",
"(",
"'input'",
",",
"[",
"'type'",
"=>",
"'text'",
",",
"'class'",
"=>",
"Style",
"::",
"FORM_ELEMENT_CONTROL",
",",
"'name'",
"=>",
"$",
"element",
"->",
"getFrom",
"(",
")",
"]",
")",
";",
"$",
"html",
".=",
"'<span class=\"input-group-addon\"> => </span>'",
";",
"$",
"html",
".=",
"html",
"(",
"'input'",
",",
"[",
"'type'",
"=>",
"'text'",
",",
"'class'",
"=>",
"Style",
"::",
"FORM_ELEMENT_CONTROL",
",",
"'name'",
"=>",
"$",
"element",
"->",
"getTo",
"(",
")",
"]",
")",
";",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"[",
"'class'",
"=>",
"'input-group input-large date-picker daterange input-daterange'",
",",
"'data-date-format'",
"=>",
"configurator",
"(",
")",
"->",
"get",
"(",
"'form.element.date.formatjs'",
")",
"]",
",",
"$",
"html",
")",
";",
"// DESCRIPTION",
"if",
"(",
"$",
"element",
"->",
"hasDescription",
"(",
")",
")",
"{",
"$",
"html",
".=",
"html",
"(",
"'span'",
",",
"[",
"'class'",
"=>",
"'help-block'",
"]",
",",
"$",
"element",
"->",
"getDescription",
"(",
")",
")",
";",
"}",
"// FINAL CONTAINER",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"[",
"'class'",
"=>",
"'col-md-9'",
"]",
",",
"$",
"html",
")",
";",
"return",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"label",
".",
"$",
"html",
")",
";",
"}"
] |
Render a date range element
@param Form\Element\DateRange $element
|
[
"Render",
"a",
"date",
"range",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Inline.php#L704-L746
|
WellCommerce/OrderBundle
|
DependencyInjection/Compiler/RegisterOrderVisitorPass.php
|
RegisterOrderVisitorPass.process
|
public function process(ContainerBuilder $container)
{
$tag = 'order.visitor';
$interface = OrderVisitorInterface::class;
$definition = $container->getDefinition('order.visitor.collection');
$visitors = [];
$hierarchies = $container->getParameter('order_visitor_hierarchy');
foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) {
$hierarchy = $hierarchies[$attributes[0]['alias']] ?? 0;
$itemDefinition = $container->getDefinition($id);
$refClass = new \ReflectionClass($itemDefinition->getClass());
if (!$refClass->implementsInterface($interface)) {
throw new \InvalidArgumentException(
sprintf('Order visitor "%s" must implement interface "%s".', $id, $interface)
);
}
$visitors[$hierarchy][] = new Reference($id);
}
ksort($visitors);
$visitors = call_user_func_array('array_merge', $visitors);
foreach ($visitors as $visitor) {
$definition->addMethodCall('add', [
$visitor
]);
}
}
|
php
|
public function process(ContainerBuilder $container)
{
$tag = 'order.visitor';
$interface = OrderVisitorInterface::class;
$definition = $container->getDefinition('order.visitor.collection');
$visitors = [];
$hierarchies = $container->getParameter('order_visitor_hierarchy');
foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) {
$hierarchy = $hierarchies[$attributes[0]['alias']] ?? 0;
$itemDefinition = $container->getDefinition($id);
$refClass = new \ReflectionClass($itemDefinition->getClass());
if (!$refClass->implementsInterface($interface)) {
throw new \InvalidArgumentException(
sprintf('Order visitor "%s" must implement interface "%s".', $id, $interface)
);
}
$visitors[$hierarchy][] = new Reference($id);
}
ksort($visitors);
$visitors = call_user_func_array('array_merge', $visitors);
foreach ($visitors as $visitor) {
$definition->addMethodCall('add', [
$visitor
]);
}
}
|
[
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"tag",
"=",
"'order.visitor'",
";",
"$",
"interface",
"=",
"OrderVisitorInterface",
"::",
"class",
";",
"$",
"definition",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'order.visitor.collection'",
")",
";",
"$",
"visitors",
"=",
"[",
"]",
";",
"$",
"hierarchies",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'order_visitor_hierarchy'",
")",
";",
"foreach",
"(",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"$",
"tag",
")",
"as",
"$",
"id",
"=>",
"$",
"attributes",
")",
"{",
"$",
"hierarchy",
"=",
"$",
"hierarchies",
"[",
"$",
"attributes",
"[",
"0",
"]",
"[",
"'alias'",
"]",
"]",
"??",
"0",
";",
"$",
"itemDefinition",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"$",
"id",
")",
";",
"$",
"refClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"itemDefinition",
"->",
"getClass",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"refClass",
"->",
"implementsInterface",
"(",
"$",
"interface",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Order visitor \"%s\" must implement interface \"%s\".'",
",",
"$",
"id",
",",
"$",
"interface",
")",
")",
";",
"}",
"$",
"visitors",
"[",
"$",
"hierarchy",
"]",
"[",
"]",
"=",
"new",
"Reference",
"(",
"$",
"id",
")",
";",
"}",
"ksort",
"(",
"$",
"visitors",
")",
";",
"$",
"visitors",
"=",
"call_user_func_array",
"(",
"'array_merge'",
",",
"$",
"visitors",
")",
";",
"foreach",
"(",
"$",
"visitors",
"as",
"$",
"visitor",
")",
"{",
"$",
"definition",
"->",
"addMethodCall",
"(",
"'add'",
",",
"[",
"$",
"visitor",
"]",
")",
";",
"}",
"}"
] |
Processes the container
@param ContainerBuilder $container
|
[
"Processes",
"the",
"container"
] |
train
|
https://github.com/WellCommerce/OrderBundle/blob/d72cfb51eab7a1f66f186900d1e2d533a822c424/DependencyInjection/Compiler/RegisterOrderVisitorPass.php#L32-L62
|
crossjoin/Css
|
src/Crossjoin/Css/Format/Rule/AtPage/PageRule.php
|
PageRule.addDeclaration
|
public function addDeclaration(DeclarationAbstract $declaration)
{
if ($declaration instanceof PageDeclaration) {
$this->declarations[] = $declaration;
} else {
throw new \InvalidArgumentException(
"Invalid declaration instance. Instance of 'PageDeclaration' expected."
);
}
return $this;
}
|
php
|
public function addDeclaration(DeclarationAbstract $declaration)
{
if ($declaration instanceof PageDeclaration) {
$this->declarations[] = $declaration;
} else {
throw new \InvalidArgumentException(
"Invalid declaration instance. Instance of 'PageDeclaration' expected."
);
}
return $this;
}
|
[
"public",
"function",
"addDeclaration",
"(",
"DeclarationAbstract",
"$",
"declaration",
")",
"{",
"if",
"(",
"$",
"declaration",
"instanceof",
"PageDeclaration",
")",
"{",
"$",
"this",
"->",
"declarations",
"[",
"]",
"=",
"$",
"declaration",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid declaration instance. Instance of 'PageDeclaration' expected.\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Adds a declaration to the rule.
@param PageDeclaration $declaration
@return $this
|
[
"Adds",
"a",
"declaration",
"to",
"the",
"rule",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtPage/PageRule.php#L58-L69
|
crossjoin/Css
|
src/Crossjoin/Css/Format/Rule/AtPage/PageRule.php
|
PageRule.parseRuleString
|
protected function parseRuleString($ruleString)
{
// Remove at-rule name and unnecessary white-spaces
$ruleString = preg_replace('/^[ \r\n\t\f]*@page[ \r\n\t\f]*/i', '', $ruleString);
$ruleString = trim($ruleString, " \r\n\t\f");
// Extract query list and create a rule from it
$pageSelector = new PageSelector($ruleString, $this->getStyleSheet());
$this->setSelector($pageSelector);
}
|
php
|
protected function parseRuleString($ruleString)
{
// Remove at-rule name and unnecessary white-spaces
$ruleString = preg_replace('/^[ \r\n\t\f]*@page[ \r\n\t\f]*/i', '', $ruleString);
$ruleString = trim($ruleString, " \r\n\t\f");
// Extract query list and create a rule from it
$pageSelector = new PageSelector($ruleString, $this->getStyleSheet());
$this->setSelector($pageSelector);
}
|
[
"protected",
"function",
"parseRuleString",
"(",
"$",
"ruleString",
")",
"{",
"// Remove at-rule name and unnecessary white-spaces",
"$",
"ruleString",
"=",
"preg_replace",
"(",
"'/^[ \\r\\n\\t\\f]*@page[ \\r\\n\\t\\f]*/i'",
",",
"''",
",",
"$",
"ruleString",
")",
";",
"$",
"ruleString",
"=",
"trim",
"(",
"$",
"ruleString",
",",
"\" \\r\\n\\t\\f\"",
")",
";",
"// Extract query list and create a rule from it",
"$",
"pageSelector",
"=",
"new",
"PageSelector",
"(",
"$",
"ruleString",
",",
"$",
"this",
"->",
"getStyleSheet",
"(",
")",
")",
";",
"$",
"this",
"->",
"setSelector",
"(",
"$",
"pageSelector",
")",
";",
"}"
] |
Parses the page rule.
@param string $ruleString
|
[
"Parses",
"the",
"page",
"rule",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtPage/PageRule.php#L76-L85
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/Factory/DocumentManagerFactory.php
|
DocumentManagerFactory.createDocumentManager
|
public function createDocumentManager($mongouri, $dbName, $debug = false, $managerId = "", $newConnection = false, $options = [])
{
if (!isset($this->connexions[$mongouri])) {
$client = new Client($mongouri);
}
if (!isset($this->managers[$managerId])) {
$database = new Database($client->getManager(), $dbName);
$class = $this->repositoryFactoryClass;
$repositoryFactory = new $class(null, $this->classMetadataFactory);
$this->managers[$managerId] = new DocumentManager(
$client,
$database,
$repositoryFactory,
$debug,
$options,
[]
);
}
return $this->managers[$managerId];
}
|
php
|
public function createDocumentManager($mongouri, $dbName, $debug = false, $managerId = "", $newConnection = false, $options = [])
{
if (!isset($this->connexions[$mongouri])) {
$client = new Client($mongouri);
}
if (!isset($this->managers[$managerId])) {
$database = new Database($client->getManager(), $dbName);
$class = $this->repositoryFactoryClass;
$repositoryFactory = new $class(null, $this->classMetadataFactory);
$this->managers[$managerId] = new DocumentManager(
$client,
$database,
$repositoryFactory,
$debug,
$options,
[]
);
}
return $this->managers[$managerId];
}
|
[
"public",
"function",
"createDocumentManager",
"(",
"$",
"mongouri",
",",
"$",
"dbName",
",",
"$",
"debug",
"=",
"false",
",",
"$",
"managerId",
"=",
"\"\"",
",",
"$",
"newConnection",
"=",
"false",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"connexions",
"[",
"$",
"mongouri",
"]",
")",
")",
"{",
"$",
"client",
"=",
"new",
"Client",
"(",
"$",
"mongouri",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"managers",
"[",
"$",
"managerId",
"]",
")",
")",
"{",
"$",
"database",
"=",
"new",
"Database",
"(",
"$",
"client",
"->",
"getManager",
"(",
")",
",",
"$",
"dbName",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"repositoryFactoryClass",
";",
"$",
"repositoryFactory",
"=",
"new",
"$",
"class",
"(",
"null",
",",
"$",
"this",
"->",
"classMetadataFactory",
")",
";",
"$",
"this",
"->",
"managers",
"[",
"$",
"managerId",
"]",
"=",
"new",
"DocumentManager",
"(",
"$",
"client",
",",
"$",
"database",
",",
"$",
"repositoryFactory",
",",
"$",
"debug",
",",
"$",
"options",
",",
"[",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"managers",
"[",
"$",
"managerId",
"]",
";",
"}"
] |
Create new DocumentManager from mongouri and DB name
@param string $mongouri mongodb uri (mongodb://user:[email protected]/auth_db)
@param string $dbName name of the DB where to work
@param boolean $debug Enable debug mode or not
@param mixed $managerId Manager unique id
@param boolean $newConnection Force to open new connection
@return DocumentManager A DocumentManager connected to mongouri specified
|
[
"Create",
"new",
"DocumentManager",
"from",
"mongouri",
"and",
"DB",
"name"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Factory/DocumentManagerFactory.php#L62-L87
|
czim/laravel-pxlcms
|
src/Generator/Writer/Model/Steps/StubReplaceAttributeData.php
|
StubReplaceAttributeData.getFillableReplace
|
protected function getFillableReplace()
{
$attributes = array_merge(
$this->data['normal_fillable'],
$this->data['translated_fillable']
);
if ( ! count($attributes)) return '';
return $this->getAttributePropertySection('fillable', $attributes);
}
|
php
|
protected function getFillableReplace()
{
$attributes = array_merge(
$this->data['normal_fillable'],
$this->data['translated_fillable']
);
if ( ! count($attributes)) return '';
return $this->getAttributePropertySection('fillable', $attributes);
}
|
[
"protected",
"function",
"getFillableReplace",
"(",
")",
"{",
"$",
"attributes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"data",
"[",
"'normal_fillable'",
"]",
",",
"$",
"this",
"->",
"data",
"[",
"'translated_fillable'",
"]",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"attributes",
")",
")",
"return",
"''",
";",
"return",
"$",
"this",
"->",
"getAttributePropertySection",
"(",
"'fillable'",
",",
"$",
"attributes",
")",
";",
"}"
] |
Returns the replacement for the fillable placeholder
@return string
|
[
"Returns",
"the",
"replacement",
"for",
"the",
"fillable",
"placeholder"
] |
train
|
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Writer/Model/Steps/StubReplaceAttributeData.php#L23-L33
|
czim/laravel-pxlcms
|
src/Generator/Writer/Model/Steps/StubReplaceAttributeData.php
|
StubReplaceAttributeData.getCastsReplace
|
protected function getCastsReplace()
{
$attributes = $this->data['casts'] ?: [];
if ( ! count($attributes)) return '';
// align assignment signs by longest attribute
$longestLength = 0;
foreach ($attributes as $attribute => $type) {
if (strlen($attribute) > $longestLength) {
$longestLength = strlen($attribute);
}
}
$replace = $this->tab() . "protected \$casts = [\n";
foreach ($attributes as $attribute => $type) {
$replace .= $this->tab(2)
. "'" . str_pad($attribute . "'", $longestLength + 1)
. " => '" . $type . "',\n";
}
$replace .= $this->tab() . "];\n\n";
return $replace;
}
|
php
|
protected function getCastsReplace()
{
$attributes = $this->data['casts'] ?: [];
if ( ! count($attributes)) return '';
// align assignment signs by longest attribute
$longestLength = 0;
foreach ($attributes as $attribute => $type) {
if (strlen($attribute) > $longestLength) {
$longestLength = strlen($attribute);
}
}
$replace = $this->tab() . "protected \$casts = [\n";
foreach ($attributes as $attribute => $type) {
$replace .= $this->tab(2)
. "'" . str_pad($attribute . "'", $longestLength + 1)
. " => '" . $type . "',\n";
}
$replace .= $this->tab() . "];\n\n";
return $replace;
}
|
[
"protected",
"function",
"getCastsReplace",
"(",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"data",
"[",
"'casts'",
"]",
"?",
":",
"[",
"]",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"attributes",
")",
")",
"return",
"''",
";",
"// align assignment signs by longest attribute",
"$",
"longestLength",
"=",
"0",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"type",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"attribute",
")",
">",
"$",
"longestLength",
")",
"{",
"$",
"longestLength",
"=",
"strlen",
"(",
"$",
"attribute",
")",
";",
"}",
"}",
"$",
"replace",
"=",
"$",
"this",
"->",
"tab",
"(",
")",
".",
"\"protected \\$casts = [\\n\"",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"type",
")",
"{",
"$",
"replace",
".=",
"$",
"this",
"->",
"tab",
"(",
"2",
")",
".",
"\"'\"",
".",
"str_pad",
"(",
"$",
"attribute",
".",
"\"'\"",
",",
"$",
"longestLength",
"+",
"1",
")",
".",
"\" => '\"",
".",
"$",
"type",
".",
"\"',\\n\"",
";",
"}",
"$",
"replace",
".=",
"$",
"this",
"->",
"tab",
"(",
")",
".",
"\"];\\n\\n\"",
";",
"return",
"$",
"replace",
";",
"}"
] |
Returns the replacement for the casts placeholder
@return string
|
[
"Returns",
"the",
"replacement",
"for",
"the",
"casts",
"placeholder"
] |
train
|
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Writer/Model/Steps/StubReplaceAttributeData.php#L68-L96
|
czim/laravel-pxlcms
|
src/Generator/Writer/Model/Steps/StubReplaceAttributeData.php
|
StubReplaceAttributeData.getDefaultsReplace
|
protected function getDefaultsReplace()
{
if ( ! config('pxlcms.generator.models.include_defaults')) return '';
$attributes = $this->data['defaults'] ?: [];
if ( ! count($attributes)) return '';
// align assignment signs by longest attribute
$longestLength = 0;
foreach ($attributes as $attribute => $default) {
if (strlen($attribute) > $longestLength) {
$longestLength = strlen($attribute);
}
}
$replace = $this->tab() . "protected \$attributes = [\n";
foreach ($attributes as $attribute => $default) {
$replace .= $this->tab(2)
. "'" . str_pad($attribute . "'", $longestLength + 1)
. " => " . $default . ",\n";
}
$replace .= $this->tab() . "];\n\n";
return $replace;
}
|
php
|
protected function getDefaultsReplace()
{
if ( ! config('pxlcms.generator.models.include_defaults')) return '';
$attributes = $this->data['defaults'] ?: [];
if ( ! count($attributes)) return '';
// align assignment signs by longest attribute
$longestLength = 0;
foreach ($attributes as $attribute => $default) {
if (strlen($attribute) > $longestLength) {
$longestLength = strlen($attribute);
}
}
$replace = $this->tab() . "protected \$attributes = [\n";
foreach ($attributes as $attribute => $default) {
$replace .= $this->tab(2)
. "'" . str_pad($attribute . "'", $longestLength + 1)
. " => " . $default . ",\n";
}
$replace .= $this->tab() . "];\n\n";
return $replace;
}
|
[
"protected",
"function",
"getDefaultsReplace",
"(",
")",
"{",
"if",
"(",
"!",
"config",
"(",
"'pxlcms.generator.models.include_defaults'",
")",
")",
"return",
"''",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"data",
"[",
"'defaults'",
"]",
"?",
":",
"[",
"]",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"attributes",
")",
")",
"return",
"''",
";",
"// align assignment signs by longest attribute",
"$",
"longestLength",
"=",
"0",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"default",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"attribute",
")",
">",
"$",
"longestLength",
")",
"{",
"$",
"longestLength",
"=",
"strlen",
"(",
"$",
"attribute",
")",
";",
"}",
"}",
"$",
"replace",
"=",
"$",
"this",
"->",
"tab",
"(",
")",
".",
"\"protected \\$attributes = [\\n\"",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"default",
")",
"{",
"$",
"replace",
".=",
"$",
"this",
"->",
"tab",
"(",
"2",
")",
".",
"\"'\"",
".",
"str_pad",
"(",
"$",
"attribute",
".",
"\"'\"",
",",
"$",
"longestLength",
"+",
"1",
")",
".",
"\" => \"",
".",
"$",
"default",
".",
"\",\\n\"",
";",
"}",
"$",
"replace",
".=",
"$",
"this",
"->",
"tab",
"(",
")",
".",
"\"];\\n\\n\"",
";",
"return",
"$",
"replace",
";",
"}"
] |
Returns the replacement for the default attributes placeholder
@return string
|
[
"Returns",
"the",
"replacement",
"for",
"the",
"default",
"attributes",
"placeholder"
] |
train
|
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Writer/Model/Steps/StubReplaceAttributeData.php#L117-L147
|
vardius/list-bundle
|
Paginator/Paginator.php
|
Paginator.render
|
public function render():string
{
return $this->templating->render($this->getTemplatePath() . 'paginator.html.twig', [
'currentPage' => $this->getCurrentPage(),
'previousPage' => $this->getPreviousPage(),
'lastPage' => $this->getLastPage(),
'nextPage' => $this->getNextPage(),
]);
}
|
php
|
public function render():string
{
return $this->templating->render($this->getTemplatePath() . 'paginator.html.twig', [
'currentPage' => $this->getCurrentPage(),
'previousPage' => $this->getPreviousPage(),
'lastPage' => $this->getLastPage(),
'nextPage' => $this->getNextPage(),
]);
}
|
[
"public",
"function",
"render",
"(",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"templating",
"->",
"render",
"(",
"$",
"this",
"->",
"getTemplatePath",
"(",
")",
".",
"'paginator.html.twig'",
",",
"[",
"'currentPage'",
"=>",
"$",
"this",
"->",
"getCurrentPage",
"(",
")",
",",
"'previousPage'",
"=>",
"$",
"this",
"->",
"getPreviousPage",
"(",
")",
",",
"'lastPage'",
"=>",
"$",
"this",
"->",
"getLastPage",
"(",
")",
",",
"'nextPage'",
"=>",
"$",
"this",
"->",
"getNextPage",
"(",
")",
",",
"]",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vardius/list-bundle/blob/70d3079ce22eed7dad7c467fee532aa2f18c68c9/Paginator/Paginator.php#L36-L44
|
vardius/list-bundle
|
Paginator/Paginator.php
|
Paginator.getNextPage
|
public function getNextPage():float
{
return ($this->page < $this->getLastPage() ? $this->page + 1 : $this->page);
}
|
php
|
public function getNextPage():float
{
return ($this->page < $this->getLastPage() ? $this->page + 1 : $this->page);
}
|
[
"public",
"function",
"getNextPage",
"(",
")",
":",
"float",
"{",
"return",
"(",
"$",
"this",
"->",
"page",
"<",
"$",
"this",
"->",
"getLastPage",
"(",
")",
"?",
"$",
"this",
"->",
"page",
"+",
"1",
":",
"$",
"this",
"->",
"page",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vardius/list-bundle/blob/70d3079ce22eed7dad7c467fee532aa2f18c68c9/Paginator/Paginator.php#L73-L76
|
prooph/link-app-core
|
src/Service/RiotTagCollectionResolver.php
|
RiotTagCollectionResolver.resolve
|
public function resolve($name)
{
if (!isset($this->collections[$name])) {
return null;
}
if (!is_array($this->collections[$name])) {
throw new \RuntimeException(
"Collection with name $name is not an array."
);
}
$collection = new AssetCollection();
$mimeType = 'application/javascript';
$collection->setTargetPath($name);
foreach ($this->collections[$name] as $asset) {
if (!is_string($asset)) {
throw new \RuntimeException(
'Asset should be of type string. got ' . gettype($asset)
);
}
if (null === ($content = $this->riotTag->__invoke($asset))) {
throw new \RuntimeException("Riot tag '$asset' could not be found.");
}
$res = new StringAsset($content);
$res->mimetype = $mimeType;
$asset .= ".js";
$this->getAssetFilterManager()->setFilters($asset, $res);
$collection->add($res);
}
$collection->mimetype = $mimeType;
return $collection;
}
|
php
|
public function resolve($name)
{
if (!isset($this->collections[$name])) {
return null;
}
if (!is_array($this->collections[$name])) {
throw new \RuntimeException(
"Collection with name $name is not an array."
);
}
$collection = new AssetCollection();
$mimeType = 'application/javascript';
$collection->setTargetPath($name);
foreach ($this->collections[$name] as $asset) {
if (!is_string($asset)) {
throw new \RuntimeException(
'Asset should be of type string. got ' . gettype($asset)
);
}
if (null === ($content = $this->riotTag->__invoke($asset))) {
throw new \RuntimeException("Riot tag '$asset' could not be found.");
}
$res = new StringAsset($content);
$res->mimetype = $mimeType;
$asset .= ".js";
$this->getAssetFilterManager()->setFilters($asset, $res);
$collection->add($res);
}
$collection->mimetype = $mimeType;
return $collection;
}
|
[
"public",
"function",
"resolve",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"collections",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"collections",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Collection with name $name is not an array.\"",
")",
";",
"}",
"$",
"collection",
"=",
"new",
"AssetCollection",
"(",
")",
";",
"$",
"mimeType",
"=",
"'application/javascript'",
";",
"$",
"collection",
"->",
"setTargetPath",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"collections",
"[",
"$",
"name",
"]",
"as",
"$",
"asset",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"asset",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Asset should be of type string. got '",
".",
"gettype",
"(",
"$",
"asset",
")",
")",
";",
"}",
"if",
"(",
"null",
"===",
"(",
"$",
"content",
"=",
"$",
"this",
"->",
"riotTag",
"->",
"__invoke",
"(",
"$",
"asset",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Riot tag '$asset' could not be found.\"",
")",
";",
"}",
"$",
"res",
"=",
"new",
"StringAsset",
"(",
"$",
"content",
")",
";",
"$",
"res",
"->",
"mimetype",
"=",
"$",
"mimeType",
";",
"$",
"asset",
".=",
"\".js\"",
";",
"$",
"this",
"->",
"getAssetFilterManager",
"(",
")",
"->",
"setFilters",
"(",
"$",
"asset",
",",
"$",
"res",
")",
";",
"$",
"collection",
"->",
"add",
"(",
"$",
"res",
")",
";",
"}",
"$",
"collection",
"->",
"mimetype",
"=",
"$",
"mimeType",
";",
"return",
"$",
"collection",
";",
"}"
] |
{@inheritDoc}
|
[
"{"
] |
train
|
https://github.com/prooph/link-app-core/blob/835a5945dfa7be7b2cebfa6e84e757ecfd783357/src/Service/RiotTagCollectionResolver.php#L34-L76
|
okvpn/fixture-bundle
|
src/Entity/Repository/DataFixtureRepository.php
|
DataFixtureRepository.isDataFixtureExists
|
public function isDataFixtureExists($where, array $parameters = [])
{
$entityId = $this->createQueryBuilder('m')
->select('m.id')
->where($where)
->setMaxResults(1)
->getQuery()
->execute($parameters);
return $entityId ? true : false;
}
|
php
|
public function isDataFixtureExists($where, array $parameters = [])
{
$entityId = $this->createQueryBuilder('m')
->select('m.id')
->where($where)
->setMaxResults(1)
->getQuery()
->execute($parameters);
return $entityId ? true : false;
}
|
[
"public",
"function",
"isDataFixtureExists",
"(",
"$",
"where",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"entityId",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'m'",
")",
"->",
"select",
"(",
"'m.id'",
")",
"->",
"where",
"(",
"$",
"where",
")",
"->",
"setMaxResults",
"(",
"1",
")",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
"$",
"parameters",
")",
";",
"return",
"$",
"entityId",
"?",
"true",
":",
"false",
";",
"}"
] |
@param string $where
@param array $parameters
@return bool
|
[
"@param",
"string",
"$where",
"@param",
"array",
"$parameters"
] |
train
|
https://github.com/okvpn/fixture-bundle/blob/243b5e4dff9773e97fa447280e929c936a5d66ae/src/Entity/Repository/DataFixtureRepository.php#L26-L36
|
okvpn/fixture-bundle
|
src/Entity/Repository/DataFixtureRepository.php
|
DataFixtureRepository.updateDataFixutreHistory
|
public function updateDataFixutreHistory(array $updateFields, $where, array $parameters = [])
{
$qb = $this->_em
->createQueryBuilder()
->update('OkvpnFixtureBundle:DataFixture', 'm')
->where($where);
foreach ($updateFields as $fieldName => $fieldValue) {
$qb->set($fieldName, $fieldValue);
}
$qb->getQuery()->execute($parameters);
}
|
php
|
public function updateDataFixutreHistory(array $updateFields, $where, array $parameters = [])
{
$qb = $this->_em
->createQueryBuilder()
->update('OkvpnFixtureBundle:DataFixture', 'm')
->where($where);
foreach ($updateFields as $fieldName => $fieldValue) {
$qb->set($fieldName, $fieldValue);
}
$qb->getQuery()->execute($parameters);
}
|
[
"public",
"function",
"updateDataFixutreHistory",
"(",
"array",
"$",
"updateFields",
",",
"$",
"where",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"_em",
"->",
"createQueryBuilder",
"(",
")",
"->",
"update",
"(",
"'OkvpnFixtureBundle:DataFixture'",
",",
"'m'",
")",
"->",
"where",
"(",
"$",
"where",
")",
";",
"foreach",
"(",
"$",
"updateFields",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldValue",
")",
"{",
"$",
"qb",
"->",
"set",
"(",
"$",
"fieldName",
",",
"$",
"fieldValue",
")",
";",
"}",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
"$",
"parameters",
")",
";",
"}"
] |
Update data fixture history
@param array $updateFields assoc array with field names and values that should be updated
@param string $where condition
@param array $parameters optional parameters for where condition
|
[
"Update",
"data",
"fixture",
"history"
] |
train
|
https://github.com/okvpn/fixture-bundle/blob/243b5e4dff9773e97fa447280e929c936a5d66ae/src/Entity/Repository/DataFixtureRepository.php#L45-L56
|
Wonail/wocenter
|
behaviors/ModifyTimestampBehavior.php
|
ModifyTimestampBehavior.createRules
|
public function createRules(array $modelRules)
{
// 删除规则里有关时间日期字段的所有规则,由系统判断是否需要添加相应的规则。如需对时间日期字段添加其他规则,
// 可合并需要的规则到该方法调用后返回的数据结果里
foreach ($modelRules as $key => &$rule) {
if (is_array($rule[0])) {
foreach ($rule[0] as $k => $v) {
if (in_array($v, [$this->createdAtAttribute, $this->updatedAtAttribute])) {
unset($rule[0][$k]);
}
}
if (count($rule[0]) === 0) {
unset($modelRules[$key]);
}
} else {
if (in_array($rule[0], [$this->createdAtAttribute, $this->updatedAtAttribute])) {
unset($modelRules[$key]);
}
}
}
// 添加相应规则
$rules = [];
$attributes = [
[
$this->createdAtAttribute,
$this->modifyCreatedAt,
],
[
$this->updatedAtAttribute,
$this->modifyUpdatedAt,
],
];
foreach ($attributes as $row) {
if (is_string($row[0])) {
// 允许自定义时间日期
if ($row[1]) {
$this->addRules($rules, $row[0]);
} // 不允许自定义时间日期则暂不需要添加其他规则,系统会根据配置自动为时间日期字段赋值$this->value
else {
continue;
}
}
}
return ArrayHelper::merge($modelRules, $rules);
}
|
php
|
public function createRules(array $modelRules)
{
// 删除规则里有关时间日期字段的所有规则,由系统判断是否需要添加相应的规则。如需对时间日期字段添加其他规则,
// 可合并需要的规则到该方法调用后返回的数据结果里
foreach ($modelRules as $key => &$rule) {
if (is_array($rule[0])) {
foreach ($rule[0] as $k => $v) {
if (in_array($v, [$this->createdAtAttribute, $this->updatedAtAttribute])) {
unset($rule[0][$k]);
}
}
if (count($rule[0]) === 0) {
unset($modelRules[$key]);
}
} else {
if (in_array($rule[0], [$this->createdAtAttribute, $this->updatedAtAttribute])) {
unset($modelRules[$key]);
}
}
}
// 添加相应规则
$rules = [];
$attributes = [
[
$this->createdAtAttribute,
$this->modifyCreatedAt,
],
[
$this->updatedAtAttribute,
$this->modifyUpdatedAt,
],
];
foreach ($attributes as $row) {
if (is_string($row[0])) {
// 允许自定义时间日期
if ($row[1]) {
$this->addRules($rules, $row[0]);
} // 不允许自定义时间日期则暂不需要添加其他规则,系统会根据配置自动为时间日期字段赋值$this->value
else {
continue;
}
}
}
return ArrayHelper::merge($modelRules, $rules);
}
|
[
"public",
"function",
"createRules",
"(",
"array",
"$",
"modelRules",
")",
"{",
"// 删除规则里有关时间日期字段的所有规则,由系统判断是否需要添加相应的规则。如需对时间日期字段添加其他规则,",
"// 可合并需要的规则到该方法调用后返回的数据结果里",
"foreach",
"(",
"$",
"modelRules",
"as",
"$",
"key",
"=>",
"&",
"$",
"rule",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"rule",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"rule",
"[",
"0",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"v",
",",
"[",
"$",
"this",
"->",
"createdAtAttribute",
",",
"$",
"this",
"->",
"updatedAtAttribute",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"rule",
"[",
"0",
"]",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"rule",
"[",
"0",
"]",
")",
"===",
"0",
")",
"{",
"unset",
"(",
"$",
"modelRules",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"in_array",
"(",
"$",
"rule",
"[",
"0",
"]",
",",
"[",
"$",
"this",
"->",
"createdAtAttribute",
",",
"$",
"this",
"->",
"updatedAtAttribute",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"modelRules",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"// 添加相应规则",
"$",
"rules",
"=",
"[",
"]",
";",
"$",
"attributes",
"=",
"[",
"[",
"$",
"this",
"->",
"createdAtAttribute",
",",
"$",
"this",
"->",
"modifyCreatedAt",
",",
"]",
",",
"[",
"$",
"this",
"->",
"updatedAtAttribute",
",",
"$",
"this",
"->",
"modifyUpdatedAt",
",",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"row",
"[",
"0",
"]",
")",
")",
"{",
"// 允许自定义时间日期",
"if",
"(",
"$",
"row",
"[",
"1",
"]",
")",
"{",
"$",
"this",
"->",
"addRules",
"(",
"$",
"rules",
",",
"$",
"row",
"[",
"0",
"]",
")",
";",
"}",
"// 不允许自定义时间日期则暂不需要添加其他规则,系统会根据配置自动为时间日期字段赋值$this->value",
"else",
"{",
"continue",
";",
"}",
"}",
"}",
"return",
"ArrayHelper",
"::",
"merge",
"(",
"$",
"modelRules",
",",
"$",
"rules",
")",
";",
"}"
] |
创建验证规则
根据配置自动添加$this->createdAtAttribute和$this->updatedAtAttribute属性的验证规则,同时滤掉该行为的其他规则
@param array $modelRules 模型验证规则
@return array 验证规则
|
[
"创建验证规则",
"根据配置自动添加$this",
"-",
">",
"createdAtAttribute和$this",
"-",
">",
"updatedAtAttribute属性的验证规则,同时滤掉该行为的其他规则"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/behaviors/ModifyTimestampBehavior.php#L175-L220
|
Wonail/wocenter
|
behaviors/ModifyTimestampBehavior.php
|
ModifyTimestampBehavior.addRules
|
protected function addRules(&$rules, $attribute)
{
$displayData = $this->getDisplayFormat($attribute, true);
$saveData = $this->getSaveFormat($attribute, true);
// 添加`required`规则
$rules[] = [$attribute, 'required'];
switch ($this->dateTimeWidget) {
case '\wocenter\widgets\DateTimePicker':
// '1901-12-14 04:45:52'的时间戳为 -2147483648,mysql int类型保存的范围从 -2^31 (-2,147,483,648) 到 2^31 – 1 (2,147,483,647) 的整型数据(所有数字)。存储大小为 4 个字节。
// 添加时间范围限制
$rules[] = [$attribute, $displayData['type'],
'format' => $displayData['format'],
'timeZone' => $this->displayTimeZone,
'timestampAttribute' => $attribute,
'timestampAttributeFormat' => $saveData['format'],
'timestampAttributeTimeZone' => $this->saveTimeZone,
'min' => -2147483648, 'minString' => '1901-12-14 04:45:52',
'max' => time(), 'maxString' => '当前时间',
];
break;
case '\wocenter\widgets\DateControl':
case '\kartik\datecontrol\DateControl':
switch ($saveData['format']) {
case 'php:U':
$rules[] = [$attribute, '\wocenter\validators\DateControlValidator'];
break;
default:
// 添加时间范围限制
$rules[] = [$attribute, $displayData['type'],
'format' => $displayData['format'],
'timeZone' => $this->displayTimeZone,
'timestampAttribute' => $attribute,
'timestampAttributeFormat' => $saveData['format'],
'timestampAttributeTimeZone' => $this->saveTimeZone,
'min' => -2147483648, 'minString' => '1901-12-14 04:45:52',
'max' => time(), 'maxString' => '当前时间',
];
break;
}
break;
default:
break;
}
}
|
php
|
protected function addRules(&$rules, $attribute)
{
$displayData = $this->getDisplayFormat($attribute, true);
$saveData = $this->getSaveFormat($attribute, true);
// 添加`required`规则
$rules[] = [$attribute, 'required'];
switch ($this->dateTimeWidget) {
case '\wocenter\widgets\DateTimePicker':
// '1901-12-14 04:45:52'的时间戳为 -2147483648,mysql int类型保存的范围从 -2^31 (-2,147,483,648) 到 2^31 – 1 (2,147,483,647) 的整型数据(所有数字)。存储大小为 4 个字节。
// 添加时间范围限制
$rules[] = [$attribute, $displayData['type'],
'format' => $displayData['format'],
'timeZone' => $this->displayTimeZone,
'timestampAttribute' => $attribute,
'timestampAttributeFormat' => $saveData['format'],
'timestampAttributeTimeZone' => $this->saveTimeZone,
'min' => -2147483648, 'minString' => '1901-12-14 04:45:52',
'max' => time(), 'maxString' => '当前时间',
];
break;
case '\wocenter\widgets\DateControl':
case '\kartik\datecontrol\DateControl':
switch ($saveData['format']) {
case 'php:U':
$rules[] = [$attribute, '\wocenter\validators\DateControlValidator'];
break;
default:
// 添加时间范围限制
$rules[] = [$attribute, $displayData['type'],
'format' => $displayData['format'],
'timeZone' => $this->displayTimeZone,
'timestampAttribute' => $attribute,
'timestampAttributeFormat' => $saveData['format'],
'timestampAttributeTimeZone' => $this->saveTimeZone,
'min' => -2147483648, 'minString' => '1901-12-14 04:45:52',
'max' => time(), 'maxString' => '当前时间',
];
break;
}
break;
default:
break;
}
}
|
[
"protected",
"function",
"addRules",
"(",
"&",
"$",
"rules",
",",
"$",
"attribute",
")",
"{",
"$",
"displayData",
"=",
"$",
"this",
"->",
"getDisplayFormat",
"(",
"$",
"attribute",
",",
"true",
")",
";",
"$",
"saveData",
"=",
"$",
"this",
"->",
"getSaveFormat",
"(",
"$",
"attribute",
",",
"true",
")",
";",
"// 添加`required`规则",
"$",
"rules",
"[",
"]",
"=",
"[",
"$",
"attribute",
",",
"'required'",
"]",
";",
"switch",
"(",
"$",
"this",
"->",
"dateTimeWidget",
")",
"{",
"case",
"'\\wocenter\\widgets\\DateTimePicker'",
":",
"// '1901-12-14 04:45:52'的时间戳为 -2147483648,mysql int类型保存的范围从 -2^31 (-2,147,483,648) 到 2^31 – 1 (2,147,483,647) 的整型数据(所有数字)。存储大小为 4 个字节。",
"// 添加时间范围限制",
"$",
"rules",
"[",
"]",
"=",
"[",
"$",
"attribute",
",",
"$",
"displayData",
"[",
"'type'",
"]",
",",
"'format'",
"=>",
"$",
"displayData",
"[",
"'format'",
"]",
",",
"'timeZone'",
"=>",
"$",
"this",
"->",
"displayTimeZone",
",",
"'timestampAttribute'",
"=>",
"$",
"attribute",
",",
"'timestampAttributeFormat'",
"=>",
"$",
"saveData",
"[",
"'format'",
"]",
",",
"'timestampAttributeTimeZone'",
"=>",
"$",
"this",
"->",
"saveTimeZone",
",",
"'min'",
"=>",
"-",
"2147483648",
",",
"'minString'",
"=>",
"'1901-12-14 04:45:52'",
",",
"'max'",
"=>",
"time",
"(",
")",
",",
"'maxString'",
"=>",
"'当前时间',",
"",
"]",
";",
"break",
";",
"case",
"'\\wocenter\\widgets\\DateControl'",
":",
"case",
"'\\kartik\\datecontrol\\DateControl'",
":",
"switch",
"(",
"$",
"saveData",
"[",
"'format'",
"]",
")",
"{",
"case",
"'php:U'",
":",
"$",
"rules",
"[",
"]",
"=",
"[",
"$",
"attribute",
",",
"'\\wocenter\\validators\\DateControlValidator'",
"]",
";",
"break",
";",
"default",
":",
"// 添加时间范围限制",
"$",
"rules",
"[",
"]",
"=",
"[",
"$",
"attribute",
",",
"$",
"displayData",
"[",
"'type'",
"]",
",",
"'format'",
"=>",
"$",
"displayData",
"[",
"'format'",
"]",
",",
"'timeZone'",
"=>",
"$",
"this",
"->",
"displayTimeZone",
",",
"'timestampAttribute'",
"=>",
"$",
"attribute",
",",
"'timestampAttributeFormat'",
"=>",
"$",
"saveData",
"[",
"'format'",
"]",
",",
"'timestampAttributeTimeZone'",
"=>",
"$",
"this",
"->",
"saveTimeZone",
",",
"'min'",
"=>",
"-",
"2147483648",
",",
"'minString'",
"=>",
"'1901-12-14 04:45:52'",
",",
"'max'",
"=>",
"time",
"(",
")",
",",
"'maxString'",
"=>",
"'当前时间',",
"",
"]",
";",
"break",
";",
"}",
"break",
";",
"default",
":",
"break",
";",
"}",
"}"
] |
添加规则
@param array $rules 规则数据
@param string $attribute 规则字段
|
[
"添加规则"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/behaviors/ModifyTimestampBehavior.php#L228-L271
|
Wonail/wocenter
|
behaviors/ModifyTimestampBehavior.php
|
ModifyTimestampBehavior.createScenarios
|
public function createScenarios(array $modelScenarios)
{
switch ($this->owner->getScenario()) {
case 'default':
// 默认场景下,只有允许自定义的时间日期字段才会被添加进场景数据里
foreach ([$this->createdAtAttribute, $this->updatedAtAttribute] as $attribute) {
if (
is_string($attribute)
&& !in_array($attribute, $modelScenarios[$this->owner->getScenario()])
&& (
($attribute == $this->createdAtAttribute && $this->modifyCreatedAt)
|| ($attribute == $this->updatedAtAttribute && $this->modifyUpdatedAt)
)
) {
$modelScenarios['default'][] = $attribute;
}
}
break;
}
return $modelScenarios;
}
|
php
|
public function createScenarios(array $modelScenarios)
{
switch ($this->owner->getScenario()) {
case 'default':
// 默认场景下,只有允许自定义的时间日期字段才会被添加进场景数据里
foreach ([$this->createdAtAttribute, $this->updatedAtAttribute] as $attribute) {
if (
is_string($attribute)
&& !in_array($attribute, $modelScenarios[$this->owner->getScenario()])
&& (
($attribute == $this->createdAtAttribute && $this->modifyCreatedAt)
|| ($attribute == $this->updatedAtAttribute && $this->modifyUpdatedAt)
)
) {
$modelScenarios['default'][] = $attribute;
}
}
break;
}
return $modelScenarios;
}
|
[
"public",
"function",
"createScenarios",
"(",
"array",
"$",
"modelScenarios",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"owner",
"->",
"getScenario",
"(",
")",
")",
"{",
"case",
"'default'",
":",
"// 默认场景下,只有允许自定义的时间日期字段才会被添加进场景数据里",
"foreach",
"(",
"[",
"$",
"this",
"->",
"createdAtAttribute",
",",
"$",
"this",
"->",
"updatedAtAttribute",
"]",
"as",
"$",
"attribute",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"attribute",
")",
"&&",
"!",
"in_array",
"(",
"$",
"attribute",
",",
"$",
"modelScenarios",
"[",
"$",
"this",
"->",
"owner",
"->",
"getScenario",
"(",
")",
"]",
")",
"&&",
"(",
"(",
"$",
"attribute",
"==",
"$",
"this",
"->",
"createdAtAttribute",
"&&",
"$",
"this",
"->",
"modifyCreatedAt",
")",
"||",
"(",
"$",
"attribute",
"==",
"$",
"this",
"->",
"updatedAtAttribute",
"&&",
"$",
"this",
"->",
"modifyUpdatedAt",
")",
")",
")",
"{",
"$",
"modelScenarios",
"[",
"'default'",
"]",
"[",
"]",
"=",
"$",
"attribute",
";",
"}",
"}",
"break",
";",
"}",
"return",
"$",
"modelScenarios",
";",
"}"
] |
创建场景
根据配置自动添加$this->createdAtAttribute和$this->updatedAtAttribute属性字段,
场景里出现的字段会被验证和保存进数据库里
@param array $modelScenarios 模型场景
@return array
|
[
"创建场景",
"根据配置自动添加$this",
"-",
">",
"createdAtAttribute和$this",
"-",
">",
"updatedAtAttribute属性字段,",
"场景里出现的字段会被验证和保存进数据库里"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/behaviors/ModifyTimestampBehavior.php#L282-L303
|
Wonail/wocenter
|
behaviors/ModifyTimestampBehavior.php
|
ModifyTimestampBehavior.getDisplayFormat
|
public function getDisplayFormat($attribute, $returnArray = false)
{
switch ($attribute) {
case $this->createdAtAttribute:
$type = $this->createdAtDisplayType;
$format = $this->createdAtDisplayFormat;
break;
case $this->updatedAtAttribute:
$type = $this->updatedAtDisplayType;
$format = $this->updatedAtDisplayFormat;
break;
default:
throw new InvalidConfigException("The property `{$attribute}` does not exists.`");
break;
}
if (empty($format)) {
if (!empty(Yii::$app->params['dateControlDisplay'][$type])) {
$format = Yii::$app->params['dateControlDisplay'][$type];
} else {
$format = $this->_displayFormats[$type];
}
}
if (strpos($format, 'php:') === false) {
$format = DateTimeHelper::parseFormat($format, $type);
}
return $returnArray ? [
'format' => $format,
'type' => $type,
] : $format;
}
|
php
|
public function getDisplayFormat($attribute, $returnArray = false)
{
switch ($attribute) {
case $this->createdAtAttribute:
$type = $this->createdAtDisplayType;
$format = $this->createdAtDisplayFormat;
break;
case $this->updatedAtAttribute:
$type = $this->updatedAtDisplayType;
$format = $this->updatedAtDisplayFormat;
break;
default:
throw new InvalidConfigException("The property `{$attribute}` does not exists.`");
break;
}
if (empty($format)) {
if (!empty(Yii::$app->params['dateControlDisplay'][$type])) {
$format = Yii::$app->params['dateControlDisplay'][$type];
} else {
$format = $this->_displayFormats[$type];
}
}
if (strpos($format, 'php:') === false) {
$format = DateTimeHelper::parseFormat($format, $type);
}
return $returnArray ? [
'format' => $format,
'type' => $type,
] : $format;
}
|
[
"public",
"function",
"getDisplayFormat",
"(",
"$",
"attribute",
",",
"$",
"returnArray",
"=",
"false",
")",
"{",
"switch",
"(",
"$",
"attribute",
")",
"{",
"case",
"$",
"this",
"->",
"createdAtAttribute",
":",
"$",
"type",
"=",
"$",
"this",
"->",
"createdAtDisplayType",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"createdAtDisplayFormat",
";",
"break",
";",
"case",
"$",
"this",
"->",
"updatedAtAttribute",
":",
"$",
"type",
"=",
"$",
"this",
"->",
"updatedAtDisplayType",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"updatedAtDisplayFormat",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidConfigException",
"(",
"\"The property `{$attribute}` does not exists.`\"",
")",
";",
"break",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"format",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'dateControlDisplay'",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"format",
"=",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'dateControlDisplay'",
"]",
"[",
"$",
"type",
"]",
";",
"}",
"else",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"_displayFormats",
"[",
"$",
"type",
"]",
";",
"}",
"}",
"if",
"(",
"strpos",
"(",
"$",
"format",
",",
"'php:'",
")",
"===",
"false",
")",
"{",
"$",
"format",
"=",
"DateTimeHelper",
"::",
"parseFormat",
"(",
"$",
"format",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"returnArray",
"?",
"[",
"'format'",
"=>",
"$",
"format",
",",
"'type'",
"=>",
"$",
"type",
",",
"]",
":",
"$",
"format",
";",
"}"
] |
获取指定时间日期属性的显示格式,行为会按照以下序列获取相关值
- 1、如果`createdAtDisplayFormat`或`updatedAtDisplayFormat`属性已设置,该值被优先读取
- 2、如果`Yii::$app->params`已经配置了键名为`dateControlDisplay`的数据,该值被读取
- 3、以上均未设置,则根据[[$createdAtDisplayType]]或[[$updatedAtDisplayType]]属性从[[$_displayFormats]]数组里获取数据
@param string $attribute 时间日期属性
@param boolean $returnArray 是否返回数组格式的数据,默认为`false`。
@return string|array 当$returnArray为`false`时,直接返回显示格式,否则返回数组['format', 'type']
@throws InvalidConfigException
|
[
"获取指定时间日期属性的显示格式,行为会按照以下序列获取相关值"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/behaviors/ModifyTimestampBehavior.php#L318-L349
|
Wonail/wocenter
|
behaviors/ModifyTimestampBehavior.php
|
ModifyTimestampBehavior.getSaveFormat
|
public function getSaveFormat($attribute, $returnArray = false)
{
switch ($attribute) {
case $this->createdAtAttribute:
$type = $this->createdAtDisplayType;
$format = $this->createdAtSaveFormat;
break;
case $this->updatedAtAttribute:
$type = $this->updatedAtDisplayType;
$format = $this->updatedAtSaveFormat;
break;
default:
throw new InvalidConfigException("The property `{$attribute}` does not exists.`");
break;
}
if (empty($format)) {
if (!empty(Yii::$app->params['dateControlSave'][$type])) {
$format = Yii::$app->params['dateControlSave'][$type];
} else {
$format = $this->_saveFormats[$type];
}
}
if (strpos($format, 'php:') === false) {
$format = DateTimeHelper::parseFormat($format, $type);
}
return $returnArray ? [
'format' => $format,
'type' => $type,
] : $format;
}
|
php
|
public function getSaveFormat($attribute, $returnArray = false)
{
switch ($attribute) {
case $this->createdAtAttribute:
$type = $this->createdAtDisplayType;
$format = $this->createdAtSaveFormat;
break;
case $this->updatedAtAttribute:
$type = $this->updatedAtDisplayType;
$format = $this->updatedAtSaveFormat;
break;
default:
throw new InvalidConfigException("The property `{$attribute}` does not exists.`");
break;
}
if (empty($format)) {
if (!empty(Yii::$app->params['dateControlSave'][$type])) {
$format = Yii::$app->params['dateControlSave'][$type];
} else {
$format = $this->_saveFormats[$type];
}
}
if (strpos($format, 'php:') === false) {
$format = DateTimeHelper::parseFormat($format, $type);
}
return $returnArray ? [
'format' => $format,
'type' => $type,
] : $format;
}
|
[
"public",
"function",
"getSaveFormat",
"(",
"$",
"attribute",
",",
"$",
"returnArray",
"=",
"false",
")",
"{",
"switch",
"(",
"$",
"attribute",
")",
"{",
"case",
"$",
"this",
"->",
"createdAtAttribute",
":",
"$",
"type",
"=",
"$",
"this",
"->",
"createdAtDisplayType",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"createdAtSaveFormat",
";",
"break",
";",
"case",
"$",
"this",
"->",
"updatedAtAttribute",
":",
"$",
"type",
"=",
"$",
"this",
"->",
"updatedAtDisplayType",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"updatedAtSaveFormat",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidConfigException",
"(",
"\"The property `{$attribute}` does not exists.`\"",
")",
";",
"break",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"format",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'dateControlSave'",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"format",
"=",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'dateControlSave'",
"]",
"[",
"$",
"type",
"]",
";",
"}",
"else",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"_saveFormats",
"[",
"$",
"type",
"]",
";",
"}",
"}",
"if",
"(",
"strpos",
"(",
"$",
"format",
",",
"'php:'",
")",
"===",
"false",
")",
"{",
"$",
"format",
"=",
"DateTimeHelper",
"::",
"parseFormat",
"(",
"$",
"format",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"returnArray",
"?",
"[",
"'format'",
"=>",
"$",
"format",
",",
"'type'",
"=>",
"$",
"type",
",",
"]",
":",
"$",
"format",
";",
"}"
] |
获取指定时间日期属性的保存格式,行为会按照以下序列获取相关值
- 1、如果`createdAtSaveFormat`或`updatedAtSaveFormat`属性已设置,该值被优先读取
- 2、如果`Yii::$app->params`已经配置了键名为`dateControlSave`的数据,该值被读取
- 3、以上均未设置,则根据[[$createdAtDisplayType]]或[[$updatedAtDisplayType]]属性从[[$_saveFormats]]数组里获取数据
@param string $attribute 时间日期属性
@param boolean $returnArray 是否返回数组格式的数据,默认为`false`。
@return string|array 当$returnArray为`false`时,直接返回保存格式,否则返回数组['format', 'type']
@throws InvalidConfigException
|
[
"获取指定时间日期属性的保存格式,行为会按照以下序列获取相关值"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/behaviors/ModifyTimestampBehavior.php#L364-L396
|
Wonail/wocenter
|
behaviors/ModifyTimestampBehavior.php
|
ModifyTimestampBehavior.getDisplayTimeZone
|
public function getDisplayTimeZone()
{
if (empty($this->_displayTimeZone)) {
if (!empty(Yii::$app->params['dateControlDisplayTimezone'])) {
$this->_displayTimeZone = Yii::$app->params['dateControlDisplayTimezone'];
} else {
$this->_displayTimeZone = Yii::$app->getTimeZone();
}
}
return $this->_displayTimeZone;
}
|
php
|
public function getDisplayTimeZone()
{
if (empty($this->_displayTimeZone)) {
if (!empty(Yii::$app->params['dateControlDisplayTimezone'])) {
$this->_displayTimeZone = Yii::$app->params['dateControlDisplayTimezone'];
} else {
$this->_displayTimeZone = Yii::$app->getTimeZone();
}
}
return $this->_displayTimeZone;
}
|
[
"public",
"function",
"getDisplayTimeZone",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_displayTimeZone",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'dateControlDisplayTimezone'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_displayTimeZone",
"=",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'dateControlDisplayTimezone'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_displayTimeZone",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getTimeZone",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_displayTimeZone",
";",
"}"
] |
DateControl 小部件会按此时区格式化显示时间日期
@return string
|
[
"DateControl",
"小部件会按此时区格式化显示时间日期"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/behaviors/ModifyTimestampBehavior.php#L408-L419
|
Wonail/wocenter
|
behaviors/ModifyTimestampBehavior.php
|
ModifyTimestampBehavior.getSaveTimeZone
|
public function getSaveTimeZone()
{
if (empty($this->_saveTimeZone)) {
if (!empty(Yii::$app->params['dateControlSaveTimezone'])) {
$this->_saveTimeZone = Yii::$app->params['dateControlSaveTimezone'];
} else {
$this->_saveTimeZone = Yii::$app->getTimeZone();
}
}
return $this->_saveTimeZone;
}
|
php
|
public function getSaveTimeZone()
{
if (empty($this->_saveTimeZone)) {
if (!empty(Yii::$app->params['dateControlSaveTimezone'])) {
$this->_saveTimeZone = Yii::$app->params['dateControlSaveTimezone'];
} else {
$this->_saveTimeZone = Yii::$app->getTimeZone();
}
}
return $this->_saveTimeZone;
}
|
[
"public",
"function",
"getSaveTimeZone",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_saveTimeZone",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'dateControlSaveTimezone'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_saveTimeZone",
"=",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'dateControlSaveTimezone'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_saveTimeZone",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getTimeZone",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_saveTimeZone",
";",
"}"
] |
DateControl 小部件会按此时区保存时间日期
@return string
|
[
"DateControl",
"小部件会按此时区保存时间日期"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/behaviors/ModifyTimestampBehavior.php#L439-L450
|
movoin/one-swoole
|
src/Swoole/Components/Timer/Scheduler.php
|
Scheduler.tick
|
public function tick(int $interval, Closure $callback, $parameters = null): int
{
return $this->getSwoole()->tick($interval, $callback, $parameters);
}
|
php
|
public function tick(int $interval, Closure $callback, $parameters = null): int
{
return $this->getSwoole()->tick($interval, $callback, $parameters);
}
|
[
"public",
"function",
"tick",
"(",
"int",
"$",
"interval",
",",
"Closure",
"$",
"callback",
",",
"$",
"parameters",
"=",
"null",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"getSwoole",
"(",
")",
"->",
"tick",
"(",
"$",
"interval",
",",
"$",
"callback",
",",
"$",
"parameters",
")",
";",
"}"
] |
添加定时执行器
@param int $interval
@param \Closure $callback
@param mixed $parameters
@return int
|
[
"添加定时执行器"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Components/Timer/Scheduler.php#L29-L32
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.is
|
public static function is(array $arr)
{
$isdot = true;
foreach ($arr as $key => $value) {
if (!($isdot = ($isdot && !Str::contains($key, '.')))) {
break;
}
if (is_array($value)) {
$isdot = ($isdot && static::is($value));
}
}
return $isdot;
}
|
php
|
public static function is(array $arr)
{
$isdot = true;
foreach ($arr as $key => $value) {
if (!($isdot = ($isdot && !Str::contains($key, '.')))) {
break;
}
if (is_array($value)) {
$isdot = ($isdot && static::is($value));
}
}
return $isdot;
}
|
[
"public",
"static",
"function",
"is",
"(",
"array",
"$",
"arr",
")",
"{",
"$",
"isdot",
"=",
"true",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"isdot",
"=",
"(",
"$",
"isdot",
"&&",
"!",
"Str",
"::",
"contains",
"(",
"$",
"key",
",",
"'.'",
")",
")",
")",
")",
"{",
"break",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"isdot",
"=",
"(",
"$",
"isdot",
"&&",
"static",
"::",
"is",
"(",
"$",
"value",
")",
")",
";",
"}",
"}",
"return",
"$",
"isdot",
";",
"}"
] |
Tests if the given value is a dot-notated accessible array.
This function tests if none of the keys contains a dot.
@param array $arr The array to test.
@return bool Returns true if the array is dot-notated accessible, false otherwise.
@SuppressWarnings(PHPMD.ShortMethodName)
|
[
"Tests",
"if",
"the",
"given",
"value",
"is",
"a",
"dot",
"-",
"notated",
"accessible",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L37-L50
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.get
|
public static function get(array $arr, $key, $default = null)
{
if (is_array($key)) {
return static::getMultiple($arr, $key, $default);
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
return static::_get($arr, $key, $default);
}
|
php
|
public static function get(array $arr, $key, $default = null)
{
if (is_array($key)) {
return static::getMultiple($arr, $key, $default);
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
return static::_get($arr, $key, $default);
}
|
[
"public",
"static",
"function",
"get",
"(",
"array",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"return",
"static",
"::",
"getMultiple",
"(",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"if",
"(",
"!",
"Int",
"::",
"is",
"(",
"$",
"key",
")",
"&&",
"!",
"Str",
"::",
"is",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$key parameter must be int or string (or an array of them).\"",
")",
";",
"}",
"return",
"static",
"::",
"_get",
"(",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] |
Gets a value from a dot-notated array.
@param array $arr The array to get the value from.
@param int|string|array $key The key of the item's value to get or an array of keys.
@param mixed $default A default value to return if the item is not found.
@return mixed The value of the item if found, the default value otherwise.
@throws \InvalidArgumentException
|
[
"Gets",
"a",
"value",
"from",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L66-L77
|
axelitus/php-base
|
src/DotArr.php
|
DotArr._get
|
protected static function _get(array $arr, $key, $default)
{
foreach (explode('.', $key) as $keySeg) {
if (!is_array($arr) || !array_key_exists($keySeg, $arr)) {
return $default;
}
$arr = $arr[$keySeg];
}
return $arr;
}
|
php
|
protected static function _get(array $arr, $key, $default)
{
foreach (explode('.', $key) as $keySeg) {
if (!is_array($arr) || !array_key_exists($keySeg, $arr)) {
return $default;
}
$arr = $arr[$keySeg];
}
return $arr;
}
|
[
"protected",
"static",
"function",
"_get",
"(",
"array",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"default",
")",
"{",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"keySeg",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arr",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"keySeg",
",",
"$",
"arr",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"arr",
"=",
"$",
"arr",
"[",
"$",
"keySeg",
"]",
";",
"}",
"return",
"$",
"arr",
";",
"}"
] |
Gets a value from a dot-notated array.
@internal
@param array $arr The array to get the value from.
@param int|string|array $key The key of the item's value to get or an array of keys.
@param mixed $default A default value to return if the item is not found.
@return mixed The value of the item if found, the default value otherwise.
|
[
"Gets",
"a",
"value",
"from",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L90-L101
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.getMultiple
|
protected static function getMultiple(array $arr, array $keys, $default = null)
{
$return = [];
foreach ($keys as $key) {
$return[$key] = static::get($arr, $key, $default);
}
return $return;
}
|
php
|
protected static function getMultiple(array $arr, array $keys, $default = null)
{
$return = [];
foreach ($keys as $key) {
$return[$key] = static::get($arr, $key, $default);
}
return $return;
}
|
[
"protected",
"static",
"function",
"getMultiple",
"(",
"array",
"$",
"arr",
",",
"array",
"$",
"keys",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"get",
"(",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Gets multiple values from a dot-notated array.
@internal
@param array $arr The array to get the values from.
@param array $keys The keys to the items to get the values from.
@param mixed $default A default value to return if the item is not found.
@return array The values of the found items or the default values if not found.
|
[
"Gets",
"multiple",
"values",
"from",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L114-L122
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.set
|
public static function set(array &$arr, $key, $value = null)
{
if (is_array($key)) {
static::setMultiple($arr, $key);
return;
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
static::_set($arr, $key, $value);
}
|
php
|
public static function set(array &$arr, $key, $value = null)
{
if (is_array($key)) {
static::setMultiple($arr, $key);
return;
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
static::_set($arr, $key, $value);
}
|
[
"public",
"static",
"function",
"set",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"static",
"::",
"setMultiple",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"Int",
"::",
"is",
"(",
"$",
"key",
")",
"&&",
"!",
"Str",
"::",
"is",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$key parameter must be int or string (or an array of them).\"",
")",
";",
"}",
"static",
"::",
"_set",
"(",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] |
Sets a value into a dot-notated array.
@param array $arr The array to set the value to.
@param int|string|array $key The key of the item to be set or an array of key=>value pairs.
@param mixed $value The value to be set to the item.
@throws \InvalidArgumentException
|
[
"Sets",
"a",
"value",
"into",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L133-L146
|
axelitus/php-base
|
src/DotArr.php
|
DotArr._set
|
protected static function _set(array &$arr, $key, $value = null)
{
$keys = explode('.', $key);
while (count($keys) > 1) {
$key = array_shift($keys);
if (!isset($arr[$key]) || !is_array($arr[$key])) {
$arr[$key] = [];
}
$arr =& $arr[$key];
}
$arr[array_shift($keys)] = $value;
}
|
php
|
protected static function _set(array &$arr, $key, $value = null)
{
$keys = explode('.', $key);
while (count($keys) > 1) {
$key = array_shift($keys);
if (!isset($arr[$key]) || !is_array($arr[$key])) {
$arr[$key] = [];
}
$arr =& $arr[$key];
}
$arr[array_shift($keys)] = $value;
}
|
[
"protected",
"static",
"function",
"_set",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"while",
"(",
"count",
"(",
"$",
"keys",
")",
">",
"1",
")",
"{",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"arr",
"[",
"$",
"key",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"arr",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"arr",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"arr",
"=",
"&",
"$",
"arr",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"arr",
"[",
"array_shift",
"(",
"$",
"keys",
")",
"]",
"=",
"$",
"value",
";",
"}"
] |
Sets a value into a dot-notated array.
@internal
@param array $arr The array to set the value to.
@param int|string|array $key The key of the item to be set or an array of key=>value pairs.
@param mixed $value The value to be set to the item.
|
[
"Sets",
"a",
"value",
"into",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L157-L170
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.setMultiple
|
protected static function setMultiple(array &$arr, array $keyvals)
{
foreach ($keyvals as $key => $value) {
static::set($arr, $key, $value);
}
}
|
php
|
protected static function setMultiple(array &$arr, array $keyvals)
{
foreach ($keyvals as $key => $value) {
static::set($arr, $key, $value);
}
}
|
[
"protected",
"static",
"function",
"setMultiple",
"(",
"array",
"&",
"$",
"arr",
",",
"array",
"$",
"keyvals",
")",
"{",
"foreach",
"(",
"$",
"keyvals",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"static",
"::",
"set",
"(",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] |
Sets multiple values to a dot-notated array.
@internal
@param array $arr The array to set the values to.
@param array $keyvals The key=>value associative array to set the item values.
|
[
"Sets",
"multiple",
"values",
"to",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L180-L185
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.delete
|
public static function delete(array &$arr, $key)
{
if (is_array($key)) {
return static::deleteMultiple($arr, $key);
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
return static::_delete($arr, $key);
}
|
php
|
public static function delete(array &$arr, $key)
{
if (is_array($key)) {
return static::deleteMultiple($arr, $key);
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
return static::_delete($arr, $key);
}
|
[
"public",
"static",
"function",
"delete",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"key",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"return",
"static",
"::",
"deleteMultiple",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}",
"if",
"(",
"!",
"Int",
"::",
"is",
"(",
"$",
"key",
")",
"&&",
"!",
"Str",
"::",
"is",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$key parameter must be int or string (or an array of them).\"",
")",
";",
"}",
"return",
"static",
"::",
"_delete",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}"
] |
Deletes an item from a dot-notated array.
@param array $arr The dot-notated array.
@param int|string|array $key The key of the item to delete or array of keys.
@return bool|array Returns true if the item was found and deleted, false otherwise (or an array of results).
@throws \InvalidArgumentException
|
[
"Deletes",
"an",
"item",
"from",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L196-L207
|
axelitus/php-base
|
src/DotArr.php
|
DotArr._delete
|
protected static function _delete(array &$arr, $key)
{
// TODO: optimize this chunk of code if possible
$tmp =& $arr;
$keys = explode('.', $key);
while (count($keys) > 1) {
$key = array_shift($keys);
if (!is_array($tmp[$key])) {
return false;
}
$tmp =& $tmp[$key];
}
$key = array_shift($keys);
if (array_key_exists($key, $tmp)) {
unset($tmp[$key]);
return true;
}
return false;
}
|
php
|
protected static function _delete(array &$arr, $key)
{
// TODO: optimize this chunk of code if possible
$tmp =& $arr;
$keys = explode('.', $key);
while (count($keys) > 1) {
$key = array_shift($keys);
if (!is_array($tmp[$key])) {
return false;
}
$tmp =& $tmp[$key];
}
$key = array_shift($keys);
if (array_key_exists($key, $tmp)) {
unset($tmp[$key]);
return true;
}
return false;
}
|
[
"protected",
"static",
"function",
"_delete",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"key",
")",
"{",
"// TODO: optimize this chunk of code if possible",
"$",
"tmp",
"=",
"&",
"$",
"arr",
";",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"while",
"(",
"count",
"(",
"$",
"keys",
")",
">",
"1",
")",
"{",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"tmp",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tmp",
"=",
"&",
"$",
"tmp",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"tmp",
")",
")",
"{",
"unset",
"(",
"$",
"tmp",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Deletes an item from a dot-notated array.
@internal
@param array $arr The dot-notated array.
@param int|string|array $key The key of the item to delete or array of keys.
@return bool|array Returns true if the item was found and deleted, false otherwise (or an array of results).
|
[
"Deletes",
"an",
"item",
"from",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L219-L242
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.deleteMultiple
|
protected static function deleteMultiple(array &$arr, array $keys)
{
$return = [];
foreach ($keys as $key) {
$return[$key] = static::delete($arr, $key);
}
return $return;
}
|
php
|
protected static function deleteMultiple(array &$arr, array $keys)
{
$return = [];
foreach ($keys as $key) {
$return[$key] = static::delete($arr, $key);
}
return $return;
}
|
[
"protected",
"static",
"function",
"deleteMultiple",
"(",
"array",
"&",
"$",
"arr",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"delete",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Deletes multiple items from a dot-notated array.
@internal
@param array $arr The array to delete the items from.
@param array $keys The keys of the items to delete.
@return array Returns an array of results.
|
[
"Deletes",
"multiple",
"items",
"from",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L254-L262
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.keyExists
|
public static function keyExists(array $arr, $key)
{
if (is_array($key)) {
return static::keyExistsMultiple($arr, $key);
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
return static::_keyExists($arr, $key);
}
|
php
|
public static function keyExists(array $arr, $key)
{
if (is_array($key)) {
return static::keyExistsMultiple($arr, $key);
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
return static::_keyExists($arr, $key);
}
|
[
"public",
"static",
"function",
"keyExists",
"(",
"array",
"$",
"arr",
",",
"$",
"key",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"return",
"static",
"::",
"keyExistsMultiple",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}",
"if",
"(",
"!",
"Int",
"::",
"is",
"(",
"$",
"key",
")",
"&&",
"!",
"Str",
"::",
"is",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$key parameter must be int or string (or an array of them).\"",
")",
";",
"}",
"return",
"static",
"::",
"_keyExists",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}"
] |
Verifies if an item with the given key exists in a dot-notated array or not.
@param array $arr The dot-notated array.
@param int|string|array $key The key of the item to check for or an array of keys.
@return bool|array Returns true if the item exists, false otherwise (or an array of results).
@throws \InvalidArgumentException
|
[
"Verifies",
"if",
"an",
"item",
"with",
"the",
"given",
"key",
"exists",
"in",
"a",
"dot",
"-",
"notated",
"array",
"or",
"not",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L277-L288
|
axelitus/php-base
|
src/DotArr.php
|
DotArr._keyExists
|
protected static function _keyExists(array $arr, $key)
{
if (array_key_exists($key, $arr)) {
return true;
}
foreach (explode('.', $key) as $keySeg) {
if (!is_array($arr) || !array_key_exists($keySeg, $arr)) {
return false;
}
$arr = $arr[$keySeg];
}
return true;
}
|
php
|
protected static function _keyExists(array $arr, $key)
{
if (array_key_exists($key, $arr)) {
return true;
}
foreach (explode('.', $key) as $keySeg) {
if (!is_array($arr) || !array_key_exists($keySeg, $arr)) {
return false;
}
$arr = $arr[$keySeg];
}
return true;
}
|
[
"protected",
"static",
"function",
"_keyExists",
"(",
"array",
"$",
"arr",
",",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"arr",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"keySeg",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arr",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"keySeg",
",",
"$",
"arr",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"arr",
"=",
"$",
"arr",
"[",
"$",
"keySeg",
"]",
";",
"}",
"return",
"true",
";",
"}"
] |
Verifies if an item with the given key exists in a dot-notated array or not.
@internal
@param array $arr The dot-notated array.
@param int|string|array $key The key of the item to check for or an array of keys.
@return bool|array Returns true if the item exists, false otherwise (or an array of results).
|
[
"Verifies",
"if",
"an",
"item",
"with",
"the",
"given",
"key",
"exists",
"in",
"a",
"dot",
"-",
"notated",
"array",
"or",
"not",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L300-L315
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.keyExistsMultiple
|
protected static function keyExistsMultiple(array $arr, array $keys)
{
$return = [];
foreach ($keys as $key) {
$return[$key] = static::keyExists($arr, $key);
}
return $return;
}
|
php
|
protected static function keyExistsMultiple(array $arr, array $keys)
{
$return = [];
foreach ($keys as $key) {
$return[$key] = static::keyExists($arr, $key);
}
return $return;
}
|
[
"protected",
"static",
"function",
"keyExistsMultiple",
"(",
"array",
"$",
"arr",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"keyExists",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Verifies if multiple keys exists in a dot-notated array or not.
@param array $arr The dot-notated array.
@param array $keys The keys to verify.
@return array The array of results.
|
[
"Verifies",
"if",
"multiple",
"keys",
"exists",
"in",
"a",
"dot",
"-",
"notated",
"array",
"or",
"not",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L325-L333
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.keyMatches
|
public static function keyMatches(array $arr, $key)
{
if (is_array($key)) {
return static::keyMatchesMultiple($arr, $key);
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
return static::_keyMatches($arr, $key);
}
|
php
|
public static function keyMatches(array $arr, $key)
{
if (is_array($key)) {
return static::keyMatchesMultiple($arr, $key);
}
if (!Int::is($key) && !Str::is($key)) {
throw new \InvalidArgumentException("The \$key parameter must be int or string (or an array of them).");
}
return static::_keyMatches($arr, $key);
}
|
[
"public",
"static",
"function",
"keyMatches",
"(",
"array",
"$",
"arr",
",",
"$",
"key",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"return",
"static",
"::",
"keyMatchesMultiple",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}",
"if",
"(",
"!",
"Int",
"::",
"is",
"(",
"$",
"key",
")",
"&&",
"!",
"Str",
"::",
"is",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$key parameter must be int or string (or an array of them).\"",
")",
";",
"}",
"return",
"static",
"::",
"_keyMatches",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}"
] |
Gets full and partial matches to the given key.
The function matches each key sub level to a partial match.
@param array $arr The array to match the key to.
@param int|string|array $key The key to be matched or an array of keys.
@return array The array of full and partial matches.
@throws \InvalidArgumentException
|
[
"Gets",
"full",
"and",
"partial",
"matches",
"to",
"the",
"given",
"key",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L346-L357
|
axelitus/php-base
|
src/DotArr.php
|
DotArr._keyMatches
|
public static function _keyMatches(array $arr, $key)
{
$match = '';
$return = [];
foreach (explode('.', $key) as $k) {
if (!is_array($arr) || !array_key_exists($k, $arr)) {
return $return;
}
$match .= (($match != '') ? '.' : '') . $k;
$return[] = $match;
$arr =& $arr[$k];
}
return $return;
}
|
php
|
public static function _keyMatches(array $arr, $key)
{
$match = '';
$return = [];
foreach (explode('.', $key) as $k) {
if (!is_array($arr) || !array_key_exists($k, $arr)) {
return $return;
}
$match .= (($match != '') ? '.' : '') . $k;
$return[] = $match;
$arr =& $arr[$k];
}
return $return;
}
|
[
"public",
"static",
"function",
"_keyMatches",
"(",
"array",
"$",
"arr",
",",
"$",
"key",
")",
"{",
"$",
"match",
"=",
"''",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arr",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"k",
",",
"$",
"arr",
")",
")",
"{",
"return",
"$",
"return",
";",
"}",
"$",
"match",
".=",
"(",
"(",
"$",
"match",
"!=",
"''",
")",
"?",
"'.'",
":",
"''",
")",
".",
"$",
"k",
";",
"$",
"return",
"[",
"]",
"=",
"$",
"match",
";",
"$",
"arr",
"=",
"&",
"$",
"arr",
"[",
"$",
"k",
"]",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Gets full and partial matches to the given key.
The function matches each key sub level to a partial match.
@internal
@param array $arr The array to match the key to.
@param int|string|array $key The key to be matched or an array of keys.
@return array The array of full and partial matches.
|
[
"Gets",
"full",
"and",
"partial",
"matches",
"to",
"the",
"given",
"key",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L371-L386
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.keyMatchesMultiple
|
protected static function keyMatchesMultiple(array $arr, array $keys)
{
$return = [];
foreach ($keys as $key) {
$return[$key] = static::keyMatches($arr, $key);
}
return $return;
}
|
php
|
protected static function keyMatchesMultiple(array $arr, array $keys)
{
$return = [];
foreach ($keys as $key) {
$return[$key] = static::keyMatches($arr, $key);
}
return $return;
}
|
[
"protected",
"static",
"function",
"keyMatchesMultiple",
"(",
"array",
"$",
"arr",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"keyMatches",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Gets full and partial matches to multiple keys.
@param array $arr The array to match the keys to.
@param array $keys The keys to be matched.
@return array The array of ful and partial matches of the given keys.
|
[
"Gets",
"full",
"and",
"partial",
"matches",
"to",
"multiple",
"keys",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L396-L404
|
axelitus/php-base
|
src/DotArr.php
|
DotArr.convert
|
public static function convert(array $arr)
{
$converted = [];
foreach ($arr as $key => $value) {
$keys = explode('.', $key);
$tmp =& $converted;
foreach ($keys as $k) {
if (!array_key_exists($k, $tmp) || !is_array($tmp[$k])) {
$tmp[$k] = [];
}
$tmp =& $tmp[$k];
}
$tmp = is_array($value) ? static::convert($value) : $value;
}
return $converted;
}
|
php
|
public static function convert(array $arr)
{
$converted = [];
foreach ($arr as $key => $value) {
$keys = explode('.', $key);
$tmp =& $converted;
foreach ($keys as $k) {
if (!array_key_exists($k, $tmp) || !is_array($tmp[$k])) {
$tmp[$k] = [];
}
$tmp =& $tmp[$k];
}
$tmp = is_array($value) ? static::convert($value) : $value;
}
return $converted;
}
|
[
"public",
"static",
"function",
"convert",
"(",
"array",
"$",
"arr",
")",
"{",
"$",
"converted",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"tmp",
"=",
"&",
"$",
"converted",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"k",
",",
"$",
"tmp",
")",
"||",
"!",
"is_array",
"(",
"$",
"tmp",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"tmp",
"[",
"$",
"k",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"tmp",
"=",
"&",
"$",
"tmp",
"[",
"$",
"k",
"]",
";",
"}",
"$",
"tmp",
"=",
"is_array",
"(",
"$",
"value",
")",
"?",
"static",
"::",
"convert",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"}",
"return",
"$",
"converted",
";",
"}"
] |
Converts an array to a dot-notated array.
Be aware that some values may be lost in this conversion if a partial key match is found
twice or more. The last found element of a partial key match is the one that takes precedence.
@param array $arr The array to convert.
@return array The converted array.
|
[
"Converts",
"an",
"array",
"to",
"a",
"dot",
"-",
"notated",
"array",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/DotArr.php#L420-L438
|
phramework/validate
|
src/ArrayValidator.php
|
ArrayValidator.validate
|
public function validate($value)
{
$return = new ValidateResult($value, false);
if (!is_array($value)) {
$return->errorObject = 'properties validation';
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'type'
]
]);
return $return;
} else {
$propertiesCount = count($value);
if ($propertiesCount < $this->minItems) {
//error
$return->errorObject = new IncorrectParametersException(
[
'type' => static::getType(),
'failure' => 'minItems'
]
);
return $return;
} elseif ($this->maxItems !== null
&& $propertiesCount > $this->maxItems
) {
$return->errorObject = new IncorrectParametersException(
[
'type' => static::getType(),
'failure' => 'maxItems'
]
);
//error
return $return;
}
}
if ($this->items !== null) {
$errorItems = [];
//Currently we support only a single type
foreach ($value as $k => $v) {
$validateItems = $this->items->validate($v);
if (!$validateItems->status) {
$errorItems[$k] = $validateItems->errorObject->getParameters()[0];
} else {
$value[$k] = $validateItems->value;
}
}
if (!empty($errorItems)) {
$return->errorObject = new IncorrectParametersException(
[
'type' => static::getType(),
'failure' => 'items',
'items' => [
$errorItems
]
]
);
return $return;
}
}
//Check if contains duplicate items
if ($this->uniqueItems
&& count($value) !== count(array_unique($value, SORT_REGULAR))
) {
$return->errorObject = new IncorrectParametersException(
[
'type' => static::getType(),
'failure' => 'uniqueItems'
]
);
return $return;
}
//Success
$return->errorObject = null;
$return->status = true;
//type casted
$return->value = $value;
return $this->validateCommon($value, $return);
}
|
php
|
public function validate($value)
{
$return = new ValidateResult($value, false);
if (!is_array($value)) {
$return->errorObject = 'properties validation';
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'type'
]
]);
return $return;
} else {
$propertiesCount = count($value);
if ($propertiesCount < $this->minItems) {
//error
$return->errorObject = new IncorrectParametersException(
[
'type' => static::getType(),
'failure' => 'minItems'
]
);
return $return;
} elseif ($this->maxItems !== null
&& $propertiesCount > $this->maxItems
) {
$return->errorObject = new IncorrectParametersException(
[
'type' => static::getType(),
'failure' => 'maxItems'
]
);
//error
return $return;
}
}
if ($this->items !== null) {
$errorItems = [];
//Currently we support only a single type
foreach ($value as $k => $v) {
$validateItems = $this->items->validate($v);
if (!$validateItems->status) {
$errorItems[$k] = $validateItems->errorObject->getParameters()[0];
} else {
$value[$k] = $validateItems->value;
}
}
if (!empty($errorItems)) {
$return->errorObject = new IncorrectParametersException(
[
'type' => static::getType(),
'failure' => 'items',
'items' => [
$errorItems
]
]
);
return $return;
}
}
//Check if contains duplicate items
if ($this->uniqueItems
&& count($value) !== count(array_unique($value, SORT_REGULAR))
) {
$return->errorObject = new IncorrectParametersException(
[
'type' => static::getType(),
'failure' => 'uniqueItems'
]
);
return $return;
}
//Success
$return->errorObject = null;
$return->status = true;
//type casted
$return->value = $value;
return $this->validateCommon($value, $return);
}
|
[
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"$",
"return",
"=",
"new",
"ValidateResult",
"(",
"$",
"value",
",",
"false",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"return",
"->",
"errorObject",
"=",
"'properties validation'",
";",
"//error",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'type'",
"]",
"]",
")",
";",
"return",
"$",
"return",
";",
"}",
"else",
"{",
"$",
"propertiesCount",
"=",
"count",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"propertiesCount",
"<",
"$",
"this",
"->",
"minItems",
")",
"{",
"//error",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'minItems'",
"]",
")",
";",
"return",
"$",
"return",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"maxItems",
"!==",
"null",
"&&",
"$",
"propertiesCount",
">",
"$",
"this",
"->",
"maxItems",
")",
"{",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'maxItems'",
"]",
")",
";",
"//error",
"return",
"$",
"return",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"items",
"!==",
"null",
")",
"{",
"$",
"errorItems",
"=",
"[",
"]",
";",
"//Currently we support only a single type",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"validateItems",
"=",
"$",
"this",
"->",
"items",
"->",
"validate",
"(",
"$",
"v",
")",
";",
"if",
"(",
"!",
"$",
"validateItems",
"->",
"status",
")",
"{",
"$",
"errorItems",
"[",
"$",
"k",
"]",
"=",
"$",
"validateItems",
"->",
"errorObject",
"->",
"getParameters",
"(",
")",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"value",
"[",
"$",
"k",
"]",
"=",
"$",
"validateItems",
"->",
"value",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"errorItems",
")",
")",
"{",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'items'",
",",
"'items'",
"=>",
"[",
"$",
"errorItems",
"]",
"]",
")",
";",
"return",
"$",
"return",
";",
"}",
"}",
"//Check if contains duplicate items",
"if",
"(",
"$",
"this",
"->",
"uniqueItems",
"&&",
"count",
"(",
"$",
"value",
")",
"!==",
"count",
"(",
"array_unique",
"(",
"$",
"value",
",",
"SORT_REGULAR",
")",
")",
")",
"{",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'uniqueItems'",
"]",
")",
";",
"return",
"$",
"return",
";",
"}",
"//Success",
"$",
"return",
"->",
"errorObject",
"=",
"null",
";",
"$",
"return",
"->",
"status",
"=",
"true",
";",
"//type casted",
"$",
"return",
"->",
"value",
"=",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"validateCommon",
"(",
"$",
"value",
",",
"$",
"return",
")",
";",
"}"
] |
Validate value
@see \Phramework\Validate\ValidateResult for ValidateResult object
@param mixed $value Value to validate
@return ValidateResult
@todo incomplete
|
[
"Validate",
"value"
] |
train
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/ArrayValidator.php#L108-L196
|
acasademont/wurfl
|
WURFL/UserAgentHandlerChainFactory.php
|
WURFL_UserAgentHandlerChainFactory.createFrom
|
public static function createFrom(WURFL_Context $context)
{
$cached_data = $context->cacheProvider->load('UserAgentHandlerChain');
if ($cached_data !== null) {
self::$_userAgentHandlerChain = $cached_data;
foreach (self::$_userAgentHandlerChain->getHandlers() as $handler) {
$handler->setupContext($context);
}
}
if (!(self::$_userAgentHandlerChain instanceof WURFL_UserAgentHandlerChain)) {
self::init($context);
$context->cacheProvider->save('UserAgentHandlerChain', self::$_userAgentHandlerChain, 3600);
}
return self::$_userAgentHandlerChain;
}
|
php
|
public static function createFrom(WURFL_Context $context)
{
$cached_data = $context->cacheProvider->load('UserAgentHandlerChain');
if ($cached_data !== null) {
self::$_userAgentHandlerChain = $cached_data;
foreach (self::$_userAgentHandlerChain->getHandlers() as $handler) {
$handler->setupContext($context);
}
}
if (!(self::$_userAgentHandlerChain instanceof WURFL_UserAgentHandlerChain)) {
self::init($context);
$context->cacheProvider->save('UserAgentHandlerChain', self::$_userAgentHandlerChain, 3600);
}
return self::$_userAgentHandlerChain;
}
|
[
"public",
"static",
"function",
"createFrom",
"(",
"WURFL_Context",
"$",
"context",
")",
"{",
"$",
"cached_data",
"=",
"$",
"context",
"->",
"cacheProvider",
"->",
"load",
"(",
"'UserAgentHandlerChain'",
")",
";",
"if",
"(",
"$",
"cached_data",
"!==",
"null",
")",
"{",
"self",
"::",
"$",
"_userAgentHandlerChain",
"=",
"$",
"cached_data",
";",
"foreach",
"(",
"self",
"::",
"$",
"_userAgentHandlerChain",
"->",
"getHandlers",
"(",
")",
"as",
"$",
"handler",
")",
"{",
"$",
"handler",
"->",
"setupContext",
"(",
"$",
"context",
")",
";",
"}",
"}",
"if",
"(",
"!",
"(",
"self",
"::",
"$",
"_userAgentHandlerChain",
"instanceof",
"WURFL_UserAgentHandlerChain",
")",
")",
"{",
"self",
"::",
"init",
"(",
"$",
"context",
")",
";",
"$",
"context",
"->",
"cacheProvider",
"->",
"save",
"(",
"'UserAgentHandlerChain'",
",",
"self",
"::",
"$",
"_userAgentHandlerChain",
",",
"3600",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_userAgentHandlerChain",
";",
"}"
] |
Create a WURFL_UserAgentHandlerChain from the given $context
@param WURFL_Context $context
@return WURFL_UserAgentHandlerChain
|
[
"Create",
"a",
"WURFL_UserAgentHandlerChain",
"from",
"the",
"given",
"$context"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/UserAgentHandlerChainFactory.php#L35-L49
|
acasademont/wurfl
|
WURFL/UserAgentHandlerChainFactory.php
|
WURFL_UserAgentHandlerChainFactory.createGenericNormalizers
|
public static function createGenericNormalizers()
{
return new WURFL_Request_UserAgentNormalizer(array(
new WURFL_Request_UserAgentNormalizer_Generic_UCWEB(),
new WURFL_Request_UserAgentNormalizer_Generic_UPLink(),
new WURFL_Request_UserAgentNormalizer_Generic_SerialNumbers(),
new WURFL_Request_UserAgentNormalizer_Generic_LocaleRemover(),
new WURFL_Request_UserAgentNormalizer_Generic_CFNetwork(),
new WURFL_Request_UserAgentNormalizer_Generic_BlackBerry(),
new WURFL_Request_UserAgentNormalizer_Generic_Android(),
//new WURFL_Request_UserAgentNormalizer_Generic_YesWAP(),
//new WURFL_Request_UserAgentNormalizer_Generic_BabelFish(),
//new WURFL_Request_UserAgentNormalizer_Generic_NovarraGoogleTranslator(),
new WURFL_Request_UserAgentNormalizer_Generic_TransferEncoding(),
));
}
|
php
|
public static function createGenericNormalizers()
{
return new WURFL_Request_UserAgentNormalizer(array(
new WURFL_Request_UserAgentNormalizer_Generic_UCWEB(),
new WURFL_Request_UserAgentNormalizer_Generic_UPLink(),
new WURFL_Request_UserAgentNormalizer_Generic_SerialNumbers(),
new WURFL_Request_UserAgentNormalizer_Generic_LocaleRemover(),
new WURFL_Request_UserAgentNormalizer_Generic_CFNetwork(),
new WURFL_Request_UserAgentNormalizer_Generic_BlackBerry(),
new WURFL_Request_UserAgentNormalizer_Generic_Android(),
//new WURFL_Request_UserAgentNormalizer_Generic_YesWAP(),
//new WURFL_Request_UserAgentNormalizer_Generic_BabelFish(),
//new WURFL_Request_UserAgentNormalizer_Generic_NovarraGoogleTranslator(),
new WURFL_Request_UserAgentNormalizer_Generic_TransferEncoding(),
));
}
|
[
"public",
"static",
"function",
"createGenericNormalizers",
"(",
")",
"{",
"return",
"new",
"WURFL_Request_UserAgentNormalizer",
"(",
"array",
"(",
"new",
"WURFL_Request_UserAgentNormalizer_Generic_UCWEB",
"(",
")",
",",
"new",
"WURFL_Request_UserAgentNormalizer_Generic_UPLink",
"(",
")",
",",
"new",
"WURFL_Request_UserAgentNormalizer_Generic_SerialNumbers",
"(",
")",
",",
"new",
"WURFL_Request_UserAgentNormalizer_Generic_LocaleRemover",
"(",
")",
",",
"new",
"WURFL_Request_UserAgentNormalizer_Generic_CFNetwork",
"(",
")",
",",
"new",
"WURFL_Request_UserAgentNormalizer_Generic_BlackBerry",
"(",
")",
",",
"new",
"WURFL_Request_UserAgentNormalizer_Generic_Android",
"(",
")",
",",
"//new WURFL_Request_UserAgentNormalizer_Generic_YesWAP(),",
"//new WURFL_Request_UserAgentNormalizer_Generic_BabelFish(),",
"//new WURFL_Request_UserAgentNormalizer_Generic_NovarraGoogleTranslator(),",
"new",
"WURFL_Request_UserAgentNormalizer_Generic_TransferEncoding",
"(",
")",
",",
")",
")",
";",
"}"
] |
Returns a User Agent Normalizer chain containing all generic normalizers
@return WURFL_Request_UserAgentNormalizer
|
[
"Returns",
"a",
"User",
"Agent",
"Normalizer",
"chain",
"containing",
"all",
"generic",
"normalizers"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/UserAgentHandlerChainFactory.php#L189-L204
|
activecollab/databasestructure
|
src/Builder/Builder.php
|
Builder.registerEventHandler
|
public function registerEventHandler($event, callable $handler)
{
if (empty($event)) {
throw new InvalidArgumentException('Event name is required');
}
if (is_callable($handler)) {
if (empty($this->event_handlers[$event])) {
$this->event_handlers[$event] = [];
}
$this->event_handlers[$event][] = $handler;
} else {
throw new InvalidArgumentException('Handler not callable');
}
}
|
php
|
public function registerEventHandler($event, callable $handler)
{
if (empty($event)) {
throw new InvalidArgumentException('Event name is required');
}
if (is_callable($handler)) {
if (empty($this->event_handlers[$event])) {
$this->event_handlers[$event] = [];
}
$this->event_handlers[$event][] = $handler;
} else {
throw new InvalidArgumentException('Handler not callable');
}
}
|
[
"public",
"function",
"registerEventHandler",
"(",
"$",
"event",
",",
"callable",
"$",
"handler",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"event",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Event name is required'",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"handler",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"event_handlers",
"[",
"$",
"event",
"]",
")",
")",
"{",
"$",
"this",
"->",
"event_handlers",
"[",
"$",
"event",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"event_handlers",
"[",
"$",
"event",
"]",
"[",
"]",
"=",
"$",
"handler",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Handler not callable'",
")",
";",
"}",
"}"
] |
Register an internal event handler.
@param string $event
@param callable $handler
|
[
"Register",
"an",
"internal",
"event",
"handler",
"."
] |
train
|
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/Builder.php#L80-L95
|
esperecyan/dictionary-php
|
src/serializer/GenericDictionarySerializer.php
|
GenericDictionarySerializer.getColumnPosition
|
protected function getColumnPosition(string $fieldName): int
{
$position = array_search($fieldName, self::COLUMN_POSITIONS, true);
return is_int($position) ? $position : PHP_INT_MAX;
}
|
php
|
protected function getColumnPosition(string $fieldName): int
{
$position = array_search($fieldName, self::COLUMN_POSITIONS, true);
return is_int($position) ? $position : PHP_INT_MAX;
}
|
[
"protected",
"function",
"getColumnPosition",
"(",
"string",
"$",
"fieldName",
")",
":",
"int",
"{",
"$",
"position",
"=",
"array_search",
"(",
"$",
"fieldName",
",",
"self",
"::",
"COLUMN_POSITIONS",
",",
"true",
")",
";",
"return",
"is_int",
"(",
"$",
"position",
")",
"?",
"$",
"position",
":",
"PHP_INT_MAX",
";",
"}"
] |
列の位置の比較に使うインデックスを返します。
@param string $fieldName
@return int
|
[
"列の位置の比較に使うインデックスを返します。"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/serializer/GenericDictionarySerializer.php#L34-L38
|
esperecyan/dictionary-php
|
src/serializer/GenericDictionarySerializer.php
|
GenericDictionarySerializer.getFieldNames
|
protected function getFieldNames(Dictionary $dictionary): array
{
// 各フィールド名について、全レコード中の最大数をそれぞれ取得
foreach ($dictionary->getWords() as $word) {
foreach ($word as $fieldName => $fields) {
$fieldLengths[$fieldName] = max(count($fields), $fieldLengths[$fieldName] ?? 0);
}
}
$fieldLengths += array_fill_keys(array_keys($dictionary->getMetadata()), 1);
uksort($fieldLengths, function (string $a, string $b): int {
return $this->getColumnPosition($a) <=> $this->getColumnPosition($b);
});
// ヘッダを生成
return array_merge(...array_map(function (string $fieldName, int $length): array {
return array_fill(0, $length, $fieldName);
}, array_keys($fieldLengths), $fieldLengths));
}
|
php
|
protected function getFieldNames(Dictionary $dictionary): array
{
// 各フィールド名について、全レコード中の最大数をそれぞれ取得
foreach ($dictionary->getWords() as $word) {
foreach ($word as $fieldName => $fields) {
$fieldLengths[$fieldName] = max(count($fields), $fieldLengths[$fieldName] ?? 0);
}
}
$fieldLengths += array_fill_keys(array_keys($dictionary->getMetadata()), 1);
uksort($fieldLengths, function (string $a, string $b): int {
return $this->getColumnPosition($a) <=> $this->getColumnPosition($b);
});
// ヘッダを生成
return array_merge(...array_map(function (string $fieldName, int $length): array {
return array_fill(0, $length, $fieldName);
}, array_keys($fieldLengths), $fieldLengths));
}
|
[
"protected",
"function",
"getFieldNames",
"(",
"Dictionary",
"$",
"dictionary",
")",
":",
"array",
"{",
"// 各フィールド名について、全レコード中の最大数をそれぞれ取得",
"foreach",
"(",
"$",
"dictionary",
"->",
"getWords",
"(",
")",
"as",
"$",
"word",
")",
"{",
"foreach",
"(",
"$",
"word",
"as",
"$",
"fieldName",
"=>",
"$",
"fields",
")",
"{",
"$",
"fieldLengths",
"[",
"$",
"fieldName",
"]",
"=",
"max",
"(",
"count",
"(",
"$",
"fields",
")",
",",
"$",
"fieldLengths",
"[",
"$",
"fieldName",
"]",
"??",
"0",
")",
";",
"}",
"}",
"$",
"fieldLengths",
"+=",
"array_fill_keys",
"(",
"array_keys",
"(",
"$",
"dictionary",
"->",
"getMetadata",
"(",
")",
")",
",",
"1",
")",
";",
"uksort",
"(",
"$",
"fieldLengths",
",",
"function",
"(",
"string",
"$",
"a",
",",
"string",
"$",
"b",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"getColumnPosition",
"(",
"$",
"a",
")",
"<=>",
"$",
"this",
"->",
"getColumnPosition",
"(",
"$",
"b",
")",
";",
"}",
")",
";",
"// ヘッダを生成",
"return",
"array_merge",
"(",
"...",
"array_map",
"(",
"function",
"(",
"string",
"$",
"fieldName",
",",
"int",
"$",
"length",
")",
":",
"array",
"{",
"return",
"array_fill",
"(",
"0",
",",
"$",
"length",
",",
"$",
"fieldName",
")",
";",
"}",
",",
"array_keys",
"(",
"$",
"fieldLengths",
")",
",",
"$",
"fieldLengths",
")",
")",
";",
"}"
] |
ヘッダ行に用いるフィールド名の一覧を生成します。
@param Dictionary $dictionary
@return string[]
|
[
"ヘッダ行に用いるフィールド名の一覧を生成します。"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/serializer/GenericDictionarySerializer.php#L45-L64
|
esperecyan/dictionary-php
|
src/serializer/GenericDictionarySerializer.php
|
GenericDictionarySerializer.putCSVRecord
|
protected function putCSVRecord(\SplFileObject $file, array $fields)
{
$file->fputcsv(array_map(function (string $field): string {
return preg_replace(
'/[\\x00-\\x09\\x11\\x7F]+/u',
'',
strtr($field, ["\r\n" => "\r\n", "\r" => "\r\n", "\n" => "\r\n"])
);
}, $fields));
$file->fseek(-1, SEEK_CUR);
$file->fwrite("\r\n");
}
|
php
|
protected function putCSVRecord(\SplFileObject $file, array $fields)
{
$file->fputcsv(array_map(function (string $field): string {
return preg_replace(
'/[\\x00-\\x09\\x11\\x7F]+/u',
'',
strtr($field, ["\r\n" => "\r\n", "\r" => "\r\n", "\n" => "\r\n"])
);
}, $fields));
$file->fseek(-1, SEEK_CUR);
$file->fwrite("\r\n");
}
|
[
"protected",
"function",
"putCSVRecord",
"(",
"\\",
"SplFileObject",
"$",
"file",
",",
"array",
"$",
"fields",
")",
"{",
"$",
"file",
"->",
"fputcsv",
"(",
"array_map",
"(",
"function",
"(",
"string",
"$",
"field",
")",
":",
"string",
"{",
"return",
"preg_replace",
"(",
"'/[\\\\x00-\\\\x09\\\\x11\\\\x7F]+/u'",
",",
"''",
",",
"strtr",
"(",
"$",
"field",
",",
"[",
"\"\\r\\n\"",
"=>",
"\"\\r\\n\"",
",",
"\"\\r\"",
"=>",
"\"\\r\\n\"",
",",
"\"\\n\"",
"=>",
"\"\\r\\n\"",
"]",
")",
")",
";",
"}",
",",
"$",
"fields",
")",
")",
";",
"$",
"file",
"->",
"fseek",
"(",
"-",
"1",
",",
"SEEK_CUR",
")",
";",
"$",
"file",
"->",
"fwrite",
"(",
"\"\\r\\n\"",
")",
";",
"}"
] |
フィールドの配列をCSVの行として書き出します。
@param \SplFileObject $file
@param string[] $fields
|
[
"フィールドの配列をCSVの行として書き出します。"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/serializer/GenericDictionarySerializer.php#L71-L82
|
esperecyan/dictionary-php
|
src/serializer/GenericDictionarySerializer.php
|
GenericDictionarySerializer.convertWordToRecord
|
protected function convertWordToRecord(array $word, array $fieldNames, array $metadata, array $filenames): array
{
$numberValidator = new NumberValidator();
$output = [];
foreach ($fieldNames as $fieldName) {
$field = isset($word[$fieldName][0])
? array_shift($word[$fieldName])
: (isset($metadata[$fieldName]) ? $metadata[$fieldName] : '');
if (is_array($field)) {
$includedFilename = false;
if (is_string($this->csvOnly)) {
$html = (new \esperecyan\html_filter\Filter(
null,
['before' => function (\DOMElement $body) use ($filenames, &$includedFilename) {
foreach (['img', 'audio', 'video'] as $elementName) {
foreach ($body->getElementsByTagName($elementName) as $element) {
$src = $element->getAttribute('src');
if (in_array($src, $filenames)) {
$includedFilename = true;
$element->setAttribute('src', sprintf($this->csvOnly, $src));
}
}
}
}]
))->filter($field['html']);
}
$field
= $includedFilename ? (new \League\HTMLToMarkdown\HtmlConverter())->convert($html) : $field['lml'];
} elseif (is_float($field)) {
$field = $numberValidator->serializeFloat($field);
} elseif (is_string($this->csvOnly)
&& in_array($fieldName, ['image', 'audio', 'video']) && in_array($field, $filenames)) {
$field = sprintf($this->csvOnly, $field);
}
$output[] = $field;
}
return $output;
}
|
php
|
protected function convertWordToRecord(array $word, array $fieldNames, array $metadata, array $filenames): array
{
$numberValidator = new NumberValidator();
$output = [];
foreach ($fieldNames as $fieldName) {
$field = isset($word[$fieldName][0])
? array_shift($word[$fieldName])
: (isset($metadata[$fieldName]) ? $metadata[$fieldName] : '');
if (is_array($field)) {
$includedFilename = false;
if (is_string($this->csvOnly)) {
$html = (new \esperecyan\html_filter\Filter(
null,
['before' => function (\DOMElement $body) use ($filenames, &$includedFilename) {
foreach (['img', 'audio', 'video'] as $elementName) {
foreach ($body->getElementsByTagName($elementName) as $element) {
$src = $element->getAttribute('src');
if (in_array($src, $filenames)) {
$includedFilename = true;
$element->setAttribute('src', sprintf($this->csvOnly, $src));
}
}
}
}]
))->filter($field['html']);
}
$field
= $includedFilename ? (new \League\HTMLToMarkdown\HtmlConverter())->convert($html) : $field['lml'];
} elseif (is_float($field)) {
$field = $numberValidator->serializeFloat($field);
} elseif (is_string($this->csvOnly)
&& in_array($fieldName, ['image', 'audio', 'video']) && in_array($field, $filenames)) {
$field = sprintf($this->csvOnly, $field);
}
$output[] = $field;
}
return $output;
}
|
[
"protected",
"function",
"convertWordToRecord",
"(",
"array",
"$",
"word",
",",
"array",
"$",
"fieldNames",
",",
"array",
"$",
"metadata",
",",
"array",
"$",
"filenames",
")",
":",
"array",
"{",
"$",
"numberValidator",
"=",
"new",
"NumberValidator",
"(",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fieldNames",
"as",
"$",
"fieldName",
")",
"{",
"$",
"field",
"=",
"isset",
"(",
"$",
"word",
"[",
"$",
"fieldName",
"]",
"[",
"0",
"]",
")",
"?",
"array_shift",
"(",
"$",
"word",
"[",
"$",
"fieldName",
"]",
")",
":",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"$",
"fieldName",
"]",
")",
"?",
"$",
"metadata",
"[",
"$",
"fieldName",
"]",
":",
"''",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"field",
")",
")",
"{",
"$",
"includedFilename",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"csvOnly",
")",
")",
"{",
"$",
"html",
"=",
"(",
"new",
"\\",
"esperecyan",
"\\",
"html_filter",
"\\",
"Filter",
"(",
"null",
",",
"[",
"'before'",
"=>",
"function",
"(",
"\\",
"DOMElement",
"$",
"body",
")",
"use",
"(",
"$",
"filenames",
",",
"&",
"$",
"includedFilename",
")",
"{",
"foreach",
"(",
"[",
"'img'",
",",
"'audio'",
",",
"'video'",
"]",
"as",
"$",
"elementName",
")",
"{",
"foreach",
"(",
"$",
"body",
"->",
"getElementsByTagName",
"(",
"$",
"elementName",
")",
"as",
"$",
"element",
")",
"{",
"$",
"src",
"=",
"$",
"element",
"->",
"getAttribute",
"(",
"'src'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"src",
",",
"$",
"filenames",
")",
")",
"{",
"$",
"includedFilename",
"=",
"true",
";",
"$",
"element",
"->",
"setAttribute",
"(",
"'src'",
",",
"sprintf",
"(",
"$",
"this",
"->",
"csvOnly",
",",
"$",
"src",
")",
")",
";",
"}",
"}",
"}",
"}",
"]",
")",
")",
"->",
"filter",
"(",
"$",
"field",
"[",
"'html'",
"]",
")",
";",
"}",
"$",
"field",
"=",
"$",
"includedFilename",
"?",
"(",
"new",
"\\",
"League",
"\\",
"HTMLToMarkdown",
"\\",
"HtmlConverter",
"(",
")",
")",
"->",
"convert",
"(",
"$",
"html",
")",
":",
"$",
"field",
"[",
"'lml'",
"]",
";",
"}",
"elseif",
"(",
"is_float",
"(",
"$",
"field",
")",
")",
"{",
"$",
"field",
"=",
"$",
"numberValidator",
"->",
"serializeFloat",
"(",
"$",
"field",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"this",
"->",
"csvOnly",
")",
"&&",
"in_array",
"(",
"$",
"fieldName",
",",
"[",
"'image'",
",",
"'audio'",
",",
"'video'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"field",
",",
"$",
"filenames",
")",
")",
"{",
"$",
"field",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"csvOnly",
",",
"$",
"field",
")",
";",
"}",
"$",
"output",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
一つのお題を表す配列を、CSVのレコードに変換します。
@param (string|string[]|float)[][] $word
@param string[] $fieldNames
@param (string|string[])[] $metadata
@param string[] $filenames
@return string[]
|
[
"一つのお題を表す配列を、CSVのレコードに変換します。"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/serializer/GenericDictionarySerializer.php#L92-L129
|
esperecyan/dictionary-php
|
src/serializer/GenericDictionarySerializer.php
|
GenericDictionarySerializer.getAsCSVFile
|
protected function getAsCSVFile(Dictionary $dictionary): \SplTempFileObject
{
$fieldNames = $this->getFieldNames($dictionary);
$csv = new \SplTempFileObject();
$this->putCSVRecord($csv, $fieldNames);
foreach ($dictionary->getWords() as $i => $word) {
$this->putCSVRecord($csv, $this->convertWordToRecord(
$word,
$fieldNames,
$i === 0 ? $dictionary->getMetadata() : [],
$dictionary->getFilenames()
));
}
$csv->rewind();
return $csv;
}
|
php
|
protected function getAsCSVFile(Dictionary $dictionary): \SplTempFileObject
{
$fieldNames = $this->getFieldNames($dictionary);
$csv = new \SplTempFileObject();
$this->putCSVRecord($csv, $fieldNames);
foreach ($dictionary->getWords() as $i => $word) {
$this->putCSVRecord($csv, $this->convertWordToRecord(
$word,
$fieldNames,
$i === 0 ? $dictionary->getMetadata() : [],
$dictionary->getFilenames()
));
}
$csv->rewind();
return $csv;
}
|
[
"protected",
"function",
"getAsCSVFile",
"(",
"Dictionary",
"$",
"dictionary",
")",
":",
"\\",
"SplTempFileObject",
"{",
"$",
"fieldNames",
"=",
"$",
"this",
"->",
"getFieldNames",
"(",
"$",
"dictionary",
")",
";",
"$",
"csv",
"=",
"new",
"\\",
"SplTempFileObject",
"(",
")",
";",
"$",
"this",
"->",
"putCSVRecord",
"(",
"$",
"csv",
",",
"$",
"fieldNames",
")",
";",
"foreach",
"(",
"$",
"dictionary",
"->",
"getWords",
"(",
")",
"as",
"$",
"i",
"=>",
"$",
"word",
")",
"{",
"$",
"this",
"->",
"putCSVRecord",
"(",
"$",
"csv",
",",
"$",
"this",
"->",
"convertWordToRecord",
"(",
"$",
"word",
",",
"$",
"fieldNames",
",",
"$",
"i",
"===",
"0",
"?",
"$",
"dictionary",
"->",
"getMetadata",
"(",
")",
":",
"[",
"]",
",",
"$",
"dictionary",
"->",
"getFilenames",
"(",
")",
")",
")",
";",
"}",
"$",
"csv",
"->",
"rewind",
"(",
")",
";",
"return",
"$",
"csv",
";",
"}"
] |
辞書をCSVファイルとして取得します。
@param Dictionary $dictionary
@return \SplTempFileObject
|
[
"辞書をCSVファイルとして取得します。"
] |
train
|
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/serializer/GenericDictionarySerializer.php#L136-L151
|
jamband/ripple
|
src/Utility.php
|
Utility.domain
|
private static function domain(string $url): ?string
{
$domain = parse_url($url, PHP_URL_HOST);
if (null !== $domain) {
return implode('.', array_slice(explode('.', $domain), -2));
}
return null;
}
|
php
|
private static function domain(string $url): ?string
{
$domain = parse_url($url, PHP_URL_HOST);
if (null !== $domain) {
return implode('.', array_slice(explode('.', $domain), -2));
}
return null;
}
|
[
"private",
"static",
"function",
"domain",
"(",
"string",
"$",
"url",
")",
":",
"?",
"string",
"{",
"$",
"domain",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_HOST",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"domain",
")",
"{",
"return",
"implode",
"(",
"'.'",
",",
"array_slice",
"(",
"explode",
"(",
"'.'",
",",
"$",
"domain",
")",
",",
"-",
"2",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the domain name from URL.
@param string $url
@return null|string
|
[
"Returns",
"the",
"domain",
"name",
"from",
"URL",
"."
] |
train
|
https://github.com/jamband/ripple/blob/91443f8016af76cacf749e05633abc1bdaf4675f/src/Utility.php#L28-L37
|
movoin/one-swoole
|
src/Middleware/Manager.php
|
Manager.matchRequest
|
public function matchRequest(Request $request)
{
$this->reset();
$groups = Arr::get($this->config, 'group', []);
$matchs = Arr::get($this->config, 'match', []);
// 全局中间件
if (isset($matchs['*'])) {
$wildcards = is_string($matchs['*']) ? (array) $matchs['*'] : $matchs['*'];
foreach ($wildcards as $alias) {
if (isset($groups[$alias])) {
foreach ($groups[$alias] as $name) {
$this->addMatched($name);
}
} else {
$this->addMatched($alias);
}
}
unset($wildcards, $matchs['*']);
}
// 匹配中间件
if (count($matchs) > 0) {
// {{
$uri = $request->getUri()->getPath();
// }}
foreach ($matchs as $pattern => $name) {
if (preg_match("#{$pattern}#i", $uri)) {
$this->addMatched($name);
}
}
unset($uri);
}
unset($groups, $matchs);
}
|
php
|
public function matchRequest(Request $request)
{
$this->reset();
$groups = Arr::get($this->config, 'group', []);
$matchs = Arr::get($this->config, 'match', []);
// 全局中间件
if (isset($matchs['*'])) {
$wildcards = is_string($matchs['*']) ? (array) $matchs['*'] : $matchs['*'];
foreach ($wildcards as $alias) {
if (isset($groups[$alias])) {
foreach ($groups[$alias] as $name) {
$this->addMatched($name);
}
} else {
$this->addMatched($alias);
}
}
unset($wildcards, $matchs['*']);
}
// 匹配中间件
if (count($matchs) > 0) {
// {{
$uri = $request->getUri()->getPath();
// }}
foreach ($matchs as $pattern => $name) {
if (preg_match("#{$pattern}#i", $uri)) {
$this->addMatched($name);
}
}
unset($uri);
}
unset($groups, $matchs);
}
|
[
"public",
"function",
"matchRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"$",
"groups",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'group'",
",",
"[",
"]",
")",
";",
"$",
"matchs",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'match'",
",",
"[",
"]",
")",
";",
"// 全局中间件",
"if",
"(",
"isset",
"(",
"$",
"matchs",
"[",
"'*'",
"]",
")",
")",
"{",
"$",
"wildcards",
"=",
"is_string",
"(",
"$",
"matchs",
"[",
"'*'",
"]",
")",
"?",
"(",
"array",
")",
"$",
"matchs",
"[",
"'*'",
"]",
":",
"$",
"matchs",
"[",
"'*'",
"]",
";",
"foreach",
"(",
"$",
"wildcards",
"as",
"$",
"alias",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"groups",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"groups",
"[",
"$",
"alias",
"]",
"as",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"addMatched",
"(",
"$",
"name",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"addMatched",
"(",
"$",
"alias",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"wildcards",
",",
"$",
"matchs",
"[",
"'*'",
"]",
")",
";",
"}",
"// 匹配中间件",
"if",
"(",
"count",
"(",
"$",
"matchs",
")",
">",
"0",
")",
"{",
"// {{",
"$",
"uri",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"// }}",
"foreach",
"(",
"$",
"matchs",
"as",
"$",
"pattern",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"#{$pattern}#i\"",
",",
"$",
"uri",
")",
")",
"{",
"$",
"this",
"->",
"addMatched",
"(",
"$",
"name",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"uri",
")",
";",
"}",
"unset",
"(",
"$",
"groups",
",",
"$",
"matchs",
")",
";",
"}"
] |
获得指定请求对象的中间件管理对象
@param \One\Protocol\Contracts\Request $request
@throws \One\Middleware\Exceptions\MiddlewareException
|
[
"获得指定请求对象的中间件管理对象"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Middleware/Manager.php#L67-L106
|
movoin/one-swoole
|
src/Middleware/Manager.php
|
Manager.executeFilters
|
public function executeFilters(Request $request, Response $response)
{
$middlewares = $this->filterMiddleware(Filter::class);
foreach ($middlewares as $middleware) {
if (($returnResponse = $middleware->doFilter($request, $response)) !== null) {
return $returnResponse;
}
unset($returnResponse);
}
unset($middlewares);
}
|
php
|
public function executeFilters(Request $request, Response $response)
{
$middlewares = $this->filterMiddleware(Filter::class);
foreach ($middlewares as $middleware) {
if (($returnResponse = $middleware->doFilter($request, $response)) !== null) {
return $returnResponse;
}
unset($returnResponse);
}
unset($middlewares);
}
|
[
"public",
"function",
"executeFilters",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"middlewares",
"=",
"$",
"this",
"->",
"filterMiddleware",
"(",
"Filter",
"::",
"class",
")",
";",
"foreach",
"(",
"$",
"middlewares",
"as",
"$",
"middleware",
")",
"{",
"if",
"(",
"(",
"$",
"returnResponse",
"=",
"$",
"middleware",
"->",
"doFilter",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"returnResponse",
";",
"}",
"unset",
"(",
"$",
"returnResponse",
")",
";",
"}",
"unset",
"(",
"$",
"middlewares",
")",
";",
"}"
] |
执行匹配的过滤器
@param \One\Protocol\Contracts\Request $request
@param \One\Protocol\Contracts\Response $response
@return \One\Protocol\Contracts\Response|null
|
[
"执行匹配的过滤器"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Middleware/Manager.php#L116-L128
|
movoin/one-swoole
|
src/Middleware/Manager.php
|
Manager.executeInterceptors
|
public function executeInterceptors(Request $request, Response $response)
{
$middlewares = $this->filterMiddleware(Interceptor::class);
foreach ($middlewares as $middleware) {
list(
$request,
$response
) = $middleware->doIntercept($request, $response);
}
unset($middlewares);
return [$request, $response];
}
|
php
|
public function executeInterceptors(Request $request, Response $response)
{
$middlewares = $this->filterMiddleware(Interceptor::class);
foreach ($middlewares as $middleware) {
list(
$request,
$response
) = $middleware->doIntercept($request, $response);
}
unset($middlewares);
return [$request, $response];
}
|
[
"public",
"function",
"executeInterceptors",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"middlewares",
"=",
"$",
"this",
"->",
"filterMiddleware",
"(",
"Interceptor",
"::",
"class",
")",
";",
"foreach",
"(",
"$",
"middlewares",
"as",
"$",
"middleware",
")",
"{",
"list",
"(",
"$",
"request",
",",
"$",
"response",
")",
"=",
"$",
"middleware",
"->",
"doIntercept",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"unset",
"(",
"$",
"middlewares",
")",
";",
"return",
"[",
"$",
"request",
",",
"$",
"response",
"]",
";",
"}"
] |
执行匹配的拦截器
@param \One\Protocol\Contracts\Request $request
@param \One\Protocol\Contracts\Response $response
@return [\One\Protocol\Contracts\Request, \One\Protocol\Contracts\Response]
|
[
"执行匹配的拦截器"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Middleware/Manager.php#L138-L152
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.