repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
g4code/utility | src/Tools.php | Tools.arrayChangeKeys | public static function arrayChangeKeys($data, $keyName = 'id')
{
$temp = [];
if (is_array($data)) {
foreach ($data as $key => $row) {
if (isset($row[$keyName])) {
$temp[$row[$keyName]] = $row;
} else {
$temp[] = $row;
}
}
}
return $temp;
} | php | public static function arrayChangeKeys($data, $keyName = 'id')
{
$temp = [];
if (is_array($data)) {
foreach ($data as $key => $row) {
if (isset($row[$keyName])) {
$temp[$row[$keyName]] = $row;
} else {
$temp[] = $row;
}
}
}
return $temp;
} | [
"public",
"static",
"function",
"arrayChangeKeys",
"(",
"$",
"data",
",",
"$",
"keyName",
"=",
"'id'",
")",
"{",
"$",
"temp",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"$",
"keyName",
"]",
")",
")",
"{",
"$",
"temp",
"[",
"$",
"row",
"[",
"$",
"keyName",
"]",
"]",
"=",
"$",
"row",
";",
"}",
"else",
"{",
"$",
"temp",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"}",
"}",
"return",
"$",
"temp",
";",
"}"
] | Rearange array keys to use selected field from row element
@param array $data
@param string $keyName
@return array | [
"Rearange",
"array",
"keys",
"to",
"use",
"selected",
"field",
"from",
"row",
"element"
] | e0c9138aab61a53d88f32bb66201b075f3f44f1d | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Tools.php#L106-L119 | train |
g4code/utility | src/Tools.php | Tools.elapsedTime | public static function elapsedTime($timestamp)
{
// @todo: deprecated - use timeDiff instead of this
$dateDiff = self::timeDiff($timestamp);
unset ($dateDiff['month']);
$dateDiff['week'] = floor($dateDiff['days_total'] / 7);
$dateDiff['day'] = $dateDiff['days_total'] % 7;
return $dateDiff;
} | php | public static function elapsedTime($timestamp)
{
// @todo: deprecated - use timeDiff instead of this
$dateDiff = self::timeDiff($timestamp);
unset ($dateDiff['month']);
$dateDiff['week'] = floor($dateDiff['days_total'] / 7);
$dateDiff['day'] = $dateDiff['days_total'] % 7;
return $dateDiff;
} | [
"public",
"static",
"function",
"elapsedTime",
"(",
"$",
"timestamp",
")",
"{",
"// @todo: deprecated - use timeDiff instead of this",
"$",
"dateDiff",
"=",
"self",
"::",
"timeDiff",
"(",
"$",
"timestamp",
")",
";",
"unset",
"(",
"$",
"dateDiff",
"[",
"'month'",
"]",
")",
";",
"$",
"dateDiff",
"[",
"'week'",
"]",
"=",
"floor",
"(",
"$",
"dateDiff",
"[",
"'days_total'",
"]",
"/",
"7",
")",
";",
"$",
"dateDiff",
"[",
"'day'",
"]",
"=",
"$",
"dateDiff",
"[",
"'days_total'",
"]",
"%",
"7",
";",
"return",
"$",
"dateDiff",
";",
"}"
] | Calculate time period and return it in separated time segments
@param int $timestamp timestamp for data in past you want to calculate elapsed period
@return array | [
"Calculate",
"time",
"period",
"and",
"return",
"it",
"in",
"separated",
"time",
"segments"
] | e0c9138aab61a53d88f32bb66201b075f3f44f1d | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Tools.php#L167-L179 | train |
g4code/utility | src/Tools.php | Tools.getRealIP | public function getRealIP($allowPrivateRange = false, array $prependHeaders = null)
{
$headers = [
'HTTP_CF_CONNECTING_IP', // CloudFlare sent IP
'CLIENT_IP',
'FORWARDED',
'FORWARDED_FOR',
'FORWARDED_FOR_IP',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED_FOR_IP',
'HTTP_PC_REMOTE_ADDR',
'HTTP_PROXY_CONNECTION',
'HTTP_VIA',
'HTTP_X_FORWARDED',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED_FOR_IP',
'HTTP_X_IMFORWARDS',
'HTTP_X_PROXY_CONNECTION',
'VIA',
'X_FORWARDED',
'X_FORWARDED_FOR',
'REMOTE_ADDR', // REMOTE_ADDR is always set, use it as last resort
];
if($prependHeaders !== null && !empty($prependHeaders)) {
$headers = array_merge($prependHeaders, $headers);
}
foreach($headers as $row) {
if(!array_key_exists($row, $_SERVER)) {
continue;
}
foreach(explode(',', $_SERVER[$row]) as $ip) {
$tmpIp = trim ($ip);
$portPos = stripos ($tmpIp, ':');
if(!filter_var($tmpIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && false !== $portPos) {
$tmpIp = substr ($tmpIp, 0, $portPos);
}
$flag = $allowPrivateRange
? FILTER_FLAG_NO_RES_RANGE
: FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE;
if(false === filter_var($tmpIp, FILTER_VALIDATE_IP, $flag)) {
continue;
}
return $realIp = $tmpIp;
}
}
return $realIp = false;
} | php | public function getRealIP($allowPrivateRange = false, array $prependHeaders = null)
{
$headers = [
'HTTP_CF_CONNECTING_IP', // CloudFlare sent IP
'CLIENT_IP',
'FORWARDED',
'FORWARDED_FOR',
'FORWARDED_FOR_IP',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED_FOR_IP',
'HTTP_PC_REMOTE_ADDR',
'HTTP_PROXY_CONNECTION',
'HTTP_VIA',
'HTTP_X_FORWARDED',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED_FOR_IP',
'HTTP_X_IMFORWARDS',
'HTTP_X_PROXY_CONNECTION',
'VIA',
'X_FORWARDED',
'X_FORWARDED_FOR',
'REMOTE_ADDR', // REMOTE_ADDR is always set, use it as last resort
];
if($prependHeaders !== null && !empty($prependHeaders)) {
$headers = array_merge($prependHeaders, $headers);
}
foreach($headers as $row) {
if(!array_key_exists($row, $_SERVER)) {
continue;
}
foreach(explode(',', $_SERVER[$row]) as $ip) {
$tmpIp = trim ($ip);
$portPos = stripos ($tmpIp, ':');
if(!filter_var($tmpIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && false !== $portPos) {
$tmpIp = substr ($tmpIp, 0, $portPos);
}
$flag = $allowPrivateRange
? FILTER_FLAG_NO_RES_RANGE
: FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE;
if(false === filter_var($tmpIp, FILTER_VALIDATE_IP, $flag)) {
continue;
}
return $realIp = $tmpIp;
}
}
return $realIp = false;
} | [
"public",
"function",
"getRealIP",
"(",
"$",
"allowPrivateRange",
"=",
"false",
",",
"array",
"$",
"prependHeaders",
"=",
"null",
")",
"{",
"$",
"headers",
"=",
"[",
"'HTTP_CF_CONNECTING_IP'",
",",
"// CloudFlare sent IP",
"'CLIENT_IP'",
",",
"'FORWARDED'",
",",
"'FORWARDED_FOR'",
",",
"'FORWARDED_FOR_IP'",
",",
"'HTTP_CLIENT_IP'",
",",
"'HTTP_FORWARDED'",
",",
"'HTTP_FORWARDED_FOR'",
",",
"'HTTP_FORWARDED_FOR_IP'",
",",
"'HTTP_PC_REMOTE_ADDR'",
",",
"'HTTP_PROXY_CONNECTION'",
",",
"'HTTP_VIA'",
",",
"'HTTP_X_FORWARDED'",
",",
"'HTTP_X_FORWARDED_FOR'",
",",
"'HTTP_X_FORWARDED_FOR_IP'",
",",
"'HTTP_X_IMFORWARDS'",
",",
"'HTTP_X_PROXY_CONNECTION'",
",",
"'VIA'",
",",
"'X_FORWARDED'",
",",
"'X_FORWARDED_FOR'",
",",
"'REMOTE_ADDR'",
",",
"// REMOTE_ADDR is always set, use it as last resort",
"]",
";",
"if",
"(",
"$",
"prependHeaders",
"!==",
"null",
"&&",
"!",
"empty",
"(",
"$",
"prependHeaders",
")",
")",
"{",
"$",
"headers",
"=",
"array_merge",
"(",
"$",
"prependHeaders",
",",
"$",
"headers",
")",
";",
"}",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"row",
",",
"$",
"_SERVER",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"_SERVER",
"[",
"$",
"row",
"]",
")",
"as",
"$",
"ip",
")",
"{",
"$",
"tmpIp",
"=",
"trim",
"(",
"$",
"ip",
")",
";",
"$",
"portPos",
"=",
"stripos",
"(",
"$",
"tmpIp",
",",
"':'",
")",
";",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"tmpIp",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV6",
")",
"&&",
"false",
"!==",
"$",
"portPos",
")",
"{",
"$",
"tmpIp",
"=",
"substr",
"(",
"$",
"tmpIp",
",",
"0",
",",
"$",
"portPos",
")",
";",
"}",
"$",
"flag",
"=",
"$",
"allowPrivateRange",
"?",
"FILTER_FLAG_NO_RES_RANGE",
":",
"FILTER_FLAG_NO_RES_RANGE",
"|",
"FILTER_FLAG_NO_PRIV_RANGE",
";",
"if",
"(",
"false",
"===",
"filter_var",
"(",
"$",
"tmpIp",
",",
"FILTER_VALIDATE_IP",
",",
"$",
"flag",
")",
")",
"{",
"continue",
";",
"}",
"return",
"$",
"realIp",
"=",
"$",
"tmpIp",
";",
"}",
"}",
"return",
"$",
"realIp",
"=",
"false",
";",
"}"
] | Return real users IP address even if behind proxy
@param bool $allowPrivateRange
@param array $prependHeaders if list of additional headers is set, prepend them to list and test first
(used for example on CloudFlare)
@return mixed - string containing IP address or (bool) false if not found | [
"Return",
"real",
"users",
"IP",
"address",
"even",
"if",
"behind",
"proxy"
] | e0c9138aab61a53d88f32bb66201b075f3f44f1d | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Tools.php#L190-L246 | train |
g4code/utility | src/Tools.php | Tools.timeDiff | public static function timeDiff($timestamp)
{
$dateRef = new \DateTime('@' . $timestamp);
$dateNow = new \DateTime();
$dateDiff = $dateNow->diff($dateRef);
return [
'past_time' => $dateDiff->invert,
'year' => $dateDiff->y,
'month' => $dateDiff->m,
'day' => $dateDiff->d,
'hour' => $dateDiff->h,
'minute' => $dateDiff->i,
'second' => $dateDiff->s,
'days_total' => $dateDiff->days,
];
} | php | public static function timeDiff($timestamp)
{
$dateRef = new \DateTime('@' . $timestamp);
$dateNow = new \DateTime();
$dateDiff = $dateNow->diff($dateRef);
return [
'past_time' => $dateDiff->invert,
'year' => $dateDiff->y,
'month' => $dateDiff->m,
'day' => $dateDiff->d,
'hour' => $dateDiff->h,
'minute' => $dateDiff->i,
'second' => $dateDiff->s,
'days_total' => $dateDiff->days,
];
} | [
"public",
"static",
"function",
"timeDiff",
"(",
"$",
"timestamp",
")",
"{",
"$",
"dateRef",
"=",
"new",
"\\",
"DateTime",
"(",
"'@'",
".",
"$",
"timestamp",
")",
";",
"$",
"dateNow",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"dateDiff",
"=",
"$",
"dateNow",
"->",
"diff",
"(",
"$",
"dateRef",
")",
";",
"return",
"[",
"'past_time'",
"=>",
"$",
"dateDiff",
"->",
"invert",
",",
"'year'",
"=>",
"$",
"dateDiff",
"->",
"y",
",",
"'month'",
"=>",
"$",
"dateDiff",
"->",
"m",
",",
"'day'",
"=>",
"$",
"dateDiff",
"->",
"d",
",",
"'hour'",
"=>",
"$",
"dateDiff",
"->",
"h",
",",
"'minute'",
"=>",
"$",
"dateDiff",
"->",
"i",
",",
"'second'",
"=>",
"$",
"dateDiff",
"->",
"s",
",",
"'days_total'",
"=>",
"$",
"dateDiff",
"->",
"days",
",",
"]",
";",
"}"
] | Calculates time difference between current time and specified timestamp
and returns array with human readable properties of time interval
@param integer $timestamp
@return array | [
"Calculates",
"time",
"difference",
"between",
"current",
"time",
"and",
"specified",
"timestamp",
"and",
"returns",
"array",
"with",
"human",
"readable",
"properties",
"of",
"time",
"interval"
] | e0c9138aab61a53d88f32bb66201b075f3f44f1d | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Tools.php#L255-L272 | train |
raymondjavaxx/php5-browserid | libraries/browserid/Verifier.php | Verifier.verify | public function verify($assertion) {
$response = $this->_post(array(
'audience' => $this->audience,
'assertion' => $assertion
));
if ($response->status !== 'okay') {
throw new Exception('Invalid assertion - ' . $response->reason);
}
return $response;
} | php | public function verify($assertion) {
$response = $this->_post(array(
'audience' => $this->audience,
'assertion' => $assertion
));
if ($response->status !== 'okay') {
throw new Exception('Invalid assertion - ' . $response->reason);
}
return $response;
} | [
"public",
"function",
"verify",
"(",
"$",
"assertion",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_post",
"(",
"array",
"(",
"'audience'",
"=>",
"$",
"this",
"->",
"audience",
",",
"'assertion'",
"=>",
"$",
"assertion",
")",
")",
";",
"if",
"(",
"$",
"response",
"->",
"status",
"!==",
"'okay'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Invalid assertion - '",
".",
"$",
"response",
"->",
"reason",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Verifies a BrowserID assertion
@param string $assertion assertion to be verified
@return object
BrowserID verification response object with the following attributes:
email: email address of the user
audience: hostname that the assertion is valid for
expires: expiration timestamp of the assertion
issuer: the entity who issued the assertion
@throws \browserid\Exception | [
"Verifies",
"a",
"BrowserID",
"assertion"
] | 1028776ef7a4b2a4f8e4e831e186a3bf2c187657 | https://github.com/raymondjavaxx/php5-browserid/blob/1028776ef7a4b2a4f8e4e831e186a3bf2c187657/libraries/browserid/Verifier.php#L51-L62 | train |
raymondjavaxx/php5-browserid | libraries/browserid/Verifier.php | Verifier._post | protected function _post($data) {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => static::ENDPOINT,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTPHEADER => array('Content-Type: application/json')
));
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
throw new Exception('Failed to contact BrowserID verification service');
}
$decodedResponse = json_decode($response);
if (!$decodedResponse) {
throw new Exception('Response is not valid JSON');
}
return $decodedResponse;
} | php | protected function _post($data) {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => static::ENDPOINT,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTPHEADER => array('Content-Type: application/json')
));
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
throw new Exception('Failed to contact BrowserID verification service');
}
$decodedResponse = json_decode($response);
if (!$decodedResponse) {
throw new Exception('Response is not valid JSON');
}
return $decodedResponse;
} | [
"protected",
"function",
"_post",
"(",
"$",
"data",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt_array",
"(",
"$",
"ch",
",",
"array",
"(",
"CURLOPT_URL",
"=>",
"static",
"::",
"ENDPOINT",
",",
"CURLOPT_POST",
"=>",
"true",
",",
"CURLOPT_POSTFIELDS",
"=>",
"json_encode",
"(",
"$",
"data",
")",
",",
"CURLOPT_HEADER",
"=>",
"false",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"true",
",",
"CURLOPT_SSL_VERIFYPEER",
"=>",
"true",
",",
"CURLOPT_SSL_VERIFYHOST",
"=>",
"2",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"false",
",",
"CURLOPT_HTTPHEADER",
"=>",
"array",
"(",
"'Content-Type: application/json'",
")",
")",
")",
";",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"$",
"response",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Failed to contact BrowserID verification service'",
")",
";",
"}",
"$",
"decodedResponse",
"=",
"json_decode",
"(",
"$",
"response",
")",
";",
"if",
"(",
"!",
"$",
"decodedResponse",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Response is not valid JSON'",
")",
";",
"}",
"return",
"$",
"decodedResponse",
";",
"}"
] | Makes an HTTP POST request to verification endpoint
@param array $data data to be sent to endpoint
@return object verification response
@throws \browserid\Exception | [
"Makes",
"an",
"HTTP",
"POST",
"request",
"to",
"verification",
"endpoint"
] | 1028776ef7a4b2a4f8e4e831e186a3bf2c187657 | https://github.com/raymondjavaxx/php5-browserid/blob/1028776ef7a4b2a4f8e4e831e186a3bf2c187657/libraries/browserid/Verifier.php#L71-L98 | train |
phpffcms/ffcms-core | src/Helper/Simplify.php | Simplify.parseUserNick | public static function parseUserNick($userId = null, $onEmpty = 'guest'): ?string
{
if (!Any::isInt($userId)) {
return \App::$Security->strip_tags($onEmpty);
}
// try to find user active record as object
$identity = App::$User->identity($userId);
if (!$identity) {
return \App::$Security->strip_tags($onEmpty);
}
// return user nickname from profile
return $identity->profile->getNickname();
} | php | public static function parseUserNick($userId = null, $onEmpty = 'guest'): ?string
{
if (!Any::isInt($userId)) {
return \App::$Security->strip_tags($onEmpty);
}
// try to find user active record as object
$identity = App::$User->identity($userId);
if (!$identity) {
return \App::$Security->strip_tags($onEmpty);
}
// return user nickname from profile
return $identity->profile->getNickname();
} | [
"public",
"static",
"function",
"parseUserNick",
"(",
"$",
"userId",
"=",
"null",
",",
"$",
"onEmpty",
"=",
"'guest'",
")",
":",
"?",
"string",
"{",
"if",
"(",
"!",
"Any",
"::",
"isInt",
"(",
"$",
"userId",
")",
")",
"{",
"return",
"\\",
"App",
"::",
"$",
"Security",
"->",
"strip_tags",
"(",
"$",
"onEmpty",
")",
";",
"}",
"// try to find user active record as object",
"$",
"identity",
"=",
"App",
"::",
"$",
"User",
"->",
"identity",
"(",
"$",
"userId",
")",
";",
"if",
"(",
"!",
"$",
"identity",
")",
"{",
"return",
"\\",
"App",
"::",
"$",
"Security",
"->",
"strip_tags",
"(",
"$",
"onEmpty",
")",
";",
"}",
"// return user nickname from profile",
"return",
"$",
"identity",
"->",
"profile",
"->",
"getNickname",
"(",
")",
";",
"}"
] | Get user nickname by user id with predefined value on empty or not exist profile
@param $userId
@param string $onEmpty
@return string | [
"Get",
"user",
"nickname",
"by",
"user",
"id",
"with",
"predefined",
"value",
"on",
"empty",
"or",
"not",
"exist",
"profile"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Simplify.php#L21-L35 | train |
buildok/validator | src/types/base/BaseValidator.php | BaseValidator.validate | public function validate($value, $options)
{
$this->value = $value;
$this->options = $options;
$this->errors = [];
return $this->checkIt();
} | php | public function validate($value, $options)
{
$this->value = $value;
$this->options = $options;
$this->errors = [];
return $this->checkIt();
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
",",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"options",
"=",
"$",
"options",
";",
"$",
"this",
"->",
"errors",
"=",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"checkIt",
"(",
")",
";",
"}"
] | Main validation function
@param mixed $value Value to check
@param buildok\helpers\ArrayWrapper $options Validation options
@return boolean | [
"Main",
"validation",
"function"
] | 3612ebca7901c84be2f26f641470933e468a0811 | https://github.com/buildok/validator/blob/3612ebca7901c84be2f26f641470933e468a0811/src/types/base/BaseValidator.php#L55-L62 | train |
stevenliebregt/crispysystem | src/Container/Container.php | Container.resolveDependencies | protected function resolveDependencies(array $dependencies, array $parameters = [])
{
$results = [];
foreach ($dependencies as $dependency) {
if (array_key_exists($dependency->name, $parameters)) { // Parameter value is given
$results[] = $parameters[$dependency->name];
} else { // Parameter value is not given
$results[] = is_null($class = $dependency->getClass())
? $dependency->getDefaultValue()
: $this->getInstance($dependency->getClass()->name);
}
}
return $results;
} | php | protected function resolveDependencies(array $dependencies, array $parameters = [])
{
$results = [];
foreach ($dependencies as $dependency) {
if (array_key_exists($dependency->name, $parameters)) { // Parameter value is given
$results[] = $parameters[$dependency->name];
} else { // Parameter value is not given
$results[] = is_null($class = $dependency->getClass())
? $dependency->getDefaultValue()
: $this->getInstance($dependency->getClass()->name);
}
}
return $results;
} | [
"protected",
"function",
"resolveDependencies",
"(",
"array",
"$",
"dependencies",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"dependency",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"dependency",
"->",
"name",
",",
"$",
"parameters",
")",
")",
"{",
"// Parameter value is given",
"$",
"results",
"[",
"]",
"=",
"$",
"parameters",
"[",
"$",
"dependency",
"->",
"name",
"]",
";",
"}",
"else",
"{",
"// Parameter value is not given",
"$",
"results",
"[",
"]",
"=",
"is_null",
"(",
"$",
"class",
"=",
"$",
"dependency",
"->",
"getClass",
"(",
")",
")",
"?",
"$",
"dependency",
"->",
"getDefaultValue",
"(",
")",
":",
"$",
"this",
"->",
"getInstance",
"(",
"$",
"dependency",
"->",
"getClass",
"(",
")",
"->",
"name",
")",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] | Resolves dependencies recursively
@param array $dependencies List of dependencies
@param array $parameters Fill parameter slots with pre-given data
@return array The resolved dependencies
@since 1.0.0 | [
"Resolves",
"dependencies",
"recursively"
] | 06547dae100dae1023a93ec903f2d2abacce9aec | https://github.com/stevenliebregt/crispysystem/blob/06547dae100dae1023a93ec903f2d2abacce9aec/src/Container/Container.php#L68-L82 | train |
stevenliebregt/crispysystem | src/Container/Container.php | Container.resolveMethod | public function resolveMethod($instance, string $method, array $parameters = [])
{
$name = get_class($instance);
$reflection = new \ReflectionMethod($name, $method);
$dependencies = $reflection->getParameters();
$instances = $this->resolveDependencies($dependencies, $parameters); // Actually resolve the dependencies
$o = $reflection->invokeArgs($instance, $instances);
return $o;
} | php | public function resolveMethod($instance, string $method, array $parameters = [])
{
$name = get_class($instance);
$reflection = new \ReflectionMethod($name, $method);
$dependencies = $reflection->getParameters();
$instances = $this->resolveDependencies($dependencies, $parameters); // Actually resolve the dependencies
$o = $reflection->invokeArgs($instance, $instances);
return $o;
} | [
"public",
"function",
"resolveMethod",
"(",
"$",
"instance",
",",
"string",
"$",
"method",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"name",
"=",
"get_class",
"(",
"$",
"instance",
")",
";",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"name",
",",
"$",
"method",
")",
";",
"$",
"dependencies",
"=",
"$",
"reflection",
"->",
"getParameters",
"(",
")",
";",
"$",
"instances",
"=",
"$",
"this",
"->",
"resolveDependencies",
"(",
"$",
"dependencies",
",",
"$",
"parameters",
")",
";",
"// Actually resolve the dependencies",
"$",
"o",
"=",
"$",
"reflection",
"->",
"invokeArgs",
"(",
"$",
"instance",
",",
"$",
"instances",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Calls the method of an instance after resolving dependencies
@param object $instance Instance to use when calling method
@param string $method Name of the method
@param array $parameters Pre-given data to fill slots that have no default value
@return mixed Value returned in method
@since 1.0.0 | [
"Calls",
"the",
"method",
"of",
"an",
"instance",
"after",
"resolving",
"dependencies"
] | 06547dae100dae1023a93ec903f2d2abacce9aec | https://github.com/stevenliebregt/crispysystem/blob/06547dae100dae1023a93ec903f2d2abacce9aec/src/Container/Container.php#L92-L102 | train |
stevenliebregt/crispysystem | src/Container/Container.php | Container.resolveClosure | public function resolveClosure(\Closure $closure)
{
$reflection = new \ReflectionFunction($closure);
$dependencies = $reflection->getParameters();
$instances = $this->resolveDependencies($dependencies); // Actually resolve the dependencies
$o = $reflection->invokeArgs($instances);
return $o;
} | php | public function resolveClosure(\Closure $closure)
{
$reflection = new \ReflectionFunction($closure);
$dependencies = $reflection->getParameters();
$instances = $this->resolveDependencies($dependencies); // Actually resolve the dependencies
$o = $reflection->invokeArgs($instances);
return $o;
} | [
"public",
"function",
"resolveClosure",
"(",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"closure",
")",
";",
"$",
"dependencies",
"=",
"$",
"reflection",
"->",
"getParameters",
"(",
")",
";",
"$",
"instances",
"=",
"$",
"this",
"->",
"resolveDependencies",
"(",
"$",
"dependencies",
")",
";",
"// Actually resolve the dependencies",
"$",
"o",
"=",
"$",
"reflection",
"->",
"invokeArgs",
"(",
"$",
"instances",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Resolves the dependencies of a function
@param \Closure $closure The closure to resolve
@return mixed Value returned in method
@since 1.0.0 | [
"Resolves",
"the",
"dependencies",
"of",
"a",
"function"
] | 06547dae100dae1023a93ec903f2d2abacce9aec | https://github.com/stevenliebregt/crispysystem/blob/06547dae100dae1023a93ec903f2d2abacce9aec/src/Container/Container.php#L110-L119 | train |
teonsystems/php-base | src/View/Helper/LayoutDataContainer.php | LayoutDataContainer.setView | public function setView(\Zend\View\Renderer\RendererInterface $view)
{
$this->view = $view;
return $this;
} | php | public function setView(\Zend\View\Renderer\RendererInterface $view)
{
$this->view = $view;
return $this;
} | [
"public",
"function",
"setView",
"(",
"\\",
"Zend",
"\\",
"View",
"\\",
"Renderer",
"\\",
"RendererInterface",
"$",
"view",
")",
"{",
"$",
"this",
"->",
"view",
"=",
"$",
"view",
";",
"return",
"$",
"this",
";",
"}"
] | Set the View object
@param Renderer $view
@return AbstractHelper | [
"Set",
"the",
"View",
"object"
] | 010418fd9df3c447a74b36cf0d31e2d38a6527ac | https://github.com/teonsystems/php-base/blob/010418fd9df3c447a74b36cf0d31e2d38a6527ac/src/View/Helper/LayoutDataContainer.php#L64-L68 | train |
Subscribo/dependencyresolver | src/Subscribo/DependencyResolver/FlatDependencyResolver.php | FlatDependencyResolver._isResolved | private static function _isResolved(array $dependenciesList, array $resolved)
{
foreach($dependenciesList as $dependency) {
if ( ! array_key_exists($dependency, $resolved)) {
return false;
}
}
return true;
} | php | private static function _isResolved(array $dependenciesList, array $resolved)
{
foreach($dependenciesList as $dependency) {
if ( ! array_key_exists($dependency, $resolved)) {
return false;
}
}
return true;
} | [
"private",
"static",
"function",
"_isResolved",
"(",
"array",
"$",
"dependenciesList",
",",
"array",
"$",
"resolved",
")",
"{",
"foreach",
"(",
"$",
"dependenciesList",
"as",
"$",
"dependency",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"dependency",
",",
"$",
"resolved",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks, whether all items from dependencies list are among keys in resolved
@param array $dependenciesList
@param array $resolved
@return bool | [
"Checks",
"whether",
"all",
"items",
"from",
"dependencies",
"list",
"are",
"among",
"keys",
"in",
"resolved"
] | c345569ca497b6d7e2ade4a93eb19bb535b8b857 | https://github.com/Subscribo/dependencyresolver/blob/c345569ca497b6d7e2ade4a93eb19bb535b8b857/src/Subscribo/DependencyResolver/FlatDependencyResolver.php#L52-L60 | train |
raulfraile/ladybug-plugin-extra | Type/ImageType.php | ImageType.setImage | public function setImage($image)
{
$this->image = base64_encode($image);
// create temp file
$this->tempPath = sys_get_temp_dir() . '/' . uniqid('ladybug_');
file_put_contents($this->tempPath, $image);
} | php | public function setImage($image)
{
$this->image = base64_encode($image);
// create temp file
$this->tempPath = sys_get_temp_dir() . '/' . uniqid('ladybug_');
file_put_contents($this->tempPath, $image);
} | [
"public",
"function",
"setImage",
"(",
"$",
"image",
")",
"{",
"$",
"this",
"->",
"image",
"=",
"base64_encode",
"(",
"$",
"image",
")",
";",
"// create temp file",
"$",
"this",
"->",
"tempPath",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/'",
".",
"uniqid",
"(",
"'ladybug_'",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"tempPath",
",",
"$",
"image",
")",
";",
"}"
] | Sets image content
@param $image | [
"Sets",
"image",
"content"
] | 0d569c28eb4706506f0057d95a1da9dd2c76c329 | https://github.com/raulfraile/ladybug-plugin-extra/blob/0d569c28eb4706506f0057d95a1da9dd2c76c329/Type/ImageType.php#L73-L80 | train |
honey-comb/resources | src/Services/HCResourceService.php | HCResourceService.generateCachePath | protected function generateCachePath(
string $resourceId,
string $disk,
string $extension,
int $width = 0,
int $height = 0,
$fit = null
): string {
if ($this->isLocalOrPublic($disk)) {
$folder = config('filesystems.disks.' . $disk . '.root') . '/cache/' . str_replace('-', '/', $resourceId);
if (!is_dir($folder)) {
mkdir($folder, 0755, true);
}
}
$path = 'cache/' . str_replace('-', '/', $resourceId) . '/';
$path .= $width . '_' . $height;
if ($fit) {
$path .= '_fit';
}
return $path . $extension;
} | php | protected function generateCachePath(
string $resourceId,
string $disk,
string $extension,
int $width = 0,
int $height = 0,
$fit = null
): string {
if ($this->isLocalOrPublic($disk)) {
$folder = config('filesystems.disks.' . $disk . '.root') . '/cache/' . str_replace('-', '/', $resourceId);
if (!is_dir($folder)) {
mkdir($folder, 0755, true);
}
}
$path = 'cache/' . str_replace('-', '/', $resourceId) . '/';
$path .= $width . '_' . $height;
if ($fit) {
$path .= '_fit';
}
return $path . $extension;
} | [
"protected",
"function",
"generateCachePath",
"(",
"string",
"$",
"resourceId",
",",
"string",
"$",
"disk",
",",
"string",
"$",
"extension",
",",
"int",
"$",
"width",
"=",
"0",
",",
"int",
"$",
"height",
"=",
"0",
",",
"$",
"fit",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"isLocalOrPublic",
"(",
"$",
"disk",
")",
")",
"{",
"$",
"folder",
"=",
"config",
"(",
"'filesystems.disks.'",
".",
"$",
"disk",
".",
"'.root'",
")",
".",
"'/cache/'",
".",
"str_replace",
"(",
"'-'",
",",
"'/'",
",",
"$",
"resourceId",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"mkdir",
"(",
"$",
"folder",
",",
"0755",
",",
"true",
")",
";",
"}",
"}",
"$",
"path",
"=",
"'cache/'",
".",
"str_replace",
"(",
"'-'",
",",
"'/'",
",",
"$",
"resourceId",
")",
".",
"'/'",
";",
"$",
"path",
".=",
"$",
"width",
".",
"'_'",
".",
"$",
"height",
";",
"if",
"(",
"$",
"fit",
")",
"{",
"$",
"path",
".=",
"'_fit'",
";",
"}",
"return",
"$",
"path",
".",
"$",
"extension",
";",
"}"
] | Generating resource cache location and name
@param string $resourceId
@param string $disk
@param string $extension
@param int|null $width
@param int|null $height
@param null $fit
@return string | [
"Generating",
"resource",
"cache",
"location",
"and",
"name"
] | 9b82eb2fd99be99edfdc4e76803d95caf981e14b | https://github.com/honey-comb/resources/blob/9b82eb2fd99be99edfdc4e76803d95caf981e14b/src/Services/HCResourceService.php#L673-L698 | train |
honey-comb/resources | src/Services/HCResourceService.php | HCResourceService.createImage | protected function createImage(string $disk, $source, $destination, $width = 0, $height = 0, $fit = false): bool
{
if ($width == 0) {
$width = null;
}
if ($height == 0) {
$height = null;
}
if ($this->isLocalOrPublic($disk)) {
$source = config('filesystems.disks.' . $disk . '.root') . DIRECTORY_SEPARATOR . $source;
$destination = config('filesystems.disks.' . $disk . '.root') . DIRECTORY_SEPARATOR . $destination;
} else {
$source = Storage::disk($disk)->url($source);
}
/** @var \Intervention\Image\Image $image */
$image = Image::make($source);
if ($fit) {
$image->fit($width, $height, function (Constraint $constraint) {
$constraint->upsize();
});
} else {
$image->resize($width, $height, function (Constraint $constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
if ($this->isLocalOrPublic($disk)) {
$image->save($destination);
$image->destroy();
} else {
Storage::disk($disk)->put($destination, (string)$image->encode());
}
return true;
} | php | protected function createImage(string $disk, $source, $destination, $width = 0, $height = 0, $fit = false): bool
{
if ($width == 0) {
$width = null;
}
if ($height == 0) {
$height = null;
}
if ($this->isLocalOrPublic($disk)) {
$source = config('filesystems.disks.' . $disk . '.root') . DIRECTORY_SEPARATOR . $source;
$destination = config('filesystems.disks.' . $disk . '.root') . DIRECTORY_SEPARATOR . $destination;
} else {
$source = Storage::disk($disk)->url($source);
}
/** @var \Intervention\Image\Image $image */
$image = Image::make($source);
if ($fit) {
$image->fit($width, $height, function (Constraint $constraint) {
$constraint->upsize();
});
} else {
$image->resize($width, $height, function (Constraint $constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
if ($this->isLocalOrPublic($disk)) {
$image->save($destination);
$image->destroy();
} else {
Storage::disk($disk)->put($destination, (string)$image->encode());
}
return true;
} | [
"protected",
"function",
"createImage",
"(",
"string",
"$",
"disk",
",",
"$",
"source",
",",
"$",
"destination",
",",
"$",
"width",
"=",
"0",
",",
"$",
"height",
"=",
"0",
",",
"$",
"fit",
"=",
"false",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"width",
"==",
"0",
")",
"{",
"$",
"width",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"height",
"==",
"0",
")",
"{",
"$",
"height",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isLocalOrPublic",
"(",
"$",
"disk",
")",
")",
"{",
"$",
"source",
"=",
"config",
"(",
"'filesystems.disks.'",
".",
"$",
"disk",
".",
"'.root'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"source",
";",
"$",
"destination",
"=",
"config",
"(",
"'filesystems.disks.'",
".",
"$",
"disk",
".",
"'.root'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"destination",
";",
"}",
"else",
"{",
"$",
"source",
"=",
"Storage",
"::",
"disk",
"(",
"$",
"disk",
")",
"->",
"url",
"(",
"$",
"source",
")",
";",
"}",
"/** @var \\Intervention\\Image\\Image $image */",
"$",
"image",
"=",
"Image",
"::",
"make",
"(",
"$",
"source",
")",
";",
"if",
"(",
"$",
"fit",
")",
"{",
"$",
"image",
"->",
"fit",
"(",
"$",
"width",
",",
"$",
"height",
",",
"function",
"(",
"Constraint",
"$",
"constraint",
")",
"{",
"$",
"constraint",
"->",
"upsize",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"$",
"image",
"->",
"resize",
"(",
"$",
"width",
",",
"$",
"height",
",",
"function",
"(",
"Constraint",
"$",
"constraint",
")",
"{",
"$",
"constraint",
"->",
"upsize",
"(",
")",
";",
"$",
"constraint",
"->",
"aspectRatio",
"(",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isLocalOrPublic",
"(",
"$",
"disk",
")",
")",
"{",
"$",
"image",
"->",
"save",
"(",
"$",
"destination",
")",
";",
"$",
"image",
"->",
"destroy",
"(",
")",
";",
"}",
"else",
"{",
"Storage",
"::",
"disk",
"(",
"$",
"disk",
")",
"->",
"put",
"(",
"$",
"destination",
",",
"(",
"string",
")",
"$",
"image",
"->",
"encode",
"(",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Creating image based on provided data
@param string $disk
@param $source
@param $destination
@param int $width
@param int $height
@param bool $fit
@return bool | [
"Creating",
"image",
"based",
"on",
"provided",
"data"
] | 9b82eb2fd99be99edfdc4e76803d95caf981e14b | https://github.com/honey-comb/resources/blob/9b82eb2fd99be99edfdc4e76803d95caf981e14b/src/Services/HCResourceService.php#L711-L750 | train |
phospr/DoubleEntryBundle | Model/PostingHandler.php | PostingHandler.findPostingForId | public function findPostingForId($id)
{
$dql = '
SELECT p
FROM %s p
WHERE p.id = :id
AND p.organization = :organization
';
return $this->em
->createQuery(sprintf($dql, $this->postingFqcn))
->setParameter('id', $id)
->setParameter('organization', $this->oh->getOrganization())
->getSingleResult()
;
} | php | public function findPostingForId($id)
{
$dql = '
SELECT p
FROM %s p
WHERE p.id = :id
AND p.organization = :organization
';
return $this->em
->createQuery(sprintf($dql, $this->postingFqcn))
->setParameter('id', $id)
->setParameter('organization', $this->oh->getOrganization())
->getSingleResult()
;
} | [
"public",
"function",
"findPostingForId",
"(",
"$",
"id",
")",
"{",
"$",
"dql",
"=",
"'\n SELECT p\n FROM %s p\n WHERE p.id = :id\n AND p.organization = :organization\n '",
";",
"return",
"$",
"this",
"->",
"em",
"->",
"createQuery",
"(",
"sprintf",
"(",
"$",
"dql",
",",
"$",
"this",
"->",
"postingFqcn",
")",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"id",
")",
"->",
"setParameter",
"(",
"'organization'",
",",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
")",
"->",
"getSingleResult",
"(",
")",
";",
"}"
] | Find Posting for id
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@param int $id
@return Posting | [
"Find",
"Posting",
"for",
"id"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/PostingHandler.php#L98-L113 | train |
phospr/DoubleEntryBundle | Model/PostingHandler.php | PostingHandler.createPosting | public function createPosting(AccountInterface $account = null, $amount = null)
{
$posting = new $this->postingFqcn($account, $amount);
$posting->setOrganization($this->oh->getOrganization());
return $posting;
} | php | public function createPosting(AccountInterface $account = null, $amount = null)
{
$posting = new $this->postingFqcn($account, $amount);
$posting->setOrganization($this->oh->getOrganization());
return $posting;
} | [
"public",
"function",
"createPosting",
"(",
"AccountInterface",
"$",
"account",
"=",
"null",
",",
"$",
"amount",
"=",
"null",
")",
"{",
"$",
"posting",
"=",
"new",
"$",
"this",
"->",
"postingFqcn",
"(",
"$",
"account",
",",
"$",
"amount",
")",
";",
"$",
"posting",
"->",
"setOrganization",
"(",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
")",
";",
"return",
"$",
"posting",
";",
"}"
] | Create new Posting
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@param AccountInterface $account
@param float $amount
@return Posting | [
"Create",
"new",
"Posting"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/PostingHandler.php#L126-L132 | train |
linpax/microphp-cache | src/adapter/Memcached.php | Memcached.check | public function check($driver)
{
switch ($driver) {
case self::DRIVER_MEMCACHE:
return extension_loaded('memcache');
case self::DRIVER_MEMCACHED:
return extension_loaded('memcached');
}
return false;
} | php | public function check($driver)
{
switch ($driver) {
case self::DRIVER_MEMCACHE:
return extension_loaded('memcache');
case self::DRIVER_MEMCACHED:
return extension_loaded('memcached');
}
return false;
} | [
"public",
"function",
"check",
"(",
"$",
"driver",
")",
"{",
"switch",
"(",
"$",
"driver",
")",
"{",
"case",
"self",
"::",
"DRIVER_MEMCACHE",
":",
"return",
"extension_loaded",
"(",
"'memcache'",
")",
";",
"case",
"self",
"::",
"DRIVER_MEMCACHED",
":",
"return",
"extension_loaded",
"(",
"'memcached'",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Checks installed extensions
@return bool | [
"Checks",
"installed",
"extensions"
] | 15dda63a3fac9ad769fdc8d825ff60e256e14c4d | https://github.com/linpax/microphp-cache/blob/15dda63a3fac9ad769fdc8d825ff60e256e14c4d/src/adapter/Memcached.php#L75-L84 | train |
cubicmushroom/valueobjects | src/Geography/Country.php | Country.fromNative | public static function fromNative()
{
$codeString = \func_get_arg(0);
$code = CountryCode::getByName($codeString);
$country = new self($code);
return $country;
} | php | public static function fromNative()
{
$codeString = \func_get_arg(0);
$code = CountryCode::getByName($codeString);
$country = new self($code);
return $country;
} | [
"public",
"static",
"function",
"fromNative",
"(",
")",
"{",
"$",
"codeString",
"=",
"\\",
"func_get_arg",
"(",
"0",
")",
";",
"$",
"code",
"=",
"CountryCode",
"::",
"getByName",
"(",
"$",
"codeString",
")",
";",
"$",
"country",
"=",
"new",
"self",
"(",
"$",
"code",
")",
";",
"return",
"$",
"country",
";",
"}"
] | Returns a new Country object given a native PHP string country code
@param string $code
@return self | [
"Returns",
"a",
"new",
"Country",
"object",
"given",
"a",
"native",
"PHP",
"string",
"country",
"code"
] | 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Country.php#L19-L26 | train |
cubicmushroom/valueobjects | src/Geography/Country.php | Country.sameValueAs | public function sameValueAs(ValueObjectInterface $country)
{
if (false === Util::classEquals($this, $country)) {
return false;
}
return $this->getCode()->sameValueAs($country->getCode());
} | php | public function sameValueAs(ValueObjectInterface $country)
{
if (false === Util::classEquals($this, $country)) {
return false;
}
return $this->getCode()->sameValueAs($country->getCode());
} | [
"public",
"function",
"sameValueAs",
"(",
"ValueObjectInterface",
"$",
"country",
")",
"{",
"if",
"(",
"false",
"===",
"Util",
"::",
"classEquals",
"(",
"$",
"this",
",",
"$",
"country",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"getCode",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"country",
"->",
"getCode",
"(",
")",
")",
";",
"}"
] | Tells whether two Country are equal
@param ValueObjectInterface $country
@return bool | [
"Tells",
"whether",
"two",
"Country",
"are",
"equal"
] | 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Country.php#L44-L51 | train |
phossa/phossa-db | src/Phossa/Db/Manager/Manager.php | Manager.driverMatcher | protected function driverMatcher(/*# string */ $tag)/*# : array */
{
$matched = [];
foreach ($this->drivers as $id => $driver) {
// disconnected or tag not match
if (!$driver->ping() ||
'' !== $tag &&
(
!$driver instanceof TaggableInterface ||
!$driver->hasTag($tag)
)
) {
continue;
}
// weight factor
$f = $this->factors[$id];
for ($i = 0; $i < $f; ++$i) {
$matched[] = $id;
}
}
return $matched;
} | php | protected function driverMatcher(/*# string */ $tag)/*# : array */
{
$matched = [];
foreach ($this->drivers as $id => $driver) {
// disconnected or tag not match
if (!$driver->ping() ||
'' !== $tag &&
(
!$driver instanceof TaggableInterface ||
!$driver->hasTag($tag)
)
) {
continue;
}
// weight factor
$f = $this->factors[$id];
for ($i = 0; $i < $f; ++$i) {
$matched[] = $id;
}
}
return $matched;
} | [
"protected",
"function",
"driverMatcher",
"(",
"/*# string */",
"$",
"tag",
")",
"/*# : array */",
"{",
"$",
"matched",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"drivers",
"as",
"$",
"id",
"=>",
"$",
"driver",
")",
"{",
"// disconnected or tag not match\r",
"if",
"(",
"!",
"$",
"driver",
"->",
"ping",
"(",
")",
"||",
"''",
"!==",
"$",
"tag",
"&&",
"(",
"!",
"$",
"driver",
"instanceof",
"TaggableInterface",
"||",
"!",
"$",
"driver",
"->",
"hasTag",
"(",
"$",
"tag",
")",
")",
")",
"{",
"continue",
";",
"}",
"// weight factor\r",
"$",
"f",
"=",
"$",
"this",
"->",
"factors",
"[",
"$",
"id",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"f",
";",
"++",
"$",
"i",
")",
"{",
"$",
"matched",
"[",
"]",
"=",
"$",
"id",
";",
"}",
"}",
"return",
"$",
"matched",
";",
"}"
] | Driver tag matcher
@param string $tag tag to match
@return array
@access protected | [
"Driver",
"tag",
"matcher"
] | 9ef2c0e0c3047f4ff2ce6b0a218187025ac64d29 | https://github.com/phossa/phossa-db/blob/9ef2c0e0c3047f4ff2ce6b0a218187025ac64d29/src/Phossa/Db/Manager/Manager.php#L146-L168 | train |
rafrsr/lib-array2object | src/Traits/ParsersAwareTrait.php | ParsersAwareTrait.prependParser | public function prependParser(ValueParserInterface $parser)
{
$parsers = $this->parsers;
if (array_key_exists($parser->getName(), $parsers)) {
unset($parsers[$parser->getName()]);
}
$this->parsers = array_merge([$parser->getName() => $parser], $parsers);
return $this;
} | php | public function prependParser(ValueParserInterface $parser)
{
$parsers = $this->parsers;
if (array_key_exists($parser->getName(), $parsers)) {
unset($parsers[$parser->getName()]);
}
$this->parsers = array_merge([$parser->getName() => $parser], $parsers);
return $this;
} | [
"public",
"function",
"prependParser",
"(",
"ValueParserInterface",
"$",
"parser",
")",
"{",
"$",
"parsers",
"=",
"$",
"this",
"->",
"parsers",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"parser",
"->",
"getName",
"(",
")",
",",
"$",
"parsers",
")",
")",
"{",
"unset",
"(",
"$",
"parsers",
"[",
"$",
"parser",
"->",
"getName",
"(",
")",
"]",
")",
";",
"}",
"$",
"this",
"->",
"parsers",
"=",
"array_merge",
"(",
"[",
"$",
"parser",
"->",
"getName",
"(",
")",
"=>",
"$",
"parser",
"]",
",",
"$",
"parsers",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Prepend parser to list of parsers, HIGH priority.
@param ValueParserInterface $parser
@return $this | [
"Prepend",
"parser",
"to",
"list",
"of",
"parsers",
"HIGH",
"priority",
"."
] | d15db63b5f5740dbc7c2213373320445785856ef | https://github.com/rafrsr/lib-array2object/blob/d15db63b5f5740dbc7c2213373320445785856ef/src/Traits/ParsersAwareTrait.php#L69-L79 | train |
LartTyler/SalesforceClient | src/DaybreakStudios/Salesforce/ClientUtil.php | ClientUtil.getSObjectFields | public static function getSObjectFields(SObject $sob) {
if (!isset($sob->fields))
return null;
$fields = $sob->fields;
if (is_object($fields))
$fields = get_object_vars($fields);
return $fields;
} | php | public static function getSObjectFields(SObject $sob) {
if (!isset($sob->fields))
return null;
$fields = $sob->fields;
if (is_object($fields))
$fields = get_object_vars($fields);
return $fields;
} | [
"public",
"static",
"function",
"getSObjectFields",
"(",
"SObject",
"$",
"sob",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"sob",
"->",
"fields",
")",
")",
"return",
"null",
";",
"$",
"fields",
"=",
"$",
"sob",
"->",
"fields",
";",
"if",
"(",
"is_object",
"(",
"$",
"fields",
")",
")",
"$",
"fields",
"=",
"get_object_vars",
"(",
"$",
"fields",
")",
";",
"return",
"$",
"fields",
";",
"}"
] | Gets the Salesforce fields member out of an SObject, and guarentees conversion to an associative array.
@param SObject $sob the SObject to retrieve the fields member from
@return array|null the fields member as an associative array, or null if fields is not defined | [
"Gets",
"the",
"Salesforce",
"fields",
"member",
"out",
"of",
"an",
"SObject",
"and",
"guarentees",
"conversion",
"to",
"an",
"associative",
"array",
"."
] | 8fc0197c0b80a78d88d5d62486567af69661a2c9 | https://github.com/LartTyler/SalesforceClient/blob/8fc0197c0b80a78d88d5d62486567af69661a2c9/src/DaybreakStudios/Salesforce/ClientUtil.php#L11-L21 | train |
LartTyler/SalesforceClient | src/DaybreakStudios/Salesforce/ClientUtil.php | ClientUtil.updateSObjectFields | public static function updateSObjectFields(SObject $sob, $fields) {
if (!is_array($fields) && !is_object($fields))
throw new InvalidArgumentException('$fields must be an array or object');
if (is_object($sob->fields))
$fields = (object)$fields;
$sob->fields = $fields;
return $sob;
} | php | public static function updateSObjectFields(SObject $sob, $fields) {
if (!is_array($fields) && !is_object($fields))
throw new InvalidArgumentException('$fields must be an array or object');
if (is_object($sob->fields))
$fields = (object)$fields;
$sob->fields = $fields;
return $sob;
} | [
"public",
"static",
"function",
"updateSObjectFields",
"(",
"SObject",
"$",
"sob",
",",
"$",
"fields",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
"&&",
"!",
"is_object",
"(",
"$",
"fields",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$fields must be an array or object'",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"sob",
"->",
"fields",
")",
")",
"$",
"fields",
"=",
"(",
"object",
")",
"$",
"fields",
";",
"$",
"sob",
"->",
"fields",
"=",
"$",
"fields",
";",
"return",
"$",
"sob",
";",
"}"
] | Updates an SObject's fields member using either an object or an associative array.
@throws InvalidArgumentException if $fields is not an array or an object
@param SObject $sob the SObject to update
@param array|object $fields the array or object to update the fields member from
@return SObject the updated SObject for chaining | [
"Updates",
"an",
"SObject",
"s",
"fields",
"member",
"using",
"either",
"an",
"object",
"or",
"an",
"associative",
"array",
"."
] | 8fc0197c0b80a78d88d5d62486567af69661a2c9 | https://github.com/LartTyler/SalesforceClient/blob/8fc0197c0b80a78d88d5d62486567af69661a2c9/src/DaybreakStudios/Salesforce/ClientUtil.php#L32-L42 | train |
smalldb/smalldb-rest | class/JsonResponse.php | JsonResponse.sendException | public static function sendException(\Exception $ex)
{
$class = get_class($ex);
switch ($class) {
case 'Smalldb\\StateMachine\\TransitionAccessException':
$http_code = '403';
break;
case 'Smalldb\\StateMachine\\InstanceDoesNotExistException':
$http_code = '404';
break;
default:
$http_code = '500';
break;
}
header("HTTP/1.0 $http_code Exception: $class");
header('Content-Type: application/json; encoding=utf-8');
static::writeException($ex);
} | php | public static function sendException(\Exception $ex)
{
$class = get_class($ex);
switch ($class) {
case 'Smalldb\\StateMachine\\TransitionAccessException':
$http_code = '403';
break;
case 'Smalldb\\StateMachine\\InstanceDoesNotExistException':
$http_code = '404';
break;
default:
$http_code = '500';
break;
}
header("HTTP/1.0 $http_code Exception: $class");
header('Content-Type: application/json; encoding=utf-8');
static::writeException($ex);
} | [
"public",
"static",
"function",
"sendException",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"ex",
")",
";",
"switch",
"(",
"$",
"class",
")",
"{",
"case",
"'Smalldb\\\\StateMachine\\\\TransitionAccessException'",
":",
"$",
"http_code",
"=",
"'403'",
";",
"break",
";",
"case",
"'Smalldb\\\\StateMachine\\\\InstanceDoesNotExistException'",
":",
"$",
"http_code",
"=",
"'404'",
";",
"break",
";",
"default",
":",
"$",
"http_code",
"=",
"'500'",
";",
"break",
";",
"}",
"header",
"(",
"\"HTTP/1.0 $http_code Exception: $class\"",
")",
";",
"header",
"(",
"'Content-Type: application/json; encoding=utf-8'",
")",
";",
"static",
"::",
"writeException",
"(",
"$",
"ex",
")",
";",
"}"
] | Send info about thrown exception and set proper HTTP code. | [
"Send",
"info",
"about",
"thrown",
"exception",
"and",
"set",
"proper",
"HTTP",
"code",
"."
] | ff393ee39060b4524d41835921e86ed40af006fe | https://github.com/smalldb/smalldb-rest/blob/ff393ee39060b4524d41835921e86ed40af006fe/class/JsonResponse.php#L39-L57 | train |
smalldb/smalldb-rest | class/JsonResponse.php | JsonResponse.writeException | public static function writeException(\Exception $ex)
{
$response = array(
'exception' => get_class($ex),
'message' => $ex->getMessage(),
'code' => $ex->getCode(),
);
static::writeJson($response);
} | php | public static function writeException(\Exception $ex)
{
$response = array(
'exception' => get_class($ex),
'message' => $ex->getMessage(),
'code' => $ex->getCode(),
);
static::writeJson($response);
} | [
"public",
"static",
"function",
"writeException",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"array",
"(",
"'exception'",
"=>",
"get_class",
"(",
"$",
"ex",
")",
",",
"'message'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"'code'",
"=>",
"$",
"ex",
"->",
"getCode",
"(",
")",
",",
")",
";",
"static",
"::",
"writeJson",
"(",
"$",
"response",
")",
";",
"}"
] | Render exception as JSON string | [
"Render",
"exception",
"as",
"JSON",
"string"
] | ff393ee39060b4524d41835921e86ed40af006fe | https://github.com/smalldb/smalldb-rest/blob/ff393ee39060b4524d41835921e86ed40af006fe/class/JsonResponse.php#L63-L71 | train |
RocketPropelledTortoise/Core | src/Taxonomy/Term.php | Term.string | public function string($key, $language = '')
{
if (!$this->hasTranslations()) {
return $this->container['lang'][$key];
}
if ($language == '') {
$language = I18N::getCurrent();
}
if (array_key_exists('lang_' . $language, $this->container)) {
return $this->container['lang_' . $language][$key];
}
return '';
} | php | public function string($key, $language = '')
{
if (!$this->hasTranslations()) {
return $this->container['lang'][$key];
}
if ($language == '') {
$language = I18N::getCurrent();
}
if (array_key_exists('lang_' . $language, $this->container)) {
return $this->container['lang_' . $language][$key];
}
return '';
} | [
"public",
"function",
"string",
"(",
"$",
"key",
",",
"$",
"language",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasTranslations",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"[",
"'lang'",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"if",
"(",
"$",
"language",
"==",
"''",
")",
"{",
"$",
"language",
"=",
"I18N",
"::",
"getCurrent",
"(",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'lang_'",
".",
"$",
"language",
",",
"$",
"this",
"->",
"container",
")",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"[",
"'lang_'",
".",
"$",
"language",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"''",
";",
"}"
] | Return the textual version of the term
@param string $key
@param string $language
@return string | [
"Return",
"the",
"textual",
"version",
"of",
"the",
"term"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Term.php#L148-L163 | train |
RocketPropelledTortoise/Core | src/Taxonomy/Term.php | Term.translated | public function translated($language = '')
{
if (!$this->hasTranslations()) {
return true;
}
if ($language == '') {
$language = I18N::getCurrent();
}
if (array_key_exists('lang_' . $language, $this->container)) {
return $this->container['lang_' . $language]['translated'];
}
return false;
} | php | public function translated($language = '')
{
if (!$this->hasTranslations()) {
return true;
}
if ($language == '') {
$language = I18N::getCurrent();
}
if (array_key_exists('lang_' . $language, $this->container)) {
return $this->container['lang_' . $language]['translated'];
}
return false;
} | [
"public",
"function",
"translated",
"(",
"$",
"language",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasTranslations",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"language",
"==",
"''",
")",
"{",
"$",
"language",
"=",
"I18N",
"::",
"getCurrent",
"(",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'lang_'",
".",
"$",
"language",
",",
"$",
"this",
"->",
"container",
")",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"[",
"'lang_'",
".",
"$",
"language",
"]",
"[",
"'translated'",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Is it translated in this language ?
@param string $language
@return bool | [
"Is",
"it",
"translated",
"in",
"this",
"language",
"?"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Term.php#L171-L186 | train |
RocketPropelledTortoise/Core | src/Taxonomy/Term.php | Term.editLanguage | public function editLanguage($language = '')
{
if (!array_key_exists('lang_' . $language, $this->container)) {
throw new UndefinedLanguageException;
}
return $this->container['lang_' . $language];
} | php | public function editLanguage($language = '')
{
if (!array_key_exists('lang_' . $language, $this->container)) {
throw new UndefinedLanguageException;
}
return $this->container['lang_' . $language];
} | [
"public",
"function",
"editLanguage",
"(",
"$",
"language",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'lang_'",
".",
"$",
"language",
",",
"$",
"this",
"->",
"container",
")",
")",
"{",
"throw",
"new",
"UndefinedLanguageException",
";",
"}",
"return",
"$",
"this",
"->",
"container",
"[",
"'lang_'",
".",
"$",
"language",
"]",
";",
"}"
] | Retrieve a language for edition
@param string $language
@throws UndefinedLanguageException
@return Model\TermData | [
"Retrieve",
"a",
"language",
"for",
"edition"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Term.php#L240-L247 | train |
rawphp/RawYaml | lib/Yaml.php | Yaml.load | public function load( $file )
{
$retVal = array( );
try
{
$retVal = SymFonyYaml::parse( $file );
}
catch ( \Exception $e )
{
throw new YamlException( $e->getmessage( ), $e->getCode( ), $e );
}
return $this->filter( self::ON_YAML_LOAD_FILTER, $retVal, $file );
} | php | public function load( $file )
{
$retVal = array( );
try
{
$retVal = SymFonyYaml::parse( $file );
}
catch ( \Exception $e )
{
throw new YamlException( $e->getmessage( ), $e->getCode( ), $e );
}
return $this->filter( self::ON_YAML_LOAD_FILTER, $retVal, $file );
} | [
"public",
"function",
"load",
"(",
"$",
"file",
")",
"{",
"$",
"retVal",
"=",
"array",
"(",
")",
";",
"try",
"{",
"$",
"retVal",
"=",
"SymFonyYaml",
"::",
"parse",
"(",
"$",
"file",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"YamlException",
"(",
"$",
"e",
"->",
"getmessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filter",
"(",
"self",
"::",
"ON_YAML_LOAD_FILTER",
",",
"$",
"retVal",
",",
"$",
"file",
")",
";",
"}"
] | Parses yaml file and returns an array.
@param string $file the yaml file.
@fitler ON_YAML_LOAD_FILTER(2)
@return array the configuration array | [
"Parses",
"yaml",
"file",
"and",
"returns",
"an",
"array",
"."
] | d680b1964d5da42c67838df3aefb10e988c9cfcf | https://github.com/rawphp/RawYaml/blob/d680b1964d5da42c67838df3aefb10e988c9cfcf/lib/Yaml.php#L77-L91 | train |
rawphp/RawYaml | lib/Yaml.php | Yaml.save | public function save( $array, $file )
{
try
{
ob_start( );
$this->dump( $array );
$data = ob_get_clean( );
file_put_contents( $file, $this->filter( self::ON_YAML_SAVE_FILTER, $data, $array, $file ) );
}
catch ( \Exception $e )
{
throw new YamlException( $e->getMessage( ), $e->getCode( ), $e );
}
} | php | public function save( $array, $file )
{
try
{
ob_start( );
$this->dump( $array );
$data = ob_get_clean( );
file_put_contents( $file, $this->filter( self::ON_YAML_SAVE_FILTER, $data, $array, $file ) );
}
catch ( \Exception $e )
{
throw new YamlException( $e->getMessage( ), $e->getCode( ), $e );
}
} | [
"public",
"function",
"save",
"(",
"$",
"array",
",",
"$",
"file",
")",
"{",
"try",
"{",
"ob_start",
"(",
")",
";",
"$",
"this",
"->",
"dump",
"(",
"$",
"array",
")",
";",
"$",
"data",
"=",
"ob_get_clean",
"(",
")",
";",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"filter",
"(",
"self",
"::",
"ON_YAML_SAVE_FILTER",
",",
"$",
"data",
",",
"$",
"array",
",",
"$",
"file",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"YamlException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Save array as yml to file.
@param array $array the array to save
@param string $file file path
@filter ON_YAML_SAVE_FILTER(3)
@throws YamlException on saving problems | [
"Save",
"array",
"as",
"yml",
"to",
"file",
"."
] | d680b1964d5da42c67838df3aefb10e988c9cfcf | https://github.com/rawphp/RawYaml/blob/d680b1964d5da42c67838df3aefb10e988c9cfcf/lib/Yaml.php#L103-L119 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgClass.php | PgClass.getEntityName | public function getEntityName()
{
// we got a entityname set already
$tags = $this->getTags();
if( isset( $tags['entity-name'] ) ) {
return $tags['entity-name'];
}
$name = ucwords( $this->name );
$name = \str_replace( '_', '', $name );
return $name;
} | php | public function getEntityName()
{
// we got a entityname set already
$tags = $this->getTags();
if( isset( $tags['entity-name'] ) ) {
return $tags['entity-name'];
}
$name = ucwords( $this->name );
$name = \str_replace( '_', '', $name );
return $name;
} | [
"public",
"function",
"getEntityName",
"(",
")",
"{",
"// we got a entityname set already",
"$",
"tags",
"=",
"$",
"this",
"->",
"getTags",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"tags",
"[",
"'entity-name'",
"]",
")",
")",
"{",
"return",
"$",
"tags",
"[",
"'entity-name'",
"]",
";",
"}",
"$",
"name",
"=",
"ucwords",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"name",
"=",
"\\",
"str_replace",
"(",
"'_'",
",",
"''",
",",
"$",
"name",
")",
";",
"return",
"$",
"name",
";",
"}"
] | The name of this relation as per the Bond convention
Uppercase first letter. Replace '_' with ''
@return string | [
"The",
"name",
"of",
"this",
"relation",
"as",
"per",
"the",
"Bond",
"convention",
"Uppercase",
"first",
"letter",
".",
"Replace",
"_",
"with"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgClass.php#L151-L166 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgClass.php | PgClass.getLinks | public function getLinks()
{
if( isset( $this->links ) ) {
return $this->links;
}
// build links
$this->links = array();
foreach( $this->getAttributes() as $column ) {
/* This relation has a link if it has a attribute which has all of the following
* 1. Is unique and is referenced by another attribute
TODO. Pete: We don't currently support dual column foreign key constraints
* 2. This another attribute is one half of a dualcolumn primary key
* TODO. Pete: I think this can be relaxed a little. We just need a unique constraint which references two tables
* 3. The other half of the primary references another unique constraint in another table
*/
// See 1.
if( $column->isUnique() and ( $references = $column->getIsReferencedBy() ) ) {
foreach( $references as $reference ) {
// See 2.
if( $reference->isPrimaryKey() and count( $primaryKeys = $reference->getRelation()->getPrimaryKeys() ) == 2 ) {
$primaryKeys->remove( $reference );
$otherHalfofPrimaryKey = $primaryKeys->pop();
// See 3.
$otherReferences = $otherHalfofPrimaryKey->getReferences();
$foreignEntities = new BaseContainer();
foreach( $otherReferences as $otherReference ) {
// Pete. We might not need the unique check here because foreign keys already have uniqueness enforced
if( $otherReference->isUnique() and $otherReference->getRelation() !== $this ) {
$foreignEntities[] = $foreignEntities->add( $otherReference->getRelation() );
$foreignEntityReference = $otherReference;
}
}
// have we a link?
if( $foreignEntities ) {
$sourceEntity = $this->getEntityName();
$linkEntity = $otherHalfofPrimaryKey->getRelation()->getEntityName();
$refSource = array( $column->name, $reference->name );
$refForeign = array( $otherHalfofPrimaryKey->name, $foreignEntityReference->name );
// get columns and look for a ranking columns
$possibleRankingAttributes = $otherHalfofPrimaryKey->getRelation()->getAttributes();
$possibleRankingAttributes->remove( $otherHalfofPrimaryKey, $reference );
$sortColumn = null;
$rankingRegex = "/^{$otherHalfofPrimaryKey->name}_?(r|rank|ranking)$/i";
foreach( $possibleRankingAttributes as $ranking ) {
if( $ranking->getType()->isNumeric() and preg_match( $rankingRegex, $ranking->name ) ) {
$sortColumn = $ranking->name;
break;
}
}
// sort foreignEntities, we want 'root' entity first then alphabetical
$foreignEntities = $foreignEntities
->sort(
function($a, $b){
if( $a->isInherited() and !$b->isInherited() ) {
return 1;
}
return $a->getEntityName() < $b->getEntityName() ? -1 : 1;
}
)
->map(function ($e) {
return $e->getEntityName();
});
$this->links[$linkEntity] = new Link(
$sourceEntity,
$linkEntity,
array_values( $foreignEntities ),
$refSource,
$refForeign,
$sortColumn
);
}
}
}
}
}
return $this->links;
} | php | public function getLinks()
{
if( isset( $this->links ) ) {
return $this->links;
}
// build links
$this->links = array();
foreach( $this->getAttributes() as $column ) {
/* This relation has a link if it has a attribute which has all of the following
* 1. Is unique and is referenced by another attribute
TODO. Pete: We don't currently support dual column foreign key constraints
* 2. This another attribute is one half of a dualcolumn primary key
* TODO. Pete: I think this can be relaxed a little. We just need a unique constraint which references two tables
* 3. The other half of the primary references another unique constraint in another table
*/
// See 1.
if( $column->isUnique() and ( $references = $column->getIsReferencedBy() ) ) {
foreach( $references as $reference ) {
// See 2.
if( $reference->isPrimaryKey() and count( $primaryKeys = $reference->getRelation()->getPrimaryKeys() ) == 2 ) {
$primaryKeys->remove( $reference );
$otherHalfofPrimaryKey = $primaryKeys->pop();
// See 3.
$otherReferences = $otherHalfofPrimaryKey->getReferences();
$foreignEntities = new BaseContainer();
foreach( $otherReferences as $otherReference ) {
// Pete. We might not need the unique check here because foreign keys already have uniqueness enforced
if( $otherReference->isUnique() and $otherReference->getRelation() !== $this ) {
$foreignEntities[] = $foreignEntities->add( $otherReference->getRelation() );
$foreignEntityReference = $otherReference;
}
}
// have we a link?
if( $foreignEntities ) {
$sourceEntity = $this->getEntityName();
$linkEntity = $otherHalfofPrimaryKey->getRelation()->getEntityName();
$refSource = array( $column->name, $reference->name );
$refForeign = array( $otherHalfofPrimaryKey->name, $foreignEntityReference->name );
// get columns and look for a ranking columns
$possibleRankingAttributes = $otherHalfofPrimaryKey->getRelation()->getAttributes();
$possibleRankingAttributes->remove( $otherHalfofPrimaryKey, $reference );
$sortColumn = null;
$rankingRegex = "/^{$otherHalfofPrimaryKey->name}_?(r|rank|ranking)$/i";
foreach( $possibleRankingAttributes as $ranking ) {
if( $ranking->getType()->isNumeric() and preg_match( $rankingRegex, $ranking->name ) ) {
$sortColumn = $ranking->name;
break;
}
}
// sort foreignEntities, we want 'root' entity first then alphabetical
$foreignEntities = $foreignEntities
->sort(
function($a, $b){
if( $a->isInherited() and !$b->isInherited() ) {
return 1;
}
return $a->getEntityName() < $b->getEntityName() ? -1 : 1;
}
)
->map(function ($e) {
return $e->getEntityName();
});
$this->links[$linkEntity] = new Link(
$sourceEntity,
$linkEntity,
array_values( $foreignEntities ),
$refSource,
$refForeign,
$sortColumn
);
}
}
}
}
}
return $this->links;
} | [
"public",
"function",
"getLinks",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"links",
")",
")",
"{",
"return",
"$",
"this",
"->",
"links",
";",
"}",
"// build links",
"$",
"this",
"->",
"links",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"column",
")",
"{",
"/* This relation has a link if it has a attribute which has all of the following\n * 1. Is unique and is referenced by another attribute\n TODO. Pete: We don't currently support dual column foreign key constraints\n * 2. This another attribute is one half of a dualcolumn primary key\n * TODO. Pete: I think this can be relaxed a little. We just need a unique constraint which references two tables\n * 3. The other half of the primary references another unique constraint in another table\n */",
"// See 1.",
"if",
"(",
"$",
"column",
"->",
"isUnique",
"(",
")",
"and",
"(",
"$",
"references",
"=",
"$",
"column",
"->",
"getIsReferencedBy",
"(",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"references",
"as",
"$",
"reference",
")",
"{",
"// See 2.",
"if",
"(",
"$",
"reference",
"->",
"isPrimaryKey",
"(",
")",
"and",
"count",
"(",
"$",
"primaryKeys",
"=",
"$",
"reference",
"->",
"getRelation",
"(",
")",
"->",
"getPrimaryKeys",
"(",
")",
")",
"==",
"2",
")",
"{",
"$",
"primaryKeys",
"->",
"remove",
"(",
"$",
"reference",
")",
";",
"$",
"otherHalfofPrimaryKey",
"=",
"$",
"primaryKeys",
"->",
"pop",
"(",
")",
";",
"// See 3.",
"$",
"otherReferences",
"=",
"$",
"otherHalfofPrimaryKey",
"->",
"getReferences",
"(",
")",
";",
"$",
"foreignEntities",
"=",
"new",
"BaseContainer",
"(",
")",
";",
"foreach",
"(",
"$",
"otherReferences",
"as",
"$",
"otherReference",
")",
"{",
"// Pete. We might not need the unique check here because foreign keys already have uniqueness enforced",
"if",
"(",
"$",
"otherReference",
"->",
"isUnique",
"(",
")",
"and",
"$",
"otherReference",
"->",
"getRelation",
"(",
")",
"!==",
"$",
"this",
")",
"{",
"$",
"foreignEntities",
"[",
"]",
"=",
"$",
"foreignEntities",
"->",
"add",
"(",
"$",
"otherReference",
"->",
"getRelation",
"(",
")",
")",
";",
"$",
"foreignEntityReference",
"=",
"$",
"otherReference",
";",
"}",
"}",
"// have we a link?",
"if",
"(",
"$",
"foreignEntities",
")",
"{",
"$",
"sourceEntity",
"=",
"$",
"this",
"->",
"getEntityName",
"(",
")",
";",
"$",
"linkEntity",
"=",
"$",
"otherHalfofPrimaryKey",
"->",
"getRelation",
"(",
")",
"->",
"getEntityName",
"(",
")",
";",
"$",
"refSource",
"=",
"array",
"(",
"$",
"column",
"->",
"name",
",",
"$",
"reference",
"->",
"name",
")",
";",
"$",
"refForeign",
"=",
"array",
"(",
"$",
"otherHalfofPrimaryKey",
"->",
"name",
",",
"$",
"foreignEntityReference",
"->",
"name",
")",
";",
"// get columns and look for a ranking columns",
"$",
"possibleRankingAttributes",
"=",
"$",
"otherHalfofPrimaryKey",
"->",
"getRelation",
"(",
")",
"->",
"getAttributes",
"(",
")",
";",
"$",
"possibleRankingAttributes",
"->",
"remove",
"(",
"$",
"otherHalfofPrimaryKey",
",",
"$",
"reference",
")",
";",
"$",
"sortColumn",
"=",
"null",
";",
"$",
"rankingRegex",
"=",
"\"/^{$otherHalfofPrimaryKey->name}_?(r|rank|ranking)$/i\"",
";",
"foreach",
"(",
"$",
"possibleRankingAttributes",
"as",
"$",
"ranking",
")",
"{",
"if",
"(",
"$",
"ranking",
"->",
"getType",
"(",
")",
"->",
"isNumeric",
"(",
")",
"and",
"preg_match",
"(",
"$",
"rankingRegex",
",",
"$",
"ranking",
"->",
"name",
")",
")",
"{",
"$",
"sortColumn",
"=",
"$",
"ranking",
"->",
"name",
";",
"break",
";",
"}",
"}",
"// sort foreignEntities, we want 'root' entity first then alphabetical",
"$",
"foreignEntities",
"=",
"$",
"foreignEntities",
"->",
"sort",
"(",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"isInherited",
"(",
")",
"and",
"!",
"$",
"b",
"->",
"isInherited",
"(",
")",
")",
"{",
"return",
"1",
";",
"}",
"return",
"$",
"a",
"->",
"getEntityName",
"(",
")",
"<",
"$",
"b",
"->",
"getEntityName",
"(",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getEntityName",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"links",
"[",
"$",
"linkEntity",
"]",
"=",
"new",
"Link",
"(",
"$",
"sourceEntity",
",",
"$",
"linkEntity",
",",
"array_values",
"(",
"$",
"foreignEntities",
")",
",",
"$",
"refSource",
",",
"$",
"refForeign",
",",
"$",
"sortColumn",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"links",
";",
"}"
] | Get array of links to this table
@return array | [
"Get",
"array",
"of",
"links",
"to",
"this",
"table"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgClass.php#L172-L276 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgClass.php | PgClass.getAttributes | public function getAttributes( $includeParents = true )
{
if( !$this->columns ) {
$this->columns = $this->catalog->pgAttributes->findByAttrelid( $this->oid )->sortByAttnum();
}
$output = $this->columns->copy();
// include parents
if( !$includeParents ) {
$output->filter(
function($attribute){
return !$attribute->isInherited();
}
);
}
return $output;
} | php | public function getAttributes( $includeParents = true )
{
if( !$this->columns ) {
$this->columns = $this->catalog->pgAttributes->findByAttrelid( $this->oid )->sortByAttnum();
}
$output = $this->columns->copy();
// include parents
if( !$includeParents ) {
$output->filter(
function($attribute){
return !$attribute->isInherited();
}
);
}
return $output;
} | [
"public",
"function",
"getAttributes",
"(",
"$",
"includeParents",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"columns",
")",
"{",
"$",
"this",
"->",
"columns",
"=",
"$",
"this",
"->",
"catalog",
"->",
"pgAttributes",
"->",
"findByAttrelid",
"(",
"$",
"this",
"->",
"oid",
")",
"->",
"sortByAttnum",
"(",
")",
";",
"}",
"$",
"output",
"=",
"$",
"this",
"->",
"columns",
"->",
"copy",
"(",
")",
";",
"// include parents",
"if",
"(",
"!",
"$",
"includeParents",
")",
"{",
"$",
"output",
"->",
"filter",
"(",
"function",
"(",
"$",
"attribute",
")",
"{",
"return",
"!",
"$",
"attribute",
"->",
"isInherited",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Get all columns on this relation
@return Container | [
"Get",
"all",
"columns",
"on",
"this",
"relation"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgClass.php#L326-L344 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgClass.php | PgClass.isLogTable | public function isLogTable( $default = false )
{
$tags = $this->getTags();
if( array_key_exists( 'isLogTable', $tags ) ) {
return boolval( $tags['isLogTable'] );
} elseif( array_key_exists( 'logging', $tags ) ) {
return true;
}
return (bool) $default;
} | php | public function isLogTable( $default = false )
{
$tags = $this->getTags();
if( array_key_exists( 'isLogTable', $tags ) ) {
return boolval( $tags['isLogTable'] );
} elseif( array_key_exists( 'logging', $tags ) ) {
return true;
}
return (bool) $default;
} | [
"public",
"function",
"isLogTable",
"(",
"$",
"default",
"=",
"false",
")",
"{",
"$",
"tags",
"=",
"$",
"this",
"->",
"getTags",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'isLogTable'",
",",
"$",
"tags",
")",
")",
"{",
"return",
"boolval",
"(",
"$",
"tags",
"[",
"'isLogTable'",
"]",
")",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"'logging'",
",",
"$",
"tags",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"default",
";",
"}"
] | Is this relation a logTable (ie, is it tagged logtable
@param bool The default value to return in the event of logTable status not defined
@return bool | [
"Is",
"this",
"relation",
"a",
"logTable",
"(",
"ie",
"is",
"it",
"tagged",
"logtable"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgClass.php#L378-L387 | train |
zhaoxianfang/tools | src/Symfony/Component/Config/Definition/Processor.php | Processor.normalizeConfig | public static function normalizeConfig($config, $key, $plural = null)
{
if (null === $plural) {
$plural = $key.'s';
}
if (isset($config[$plural])) {
return $config[$plural];
}
if (isset($config[$key])) {
if (is_string($config[$key]) || !is_int(key($config[$key]))) {
// only one
return array($config[$key]);
}
return $config[$key];
}
return array();
} | php | public static function normalizeConfig($config, $key, $plural = null)
{
if (null === $plural) {
$plural = $key.'s';
}
if (isset($config[$plural])) {
return $config[$plural];
}
if (isset($config[$key])) {
if (is_string($config[$key]) || !is_int(key($config[$key]))) {
// only one
return array($config[$key]);
}
return $config[$key];
}
return array();
} | [
"public",
"static",
"function",
"normalizeConfig",
"(",
"$",
"config",
",",
"$",
"key",
",",
"$",
"plural",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"plural",
")",
"{",
"$",
"plural",
"=",
"$",
"key",
".",
"'s'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"$",
"plural",
"]",
")",
")",
"{",
"return",
"$",
"config",
"[",
"$",
"plural",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
"||",
"!",
"is_int",
"(",
"key",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
")",
")",
"{",
"// only one",
"return",
"array",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"config",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Normalizes a configuration entry.
This method returns a normalize configuration array for a given key
to remove the differences due to the original format (YAML and XML mainly).
Here is an example.
The configuration in XML:
<twig:extension>twig.extension.foo</twig:extension>
<twig:extension>twig.extension.bar</twig:extension>
And the same configuration in YAML:
extensions: ['twig.extension.foo', 'twig.extension.bar']
@param array $config A config array
@param string $key The key to normalize
@param string $plural The plural form of the key if it is irregular
@return array | [
"Normalizes",
"a",
"configuration",
"entry",
"."
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/Config/Definition/Processor.php#L76-L96 | train |
libreworks/caridea-container | src/Builder.php | Builder.addProvider | public function addProvider(string $name, Provider $provider): self
{
$this->providers[$name] = $provider;
return $this;
} | php | public function addProvider(string $name, Provider $provider): self
{
$this->providers[$name] = $provider;
return $this;
} | [
"public",
"function",
"addProvider",
"(",
"string",
"$",
"name",
",",
"Provider",
"$",
"provider",
")",
":",
"self",
"{",
"$",
"this",
"->",
"providers",
"[",
"$",
"name",
"]",
"=",
"$",
"provider",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a new Provider.
This method exists only for completeness. You'd probably spend less
effort if you call `->eager`, `->lazy`, or `->proto`.
@param string $name The component name
@param \Caridea\Container\Provider $provider The provider
@return $this provides a fluent interface | [
"Adds",
"a",
"new",
"Provider",
"."
] | b93087ff5bf49f5885025da691575093335bfe8f | https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Builder.php#L50-L54 | train |
libreworks/caridea-container | src/Builder.php | Builder.eager | public function eager(string $name, string $type, $factory): self
{
$provider = new Provider($type, $factory);
$this->eager[] = $name;
return $this->addProvider($name, $provider);
} | php | public function eager(string $name, string $type, $factory): self
{
$provider = new Provider($type, $factory);
$this->eager[] = $name;
return $this->addProvider($name, $provider);
} | [
"public",
"function",
"eager",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"type",
",",
"$",
"factory",
")",
":",
"self",
"{",
"$",
"provider",
"=",
"new",
"Provider",
"(",
"$",
"type",
",",
"$",
"factory",
")",
";",
"$",
"this",
"->",
"eager",
"[",
"]",
"=",
"$",
"name",
";",
"return",
"$",
"this",
"->",
"addProvider",
"(",
"$",
"name",
",",
"$",
"provider",
")",
";",
"}"
] | Adds a singleton component to be instantiated after the container is.
```php
$builder->eager('foobar', 'Acme\Mail\Service', function($c) {
return new \Acme\Mail\Service($c['dependency']);
});
```
@param string $name The component name
@param string $type The class name of the component
@param object $factory A `Closure` or class with an `__invoke` method to return the component
@return $this provides a fluent interface | [
"Adds",
"a",
"singleton",
"component",
"to",
"be",
"instantiated",
"after",
"the",
"container",
"is",
"."
] | b93087ff5bf49f5885025da691575093335bfe8f | https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Builder.php#L70-L75 | train |
libreworks/caridea-container | src/Builder.php | Builder.lazy | public function lazy(string $name, string $type, $factory): self
{
return $this->addProvider($name, new Provider($type, $factory));
} | php | public function lazy(string $name, string $type, $factory): self
{
return $this->addProvider($name, new Provider($type, $factory));
} | [
"public",
"function",
"lazy",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"type",
",",
"$",
"factory",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addProvider",
"(",
"$",
"name",
",",
"new",
"Provider",
"(",
"$",
"type",
",",
"$",
"factory",
")",
")",
";",
"}"
] | Adds a singleton component to be instantiated on demand.
```php
$builder->lazy('foobar', 'Acme\Mail\Service', function($c) {
return new \Acme\Mail\Service($c['dependency']);
});
```
@param string $name The component name
@param string $type The class name of the component
@param object $factory A `Closure` or class with an `__invoke` method to return the component
@return $this provides a fluent interface | [
"Adds",
"a",
"singleton",
"component",
"to",
"be",
"instantiated",
"on",
"demand",
"."
] | b93087ff5bf49f5885025da691575093335bfe8f | https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Builder.php#L91-L94 | train |
libreworks/caridea-container | src/Builder.php | Builder.proto | public function proto(string $name, string $type, $factory): self
{
return $this->addProvider($name, new Provider($type, $factory, false));
} | php | public function proto(string $name, string $type, $factory): self
{
return $this->addProvider($name, new Provider($type, $factory, false));
} | [
"public",
"function",
"proto",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"type",
",",
"$",
"factory",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addProvider",
"(",
"$",
"name",
",",
"new",
"Provider",
"(",
"$",
"type",
",",
"$",
"factory",
",",
"false",
")",
")",
";",
"}"
] | Adds a component that provides a new instance each time it's instantiated.
```php
$builder->lazy('objectStorage', 'SplObjectStorage', function($c) {
return new \SplObjectStorage();
});
```
@param string $name The component name
@param string $type The class name of the component
@param object $factory A `Closure` or class with an `__invoke` method to return the component
@return $this provides a fluent interface | [
"Adds",
"a",
"component",
"that",
"provides",
"a",
"new",
"instance",
"each",
"time",
"it",
"s",
"instantiated",
"."
] | b93087ff5bf49f5885025da691575093335bfe8f | https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Builder.php#L110-L113 | train |
libreworks/caridea-container | src/Builder.php | Builder.build | public function build(Container $parent = null): Objects
{
$container = new Objects($this->providers, $parent);
if (!empty($this->eager)) {
foreach ($this->eager as $v) {
$container->get($v);
}
}
$this->providers = [];
$this->eager = [];
return $container;
} | php | public function build(Container $parent = null): Objects
{
$container = new Objects($this->providers, $parent);
if (!empty($this->eager)) {
foreach ($this->eager as $v) {
$container->get($v);
}
}
$this->providers = [];
$this->eager = [];
return $container;
} | [
"public",
"function",
"build",
"(",
"Container",
"$",
"parent",
"=",
"null",
")",
":",
"Objects",
"{",
"$",
"container",
"=",
"new",
"Objects",
"(",
"$",
"this",
"->",
"providers",
",",
"$",
"parent",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"eager",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"eager",
"as",
"$",
"v",
")",
"{",
"$",
"container",
"->",
"get",
"(",
"$",
"v",
")",
";",
"}",
"}",
"$",
"this",
"->",
"providers",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"eager",
"=",
"[",
"]",
";",
"return",
"$",
"container",
";",
"}"
] | Builds a container using the settings called.
Any *eager* components will be instantiated at this time.
When this method is called, this builder is reset to its default state.
@param Container $parent An optional parent container
@return Objects The constructed `Objects` container | [
"Builds",
"a",
"container",
"using",
"the",
"settings",
"called",
"."
] | b93087ff5bf49f5885025da691575093335bfe8f | https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Builder.php#L125-L136 | train |
locomotivemtl/charcoal-config | src/Charcoal/Config/ConfigurableTrait.php | ConfigurableTrait.setConfig | public function setConfig($config)
{
if (is_string($config)) {
// Treat the parameter as a filepath
$this->config = $this->createConfig($config);
} elseif (is_array($config)) {
$this->config = $this->createConfig($config);
} elseif ($config instanceof ConfigInterface) {
$this->config = $config;
} else {
throw new InvalidArgumentException(sprintf(
'Configset must be an associative array, a file path, or an instance of %s',
ConfigInterface::class
));
}
return $this;
} | php | public function setConfig($config)
{
if (is_string($config)) {
// Treat the parameter as a filepath
$this->config = $this->createConfig($config);
} elseif (is_array($config)) {
$this->config = $this->createConfig($config);
} elseif ($config instanceof ConfigInterface) {
$this->config = $config;
} else {
throw new InvalidArgumentException(sprintf(
'Configset must be an associative array, a file path, or an instance of %s',
ConfigInterface::class
));
}
return $this;
} | [
"public",
"function",
"setConfig",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"// Treat the parameter as a filepath",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"createConfig",
"(",
"$",
"config",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"createConfig",
"(",
"$",
"config",
")",
";",
"}",
"elseif",
"(",
"$",
"config",
"instanceof",
"ConfigInterface",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Configset must be an associative array, a file path, or an instance of %s'",
",",
"ConfigInterface",
"::",
"class",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the object's configuration container.
@param mixed $config The Config object, datamap, or filepath.
@throws InvalidArgumentException If the parameter is invalid.
@return self Chainable | [
"Sets",
"the",
"object",
"s",
"configuration",
"container",
"."
] | 722b34955360c287dea8fffb3b5491866ce5f6cb | https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/ConfigurableTrait.php#L28-L45 | train |
locomotivemtl/charcoal-config | src/Charcoal/Config/ConfigurableTrait.php | ConfigurableTrait.config | public function config($key = null, $default = null)
{
if ($this->config === null) {
$this->config = $this->createConfig();
}
if ($key !== null) {
if ($this->config->has($key)) {
return $this->config->get($key);
} elseif (!is_string($default) && is_callable($default)) {
return $default();
} else {
return $default;
}
}
return $this->config;
} | php | public function config($key = null, $default = null)
{
if ($this->config === null) {
$this->config = $this->createConfig();
}
if ($key !== null) {
if ($this->config->has($key)) {
return $this->config->get($key);
} elseif (!is_string($default) && is_callable($default)) {
return $default();
} else {
return $default;
}
}
return $this->config;
} | [
"public",
"function",
"config",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"createConfig",
"(",
")",
";",
"}",
"if",
"(",
"$",
"key",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"elseif",
"(",
"!",
"is_string",
"(",
"$",
"default",
")",
"&&",
"is_callable",
"(",
"$",
"default",
")",
")",
"{",
"return",
"$",
"default",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"config",
";",
"}"
] | Gets the object's configuration container or a specific key from the container.
@param string|null $key If provided, the data key to retrieve.
@param mixed $default The fallback value to return if $key does not exist.
@return mixed If $key is NULL, the Config object is returned.
If $key is given, its value on the Config object is returned.
If the value of $key is NULL, the value of $default is returned. | [
"Gets",
"the",
"object",
"s",
"configuration",
"container",
"or",
"a",
"specific",
"key",
"from",
"the",
"container",
"."
] | 722b34955360c287dea8fffb3b5491866ce5f6cb | https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/ConfigurableTrait.php#L56-L73 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/caching/stores/LocalCacheStore.php | LocalCacheStore.getData | protected function getData($key)
{
$cacheKey = $this->key($key);
return array_key_exists($cacheKey, $this->cache)?$this->cache[$this->key($key)]:false;
} | php | protected function getData($key)
{
$cacheKey = $this->key($key);
return array_key_exists($cacheKey, $this->cache)?$this->cache[$this->key($key)]:false;
} | [
"protected",
"function",
"getData",
"(",
"$",
"key",
")",
"{",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"key",
"(",
"$",
"key",
")",
";",
"return",
"array_key_exists",
"(",
"$",
"cacheKey",
",",
"$",
"this",
"->",
"cache",
")",
"?",
"$",
"this",
"->",
"cache",
"[",
"$",
"this",
"->",
"key",
"(",
"$",
"key",
")",
"]",
":",
"false",
";",
"}"
] | Performs a fetch of our data from the cache without logging in the logger.
That allows this method to be used in other functions.
@param string $key The key to fetch
@return mixed Data in this->storageFormat format or FALSE if data is invalid | [
"Performs",
"a",
"fetch",
"of",
"our",
"data",
"from",
"the",
"cache",
"without",
"logging",
"in",
"the",
"logger",
".",
"That",
"allows",
"this",
"method",
"to",
"be",
"used",
"in",
"other",
"functions",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/LocalCacheStore.php#L72-L76 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Url.php | Url.getPort | public function getPort()
{
if ($this->port) {
return $this->port;
} elseif (isset(self::$defaultPorts[$this->scheme])) {
return self::$defaultPorts[$this->scheme];
}
return null;
} | php | public function getPort()
{
if ($this->port) {
return $this->port;
} elseif (isset(self::$defaultPorts[$this->scheme])) {
return self::$defaultPorts[$this->scheme];
}
return null;
} | [
"public",
"function",
"getPort",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"port",
")",
"{",
"return",
"$",
"this",
"->",
"port",
";",
"}",
"elseif",
"(",
"isset",
"(",
"self",
"::",
"$",
"defaultPorts",
"[",
"$",
"this",
"->",
"scheme",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"defaultPorts",
"[",
"$",
"this",
"->",
"scheme",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Get the port part of the URl.
If no port was set, this method will return the default port for the
scheme of the URI.
@return int|null | [
"Get",
"the",
"port",
"part",
"of",
"the",
"URl",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Url.php#L273-L282 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Url.php | Url.combine | public function combine($url)
{
$url = static::fromString($url);
// Use the more absolute URL as the base URL
if (!$this->isAbsolute() && $url->isAbsolute()) {
$url = $url->combine($this);
}
$parts = $url->getParts();
// Passing a URL with a scheme overrides everything
if ($parts['scheme']) {
return new static(
$parts['scheme'],
$parts['host'],
$parts['user'],
$parts['pass'],
$parts['port'],
$parts['path'],
clone $parts['query'],
$parts['fragment']
);
}
// Setting a host overrides the entire rest of the URL
if ($parts['host']) {
return new static(
$this->scheme,
$parts['host'],
$parts['user'],
$parts['pass'],
$parts['port'],
$parts['path'],
clone $parts['query'],
$parts['fragment']
);
}
if (!$parts['path'] && $parts['path'] !== '0') {
// The relative URL has no path, so check if it is just a query
$path = $this->path ?: '';
$query = count($parts['query']) ? $parts['query'] : $this->query;
} else {
$query = $parts['query'];
if ($parts['path'][0] == '/' || !$this->path) {
// Overwrite the existing path if the rel path starts with "/"
$path = $parts['path'];
} else {
// If the relative URL does not have a path or the base URL
// path does not end in a "/" then overwrite the existing path
// up to the last "/"
$path = substr($this->path, 0, strrpos($this->path, '/') + 1) . $parts['path'];
}
}
$result = new self(
$this->scheme,
$this->host,
$this->username,
$this->password,
$this->port,
$path,
clone $query,
$parts['fragment']
);
if ($path) {
$result->removeDotSegments();
}
return $result;
} | php | public function combine($url)
{
$url = static::fromString($url);
// Use the more absolute URL as the base URL
if (!$this->isAbsolute() && $url->isAbsolute()) {
$url = $url->combine($this);
}
$parts = $url->getParts();
// Passing a URL with a scheme overrides everything
if ($parts['scheme']) {
return new static(
$parts['scheme'],
$parts['host'],
$parts['user'],
$parts['pass'],
$parts['port'],
$parts['path'],
clone $parts['query'],
$parts['fragment']
);
}
// Setting a host overrides the entire rest of the URL
if ($parts['host']) {
return new static(
$this->scheme,
$parts['host'],
$parts['user'],
$parts['pass'],
$parts['port'],
$parts['path'],
clone $parts['query'],
$parts['fragment']
);
}
if (!$parts['path'] && $parts['path'] !== '0') {
// The relative URL has no path, so check if it is just a query
$path = $this->path ?: '';
$query = count($parts['query']) ? $parts['query'] : $this->query;
} else {
$query = $parts['query'];
if ($parts['path'][0] == '/' || !$this->path) {
// Overwrite the existing path if the rel path starts with "/"
$path = $parts['path'];
} else {
// If the relative URL does not have a path or the base URL
// path does not end in a "/" then overwrite the existing path
// up to the last "/"
$path = substr($this->path, 0, strrpos($this->path, '/') + 1) . $parts['path'];
}
}
$result = new self(
$this->scheme,
$this->host,
$this->username,
$this->password,
$this->port,
$path,
clone $query,
$parts['fragment']
);
if ($path) {
$result->removeDotSegments();
}
return $result;
} | [
"public",
"function",
"combine",
"(",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"static",
"::",
"fromString",
"(",
"$",
"url",
")",
";",
"// Use the more absolute URL as the base URL",
"if",
"(",
"!",
"$",
"this",
"->",
"isAbsolute",
"(",
")",
"&&",
"$",
"url",
"->",
"isAbsolute",
"(",
")",
")",
"{",
"$",
"url",
"=",
"$",
"url",
"->",
"combine",
"(",
"$",
"this",
")",
";",
"}",
"$",
"parts",
"=",
"$",
"url",
"->",
"getParts",
"(",
")",
";",
"// Passing a URL with a scheme overrides everything",
"if",
"(",
"$",
"parts",
"[",
"'scheme'",
"]",
")",
"{",
"return",
"new",
"static",
"(",
"$",
"parts",
"[",
"'scheme'",
"]",
",",
"$",
"parts",
"[",
"'host'",
"]",
",",
"$",
"parts",
"[",
"'user'",
"]",
",",
"$",
"parts",
"[",
"'pass'",
"]",
",",
"$",
"parts",
"[",
"'port'",
"]",
",",
"$",
"parts",
"[",
"'path'",
"]",
",",
"clone",
"$",
"parts",
"[",
"'query'",
"]",
",",
"$",
"parts",
"[",
"'fragment'",
"]",
")",
";",
"}",
"// Setting a host overrides the entire rest of the URL",
"if",
"(",
"$",
"parts",
"[",
"'host'",
"]",
")",
"{",
"return",
"new",
"static",
"(",
"$",
"this",
"->",
"scheme",
",",
"$",
"parts",
"[",
"'host'",
"]",
",",
"$",
"parts",
"[",
"'user'",
"]",
",",
"$",
"parts",
"[",
"'pass'",
"]",
",",
"$",
"parts",
"[",
"'port'",
"]",
",",
"$",
"parts",
"[",
"'path'",
"]",
",",
"clone",
"$",
"parts",
"[",
"'query'",
"]",
",",
"$",
"parts",
"[",
"'fragment'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"parts",
"[",
"'path'",
"]",
"&&",
"$",
"parts",
"[",
"'path'",
"]",
"!==",
"'0'",
")",
"{",
"// The relative URL has no path, so check if it is just a query",
"$",
"path",
"=",
"$",
"this",
"->",
"path",
"?",
":",
"''",
";",
"$",
"query",
"=",
"count",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
"?",
"$",
"parts",
"[",
"'query'",
"]",
":",
"$",
"this",
"->",
"query",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"$",
"parts",
"[",
"'query'",
"]",
";",
"if",
"(",
"$",
"parts",
"[",
"'path'",
"]",
"[",
"0",
"]",
"==",
"'/'",
"||",
"!",
"$",
"this",
"->",
"path",
")",
"{",
"// Overwrite the existing path if the rel path starts with \"/\"",
"$",
"path",
"=",
"$",
"parts",
"[",
"'path'",
"]",
";",
"}",
"else",
"{",
"// If the relative URL does not have a path or the base URL",
"// path does not end in a \"/\" then overwrite the existing path",
"// up to the last \"/\"",
"$",
"path",
"=",
"substr",
"(",
"$",
"this",
"->",
"path",
",",
"0",
",",
"strrpos",
"(",
"$",
"this",
"->",
"path",
",",
"'/'",
")",
"+",
"1",
")",
".",
"$",
"parts",
"[",
"'path'",
"]",
";",
"}",
"}",
"$",
"result",
"=",
"new",
"self",
"(",
"$",
"this",
"->",
"scheme",
",",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"this",
"->",
"port",
",",
"$",
"path",
",",
"clone",
"$",
"query",
",",
"$",
"parts",
"[",
"'fragment'",
"]",
")",
";",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"result",
"->",
"removeDotSegments",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Combine the URL with another URL and return a new URL instance.
Follows the rules specific in RFC 3986 section 5.4.
@param string $url Relative URL to combine with
@return Url
@throws \InvalidArgumentException
@link http://tools.ietf.org/html/rfc3986#section-5.4 | [
"Combine",
"the",
"URL",
"with",
"another",
"URL",
"and",
"return",
"a",
"new",
"URL",
"instance",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Url.php#L519-L591 | train |
cubicmushroom/valueobjects | src/Person/Name.php | Name.fromNative | public static function fromNative()
{
$args = func_get_args();
$firstName = new StringLiteral($args[0]);
$middleName = new StringLiteral($args[1]);
$lastName = new StringLiteral($args[2]);
return new self($firstName, $middleName, $lastName);
} | php | public static function fromNative()
{
$args = func_get_args();
$firstName = new StringLiteral($args[0]);
$middleName = new StringLiteral($args[1]);
$lastName = new StringLiteral($args[2]);
return new self($firstName, $middleName, $lastName);
} | [
"public",
"static",
"function",
"fromNative",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"firstName",
"=",
"new",
"StringLiteral",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"$",
"middleName",
"=",
"new",
"StringLiteral",
"(",
"$",
"args",
"[",
"1",
"]",
")",
";",
"$",
"lastName",
"=",
"new",
"StringLiteral",
"(",
"$",
"args",
"[",
"2",
"]",
")",
";",
"return",
"new",
"self",
"(",
"$",
"firstName",
",",
"$",
"middleName",
",",
"$",
"lastName",
")",
";",
"}"
] | Returns a Name objects form PHP native values
@param string $first_name
@param string $middle_name
@param string $last_name
@return Name | [
"Returns",
"a",
"Name",
"objects",
"form",
"PHP",
"native",
"values"
] | 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Person/Name.php#L40-L49 | train |
cubicmushroom/valueobjects | src/Person/Name.php | Name.sameValueAs | public function sameValueAs(ValueObjectInterface $name)
{
if (false === Util::classEquals($this, $name)) {
return false;
}
return $this->getFullName() == $name->getFullName();
} | php | public function sameValueAs(ValueObjectInterface $name)
{
if (false === Util::classEquals($this, $name)) {
return false;
}
return $this->getFullName() == $name->getFullName();
} | [
"public",
"function",
"sameValueAs",
"(",
"ValueObjectInterface",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"===",
"Util",
"::",
"classEquals",
"(",
"$",
"this",
",",
"$",
"name",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"getFullName",
"(",
")",
"==",
"$",
"name",
"->",
"getFullName",
"(",
")",
";",
"}"
] | Tells whether two names are equal by comparing their values
@param ValueObjectInterface $name
@return bool | [
"Tells",
"whether",
"two",
"names",
"are",
"equal",
"by",
"comparing",
"their",
"values"
] | 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Person/Name.php#L117-L124 | train |
Stinger-Soft/PhpCommons | src/StingerSoft/PhpCommons/Arrays/Utils.php | Utils.insertElement | public static function insertElement(array $array, $element, $position) {
$res = array_slice($array, 0, $position, true);
if(is_array($element)) {
$res = array_merge($res, $element);
} else {
array_push($res, $element);
}
$res = array_merge($res, array_slice($array, $position, count($array) - 1, true));
return $res;
} | php | public static function insertElement(array $array, $element, $position) {
$res = array_slice($array, 0, $position, true);
if(is_array($element)) {
$res = array_merge($res, $element);
} else {
array_push($res, $element);
}
$res = array_merge($res, array_slice($array, $position, count($array) - 1, true));
return $res;
} | [
"public",
"static",
"function",
"insertElement",
"(",
"array",
"$",
"array",
",",
"$",
"element",
",",
"$",
"position",
")",
"{",
"$",
"res",
"=",
"array_slice",
"(",
"$",
"array",
",",
"0",
",",
"$",
"position",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"element",
")",
")",
"{",
"$",
"res",
"=",
"array_merge",
"(",
"$",
"res",
",",
"$",
"element",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"res",
",",
"$",
"element",
")",
";",
"}",
"$",
"res",
"=",
"array_merge",
"(",
"$",
"res",
",",
"array_slice",
"(",
"$",
"array",
",",
"$",
"position",
",",
"count",
"(",
"$",
"array",
")",
"-",
"1",
",",
"true",
")",
")",
";",
"return",
"$",
"res",
";",
"}"
] | Adds a given element into the array on the given position without replacing the old entry
@param array $array
The array the element should be insert into
@param mixed $element
The element to insert
@param integer $position
The position to insert the element into the array.
If this value is greater than the array size, the element will be put at the end of the array
@return array | [
"Adds",
"a",
"given",
"element",
"into",
"the",
"array",
"on",
"the",
"given",
"position",
"without",
"replacing",
"the",
"old",
"entry"
] | e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b | https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/Arrays/Utils.php#L31-L43 | train |
Stinger-Soft/PhpCommons | src/StingerSoft/PhpCommons/Arrays/Utils.php | Utils.getPrevKey | public static function getPrevKey($key, array $array) {
$keys = array_keys($array);
$found_index = array_search($key, $keys);
if($found_index === false || $found_index === 0)
return false;
return $keys[$found_index - 1];
} | php | public static function getPrevKey($key, array $array) {
$keys = array_keys($array);
$found_index = array_search($key, $keys);
if($found_index === false || $found_index === 0)
return false;
return $keys[$found_index - 1];
} | [
"public",
"static",
"function",
"getPrevKey",
"(",
"$",
"key",
",",
"array",
"$",
"array",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"array",
")",
";",
"$",
"found_index",
"=",
"array_search",
"(",
"$",
"key",
",",
"$",
"keys",
")",
";",
"if",
"(",
"$",
"found_index",
"===",
"false",
"||",
"$",
"found_index",
"===",
"0",
")",
"return",
"false",
";",
"return",
"$",
"keys",
"[",
"$",
"found_index",
"-",
"1",
"]",
";",
"}"
] | Returns the previous key from an array
@param mixed $key
@param array $array
@return boolean|mixed previous key or false if no previous key is available | [
"Returns",
"the",
"previous",
"key",
"from",
"an",
"array"
] | e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b | https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/Arrays/Utils.php#L80-L86 | train |
Stinger-Soft/PhpCommons | src/StingerSoft/PhpCommons/Arrays/Utils.php | Utils.getNextKey | public static function getNextKey($key, array $array) {
$keys = array_keys($array);
$found_index = array_search($key, $keys);
if($found_index === false || $found_index + 1 === count($keys))
return false;
return $keys[$found_index + 1];
} | php | public static function getNextKey($key, array $array) {
$keys = array_keys($array);
$found_index = array_search($key, $keys);
if($found_index === false || $found_index + 1 === count($keys))
return false;
return $keys[$found_index + 1];
} | [
"public",
"static",
"function",
"getNextKey",
"(",
"$",
"key",
",",
"array",
"$",
"array",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"array",
")",
";",
"$",
"found_index",
"=",
"array_search",
"(",
"$",
"key",
",",
"$",
"keys",
")",
";",
"if",
"(",
"$",
"found_index",
"===",
"false",
"||",
"$",
"found_index",
"+",
"1",
"===",
"count",
"(",
"$",
"keys",
")",
")",
"return",
"false",
";",
"return",
"$",
"keys",
"[",
"$",
"found_index",
"+",
"1",
"]",
";",
"}"
] | Returns the next key from an array
@param mixed $key
@param array $array
@return boolean|mixed next key or false if no next key is available | [
"Returns",
"the",
"next",
"key",
"from",
"an",
"array"
] | e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b | https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/Arrays/Utils.php#L95-L101 | train |
Eden-PHP/Validation | src/Index.php | Index.lengthGreaterThan | public function lengthGreaterThan($number)
{
//argument 1 must be numeric
Argument::i()->test(1, 'numeric');
return strlen((string)$this->value) > (float)$number;
} | php | public function lengthGreaterThan($number)
{
//argument 1 must be numeric
Argument::i()->test(1, 'numeric');
return strlen((string)$this->value) > (float)$number;
} | [
"public",
"function",
"lengthGreaterThan",
"(",
"$",
"number",
")",
"{",
"//argument 1 must be numeric",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"1",
",",
"'numeric'",
")",
";",
"return",
"strlen",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"value",
")",
">",
"(",
"float",
")",
"$",
"number",
";",
"}"
] | Returns true if the value length is greater than the passed argument
@param *int $number Number to test against
@return bool | [
"Returns",
"true",
"if",
"the",
"value",
"length",
"is",
"greater",
"than",
"the",
"passed",
"argument"
] | 480fd3b745a1d5feb432cf1cb427a7fb606d87c4 | https://github.com/Eden-PHP/Validation/blob/480fd3b745a1d5feb432cf1cb427a7fb606d87c4/src/Index.php#L191-L197 | train |
Eden-PHP/Validation | src/Index.php | Index.isSoftBool | protected function isSoftBool($string)
{
if (!is_scalar($string) || $string === null) {
return false;
}
$string = (string) $string;
return $string == '0' || $string == '1';
} | php | protected function isSoftBool($string)
{
if (!is_scalar($string) || $string === null) {
return false;
}
$string = (string) $string;
return $string == '0' || $string == '1';
} | [
"protected",
"function",
"isSoftBool",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"string",
")",
"||",
"$",
"string",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"string",
"=",
"(",
"string",
")",
"$",
"string",
";",
"return",
"$",
"string",
"==",
"'0'",
"||",
"$",
"string",
"==",
"'1'",
";",
"}"
] | Test if 0 or 1 or string 1 oe 0
@param *scalar $string Value to test
@return bool | [
"Test",
"if",
"0",
"or",
"1",
"or",
"string",
"1",
"oe",
"0"
] | 480fd3b745a1d5feb432cf1cb427a7fb606d87c4 | https://github.com/Eden-PHP/Validation/blob/480fd3b745a1d5feb432cf1cb427a7fb606d87c4/src/Index.php#L396-L405 | train |
Eden-PHP/Validation | src/Index.php | Index.isSoftFloat | protected function isSoftFloat($number)
{
if (!is_scalar($number) || $number === null) {
return false;
}
$number = (string) $number;
return preg_match('/^[-+]?(\d*)?\.\d+$/', $number);
} | php | protected function isSoftFloat($number)
{
if (!is_scalar($number) || $number === null) {
return false;
}
$number = (string) $number;
return preg_match('/^[-+]?(\d*)?\.\d+$/', $number);
} | [
"protected",
"function",
"isSoftFloat",
"(",
"$",
"number",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"number",
")",
"||",
"$",
"number",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"number",
"=",
"(",
"string",
")",
"$",
"number",
";",
"return",
"preg_match",
"(",
"'/^[-+]?(\\d*)?\\.\\d+$/'",
",",
"$",
"number",
")",
";",
"}"
] | Test if float or string float
@param *scalar $number Value to test
@return bool | [
"Test",
"if",
"float",
"or",
"string",
"float"
] | 480fd3b745a1d5feb432cf1cb427a7fb606d87c4 | https://github.com/Eden-PHP/Validation/blob/480fd3b745a1d5feb432cf1cb427a7fb606d87c4/src/Index.php#L414-L423 | train |
Eden-PHP/Validation | src/Index.php | Index.isSoftInteger | protected function isSoftInteger($number)
{
if (!is_scalar($number) || $number === null) {
return false;
}
$number = (string) $number;
return preg_match('/^[-+]?\d+$/', $number);
} | php | protected function isSoftInteger($number)
{
if (!is_scalar($number) || $number === null) {
return false;
}
$number = (string) $number;
return preg_match('/^[-+]?\d+$/', $number);
} | [
"protected",
"function",
"isSoftInteger",
"(",
"$",
"number",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"number",
")",
"||",
"$",
"number",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"number",
"=",
"(",
"string",
")",
"$",
"number",
";",
"return",
"preg_match",
"(",
"'/^[-+]?\\d+$/'",
",",
"$",
"number",
")",
";",
"}"
] | Test if integer or string integer
@param *scalar $number Value to test
@return bool | [
"Test",
"if",
"integer",
"or",
"string",
"integer"
] | 480fd3b745a1d5feb432cf1cb427a7fb606d87c4 | https://github.com/Eden-PHP/Validation/blob/480fd3b745a1d5feb432cf1cb427a7fb606d87c4/src/Index.php#L432-L441 | train |
Eden-PHP/Validation | src/Index.php | Index.isSoftSmall | protected function isSoftSmall($value)
{
if (!is_scalar($value) || $value === null) {
return false;
}
$value = (float) $value;
return $value >= 0 && $value <= 9;
} | php | protected function isSoftSmall($value)
{
if (!is_scalar($value) || $value === null) {
return false;
}
$value = (float) $value;
return $value >= 0 && $value <= 9;
} | [
"protected",
"function",
"isSoftSmall",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"return",
"$",
"value",
">=",
"0",
"&&",
"$",
"value",
"<=",
"9",
";",
"}"
] | Returns true if the value is between 0 and 9
@param *scalar $value Value to test
@return bool | [
"Returns",
"true",
"if",
"the",
"value",
"is",
"between",
"0",
"and",
"9"
] | 480fd3b745a1d5feb432cf1cb427a7fb606d87c4 | https://github.com/Eden-PHP/Validation/blob/480fd3b745a1d5feb432cf1cb427a7fb606d87c4/src/Index.php#L450-L459 | train |
jabernardo/lollipop-php | Library/Utils/Collection.php | Collection.arrayMerge | static function arrayMerge() {
$output = [];
foreach(func_get_args() as $array) {
foreach($array as $key => $value) {
$output[$key] = isset($output[$key]) ?
array_merge($output[$key], $value) : $value;
}
}
return $output;
} | php | static function arrayMerge() {
$output = [];
foreach(func_get_args() as $array) {
foreach($array as $key => $value) {
$output[$key] = isset($output[$key]) ?
array_merge($output[$key], $value) : $value;
}
}
return $output;
} | [
"static",
"function",
"arrayMerge",
"(",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"output",
"[",
"$",
"key",
"]",
"=",
"isset",
"(",
"$",
"output",
"[",
"$",
"key",
"]",
")",
"?",
"array_merge",
"(",
"$",
"output",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
":",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Array merge including integers as key
@access public
@param array ...$args Arguments
@return array | [
"Array",
"merge",
"including",
"integers",
"as",
"key"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Utils/Collection.php#L22-L33 | train |
jabernardo/lollipop-php | Library/Utils/Collection.php | Collection.arrayGet | static function arrayGet(&$var, $key, $default = null) {
$toks = explode('.', $key);
for ($i = 0; $i < count($toks); $i++) {
$var = &$var[$toks[$i]];
}
return is_array($var) || is_object($var)
? json_decode(json_encode($var))
: (is_null($var) && !is_null($default) ? $default : $var);
} | php | static function arrayGet(&$var, $key, $default = null) {
$toks = explode('.', $key);
for ($i = 0; $i < count($toks); $i++) {
$var = &$var[$toks[$i]];
}
return is_array($var) || is_object($var)
? json_decode(json_encode($var))
: (is_null($var) && !is_null($default) ? $default : $var);
} | [
"static",
"function",
"arrayGet",
"(",
"&",
"$",
"var",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"toks",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"toks",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"var",
"=",
"&",
"$",
"var",
"[",
"$",
"toks",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"return",
"is_array",
"(",
"$",
"var",
")",
"||",
"is_object",
"(",
"$",
"var",
")",
"?",
"json_decode",
"(",
"json_encode",
"(",
"$",
"var",
")",
")",
":",
"(",
"is_null",
"(",
"$",
"var",
")",
"&&",
"!",
"is_null",
"(",
"$",
"default",
")",
"?",
"$",
"default",
":",
"$",
"var",
")",
";",
"}"
] | Array get using dots to traverse keys
@example
$arr = ['test' => ['word' => 'hello']];
print_r(arrayGet($arr, 'test.word'));
@access public
@param array $var Local declared variable
@param string $key Key
@param mixed $default Default value if $key isn't existing
@return mixed | [
"Array",
"get",
"using",
"dots",
"to",
"traverse",
"keys"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Utils/Collection.php#L50-L60 | train |
jabernardo/lollipop-php | Library/Utils/Collection.php | Collection.arraySet | static function arraySet(&$var, $key, $val) {
$toks = explode('.', $key);
for ($i = 0; $i < count($toks); $i++) {
$var = &$var[$toks[$i]];
}
$var = $val;
} | php | static function arraySet(&$var, $key, $val) {
$toks = explode('.', $key);
for ($i = 0; $i < count($toks); $i++) {
$var = &$var[$toks[$i]];
}
$var = $val;
} | [
"static",
"function",
"arraySet",
"(",
"&",
"$",
"var",
",",
"$",
"key",
",",
"$",
"val",
")",
"{",
"$",
"toks",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"toks",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"var",
"=",
"&",
"$",
"var",
"[",
"$",
"toks",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"$",
"var",
"=",
"$",
"val",
";",
"}"
] | Set array key value using dots to traverse keys
@example
$arr = [];
arraySet($arr, 'sample.word', 'Hello');
@access public
@param array $var Local declared variable
@param string $key Array key
@param mixed $val Value
@return void | [
"Set",
"array",
"key",
"value",
"using",
"dots",
"to",
"traverse",
"keys"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Utils/Collection.php#L77-L85 | train |
jabernardo/lollipop-php | Library/Utils/Collection.php | Collection.arrayUnset | static function arrayUnset(&$var, $key) {
$toks = explode('.', $key);
$toks_len = count($toks);
$last = null;
for ($i = 0; $i < $toks_len - 1; $i++) {
$var = &$var[$toks[$i]];
}
if (isset($toks[$toks_len - 1])) {
$last = $toks[$toks_len - 1];
}
if ($last) unset($var[$last]);
} | php | static function arrayUnset(&$var, $key) {
$toks = explode('.', $key);
$toks_len = count($toks);
$last = null;
for ($i = 0; $i < $toks_len - 1; $i++) {
$var = &$var[$toks[$i]];
}
if (isset($toks[$toks_len - 1])) {
$last = $toks[$toks_len - 1];
}
if ($last) unset($var[$last]);
} | [
"static",
"function",
"arrayUnset",
"(",
"&",
"$",
"var",
",",
"$",
"key",
")",
"{",
"$",
"toks",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"toks_len",
"=",
"count",
"(",
"$",
"toks",
")",
";",
"$",
"last",
"=",
"null",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"toks_len",
"-",
"1",
";",
"$",
"i",
"++",
")",
"{",
"$",
"var",
"=",
"&",
"$",
"var",
"[",
"$",
"toks",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"toks",
"[",
"$",
"toks_len",
"-",
"1",
"]",
")",
")",
"{",
"$",
"last",
"=",
"$",
"toks",
"[",
"$",
"toks_len",
"-",
"1",
"]",
";",
"}",
"if",
"(",
"$",
"last",
")",
"unset",
"(",
"$",
"var",
"[",
"$",
"last",
"]",
")",
";",
"}"
] | Remove array key using dots to traverse keys
$arr = ['test' => ['word' => 'hello']];
arrayUnset($arr, 'sample.word');
@access public
@param array $var Local declared variable
@param string $key Array key
@param mixed $val Value
@return void | [
"Remove",
"array",
"key",
"using",
"dots",
"to",
"traverse",
"keys"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Utils/Collection.php#L100-L114 | train |
mtils/cmsable | src/Cmsable/View/FallbackFileViewFinder.php | FallbackFileViewFinder.fromOther | public static function fromOther(FileViewFinder $otherFinder){
$copy = new static($otherFinder->getFilesystem(),
$otherFinder->getPaths(),
$otherFinder->getExtensions());
if($otherFinder instanceof FallbackFileViewFinder){
$copy->setFallbackDir($otherFinder->getFallbackDir());
}
return $copy;
} | php | public static function fromOther(FileViewFinder $otherFinder){
$copy = new static($otherFinder->getFilesystem(),
$otherFinder->getPaths(),
$otherFinder->getExtensions());
if($otherFinder instanceof FallbackFileViewFinder){
$copy->setFallbackDir($otherFinder->getFallbackDir());
}
return $copy;
} | [
"public",
"static",
"function",
"fromOther",
"(",
"FileViewFinder",
"$",
"otherFinder",
")",
"{",
"$",
"copy",
"=",
"new",
"static",
"(",
"$",
"otherFinder",
"->",
"getFilesystem",
"(",
")",
",",
"$",
"otherFinder",
"->",
"getPaths",
"(",
")",
",",
"$",
"otherFinder",
"->",
"getExtensions",
"(",
")",
")",
";",
"if",
"(",
"$",
"otherFinder",
"instanceof",
"FallbackFileViewFinder",
")",
"{",
"$",
"copy",
"->",
"setFallbackDir",
"(",
"$",
"otherFinder",
"->",
"getFallbackDir",
"(",
")",
")",
";",
"}",
"return",
"$",
"copy",
";",
"}"
] | Copy a FileViewFinder to a FallbackFileViewFinder
@param \Illuminate\View\FileViewFinder $otherFinder
@return static | [
"Copy",
"a",
"FileViewFinder",
"to",
"a",
"FallbackFileViewFinder"
] | 03ae84ee3c7d46146f2a1cf687e5c29d6de4286d | https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/View/FallbackFileViewFinder.php#L160-L172 | train |
kambalabs/KmbDomain | src/KmbDomain/Service/GroupClassFactory.php | GroupClassFactory.createFromImportedData | public function createFromImportedData($name, $data)
{
$class = new GroupClass($name);
foreach ($data as $parameterName => $parameterData) {
$class->addParameter($this->getGroupParameterFactory()->createFromImportedData($parameterName, $parameterData));
}
return $class;
} | php | public function createFromImportedData($name, $data)
{
$class = new GroupClass($name);
foreach ($data as $parameterName => $parameterData) {
$class->addParameter($this->getGroupParameterFactory()->createFromImportedData($parameterName, $parameterData));
}
return $class;
} | [
"public",
"function",
"createFromImportedData",
"(",
"$",
"name",
",",
"$",
"data",
")",
"{",
"$",
"class",
"=",
"new",
"GroupClass",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"parameterName",
"=>",
"$",
"parameterData",
")",
"{",
"$",
"class",
"->",
"addParameter",
"(",
"$",
"this",
"->",
"getGroupParameterFactory",
"(",
")",
"->",
"createFromImportedData",
"(",
"$",
"parameterName",
",",
"$",
"parameterData",
")",
")",
";",
"}",
"return",
"$",
"class",
";",
"}"
] | Create GroupClass instance from imported data.
@param string $name
@param array $data
@return GroupClass | [
"Create",
"GroupClass",
"instance",
"from",
"imported",
"data",
"."
] | b1631bd936c6c6798076b51dfaebd706e1bdc8c2 | https://github.com/kambalabs/KmbDomain/blob/b1631bd936c6c6798076b51dfaebd706e1bdc8c2/src/KmbDomain/Service/GroupClassFactory.php#L37-L44 | train |
pharmonic/container | src/Container.php | Container.get | public function get($id)
{
if ($id instanceof \Closure) {
return $id($this);
}
if (!$this->has($id)) {
$service = $this->factory->create($id, $this);
$this->repository->set($id, $service);
}
return $this->repository->get($id);
} | php | public function get($id)
{
if ($id instanceof \Closure) {
return $id($this);
}
if (!$this->has($id)) {
$service = $this->factory->create($id, $this);
$this->repository->set($id, $service);
}
return $this->repository->get($id);
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"id",
"instanceof",
"\\",
"Closure",
")",
"{",
"return",
"$",
"id",
"(",
"$",
"this",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"factory",
"->",
"create",
"(",
"$",
"id",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"repository",
"->",
"set",
"(",
"$",
"id",
",",
"$",
"service",
")",
";",
"}",
"return",
"$",
"this",
"->",
"repository",
"->",
"get",
"(",
"$",
"id",
")",
";",
"}"
] | Get a service or params and create it first if it's not already defined.
@param int $id
@return mixed | [
"Get",
"a",
"service",
"or",
"params",
"and",
"create",
"it",
"first",
"if",
"it",
"s",
"not",
"already",
"defined",
"."
] | 100e6e1ab34d111da559fa50f40d5fef6dbb1ec3 | https://github.com/pharmonic/container/blob/100e6e1ab34d111da559fa50f40d5fef6dbb1ec3/src/Container.php#L30-L42 | train |
pharmonic/container | src/Container.php | Container.set | public function set($id, $service)
{
if (!$this->has($id)) {
$this->repository->set($id, $service);
}
} | php | public function set($id, $service)
{
if (!$this->has($id)) {
$this->repository->set($id, $service);
}
} | [
"public",
"function",
"set",
"(",
"$",
"id",
",",
"$",
"service",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"repository",
"->",
"set",
"(",
"$",
"id",
",",
"$",
"service",
")",
";",
"}",
"}"
] | Bypass factory and register a service directly into repository.
@param string $id
@param mixed $service | [
"Bypass",
"factory",
"and",
"register",
"a",
"service",
"directly",
"into",
"repository",
"."
] | 100e6e1ab34d111da559fa50f40d5fef6dbb1ec3 | https://github.com/pharmonic/container/blob/100e6e1ab34d111da559fa50f40d5fef6dbb1ec3/src/Container.php#L61-L66 | train |
koolkode/view-express | src/ExpressViewRenderer.php | ExpressViewRenderer.triggerContextBound | public function triggerContextBound(ExpressContext $context)
{
if($this->eventDispatcher)
{
$this->eventDispatcher->notify(new ExpressContextBoundEvent($context));
}
} | php | public function triggerContextBound(ExpressContext $context)
{
if($this->eventDispatcher)
{
$this->eventDispatcher->notify(new ExpressContextBoundEvent($context));
}
} | [
"public",
"function",
"triggerContextBound",
"(",
"ExpressContext",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"eventDispatcher",
")",
"{",
"$",
"this",
"->",
"eventDispatcher",
"->",
"notify",
"(",
"new",
"ExpressContextBoundEvent",
"(",
"$",
"context",
")",
")",
";",
"}",
"}"
] | Trigger the context-bound event for the given context.
@param ExpressContext $context | [
"Trigger",
"the",
"context",
"-",
"bound",
"event",
"for",
"the",
"given",
"context",
"."
] | a8ebe6f373b6bfe8b8818d6264535e8fe063a596 | https://github.com/koolkode/view-express/blob/a8ebe6f373b6bfe8b8818d6264535e8fe063a596/src/ExpressViewRenderer.php#L105-L111 | train |
koolkode/view-express | src/ExpressViewRenderer.php | ExpressViewRenderer.generateXmlSchemaBuilders | public function generateXmlSchemaBuilders()
{
$result = [];
foreach($this->helpers->findAll() as $key => $helper)
{
list($namespace, $name) = explode('>', $key, 2);
if(empty($result[$namespace]))
{
$result[$namespace] = new HelperXmlSchemaBuilder($namespace);
}
$result[$namespace]->addHelper($name, $helper);
}
return $result;
} | php | public function generateXmlSchemaBuilders()
{
$result = [];
foreach($this->helpers->findAll() as $key => $helper)
{
list($namespace, $name) = explode('>', $key, 2);
if(empty($result[$namespace]))
{
$result[$namespace] = new HelperXmlSchemaBuilder($namespace);
}
$result[$namespace]->addHelper($name, $helper);
}
return $result;
} | [
"public",
"function",
"generateXmlSchemaBuilders",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"helpers",
"->",
"findAll",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"helper",
")",
"{",
"list",
"(",
"$",
"namespace",
",",
"$",
"name",
")",
"=",
"explode",
"(",
"'>'",
",",
"$",
"key",
",",
"2",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"namespace",
"]",
"=",
"new",
"HelperXmlSchemaBuilder",
"(",
"$",
"namespace",
")",
";",
"}",
"$",
"result",
"[",
"$",
"namespace",
"]",
"->",
"addHelper",
"(",
"$",
"name",
",",
"$",
"helper",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Generate XML-schema builders for each registered view helper namespace.
@return array<string, HelperXmlSchemaBuilder> | [
"Generate",
"XML",
"-",
"schema",
"builders",
"for",
"each",
"registered",
"view",
"helper",
"namespace",
"."
] | a8ebe6f373b6bfe8b8818d6264535e8fe063a596 | https://github.com/koolkode/view-express/blob/a8ebe6f373b6bfe8b8818d6264535e8fe063a596/src/ExpressViewRenderer.php#L165-L182 | train |
bseddon/XPath20 | DOM/DOMSchemaElement.php | DOMSchemaElement.fromQName | public static function fromQName( $name )
{
$types = SchemaTypes::getInstance();
if ( $name instanceof QName )
{
// If prefix is empty try looking it up
if ( empty( $name->prefix ) )
{
$prefix = $types->getPrefixForNamespace( $name->namespaceURI );
if ( $prefix ) $name->prefix = $prefix;
}
$qname = "{$name->prefix}:{$name->localName}";
}
else if ( is_string( $name ) )
{
$qname = $name;
}
else
{
throw new \InvalidArgumentException( "$qname must be string or a QName instance" );
}
$element = $types->getElement( $qname );
if ( ! $element )
{
return null;
}
$result = new DOMSchemaElement();
$result->QualifiedName = $name;
$type = is_array( $element['types'][0] ) && isset( $element['types'][0]['parent'] )
? $element['types'][0]['parent']
: $element['types'][0];
// if ( is_array( $element['types'][0] ) )
// {
// $x = 1;
// }
$elementType = is_array( $type ) ? false : $types->getType( $type );
$result->ElementSchemaType = $elementType;
$result->SchemaTypeName = $elementType['name'];
$result->SubstitutionGroup = isset( $element['substitutionGroup'] ) ? $element['substitutionGroup'] : $type;
// error_log( __CLASS__ . " need to populate the DOMSchemaElement instance" );
return $result;
} | php | public static function fromQName( $name )
{
$types = SchemaTypes::getInstance();
if ( $name instanceof QName )
{
// If prefix is empty try looking it up
if ( empty( $name->prefix ) )
{
$prefix = $types->getPrefixForNamespace( $name->namespaceURI );
if ( $prefix ) $name->prefix = $prefix;
}
$qname = "{$name->prefix}:{$name->localName}";
}
else if ( is_string( $name ) )
{
$qname = $name;
}
else
{
throw new \InvalidArgumentException( "$qname must be string or a QName instance" );
}
$element = $types->getElement( $qname );
if ( ! $element )
{
return null;
}
$result = new DOMSchemaElement();
$result->QualifiedName = $name;
$type = is_array( $element['types'][0] ) && isset( $element['types'][0]['parent'] )
? $element['types'][0]['parent']
: $element['types'][0];
// if ( is_array( $element['types'][0] ) )
// {
// $x = 1;
// }
$elementType = is_array( $type ) ? false : $types->getType( $type );
$result->ElementSchemaType = $elementType;
$result->SchemaTypeName = $elementType['name'];
$result->SubstitutionGroup = isset( $element['substitutionGroup'] ) ? $element['substitutionGroup'] : $type;
// error_log( __CLASS__ . " need to populate the DOMSchemaElement instance" );
return $result;
} | [
"public",
"static",
"function",
"fromQName",
"(",
"$",
"name",
")",
"{",
"$",
"types",
"=",
"SchemaTypes",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"$",
"name",
"instanceof",
"QName",
")",
"{",
"// If prefix is empty try looking it up\r",
"if",
"(",
"empty",
"(",
"$",
"name",
"->",
"prefix",
")",
")",
"{",
"$",
"prefix",
"=",
"$",
"types",
"->",
"getPrefixForNamespace",
"(",
"$",
"name",
"->",
"namespaceURI",
")",
";",
"if",
"(",
"$",
"prefix",
")",
"$",
"name",
"->",
"prefix",
"=",
"$",
"prefix",
";",
"}",
"$",
"qname",
"=",
"\"{$name->prefix}:{$name->localName}\"",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"$",
"qname",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"$qname must be string or a QName instance\"",
")",
";",
"}",
"$",
"element",
"=",
"$",
"types",
"->",
"getElement",
"(",
"$",
"qname",
")",
";",
"if",
"(",
"!",
"$",
"element",
")",
"{",
"return",
"null",
";",
"}",
"$",
"result",
"=",
"new",
"DOMSchemaElement",
"(",
")",
";",
"$",
"result",
"->",
"QualifiedName",
"=",
"$",
"name",
";",
"$",
"type",
"=",
"is_array",
"(",
"$",
"element",
"[",
"'types'",
"]",
"[",
"0",
"]",
")",
"&&",
"isset",
"(",
"$",
"element",
"[",
"'types'",
"]",
"[",
"0",
"]",
"[",
"'parent'",
"]",
")",
"?",
"$",
"element",
"[",
"'types'",
"]",
"[",
"0",
"]",
"[",
"'parent'",
"]",
":",
"$",
"element",
"[",
"'types'",
"]",
"[",
"0",
"]",
";",
"// if ( is_array( $element['types'][0] ) )\r",
"// {\r",
"// \t$x = 1;\r",
"// }\r",
"$",
"elementType",
"=",
"is_array",
"(",
"$",
"type",
")",
"?",
"false",
":",
"$",
"types",
"->",
"getType",
"(",
"$",
"type",
")",
";",
"$",
"result",
"->",
"ElementSchemaType",
"=",
"$",
"elementType",
";",
"$",
"result",
"->",
"SchemaTypeName",
"=",
"$",
"elementType",
"[",
"'name'",
"]",
";",
"$",
"result",
"->",
"SubstitutionGroup",
"=",
"isset",
"(",
"$",
"element",
"[",
"'substitutionGroup'",
"]",
")",
"?",
"$",
"element",
"[",
"'substitutionGroup'",
"]",
":",
"$",
"type",
";",
"// error_log( __CLASS__ . \" need to populate the DOMSchemaElement instance\" );\r",
"return",
"$",
"result",
";",
"}"
] | The qualified name of the element
@param QName|string $name | [
"The",
"qualified",
"name",
"of",
"the",
"element"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMSchemaElement.php#L50-L95 | train |
mullanaphy/markup | src/PHY/Markup/Element.php | Element.toString | public function toString()
{
if ($this->void) {
return '<'.$this->tag.$this->createAttributes().' />';
} else {
return '<'.$this->tag.$this->createAttributes().'>'.$this->recursivelyStringify($this->content).'</'.$this->tag.'>';
}
} | php | public function toString()
{
if ($this->void) {
return '<'.$this->tag.$this->createAttributes().' />';
} else {
return '<'.$this->tag.$this->createAttributes().'>'.$this->recursivelyStringify($this->content).'</'.$this->tag.'>';
}
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"void",
")",
"{",
"return",
"'<'",
".",
"$",
"this",
"->",
"tag",
".",
"$",
"this",
"->",
"createAttributes",
"(",
")",
".",
"' />'",
";",
"}",
"else",
"{",
"return",
"'<'",
".",
"$",
"this",
"->",
"tag",
".",
"$",
"this",
"->",
"createAttributes",
"(",
")",
".",
"'>'",
".",
"$",
"this",
"->",
"recursivelyStringify",
"(",
"$",
"this",
"->",
"content",
")",
".",
"'</'",
".",
"$",
"this",
"->",
"tag",
".",
"'>'",
";",
"}",
"}"
] | Generates the HTML and will recursively generate HTML out of inner
content.
@return string | [
"Generates",
"the",
"HTML",
"and",
"will",
"recursively",
"generate",
"HTML",
"out",
"of",
"inner",
"content",
"."
] | 7babac73bbefc2203aca990a8a42294a9738a0dd | https://github.com/mullanaphy/markup/blob/7babac73bbefc2203aca990a8a42294a9738a0dd/src/PHY/Markup/Element.php#L108-L115 | train |
mullanaphy/markup | src/PHY/Markup/Element.php | Element.toArray | public function toArray()
{
return [
'tag' => $this->tag,
'void' => $this->void,
'attributes' => $this->attributes,
'content' => $this->recursivelyArrayify($this->content)
];
} | php | public function toArray()
{
return [
'tag' => $this->tag,
'void' => $this->void,
'attributes' => $this->attributes,
'content' => $this->recursivelyArrayify($this->content)
];
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"[",
"'tag'",
"=>",
"$",
"this",
"->",
"tag",
",",
"'void'",
"=>",
"$",
"this",
"->",
"void",
",",
"'attributes'",
"=>",
"$",
"this",
"->",
"attributes",
",",
"'content'",
"=>",
"$",
"this",
"->",
"recursivelyArrayify",
"(",
"$",
"this",
"->",
"content",
")",
"]",
";",
"}"
] | Return our element as an array.
@return array | [
"Return",
"our",
"element",
"as",
"an",
"array",
"."
] | 7babac73bbefc2203aca990a8a42294a9738a0dd | https://github.com/mullanaphy/markup/blob/7babac73bbefc2203aca990a8a42294a9738a0dd/src/PHY/Markup/Element.php#L133-L141 | train |
mullanaphy/markup | src/PHY/Markup/Element.php | Element.append | public function append($content = null)
{
if (null === $content) {
return;
} else if (is_array($content)) {
foreach ($content as $row) {
$this->content[] = $row;
}
} else {
$this->content[] = $content;
}
return $this;
} | php | public function append($content = null)
{
if (null === $content) {
return;
} else if (is_array($content)) {
foreach ($content as $row) {
$this->content[] = $row;
}
} else {
$this->content[] = $content;
}
return $this;
} | [
"public",
"function",
"append",
"(",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"content",
")",
"{",
"return",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"foreach",
"(",
"$",
"content",
"as",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"content",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"content",
"[",
"]",
"=",
"$",
"content",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Append content into an element.
@param mixed $content
@return Element | [
"Append",
"content",
"into",
"an",
"element",
"."
] | 7babac73bbefc2203aca990a8a42294a9738a0dd | https://github.com/mullanaphy/markup/blob/7babac73bbefc2203aca990a8a42294a9738a0dd/src/PHY/Markup/Element.php#L159-L171 | train |
mullanaphy/markup | src/PHY/Markup/Element.php | Element.attributes | public function attributes(array $attributes)
{
$this->attributes = array_replace($this->attributes, $this->markup->attributes($this->tag, $attributes));
return $this;
} | php | public function attributes(array $attributes)
{
$this->attributes = array_replace($this->attributes, $this->markup->attributes($this->tag, $attributes));
return $this;
} | [
"public",
"function",
"attributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"this",
"->",
"attributes",
"=",
"array_replace",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"this",
"->",
"markup",
"->",
"attributes",
"(",
"$",
"this",
"->",
"tag",
",",
"$",
"attributes",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Change attributes of an element.
@param array $attributes
@return Element | [
"Change",
"attributes",
"of",
"an",
"element",
"."
] | 7babac73bbefc2203aca990a8a42294a9738a0dd | https://github.com/mullanaphy/markup/blob/7babac73bbefc2203aca990a8a42294a9738a0dd/src/PHY/Markup/Element.php#L179-L184 | train |
mullanaphy/markup | src/PHY/Markup/Element.php | Element.prepend | public function prepend($content = null)
{
if (null === $content) {
return;
} else if (is_array($content)) {
foreach (array_reverse($content) as $row) {
array_unshift($this->content, $row);
}
} else {
array_unshift($this->content, $content);
}
return $this;
} | php | public function prepend($content = null)
{
if (null === $content) {
return;
} else if (is_array($content)) {
foreach (array_reverse($content) as $row) {
array_unshift($this->content, $row);
}
} else {
array_unshift($this->content, $content);
}
return $this;
} | [
"public",
"function",
"prepend",
"(",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"content",
")",
"{",
"return",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"foreach",
"(",
"array_reverse",
"(",
"$",
"content",
")",
"as",
"$",
"row",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"row",
")",
";",
"}",
"}",
"else",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"content",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Prepend content into an element.
@param mixed $content
@return Element | [
"Prepend",
"content",
"into",
"an",
"element",
"."
] | 7babac73bbefc2203aca990a8a42294a9738a0dd | https://github.com/mullanaphy/markup/blob/7babac73bbefc2203aca990a8a42294a9738a0dd/src/PHY/Markup/Element.php#L229-L241 | train |
kaylathedev/io | src/JsonFileStorage.php | JsonFileStorage.open | public function open()
{
if (is_file($this->filename)) {
$fileData = file_get_contents($this->filename);
if (false === $fileData) {
throw new IOException('Unable to get the contents of the json file!');
}
} else {
$fileData = null;
if (!$this->createIfNotExists) {
throw new FileNotFoundException("The file doesn't exist!");
}
}
if (0 === strlen($fileData)) {
$this->contents = [];
} else {
$this->contents = json_decode($fileData, true);
if (null === $this->contents) {
throw new RuntimeException('The format of the JSON file is invalid!');
}
}
} | php | public function open()
{
if (is_file($this->filename)) {
$fileData = file_get_contents($this->filename);
if (false === $fileData) {
throw new IOException('Unable to get the contents of the json file!');
}
} else {
$fileData = null;
if (!$this->createIfNotExists) {
throw new FileNotFoundException("The file doesn't exist!");
}
}
if (0 === strlen($fileData)) {
$this->contents = [];
} else {
$this->contents = json_decode($fileData, true);
if (null === $this->contents) {
throw new RuntimeException('The format of the JSON file is invalid!');
}
}
} | [
"public",
"function",
"open",
"(",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"this",
"->",
"filename",
")",
")",
"{",
"$",
"fileData",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"filename",
")",
";",
"if",
"(",
"false",
"===",
"$",
"fileData",
")",
"{",
"throw",
"new",
"IOException",
"(",
"'Unable to get the contents of the json file!'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"fileData",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"createIfNotExists",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"\"The file doesn't exist!\"",
")",
";",
"}",
"}",
"if",
"(",
"0",
"===",
"strlen",
"(",
"$",
"fileData",
")",
")",
"{",
"$",
"this",
"->",
"contents",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"contents",
"=",
"json_decode",
"(",
"$",
"fileData",
",",
"true",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"contents",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The format of the JSON file is invalid!'",
")",
";",
"}",
"}",
"}"
] | Opens the json file.
If the file isn't found, and the {@link createIfNotExists} method is
called with true, then the file will be created when data is written to it.
If the file is empty, then this class will assume the contents to be a
json object.
@return void | [
"Opens",
"the",
"json",
"file",
"."
] | 9e8754a6972fc80523d0aaadb6f5629e552f0043 | https://github.com/kaylathedev/io/blob/9e8754a6972fc80523d0aaadb6f5629e552f0043/src/JsonFileStorage.php#L72-L95 | train |
kaylathedev/io | src/JsonFileStorage.php | JsonFileStorage.set | public function set($key, $value)
{
$this->assertOpened();
$this->contents[(string) $key] = $value;
} | php | public function set($key, $value)
{
$this->assertOpened();
$this->contents[(string) $key] = $value;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"assertOpened",
"(",
")",
";",
"$",
"this",
"->",
"contents",
"[",
"(",
"string",
")",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Overwrites a record with the key parameter.
If the record doesn't exist, it will be created automatically.
The entire record will be replaced by the value parameter.
@param string $key The record's key.
@param mixed $value The value to be replaced with the record's contents.
@return void | [
"Overwrites",
"a",
"record",
"with",
"the",
"key",
"parameter",
"."
] | 9e8754a6972fc80523d0aaadb6f5629e552f0043 | https://github.com/kaylathedev/io/blob/9e8754a6972fc80523d0aaadb6f5629e552f0043/src/JsonFileStorage.php#L107-L111 | train |
kaylathedev/io | src/JsonFileStorage.php | JsonFileStorage.get | public function get($key)
{
$this->assertOpened();
$key = (string) $key;
if (isset($this->contents[$key])) {
return $this->contents[$key];
}
return null;
} | php | public function get($key)
{
$this->assertOpened();
$key = (string) $key;
if (isset($this->contents[$key])) {
return $this->contents[$key];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"assertOpened",
"(",
")",
";",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"key",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"contents",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"contents",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns a record that originates from the opened json file.
If the key doesn't exist, then null will be returned.
@param string $key The key of the record.
@return mixed | [
"Returns",
"a",
"record",
"that",
"originates",
"from",
"the",
"opened",
"json",
"file",
"."
] | 9e8754a6972fc80523d0aaadb6f5629e552f0043 | https://github.com/kaylathedev/io/blob/9e8754a6972fc80523d0aaadb6f5629e552f0043/src/JsonFileStorage.php#L121-L129 | train |
kaylathedev/io | src/JsonFileStorage.php | JsonFileStorage.clear | public function clear()
{
$this->assertOpened();
foreach ($this->contents as $key => $value) {
unset($this->contents[$key]);
}
} | php | public function clear()
{
$this->assertOpened();
foreach ($this->contents as $key => $value) {
unset($this->contents[$key]);
}
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"this",
"->",
"assertOpened",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"contents",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"contents",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] | Deletes all of the records.
@return void | [
"Deletes",
"all",
"of",
"the",
"records",
"."
] | 9e8754a6972fc80523d0aaadb6f5629e552f0043 | https://github.com/kaylathedev/io/blob/9e8754a6972fc80523d0aaadb6f5629e552f0043/src/JsonFileStorage.php#L160-L166 | train |
kaylathedev/io | src/JsonFileStorage.php | JsonFileStorage.close | public function close()
{
if (null !== $this->contents) {
$result = file_put_contents($this->filename, json_encode($this->contents));
if (false === $result) {
throw new IOException('Unable to write to file!');
}
$this->contents = null;
}
} | php | public function close()
{
if (null !== $this->contents) {
$result = file_put_contents($this->filename, json_encode($this->contents));
if (false === $result) {
throw new IOException('Unable to write to file!');
}
$this->contents = null;
}
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"contents",
")",
"{",
"$",
"result",
"=",
"file_put_contents",
"(",
"$",
"this",
"->",
"filename",
",",
"json_encode",
"(",
"$",
"this",
"->",
"contents",
")",
")",
";",
"if",
"(",
"false",
"===",
"$",
"result",
")",
"{",
"throw",
"new",
"IOException",
"(",
"'Unable to write to file!'",
")",
";",
"}",
"$",
"this",
"->",
"contents",
"=",
"null",
";",
"}",
"}"
] | Writes any pending changes to the opened json file
and disposes of the class.
If this object wasn't opened, then this method will do nothing.
@return void | [
"Writes",
"any",
"pending",
"changes",
"to",
"the",
"opened",
"json",
"file",
"and",
"disposes",
"of",
"the",
"class",
"."
] | 9e8754a6972fc80523d0aaadb6f5629e552f0043 | https://github.com/kaylathedev/io/blob/9e8754a6972fc80523d0aaadb6f5629e552f0043/src/JsonFileStorage.php#L175-L184 | train |
Dhii/callback-abstract | src/NormalizeCallableCapableTrait.php | NormalizeCallableCapableTrait._normalizeCallable | public function _normalizeCallable($callable)
{
// Closure remains as such
if ($callable instanceof Closure) {
return $callable;
}
// Invocable objects take precedence over stringable ones
if (!(is_object($callable) && is_callable($callable))) {
try {
// Strings that don't identify methods get normalized and returned
$callable = $this->_normalizeString($callable);
if (strpos($callable, '::', 1) === false) {
return $callable;
}
} catch (InvalidArgumentException $e) {
// Continue
}
}
// Everything else is a method
return $this->_normalizeMethodCallable($callable);
} | php | public function _normalizeCallable($callable)
{
// Closure remains as such
if ($callable instanceof Closure) {
return $callable;
}
// Invocable objects take precedence over stringable ones
if (!(is_object($callable) && is_callable($callable))) {
try {
// Strings that don't identify methods get normalized and returned
$callable = $this->_normalizeString($callable);
if (strpos($callable, '::', 1) === false) {
return $callable;
}
} catch (InvalidArgumentException $e) {
// Continue
}
}
// Everything else is a method
return $this->_normalizeMethodCallable($callable);
} | [
"public",
"function",
"_normalizeCallable",
"(",
"$",
"callable",
")",
"{",
"// Closure remains as such",
"if",
"(",
"$",
"callable",
"instanceof",
"Closure",
")",
"{",
"return",
"$",
"callable",
";",
"}",
"// Invocable objects take precedence over stringable ones",
"if",
"(",
"!",
"(",
"is_object",
"(",
"$",
"callable",
")",
"&&",
"is_callable",
"(",
"$",
"callable",
")",
")",
")",
"{",
"try",
"{",
"// Strings that don't identify methods get normalized and returned",
"$",
"callable",
"=",
"$",
"this",
"->",
"_normalizeString",
"(",
"$",
"callable",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"callable",
",",
"'::'",
",",
"1",
")",
"===",
"false",
")",
"{",
"return",
"$",
"callable",
";",
"}",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"// Continue",
"}",
"}",
"// Everything else is a method",
"return",
"$",
"this",
"->",
"_normalizeMethodCallable",
"(",
"$",
"callable",
")",
";",
"}"
] | Normalizes a callable, such that it is possible to distinguish between function and method formats.
- 'MyClass:myMethod' -> ['MyClass', 'myMethod'].
- Closures remain closures.
- Invocable object -> [$object, '__invoke']
- An object that is both stringable and invocable will be treated as invocable.
- Arrays remain arrays, with normalization.
@param array|Stringable|string|object|Closure.
@since [*next-version*]
@throws InvalidArgumentException If the type of callable is wrong.
@throws OutOfRangeException If the format of the callable is wrong.
@return array|Closure|string The normalized callable. | [
"Normalizes",
"a",
"callable",
"such",
"that",
"it",
"is",
"possible",
"to",
"distinguish",
"between",
"function",
"and",
"method",
"formats",
"."
] | 43ed4e99fc6ccdaf46a25d06da482a2fba8d9b19 | https://github.com/Dhii/callback-abstract/blob/43ed4e99fc6ccdaf46a25d06da482a2fba8d9b19/src/NormalizeCallableCapableTrait.php#L37-L59 | train |
sndsgd/http | src/http/data/Collection.php | Collection.addValue | public function addValue(string $key, $value)
{
# ensure the total input variables doesn't exceed `max_input_variables`
if ($this->count === $this->maxVars) {
throw new DecodeException("max_input_variables exceeded");
}
# if the key has both open and close brackets
# and the close comes after the open, the key contains nesting
if (
($openPos = strpos($key, "[")) !== false &&
($closePos = strpos($key, "]")) !== false &&
$openPos < $closePos
) {
$this->addNestedValue($key, $value, $openPos);
} else {
\sndsgd\Arr::addValue($this->values, $key, $value);
}
$this->count++;
} | php | public function addValue(string $key, $value)
{
# ensure the total input variables doesn't exceed `max_input_variables`
if ($this->count === $this->maxVars) {
throw new DecodeException("max_input_variables exceeded");
}
# if the key has both open and close brackets
# and the close comes after the open, the key contains nesting
if (
($openPos = strpos($key, "[")) !== false &&
($closePos = strpos($key, "]")) !== false &&
$openPos < $closePos
) {
$this->addNestedValue($key, $value, $openPos);
} else {
\sndsgd\Arr::addValue($this->values, $key, $value);
}
$this->count++;
} | [
"public",
"function",
"addValue",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
"{",
"# ensure the total input variables doesn't exceed `max_input_variables`",
"if",
"(",
"$",
"this",
"->",
"count",
"===",
"$",
"this",
"->",
"maxVars",
")",
"{",
"throw",
"new",
"DecodeException",
"(",
"\"max_input_variables exceeded\"",
")",
";",
"}",
"# if the key has both open and close brackets",
"# and the close comes after the open, the key contains nesting",
"if",
"(",
"(",
"$",
"openPos",
"=",
"strpos",
"(",
"$",
"key",
",",
"\"[\"",
")",
")",
"!==",
"false",
"&&",
"(",
"$",
"closePos",
"=",
"strpos",
"(",
"$",
"key",
",",
"\"]\"",
")",
")",
"!==",
"false",
"&&",
"$",
"openPos",
"<",
"$",
"closePos",
")",
"{",
"$",
"this",
"->",
"addNestedValue",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"openPos",
")",
";",
"}",
"else",
"{",
"\\",
"sndsgd",
"\\",
"Arr",
"::",
"addValue",
"(",
"$",
"this",
"->",
"values",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"count",
"++",
";",
"}"
] | Add a value to the collection
@param string $key The key to add the value under
@param string|\sndsgd\http\UploadedFile $value The value to add | [
"Add",
"a",
"value",
"to",
"the",
"collection"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/data/Collection.php#L70-L90 | train |
sndsgd/http | src/http/data/Collection.php | Collection.addNestedValue | protected function addNestedValue(string $key, $value, int $pos)
{
# convert the levels into an array of strings
$levels = (strpos($key, "][") !== false)
? explode("][", substr($key, $pos + 1, -1))
: [substr($key, $pos + 1, -1)];
array_unshift($levels, substr($key, 0, $pos));
# ensure the nesting doesn't exceed `max_nesting_levels`
$levelLen = count($levels);
if ($levelLen > $this->maxNestingLevels) {
throw new DecodeException("max_input_nesting_level exceeded");
}
$lastKey = array_pop($levels);
$values = &$this->values;
foreach ($levels as $level) {
if ($level === "") {
$level = count($values);
}
if (!array_key_exists($level, $values)) {
$values[$level] = [];
}
$values = &$values[$level];
}
if ($lastKey === "") {
$lastKey = count($values);
}
\sndsgd\Arr::addValue($values, $lastKey, $value);
} | php | protected function addNestedValue(string $key, $value, int $pos)
{
# convert the levels into an array of strings
$levels = (strpos($key, "][") !== false)
? explode("][", substr($key, $pos + 1, -1))
: [substr($key, $pos + 1, -1)];
array_unshift($levels, substr($key, 0, $pos));
# ensure the nesting doesn't exceed `max_nesting_levels`
$levelLen = count($levels);
if ($levelLen > $this->maxNestingLevels) {
throw new DecodeException("max_input_nesting_level exceeded");
}
$lastKey = array_pop($levels);
$values = &$this->values;
foreach ($levels as $level) {
if ($level === "") {
$level = count($values);
}
if (!array_key_exists($level, $values)) {
$values[$level] = [];
}
$values = &$values[$level];
}
if ($lastKey === "") {
$lastKey = count($values);
}
\sndsgd\Arr::addValue($values, $lastKey, $value);
} | [
"protected",
"function",
"addNestedValue",
"(",
"string",
"$",
"key",
",",
"$",
"value",
",",
"int",
"$",
"pos",
")",
"{",
"# convert the levels into an array of strings",
"$",
"levels",
"=",
"(",
"strpos",
"(",
"$",
"key",
",",
"\"][\"",
")",
"!==",
"false",
")",
"?",
"explode",
"(",
"\"][\"",
",",
"substr",
"(",
"$",
"key",
",",
"$",
"pos",
"+",
"1",
",",
"-",
"1",
")",
")",
":",
"[",
"substr",
"(",
"$",
"key",
",",
"$",
"pos",
"+",
"1",
",",
"-",
"1",
")",
"]",
";",
"array_unshift",
"(",
"$",
"levels",
",",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"$",
"pos",
")",
")",
";",
"# ensure the nesting doesn't exceed `max_nesting_levels`",
"$",
"levelLen",
"=",
"count",
"(",
"$",
"levels",
")",
";",
"if",
"(",
"$",
"levelLen",
">",
"$",
"this",
"->",
"maxNestingLevels",
")",
"{",
"throw",
"new",
"DecodeException",
"(",
"\"max_input_nesting_level exceeded\"",
")",
";",
"}",
"$",
"lastKey",
"=",
"array_pop",
"(",
"$",
"levels",
")",
";",
"$",
"values",
"=",
"&",
"$",
"this",
"->",
"values",
";",
"foreach",
"(",
"$",
"levels",
"as",
"$",
"level",
")",
"{",
"if",
"(",
"$",
"level",
"===",
"\"\"",
")",
"{",
"$",
"level",
"=",
"count",
"(",
"$",
"values",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"level",
",",
"$",
"values",
")",
")",
"{",
"$",
"values",
"[",
"$",
"level",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"values",
"=",
"&",
"$",
"values",
"[",
"$",
"level",
"]",
";",
"}",
"if",
"(",
"$",
"lastKey",
"===",
"\"\"",
")",
"{",
"$",
"lastKey",
"=",
"count",
"(",
"$",
"values",
")",
";",
"}",
"\\",
"sndsgd",
"\\",
"Arr",
"::",
"addValue",
"(",
"$",
"values",
",",
"$",
"lastKey",
",",
"$",
"value",
")",
";",
"}"
] | Add a value that has a nested key
@param string $key
@param mixed $value
@param integer $pos The position of the first open bracket | [
"Add",
"a",
"value",
"that",
"has",
"a",
"nested",
"key"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/data/Collection.php#L99-L131 | train |
squareproton/Bond | src/Bond/Normality/PhpClass.php | PhpClass.getUsesDeclarations | private function getUsesDeclarations()
{
asort( $this->usesDeclarations );
$output = [];
foreach( $this->usesDeclarations as $namespace ) {
$output[] = sprintf( 'use %s;', $namespace );
}
return new Format( $output );
} | php | private function getUsesDeclarations()
{
asort( $this->usesDeclarations );
$output = [];
foreach( $this->usesDeclarations as $namespace ) {
$output[] = sprintf( 'use %s;', $namespace );
}
return new Format( $output );
} | [
"private",
"function",
"getUsesDeclarations",
"(",
")",
"{",
"asort",
"(",
"$",
"this",
"->",
"usesDeclarations",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"usesDeclarations",
"as",
"$",
"namespace",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"sprintf",
"(",
"'use %s;'",
",",
"$",
"namespace",
")",
";",
"}",
"return",
"new",
"Format",
"(",
"$",
"output",
")",
";",
"}"
] | Get uses declaration
@return Bond/Format | [
"Get",
"uses",
"declaration"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/PhpClass.php#L194-L202 | train |
squareproton/Bond | src/Bond/Normality/PhpClass.php | PhpClass.getClassDeclaration | private function getClassDeclaration()
{
return new Format(
sprintf(
'%sclass %s%s%s',
$this->isAbstract ? 'abstract ' : '',
$this->class,
$this->getImplementOrExtendsDeclaration('extends', $this->extends),
$this->getImplementOrExtendsDeclaration('implements', $this->implements)
)
);
} | php | private function getClassDeclaration()
{
return new Format(
sprintf(
'%sclass %s%s%s',
$this->isAbstract ? 'abstract ' : '',
$this->class,
$this->getImplementOrExtendsDeclaration('extends', $this->extends),
$this->getImplementOrExtendsDeclaration('implements', $this->implements)
)
);
} | [
"private",
"function",
"getClassDeclaration",
"(",
")",
"{",
"return",
"new",
"Format",
"(",
"sprintf",
"(",
"'%sclass %s%s%s'",
",",
"$",
"this",
"->",
"isAbstract",
"?",
"'abstract '",
":",
"''",
",",
"$",
"this",
"->",
"class",
",",
"$",
"this",
"->",
"getImplementOrExtendsDeclaration",
"(",
"'extends'",
",",
"$",
"this",
"->",
"extends",
")",
",",
"$",
"this",
"->",
"getImplementOrExtendsDeclaration",
"(",
"'implements'",
",",
"$",
"this",
"->",
"implements",
")",
")",
")",
";",
"}"
] | Get class declaration
@return Bond/Format | [
"Get",
"class",
"declaration"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/PhpClass.php#L208-L219 | train |
squareproton/Bond | src/Bond/Normality/PhpClass.php | PhpClass.getClassBody | private function getClassBody()
{
// sort the class components by their name
$this->classComponents->sort(
function( PhpClassComponent $a, PhpClassComponent $b ) {
if ($a::SORT_ORDERING == $b::SORT_ORDERING) {
return $a->name < $b->name ? -1 : 1;
}
return ($a::SORT_ORDERING < $b::SORT_ORDERING) ? -1 : 1;
}
);
$output = [];
$lastType = null;
$lastNumLines = null;
foreach( $this->classComponents as $component ) {
// manage strategy for adding new lines
$componentAsLines = $component->content->toArray();
if( !$lastType || !$component instanceof $lastType ) {
$output[] = "\n";
} elseif( count($componentAsLines) > 1 or $lastNumLines > 1 ) {
$output[] = "\n";
}
$lastType = get_class( $component );
$lastNumLines = count( $componentAsLines );
// build the output;
$output = array_merge( $output, $componentAsLines );
}
$output[] = "\n";
return new Format( $output );
} | php | private function getClassBody()
{
// sort the class components by their name
$this->classComponents->sort(
function( PhpClassComponent $a, PhpClassComponent $b ) {
if ($a::SORT_ORDERING == $b::SORT_ORDERING) {
return $a->name < $b->name ? -1 : 1;
}
return ($a::SORT_ORDERING < $b::SORT_ORDERING) ? -1 : 1;
}
);
$output = [];
$lastType = null;
$lastNumLines = null;
foreach( $this->classComponents as $component ) {
// manage strategy for adding new lines
$componentAsLines = $component->content->toArray();
if( !$lastType || !$component instanceof $lastType ) {
$output[] = "\n";
} elseif( count($componentAsLines) > 1 or $lastNumLines > 1 ) {
$output[] = "\n";
}
$lastType = get_class( $component );
$lastNumLines = count( $componentAsLines );
// build the output;
$output = array_merge( $output, $componentAsLines );
}
$output[] = "\n";
return new Format( $output );
} | [
"private",
"function",
"getClassBody",
"(",
")",
"{",
"// sort the class components by their name",
"$",
"this",
"->",
"classComponents",
"->",
"sort",
"(",
"function",
"(",
"PhpClassComponent",
"$",
"a",
",",
"PhpClassComponent",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"::",
"SORT_ORDERING",
"==",
"$",
"b",
"::",
"SORT_ORDERING",
")",
"{",
"return",
"$",
"a",
"->",
"name",
"<",
"$",
"b",
"->",
"name",
"?",
"-",
"1",
":",
"1",
";",
"}",
"return",
"(",
"$",
"a",
"::",
"SORT_ORDERING",
"<",
"$",
"b",
"::",
"SORT_ORDERING",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"$",
"lastType",
"=",
"null",
";",
"$",
"lastNumLines",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"classComponents",
"as",
"$",
"component",
")",
"{",
"// manage strategy for adding new lines",
"$",
"componentAsLines",
"=",
"$",
"component",
"->",
"content",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"!",
"$",
"lastType",
"||",
"!",
"$",
"component",
"instanceof",
"$",
"lastType",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"\"\\n\"",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"componentAsLines",
")",
">",
"1",
"or",
"$",
"lastNumLines",
">",
"1",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"\"\\n\"",
";",
"}",
"$",
"lastType",
"=",
"get_class",
"(",
"$",
"component",
")",
";",
"$",
"lastNumLines",
"=",
"count",
"(",
"$",
"componentAsLines",
")",
";",
"// build the output;",
"$",
"output",
"=",
"array_merge",
"(",
"$",
"output",
",",
"$",
"componentAsLines",
")",
";",
"}",
"$",
"output",
"[",
"]",
"=",
"\"\\n\"",
";",
"return",
"new",
"Format",
"(",
"$",
"output",
")",
";",
"}"
] | Get class body
@return Bond\Format | [
"Get",
"class",
"body"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/PhpClass.php#L242-L277 | train |
modulusphp/utility | GlobalVariables.php | GlobalVariables.get | public static function get() : array
{
return [
'csrf_token' => CSRF::generate(),
'errors' => Variable::has('validation.errors') ? Variable::get('validation.errors') : (new ValidatorFactory())->make([], [])->errors(),
'old' => Variable::has('form.old') ? Variable::get('form.old') : [],
];
} | php | public static function get() : array
{
return [
'csrf_token' => CSRF::generate(),
'errors' => Variable::has('validation.errors') ? Variable::get('validation.errors') : (new ValidatorFactory())->make([], [])->errors(),
'old' => Variable::has('form.old') ? Variable::get('form.old') : [],
];
} | [
"public",
"static",
"function",
"get",
"(",
")",
":",
"array",
"{",
"return",
"[",
"'csrf_token'",
"=>",
"CSRF",
"::",
"generate",
"(",
")",
",",
"'errors'",
"=>",
"Variable",
"::",
"has",
"(",
"'validation.errors'",
")",
"?",
"Variable",
"::",
"get",
"(",
"'validation.errors'",
")",
":",
"(",
"new",
"ValidatorFactory",
"(",
")",
")",
"->",
"make",
"(",
"[",
"]",
",",
"[",
"]",
")",
"->",
"errors",
"(",
")",
",",
"'old'",
"=>",
"Variable",
"::",
"has",
"(",
"'form.old'",
")",
"?",
"Variable",
"::",
"get",
"(",
"'form.old'",
")",
":",
"[",
"]",
",",
"]",
";",
"}"
] | Get global variables
@return array | [
"Get",
"global",
"variables"
] | c1e127539b13d3ec8381e41c64b881e0701807f5 | https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/GlobalVariables.php#L19-L26 | train |
Jalle19/yii-lazy-image | src/yiilazyimage/components/LazyImage.php | LazyImage.loadAssets | private static function loadAssets()
{
$am = \Yii::app()->assetManager;
$cs = \Yii::app()->clientScript;
// Publish all assets
self::$_assetsUrl = $am->publish(realpath(__DIR__.'/../assets'));
// Register jquery-unveil
$script = YII_DEBUG ? 'jquery-unveil.js' : 'jquery-unveil.min.js';
$cs->registerScriptFile(self::$_assetsUrl
.'/js/'.$script, \CClientScript::POS_END);
$cs->registerScript(__CLASS__.'_unveil', '
$(".lazy").unveil(50);
', \CClientScript::POS_END);
} | php | private static function loadAssets()
{
$am = \Yii::app()->assetManager;
$cs = \Yii::app()->clientScript;
// Publish all assets
self::$_assetsUrl = $am->publish(realpath(__DIR__.'/../assets'));
// Register jquery-unveil
$script = YII_DEBUG ? 'jquery-unveil.js' : 'jquery-unveil.min.js';
$cs->registerScriptFile(self::$_assetsUrl
.'/js/'.$script, \CClientScript::POS_END);
$cs->registerScript(__CLASS__.'_unveil', '
$(".lazy").unveil(50);
', \CClientScript::POS_END);
} | [
"private",
"static",
"function",
"loadAssets",
"(",
")",
"{",
"$",
"am",
"=",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"assetManager",
";",
"$",
"cs",
"=",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"clientScript",
";",
"// Publish all assets",
"self",
"::",
"$",
"_assetsUrl",
"=",
"$",
"am",
"->",
"publish",
"(",
"realpath",
"(",
"__DIR__",
".",
"'/../assets'",
")",
")",
";",
"// Register jquery-unveil",
"$",
"script",
"=",
"YII_DEBUG",
"?",
"'jquery-unveil.js'",
":",
"'jquery-unveil.min.js'",
";",
"$",
"cs",
"->",
"registerScriptFile",
"(",
"self",
"::",
"$",
"_assetsUrl",
".",
"'/js/'",
".",
"$",
"script",
",",
"\\",
"CClientScript",
"::",
"POS_END",
")",
";",
"$",
"cs",
"->",
"registerScript",
"(",
"__CLASS__",
".",
"'_unveil'",
",",
"'\n\t\t\t$(\".lazy\").unveil(50);\n\t\t'",
",",
"\\",
"CClientScript",
"::",
"POS_END",
")",
";",
"}"
] | Publishes the required assets | [
"Publishes",
"the",
"required",
"assets"
] | 8440028b7223b88fcd3f25e917ac8c40006567a8 | https://github.com/Jalle19/yii-lazy-image/blob/8440028b7223b88fcd3f25e917ac8c40006567a8/src/yiilazyimage/components/LazyImage.php#L56-L73 | train |
QoboLtd/Qobo-WP-Custom-Theme-Path | src/qobo-custom-theme-path.php | Qobo_Custom_Theme_Path.get_default_path | public function get_default_path() {
if ( ! defined( 'ABSPATH' ) ) {
throw \RuntimeException( 'ABSPATH constant is not defined. Something is very wrong!' );
}
$default_path = $this->default_path;
// Allow to change this in wp-config.php or elsewhere.
if ( defined( 'QB_CUSTOM_THEME_PATH' ) ) {
$default_path = QB_CUSTOM_THEME_PATH;
}
$result = ABSPATH . $default_path;
return $result;
} | php | public function get_default_path() {
if ( ! defined( 'ABSPATH' ) ) {
throw \RuntimeException( 'ABSPATH constant is not defined. Something is very wrong!' );
}
$default_path = $this->default_path;
// Allow to change this in wp-config.php or elsewhere.
if ( defined( 'QB_CUSTOM_THEME_PATH' ) ) {
$default_path = QB_CUSTOM_THEME_PATH;
}
$result = ABSPATH . $default_path;
return $result;
} | [
"public",
"function",
"get_default_path",
"(",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'ABSPATH'",
")",
")",
"{",
"throw",
"\\",
"RuntimeException",
"(",
"'ABSPATH constant is not defined. Something is very wrong!'",
")",
";",
"}",
"$",
"default_path",
"=",
"$",
"this",
"->",
"default_path",
";",
"// Allow to change this in wp-config.php or elsewhere.",
"if",
"(",
"defined",
"(",
"'QB_CUSTOM_THEME_PATH'",
")",
")",
"{",
"$",
"default_path",
"=",
"QB_CUSTOM_THEME_PATH",
";",
"}",
"$",
"result",
"=",
"ABSPATH",
".",
"$",
"default_path",
";",
"return",
"$",
"result",
";",
"}"
] | Get default path
Get the default path to custom themes directory. Can be adjusted
from outside with QB_CUSTOM_THEME_PATH constant, defined, for
example, in wp-config.php.
@throws RuntimeException If ABSPATH constant is not defined.
@return string | [
"Get",
"default",
"path"
] | e7cdb5bfa4fbb482c460589c9adf2d5fed83ec91 | https://github.com/QoboLtd/Qobo-WP-Custom-Theme-Path/blob/e7cdb5bfa4fbb482c460589c9adf2d5fed83ec91/src/qobo-custom-theme-path.php#L30-L44 | train |
QoboLtd/Qobo-WP-Custom-Theme-Path | src/qobo-custom-theme-path.php | Qobo_Custom_Theme_Path.validate_path | public function validate_path( $path ) {
$result = null;
$path = (string) $path;
// Empty values are not valid.
if ( empty( $path ) ) {
return 'Empty path is not allowed';
}
// Path must not end in slash.
// As per https://codex.wordpress.org/Function_Reference/register_theme_directory .
if ( DIRECTORY_SEPARATOR === substr( $path, -1, 1 ) ) {
return "Path ends in slash [$path]";
}
return $result;
} | php | public function validate_path( $path ) {
$result = null;
$path = (string) $path;
// Empty values are not valid.
if ( empty( $path ) ) {
return 'Empty path is not allowed';
}
// Path must not end in slash.
// As per https://codex.wordpress.org/Function_Reference/register_theme_directory .
if ( DIRECTORY_SEPARATOR === substr( $path, -1, 1 ) ) {
return "Path ends in slash [$path]";
}
return $result;
} | [
"public",
"function",
"validate_path",
"(",
"$",
"path",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"path",
"=",
"(",
"string",
")",
"$",
"path",
";",
"// Empty values are not valid.",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"return",
"'Empty path is not allowed'",
";",
"}",
"// Path must not end in slash.",
"// As per https://codex.wordpress.org/Function_Reference/register_theme_directory .",
"if",
"(",
"DIRECTORY_SEPARATOR",
"===",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
",",
"1",
")",
")",
"{",
"return",
"\"Path ends in slash [$path]\"",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Validate given path
@param string $path Path to check.
@return string|null Problem description. | [
"Validate",
"given",
"path"
] | e7cdb5bfa4fbb482c460589c9adf2d5fed83ec91 | https://github.com/QoboLtd/Qobo-WP-Custom-Theme-Path/blob/e7cdb5bfa4fbb482c460589c9adf2d5fed83ec91/src/qobo-custom-theme-path.php#L52-L69 | train |
QoboLtd/Qobo-WP-Custom-Theme-Path | src/qobo-custom-theme-path.php | Qobo_Custom_Theme_Path.register_path | public function register_path( $dir = null, $persistent = true ) {
$result = false;
// Cast parameters to known values.
$dir = (string) $dir;
$persistent = (bool) $persistent;
if ( empty( $dir ) ) {
$dir = $this->get_default_path();
}
$path_fail_reason = $this->validate_path( $dir );
if ( $path_fail_reason ) {
return new WP_Error( 'custom_theme_path_invalid', "Custom themes directory is invalid: $path_fail_reason", $dir );
}
// Register custom-theme path for "on the fly".
$result = register_theme_directory( $dir );
if ( ! $persistent ) {
return $result;
}
// WordPress option is already set.
if ( get_option( 'stylesheet_root' ) === $dir ) {
return $result;
}
// Update WordPress option if persistence is required.
//
// Not returning the result of this operation as it can
// be confusing - false is returned either on failure or
// when the option value was the same and wasn't updated.
update_option( 'stylesheet_root', $dir );
} | php | public function register_path( $dir = null, $persistent = true ) {
$result = false;
// Cast parameters to known values.
$dir = (string) $dir;
$persistent = (bool) $persistent;
if ( empty( $dir ) ) {
$dir = $this->get_default_path();
}
$path_fail_reason = $this->validate_path( $dir );
if ( $path_fail_reason ) {
return new WP_Error( 'custom_theme_path_invalid', "Custom themes directory is invalid: $path_fail_reason", $dir );
}
// Register custom-theme path for "on the fly".
$result = register_theme_directory( $dir );
if ( ! $persistent ) {
return $result;
}
// WordPress option is already set.
if ( get_option( 'stylesheet_root' ) === $dir ) {
return $result;
}
// Update WordPress option if persistence is required.
//
// Not returning the result of this operation as it can
// be confusing - false is returned either on failure or
// when the option value was the same and wasn't updated.
update_option( 'stylesheet_root', $dir );
} | [
"public",
"function",
"register_path",
"(",
"$",
"dir",
"=",
"null",
",",
"$",
"persistent",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"false",
";",
"// Cast parameters to known values.",
"$",
"dir",
"=",
"(",
"string",
")",
"$",
"dir",
";",
"$",
"persistent",
"=",
"(",
"bool",
")",
"$",
"persistent",
";",
"if",
"(",
"empty",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"dir",
"=",
"$",
"this",
"->",
"get_default_path",
"(",
")",
";",
"}",
"$",
"path_fail_reason",
"=",
"$",
"this",
"->",
"validate_path",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"$",
"path_fail_reason",
")",
"{",
"return",
"new",
"WP_Error",
"(",
"'custom_theme_path_invalid'",
",",
"\"Custom themes directory is invalid: $path_fail_reason\"",
",",
"$",
"dir",
")",
";",
"}",
"// Register custom-theme path for \"on the fly\".",
"$",
"result",
"=",
"register_theme_directory",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"!",
"$",
"persistent",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// WordPress option is already set.",
"if",
"(",
"get_option",
"(",
"'stylesheet_root'",
")",
"===",
"$",
"dir",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// Update WordPress option if persistence is required.",
"//",
"// Not returning the result of this operation as it can",
"// be confusing - false is returned either on failure or",
"// when the option value was the same and wasn't updated.",
"update_option",
"(",
"'stylesheet_root'",
",",
"$",
"dir",
")",
";",
"}"
] | Register custom theme path
@param string $dir Directory to register (Relative to WP_CONTENT_DIR).
@param bool $persistent Whether to update WordPress options or not.
@return boolean|WP_Error True on success, false or WP_Error otherwise | [
"Register",
"custom",
"theme",
"path"
] | e7cdb5bfa4fbb482c460589c9adf2d5fed83ec91 | https://github.com/QoboLtd/Qobo-WP-Custom-Theme-Path/blob/e7cdb5bfa4fbb482c460589c9adf2d5fed83ec91/src/qobo-custom-theme-path.php#L78-L112 | train |
wb-crowdfusion/crowdfusion | system/core/classes/nodedb/model/MetaPartial.php | MetaPartial.toString | public function toString()
{
$metaString = '#';
$metaString .= $this->fields['MetaName'];
if (!empty($this->fields['MetaValue']))
$metaString .= '="'. $this->fields['MetaValue'] .'"';
return $metaString;
} | php | public function toString()
{
$metaString = '#';
$metaString .= $this->fields['MetaName'];
if (!empty($this->fields['MetaValue']))
$metaString .= '="'. $this->fields['MetaValue'] .'"';
return $metaString;
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"metaString",
"=",
"'#'",
";",
"$",
"metaString",
".=",
"$",
"this",
"->",
"fields",
"[",
"'MetaName'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"fields",
"[",
"'MetaValue'",
"]",
")",
")",
"$",
"metaString",
".=",
"'=\"'",
".",
"$",
"this",
"->",
"fields",
"[",
"'MetaValue'",
"]",
".",
"'\"'",
";",
"return",
"$",
"metaString",
";",
"}"
] | Returns the string representation of this MetaPartial
@return string | [
"Returns",
"the",
"string",
"representation",
"of",
"this",
"MetaPartial"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/model/MetaPartial.php#L131-L141 | train |
freialib/hlin.tools | src/Arr.php | Arr.join | static function join($glue, array $list, callable $manipulator) {
$glued = '';
foreach ($list as $key => $value) {
$item = $manipulator($key, $value);
if ($item !== false) {
$glued .= $glue.$item;
}
}
if ( ! empty($glued)) {
$glued = substr($glued, strlen($glue));
}
return $glued;
} | php | static function join($glue, array $list, callable $manipulator) {
$glued = '';
foreach ($list as $key => $value) {
$item = $manipulator($key, $value);
if ($item !== false) {
$glued .= $glue.$item;
}
}
if ( ! empty($glued)) {
$glued = substr($glued, strlen($glue));
}
return $glued;
} | [
"static",
"function",
"join",
"(",
"$",
"glue",
",",
"array",
"$",
"list",
",",
"callable",
"$",
"manipulator",
")",
"{",
"$",
"glued",
"=",
"''",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"item",
"=",
"$",
"manipulator",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"item",
"!==",
"false",
")",
"{",
"$",
"glued",
".=",
"$",
"glue",
".",
"$",
"item",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"glued",
")",
")",
"{",
"$",
"glued",
"=",
"substr",
"(",
"$",
"glued",
",",
"strlen",
"(",
"$",
"glue",
")",
")",
";",
"}",
"return",
"$",
"glued",
";",
"}"
] | PHP join with a callback
This is slightly different from implode($glue, array_map) in that it can
ignore entries if the entry in question passes false out.
@return string | [
"PHP",
"join",
"with",
"a",
"callback"
] | 42ad9e9fe081918d2ee5d52b72d174ccdcf7cbe7 | https://github.com/freialib/hlin.tools/blob/42ad9e9fe081918d2ee5d52b72d174ccdcf7cbe7/src/Arr.php#L18-L32 | train |
joegreen88/zf1-component-validate | src/Zend/Validate/Barcode.php | Zend_Validate_Barcode.setAdapter | public function setAdapter($adapter, $options = null)
{
$adapter = ucfirst(strtolower($adapter));
if (Zend_Loader::isReadable('Zend/Validate/Barcode/' . $adapter. '.php')) {
$adapter = 'Zend_Validate_Barcode_' . $adapter;
}
if (!class_exists($adapter)) {
Zend_Loader::loadClass($adapter);
}
$this->_adapter = new $adapter($options);
if (!$this->_adapter instanceof Zend_Validate_Barcode_AdapterInterface) {
throw new Zend_Validate_Exception(
"Adapter " . $adapter . " does not implement Zend_Validate_Barcode_AdapterInterface"
);
}
return $this;
} | php | public function setAdapter($adapter, $options = null)
{
$adapter = ucfirst(strtolower($adapter));
if (Zend_Loader::isReadable('Zend/Validate/Barcode/' . $adapter. '.php')) {
$adapter = 'Zend_Validate_Barcode_' . $adapter;
}
if (!class_exists($adapter)) {
Zend_Loader::loadClass($adapter);
}
$this->_adapter = new $adapter($options);
if (!$this->_adapter instanceof Zend_Validate_Barcode_AdapterInterface) {
throw new Zend_Validate_Exception(
"Adapter " . $adapter . " does not implement Zend_Validate_Barcode_AdapterInterface"
);
}
return $this;
} | [
"public",
"function",
"setAdapter",
"(",
"$",
"adapter",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"adapter",
"=",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"adapter",
")",
")",
";",
"if",
"(",
"Zend_Loader",
"::",
"isReadable",
"(",
"'Zend/Validate/Barcode/'",
".",
"$",
"adapter",
".",
"'.php'",
")",
")",
"{",
"$",
"adapter",
"=",
"'Zend_Validate_Barcode_'",
".",
"$",
"adapter",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"adapter",
")",
")",
"{",
"Zend_Loader",
"::",
"loadClass",
"(",
"$",
"adapter",
")",
";",
"}",
"$",
"this",
"->",
"_adapter",
"=",
"new",
"$",
"adapter",
"(",
"$",
"options",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_adapter",
"instanceof",
"Zend_Validate_Barcode_AdapterInterface",
")",
"{",
"throw",
"new",
"Zend_Validate_Exception",
"(",
"\"Adapter \"",
".",
"$",
"adapter",
".",
"\" does not implement Zend_Validate_Barcode_AdapterInterface\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets a new barcode adapter
@param string|Zend_Validate_Barcode $adapter Barcode adapter to use
@param array $options Options for this adapter
@return void
@throws Zend_Validate_Exception | [
"Sets",
"a",
"new",
"barcode",
"adapter"
] | 88d9ea016f73d48ff0ba7d06ecbbf28951fd279e | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Barcode.php#L132-L153 | train |
naucon/Utility | src/ObservableAbstract.php | ObservableAbstract.addObserver | public function addObserver(ObserverInterface $observerObject)
{
if (is_null($observerObject)) {
throw new ObservableException('Given observer is null.', E_WARNING);
} else {
$this->getObserverSetObject()->add($observerObject);
}
} | php | public function addObserver(ObserverInterface $observerObject)
{
if (is_null($observerObject)) {
throw new ObservableException('Given observer is null.', E_WARNING);
} else {
$this->getObserverSetObject()->add($observerObject);
}
} | [
"public",
"function",
"addObserver",
"(",
"ObserverInterface",
"$",
"observerObject",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"observerObject",
")",
")",
"{",
"throw",
"new",
"ObservableException",
"(",
"'Given observer is null.'",
",",
"E_WARNING",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getObserverSetObject",
"(",
")",
"->",
"add",
"(",
"$",
"observerObject",
")",
";",
"}",
"}"
] | add a observer to the observable
@param ObserverInterface $observerObject
@return void
@throws ObservableException | [
"add",
"a",
"observer",
"to",
"the",
"observable"
] | d225bb5d09d82400917f710c9d502949a66442c4 | https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/ObservableAbstract.php#L65-L72 | train |
naucon/Utility | src/ObservableAbstract.php | ObservableAbstract.notifyObservers | public function notifyObservers($arg = null)
{
if ($this->hasChanged()) {
foreach ($this->getObserverSetObject() as $observerObject) {
$observerObject->update($this, $arg);
}
$this->clearChanged();
}
} | php | public function notifyObservers($arg = null)
{
if ($this->hasChanged()) {
foreach ($this->getObserverSetObject() as $observerObject) {
$observerObject->update($this, $arg);
}
$this->clearChanged();
}
} | [
"public",
"function",
"notifyObservers",
"(",
"$",
"arg",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasChanged",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getObserverSetObject",
"(",
")",
"as",
"$",
"observerObject",
")",
"{",
"$",
"observerObject",
"->",
"update",
"(",
"$",
"this",
",",
"$",
"arg",
")",
";",
"}",
"$",
"this",
"->",
"clearChanged",
"(",
")",
";",
"}",
"}"
] | notify all observer
@param mixed $arg optional argument
@return void | [
"notify",
"all",
"observer"
] | d225bb5d09d82400917f710c9d502949a66442c4 | https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/ObservableAbstract.php#L111-L119 | train |
Linkvalue-Interne/MobileNotifBundle | DependencyInjection/LinkValueMobileNotifExtension.php | LinkValueMobileNotifExtension.registerClients | private function registerClients(array $config, ContainerBuilder $container)
{
foreach ($config['clients'] as $clientType => $clients) {
$clientFQCN = ($clientType == 'apns') ? 'LinkValue\MobileNotifBundle\Client\ApnsClient' : 'LinkValue\MobileNotifBundle\Client\GcmClient';
foreach ($clients as $clientName => $clientConfig) {
$params = isset($clientConfig['params']) ? $clientConfig['params'] : array();
$services = isset($clientConfig['services']) ? $clientConfig['services'] : array();
// The final client name is a concatenation of the client type (apns/gcm) and the client name (defined by user) separated by a point '.'
$clientName = sprintf('%s.%s', $clientType, $clientName);
// Register client with required stuff
$client = $container->register(sprintf('link_value_mobile_notif.clients.%s', $clientName), $clientFQCN)
->addMethodCall('setUp', array($params))
->addTag('link_value_mobile_notif.client', array('name' => $clientName))
;
// Set optional logger
if(!empty($services['logger'])) {
$client->addMethodCall('setLogger', array(new Reference($services['logger'])));
}
// Set optional profiler
if(!empty($services['profiler'])) {
$client->addMethodCall('setClientProfiler', array(new Reference($services['profiler'])));
}
}
}
} | php | private function registerClients(array $config, ContainerBuilder $container)
{
foreach ($config['clients'] as $clientType => $clients) {
$clientFQCN = ($clientType == 'apns') ? 'LinkValue\MobileNotifBundle\Client\ApnsClient' : 'LinkValue\MobileNotifBundle\Client\GcmClient';
foreach ($clients as $clientName => $clientConfig) {
$params = isset($clientConfig['params']) ? $clientConfig['params'] : array();
$services = isset($clientConfig['services']) ? $clientConfig['services'] : array();
// The final client name is a concatenation of the client type (apns/gcm) and the client name (defined by user) separated by a point '.'
$clientName = sprintf('%s.%s', $clientType, $clientName);
// Register client with required stuff
$client = $container->register(sprintf('link_value_mobile_notif.clients.%s', $clientName), $clientFQCN)
->addMethodCall('setUp', array($params))
->addTag('link_value_mobile_notif.client', array('name' => $clientName))
;
// Set optional logger
if(!empty($services['logger'])) {
$client->addMethodCall('setLogger', array(new Reference($services['logger'])));
}
// Set optional profiler
if(!empty($services['profiler'])) {
$client->addMethodCall('setClientProfiler', array(new Reference($services['profiler'])));
}
}
}
} | [
"private",
"function",
"registerClients",
"(",
"array",
"$",
"config",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"config",
"[",
"'clients'",
"]",
"as",
"$",
"clientType",
"=>",
"$",
"clients",
")",
"{",
"$",
"clientFQCN",
"=",
"(",
"$",
"clientType",
"==",
"'apns'",
")",
"?",
"'LinkValue\\MobileNotifBundle\\Client\\ApnsClient'",
":",
"'LinkValue\\MobileNotifBundle\\Client\\GcmClient'",
";",
"foreach",
"(",
"$",
"clients",
"as",
"$",
"clientName",
"=>",
"$",
"clientConfig",
")",
"{",
"$",
"params",
"=",
"isset",
"(",
"$",
"clientConfig",
"[",
"'params'",
"]",
")",
"?",
"$",
"clientConfig",
"[",
"'params'",
"]",
":",
"array",
"(",
")",
";",
"$",
"services",
"=",
"isset",
"(",
"$",
"clientConfig",
"[",
"'services'",
"]",
")",
"?",
"$",
"clientConfig",
"[",
"'services'",
"]",
":",
"array",
"(",
")",
";",
"// The final client name is a concatenation of the client type (apns/gcm) and the client name (defined by user) separated by a point '.'",
"$",
"clientName",
"=",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"clientType",
",",
"$",
"clientName",
")",
";",
"// Register client with required stuff",
"$",
"client",
"=",
"$",
"container",
"->",
"register",
"(",
"sprintf",
"(",
"'link_value_mobile_notif.clients.%s'",
",",
"$",
"clientName",
")",
",",
"$",
"clientFQCN",
")",
"->",
"addMethodCall",
"(",
"'setUp'",
",",
"array",
"(",
"$",
"params",
")",
")",
"->",
"addTag",
"(",
"'link_value_mobile_notif.client'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"clientName",
")",
")",
";",
"// Set optional logger",
"if",
"(",
"!",
"empty",
"(",
"$",
"services",
"[",
"'logger'",
"]",
")",
")",
"{",
"$",
"client",
"->",
"addMethodCall",
"(",
"'setLogger'",
",",
"array",
"(",
"new",
"Reference",
"(",
"$",
"services",
"[",
"'logger'",
"]",
")",
")",
")",
";",
"}",
"// Set optional profiler",
"if",
"(",
"!",
"empty",
"(",
"$",
"services",
"[",
"'profiler'",
"]",
")",
")",
"{",
"$",
"client",
"->",
"addMethodCall",
"(",
"'setClientProfiler'",
",",
"array",
"(",
"new",
"Reference",
"(",
"$",
"services",
"[",
"'profiler'",
"]",
")",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Register each client as service, such as "link_value_mobile_notif.clients.the_client_type.my_custom_client_name"
@param array $config
@param ContainerBuilder $container | [
"Register",
"each",
"client",
"as",
"service",
"such",
"as",
"link_value_mobile_notif",
".",
"clients",
".",
"the_client_type",
".",
"my_custom_client_name"
] | 8124f4132c581516be9928ece81ae2cf9f59763d | https://github.com/Linkvalue-Interne/MobileNotifBundle/blob/8124f4132c581516be9928ece81ae2cf9f59763d/DependencyInjection/LinkValueMobileNotifExtension.php#L36-L65 | train |
wearenolte/wp-endpoints-static | src/StaticApi/GravityForms.php | GravityForms.get_settings | public static function get_settings() {
// If the gforms plugin is not active.
if ( ! class_exists( 'GFWebAPI' ) ) {
return false;
}
$settings = get_option( 'gravityformsaddon_gravityformswebapi_settings' );
// If the API is not enabled.
if ( empty( $settings ) || ! $settings['enabled'] ) {
return false;
}
$forms = [];
$method = 'GET';
$expires = strtotime( self::SIGNATURE_EXPIRY );
foreach ( \GFAPI::get_forms() as $form ) {
$get_form_route = 'forms/' . $form['id'];
$string_to_sign = sprintf( '%s:%s:%s:%s', $settings['public_key'], $method, $get_form_route, $expires );
$forms[ $form['id'] ] = [
'get_form' => [
'route' => $get_form_route,
'expires' => $expires,
'signature' => self::calculate_signature( $string_to_sign, $settings['private_key'] ),
],
'post_submission' => [
'route' => 'forms/' . $form['id'] . '/submissions',
],
];
}
return [
'api_base' => GFWEBAPI_API_BASE_URL,
'api_key' => $settings['public_key'],
'forms' => $forms,
];
} | php | public static function get_settings() {
// If the gforms plugin is not active.
if ( ! class_exists( 'GFWebAPI' ) ) {
return false;
}
$settings = get_option( 'gravityformsaddon_gravityformswebapi_settings' );
// If the API is not enabled.
if ( empty( $settings ) || ! $settings['enabled'] ) {
return false;
}
$forms = [];
$method = 'GET';
$expires = strtotime( self::SIGNATURE_EXPIRY );
foreach ( \GFAPI::get_forms() as $form ) {
$get_form_route = 'forms/' . $form['id'];
$string_to_sign = sprintf( '%s:%s:%s:%s', $settings['public_key'], $method, $get_form_route, $expires );
$forms[ $form['id'] ] = [
'get_form' => [
'route' => $get_form_route,
'expires' => $expires,
'signature' => self::calculate_signature( $string_to_sign, $settings['private_key'] ),
],
'post_submission' => [
'route' => 'forms/' . $form['id'] . '/submissions',
],
];
}
return [
'api_base' => GFWEBAPI_API_BASE_URL,
'api_key' => $settings['public_key'],
'forms' => $forms,
];
} | [
"public",
"static",
"function",
"get_settings",
"(",
")",
"{",
"// If the gforms plugin is not active.",
"if",
"(",
"!",
"class_exists",
"(",
"'GFWebAPI'",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"settings",
"=",
"get_option",
"(",
"'gravityformsaddon_gravityformswebapi_settings'",
")",
";",
"// If the API is not enabled.",
"if",
"(",
"empty",
"(",
"$",
"settings",
")",
"||",
"!",
"$",
"settings",
"[",
"'enabled'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"$",
"forms",
"=",
"[",
"]",
";",
"$",
"method",
"=",
"'GET'",
";",
"$",
"expires",
"=",
"strtotime",
"(",
"self",
"::",
"SIGNATURE_EXPIRY",
")",
";",
"foreach",
"(",
"\\",
"GFAPI",
"::",
"get_forms",
"(",
")",
"as",
"$",
"form",
")",
"{",
"$",
"get_form_route",
"=",
"'forms/'",
".",
"$",
"form",
"[",
"'id'",
"]",
";",
"$",
"string_to_sign",
"=",
"sprintf",
"(",
"'%s:%s:%s:%s'",
",",
"$",
"settings",
"[",
"'public_key'",
"]",
",",
"$",
"method",
",",
"$",
"get_form_route",
",",
"$",
"expires",
")",
";",
"$",
"forms",
"[",
"$",
"form",
"[",
"'id'",
"]",
"]",
"=",
"[",
"'get_form'",
"=>",
"[",
"'route'",
"=>",
"$",
"get_form_route",
",",
"'expires'",
"=>",
"$",
"expires",
",",
"'signature'",
"=>",
"self",
"::",
"calculate_signature",
"(",
"$",
"string_to_sign",
",",
"$",
"settings",
"[",
"'private_key'",
"]",
")",
",",
"]",
",",
"'post_submission'",
"=>",
"[",
"'route'",
"=>",
"'forms/'",
".",
"$",
"form",
"[",
"'id'",
"]",
".",
"'/submissions'",
",",
"]",
",",
"]",
";",
"}",
"return",
"[",
"'api_base'",
"=>",
"GFWEBAPI_API_BASE_URL",
",",
"'api_key'",
"=>",
"$",
"settings",
"[",
"'public_key'",
"]",
",",
"'forms'",
"=>",
"$",
"forms",
",",
"]",
";",
"}"
] | Get the settings need to Gravity Forms. | [
"Get",
"the",
"settings",
"need",
"to",
"Gravity",
"Forms",
"."
] | 23258bba9b65d55b78b3dc3edc123d75009b0825 | https://github.com/wearenolte/wp-endpoints-static/blob/23258bba9b65d55b78b3dc3edc123d75009b0825/src/StaticApi/GravityForms.php#L14-L56 | train |
wearenolte/wp-endpoints-static | src/StaticApi/GravityForms.php | GravityForms.calculate_signature | private static function calculate_signature( $string, $private_key ) {
$hash = hash_hmac( 'sha1', $string, $private_key, true );
return rawurlencode( base64_encode( $hash ) );
} | php | private static function calculate_signature( $string, $private_key ) {
$hash = hash_hmac( 'sha1', $string, $private_key, true );
return rawurlencode( base64_encode( $hash ) );
} | [
"private",
"static",
"function",
"calculate_signature",
"(",
"$",
"string",
",",
"$",
"private_key",
")",
"{",
"$",
"hash",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"string",
",",
"$",
"private_key",
",",
"true",
")",
";",
"return",
"rawurlencode",
"(",
"base64_encode",
"(",
"$",
"hash",
")",
")",
";",
"}"
] | Get the signature.
@param string $string The string to sign.
@param string $private_key The private key to sign it with.
@return string | [
"Get",
"the",
"signature",
"."
] | 23258bba9b65d55b78b3dc3edc123d75009b0825 | https://github.com/wearenolte/wp-endpoints-static/blob/23258bba9b65d55b78b3dc3edc123d75009b0825/src/StaticApi/GravityForms.php#L65-L69 | train |
FuzeWorks/Core | src/FuzeWorks/Layout.php | Layout.display | public function display($file, $directory = null, $directOutput = false)
{
$output = Factory::getInstance()->output;
$directory = (is_null($directory) ? $this->directory : $directory);
if ($directOutput === true)
{
echo $this->get($file, $directory);
}
else
{
$output->append_output($this->get($file, $directory));
}
return;
} | php | public function display($file, $directory = null, $directOutput = false)
{
$output = Factory::getInstance()->output;
$directory = (is_null($directory) ? $this->directory : $directory);
if ($directOutput === true)
{
echo $this->get($file, $directory);
}
else
{
$output->append_output($this->get($file, $directory));
}
return;
} | [
"public",
"function",
"display",
"(",
"$",
"file",
",",
"$",
"directory",
"=",
"null",
",",
"$",
"directOutput",
"=",
"false",
")",
"{",
"$",
"output",
"=",
"Factory",
"::",
"getInstance",
"(",
")",
"->",
"output",
";",
"$",
"directory",
"=",
"(",
"is_null",
"(",
"$",
"directory",
")",
"?",
"$",
"this",
"->",
"directory",
":",
"$",
"directory",
")",
";",
"if",
"(",
"$",
"directOutput",
"===",
"true",
")",
"{",
"echo",
"$",
"this",
"->",
"get",
"(",
"$",
"file",
",",
"$",
"directory",
")",
";",
"}",
"else",
"{",
"$",
"output",
"->",
"append_output",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"file",
",",
"$",
"directory",
")",
")",
";",
"}",
"return",
";",
"}"
] | Retrieve a template file using a string and a directory and immediatly parse it to the output class.
What template file gets loaded depends on the template engine that is being used.
PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/layout.dashboard.php file.
You can also provide no particular engine, and the manager will decide what template to load.
Remember that doing so will result in a LayoutException when multiple compatible files are found.
@param string $file File to load
@param string $directory Directory to load it from
@param bool $directOutput Whether to directly output the result with an echo or send it to the output class. True if echo
@throws LayoutException On error | [
"Retrieve",
"a",
"template",
"file",
"using",
"a",
"string",
"and",
"a",
"directory",
"and",
"immediatly",
"parse",
"it",
"to",
"the",
"output",
"class",
"."
] | 051c64fdaa3a648174cbd54557d05ad553dd826b | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Layout.php#L114-L129 | train |
FuzeWorks/Core | src/FuzeWorks/Layout.php | Layout.get | public function get($file, $directory = null): string
{
$directory = (is_null($directory) ? $this->directory : $directory);
Logger::newLevel("Loading template file '".$file."' in '".$directory."'");
// First load the template engines
$this->loadTemplateEngines();
// First retrieve the filepath
if (is_null($this->current_engine)) {
$this->setFileFromString($file, $directory, array_keys($this->file_extensions));
} else {
$this->setFileFromString($file, $directory, $this->current_engine->getFileExtensions());
}
// Then assign some basic variables for the template
$main_config = Factory::getInstance()->config->get('main');
$contact_config = Factory::getInstance()->config->get('contact');
$this->assigned_variables['wwwDir'] = $main_config->base_url;
$this->assigned_variables['siteURL'] = $main_config->base_url;
$this->assigned_variables['serverName'] = $main_config->server_name;
$this->assigned_variables['adminMail'] = $main_config->administrator_mail;
$this->assigned_variables['contact'] = $contact_config->toArray();
$this->assigned_variables['csrfTokenName'] = Factory::getInstance()->security->get_csrf_token_name();
$this->assigned_variables['csrfHash'] = Factory::getInstance()->security->get_csrf_hash();
// Select an engine if one is not already selected
if (is_null($this->current_engine)) {
$this->current_engine = $this->getEngineFromExtension($this->getExtensionFromFile($this->file));
}
$this->current_engine->setDirectory($this->directory);
// And run an Event to see what other parts have to say about it
$event = Events::fireEvent('layoutLoadEvent', $this->file, $this->directory, $this->current_engine, $this->assigned_variables);
// The event has been cancelled
if ($event->isCancelled()) {
return false;
}
// And refetch the data from the event
$this->current_engine = $event->engine;
$this->assigned_variables = $event->assigned_variables;
Logger::stopLevel();
// And finally run it
if (file_exists($event->file)) {
return $this->current_engine->get($event->file, $this->assigned_variables);
}
throw new LayoutException('The requested file was not found', 1);
} | php | public function get($file, $directory = null): string
{
$directory = (is_null($directory) ? $this->directory : $directory);
Logger::newLevel("Loading template file '".$file."' in '".$directory."'");
// First load the template engines
$this->loadTemplateEngines();
// First retrieve the filepath
if (is_null($this->current_engine)) {
$this->setFileFromString($file, $directory, array_keys($this->file_extensions));
} else {
$this->setFileFromString($file, $directory, $this->current_engine->getFileExtensions());
}
// Then assign some basic variables for the template
$main_config = Factory::getInstance()->config->get('main');
$contact_config = Factory::getInstance()->config->get('contact');
$this->assigned_variables['wwwDir'] = $main_config->base_url;
$this->assigned_variables['siteURL'] = $main_config->base_url;
$this->assigned_variables['serverName'] = $main_config->server_name;
$this->assigned_variables['adminMail'] = $main_config->administrator_mail;
$this->assigned_variables['contact'] = $contact_config->toArray();
$this->assigned_variables['csrfTokenName'] = Factory::getInstance()->security->get_csrf_token_name();
$this->assigned_variables['csrfHash'] = Factory::getInstance()->security->get_csrf_hash();
// Select an engine if one is not already selected
if (is_null($this->current_engine)) {
$this->current_engine = $this->getEngineFromExtension($this->getExtensionFromFile($this->file));
}
$this->current_engine->setDirectory($this->directory);
// And run an Event to see what other parts have to say about it
$event = Events::fireEvent('layoutLoadEvent', $this->file, $this->directory, $this->current_engine, $this->assigned_variables);
// The event has been cancelled
if ($event->isCancelled()) {
return false;
}
// And refetch the data from the event
$this->current_engine = $event->engine;
$this->assigned_variables = $event->assigned_variables;
Logger::stopLevel();
// And finally run it
if (file_exists($event->file)) {
return $this->current_engine->get($event->file, $this->assigned_variables);
}
throw new LayoutException('The requested file was not found', 1);
} | [
"public",
"function",
"get",
"(",
"$",
"file",
",",
"$",
"directory",
"=",
"null",
")",
":",
"string",
"{",
"$",
"directory",
"=",
"(",
"is_null",
"(",
"$",
"directory",
")",
"?",
"$",
"this",
"->",
"directory",
":",
"$",
"directory",
")",
";",
"Logger",
"::",
"newLevel",
"(",
"\"Loading template file '\"",
".",
"$",
"file",
".",
"\"' in '\"",
".",
"$",
"directory",
".",
"\"'\"",
")",
";",
"// First load the template engines",
"$",
"this",
"->",
"loadTemplateEngines",
"(",
")",
";",
"// First retrieve the filepath",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"current_engine",
")",
")",
"{",
"$",
"this",
"->",
"setFileFromString",
"(",
"$",
"file",
",",
"$",
"directory",
",",
"array_keys",
"(",
"$",
"this",
"->",
"file_extensions",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setFileFromString",
"(",
"$",
"file",
",",
"$",
"directory",
",",
"$",
"this",
"->",
"current_engine",
"->",
"getFileExtensions",
"(",
")",
")",
";",
"}",
"// Then assign some basic variables for the template",
"$",
"main_config",
"=",
"Factory",
"::",
"getInstance",
"(",
")",
"->",
"config",
"->",
"get",
"(",
"'main'",
")",
";",
"$",
"contact_config",
"=",
"Factory",
"::",
"getInstance",
"(",
")",
"->",
"config",
"->",
"get",
"(",
"'contact'",
")",
";",
"$",
"this",
"->",
"assigned_variables",
"[",
"'wwwDir'",
"]",
"=",
"$",
"main_config",
"->",
"base_url",
";",
"$",
"this",
"->",
"assigned_variables",
"[",
"'siteURL'",
"]",
"=",
"$",
"main_config",
"->",
"base_url",
";",
"$",
"this",
"->",
"assigned_variables",
"[",
"'serverName'",
"]",
"=",
"$",
"main_config",
"->",
"server_name",
";",
"$",
"this",
"->",
"assigned_variables",
"[",
"'adminMail'",
"]",
"=",
"$",
"main_config",
"->",
"administrator_mail",
";",
"$",
"this",
"->",
"assigned_variables",
"[",
"'contact'",
"]",
"=",
"$",
"contact_config",
"->",
"toArray",
"(",
")",
";",
"$",
"this",
"->",
"assigned_variables",
"[",
"'csrfTokenName'",
"]",
"=",
"Factory",
"::",
"getInstance",
"(",
")",
"->",
"security",
"->",
"get_csrf_token_name",
"(",
")",
";",
"$",
"this",
"->",
"assigned_variables",
"[",
"'csrfHash'",
"]",
"=",
"Factory",
"::",
"getInstance",
"(",
")",
"->",
"security",
"->",
"get_csrf_hash",
"(",
")",
";",
"// Select an engine if one is not already selected",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"current_engine",
")",
")",
"{",
"$",
"this",
"->",
"current_engine",
"=",
"$",
"this",
"->",
"getEngineFromExtension",
"(",
"$",
"this",
"->",
"getExtensionFromFile",
"(",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"$",
"this",
"->",
"current_engine",
"->",
"setDirectory",
"(",
"$",
"this",
"->",
"directory",
")",
";",
"// And run an Event to see what other parts have to say about it",
"$",
"event",
"=",
"Events",
"::",
"fireEvent",
"(",
"'layoutLoadEvent'",
",",
"$",
"this",
"->",
"file",
",",
"$",
"this",
"->",
"directory",
",",
"$",
"this",
"->",
"current_engine",
",",
"$",
"this",
"->",
"assigned_variables",
")",
";",
"// The event has been cancelled",
"if",
"(",
"$",
"event",
"->",
"isCancelled",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// And refetch the data from the event",
"$",
"this",
"->",
"current_engine",
"=",
"$",
"event",
"->",
"engine",
";",
"$",
"this",
"->",
"assigned_variables",
"=",
"$",
"event",
"->",
"assigned_variables",
";",
"Logger",
"::",
"stopLevel",
"(",
")",
";",
"// And finally run it",
"if",
"(",
"file_exists",
"(",
"$",
"event",
"->",
"file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"current_engine",
"->",
"get",
"(",
"$",
"event",
"->",
"file",
",",
"$",
"this",
"->",
"assigned_variables",
")",
";",
"}",
"throw",
"new",
"LayoutException",
"(",
"'The requested file was not found'",
",",
"1",
")",
";",
"}"
] | Retrieve a template file using a string and a directory.
What template file gets loaded depends on the template engine that is being used.
PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/layout.dashboard.php file.
You can also provide no particular engine, and the manager will decide what template to load.
Remember that doing so will result in a LayoutException when multiple compatible files are found.
@param string $file File to load
@param string $directory Directory to load it from
@return string The output of the template
@throws LayoutException On error | [
"Retrieve",
"a",
"template",
"file",
"using",
"a",
"string",
"and",
"a",
"directory",
"."
] | 051c64fdaa3a648174cbd54557d05ad553dd826b | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Layout.php#L146-L199 | train |
FuzeWorks/Core | src/FuzeWorks/Layout.php | Layout.getEngineFromExtension | public function getEngineFromExtension($extension): TemplateEngine
{
if (isset($this->file_extensions[strtolower($extension)])) {
return $this->engines[ $this->file_extensions[strtolower($extension)]];
}
throw new LayoutException('Could not get Template Engine. No engine has corresponding file extension', 1);
} | php | public function getEngineFromExtension($extension): TemplateEngine
{
if (isset($this->file_extensions[strtolower($extension)])) {
return $this->engines[ $this->file_extensions[strtolower($extension)]];
}
throw new LayoutException('Could not get Template Engine. No engine has corresponding file extension', 1);
} | [
"public",
"function",
"getEngineFromExtension",
"(",
"$",
"extension",
")",
":",
"TemplateEngine",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"file_extensions",
"[",
"strtolower",
"(",
"$",
"extension",
")",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"engines",
"[",
"$",
"this",
"->",
"file_extensions",
"[",
"strtolower",
"(",
"$",
"extension",
")",
"]",
"]",
";",
"}",
"throw",
"new",
"LayoutException",
"(",
"'Could not get Template Engine. No engine has corresponding file extension'",
",",
"1",
")",
";",
"}"
] | Retrieve a Template Engine from a File Extension.
@param string $extension File extention to look for
@return TemplateEngine | [
"Retrieve",
"a",
"Template",
"Engine",
"from",
"a",
"File",
"Extension",
"."
] | 051c64fdaa3a648174cbd54557d05ad553dd826b | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Layout.php#L208-L215 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.