id
int32 0
241k
| 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
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
25,100
|
locomotivemtl/charcoal-translator
|
src/Charcoal/Translator/Translation.php
|
Translation.sanitize
|
public function sanitize(callable $sanitizeCallback)
{
foreach ($this->val as $lang => $val) {
$this->val[$lang] = call_user_func($sanitizeCallback, $val);
}
return $this;
}
|
php
|
public function sanitize(callable $sanitizeCallback)
{
foreach ($this->val as $lang => $val) {
$this->val[$lang] = call_user_func($sanitizeCallback, $val);
}
return $this;
}
|
[
"public",
"function",
"sanitize",
"(",
"callable",
"$",
"sanitizeCallback",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"val",
"as",
"$",
"lang",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"val",
"[",
"$",
"lang",
"]",
"=",
"call_user_func",
"(",
"$",
"sanitizeCallback",
",",
"$",
"val",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sanitize each language's string with a callback function.
The callback method signature is to take a string as parameter and return the sanitized string.
@param callable $sanitizeCallback The sanitizing function callback.
@return self
|
[
"Sanitize",
"each",
"language",
"s",
"string",
"with",
"a",
"callback",
"function",
"."
] |
0a64432baef223dcccbfecf057015440dfa76e49
|
https://github.com/locomotivemtl/charcoal-translator/blob/0a64432baef223dcccbfecf057015440dfa76e49/src/Charcoal/Translator/Translation.php#L178-L184
|
25,101
|
dms-org/common.structure
|
src/DateTime/DayOfWeek.php
|
DayOfWeek.weekdays
|
public static function weekdays() : array
{
$days = self::getAll();
$weekDays = [];
foreach ($days as $key => $day) {
if ($day->isWeekDay()) {
$weekDays[] = $day;
}
}
return $weekDays;
}
|
php
|
public static function weekdays() : array
{
$days = self::getAll();
$weekDays = [];
foreach ($days as $key => $day) {
if ($day->isWeekDay()) {
$weekDays[] = $day;
}
}
return $weekDays;
}
|
[
"public",
"static",
"function",
"weekdays",
"(",
")",
":",
"array",
"{",
"$",
"days",
"=",
"self",
"::",
"getAll",
"(",
")",
";",
"$",
"weekDays",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"days",
"as",
"$",
"key",
"=>",
"$",
"day",
")",
"{",
"if",
"(",
"$",
"day",
"->",
"isWeekDay",
"(",
")",
")",
"{",
"$",
"weekDays",
"[",
"]",
"=",
"$",
"day",
";",
"}",
"}",
"return",
"$",
"weekDays",
";",
"}"
] |
Gets the weekdays.
@return DayOfWeek[]
|
[
"Gets",
"the",
"weekdays",
"."
] |
23f122182f60df5ec847047a81a39c8aab019ff1
|
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/DayOfWeek.php#L123-L135
|
25,102
|
dms-org/common.structure
|
src/DateTime/DayOfWeek.php
|
DayOfWeek.weekends
|
public static function weekends() : array
{
$days = self::getAll();
$weekEndDays = [];
foreach ($days as $key => $day) {
if ($day->isWeekEnd()) {
$weekEndDays[] = $day;
}
}
return $weekEndDays;
}
|
php
|
public static function weekends() : array
{
$days = self::getAll();
$weekEndDays = [];
foreach ($days as $key => $day) {
if ($day->isWeekEnd()) {
$weekEndDays[] = $day;
}
}
return $weekEndDays;
}
|
[
"public",
"static",
"function",
"weekends",
"(",
")",
":",
"array",
"{",
"$",
"days",
"=",
"self",
"::",
"getAll",
"(",
")",
";",
"$",
"weekEndDays",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"days",
"as",
"$",
"key",
"=>",
"$",
"day",
")",
"{",
"if",
"(",
"$",
"day",
"->",
"isWeekEnd",
"(",
")",
")",
"{",
"$",
"weekEndDays",
"[",
"]",
"=",
"$",
"day",
";",
"}",
"}",
"return",
"$",
"weekEndDays",
";",
"}"
] |
Gets the weekend days.
@return DayOfWeek[]
|
[
"Gets",
"the",
"weekend",
"days",
"."
] |
23f122182f60df5ec847047a81a39c8aab019ff1
|
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/DayOfWeek.php#L142-L154
|
25,103
|
codeinchq/psr7-responses
|
src/HttpProxyResponse.php
|
HttpProxyResponse.getResponse
|
public function getResponse():ResponseInterface
{
if (!$this->response) {
$this->response = (new Client())->request('GET', $this->remoteUrl);
}
return $this->response;
}
|
php
|
public function getResponse():ResponseInterface
{
if (!$this->response) {
$this->response = (new Client())->request('GET', $this->remoteUrl);
}
return $this->response;
}
|
[
"public",
"function",
"getResponse",
"(",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"response",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"(",
"new",
"Client",
"(",
")",
")",
"->",
"request",
"(",
"'GET'",
",",
"$",
"this",
"->",
"remoteUrl",
")",
";",
"}",
"return",
"$",
"this",
"->",
"response",
";",
"}"
] |
Returns the HTTP response.
@return ResponseInterface
@throws \GuzzleHttp\Exception\GuzzleException
|
[
"Returns",
"the",
"HTTP",
"response",
"."
] |
d4bb6bc9b4219694e7c1f5ee9b40b75b22362fce
|
https://github.com/codeinchq/psr7-responses/blob/d4bb6bc9b4219694e7c1f5ee9b40b75b22362fce/src/HttpProxyResponse.php#L97-L103
|
25,104
|
codeinchq/psr7-responses
|
src/HttpProxyResponse.php
|
HttpProxyResponse.getResponseHeaders
|
public function getResponseHeaders():array
{
$headers = [];
foreach ($this->getResponse()->getHeaders() as $header => $values) {
if (preg_grep('/^'.preg_quote($header, '$/').'/ui', $this->acceptableProxyHeaders)) {
$headers[$header] = $values;
}
}
return $headers;
}
|
php
|
public function getResponseHeaders():array
{
$headers = [];
foreach ($this->getResponse()->getHeaders() as $header => $values) {
if (preg_grep('/^'.preg_quote($header, '$/').'/ui', $this->acceptableProxyHeaders)) {
$headers[$header] = $values;
}
}
return $headers;
}
|
[
"public",
"function",
"getResponseHeaders",
"(",
")",
":",
"array",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"header",
"=>",
"$",
"values",
")",
"{",
"if",
"(",
"preg_grep",
"(",
"'/^'",
".",
"preg_quote",
"(",
"$",
"header",
",",
"'$/'",
")",
".",
"'/ui'",
",",
"$",
"this",
"->",
"acceptableProxyHeaders",
")",
")",
"{",
"$",
"headers",
"[",
"$",
"header",
"]",
"=",
"$",
"values",
";",
"}",
"}",
"return",
"$",
"headers",
";",
"}"
] |
Returns all the imported headers from the HTTP response.
@return array
@throws \GuzzleHttp\Exception\GuzzleException
|
[
"Returns",
"all",
"the",
"imported",
"headers",
"from",
"the",
"HTTP",
"response",
"."
] |
d4bb6bc9b4219694e7c1f5ee9b40b75b22362fce
|
https://github.com/codeinchq/psr7-responses/blob/d4bb6bc9b4219694e7c1f5ee9b40b75b22362fce/src/HttpProxyResponse.php#L111-L120
|
25,105
|
libreworks/caridea-container
|
src/Properties.php
|
Properties.typeof
|
protected static function typeof($v): string
{
if (is_bool($v)) {
return 'bool';
} elseif (is_int($v)) {
return 'int';
} elseif (is_float($v)) {
return 'float';
} elseif (is_string($v)) {
return 'string';
} elseif (is_array($v)) {
return 'array';
} elseif (is_resource($v)) {
return 'resource';
}
return get_class($v);
}
|
php
|
protected static function typeof($v): string
{
if (is_bool($v)) {
return 'bool';
} elseif (is_int($v)) {
return 'int';
} elseif (is_float($v)) {
return 'float';
} elseif (is_string($v)) {
return 'string';
} elseif (is_array($v)) {
return 'array';
} elseif (is_resource($v)) {
return 'resource';
}
return get_class($v);
}
|
[
"protected",
"static",
"function",
"typeof",
"(",
"$",
"v",
")",
":",
"string",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'bool'",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'int'",
";",
"}",
"elseif",
"(",
"is_float",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'float'",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'string'",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'array'",
";",
"}",
"elseif",
"(",
"is_resource",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'resource'",
";",
"}",
"return",
"get_class",
"(",
"$",
"v",
")",
";",
"}"
] |
More predictable results than `gettype`.
@param mixed $v The value to evaluate
|
[
"More",
"predictable",
"results",
"than",
"gettype",
"."
] |
b93087ff5bf49f5885025da691575093335bfe8f
|
https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Properties.php#L76-L92
|
25,106
|
ARCANESOFT/Auth
|
src/Models/User.php
|
User.scopeProtectAdmins
|
public function scopeProtectAdmins(Builder $query)
{
/** @var self $user */
$user = auth()->user();
return ($user && $user->is_admin)
? $query
: $query->where('is_admin', false);
}
|
php
|
public function scopeProtectAdmins(Builder $query)
{
/** @var self $user */
$user = auth()->user();
return ($user && $user->is_admin)
? $query
: $query->where('is_admin', false);
}
|
[
"public",
"function",
"scopeProtectAdmins",
"(",
"Builder",
"$",
"query",
")",
"{",
"/** @var self $user */",
"$",
"user",
"=",
"auth",
"(",
")",
"->",
"user",
"(",
")",
";",
"return",
"(",
"$",
"user",
"&&",
"$",
"user",
"->",
"is_admin",
")",
"?",
"$",
"query",
":",
"$",
"query",
"->",
"where",
"(",
"'is_admin'",
",",
"false",
")",
";",
"}"
] |
Protect admins.
@param \Illuminate\Database\Eloquent\Builder $query
@return \Illuminate\Database\Eloquent\Builder
|
[
"Protect",
"admins",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Models/User.php#L53-L61
|
25,107
|
mrbase/Smesg
|
src/Smesg/Provider/UnwireProvider.php
|
UnwireProvider.getDefaultValues
|
public function getDefaultValues()
{
preg_match('/([0-9.]+)([A-Z]{3})/', $this->config['price'], $matches);
$this->defaults['price'] = array(
'currency' => (!empty($this->defaults['price']['currency']) ? $this->defaults['price']['currency'] : $matches[2]),
'amount' => (!empty($this->defaults['price']['amount']) ? $this->defaults['price']['amount'] : $matches[1]),
'vat' => (!empty($this->defaults['price']['vat']) ? $this->defaults['price']['vat'] : null),
);
return $this->defaults;
}
|
php
|
public function getDefaultValues()
{
preg_match('/([0-9.]+)([A-Z]{3})/', $this->config['price'], $matches);
$this->defaults['price'] = array(
'currency' => (!empty($this->defaults['price']['currency']) ? $this->defaults['price']['currency'] : $matches[2]),
'amount' => (!empty($this->defaults['price']['amount']) ? $this->defaults['price']['amount'] : $matches[1]),
'vat' => (!empty($this->defaults['price']['vat']) ? $this->defaults['price']['vat'] : null),
);
return $this->defaults;
}
|
[
"public",
"function",
"getDefaultValues",
"(",
")",
"{",
"preg_match",
"(",
"'/([0-9.]+)([A-Z]{3})/'",
",",
"$",
"this",
"->",
"config",
"[",
"'price'",
"]",
",",
"$",
"matches",
")",
";",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"=",
"array",
"(",
"'currency'",
"=>",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'currency'",
"]",
")",
"?",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'currency'",
"]",
":",
"$",
"matches",
"[",
"2",
"]",
")",
",",
"'amount'",
"=>",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'amount'",
"]",
")",
"?",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'amount'",
"]",
":",
"$",
"matches",
"[",
"1",
"]",
")",
",",
"'vat'",
"=>",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'vat'",
"]",
")",
"?",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'vat'",
"]",
":",
"null",
")",
",",
")",
";",
"return",
"$",
"this",
"->",
"defaults",
";",
"}"
] |
Return default values.
@return array
|
[
"Return",
"default",
"values",
"."
] |
e9692ed5915f5a9cd4dca0df875935a2c528e128
|
https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Provider/UnwireProvider.php#L130-L141
|
25,108
|
mrbase/Smesg
|
src/Smesg/Provider/UnwireProvider.php
|
UnwireProvider.getSmsc
|
protected function getSmsc($number)
{
$adapter = $this->getAdapter();
$adapter->setEndpoint(self::SMSC_ENDPOINT);
$adapter->setParameters(array(
'user' => $this->config['user'],
'password' => $this->config['password'],
'msisdn' => $number
));
$response = $adapter->get();
return $response->getBody();
}
|
php
|
protected function getSmsc($number)
{
$adapter = $this->getAdapter();
$adapter->setEndpoint(self::SMSC_ENDPOINT);
$adapter->setParameters(array(
'user' => $this->config['user'],
'password' => $this->config['password'],
'msisdn' => $number
));
$response = $adapter->get();
return $response->getBody();
}
|
[
"protected",
"function",
"getSmsc",
"(",
"$",
"number",
")",
"{",
"$",
"adapter",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
";",
"$",
"adapter",
"->",
"setEndpoint",
"(",
"self",
"::",
"SMSC_ENDPOINT",
")",
";",
"$",
"adapter",
"->",
"setParameters",
"(",
"array",
"(",
"'user'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'user'",
"]",
",",
"'password'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'password'",
"]",
",",
"'msisdn'",
"=>",
"$",
"number",
")",
")",
";",
"$",
"response",
"=",
"$",
"adapter",
"->",
"get",
"(",
")",
";",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}"
] |
Get smsc for a given mobile number.
TODO: implement some sort of caching here.
@param int $number the mobilenumber with countrycode prefix, not zero-padded tho
@return string
|
[
"Get",
"smsc",
"for",
"a",
"given",
"mobile",
"number",
"."
] |
e9692ed5915f5a9cd4dca0df875935a2c528e128
|
https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Provider/UnwireProvider.php#L310-L322
|
25,109
|
wobblecode/WobbleCodeUserBundle
|
EventListener/RegistrationSubscriber.php
|
RegistrationSubscriber.getIpInfo
|
public function getIpInfo()
{
$request = $this->requestStack->getCurrentRequest();
$ipInfo = [];
$ipInfo['country'] = $request->server->get('GEOIP_COUNTRY_CODE', null);
$ipInfo['city'] = $request->server->get('GEOIP_CITY', null);
$ipInfo['region'] = $request->server->get('GEOIP_REGION_NAME', null);
$ipInfo['ip'] = $request->getClientIp();
return $ipInfo;
}
|
php
|
public function getIpInfo()
{
$request = $this->requestStack->getCurrentRequest();
$ipInfo = [];
$ipInfo['country'] = $request->server->get('GEOIP_COUNTRY_CODE', null);
$ipInfo['city'] = $request->server->get('GEOIP_CITY', null);
$ipInfo['region'] = $request->server->get('GEOIP_REGION_NAME', null);
$ipInfo['ip'] = $request->getClientIp();
return $ipInfo;
}
|
[
"public",
"function",
"getIpInfo",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
";",
"$",
"ipInfo",
"=",
"[",
"]",
";",
"$",
"ipInfo",
"[",
"'country'",
"]",
"=",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'GEOIP_COUNTRY_CODE'",
",",
"null",
")",
";",
"$",
"ipInfo",
"[",
"'city'",
"]",
"=",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'GEOIP_CITY'",
",",
"null",
")",
";",
"$",
"ipInfo",
"[",
"'region'",
"]",
"=",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'GEOIP_REGION_NAME'",
",",
"null",
")",
";",
"$",
"ipInfo",
"[",
"'ip'",
"]",
"=",
"$",
"request",
"->",
"getClientIp",
"(",
")",
";",
"return",
"$",
"ipInfo",
";",
"}"
] |
Gets array with IP info and Geo Ip
@return array
|
[
"Gets",
"array",
"with",
"IP",
"info",
"and",
"Geo",
"Ip"
] |
7b8206f8b4a50fbc61f7bfe4f83eb466cad96440
|
https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/EventListener/RegistrationSubscriber.php#L159-L170
|
25,110
|
heiglandreas/OrgHeiglFileFinder
|
src/Service/Tokenlist.php
|
Tokenlist.getClassName
|
public function getClassName()
{
foreach ($this->tokenlist as $key => $token) {
if (T_CLASS === $token[0]) {
return $this->tokenlist[$key + 2][1];
}
}
return '';
}
|
php
|
public function getClassName()
{
foreach ($this->tokenlist as $key => $token) {
if (T_CLASS === $token[0]) {
return $this->tokenlist[$key + 2][1];
}
}
return '';
}
|
[
"public",
"function",
"getClassName",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tokenlist",
"as",
"$",
"key",
"=>",
"$",
"token",
")",
"{",
"if",
"(",
"T_CLASS",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"tokenlist",
"[",
"$",
"key",
"+",
"2",
"]",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"''",
";",
"}"
] |
Get the first classname
@return string
|
[
"Get",
"the",
"first",
"classname"
] |
189d15b95bec7dc186ef73681463c104831234d8
|
https://github.com/heiglandreas/OrgHeiglFileFinder/blob/189d15b95bec7dc186ef73681463c104831234d8/src/Service/Tokenlist.php#L58-L67
|
25,111
|
heiglandreas/OrgHeiglFileFinder
|
src/Service/Tokenlist.php
|
Tokenlist.getNamespace
|
public function getNamespace()
{
$class = array();
$inNamespace = false;
foreach ($this->tokenlist as $key => $token) {
if (T_NAMESPACE === $token[0]) {
$inNamespace = true;
continue;
}
if (T_STRING === $token[0] && $inNamespace) {
$class[] = $token[1];
}
if (';' === $token && $inNamespace) {
return $class;
}
}
return array();
}
|
php
|
public function getNamespace()
{
$class = array();
$inNamespace = false;
foreach ($this->tokenlist as $key => $token) {
if (T_NAMESPACE === $token[0]) {
$inNamespace = true;
continue;
}
if (T_STRING === $token[0] && $inNamespace) {
$class[] = $token[1];
}
if (';' === $token && $inNamespace) {
return $class;
}
}
return array();
}
|
[
"public",
"function",
"getNamespace",
"(",
")",
"{",
"$",
"class",
"=",
"array",
"(",
")",
";",
"$",
"inNamespace",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"tokenlist",
"as",
"$",
"key",
"=>",
"$",
"token",
")",
"{",
"if",
"(",
"T_NAMESPACE",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"$",
"inNamespace",
"=",
"true",
";",
"continue",
";",
"}",
"if",
"(",
"T_STRING",
"===",
"$",
"token",
"[",
"0",
"]",
"&&",
"$",
"inNamespace",
")",
"{",
"$",
"class",
"[",
"]",
"=",
"$",
"token",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"';'",
"===",
"$",
"token",
"&&",
"$",
"inNamespace",
")",
"{",
"return",
"$",
"class",
";",
"}",
"}",
"return",
"array",
"(",
")",
";",
"}"
] |
Get the first namespace of the given content
@return array
|
[
"Get",
"the",
"first",
"namespace",
"of",
"the",
"given",
"content"
] |
189d15b95bec7dc186ef73681463c104831234d8
|
https://github.com/heiglandreas/OrgHeiglFileFinder/blob/189d15b95bec7dc186ef73681463c104831234d8/src/Service/Tokenlist.php#L74-L94
|
25,112
|
proem-components/service
|
AssetComposer.php
|
AssetComposer.compose
|
public function compose($single = false)
{
$reflection = new \ReflectionClass($this->class);
$constructArgs = $this->constructArgs;
$methodArgs = $this->methodArgs;
if ($single) {
static $obj;
if ($obj == null) {
$obj = (new Asset($this->class))->single(
function () use ($reflection, $constructArgs, $methodArgs) {
if ($constructArgs) {
$object = $reflection->newInstanceArgs($constructArgs);
} else {
$object = $reflection->newInstance();
}
foreach ($methodArgs as $method => $params) {
if ($reflection->hasMethod($method)) {
call_user_func_array([$object, $method], $params);
}
}
return $object;
}
);
}
return $obj;
} else {
return new Asset(
$this->class,
function () use ($reflection, $constructArgs, $methodArgs) {
if ($constructArgs) {
$object = $reflection->newInstanceArgs($constructArgs);
} else {
$object = $reflection->newInstance();
}
foreach ($methodArgs as $method => $params) {
if ($reflection->hasMethod($method)) {
call_user_func_array([$object, $method], $params);
}
}
return $object;
}
);
}
}
|
php
|
public function compose($single = false)
{
$reflection = new \ReflectionClass($this->class);
$constructArgs = $this->constructArgs;
$methodArgs = $this->methodArgs;
if ($single) {
static $obj;
if ($obj == null) {
$obj = (new Asset($this->class))->single(
function () use ($reflection, $constructArgs, $methodArgs) {
if ($constructArgs) {
$object = $reflection->newInstanceArgs($constructArgs);
} else {
$object = $reflection->newInstance();
}
foreach ($methodArgs as $method => $params) {
if ($reflection->hasMethod($method)) {
call_user_func_array([$object, $method], $params);
}
}
return $object;
}
);
}
return $obj;
} else {
return new Asset(
$this->class,
function () use ($reflection, $constructArgs, $methodArgs) {
if ($constructArgs) {
$object = $reflection->newInstanceArgs($constructArgs);
} else {
$object = $reflection->newInstance();
}
foreach ($methodArgs as $method => $params) {
if ($reflection->hasMethod($method)) {
call_user_func_array([$object, $method], $params);
}
}
return $object;
}
);
}
}
|
[
"public",
"function",
"compose",
"(",
"$",
"single",
"=",
"false",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"class",
")",
";",
"$",
"constructArgs",
"=",
"$",
"this",
"->",
"constructArgs",
";",
"$",
"methodArgs",
"=",
"$",
"this",
"->",
"methodArgs",
";",
"if",
"(",
"$",
"single",
")",
"{",
"static",
"$",
"obj",
";",
"if",
"(",
"$",
"obj",
"==",
"null",
")",
"{",
"$",
"obj",
"=",
"(",
"new",
"Asset",
"(",
"$",
"this",
"->",
"class",
")",
")",
"->",
"single",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"reflection",
",",
"$",
"constructArgs",
",",
"$",
"methodArgs",
")",
"{",
"if",
"(",
"$",
"constructArgs",
")",
"{",
"$",
"object",
"=",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"constructArgs",
")",
";",
"}",
"else",
"{",
"$",
"object",
"=",
"$",
"reflection",
"->",
"newInstance",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"methodArgs",
"as",
"$",
"method",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"reflection",
"->",
"hasMethod",
"(",
"$",
"method",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"object",
",",
"$",
"method",
"]",
",",
"$",
"params",
")",
";",
"}",
"}",
"return",
"$",
"object",
";",
"}",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}",
"else",
"{",
"return",
"new",
"Asset",
"(",
"$",
"this",
"->",
"class",
",",
"function",
"(",
")",
"use",
"(",
"$",
"reflection",
",",
"$",
"constructArgs",
",",
"$",
"methodArgs",
")",
"{",
"if",
"(",
"$",
"constructArgs",
")",
"{",
"$",
"object",
"=",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"constructArgs",
")",
";",
"}",
"else",
"{",
"$",
"object",
"=",
"$",
"reflection",
"->",
"newInstance",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"methodArgs",
"as",
"$",
"method",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"reflection",
"->",
"hasMethod",
"(",
"$",
"method",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"object",
",",
"$",
"method",
"]",
",",
"$",
"params",
")",
";",
"}",
"}",
"return",
"$",
"object",
";",
"}",
")",
";",
"}",
"}"
] |
Build a configured Asset and return it.
This Asset can optionally be returned implementing a singleton.
@param bool $single
@return Proem\Service\AssetInterface
|
[
"Build",
"a",
"configured",
"Asset",
"and",
"return",
"it",
"."
] |
8c8e9547f16ecaa2789482f34947618f96e453cc
|
https://github.com/proem-components/service/blob/8c8e9547f16ecaa2789482f34947618f96e453cc/AssetComposer.php#L142-L189
|
25,113
|
stubbles/stubbles-peer
|
src/main/php/Socket.php
|
Socket.connect
|
public function connect(float $connectTimeout = 1.0): Stream
{
$errno = 0;
$errstr = '';
$fsockopen = $this->fsockopen;
$resource = $fsockopen(
$this->prefix . $this->host,
$this->port,
$errno,
$errstr,
$connectTimeout
);
if (false === $resource) {
throw new ConnectionFailure(
'Connect to ' . $this->prefix . $this->host . ':'. $this->port
. ' within ' . $connectTimeout . ' second'
. (1 == $connectTimeout ? '' : 's') . ' failed: '
. $errstr . ' (' . $errno . ').'
);
}
return new Stream($resource, $this->usesSsl());
}
|
php
|
public function connect(float $connectTimeout = 1.0): Stream
{
$errno = 0;
$errstr = '';
$fsockopen = $this->fsockopen;
$resource = $fsockopen(
$this->prefix . $this->host,
$this->port,
$errno,
$errstr,
$connectTimeout
);
if (false === $resource) {
throw new ConnectionFailure(
'Connect to ' . $this->prefix . $this->host . ':'. $this->port
. ' within ' . $connectTimeout . ' second'
. (1 == $connectTimeout ? '' : 's') . ' failed: '
. $errstr . ' (' . $errno . ').'
);
}
return new Stream($resource, $this->usesSsl());
}
|
[
"public",
"function",
"connect",
"(",
"float",
"$",
"connectTimeout",
"=",
"1.0",
")",
":",
"Stream",
"{",
"$",
"errno",
"=",
"0",
";",
"$",
"errstr",
"=",
"''",
";",
"$",
"fsockopen",
"=",
"$",
"this",
"->",
"fsockopen",
";",
"$",
"resource",
"=",
"$",
"fsockopen",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"connectTimeout",
")",
";",
"if",
"(",
"false",
"===",
"$",
"resource",
")",
"{",
"throw",
"new",
"ConnectionFailure",
"(",
"'Connect to '",
".",
"$",
"this",
"->",
"prefix",
".",
"$",
"this",
"->",
"host",
".",
"':'",
".",
"$",
"this",
"->",
"port",
".",
"' within '",
".",
"$",
"connectTimeout",
".",
"' second'",
".",
"(",
"1",
"==",
"$",
"connectTimeout",
"?",
"''",
":",
"'s'",
")",
".",
"' failed: '",
".",
"$",
"errstr",
".",
"' ('",
".",
"$",
"errno",
".",
"').'",
")",
";",
"}",
"return",
"new",
"Stream",
"(",
"$",
"resource",
",",
"$",
"this",
"->",
"usesSsl",
"(",
")",
")",
";",
"}"
] |
opens a connection to host
@param float $connectTimeout optional timeout for establishing the connection, defaults to 1 second
@return \stubbles\peer\Stream
@throws \stubbles\peer\ConnectionFailure
|
[
"opens",
"a",
"connection",
"to",
"host"
] |
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
|
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Socket.php#L85-L107
|
25,114
|
AltCtrlSupr/ACSPanel-Settings
|
Controller/ConfigSettingController.php
|
ConfigSettingController.createObjectSettingsAction
|
public function createObjectSettingsAction($object_id)
{
$em = $this->getDoctrine()->getManager();
$class_name = $this->container->getParameter('acs_settings.setting_class');
// Get the object fields
$object = $em->getRepository('ACSACSPanelBundle:Service')->find($object_id);
$object_fields = $object->getType()->getFieldTypes();
$user = $this->get('security.context')->getToken()->getUser();
// Adding one form for each setting field
foreach($object_fields as $id => $field_config){
$setting = $em->getRepository('ACSACSPanelBundle:PanelSetting')->findOneBy(
array(
'user' => $user->getId(),
'setting_key' => $field_config->getSettingKey(),
'focus' => 'object_setting',
'service' => $object,
)
);
if (!count($setting)) {
$setting = new $class_name;
$setting->setSettingKey($field_config->getSettingKey());
$setting->setValue($field_config->getDefaultValue());
$setting->setContext($field_config->getContext());
$setting->setLabel($field_config->getLabel());
$setting->setType($field_config->getType());
$setting->setFocus('object_setting');
$setting->setService($object);
$user->addSetting($setting);
$em->persist($user);
$em->flush();
}
}
return $this->redirect($this->generateUrl('settings'));
}
|
php
|
public function createObjectSettingsAction($object_id)
{
$em = $this->getDoctrine()->getManager();
$class_name = $this->container->getParameter('acs_settings.setting_class');
// Get the object fields
$object = $em->getRepository('ACSACSPanelBundle:Service')->find($object_id);
$object_fields = $object->getType()->getFieldTypes();
$user = $this->get('security.context')->getToken()->getUser();
// Adding one form for each setting field
foreach($object_fields as $id => $field_config){
$setting = $em->getRepository('ACSACSPanelBundle:PanelSetting')->findOneBy(
array(
'user' => $user->getId(),
'setting_key' => $field_config->getSettingKey(),
'focus' => 'object_setting',
'service' => $object,
)
);
if (!count($setting)) {
$setting = new $class_name;
$setting->setSettingKey($field_config->getSettingKey());
$setting->setValue($field_config->getDefaultValue());
$setting->setContext($field_config->getContext());
$setting->setLabel($field_config->getLabel());
$setting->setType($field_config->getType());
$setting->setFocus('object_setting');
$setting->setService($object);
$user->addSetting($setting);
$em->persist($user);
$em->flush();
}
}
return $this->redirect($this->generateUrl('settings'));
}
|
[
"public",
"function",
"createObjectSettingsAction",
"(",
"$",
"object_id",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"class_name",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'acs_settings.setting_class'",
")",
";",
"// Get the object fields",
"$",
"object",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:Service'",
")",
"->",
"find",
"(",
"$",
"object_id",
")",
";",
"$",
"object_fields",
"=",
"$",
"object",
"->",
"getType",
"(",
")",
"->",
"getFieldTypes",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"// Adding one form for each setting field",
"foreach",
"(",
"$",
"object_fields",
"as",
"$",
"id",
"=>",
"$",
"field_config",
")",
"{",
"$",
"setting",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:PanelSetting'",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"'user'",
"=>",
"$",
"user",
"->",
"getId",
"(",
")",
",",
"'setting_key'",
"=>",
"$",
"field_config",
"->",
"getSettingKey",
"(",
")",
",",
"'focus'",
"=>",
"'object_setting'",
",",
"'service'",
"=>",
"$",
"object",
",",
")",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"setting",
")",
")",
"{",
"$",
"setting",
"=",
"new",
"$",
"class_name",
";",
"$",
"setting",
"->",
"setSettingKey",
"(",
"$",
"field_config",
"->",
"getSettingKey",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setValue",
"(",
"$",
"field_config",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setContext",
"(",
"$",
"field_config",
"->",
"getContext",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setLabel",
"(",
"$",
"field_config",
"->",
"getLabel",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setType",
"(",
"$",
"field_config",
"->",
"getType",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setFocus",
"(",
"'object_setting'",
")",
";",
"$",
"setting",
"->",
"setService",
"(",
"$",
"object",
")",
";",
"$",
"user",
"->",
"addSetting",
"(",
"$",
"setting",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'settings'",
")",
")",
";",
"}"
] |
It creates the object settings specified
|
[
"It",
"creates",
"the",
"object",
"settings",
"specified"
] |
b1e363bf98d4c74368b3063abba0c77bb3a61230
|
https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Controller/ConfigSettingController.php#L26-L64
|
25,115
|
AltCtrlSupr/ACSPanel-Settings
|
Controller/ConfigSettingController.php
|
ConfigSettingController.panelSettingsAction
|
public function panelSettingsAction()
{
$em = $this->getDoctrine()->getManager();
$user = $this->get('security.context')->getToken()->getUser();
$settingmanager = $this->get('acs.setting_manager');
$user_fields = $settingmanager->loadUserFields();
$object_settings = $settingmanager->getObjectSettingsPrototype($user);
array_merge($user_fields, $object_settings);
$form = $this->createForm(new ConfigSettingCollectionType($user_fields, $em), $user);
$contexts = $settingmanager->getContexts($user);
return $this->render('ACSACSPanelSettingsBundle:ConfigSetting:edit.html.twig', array(
'entity' => $user,
'contexts' => $contexts,
'form' => $form->createView(),
));
}
|
php
|
public function panelSettingsAction()
{
$em = $this->getDoctrine()->getManager();
$user = $this->get('security.context')->getToken()->getUser();
$settingmanager = $this->get('acs.setting_manager');
$user_fields = $settingmanager->loadUserFields();
$object_settings = $settingmanager->getObjectSettingsPrototype($user);
array_merge($user_fields, $object_settings);
$form = $this->createForm(new ConfigSettingCollectionType($user_fields, $em), $user);
$contexts = $settingmanager->getContexts($user);
return $this->render('ACSACSPanelSettingsBundle:ConfigSetting:edit.html.twig', array(
'entity' => $user,
'contexts' => $contexts,
'form' => $form->createView(),
));
}
|
[
"public",
"function",
"panelSettingsAction",
"(",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"settingmanager",
"=",
"$",
"this",
"->",
"get",
"(",
"'acs.setting_manager'",
")",
";",
"$",
"user_fields",
"=",
"$",
"settingmanager",
"->",
"loadUserFields",
"(",
")",
";",
"$",
"object_settings",
"=",
"$",
"settingmanager",
"->",
"getObjectSettingsPrototype",
"(",
"$",
"user",
")",
";",
"array_merge",
"(",
"$",
"user_fields",
",",
"$",
"object_settings",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ConfigSettingCollectionType",
"(",
"$",
"user_fields",
",",
"$",
"em",
")",
",",
"$",
"user",
")",
";",
"$",
"contexts",
"=",
"$",
"settingmanager",
"->",
"getContexts",
"(",
"$",
"user",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelSettingsBundle:ConfigSetting:edit.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"user",
",",
"'contexts'",
"=>",
"$",
"contexts",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] |
Displays a form with all the user settings
|
[
"Displays",
"a",
"form",
"with",
"all",
"the",
"user",
"settings"
] |
b1e363bf98d4c74368b3063abba0c77bb3a61230
|
https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Controller/ConfigSettingController.php#L69-L91
|
25,116
|
AltCtrlSupr/ACSPanel-Settings
|
Controller/ConfigSettingController.php
|
ConfigSettingController.updateAction
|
public function updateAction(Request $request, $id)
{
$class_name = $this->container->getParameter('acs_settings.setting_class');
$settingmanager = $this->get('acs.setting_manager');
$user_fields = $settingmanager->loadUserFields();
$em = $this->getDoctrine()->getManager();
$entity = $this->get('security.context')->getToken()->getUser();
if (!$entity) {
throw $this->createNotFoundException('Unable to find ConfigSetting entity.');
}
$editForm = $this->createForm(new ConfigSettingCollectionType($user_fields,$em), $entity);
$editForm->bind($request);
$postData = $request->request->get('acs_settings_usersettings');
if ($editForm->isValid()) {
if (isset($postData['settings'])) {
$settings = $postData['settings'];
foreach ($settings as $setting) {
$args = array(
'user' => $entity->getId(),
'setting_key' => $setting['setting_key'],
);
if(isset($setting['service_id'])){
$service = $em->getRepository('ACSACSPanelBundle:Service')->find($setting['service_id']);
$args['service'] = $service;
}
$panelsetting = $em->getRepository('ACSACSPanelBundle:PanelSetting')->findOneBy($args);
if ($panelsetting && isset($setting['value'])) {
$panelsetting->setValue($setting['value']);
$em->persist($panelsetting);
$em->flush();
}
}
$em->flush();
}
return $this->redirect($this->generateUrl('settings'));
}
return $this->render('ACSACSPanelSettingsBundle:ConfigSetting:new.html.twig', array(
'entity' => $entity,
'form' => $editForm->createView(),
));
}
|
php
|
public function updateAction(Request $request, $id)
{
$class_name = $this->container->getParameter('acs_settings.setting_class');
$settingmanager = $this->get('acs.setting_manager');
$user_fields = $settingmanager->loadUserFields();
$em = $this->getDoctrine()->getManager();
$entity = $this->get('security.context')->getToken()->getUser();
if (!$entity) {
throw $this->createNotFoundException('Unable to find ConfigSetting entity.');
}
$editForm = $this->createForm(new ConfigSettingCollectionType($user_fields,$em), $entity);
$editForm->bind($request);
$postData = $request->request->get('acs_settings_usersettings');
if ($editForm->isValid()) {
if (isset($postData['settings'])) {
$settings = $postData['settings'];
foreach ($settings as $setting) {
$args = array(
'user' => $entity->getId(),
'setting_key' => $setting['setting_key'],
);
if(isset($setting['service_id'])){
$service = $em->getRepository('ACSACSPanelBundle:Service')->find($setting['service_id']);
$args['service'] = $service;
}
$panelsetting = $em->getRepository('ACSACSPanelBundle:PanelSetting')->findOneBy($args);
if ($panelsetting && isset($setting['value'])) {
$panelsetting->setValue($setting['value']);
$em->persist($panelsetting);
$em->flush();
}
}
$em->flush();
}
return $this->redirect($this->generateUrl('settings'));
}
return $this->render('ACSACSPanelSettingsBundle:ConfigSetting:new.html.twig', array(
'entity' => $entity,
'form' => $editForm->createView(),
));
}
|
[
"public",
"function",
"updateAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"class_name",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'acs_settings.setting_class'",
")",
";",
"$",
"settingmanager",
"=",
"$",
"this",
"->",
"get",
"(",
"'acs.setting_manager'",
")",
";",
"$",
"user_fields",
"=",
"$",
"settingmanager",
"->",
"loadUserFields",
"(",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find ConfigSetting entity.'",
")",
";",
"}",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ConfigSettingCollectionType",
"(",
"$",
"user_fields",
",",
"$",
"em",
")",
",",
"$",
"entity",
")",
";",
"$",
"editForm",
"->",
"bind",
"(",
"$",
"request",
")",
";",
"$",
"postData",
"=",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'acs_settings_usersettings'",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"isValid",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"postData",
"[",
"'settings'",
"]",
")",
")",
"{",
"$",
"settings",
"=",
"$",
"postData",
"[",
"'settings'",
"]",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"setting",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'user'",
"=>",
"$",
"entity",
"->",
"getId",
"(",
")",
",",
"'setting_key'",
"=>",
"$",
"setting",
"[",
"'setting_key'",
"]",
",",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"setting",
"[",
"'service_id'",
"]",
")",
")",
"{",
"$",
"service",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:Service'",
")",
"->",
"find",
"(",
"$",
"setting",
"[",
"'service_id'",
"]",
")",
";",
"$",
"args",
"[",
"'service'",
"]",
"=",
"$",
"service",
";",
"}",
"$",
"panelsetting",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:PanelSetting'",
")",
"->",
"findOneBy",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"panelsetting",
"&&",
"isset",
"(",
"$",
"setting",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"panelsetting",
"->",
"setValue",
"(",
"$",
"setting",
"[",
"'value'",
"]",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"panelsetting",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"}",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'settings'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelSettingsBundle:ConfigSetting:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] |
Edits an existing ConfigSetting entity.
|
[
"Edits",
"an",
"existing",
"ConfigSetting",
"entity",
"."
] |
b1e363bf98d4c74368b3063abba0c77bb3a61230
|
https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Controller/ConfigSettingController.php#L96-L148
|
25,117
|
stingus/phpdt
|
src/PHPdt/DataType/ObjectValidationTrait.php
|
ObjectValidationTrait.validateType
|
public static function validateType($value)
{
if (get_called_class() === $value) {
return true;
}
if (array_key_exists($value, class_implements(get_called_class()))) {
return true;
}
if (array_key_exists($value, class_parents(get_called_class()))) {
return true;
}
throw new InvalidDataTypeException(__CLASS__, new static);
}
|
php
|
public static function validateType($value)
{
if (get_called_class() === $value) {
return true;
}
if (array_key_exists($value, class_implements(get_called_class()))) {
return true;
}
if (array_key_exists($value, class_parents(get_called_class()))) {
return true;
}
throw new InvalidDataTypeException(__CLASS__, new static);
}
|
[
"public",
"static",
"function",
"validateType",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"get_called_class",
"(",
")",
"===",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"value",
",",
"class_implements",
"(",
"get_called_class",
"(",
")",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"value",
",",
"class_parents",
"(",
"get_called_class",
"(",
")",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"throw",
"new",
"InvalidDataTypeException",
"(",
"__CLASS__",
",",
"new",
"static",
")",
";",
"}"
] |
Validate object type
@param $value
@return bool
@throws InvalidDataTypeException
|
[
"Validate",
"object",
"type"
] |
931088dd8a04ace0bc83ff85cfc1707c6edbdc95
|
https://github.com/stingus/phpdt/blob/931088dd8a04ace0bc83ff85cfc1707c6edbdc95/src/PHPdt/DataType/ObjectValidationTrait.php#L23-L35
|
25,118
|
Vectrex/vxPHP
|
src/Database/Util.php
|
Util.unFormatDecimal
|
public static function unFormatDecimal($decimalString) {
if(trim($decimalString) == '') {
return NAN;
}
// remove a leading "+"
$decimalString = rtrim('+', trim($decimalString));
// only a decimal separator ("," or ".")
if(preg_match('/^\-?\d+([,.]\d+)?$/', $decimalString)) {
return (float) (str_replace(',', '.', $decimalString));
}
// "," as thousands separator "." as decimal separator
if(preg_match('/^\-?[1-9]\d{0,2}((,|\')\d{3})*(\.\d+)?$/', $decimalString)) {
return (float) (str_replace(array(',', '\''), array('', ''), $decimalString));
}
// "." as thousands separator "," as decimal separator
if(preg_match('/^\-?[1-9]\d{0,2}(\.\d{3})*(,\d+)?$/', $decimalString)) {
return (float) (str_replace(array('.', ','), array('', '.'), $decimalString));
}
// try type casting
return (float) $decimalString;
}
|
php
|
public static function unFormatDecimal($decimalString) {
if(trim($decimalString) == '') {
return NAN;
}
// remove a leading "+"
$decimalString = rtrim('+', trim($decimalString));
// only a decimal separator ("," or ".")
if(preg_match('/^\-?\d+([,.]\d+)?$/', $decimalString)) {
return (float) (str_replace(',', '.', $decimalString));
}
// "," as thousands separator "." as decimal separator
if(preg_match('/^\-?[1-9]\d{0,2}((,|\')\d{3})*(\.\d+)?$/', $decimalString)) {
return (float) (str_replace(array(',', '\''), array('', ''), $decimalString));
}
// "." as thousands separator "," as decimal separator
if(preg_match('/^\-?[1-9]\d{0,2}(\.\d{3})*(,\d+)?$/', $decimalString)) {
return (float) (str_replace(array('.', ','), array('', '.'), $decimalString));
}
// try type casting
return (float) $decimalString;
}
|
[
"public",
"static",
"function",
"unFormatDecimal",
"(",
"$",
"decimalString",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"decimalString",
")",
"==",
"''",
")",
"{",
"return",
"NAN",
";",
"}",
"// remove a leading \"+\"",
"$",
"decimalString",
"=",
"rtrim",
"(",
"'+'",
",",
"trim",
"(",
"$",
"decimalString",
")",
")",
";",
"// only a decimal separator (\",\" or \".\")",
"if",
"(",
"preg_match",
"(",
"'/^\\-?\\d+([,.]\\d+)?$/'",
",",
"$",
"decimalString",
")",
")",
"{",
"return",
"(",
"float",
")",
"(",
"str_replace",
"(",
"','",
",",
"'.'",
",",
"$",
"decimalString",
")",
")",
";",
"}",
"// \",\" as thousands separator \".\" as decimal separator",
"if",
"(",
"preg_match",
"(",
"'/^\\-?[1-9]\\d{0,2}((,|\\')\\d{3})*(\\.\\d+)?$/'",
",",
"$",
"decimalString",
")",
")",
"{",
"return",
"(",
"float",
")",
"(",
"str_replace",
"(",
"array",
"(",
"','",
",",
"'\\''",
")",
",",
"array",
"(",
"''",
",",
"''",
")",
",",
"$",
"decimalString",
")",
")",
";",
"}",
"// \".\" as thousands separator \",\" as decimal separator",
"if",
"(",
"preg_match",
"(",
"'/^\\-?[1-9]\\d{0,2}(\\.\\d{3})*(,\\d+)?$/'",
",",
"$",
"decimalString",
")",
")",
"{",
"return",
"(",
"float",
")",
"(",
"str_replace",
"(",
"array",
"(",
"'.'",
",",
"','",
")",
",",
"array",
"(",
"''",
",",
"'.'",
")",
",",
"$",
"decimalString",
")",
")",
";",
"}",
"// try type casting",
"return",
"(",
"float",
")",
"$",
"decimalString",
";",
"}"
] |
Strips decimal strings from everything but decimal point and negative prefix
and returns the result as float
@param string $decimalString
@return float | NaN
|
[
"Strips",
"decimal",
"strings",
"from",
"everything",
"but",
"decimal",
"point",
"and",
"negative",
"prefix",
"and",
"returns",
"the",
"result",
"as",
"float"
] |
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
|
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Database/Util.php#L81-L112
|
25,119
|
raykolbe/CKEditorModule
|
src/CKEditorModule/View/Helper/CKEditor.php
|
CKEditor.getRenderedEditor
|
public function getRenderedEditor($id, array $options = array())
{
$config = clone $this->options;
$config->setFromArray($options);
$basePath = $this->getView()->basePath($config->getBasePath());
$editor = new \CKEditor($basePath);
return $editor->replace($id, $this->optionsToCKEditorConfig($config));
}
|
php
|
public function getRenderedEditor($id, array $options = array())
{
$config = clone $this->options;
$config->setFromArray($options);
$basePath = $this->getView()->basePath($config->getBasePath());
$editor = new \CKEditor($basePath);
return $editor->replace($id, $this->optionsToCKEditorConfig($config));
}
|
[
"public",
"function",
"getRenderedEditor",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"config",
"=",
"clone",
"$",
"this",
"->",
"options",
";",
"$",
"config",
"->",
"setFromArray",
"(",
"$",
"options",
")",
";",
"$",
"basePath",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"basePath",
"(",
"$",
"config",
"->",
"getBasePath",
"(",
")",
")",
";",
"$",
"editor",
"=",
"new",
"\\",
"CKEditor",
"(",
"$",
"basePath",
")",
";",
"return",
"$",
"editor",
"->",
"replace",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"optionsToCKEditorConfig",
"(",
"$",
"config",
")",
")",
";",
"}"
] |
Generates output needed for CKEditor.
@param string $id The DOM ID to apply this editor to.
@param array $options An array of options specific to this instance.
@return string The HTML output.
|
[
"Generates",
"output",
"needed",
"for",
"CKEditor",
"."
] |
5088cc4ab085ee1e4ba9ee9d0209c27082c90259
|
https://github.com/raykolbe/CKEditorModule/blob/5088cc4ab085ee1e4ba9ee9d0209c27082c90259/src/CKEditorModule/View/Helper/CKEditor.php#L81-L90
|
25,120
|
raykolbe/CKEditorModule
|
src/CKEditorModule/View/Helper/CKEditor.php
|
CKEditor.optionsToCKEditorConfig
|
protected function optionsToCKEditorConfig(Options $options)
{
$config = array();
foreach ($options->toArray() as $key => $value) {
if (!array_key_exists($key, static::$optionsToConfigMap)) {
continue;
}
if (in_array($key, static::$optionsToPrependBasePath)) {
if (is_array($value)) {
foreach ($value as &$deepValue) {
$deepValue = $this->view->basePath($deepValue);
}
} else {
$value = $this->view->basePath($value);
}
}
$config[static::$optionsToConfigMap[$key]] = $value;
}
return $config;
}
|
php
|
protected function optionsToCKEditorConfig(Options $options)
{
$config = array();
foreach ($options->toArray() as $key => $value) {
if (!array_key_exists($key, static::$optionsToConfigMap)) {
continue;
}
if (in_array($key, static::$optionsToPrependBasePath)) {
if (is_array($value)) {
foreach ($value as &$deepValue) {
$deepValue = $this->view->basePath($deepValue);
}
} else {
$value = $this->view->basePath($value);
}
}
$config[static::$optionsToConfigMap[$key]] = $value;
}
return $config;
}
|
[
"protected",
"function",
"optionsToCKEditorConfig",
"(",
"Options",
"$",
"options",
")",
"{",
"$",
"config",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"options",
"->",
"toArray",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"static",
"::",
"$",
"optionsToConfigMap",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"static",
"::",
"$",
"optionsToPrependBasePath",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"&",
"$",
"deepValue",
")",
"{",
"$",
"deepValue",
"=",
"$",
"this",
"->",
"view",
"->",
"basePath",
"(",
"$",
"deepValue",
")",
";",
"}",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"view",
"->",
"basePath",
"(",
"$",
"value",
")",
";",
"}",
"}",
"$",
"config",
"[",
"static",
"::",
"$",
"optionsToConfigMap",
"[",
"$",
"key",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"config",
";",
"}"
] |
Translates our internal Options object into a usable config array
for CKEditor.
@param \CKEditor\Options $options
@return array
|
[
"Translates",
"our",
"internal",
"Options",
"object",
"into",
"a",
"usable",
"config",
"array",
"for",
"CKEditor",
"."
] |
5088cc4ab085ee1e4ba9ee9d0209c27082c90259
|
https://github.com/raykolbe/CKEditorModule/blob/5088cc4ab085ee1e4ba9ee9d0209c27082c90259/src/CKEditorModule/View/Helper/CKEditor.php#L99-L121
|
25,121
|
Kris-Kuiper/sFire-Framework
|
src/Cache/Cache.php
|
Cache.setDriver
|
public function setDriver($driver) {
if(false === is_string($driver)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($driver)), E_USER_ERROR);
}
if(false === class_exists($driver)) {
$driver = __NAMESPACE__ . '\\Driver\\' . $driver;
if(false === class_exists($driver)) {
return trigger_error(sprintf('Driver "%s" does not exists', $driver), E_USER_ERROR);
}
}
$this -> driver = $driver;
return $this;
}
|
php
|
public function setDriver($driver) {
if(false === is_string($driver)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($driver)), E_USER_ERROR);
}
if(false === class_exists($driver)) {
$driver = __NAMESPACE__ . '\\Driver\\' . $driver;
if(false === class_exists($driver)) {
return trigger_error(sprintf('Driver "%s" does not exists', $driver), E_USER_ERROR);
}
}
$this -> driver = $driver;
return $this;
}
|
[
"public",
"function",
"setDriver",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"driver",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"driver",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"class_exists",
"(",
"$",
"driver",
")",
")",
"{",
"$",
"driver",
"=",
"__NAMESPACE__",
".",
"'\\\\Driver\\\\'",
".",
"$",
"driver",
";",
"if",
"(",
"false",
"===",
"class_exists",
"(",
"$",
"driver",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Driver \"%s\" does not exists'",
",",
"$",
"driver",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"}",
"$",
"this",
"->",
"driver",
"=",
"$",
"driver",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the driver
@param string $driver
@return sFire\Cache\Cache
|
[
"Sets",
"the",
"driver"
] |
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
|
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Cache.php#L34-L52
|
25,122
|
Kris-Kuiper/sFire-Framework
|
src/Cache/Cache.php
|
Cache.call
|
private function call() {
if(null === $this -> driver) {
return trigger_error('Driver is not set. Set the driver with the setDriver() method', E_USER_ERROR);
}
if(null === $this -> driverInstance) {
$this -> driverInstance = new $this -> driver();
}
return $this -> driverInstance;
}
|
php
|
private function call() {
if(null === $this -> driver) {
return trigger_error('Driver is not set. Set the driver with the setDriver() method', E_USER_ERROR);
}
if(null === $this -> driverInstance) {
$this -> driverInstance = new $this -> driver();
}
return $this -> driverInstance;
}
|
[
"private",
"function",
"call",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"driver",
")",
"{",
"return",
"trigger_error",
"(",
"'Driver is not set. Set the driver with the setDriver() method'",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"driverInstance",
")",
"{",
"$",
"this",
"->",
"driverInstance",
"=",
"new",
"$",
"this",
"->",
"driver",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"driverInstance",
";",
"}"
] |
Check if driver is set and returns it
@return mixed
|
[
"Check",
"if",
"driver",
"is",
"set",
"and",
"returns",
"it"
] |
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
|
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Cache.php#L137-L148
|
25,123
|
dms-org/common.structure
|
src/DateTime/TimeRange.php
|
TimeRange.encompasses
|
public function encompasses(TimeRange $otherRange) : bool
{
return $this->start->isEarlierThanOrEqual($otherRange->start) && $this->end->isLaterThanOrEqual($otherRange->end);
}
|
php
|
public function encompasses(TimeRange $otherRange) : bool
{
return $this->start->isEarlierThanOrEqual($otherRange->start) && $this->end->isLaterThanOrEqual($otherRange->end);
}
|
[
"public",
"function",
"encompasses",
"(",
"TimeRange",
"$",
"otherRange",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"start",
"->",
"isEarlierThanOrEqual",
"(",
"$",
"otherRange",
"->",
"start",
")",
"&&",
"$",
"this",
"->",
"end",
"->",
"isLaterThanOrEqual",
"(",
"$",
"otherRange",
"->",
"end",
")",
";",
"}"
] |
Returns whether the supplied time range is encompassed by this
time range.
@param TimeRange $otherRange
@return bool
|
[
"Returns",
"whether",
"the",
"supplied",
"time",
"range",
"is",
"encompassed",
"by",
"this",
"time",
"range",
"."
] |
23f122182f60df5ec847047a81a39c8aab019ff1
|
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/TimeRange.php#L93-L96
|
25,124
|
fulgurio/LightCMSBundle
|
Utils/LightCMSUtils.php
|
LightCMSUtils.getUploadDir
|
static function getUploadDir($withUploadUrl = TRUE)
{
$dir = __DIR__ . '/../../../../web/';
if (!is_dir($dir))
{
$dir = __DIR__ . '/../../../../../web';
if (!is_dir($dir))
{
$dir = __DIR__ . '/../../../../../../web';
if (!is_dir($dir))
{
throw new \Exception('Upload dir not found');
}
}
}
if (!is_dir($dir . self::getUploadUrl()))
{
if (!is_writable($dir))
{
throw new \Exception($dir . ' is not writable');
}
else
{
mkdir($dir . self::getUploadUrl());
}
}
return $withUploadUrl ? $dir . self::getUploadUrl() : $dir;
}
|
php
|
static function getUploadDir($withUploadUrl = TRUE)
{
$dir = __DIR__ . '/../../../../web/';
if (!is_dir($dir))
{
$dir = __DIR__ . '/../../../../../web';
if (!is_dir($dir))
{
$dir = __DIR__ . '/../../../../../../web';
if (!is_dir($dir))
{
throw new \Exception('Upload dir not found');
}
}
}
if (!is_dir($dir . self::getUploadUrl()))
{
if (!is_writable($dir))
{
throw new \Exception($dir . ' is not writable');
}
else
{
mkdir($dir . self::getUploadUrl());
}
}
return $withUploadUrl ? $dir . self::getUploadUrl() : $dir;
}
|
[
"static",
"function",
"getUploadDir",
"(",
"$",
"withUploadUrl",
"=",
"TRUE",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"'/../../../../web/'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"'/../../../../../web'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"'/../../../../../../web'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Upload dir not found'",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
".",
"self",
"::",
"getUploadUrl",
"(",
")",
")",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"dir",
".",
"' is not writable'",
")",
";",
"}",
"else",
"{",
"mkdir",
"(",
"$",
"dir",
".",
"self",
"::",
"getUploadUrl",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"withUploadUrl",
"?",
"$",
"dir",
".",
"self",
"::",
"getUploadUrl",
"(",
")",
":",
"$",
"dir",
";",
"}"
] |
Get upload file dir
@throws \Exception
|
[
"Get",
"upload",
"file",
"dir"
] |
66319af52b97b6552b7c391ee370538263f42d10
|
https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Utils/LightCMSUtils.php#L23-L50
|
25,125
|
fulgurio/LightCMSBundle
|
Utils/LightCMSUtils.php
|
LightCMSUtils.getThumbFilename
|
static public function getThumbFilename($filename, $mimeType, $size)
{
if (substr($mimeType, 0, 5) == 'image')
{
$pos = mb_strrpos($filename, '.');
if ($pos === FALSE)
{
return $filename . '_' . $size['width'] . 'x' . $size['height'];
}
else
{
return mb_substr($filename, 0, $pos) . '_' . $size['width'] . 'x' . $size['height'] . mb_substr($filename, $pos);
}
}
else if ($mimeType == 'application/pdf')
{
return $GLOBALS['kernel']->getContainer()->get('templating.helper.assets')->getUrl('bundles/fulguriolightcms/img/thumb_pdf.png');
}
else
{
return 'http://www.placehold.it/' . $size['width'] . 'x' . $size['height'] . '/EFEFEF/AAAAAA';
}
}
|
php
|
static public function getThumbFilename($filename, $mimeType, $size)
{
if (substr($mimeType, 0, 5) == 'image')
{
$pos = mb_strrpos($filename, '.');
if ($pos === FALSE)
{
return $filename . '_' . $size['width'] . 'x' . $size['height'];
}
else
{
return mb_substr($filename, 0, $pos) . '_' . $size['width'] . 'x' . $size['height'] . mb_substr($filename, $pos);
}
}
else if ($mimeType == 'application/pdf')
{
return $GLOBALS['kernel']->getContainer()->get('templating.helper.assets')->getUrl('bundles/fulguriolightcms/img/thumb_pdf.png');
}
else
{
return 'http://www.placehold.it/' . $size['width'] . 'x' . $size['height'] . '/EFEFEF/AAAAAA';
}
}
|
[
"static",
"public",
"function",
"getThumbFilename",
"(",
"$",
"filename",
",",
"$",
"mimeType",
",",
"$",
"size",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"mimeType",
",",
"0",
",",
"5",
")",
"==",
"'image'",
")",
"{",
"$",
"pos",
"=",
"mb_strrpos",
"(",
"$",
"filename",
",",
"'.'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"FALSE",
")",
"{",
"return",
"$",
"filename",
".",
"'_'",
".",
"$",
"size",
"[",
"'width'",
"]",
".",
"'x'",
".",
"$",
"size",
"[",
"'height'",
"]",
";",
"}",
"else",
"{",
"return",
"mb_substr",
"(",
"$",
"filename",
",",
"0",
",",
"$",
"pos",
")",
".",
"'_'",
".",
"$",
"size",
"[",
"'width'",
"]",
".",
"'x'",
".",
"$",
"size",
"[",
"'height'",
"]",
".",
"mb_substr",
"(",
"$",
"filename",
",",
"$",
"pos",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"mimeType",
"==",
"'application/pdf'",
")",
"{",
"return",
"$",
"GLOBALS",
"[",
"'kernel'",
"]",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'templating.helper.assets'",
")",
"->",
"getUrl",
"(",
"'bundles/fulguriolightcms/img/thumb_pdf.png'",
")",
";",
"}",
"else",
"{",
"return",
"'http://www.placehold.it/'",
".",
"$",
"size",
"[",
"'width'",
"]",
".",
"'x'",
".",
"$",
"size",
"[",
"'height'",
"]",
".",
"'/EFEFEF/AAAAAA'",
";",
"}",
"}"
] |
Get thumb filename for a specified size
@param string $filename
@param string $mimeType
@param array $size Contains width and height
@return string
|
[
"Get",
"thumb",
"filename",
"for",
"a",
"specified",
"size"
] |
66319af52b97b6552b7c391ee370538263f42d10
|
https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Utils/LightCMSUtils.php#L70-L92
|
25,126
|
koolkode/view
|
src/AbstractViewRenderer.php
|
AbstractViewRenderer.partial
|
protected function partial($resource, array $data = [])
{
if($resource instanceof ViewModelInterface)
{
return $this->view->render($resource, true);
}
return $this->view->render(new ViewModel($this->view->resolveResourcePath($resource), $data), true);
}
|
php
|
protected function partial($resource, array $data = [])
{
if($resource instanceof ViewModelInterface)
{
return $this->view->render($resource, true);
}
return $this->view->render(new ViewModel($this->view->resolveResourcePath($resource), $data), true);
}
|
[
"protected",
"function",
"partial",
"(",
"$",
"resource",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"resource",
"instanceof",
"ViewModelInterface",
")",
"{",
"return",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
"$",
"resource",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
"new",
"ViewModel",
"(",
"$",
"this",
"->",
"view",
"->",
"resolveResourcePath",
"(",
"$",
"resource",
")",
",",
"$",
"data",
")",
",",
"true",
")",
";",
"}"
] |
Render a partial view and return the generated output.
@param string|ViewModelInterface $resource
@param array<string, mixed> $data
|
[
"Render",
"a",
"partial",
"view",
"and",
"return",
"the",
"generated",
"output",
"."
] |
70a6784611c7184805d5a18fe6f7e534e4e44c59
|
https://github.com/koolkode/view/blob/70a6784611c7184805d5a18fe6f7e534e4e44c59/src/AbstractViewRenderer.php#L59-L67
|
25,127
|
ThomasSquall/PHPMagicAnnotations
|
src/Reflection/Reflector.php
|
Reflector.getProperty
|
public function getProperty($name)
{
if ($this->reflected->hasProperty($name))
return $this->annotations['properties'][$name];
return null;
}
|
php
|
public function getProperty($name)
{
if ($this->reflected->hasProperty($name))
return $this->annotations['properties'][$name];
return null;
}
|
[
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"reflected",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"return",
"$",
"this",
"->",
"annotations",
"[",
"'properties'",
"]",
"[",
"$",
"name",
"]",
";",
"return",
"null",
";",
"}"
] |
Returns the reflected parameter.
@param string $name
@return ReflectionProperty
|
[
"Returns",
"the",
"reflected",
"parameter",
"."
] |
3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001
|
https://github.com/ThomasSquall/PHPMagicAnnotations/blob/3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001/src/Reflection/Reflector.php#L96-L102
|
25,128
|
ThomasSquall/PHPMagicAnnotations
|
src/Reflection/Reflector.php
|
Reflector.getMethod
|
public function getMethod($name)
{
if ($this->reflected->hasMethod($name))
return $this->annotations['methods'][$name];
return null;
}
|
php
|
public function getMethod($name)
{
if ($this->reflected->hasMethod($name))
return $this->annotations['methods'][$name];
return null;
}
|
[
"public",
"function",
"getMethod",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"reflected",
"->",
"hasMethod",
"(",
"$",
"name",
")",
")",
"return",
"$",
"this",
"->",
"annotations",
"[",
"'methods'",
"]",
"[",
"$",
"name",
"]",
";",
"return",
"null",
";",
"}"
] |
Returns the reflected method.
@param string $name
@return ReflectionMethod
|
[
"Returns",
"the",
"reflected",
"method",
"."
] |
3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001
|
https://github.com/ThomasSquall/PHPMagicAnnotations/blob/3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001/src/Reflection/Reflector.php#L118-L124
|
25,129
|
Bistro/Router
|
lib/Bistro/Router/Router.php
|
Router.match
|
public function match($method, $url)
{
$params = array();
foreach ($this->routes as $name => $route)
{
if ($route->isMatch($method, $url))
{
$params = $route->getMatchedParams();
break;
}
}
return $params;
}
|
php
|
public function match($method, $url)
{
$params = array();
foreach ($this->routes as $name => $route)
{
if ($route->isMatch($method, $url))
{
$params = $route->getMatchedParams();
break;
}
}
return $params;
}
|
[
"public",
"function",
"match",
"(",
"$",
"method",
",",
"$",
"url",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"->",
"isMatch",
"(",
"$",
"method",
",",
"$",
"url",
")",
")",
"{",
"$",
"params",
"=",
"$",
"route",
"->",
"getMatchedParams",
"(",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"params",
";",
"}"
] |
Loops through all of the registered routes and tries to find a match.
@param string $method The http request method
@param string $url The url to match
@return array An array of matches params or an empty array
|
[
"Loops",
"through",
"all",
"of",
"the",
"registered",
"routes",
"and",
"tries",
"to",
"find",
"a",
"match",
"."
] |
ab5c3fff119c0e6c43c05300122b236afabfff41
|
https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Router.php#L53-L67
|
25,130
|
Bistro/Router
|
lib/Bistro/Router/Router.php
|
Router.url
|
public function url($name, $params = array())
{
if ( ! array_key_exists($name, $this->routes))
{
throw new \UnexpectedValueException("A route with the name {$name} was not found");
}
$route = $this->routes[$name];
return $route->url($params);
}
|
php
|
public function url($name, $params = array())
{
if ( ! array_key_exists($name, $this->routes))
{
throw new \UnexpectedValueException("A route with the name {$name} was not found");
}
$route = $this->routes[$name];
return $route->url($params);
}
|
[
"public",
"function",
"url",
"(",
"$",
"name",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"A route with the name {$name} was not found\"",
")",
";",
"}",
"$",
"route",
"=",
"$",
"this",
"->",
"routes",
"[",
"$",
"name",
"]",
";",
"return",
"$",
"route",
"->",
"url",
"(",
"$",
"params",
")",
";",
"}"
] |
Reverse routing helper.
@throws \UnexpectedValueException
@param string $name The route name
@param array $params Route parameters
@return string The route url
|
[
"Reverse",
"routing",
"helper",
"."
] |
ab5c3fff119c0e6c43c05300122b236afabfff41
|
https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Router.php#L141-L150
|
25,131
|
EvanDarwin/JSend
|
src/JSendResponse.php
|
JSendResponse.getArray
|
public function getArray()
{
$errors = empty($this->errors) ? null : $this->errors;
$response = array(
'status' => $this->getStatus(),
'data' => $this->data,
'errors' => $errors,
);
if (!is_null($this->code)) {
$response['code'] = $this->code;
}
if (!is_null($this->message)) {
$response['message'] = $this->message;
}
return $response;
}
|
php
|
public function getArray()
{
$errors = empty($this->errors) ? null : $this->errors;
$response = array(
'status' => $this->getStatus(),
'data' => $this->data,
'errors' => $errors,
);
if (!is_null($this->code)) {
$response['code'] = $this->code;
}
if (!is_null($this->message)) {
$response['message'] = $this->message;
}
return $response;
}
|
[
"public",
"function",
"getArray",
"(",
")",
"{",
"$",
"errors",
"=",
"empty",
"(",
"$",
"this",
"->",
"errors",
")",
"?",
"null",
":",
"$",
"this",
"->",
"errors",
";",
"$",
"response",
"=",
"array",
"(",
"'status'",
"=>",
"$",
"this",
"->",
"getStatus",
"(",
")",
",",
"'data'",
"=>",
"$",
"this",
"->",
"data",
",",
"'errors'",
"=>",
"$",
"errors",
",",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"code",
")",
")",
"{",
"$",
"response",
"[",
"'code'",
"]",
"=",
"$",
"this",
"->",
"code",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"message",
")",
")",
"{",
"$",
"response",
"[",
"'message'",
"]",
"=",
"$",
"this",
"->",
"message",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Returns the array version of the request response
@return array
|
[
"Returns",
"the",
"array",
"version",
"of",
"the",
"request",
"response"
] |
a31f7590e8503590d10012510ffc50a0ef064d02
|
https://github.com/EvanDarwin/JSend/blob/a31f7590e8503590d10012510ffc50a0ef064d02/src/JSendResponse.php#L117-L136
|
25,132
|
geoffroy-aubry/ErrorHandler
|
src/GAubry/ErrorHandler/ErrorHandler.php
|
ErrorHandler.internalShutdownFunction
|
public function internalShutdownFunction()
{
$aError = error_get_last();
if (! $this->aConfig['display_errors'] && is_array($aError) && $aError['type'] === E_ERROR) {
$oException = new \ErrorException(
$aError['message'],
$this->aConfig['default_error_code'],
$aError['type'],
$aError['file'],
$aError['line']
);
call_user_func($this->callbackGenericDisplay, $oException);
}
if (! empty($this->callbackAdditionalShutdownFct)) {
call_user_func($this->callbackAdditionalShutdownFct);
// @codeCoverageIgnoreStart
}
}
|
php
|
public function internalShutdownFunction()
{
$aError = error_get_last();
if (! $this->aConfig['display_errors'] && is_array($aError) && $aError['type'] === E_ERROR) {
$oException = new \ErrorException(
$aError['message'],
$this->aConfig['default_error_code'],
$aError['type'],
$aError['file'],
$aError['line']
);
call_user_func($this->callbackGenericDisplay, $oException);
}
if (! empty($this->callbackAdditionalShutdownFct)) {
call_user_func($this->callbackAdditionalShutdownFct);
// @codeCoverageIgnoreStart
}
}
|
[
"public",
"function",
"internalShutdownFunction",
"(",
")",
"{",
"$",
"aError",
"=",
"error_get_last",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"aConfig",
"[",
"'display_errors'",
"]",
"&&",
"is_array",
"(",
"$",
"aError",
")",
"&&",
"$",
"aError",
"[",
"'type'",
"]",
"===",
"E_ERROR",
")",
"{",
"$",
"oException",
"=",
"new",
"\\",
"ErrorException",
"(",
"$",
"aError",
"[",
"'message'",
"]",
",",
"$",
"this",
"->",
"aConfig",
"[",
"'default_error_code'",
"]",
",",
"$",
"aError",
"[",
"'type'",
"]",
",",
"$",
"aError",
"[",
"'file'",
"]",
",",
"$",
"aError",
"[",
"'line'",
"]",
")",
";",
"call_user_func",
"(",
"$",
"this",
"->",
"callbackGenericDisplay",
",",
"$",
"oException",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"callbackAdditionalShutdownFct",
")",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"callbackAdditionalShutdownFct",
")",
";",
"// @codeCoverageIgnoreStart",
"}",
"}"
] |
Registered shutdown function.
|
[
"Registered",
"shutdown",
"function",
"."
] |
77575e8e0e4312f9a5f334e27c33549ec6adb35b
|
https://github.com/geoffroy-aubry/ErrorHandler/blob/77575e8e0e4312f9a5f334e27c33549ec6adb35b/src/GAubry/ErrorHandler/ErrorHandler.php#L260-L277
|
25,133
|
rollerworks/search-core
|
Value/ValuesBag.php
|
ValuesBag.removeExcludedSimpleValue
|
public function removeExcludedSimpleValue(int $index)
{
if (isset($this->simpleExcludedValues[$index])) {
unset($this->simpleExcludedValues[$index]);
--$this->valuesCount;
}
return $this;
}
|
php
|
public function removeExcludedSimpleValue(int $index)
{
if (isset($this->simpleExcludedValues[$index])) {
unset($this->simpleExcludedValues[$index]);
--$this->valuesCount;
}
return $this;
}
|
[
"public",
"function",
"removeExcludedSimpleValue",
"(",
"int",
"$",
"index",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"simpleExcludedValues",
"[",
"$",
"index",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"simpleExcludedValues",
"[",
"$",
"index",
"]",
")",
";",
"--",
"$",
"this",
"->",
"valuesCount",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Remove a simple excluded value by index.
@param int $index
@return static
|
[
"Remove",
"a",
"simple",
"excluded",
"value",
"by",
"index",
"."
] |
6b5671b8c4d6298906ded768261b0a59845140fb
|
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesBag.php#L141-L150
|
25,134
|
rollerworks/search-core
|
Value/ValuesBag.php
|
ValuesBag.get
|
public function get(string $type): array
{
if (!isset($this->values[$type])) {
return [];
}
return $this->values[$type];
}
|
php
|
public function get(string $type): array
{
if (!isset($this->values[$type])) {
return [];
}
return $this->values[$type];
}
|
[
"public",
"function",
"get",
"(",
"string",
"$",
"type",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
";",
"}"
] |
Get all values from a specific type.
@return ValueHolder[]
|
[
"Get",
"all",
"values",
"from",
"a",
"specific",
"type",
"."
] |
6b5671b8c4d6298906ded768261b0a59845140fb
|
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesBag.php#L157-L164
|
25,135
|
rollerworks/search-core
|
Value/ValuesBag.php
|
ValuesBag.has
|
public function has(string $type): bool
{
return isset($this->values[$type]) && \count($this->values[$type]) > 0;
}
|
php
|
public function has(string $type): bool
{
return isset($this->values[$type]) && \count($this->values[$type]) > 0;
}
|
[
"public",
"function",
"has",
"(",
"string",
"$",
"type",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
")",
"&&",
"\\",
"count",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
")",
">",
"0",
";",
"}"
] |
Get a single value by type and index.
@return bool
|
[
"Get",
"a",
"single",
"value",
"by",
"type",
"and",
"index",
"."
] |
6b5671b8c4d6298906ded768261b0a59845140fb
|
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesBag.php#L171-L174
|
25,136
|
rollerworks/search-core
|
Value/ValuesBag.php
|
ValuesBag.remove
|
public function remove(string $type, int $index)
{
if (isset($this->values[$type][$index])) {
unset($this->values[$type][$index]);
--$this->valuesCount;
}
return $this;
}
|
php
|
public function remove(string $type, int $index)
{
if (isset($this->values[$type][$index])) {
unset($this->values[$type][$index]);
--$this->valuesCount;
}
return $this;
}
|
[
"public",
"function",
"remove",
"(",
"string",
"$",
"type",
",",
"int",
"$",
"index",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
"[",
"$",
"index",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
"[",
"$",
"index",
"]",
")",
";",
"--",
"$",
"this",
"->",
"valuesCount",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Remove a value by type and index.
@return ValuesBag New ValuesBag object with the referenced values removed
|
[
"Remove",
"a",
"value",
"by",
"type",
"and",
"index",
"."
] |
6b5671b8c4d6298906ded768261b0a59845140fb
|
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesBag.php#L181-L190
|
25,137
|
dms-org/common.structure
|
src/Colour/Colour.php
|
Colour.fromRgbString
|
public static function fromRgbString(string $string) : Colour
{
list($r, $g, $b) = ColourStringParser::parseRgbString($string);
return new self($r, $g, $b);
}
|
php
|
public static function fromRgbString(string $string) : Colour
{
list($r, $g, $b) = ColourStringParser::parseRgbString($string);
return new self($r, $g, $b);
}
|
[
"public",
"static",
"function",
"fromRgbString",
"(",
"string",
"$",
"string",
")",
":",
"Colour",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"ColourStringParser",
"::",
"parseRgbString",
"(",
"$",
"string",
")",
";",
"return",
"new",
"self",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] |
Creates a new colour from the supplied rgb string value
@param string $string eg: "rgb(100, 100, 100)"
@return Colour
@throws InvalidArgumentException
|
[
"Creates",
"a",
"new",
"colour",
"from",
"the",
"supplied",
"rgb",
"string",
"value"
] |
23f122182f60df5ec847047a81a39c8aab019ff1
|
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/Colour.php#L84-L89
|
25,138
|
dms-org/common.structure
|
src/Colour/Colour.php
|
Colour.fromHexString
|
public static function fromHexString(string $string) : Colour
{
list($r, $g, $b) = ColourStringParser::parseHexString($string);
return new self($r, $g, $b);
}
|
php
|
public static function fromHexString(string $string) : Colour
{
list($r, $g, $b) = ColourStringParser::parseHexString($string);
return new self($r, $g, $b);
}
|
[
"public",
"static",
"function",
"fromHexString",
"(",
"string",
"$",
"string",
")",
":",
"Colour",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"ColourStringParser",
"::",
"parseHexString",
"(",
"$",
"string",
")",
";",
"return",
"new",
"self",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] |
Creates a new colour from the supplied hex value
@param string $string
@return Colour
|
[
"Creates",
"a",
"new",
"colour",
"from",
"the",
"supplied",
"hex",
"value"
] |
23f122182f60df5ec847047a81a39c8aab019ff1
|
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/Colour.php#L98-L103
|
25,139
|
dms-org/common.structure
|
src/Colour/Colour.php
|
Colour.toHexString
|
public function toHexString() : string
{
return '#' . sprintf('%02x', $this->red) . sprintf('%02x', $this->green) . sprintf('%02x', $this->blue);
}
|
php
|
public function toHexString() : string
{
return '#' . sprintf('%02x', $this->red) . sprintf('%02x', $this->green) . sprintf('%02x', $this->blue);
}
|
[
"public",
"function",
"toHexString",
"(",
")",
":",
"string",
"{",
"return",
"'#'",
".",
"sprintf",
"(",
"'%02x'",
",",
"$",
"this",
"->",
"red",
")",
".",
"sprintf",
"(",
"'%02x'",
",",
"$",
"this",
"->",
"green",
")",
".",
"sprintf",
"(",
"'%02x'",
",",
"$",
"this",
"->",
"blue",
")",
";",
"}"
] |
Gets the colour as a hex string.
@return string
|
[
"Gets",
"the",
"colour",
"as",
"a",
"hex",
"string",
"."
] |
23f122182f60df5ec847047a81a39c8aab019ff1
|
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/Colour.php#L144-L147
|
25,140
|
robertmain/communique
|
src/Communique.php
|
Communique._call
|
protected function _call(\Communique\RESTClientRequest $request, $debug = null) {
foreach ($this->_interceptors as $request_interceptor) {
$request = $request_interceptor->request($request);
}
$response = $this->_http->request($request);
foreach ($this->_interceptors as $response_interceptor) {
$response = $response_interceptor->response($response);
}
if ($debug) {
$debug($request, $response);
}
return $response;
}
|
php
|
protected function _call(\Communique\RESTClientRequest $request, $debug = null) {
foreach ($this->_interceptors as $request_interceptor) {
$request = $request_interceptor->request($request);
}
$response = $this->_http->request($request);
foreach ($this->_interceptors as $response_interceptor) {
$response = $response_interceptor->response($response);
}
if ($debug) {
$debug($request, $response);
}
return $response;
}
|
[
"protected",
"function",
"_call",
"(",
"\\",
"Communique",
"\\",
"RESTClientRequest",
"$",
"request",
",",
"$",
"debug",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_interceptors",
"as",
"$",
"request_interceptor",
")",
"{",
"$",
"request",
"=",
"$",
"request_interceptor",
"->",
"request",
"(",
"$",
"request",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"_http",
"->",
"request",
"(",
"$",
"request",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_interceptors",
"as",
"$",
"response_interceptor",
")",
"{",
"$",
"response",
"=",
"$",
"response_interceptor",
"->",
"response",
"(",
"$",
"response",
")",
";",
"}",
"if",
"(",
"$",
"debug",
")",
"{",
"$",
"debug",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Makes the HTTP request using the chosen HTTP client.
@param \Communique\RESTClientRequest $request A RESTClientRequest object encapsulating the request
@param callable $debug A debugging callback to be run after the request has finished. This function is expected to accept two parameters, \Communique\RESTClientRequest and \Communique\RESTClientResponse
@return \Communique\RESTClientResponse A RESTClientResponse object encapsulating the response
|
[
"Makes",
"the",
"HTTP",
"request",
"using",
"the",
"chosen",
"HTTP",
"client",
"."
] |
025d4f0f9bc391f6f9fc653a363158d2f83e9051
|
https://github.com/robertmain/communique/blob/025d4f0f9bc391f6f9fc653a363158d2f83e9051/src/Communique.php#L75-L87
|
25,141
|
robertmain/communique
|
src/Communique.php
|
Communique.put
|
public function put($url, $payload, array $headers = array(), $debug = null) {
$request = new \Communique\RESTClientRequest('put', $this->_BASE_URL . $url, $payload, $headers);
return $this->_call($request, $debug);
}
|
php
|
public function put($url, $payload, array $headers = array(), $debug = null) {
$request = new \Communique\RESTClientRequest('put', $this->_BASE_URL . $url, $payload, $headers);
return $this->_call($request, $debug);
}
|
[
"public",
"function",
"put",
"(",
"$",
"url",
",",
"$",
"payload",
",",
"array",
"$",
"headers",
"=",
"array",
"(",
")",
",",
"$",
"debug",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"new",
"\\",
"Communique",
"\\",
"RESTClientRequest",
"(",
"'put'",
",",
"$",
"this",
"->",
"_BASE_URL",
".",
"$",
"url",
",",
"$",
"payload",
",",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"_call",
"(",
"$",
"request",
",",
"$",
"debug",
")",
";",
"}"
] |
Make an HTTP PUT request
@param String $url The API to make the request to
@param mixed $payload The payload of the request(any data you wish to send across)
@param array $headers Any headers you want to add to the request(optional)
@param callable $debug A function to be used for request debugging.
This function should accept two parameters, one for the request object one for the response object.
@return \Communique\RESTClientResponse REST response encapsulation object
|
[
"Make",
"an",
"HTTP",
"PUT",
"request"
] |
025d4f0f9bc391f6f9fc653a363158d2f83e9051
|
https://github.com/robertmain/communique/blob/025d4f0f9bc391f6f9fc653a363158d2f83e9051/src/Communique.php#L112-L115
|
25,142
|
dpiquet/Mapping
|
src/Mapping.php
|
Mapping.addMapping
|
public function addMapping($key, array $accepted_names, $required = true)
{
$lower_accepted_names = [];
foreach($accepted_names as $name) {
$lower_name = strtolower($name);
if ($this->getMapping($lower_name) !== false) {
throw new MappingOverlapException(sprintf('Column name %s already mapped on %s', $name, $key));
}
$lower_accepted_names[] = $lower_name;
}
$this->mappings[$key] = [
'accepted_names' => $lower_accepted_names,
'required' => $required,
'index' => null,
];
return $this;
}
|
php
|
public function addMapping($key, array $accepted_names, $required = true)
{
$lower_accepted_names = [];
foreach($accepted_names as $name) {
$lower_name = strtolower($name);
if ($this->getMapping($lower_name) !== false) {
throw new MappingOverlapException(sprintf('Column name %s already mapped on %s', $name, $key));
}
$lower_accepted_names[] = $lower_name;
}
$this->mappings[$key] = [
'accepted_names' => $lower_accepted_names,
'required' => $required,
'index' => null,
];
return $this;
}
|
[
"public",
"function",
"addMapping",
"(",
"$",
"key",
",",
"array",
"$",
"accepted_names",
",",
"$",
"required",
"=",
"true",
")",
"{",
"$",
"lower_accepted_names",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"accepted_names",
"as",
"$",
"name",
")",
"{",
"$",
"lower_name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getMapping",
"(",
"$",
"lower_name",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"MappingOverlapException",
"(",
"sprintf",
"(",
"'Column name %s already mapped on %s'",
",",
"$",
"name",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"lower_accepted_names",
"[",
"]",
"=",
"$",
"lower_name",
";",
"}",
"$",
"this",
"->",
"mappings",
"[",
"$",
"key",
"]",
"=",
"[",
"'accepted_names'",
"=>",
"$",
"lower_accepted_names",
",",
"'required'",
"=>",
"$",
"required",
",",
"'index'",
"=>",
"null",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a mapping expectation
@param string $key Mapping identifier
@param array $accepted_names Allowed columns names
@param boolean $required Column is required
@return $this
@throws MappingOverlapException
|
[
"Add",
"a",
"mapping",
"expectation"
] |
13cccfa490003a12b1c047c0c21f6a24815dd4ba
|
https://github.com/dpiquet/Mapping/blob/13cccfa490003a12b1c047c0c21f6a24815dd4ba/src/Mapping.php#L35-L56
|
25,143
|
dpiquet/Mapping
|
src/Mapping.php
|
Mapping.getMapping
|
protected function getMapping($name)
{
foreach($this->mappings as $key => $data) {
if (in_array(strtolower($name), $data['accepted_names'])) {
return $key;
}
}
return false;
}
|
php
|
protected function getMapping($name)
{
foreach($this->mappings as $key => $data) {
if (in_array(strtolower($name), $data['accepted_names'])) {
return $key;
}
}
return false;
}
|
[
"protected",
"function",
"getMapping",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"mappings",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"name",
")",
",",
"$",
"data",
"[",
"'accepted_names'",
"]",
")",
")",
"{",
"return",
"$",
"key",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Get a mapped column index
@param string $name
@return int|false
|
[
"Get",
"a",
"mapped",
"column",
"index"
] |
13cccfa490003a12b1c047c0c21f6a24815dd4ba
|
https://github.com/dpiquet/Mapping/blob/13cccfa490003a12b1c047c0c21f6a24815dd4ba/src/Mapping.php#L76-L85
|
25,144
|
dpiquet/Mapping
|
src/Mapping.php
|
Mapping.map
|
public function map(array $columns)
{
$maps = [];
$seenKeys = [];
foreach($columns as $index => $column_name) {
$key = $this->getMapping($column_name);
if ($key === false) {
continue;
}
if (in_array($key, $seenKeys)) {
throw new OverlapColumnException($key);
}
$seenKeys[] = $key;
$this->mappings[$key]['index'] = $index;
$maps[$key] = $index;
}
// Check all required mappings are satisfied
foreach($this->mappings as $key => $data) {
if ($data['required'] && !array_key_exists($key, $maps)) {
throw new MappingIncompleteException($key);
}
}
return $maps;
}
|
php
|
public function map(array $columns)
{
$maps = [];
$seenKeys = [];
foreach($columns as $index => $column_name) {
$key = $this->getMapping($column_name);
if ($key === false) {
continue;
}
if (in_array($key, $seenKeys)) {
throw new OverlapColumnException($key);
}
$seenKeys[] = $key;
$this->mappings[$key]['index'] = $index;
$maps[$key] = $index;
}
// Check all required mappings are satisfied
foreach($this->mappings as $key => $data) {
if ($data['required'] && !array_key_exists($key, $maps)) {
throw new MappingIncompleteException($key);
}
}
return $maps;
}
|
[
"public",
"function",
"map",
"(",
"array",
"$",
"columns",
")",
"{",
"$",
"maps",
"=",
"[",
"]",
";",
"$",
"seenKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"index",
"=>",
"$",
"column_name",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getMapping",
"(",
"$",
"column_name",
")",
";",
"if",
"(",
"$",
"key",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"seenKeys",
")",
")",
"{",
"throw",
"new",
"OverlapColumnException",
"(",
"$",
"key",
")",
";",
"}",
"$",
"seenKeys",
"[",
"]",
"=",
"$",
"key",
";",
"$",
"this",
"->",
"mappings",
"[",
"$",
"key",
"]",
"[",
"'index'",
"]",
"=",
"$",
"index",
";",
"$",
"maps",
"[",
"$",
"key",
"]",
"=",
"$",
"index",
";",
"}",
"// Check all required mappings are satisfied",
"foreach",
"(",
"$",
"this",
"->",
"mappings",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"'required'",
"]",
"&&",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"maps",
")",
")",
"{",
"throw",
"new",
"MappingIncompleteException",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"maps",
";",
"}"
] |
Map columns on array
@param array $columns Array to map
@return array mappings
@throws MappingIncompleteException
@throws OverlapColumnException
|
[
"Map",
"columns",
"on",
"array"
] |
13cccfa490003a12b1c047c0c21f6a24815dd4ba
|
https://github.com/dpiquet/Mapping/blob/13cccfa490003a12b1c047c0c21f6a24815dd4ba/src/Mapping.php#L96-L128
|
25,145
|
TitaPHP/framework
|
src/TitaPHP/Helpers/NumberFormatter.php
|
NumberFormatter.currency
|
public static function currency( $value, $decimals = 2, $currencyCode = null )
{
$app = Application::instance();
$currencyCode = $currencyCode ?: $app->getConfig('app.settings.currency');
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $nf->formatCurrency($value, $currencyCode);
}
|
php
|
public static function currency( $value, $decimals = 2, $currencyCode = null )
{
$app = Application::instance();
$currencyCode = $currencyCode ?: $app->getConfig('app.settings.currency');
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $nf->formatCurrency($value, $currencyCode);
}
|
[
"public",
"static",
"function",
"currency",
"(",
"$",
"value",
",",
"$",
"decimals",
"=",
"2",
",",
"$",
"currencyCode",
"=",
"null",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"instance",
"(",
")",
";",
"$",
"currencyCode",
"=",
"$",
"currencyCode",
"?",
":",
"$",
"app",
"->",
"getConfig",
"(",
"'app.settings.currency'",
")",
";",
"$",
"nf",
"=",
"new",
"\\",
"NumberFormatter",
"(",
"\\",
"Locale",
"::",
"getDefault",
"(",
")",
",",
"\\",
"NumberFormatter",
"::",
"CURRENCY",
")",
";",
"$",
"nf",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"MAX_FRACTION_DIGITS",
",",
"$",
"decimals",
")",
";",
"return",
"$",
"nf",
"->",
"formatCurrency",
"(",
"$",
"value",
",",
"$",
"currencyCode",
")",
";",
"}"
] |
returns a string with currency formatted accordingly to locale settings
@param string $value
@param string $decimals
@param string $currencyCode
@return string
|
[
"returns",
"a",
"string",
"with",
"currency",
"formatted",
"accordingly",
"to",
"locale",
"settings"
] |
72283a45733a49c1d9c1fc0eba22ff13a802295c
|
https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Helpers/NumberFormatter.php#L14-L22
|
25,146
|
TitaPHP/framework
|
src/TitaPHP/Helpers/NumberFormatter.php
|
NumberFormatter.decimal
|
public static function decimal( $value, $decimals = 2 )
{
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $nf->format($value);
}
|
php
|
public static function decimal( $value, $decimals = 2 )
{
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $nf->format($value);
}
|
[
"public",
"static",
"function",
"decimal",
"(",
"$",
"value",
",",
"$",
"decimals",
"=",
"2",
")",
"{",
"$",
"nf",
"=",
"new",
"\\",
"NumberFormatter",
"(",
"\\",
"Locale",
"::",
"getDefault",
"(",
")",
",",
"\\",
"NumberFormatter",
"::",
"DECIMAL",
")",
";",
"$",
"nf",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"MAX_FRACTION_DIGITS",
",",
"$",
"decimals",
")",
";",
"return",
"$",
"nf",
"->",
"format",
"(",
"$",
"value",
")",
";",
"}"
] |
returns a string with decimal formatted accordingly to locale settings
@param string $value
@param string $decimals
@return string
|
[
"returns",
"a",
"string",
"with",
"decimal",
"formatted",
"accordingly",
"to",
"locale",
"settings"
] |
72283a45733a49c1d9c1fc0eba22ff13a802295c
|
https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Helpers/NumberFormatter.php#L30-L35
|
25,147
|
TitaPHP/framework
|
src/TitaPHP/Helpers/NumberFormatter.php
|
NumberFormatter.percentage
|
public static function percentage( $value, $decimals = 0 )
{
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::PERCENT);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $value > 1 ? $nf->format($value) : $nf->format($value);
}
|
php
|
public static function percentage( $value, $decimals = 0 )
{
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::PERCENT);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $value > 1 ? $nf->format($value) : $nf->format($value);
}
|
[
"public",
"static",
"function",
"percentage",
"(",
"$",
"value",
",",
"$",
"decimals",
"=",
"0",
")",
"{",
"$",
"nf",
"=",
"new",
"\\",
"NumberFormatter",
"(",
"\\",
"Locale",
"::",
"getDefault",
"(",
")",
",",
"\\",
"NumberFormatter",
"::",
"PERCENT",
")",
";",
"$",
"nf",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"MAX_FRACTION_DIGITS",
",",
"$",
"decimals",
")",
";",
"return",
"$",
"value",
">",
"1",
"?",
"$",
"nf",
"->",
"format",
"(",
"$",
"value",
")",
":",
"$",
"nf",
"->",
"format",
"(",
"$",
"value",
")",
";",
"}"
] |
returns a string with percentage formatted accordingly to Yii dateFormatter
@param $value
@param $decimals
@return string
|
[
"returns",
"a",
"string",
"with",
"percentage",
"formatted",
"accordingly",
"to",
"Yii",
"dateFormatter"
] |
72283a45733a49c1d9c1fc0eba22ff13a802295c
|
https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Helpers/NumberFormatter.php#L54-L59
|
25,148
|
shrink0r/php-schema
|
src/Property/FloatProperty.php
|
FloatProperty.validate
|
public function validate($value)
{
return is_float($value) ? Ok::unit() : Error::unit([ Error::NON_FLOAT ]);
}
|
php
|
public function validate($value)
{
return is_float($value) ? Ok::unit() : Error::unit([ Error::NON_FLOAT ]);
}
|
[
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"return",
"is_float",
"(",
"$",
"value",
")",
"?",
"Ok",
"::",
"unit",
"(",
")",
":",
"Error",
"::",
"unit",
"(",
"[",
"Error",
"::",
"NON_FLOAT",
"]",
")",
";",
"}"
] |
Tells if a given value is a valid float.
@param mixed $value
@return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned.
|
[
"Tells",
"if",
"a",
"given",
"value",
"is",
"a",
"valid",
"float",
"."
] |
94293fe897af376dd9d05962e2c516079409dd29
|
https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/FloatProperty.php#L18-L21
|
25,149
|
jenskooij/cloudcontrol
|
src/components/FormComponent.php
|
FormComponent.checkParameters
|
protected function checkParameters()
{
$this->checkDocumentTypeParameter();
$this->checkResponseFolderParameter();
$this->checkSubTemplateParameter();
$this->checkFormParameterNameParameter();
$this->checkThankYouMessageParameter();
$this->checkSubmitOncePerSessionParameter();
}
|
php
|
protected function checkParameters()
{
$this->checkDocumentTypeParameter();
$this->checkResponseFolderParameter();
$this->checkSubTemplateParameter();
$this->checkFormParameterNameParameter();
$this->checkThankYouMessageParameter();
$this->checkSubmitOncePerSessionParameter();
}
|
[
"protected",
"function",
"checkParameters",
"(",
")",
"{",
"$",
"this",
"->",
"checkDocumentTypeParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkResponseFolderParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkSubTemplateParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkFormParameterNameParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkThankYouMessageParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkSubmitOncePerSessionParameter",
"(",
")",
";",
"}"
] |
Checks if parameters were given in the CMS configuration and
sets them to their respective fields
|
[
"Checks",
"if",
"parameters",
"were",
"given",
"in",
"the",
"CMS",
"configuration",
"and",
"sets",
"them",
"to",
"their",
"respective",
"fields"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L103-L111
|
25,150
|
jenskooij/cloudcontrol
|
src/components/FormComponent.php
|
FormComponent.initialize
|
protected function initialize($storage)
{
$this->parameters[self::PARAMETER_SMALLEST_IMAGE] = $storage->getImageSet()->getSmallestImageSet();
$this->parameters[self::PARAMETER_CMS_PREFIX] = '';
$this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $this->storage->getDocumentTypes()->getDocumentTypeBySlug($this->documentType,
true);
$this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes()->getDocumentTypes();
$this->parameters[self::PARAMETER_HIDE_TITLE_AND_STATE] = true;
$this->parameters[self::PARAMETER_FORM_ID] = $this->formId;
}
|
php
|
protected function initialize($storage)
{
$this->parameters[self::PARAMETER_SMALLEST_IMAGE] = $storage->getImageSet()->getSmallestImageSet();
$this->parameters[self::PARAMETER_CMS_PREFIX] = '';
$this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $this->storage->getDocumentTypes()->getDocumentTypeBySlug($this->documentType,
true);
$this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes()->getDocumentTypes();
$this->parameters[self::PARAMETER_HIDE_TITLE_AND_STATE] = true;
$this->parameters[self::PARAMETER_FORM_ID] = $this->formId;
}
|
[
"protected",
"function",
"initialize",
"(",
"$",
"storage",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_SMALLEST_IMAGE",
"]",
"=",
"$",
"storage",
"->",
"getImageSet",
"(",
")",
"->",
"getSmallestImageSet",
"(",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_CMS_PREFIX",
"]",
"=",
"''",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_DOCUMENT_TYPE",
"]",
"=",
"$",
"this",
"->",
"storage",
"->",
"getDocumentTypes",
"(",
")",
"->",
"getDocumentTypeBySlug",
"(",
"$",
"this",
"->",
"documentType",
",",
"true",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_DOCUMENT_TYPES",
"]",
"=",
"$",
"this",
"->",
"storage",
"->",
"getDocumentTypes",
"(",
")",
"->",
"getDocumentTypes",
"(",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_HIDE_TITLE_AND_STATE",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
"=",
"$",
"this",
"->",
"formId",
";",
"}"
] |
Sets variables needed for rendering the form template
@param Storage $storage
|
[
"Sets",
"variables",
"needed",
"for",
"rendering",
"the",
"form",
"template"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L118-L128
|
25,151
|
jenskooij/cloudcontrol
|
src/components/FormComponent.php
|
FormComponent.setFormId
|
protected function setFormId()
{
if (isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
} else {
$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] = (string)microtime(true);
$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = false;
$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
}
}
|
php
|
protected function setFormId()
{
if (isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
} else {
$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] = (string)microtime(true);
$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = false;
$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
}
}
|
[
"protected",
"function",
"setFormId",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
")",
")",
"{",
"$",
"this",
"->",
"formId",
"=",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
";",
"}",
"else",
"{",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
"=",
"(",
"string",
")",
"microtime",
"(",
"true",
")",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"'submitted'",
"]",
"=",
"false",
";",
"$",
"this",
"->",
"formId",
"=",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
";",
"}",
"}"
] |
Sets a unique id for this particular form, so it can recognize
it when a submit occurs
|
[
"Sets",
"a",
"unique",
"id",
"for",
"this",
"particular",
"form",
"so",
"it",
"can",
"recognize",
"it",
"when",
"a",
"submit",
"occurs"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L169-L178
|
25,152
|
jenskooij/cloudcontrol
|
src/components/FormComponent.php
|
FormComponent.setUserSessionBackup
|
protected function setUserSessionBackup()
{
$this->userSessionBackup = isset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]) ? $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] : null;
$fakeUser = new \stdClass();
$fakeUser->username = self::SESSION_PARAMETER_FORM_COMPONENT;
$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $fakeUser;
}
|
php
|
protected function setUserSessionBackup()
{
$this->userSessionBackup = isset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]) ? $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] : null;
$fakeUser = new \stdClass();
$fakeUser->username = self::SESSION_PARAMETER_FORM_COMPONENT;
$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $fakeUser;
}
|
[
"protected",
"function",
"setUserSessionBackup",
"(",
")",
"{",
"$",
"this",
"->",
"userSessionBackup",
"=",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
")",
"?",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
":",
"null",
";",
"$",
"fakeUser",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"fakeUser",
"->",
"username",
"=",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
"=",
"$",
"fakeUser",
";",
"}"
] |
Temporarily stores the current user session in a backup variable
and sets a fake user instead
|
[
"Temporarily",
"stores",
"the",
"current",
"user",
"session",
"in",
"a",
"backup",
"variable",
"and",
"sets",
"a",
"fake",
"user",
"instead"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L198-L204
|
25,153
|
jenskooij/cloudcontrol
|
src/components/FormComponent.php
|
FormComponent.restoreUserSessionBackup
|
protected function restoreUserSessionBackup()
{
if ($this->userSessionBackup === null) {
unset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]);
} else {
$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $this->userSessionBackup;
}
}
|
php
|
protected function restoreUserSessionBackup()
{
if ($this->userSessionBackup === null) {
unset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]);
} else {
$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $this->userSessionBackup;
}
}
|
[
"protected",
"function",
"restoreUserSessionBackup",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"userSessionBackup",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
")",
";",
"}",
"else",
"{",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
"=",
"$",
"this",
"->",
"userSessionBackup",
";",
"}",
"}"
] |
Removes the fake user and restores the existing user
session if it was there
|
[
"Removes",
"the",
"fake",
"user",
"and",
"restores",
"the",
"existing",
"user",
"session",
"if",
"it",
"was",
"there"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L210-L217
|
25,154
|
jenskooij/cloudcontrol
|
src/components/FormComponent.php
|
FormComponent.checkFormIdInPost
|
private function checkFormIdInPost($request)
{
if (!isset($request::$post[self::PARAMETER_FORM_ID])) {
return false;
}
if (!$request::$post[self::PARAMETER_FORM_ID] === $this->formId) {
return false;
}
return true;
}
|
php
|
private function checkFormIdInPost($request)
{
if (!isset($request::$post[self::PARAMETER_FORM_ID])) {
return false;
}
if (!$request::$post[self::PARAMETER_FORM_ID] === $this->formId) {
return false;
}
return true;
}
|
[
"private",
"function",
"checkFormIdInPost",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"request",
"::",
"$",
"post",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"request",
"::",
"$",
"post",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
"===",
"$",
"this",
"->",
"formId",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks if form id is set in _POST variable
@param $request
@return bool
|
[
"Checks",
"if",
"form",
"id",
"is",
"set",
"in",
"_POST",
"variable"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L364-L375
|
25,155
|
jenskooij/cloudcontrol
|
src/components/FormComponent.php
|
FormComponent.checkFormIdInSession
|
private function checkFormIdInSession()
{
if (!isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
return false;
}
if (!$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] === $this->formId) {
return false;
}
return true;
}
|
php
|
private function checkFormIdInSession()
{
if (!isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
return false;
}
if (!$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] === $this->formId) {
return false;
}
return true;
}
|
[
"private",
"function",
"checkFormIdInSession",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
"===",
"$",
"this",
"->",
"formId",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks if form is is set in _SESSION variable
@return bool
|
[
"Checks",
"if",
"form",
"is",
"is",
"set",
"in",
"_SESSION",
"variable"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L381-L392
|
25,156
|
DreadLabs/app-migration
|
src/Mediator.php
|
Mediator.negotiate
|
public function negotiate()
{
// This is a workaround for PHP5.5, @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/143#issuecomment-108148498
$catchedException = null;
try {
$this->lock->acquire();
$this->executeMigrations();
} catch (LockingException $exc) {
$this->logger->emergency($exc->getMessage());
$catchedException = $exc;
} catch (TopologyViolationException $exc) {
$this->logger->emergency('The version to migrate to is older than the current one.');
$catchedException = $exc;
} catch (MigrationException $exc) {
$this->logger->emergency('Migration of version ' . $exc->getCode() . ' failed.', array($exc->getMessage()));
$catchedException = $exc;
}
$this->lock->release();
if (!is_null($catchedException)) {
throw $catchedException;
}
}
|
php
|
public function negotiate()
{
// This is a workaround for PHP5.5, @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/143#issuecomment-108148498
$catchedException = null;
try {
$this->lock->acquire();
$this->executeMigrations();
} catch (LockingException $exc) {
$this->logger->emergency($exc->getMessage());
$catchedException = $exc;
} catch (TopologyViolationException $exc) {
$this->logger->emergency('The version to migrate to is older than the current one.');
$catchedException = $exc;
} catch (MigrationException $exc) {
$this->logger->emergency('Migration of version ' . $exc->getCode() . ' failed.', array($exc->getMessage()));
$catchedException = $exc;
}
$this->lock->release();
if (!is_null($catchedException)) {
throw $catchedException;
}
}
|
[
"public",
"function",
"negotiate",
"(",
")",
"{",
"// This is a workaround for PHP5.5, @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/143#issuecomment-108148498",
"$",
"catchedException",
"=",
"null",
";",
"try",
"{",
"$",
"this",
"->",
"lock",
"->",
"acquire",
"(",
")",
";",
"$",
"this",
"->",
"executeMigrations",
"(",
")",
";",
"}",
"catch",
"(",
"LockingException",
"$",
"exc",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"emergency",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"catchedException",
"=",
"$",
"exc",
";",
"}",
"catch",
"(",
"TopologyViolationException",
"$",
"exc",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"emergency",
"(",
"'The version to migrate to is older than the current one.'",
")",
";",
"$",
"catchedException",
"=",
"$",
"exc",
";",
"}",
"catch",
"(",
"MigrationException",
"$",
"exc",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"emergency",
"(",
"'Migration of version '",
".",
"$",
"exc",
"->",
"getCode",
"(",
")",
".",
"' failed.'",
",",
"array",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"$",
"catchedException",
"=",
"$",
"exc",
";",
"}",
"$",
"this",
"->",
"lock",
"->",
"release",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"catchedException",
")",
")",
"{",
"throw",
"$",
"catchedException",
";",
"}",
"}"
] |
Negotiates the migration process
@return void
@throws MigrationException If something went wrong with the involved
components
|
[
"Negotiates",
"the",
"migration",
"process"
] |
a416d770c51db28db9750251b40cd4f13e57c148
|
https://github.com/DreadLabs/app-migration/blob/a416d770c51db28db9750251b40cd4f13e57c148/src/Mediator.php#L72-L99
|
25,157
|
Innmind/Math
|
src/Geometry/Theorem/AlKashi.php
|
AlKashi.angle
|
public static function angle(
Segment $a,
Segment $b,
Segment $c
): Degree {
$a = $a->length();
$b = $b->length();
$c = $c->length();
$longest = max($a, $b, $c);
$opposites = (new Set(Number::class))
->add($a)
->add($b)
->add($c)
->remove($longest);
$opposites = add(...$opposites);
if ($longest->higherThan($opposites) && !$longest->equals($opposites)) {
throw new SegmentsCannotBeJoined;
}
$cosAB = $a
->power(new Integer(2))
->add($b->power(new Integer(2)))
->subtract($c->power(new Integer(2)))
->divideBy(
(new Integer(2))
->multiplyBy($a)
->multiplyBy($b)
);
return arcCosine($cosAB)->toDegree();
}
|
php
|
public static function angle(
Segment $a,
Segment $b,
Segment $c
): Degree {
$a = $a->length();
$b = $b->length();
$c = $c->length();
$longest = max($a, $b, $c);
$opposites = (new Set(Number::class))
->add($a)
->add($b)
->add($c)
->remove($longest);
$opposites = add(...$opposites);
if ($longest->higherThan($opposites) && !$longest->equals($opposites)) {
throw new SegmentsCannotBeJoined;
}
$cosAB = $a
->power(new Integer(2))
->add($b->power(new Integer(2)))
->subtract($c->power(new Integer(2)))
->divideBy(
(new Integer(2))
->multiplyBy($a)
->multiplyBy($b)
);
return arcCosine($cosAB)->toDegree();
}
|
[
"public",
"static",
"function",
"angle",
"(",
"Segment",
"$",
"a",
",",
"Segment",
"$",
"b",
",",
"Segment",
"$",
"c",
")",
":",
"Degree",
"{",
"$",
"a",
"=",
"$",
"a",
"->",
"length",
"(",
")",
";",
"$",
"b",
"=",
"$",
"b",
"->",
"length",
"(",
")",
";",
"$",
"c",
"=",
"$",
"c",
"->",
"length",
"(",
")",
";",
"$",
"longest",
"=",
"max",
"(",
"$",
"a",
",",
"$",
"b",
",",
"$",
"c",
")",
";",
"$",
"opposites",
"=",
"(",
"new",
"Set",
"(",
"Number",
"::",
"class",
")",
")",
"->",
"add",
"(",
"$",
"a",
")",
"->",
"add",
"(",
"$",
"b",
")",
"->",
"add",
"(",
"$",
"c",
")",
"->",
"remove",
"(",
"$",
"longest",
")",
";",
"$",
"opposites",
"=",
"add",
"(",
"...",
"$",
"opposites",
")",
";",
"if",
"(",
"$",
"longest",
"->",
"higherThan",
"(",
"$",
"opposites",
")",
"&&",
"!",
"$",
"longest",
"->",
"equals",
"(",
"$",
"opposites",
")",
")",
"{",
"throw",
"new",
"SegmentsCannotBeJoined",
";",
"}",
"$",
"cosAB",
"=",
"$",
"a",
"->",
"power",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
"->",
"add",
"(",
"$",
"b",
"->",
"power",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
")",
"->",
"subtract",
"(",
"$",
"c",
"->",
"power",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
")",
"->",
"divideBy",
"(",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
"->",
"multiplyBy",
"(",
"$",
"a",
")",
"->",
"multiplyBy",
"(",
"$",
"b",
")",
")",
";",
"return",
"arcCosine",
"(",
"$",
"cosAB",
")",
"->",
"toDegree",
"(",
")",
";",
"}"
] |
Return the angle between a and b sides
|
[
"Return",
"the",
"angle",
"between",
"a",
"and",
"b",
"sides"
] |
ac9ad4dd1852c145e90f5edc0f38a873b125a50b
|
https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Geometry/Theorem/AlKashi.php#L55-L86
|
25,158
|
PenoaksDev/Milky-Framework
|
src/Milky/Framework.php
|
Framework.buildPath
|
public function buildPath()
{
$slugs = func_get_args();
if ( is_array( $slugs[0] ) )
$slugs = $slugs[0];
if ( count( $slugs ) == 0 )
return $this->basePath;
if ( Str::startsWith( $slugs[0], '__' ) )
{
$key = substr( $slugs[0], 2 );
if ( $key == 'base' )
$slugs[0] = $this->basePath;
else if ( array_key_exists( $key, $this->paths ) )
{
$paths = $this->paths[$key];
if ( is_array( $paths ) )
{
unset( $slugs[0] );
foreach ( array_reverse( $paths ) as $slug )
$slugs = Arr::prepend( $slugs, $slug );
}
else
$slugs[0] = $paths;
}
else
throw new FrameworkException( "Path [" . $key . "] is not set" );
return $this->buildPath( $slugs );
}
else if ( !Str::startsWith( $slugs[0], '/' ) )
$slugs = Arr::prepend( $slugs, $this->basePath );
$dir = strpos( end( $slugs ), '.' ) !== false ? implode( DIRECTORY_SEPARATOR, array_slice( $slugs, 0, count( $slugs ) - 1 ) ) : implode( DIRECTORY_SEPARATOR, $slugs );
if ( !file_exists( $dir ) )
if ( !mkdir( $dir, 0755, true ) )
throw new FrameworkException( "The directory [" . $dir . "] does not exist and we failed to create it" );
return implode( DIRECTORY_SEPARATOR, $slugs );
}
|
php
|
public function buildPath()
{
$slugs = func_get_args();
if ( is_array( $slugs[0] ) )
$slugs = $slugs[0];
if ( count( $slugs ) == 0 )
return $this->basePath;
if ( Str::startsWith( $slugs[0], '__' ) )
{
$key = substr( $slugs[0], 2 );
if ( $key == 'base' )
$slugs[0] = $this->basePath;
else if ( array_key_exists( $key, $this->paths ) )
{
$paths = $this->paths[$key];
if ( is_array( $paths ) )
{
unset( $slugs[0] );
foreach ( array_reverse( $paths ) as $slug )
$slugs = Arr::prepend( $slugs, $slug );
}
else
$slugs[0] = $paths;
}
else
throw new FrameworkException( "Path [" . $key . "] is not set" );
return $this->buildPath( $slugs );
}
else if ( !Str::startsWith( $slugs[0], '/' ) )
$slugs = Arr::prepend( $slugs, $this->basePath );
$dir = strpos( end( $slugs ), '.' ) !== false ? implode( DIRECTORY_SEPARATOR, array_slice( $slugs, 0, count( $slugs ) - 1 ) ) : implode( DIRECTORY_SEPARATOR, $slugs );
if ( !file_exists( $dir ) )
if ( !mkdir( $dir, 0755, true ) )
throw new FrameworkException( "The directory [" . $dir . "] does not exist and we failed to create it" );
return implode( DIRECTORY_SEPARATOR, $slugs );
}
|
[
"public",
"function",
"buildPath",
"(",
")",
"{",
"$",
"slugs",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"slugs",
"[",
"0",
"]",
")",
")",
"$",
"slugs",
"=",
"$",
"slugs",
"[",
"0",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"slugs",
")",
"==",
"0",
")",
"return",
"$",
"this",
"->",
"basePath",
";",
"if",
"(",
"Str",
"::",
"startsWith",
"(",
"$",
"slugs",
"[",
"0",
"]",
",",
"'__'",
")",
")",
"{",
"$",
"key",
"=",
"substr",
"(",
"$",
"slugs",
"[",
"0",
"]",
",",
"2",
")",
";",
"if",
"(",
"$",
"key",
"==",
"'base'",
")",
"$",
"slugs",
"[",
"0",
"]",
"=",
"$",
"this",
"->",
"basePath",
";",
"else",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"paths",
")",
")",
"{",
"$",
"paths",
"=",
"$",
"this",
"->",
"paths",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"paths",
")",
")",
"{",
"unset",
"(",
"$",
"slugs",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"paths",
")",
"as",
"$",
"slug",
")",
"$",
"slugs",
"=",
"Arr",
"::",
"prepend",
"(",
"$",
"slugs",
",",
"$",
"slug",
")",
";",
"}",
"else",
"$",
"slugs",
"[",
"0",
"]",
"=",
"$",
"paths",
";",
"}",
"else",
"throw",
"new",
"FrameworkException",
"(",
"\"Path [\"",
".",
"$",
"key",
".",
"\"] is not set\"",
")",
";",
"return",
"$",
"this",
"->",
"buildPath",
"(",
"$",
"slugs",
")",
";",
"}",
"else",
"if",
"(",
"!",
"Str",
"::",
"startsWith",
"(",
"$",
"slugs",
"[",
"0",
"]",
",",
"'/'",
")",
")",
"$",
"slugs",
"=",
"Arr",
"::",
"prepend",
"(",
"$",
"slugs",
",",
"$",
"this",
"->",
"basePath",
")",
";",
"$",
"dir",
"=",
"strpos",
"(",
"end",
"(",
"$",
"slugs",
")",
",",
"'.'",
")",
"!==",
"false",
"?",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"array_slice",
"(",
"$",
"slugs",
",",
"0",
",",
"count",
"(",
"$",
"slugs",
")",
"-",
"1",
")",
")",
":",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"slugs",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
")",
")",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"dir",
",",
"0755",
",",
"true",
")",
")",
"throw",
"new",
"FrameworkException",
"(",
"\"The directory [\"",
".",
"$",
"dir",
".",
"\"] does not exist and we failed to create it\"",
")",
";",
"return",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"slugs",
")",
";",
"}"
] |
Append args to the base path
@return string
@throws FrameworkException
|
[
"Append",
"args",
"to",
"the",
"base",
"path"
] |
8afd7156610a70371aa5b1df50b8a212bf7b142c
|
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Framework.php#L237-L279
|
25,159
|
Subscribo/klarna-invoice-sdk-wrapped
|
src/Language.php
|
KlarnaLanguage.getCode
|
public static function getCode($val)
{
if (self::$_languageFlip === array()) {
self::$_languageFlip = array_flip(self::$_languages);
}
if (array_key_exists($val, self::$_languageFlip)) {
return strtolower(self::$_languageFlip[$val]);
}
return null;
}
|
php
|
public static function getCode($val)
{
if (self::$_languageFlip === array()) {
self::$_languageFlip = array_flip(self::$_languages);
}
if (array_key_exists($val, self::$_languageFlip)) {
return strtolower(self::$_languageFlip[$val]);
}
return null;
}
|
[
"public",
"static",
"function",
"getCode",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_languageFlip",
"===",
"array",
"(",
")",
")",
"{",
"self",
"::",
"$",
"_languageFlip",
"=",
"array_flip",
"(",
"self",
"::",
"$",
"_languages",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"val",
",",
"self",
"::",
"$",
"_languageFlip",
")",
")",
"{",
"return",
"strtolower",
"(",
"self",
"::",
"$",
"_languageFlip",
"[",
"$",
"val",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Converts a KlarnaLanguage constant to the respective language code.
@param int $val KlarnaLanguage constant
@return lowercase string|null
|
[
"Converts",
"a",
"KlarnaLanguage",
"constant",
"to",
"the",
"respective",
"language",
"code",
"."
] |
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
|
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Language.php#L108-L117
|
25,160
|
rafflesargentina/l5-filterable-sortable
|
src/QuerySorters.php
|
QuerySorters.apply
|
public function apply(Builder $builder)
{
$this->builder = $builder;
if (method_exists($this, $this->orderBy())) {
call_user_func([$this, $this->orderBy()]);
}
return $this->builder;
}
|
php
|
public function apply(Builder $builder)
{
$this->builder = $builder;
if (method_exists($this, $this->orderBy())) {
call_user_func([$this, $this->orderBy()]);
}
return $this->builder;
}
|
[
"public",
"function",
"apply",
"(",
"Builder",
"$",
"builder",
")",
"{",
"$",
"this",
"->",
"builder",
"=",
"$",
"builder",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"orderBy",
"(",
")",
")",
")",
"{",
"call_user_func",
"(",
"[",
"$",
"this",
",",
"$",
"this",
"->",
"orderBy",
"(",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"builder",
";",
"}"
] |
Apply the sorter to the builder.
@param Builder $builder The builder instance.
@return Builder
|
[
"Apply",
"the",
"sorter",
"to",
"the",
"builder",
"."
] |
eb3ecf399145ec7c5241ba2134ed0bea2057e6c3
|
https://github.com/rafflesargentina/l5-filterable-sortable/blob/eb3ecf399145ec7c5241ba2134ed0bea2057e6c3/src/QuerySorters.php#L82-L91
|
25,161
|
rafflesargentina/l5-filterable-sortable
|
src/QuerySorters.php
|
QuerySorters.listOrderByKeys
|
public static function listOrderByKeys()
{
$classMethods = get_class_methods(get_class());
$calledClassMethods = get_class_methods(get_called_class());
$filteredMethods = array_filter(
$calledClassMethods, function ($calledClassMethod) use ($classMethods) {
return !in_array($calledClassMethod, $classMethods, true);
}
);
$list = [];
foreach ($filteredMethods as $k => $v) {
$list[$v] = $v;
}
return $list;
}
|
php
|
public static function listOrderByKeys()
{
$classMethods = get_class_methods(get_class());
$calledClassMethods = get_class_methods(get_called_class());
$filteredMethods = array_filter(
$calledClassMethods, function ($calledClassMethod) use ($classMethods) {
return !in_array($calledClassMethod, $classMethods, true);
}
);
$list = [];
foreach ($filteredMethods as $k => $v) {
$list[$v] = $v;
}
return $list;
}
|
[
"public",
"static",
"function",
"listOrderByKeys",
"(",
")",
"{",
"$",
"classMethods",
"=",
"get_class_methods",
"(",
"get_class",
"(",
")",
")",
";",
"$",
"calledClassMethods",
"=",
"get_class_methods",
"(",
"get_called_class",
"(",
")",
")",
";",
"$",
"filteredMethods",
"=",
"array_filter",
"(",
"$",
"calledClassMethods",
",",
"function",
"(",
"$",
"calledClassMethod",
")",
"use",
"(",
"$",
"classMethods",
")",
"{",
"return",
"!",
"in_array",
"(",
"$",
"calledClassMethod",
",",
"$",
"classMethods",
",",
"true",
")",
";",
"}",
")",
";",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"filteredMethods",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"list",
"[",
"$",
"v",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
Pluck all sorters from class methods.
@return array
|
[
"Pluck",
"all",
"sorters",
"from",
"class",
"methods",
"."
] |
eb3ecf399145ec7c5241ba2134ed0bea2057e6c3
|
https://github.com/rafflesargentina/l5-filterable-sortable/blob/eb3ecf399145ec7c5241ba2134ed0bea2057e6c3/src/QuerySorters.php#L139-L156
|
25,162
|
rafflesargentina/l5-filterable-sortable
|
src/QuerySorters.php
|
QuerySorters.getAppliedSorters
|
public static function getAppliedSorters()
{
$order = static::getOrderKey();
$orderBy = static::getOrderByKey();
$applied = \Illuminate\Support\Facades\Request::only($order, $orderBy);
$applied = array_filter($applied);
$default = [
$orderBy => static::getDefaultOrderBy(),
$order => static::getDefaultOrder()
];
return $applied ?: $default;
}
|
php
|
public static function getAppliedSorters()
{
$order = static::getOrderKey();
$orderBy = static::getOrderByKey();
$applied = \Illuminate\Support\Facades\Request::only($order, $orderBy);
$applied = array_filter($applied);
$default = [
$orderBy => static::getDefaultOrderBy(),
$order => static::getDefaultOrder()
];
return $applied ?: $default;
}
|
[
"public",
"static",
"function",
"getAppliedSorters",
"(",
")",
"{",
"$",
"order",
"=",
"static",
"::",
"getOrderKey",
"(",
")",
";",
"$",
"orderBy",
"=",
"static",
"::",
"getOrderByKey",
"(",
")",
";",
"$",
"applied",
"=",
"\\",
"Illuminate",
"\\",
"Support",
"\\",
"Facades",
"\\",
"Request",
"::",
"only",
"(",
"$",
"order",
",",
"$",
"orderBy",
")",
";",
"$",
"applied",
"=",
"array_filter",
"(",
"$",
"applied",
")",
";",
"$",
"default",
"=",
"[",
"$",
"orderBy",
"=>",
"static",
"::",
"getDefaultOrderBy",
"(",
")",
",",
"$",
"order",
"=>",
"static",
"::",
"getDefaultOrder",
"(",
")",
"]",
";",
"return",
"$",
"applied",
"?",
":",
"$",
"default",
";",
"}"
] |
Get applied sorters from request or fallback to default.
@return array
|
[
"Get",
"applied",
"sorters",
"from",
"request",
"or",
"fallback",
"to",
"default",
"."
] |
eb3ecf399145ec7c5241ba2134ed0bea2057e6c3
|
https://github.com/rafflesargentina/l5-filterable-sortable/blob/eb3ecf399145ec7c5241ba2134ed0bea2057e6c3/src/QuerySorters.php#L163-L178
|
25,163
|
elifesciences/bus-sdk-php
|
src/Queue/SqsWatchableQueue.php
|
SqsWatchableQueue.enqueue
|
public function enqueue(QueueItem $item)
{
$this->client->sendMessage([
'QueueUrl' => $this->url,
'MessageBody' => json_encode([
'type' => $item->getType(),
'id' => $item->getId(),
]),
]);
}
|
php
|
public function enqueue(QueueItem $item)
{
$this->client->sendMessage([
'QueueUrl' => $this->url,
'MessageBody' => json_encode([
'type' => $item->getType(),
'id' => $item->getId(),
]),
]);
}
|
[
"public",
"function",
"enqueue",
"(",
"QueueItem",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"sendMessage",
"(",
"[",
"'QueueUrl'",
"=>",
"$",
"this",
"->",
"url",
",",
"'MessageBody'",
"=>",
"json_encode",
"(",
"[",
"'type'",
"=>",
"$",
"item",
"->",
"getType",
"(",
")",
",",
"'id'",
"=>",
"$",
"item",
"->",
"getId",
"(",
")",
",",
"]",
")",
",",
"]",
")",
";",
"}"
] |
Adds item to the queue.
|
[
"Adds",
"item",
"to",
"the",
"queue",
"."
] |
3af0739fac110e79ea7f21aadf8d17b891f3b918
|
https://github.com/elifesciences/bus-sdk-php/blob/3af0739fac110e79ea7f21aadf8d17b891f3b918/src/Queue/SqsWatchableQueue.php#L25-L34
|
25,164
|
elifesciences/bus-sdk-php
|
src/Queue/SqsWatchableQueue.php
|
SqsWatchableQueue.commit
|
public function commit(QueueItem $item)
{
$this->client->deleteMessage([
'QueueUrl' => $this->url,
'ReceiptHandle' => $item->getReceipt(),
]);
}
|
php
|
public function commit(QueueItem $item)
{
$this->client->deleteMessage([
'QueueUrl' => $this->url,
'ReceiptHandle' => $item->getReceipt(),
]);
}
|
[
"public",
"function",
"commit",
"(",
"QueueItem",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"deleteMessage",
"(",
"[",
"'QueueUrl'",
"=>",
"$",
"this",
"->",
"url",
",",
"'ReceiptHandle'",
"=>",
"$",
"item",
"->",
"getReceipt",
"(",
")",
",",
"]",
")",
";",
"}"
] |
Commits to removing item from queue, marks item as done and processed.
|
[
"Commits",
"to",
"removing",
"item",
"from",
"queue",
"marks",
"item",
"as",
"done",
"and",
"processed",
"."
] |
3af0739fac110e79ea7f21aadf8d17b891f3b918
|
https://github.com/elifesciences/bus-sdk-php/blob/3af0739fac110e79ea7f21aadf8d17b891f3b918/src/Queue/SqsWatchableQueue.php#L59-L65
|
25,165
|
elifesciences/bus-sdk-php
|
src/Queue/SqsWatchableQueue.php
|
SqsWatchableQueue.release
|
public function release(QueueItem $item)
{
$this->client->changeMessageVisibility([
'QueueUrl' => $this->url,
'ReceiptHandle' => $item->getReceipt(),
'VisibilityTimeout' => $this->visibilityTimeout * ($item->getAttempts() + 1),
]);
}
|
php
|
public function release(QueueItem $item)
{
$this->client->changeMessageVisibility([
'QueueUrl' => $this->url,
'ReceiptHandle' => $item->getReceipt(),
'VisibilityTimeout' => $this->visibilityTimeout * ($item->getAttempts() + 1),
]);
}
|
[
"public",
"function",
"release",
"(",
"QueueItem",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"changeMessageVisibility",
"(",
"[",
"'QueueUrl'",
"=>",
"$",
"this",
"->",
"url",
",",
"'ReceiptHandle'",
"=>",
"$",
"item",
"->",
"getReceipt",
"(",
")",
",",
"'VisibilityTimeout'",
"=>",
"$",
"this",
"->",
"visibilityTimeout",
"*",
"(",
"$",
"item",
"->",
"getAttempts",
"(",
")",
"+",
"1",
")",
",",
"]",
")",
";",
"}"
] |
This will happen when an error happens, we release the item back into the queue.
|
[
"This",
"will",
"happen",
"when",
"an",
"error",
"happens",
"we",
"release",
"the",
"item",
"back",
"into",
"the",
"queue",
"."
] |
3af0739fac110e79ea7f21aadf8d17b891f3b918
|
https://github.com/elifesciences/bus-sdk-php/blob/3af0739fac110e79ea7f21aadf8d17b891f3b918/src/Queue/SqsWatchableQueue.php#L70-L77
|
25,166
|
mitogh/Katana
|
src/Filters/Page.php
|
Page.filter_by_template_page
|
public function filter_by_template_page( $sizes, $id = 0 ) {
$template = get_page_template_slug( $id );
if ( empty( $template ) ) {
return $sizes;
}
$template_name = Formatter::to_filter_format( $template );
return apply_filters( Formatter::katana_filter( $template_name ), $sizes );
}
|
php
|
public function filter_by_template_page( $sizes, $id = 0 ) {
$template = get_page_template_slug( $id );
if ( empty( $template ) ) {
return $sizes;
}
$template_name = Formatter::to_filter_format( $template );
return apply_filters( Formatter::katana_filter( $template_name ), $sizes );
}
|
[
"public",
"function",
"filter_by_template_page",
"(",
"$",
"sizes",
",",
"$",
"id",
"=",
"0",
")",
"{",
"$",
"template",
"=",
"get_page_template_slug",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"template",
")",
")",
"{",
"return",
"$",
"sizes",
";",
"}",
"$",
"template_name",
"=",
"Formatter",
"::",
"to_filter_format",
"(",
"$",
"template",
")",
";",
"return",
"apply_filters",
"(",
"Formatter",
"::",
"katana_filter",
"(",
"$",
"template_name",
")",
",",
"$",
"sizes",
")",
";",
"}"
] |
Filter that allow to change the sizes on pages that uses custom
page templates.
@since 1.1.0
@param array $sizes The images sizes.
@param int $id The id of the post, page or custom post type.
@return return the array with the new sizes.
|
[
"Filter",
"that",
"allow",
"to",
"change",
"the",
"sizes",
"on",
"pages",
"that",
"uses",
"custom",
"page",
"templates",
"."
] |
9eb7267f061fbe555dbe9c12461650bb4153915f
|
https://github.com/mitogh/Katana/blob/9eb7267f061fbe555dbe9c12461650bb4153915f/src/Filters/Page.php#L32-L39
|
25,167
|
Subscribo/klarna-invoice-sdk-wrapped
|
src/Currency.php
|
KlarnaCurrency.getCode
|
public static function getCode($val)
{
switch($val) {
case self::DKK:
return 'dkk';
case self::EUR:
return 'eur';
case self::NOK:
return 'nok';
case self::SEK:
return 'sek';
default:
return null;
}
}
|
php
|
public static function getCode($val)
{
switch($val) {
case self::DKK:
return 'dkk';
case self::EUR:
return 'eur';
case self::NOK:
return 'nok';
case self::SEK:
return 'sek';
default:
return null;
}
}
|
[
"public",
"static",
"function",
"getCode",
"(",
"$",
"val",
")",
"{",
"switch",
"(",
"$",
"val",
")",
"{",
"case",
"self",
"::",
"DKK",
":",
"return",
"'dkk'",
";",
"case",
"self",
"::",
"EUR",
":",
"return",
"'eur'",
";",
"case",
"self",
"::",
"NOK",
":",
"return",
"'nok'",
";",
"case",
"self",
"::",
"SEK",
":",
"return",
"'sek'",
";",
"default",
":",
"return",
"null",
";",
"}",
"}"
] |
Converts a KlarnaCurrency constant to the respective language code.
@param int $val KlarnaCurrency constant
@return string|null
|
[
"Converts",
"a",
"KlarnaCurrency",
"constant",
"to",
"the",
"respective",
"language",
"code",
"."
] |
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
|
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Currency.php#L88-L102
|
25,168
|
NukaCode/users
|
src/NukaCode/Users/Presenters/UserPresenter.php
|
UserPresenter.gravatar
|
public function gravatar()
{
// Check for valid gravatar
$gravCheck = 'http://www.gravatar.com/avatar/'. md5( strtolower( trim( $this->email ) ) ) .'.png?d=404';
$response = get_headers($gravCheck);
// If a valid gravatar URL is found, use the gravatar image
if ($response[0] != "HTTP/1.0 404 Not Found"){
return 'http://www.gravatar.com/avatar/'. md5( strtolower( trim( $this->email ) ) ) .'.png?s=200&d=blank';
}
// If no other image is set, use the default
return '/img/no_user.png';
}
|
php
|
public function gravatar()
{
// Check for valid gravatar
$gravCheck = 'http://www.gravatar.com/avatar/'. md5( strtolower( trim( $this->email ) ) ) .'.png?d=404';
$response = get_headers($gravCheck);
// If a valid gravatar URL is found, use the gravatar image
if ($response[0] != "HTTP/1.0 404 Not Found"){
return 'http://www.gravatar.com/avatar/'. md5( strtolower( trim( $this->email ) ) ) .'.png?s=200&d=blank';
}
// If no other image is set, use the default
return '/img/no_user.png';
}
|
[
"public",
"function",
"gravatar",
"(",
")",
"{",
"// Check for valid gravatar\r",
"$",
"gravCheck",
"=",
"'http://www.gravatar.com/avatar/'",
".",
"md5",
"(",
"strtolower",
"(",
"trim",
"(",
"$",
"this",
"->",
"email",
")",
")",
")",
".",
"'.png?d=404'",
";",
"$",
"response",
"=",
"get_headers",
"(",
"$",
"gravCheck",
")",
";",
"// If a valid gravatar URL is found, use the gravatar image\r",
"if",
"(",
"$",
"response",
"[",
"0",
"]",
"!=",
"\"HTTP/1.0 404 Not Found\"",
")",
"{",
"return",
"'http://www.gravatar.com/avatar/'",
".",
"md5",
"(",
"strtolower",
"(",
"trim",
"(",
"$",
"this",
"->",
"email",
")",
")",
")",
".",
"'.png?s=200&d=blank'",
";",
"}",
"// If no other image is set, use the default\r",
"return",
"'/img/no_user.png'",
";",
"}"
] |
Check for an avatar uploaded to the site, resort to gravatar if none exists, resort to no user image if no gravatar exists
@return string
|
[
"Check",
"for",
"an",
"avatar",
"uploaded",
"to",
"the",
"site",
"resort",
"to",
"gravatar",
"if",
"none",
"exists",
"resort",
"to",
"no",
"user",
"image",
"if",
"no",
"gravatar",
"exists"
] |
d827b8e6ba3faf27c85d867ec1d7e0a426968551
|
https://github.com/NukaCode/users/blob/d827b8e6ba3faf27c85d867ec1d7e0a426968551/src/NukaCode/Users/Presenters/UserPresenter.php#L88-L101
|
25,169
|
NukaCode/users
|
src/NukaCode/Users/Presenters/UserPresenter.php
|
UserPresenter.postsCount
|
public function postsCount()
{
$postsCount = $this->posts->count();
$repliesCount = $this->replies->count();
return $postsCount + $repliesCount;
}
|
php
|
public function postsCount()
{
$postsCount = $this->posts->count();
$repliesCount = $this->replies->count();
return $postsCount + $repliesCount;
}
|
[
"public",
"function",
"postsCount",
"(",
")",
"{",
"$",
"postsCount",
"=",
"$",
"this",
"->",
"posts",
"->",
"count",
"(",
")",
";",
"$",
"repliesCount",
"=",
"$",
"this",
"->",
"replies",
"->",
"count",
"(",
")",
";",
"return",
"$",
"postsCount",
"+",
"$",
"repliesCount",
";",
"}"
] |
Get the number of posts from this user
|
[
"Get",
"the",
"number",
"of",
"posts",
"from",
"this",
"user"
] |
d827b8e6ba3faf27c85d867ec1d7e0a426968551
|
https://github.com/NukaCode/users/blob/d827b8e6ba3faf27c85d867ec1d7e0a426968551/src/NukaCode/Users/Presenters/UserPresenter.php#L130-L136
|
25,170
|
NukaCode/users
|
src/NukaCode/Users/Presenters/UserPresenter.php
|
UserPresenter.lastActiveReadable
|
public function lastActiveReadable()
{
return ($this->lastActive == '0000-00-00 00:00:00' || $this->lastActive == null ? 'Never' : date('F jS, Y \a\t h:ia', strtotime($this->lastActive)));
}
|
php
|
public function lastActiveReadable()
{
return ($this->lastActive == '0000-00-00 00:00:00' || $this->lastActive == null ? 'Never' : date('F jS, Y \a\t h:ia', strtotime($this->lastActive)));
}
|
[
"public",
"function",
"lastActiveReadable",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"lastActive",
"==",
"'0000-00-00 00:00:00'",
"||",
"$",
"this",
"->",
"lastActive",
"==",
"null",
"?",
"'Never'",
":",
"date",
"(",
"'F jS, Y \\a\\t h:ia'",
",",
"strtotime",
"(",
"$",
"this",
"->",
"lastActive",
")",
")",
")",
";",
"}"
] |
Make the last active date easier to read
@return string
|
[
"Make",
"the",
"last",
"active",
"date",
"easier",
"to",
"read"
] |
d827b8e6ba3faf27c85d867ec1d7e0a426968551
|
https://github.com/NukaCode/users/blob/d827b8e6ba3faf27c85d867ec1d7e0a426968551/src/NukaCode/Users/Presenters/UserPresenter.php#L181-L184
|
25,171
|
vpg/titon.utility
|
src/Titon/Utility/Crypt.php
|
Crypt.blowfish
|
public static function blowfish($string, $key, $operation = self::ENCRYPT) {
if ($operation === static::ENCRYPT) {
return static::encrypt($string, $key, static::BLOWFISH);
} else {
return static::decrypt($string, $key, static::BLOWFISH);
}
}
|
php
|
public static function blowfish($string, $key, $operation = self::ENCRYPT) {
if ($operation === static::ENCRYPT) {
return static::encrypt($string, $key, static::BLOWFISH);
} else {
return static::decrypt($string, $key, static::BLOWFISH);
}
}
|
[
"public",
"static",
"function",
"blowfish",
"(",
"$",
"string",
",",
"$",
"key",
",",
"$",
"operation",
"=",
"self",
"::",
"ENCRYPT",
")",
"{",
"if",
"(",
"$",
"operation",
"===",
"static",
"::",
"ENCRYPT",
")",
"{",
"return",
"static",
"::",
"encrypt",
"(",
"$",
"string",
",",
"$",
"key",
",",
"static",
"::",
"BLOWFISH",
")",
";",
"}",
"else",
"{",
"return",
"static",
"::",
"decrypt",
"(",
"$",
"string",
",",
"$",
"key",
",",
"static",
"::",
"BLOWFISH",
")",
";",
"}",
"}"
] |
Encrypt and decrypt a string using the Blowfish algorithm with CBC mode.
@param string $string
@param string $key
@param int $operation
@return string
|
[
"Encrypt",
"and",
"decrypt",
"a",
"string",
"using",
"the",
"Blowfish",
"algorithm",
"with",
"CBC",
"mode",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Crypt.php#L45-L51
|
25,172
|
vpg/titon.utility
|
src/Titon/Utility/Crypt.php
|
Crypt.decrypt
|
public static function decrypt($string, $key, $cipher, $mode = MCRYPT_MODE_CBC) {
list($key, $iv) = static::vector($key, $cipher, $mode);
return rtrim(mcrypt_decrypt($cipher, $key, $string, $mode, $iv), "\0");
}
|
php
|
public static function decrypt($string, $key, $cipher, $mode = MCRYPT_MODE_CBC) {
list($key, $iv) = static::vector($key, $cipher, $mode);
return rtrim(mcrypt_decrypt($cipher, $key, $string, $mode, $iv), "\0");
}
|
[
"public",
"static",
"function",
"decrypt",
"(",
"$",
"string",
",",
"$",
"key",
",",
"$",
"cipher",
",",
"$",
"mode",
"=",
"MCRYPT_MODE_CBC",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"iv",
")",
"=",
"static",
"::",
"vector",
"(",
"$",
"key",
",",
"$",
"cipher",
",",
"$",
"mode",
")",
";",
"return",
"rtrim",
"(",
"mcrypt_decrypt",
"(",
"$",
"cipher",
",",
"$",
"key",
",",
"$",
"string",
",",
"$",
"mode",
",",
"$",
"iv",
")",
",",
"\"\\0\"",
")",
";",
"}"
] |
Decrypt an encrypted string using the passed cipher and mode.
Additional types of ciphers and modes can be used that aren't constants of this class.
@param string $string
@param string $key
@param string $cipher
@param string $mode
@return string
|
[
"Decrypt",
"an",
"encrypted",
"string",
"using",
"the",
"passed",
"cipher",
"and",
"mode",
".",
"Additional",
"types",
"of",
"ciphers",
"and",
"modes",
"can",
"be",
"used",
"that",
"aren",
"t",
"constants",
"of",
"this",
"class",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Crypt.php#L63-L67
|
25,173
|
vpg/titon.utility
|
src/Titon/Utility/Crypt.php
|
Crypt.encrypt
|
public static function encrypt($string, $key, $cipher, $mode = MCRYPT_MODE_CBC) {
list($key, $iv) = static::vector($key, $cipher, $mode);
return mcrypt_encrypt($cipher, $key, $string, $mode, $iv);
}
|
php
|
public static function encrypt($string, $key, $cipher, $mode = MCRYPT_MODE_CBC) {
list($key, $iv) = static::vector($key, $cipher, $mode);
return mcrypt_encrypt($cipher, $key, $string, $mode, $iv);
}
|
[
"public",
"static",
"function",
"encrypt",
"(",
"$",
"string",
",",
"$",
"key",
",",
"$",
"cipher",
",",
"$",
"mode",
"=",
"MCRYPT_MODE_CBC",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"iv",
")",
"=",
"static",
"::",
"vector",
"(",
"$",
"key",
",",
"$",
"cipher",
",",
"$",
"mode",
")",
";",
"return",
"mcrypt_encrypt",
"(",
"$",
"cipher",
",",
"$",
"key",
",",
"$",
"string",
",",
"$",
"mode",
",",
"$",
"iv",
")",
";",
"}"
] |
Encrypt string using the passed cipher and mode.
Additional types of ciphers and modes can be used that aren't constants of this class.
@param string $string
@param string $key
@param string $cipher
@param string $mode
@return string
|
[
"Encrypt",
"string",
"using",
"the",
"passed",
"cipher",
"and",
"mode",
".",
"Additional",
"types",
"of",
"ciphers",
"and",
"modes",
"can",
"be",
"used",
"that",
"aren",
"t",
"constants",
"of",
"this",
"class",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Crypt.php#L95-L99
|
25,174
|
vpg/titon.utility
|
src/Titon/Utility/Crypt.php
|
Crypt.obfuscate
|
public static function obfuscate($string) {
$string = (string) $string;
$length = mb_strlen($string);
$scrambled = '';
if ($length > 0) {
for ($i = 0; $i < $length; $i++) {
$scrambled .= '&#' . ord($string[$i]) . ';';
}
}
return $scrambled;
}
|
php
|
public static function obfuscate($string) {
$string = (string) $string;
$length = mb_strlen($string);
$scrambled = '';
if ($length > 0) {
for ($i = 0; $i < $length; $i++) {
$scrambled .= '&#' . ord($string[$i]) . ';';
}
}
return $scrambled;
}
|
[
"public",
"static",
"function",
"obfuscate",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"(",
"string",
")",
"$",
"string",
";",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"string",
")",
";",
"$",
"scrambled",
"=",
"''",
";",
"if",
"(",
"$",
"length",
">",
"0",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"scrambled",
".=",
"'&#'",
".",
"ord",
"(",
"$",
"string",
"[",
"$",
"i",
"]",
")",
".",
"';'",
";",
"}",
"}",
"return",
"$",
"scrambled",
";",
"}"
] |
Scrambles the source of a string.
@param string $string
@return string
|
[
"Scrambles",
"the",
"source",
"of",
"a",
"string",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Crypt.php#L120-L132
|
25,175
|
vpg/titon.utility
|
src/Titon/Utility/Crypt.php
|
Crypt.rijndael
|
public static function rijndael($string, $key, $operation = self::ENCRYPT) {
if ($operation === static::ENCRYPT) {
return static::encrypt($string, $key, static::RIJNDAEL);
} else {
return static::decrypt($string, $key, static::RIJNDAEL);
}
}
|
php
|
public static function rijndael($string, $key, $operation = self::ENCRYPT) {
if ($operation === static::ENCRYPT) {
return static::encrypt($string, $key, static::RIJNDAEL);
} else {
return static::decrypt($string, $key, static::RIJNDAEL);
}
}
|
[
"public",
"static",
"function",
"rijndael",
"(",
"$",
"string",
",",
"$",
"key",
",",
"$",
"operation",
"=",
"self",
"::",
"ENCRYPT",
")",
"{",
"if",
"(",
"$",
"operation",
"===",
"static",
"::",
"ENCRYPT",
")",
"{",
"return",
"static",
"::",
"encrypt",
"(",
"$",
"string",
",",
"$",
"key",
",",
"static",
"::",
"RIJNDAEL",
")",
";",
"}",
"else",
"{",
"return",
"static",
"::",
"decrypt",
"(",
"$",
"string",
",",
"$",
"key",
",",
"static",
"::",
"RIJNDAEL",
")",
";",
"}",
"}"
] |
Encrypt and decrypt a string using the Rijndael 128 algorithm with CBC mode.
@param string $string
@param string $key
@param int $operation
@return string
|
[
"Encrypt",
"and",
"decrypt",
"a",
"string",
"using",
"the",
"Rijndael",
"128",
"algorithm",
"with",
"CBC",
"mode",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Crypt.php#L142-L148
|
25,176
|
naucon/Utility
|
src/HashSetAbstract.php
|
HashSetAbstract.add
|
public function add($element)
{
if (!$this->contains($element)) {
$hashIndex = $this->hashIndex($element);
$this->_items[$hashIndex] = $element;
$this->_iterator = null;
return true;
} else {
// element already exist
return false;
}
}
|
php
|
public function add($element)
{
if (!$this->contains($element)) {
$hashIndex = $this->hashIndex($element);
$this->_items[$hashIndex] = $element;
$this->_iterator = null;
return true;
} else {
// element already exist
return false;
}
}
|
[
"public",
"function",
"add",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"contains",
"(",
"$",
"element",
")",
")",
"{",
"$",
"hashIndex",
"=",
"$",
"this",
"->",
"hashIndex",
"(",
"$",
"element",
")",
";",
"$",
"this",
"->",
"_items",
"[",
"$",
"hashIndex",
"]",
"=",
"$",
"element",
";",
"$",
"this",
"->",
"_iterator",
"=",
"null",
";",
"return",
"true",
";",
"}",
"else",
"{",
"// element already exist",
"return",
"false",
";",
"}",
"}"
] |
add a element to the end of the collection
@param mixed $element element
@return bool
|
[
"add",
"a",
"element",
"to",
"the",
"end",
"of",
"the",
"collection"
] |
d225bb5d09d82400917f710c9d502949a66442c4
|
https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/HashSetAbstract.php#L27-L39
|
25,177
|
naucon/Utility
|
src/HashSetAbstract.php
|
HashSetAbstract.contains
|
public function contains($element)
{
$hashIndex = $this->hashIndex($element);
if (array_key_exists($hashIndex, $this->_items)) {
return true;
}
return false;
}
|
php
|
public function contains($element)
{
$hashIndex = $this->hashIndex($element);
if (array_key_exists($hashIndex, $this->_items)) {
return true;
}
return false;
}
|
[
"public",
"function",
"contains",
"(",
"$",
"element",
")",
"{",
"$",
"hashIndex",
"=",
"$",
"this",
"->",
"hashIndex",
"(",
"$",
"element",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"hashIndex",
",",
"$",
"this",
"->",
"_items",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
collection contains a given element
@param mixed $element element
@return bool true if the hashset contains a specified element
|
[
"collection",
"contains",
"a",
"given",
"element"
] |
d225bb5d09d82400917f710c9d502949a66442c4
|
https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/HashSetAbstract.php#L63-L71
|
25,178
|
gplcart/cli
|
controllers/commands/Zone.php
|
Zone.cmdGetZone
|
public function cmdGetZone()
{
$result = $this->getListZone();
$this->outputFormat($result);
$this->outputFormatTableZone($result);
$this->output();
}
|
php
|
public function cmdGetZone()
{
$result = $this->getListZone();
$this->outputFormat($result);
$this->outputFormatTableZone($result);
$this->output();
}
|
[
"public",
"function",
"cmdGetZone",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListZone",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableZone",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] |
Callback for "zone-get" command
|
[
"Callback",
"for",
"zone",
"-",
"get",
"command"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Zone.php#L40-L46
|
25,179
|
gplcart/cli
|
controllers/commands/Zone.php
|
Zone.cmdUpdateZone
|
public function cmdUpdateZone()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('zone');
$this->updateZone($params[0]);
$this->output();
}
|
php
|
public function cmdUpdateZone()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('zone');
$this->updateZone($params[0]);
$this->output();
}
|
[
"public",
"function",
"cmdUpdateZone",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'zone'",
")",
";",
"$",
"this",
"->",
"updateZone",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] |
Callback for "zone-update" command
|
[
"Callback",
"for",
"zone",
"-",
"update",
"command"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Zone.php#L66-L85
|
25,180
|
gplcart/cli
|
controllers/commands/Zone.php
|
Zone.cmdDeleteZone
|
public function cmdDeleteZone()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (empty($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = false;
if (!empty($id)) {
$result = $this->zone->delete($id);
} else if (!empty($all)) {
$deleted = $count = 0;
foreach ($this->zone->getList() as $zone) {
$count++;
$deleted += (int) $this->zone->delete($zone['zone_id']);
}
$result = $count && $count == $deleted;
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
}
|
php
|
public function cmdDeleteZone()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (empty($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = false;
if (!empty($id)) {
$result = $this->zone->delete($id);
} else if (!empty($all)) {
$deleted = $count = 0;
foreach ($this->zone->getList() as $zone) {
$count++;
$deleted += (int) $this->zone->delete($zone['zone_id']);
}
$result = $count && $count == $deleted;
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
}
|
[
"public",
"function",
"cmdDeleteZone",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"$",
"all",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'all'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"&&",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"zone",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"deleted",
"=",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"zone",
"->",
"getList",
"(",
")",
"as",
"$",
"zone",
")",
"{",
"$",
"count",
"++",
";",
"$",
"deleted",
"+=",
"(",
"int",
")",
"$",
"this",
"->",
"zone",
"->",
"delete",
"(",
"$",
"zone",
"[",
"'zone_id'",
"]",
")",
";",
"}",
"$",
"result",
"=",
"$",
"count",
"&&",
"$",
"count",
"==",
"$",
"deleted",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] |
Callback for "zone-delete" command
|
[
"Callback",
"for",
"zone",
"-",
"delete",
"command"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Zone.php#L90-L119
|
25,181
|
gplcart/cli
|
controllers/commands/Zone.php
|
Zone.submitAddZone
|
protected function submitAddZone()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('zone');
$this->addZone();
}
|
php
|
protected function submitAddZone()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('zone');
$this->addZone();
}
|
[
"protected",
"function",
"submitAddZone",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'zone'",
")",
";",
"$",
"this",
"->",
"addZone",
"(",
")",
";",
"}"
] |
Add a new zone at once
|
[
"Add",
"a",
"new",
"zone",
"at",
"once"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Zone.php#L185-L190
|
25,182
|
gplcart/cli
|
controllers/commands/Zone.php
|
Zone.addZone
|
protected function addZone()
{
if (!$this->isError()) {
$id = $this->zone->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
}
|
php
|
protected function addZone()
{
if (!$this->isError()) {
$id = $this->zone->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
}
|
[
"protected",
"function",
"addZone",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"zone",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"}",
"}"
] |
Add a new zone
|
[
"Add",
"a",
"new",
"zone"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Zone.php#L195-L204
|
25,183
|
gplcart/cli
|
controllers/commands/Zone.php
|
Zone.wizardAddZone
|
protected function wizardAddZone()
{
$this->validatePrompt('title', $this->text('Title'), 'zone');
$this->validatePrompt('status', $this->text('Status'), 'zone', 0);
$this->validateComponent('zone');
$this->addZone();
}
|
php
|
protected function wizardAddZone()
{
$this->validatePrompt('title', $this->text('Title'), 'zone');
$this->validatePrompt('status', $this->text('Status'), 'zone', 0);
$this->validateComponent('zone');
$this->addZone();
}
|
[
"protected",
"function",
"wizardAddZone",
"(",
")",
"{",
"$",
"this",
"->",
"validatePrompt",
"(",
"'title'",
",",
"$",
"this",
"->",
"text",
"(",
"'Title'",
")",
",",
"'zone'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'zone'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'zone'",
")",
";",
"$",
"this",
"->",
"addZone",
"(",
")",
";",
"}"
] |
Add a new zone step by step
|
[
"Add",
"a",
"new",
"zone",
"step",
"by",
"step"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Zone.php#L209-L216
|
25,184
|
climphp/Clim
|
Clim/Helper/DeferredDefinitionTrait.php
|
DeferredDefinitionTrait.needDefined
|
protected function needDefined()
{
if ($this->defined) return;
$this->defined = true;
$name = $pattern = $note = null;
if (preg_match(PARSER_PATTERN, $this->definition, $matches)) {
$body = $matches[1];
$name = $matches[2];
$note = $matches[3];
$pos = strpos($name, '|');
if ($pos !== false) {
$pattern = $this->assertPattern(trim(substr($name, $pos + 1)));
$name = trim(substr($name, 0, $pos));
}
} else {
$body = $this->definition;
}
$this->define($body, $name, $pattern, $note);
}
|
php
|
protected function needDefined()
{
if ($this->defined) return;
$this->defined = true;
$name = $pattern = $note = null;
if (preg_match(PARSER_PATTERN, $this->definition, $matches)) {
$body = $matches[1];
$name = $matches[2];
$note = $matches[3];
$pos = strpos($name, '|');
if ($pos !== false) {
$pattern = $this->assertPattern(trim(substr($name, $pos + 1)));
$name = trim(substr($name, 0, $pos));
}
} else {
$body = $this->definition;
}
$this->define($body, $name, $pattern, $note);
}
|
[
"protected",
"function",
"needDefined",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"defined",
")",
"return",
";",
"$",
"this",
"->",
"defined",
"=",
"true",
";",
"$",
"name",
"=",
"$",
"pattern",
"=",
"$",
"note",
"=",
"null",
";",
"if",
"(",
"preg_match",
"(",
"PARSER_PATTERN",
",",
"$",
"this",
"->",
"definition",
",",
"$",
"matches",
")",
")",
"{",
"$",
"body",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"name",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"note",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"name",
",",
"'|'",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"assertPattern",
"(",
"trim",
"(",
"substr",
"(",
"$",
"name",
",",
"$",
"pos",
"+",
"1",
")",
")",
")",
";",
"$",
"name",
"=",
"trim",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"$",
"pos",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"definition",
";",
"}",
"$",
"this",
"->",
"define",
"(",
"$",
"body",
",",
"$",
"name",
",",
"$",
"pattern",
",",
"$",
"note",
")",
";",
"}"
] |
Ensure definition has been parsed before actual use.
It is safe to call it multiple times.
|
[
"Ensure",
"definition",
"has",
"been",
"parsed",
"before",
"actual",
"use",
".",
"It",
"is",
"safe",
"to",
"call",
"it",
"multiple",
"times",
"."
] |
d2d09a82e1b7a0b8d454e585e6db421ff02ec8e4
|
https://github.com/climphp/Clim/blob/d2d09a82e1b7a0b8d454e585e6db421ff02ec8e4/Clim/Helper/DeferredDefinitionTrait.php#L44-L67
|
25,185
|
climphp/Clim
|
Clim/Helper/DeferredDefinitionTrait.php
|
DeferredDefinitionTrait.assertPattern
|
protected function assertPattern($pattern)
{
if (strlen($pattern) == 0) return null;
$pattern = '/^'. str_replace('/', '\\/', $pattern). '$/';
if (@preg_match($pattern, null) === false) {
throw new DefinitionException("invalid regular expression pattern");
}
return $pattern;
}
|
php
|
protected function assertPattern($pattern)
{
if (strlen($pattern) == 0) return null;
$pattern = '/^'. str_replace('/', '\\/', $pattern). '$/';
if (@preg_match($pattern, null) === false) {
throw new DefinitionException("invalid regular expression pattern");
}
return $pattern;
}
|
[
"protected",
"function",
"assertPattern",
"(",
"$",
"pattern",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"pattern",
")",
"==",
"0",
")",
"return",
"null",
";",
"$",
"pattern",
"=",
"'/^'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\/'",
",",
"$",
"pattern",
")",
".",
"'$/'",
";",
"if",
"(",
"@",
"preg_match",
"(",
"$",
"pattern",
",",
"null",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"DefinitionException",
"(",
"\"invalid regular expression pattern\"",
")",
";",
"}",
"return",
"$",
"pattern",
";",
"}"
] |
Validate the regular expression pattern string
@param string $pattern
@return string|null
@throws DefinitionException
|
[
"Validate",
"the",
"regular",
"expression",
"pattern",
"string"
] |
d2d09a82e1b7a0b8d454e585e6db421ff02ec8e4
|
https://github.com/climphp/Clim/blob/d2d09a82e1b7a0b8d454e585e6db421ff02ec8e4/Clim/Helper/DeferredDefinitionTrait.php#L75-L85
|
25,186
|
Ydle/HubBundle
|
Controller/RestNodeController.php
|
RestNodeController.getNodesListAction
|
public function getNodesListAction(ParamFetcher $paramFetcher)
{
$page = $paramFetcher->get('page');
$count = $paramFetcher->get('count');
$pager = $this->getNodeManager()->getPager($this->filterCriteria($paramFetcher), $page, $count);
return $pager;
}
|
php
|
public function getNodesListAction(ParamFetcher $paramFetcher)
{
$page = $paramFetcher->get('page');
$count = $paramFetcher->get('count');
$pager = $this->getNodeManager()->getPager($this->filterCriteria($paramFetcher), $page, $count);
return $pager;
}
|
[
"public",
"function",
"getNodesListAction",
"(",
"ParamFetcher",
"$",
"paramFetcher",
")",
"{",
"$",
"page",
"=",
"$",
"paramFetcher",
"->",
"get",
"(",
"'page'",
")",
";",
"$",
"count",
"=",
"$",
"paramFetcher",
"->",
"get",
"(",
"'count'",
")",
";",
"$",
"pager",
"=",
"$",
"this",
"->",
"getNodeManager",
"(",
")",
"->",
"getPager",
"(",
"$",
"this",
"->",
"filterCriteria",
"(",
"$",
"paramFetcher",
")",
",",
"$",
"page",
",",
"$",
"count",
")",
";",
"return",
"$",
"pager",
";",
"}"
] |
Retrieve the list of available nodes
@QueryParam(name="page", requirements="\d+", default="0", description="Number of page")
@QueryParam(name="count", requirements="\d+", default="0", description="Number of nodes by page")
@param ParamFetcher $paramFetcher
|
[
"Retrieve",
"the",
"list",
"of",
"available",
"nodes"
] |
7fa423241246bcfd115f2ed3ad3997b4b63adb01
|
https://github.com/Ydle/HubBundle/blob/7fa423241246bcfd115f2ed3ad3997b4b63adb01/Controller/RestNodeController.php#L53-L61
|
25,187
|
miaoxing/plugin
|
src/ConstTrait.php
|
ConstTrait.getConsts
|
public function getConsts($prefix)
{
if (isset(self::$consts[$prefix])) {
return self::$consts[$prefix];
}
// 1. Get all class constants
$class = new \ReflectionClass($this);
$consts = $class->getConstants();
// 2. Use exiting constant configs
$property = lcfirst(str_replace('_', '', ucwords($prefix, '_'))) . 'Table';
if (isset($this->$property)) {
$data = $this->$property;
} else {
$data = [];
}
// 3. Generate id and name
$prefix .= '_';
$length = strlen($prefix);
foreach ($consts as $name => $id) {
if (stripos($name, $prefix) !== 0) {
continue;
}
if (in_array($name, $this->constExcludes)) {
continue;
}
$data[$id]['id'] = $id;
$data[$id]['name'] = strtolower(strtr(substr($name, $length), ['_' => '-']));
}
self::$consts[$prefix] = $data;
return $data;
}
|
php
|
public function getConsts($prefix)
{
if (isset(self::$consts[$prefix])) {
return self::$consts[$prefix];
}
// 1. Get all class constants
$class = new \ReflectionClass($this);
$consts = $class->getConstants();
// 2. Use exiting constant configs
$property = lcfirst(str_replace('_', '', ucwords($prefix, '_'))) . 'Table';
if (isset($this->$property)) {
$data = $this->$property;
} else {
$data = [];
}
// 3. Generate id and name
$prefix .= '_';
$length = strlen($prefix);
foreach ($consts as $name => $id) {
if (stripos($name, $prefix) !== 0) {
continue;
}
if (in_array($name, $this->constExcludes)) {
continue;
}
$data[$id]['id'] = $id;
$data[$id]['name'] = strtolower(strtr(substr($name, $length), ['_' => '-']));
}
self::$consts[$prefix] = $data;
return $data;
}
|
[
"public",
"function",
"getConsts",
"(",
"$",
"prefix",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"consts",
"[",
"$",
"prefix",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"consts",
"[",
"$",
"prefix",
"]",
";",
"}",
"// 1. Get all class constants",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"$",
"consts",
"=",
"$",
"class",
"->",
"getConstants",
"(",
")",
";",
"// 2. Use exiting constant configs",
"$",
"property",
"=",
"lcfirst",
"(",
"str_replace",
"(",
"'_'",
",",
"''",
",",
"ucwords",
"(",
"$",
"prefix",
",",
"'_'",
")",
")",
")",
".",
"'Table'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"$",
"property",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"$",
"property",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"}",
"// 3. Generate id and name",
"$",
"prefix",
".=",
"'_'",
";",
"$",
"length",
"=",
"strlen",
"(",
"$",
"prefix",
")",
";",
"foreach",
"(",
"$",
"consts",
"as",
"$",
"name",
"=>",
"$",
"id",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"name",
",",
"$",
"prefix",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"constExcludes",
")",
")",
"{",
"continue",
";",
"}",
"$",
"data",
"[",
"$",
"id",
"]",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"$",
"data",
"[",
"$",
"id",
"]",
"[",
"'name'",
"]",
"=",
"strtolower",
"(",
"strtr",
"(",
"substr",
"(",
"$",
"name",
",",
"$",
"length",
")",
",",
"[",
"'_'",
"=>",
"'-'",
"]",
")",
")",
";",
"}",
"self",
"::",
"$",
"consts",
"[",
"$",
"prefix",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"data",
";",
"}"
] |
Get constants table by prefix
@param string $prefix
@return array
|
[
"Get",
"constants",
"table",
"by",
"prefix"
] |
f287a1e6c97abba6f06906255b8c26e8ab0afe61
|
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/ConstTrait.php#L31-L66
|
25,188
|
miaoxing/plugin
|
src/ConstTrait.php
|
ConstTrait.getConstValue
|
public function getConstValue($prefix, $id, $key)
{
$consts = $this->getConsts($prefix);
return isset($consts[$id][$key]) ? $consts[$id][$key] : null;
}
|
php
|
public function getConstValue($prefix, $id, $key)
{
$consts = $this->getConsts($prefix);
return isset($consts[$id][$key]) ? $consts[$id][$key] : null;
}
|
[
"public",
"function",
"getConstValue",
"(",
"$",
"prefix",
",",
"$",
"id",
",",
"$",
"key",
")",
"{",
"$",
"consts",
"=",
"$",
"this",
"->",
"getConsts",
"(",
"$",
"prefix",
")",
";",
"return",
"isset",
"(",
"$",
"consts",
"[",
"$",
"id",
"]",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"consts",
"[",
"$",
"id",
"]",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] |
Returns the constant value by specified id and key
@param string $prefix
@param int $id
@param string $key
@return mixed
|
[
"Returns",
"the",
"constant",
"value",
"by",
"specified",
"id",
"and",
"key"
] |
f287a1e6c97abba6f06906255b8c26e8ab0afe61
|
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/ConstTrait.php#L76-L81
|
25,189
|
miaoxing/plugin
|
src/ConstTrait.php
|
ConstTrait.getConstIdByName
|
public function getConstIdByName($prefix, $name)
{
$nameToIds = $this->getConstNameToIds($prefix);
return isset($nameToIds[$name]) ? $nameToIds[$name] : null;
}
|
php
|
public function getConstIdByName($prefix, $name)
{
$nameToIds = $this->getConstNameToIds($prefix);
return isset($nameToIds[$name]) ? $nameToIds[$name] : null;
}
|
[
"public",
"function",
"getConstIdByName",
"(",
"$",
"prefix",
",",
"$",
"name",
")",
"{",
"$",
"nameToIds",
"=",
"$",
"this",
"->",
"getConstNameToIds",
"(",
"$",
"prefix",
")",
";",
"return",
"isset",
"(",
"$",
"nameToIds",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"nameToIds",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] |
Returns the constant id by name
@param string $prefix
@param string $name
@return int
|
[
"Returns",
"the",
"constant",
"id",
"by",
"name"
] |
f287a1e6c97abba6f06906255b8c26e8ab0afe61
|
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/ConstTrait.php#L114-L119
|
25,190
|
miaoxing/plugin
|
src/ConstTrait.php
|
ConstTrait.getConstNameToIds
|
protected function getConstNameToIds($prefix)
{
if (!isset(self::$constNameToIds[$prefix])) {
foreach ($this->getConsts($prefix) as $const) {
self::$constNameToIds[$prefix][$const['name']] = $const['id'];
}
}
return self::$constNameToIds[$prefix];
}
|
php
|
protected function getConstNameToIds($prefix)
{
if (!isset(self::$constNameToIds[$prefix])) {
foreach ($this->getConsts($prefix) as $const) {
self::$constNameToIds[$prefix][$const['name']] = $const['id'];
}
}
return self::$constNameToIds[$prefix];
}
|
[
"protected",
"function",
"getConstNameToIds",
"(",
"$",
"prefix",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"constNameToIds",
"[",
"$",
"prefix",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getConsts",
"(",
"$",
"prefix",
")",
"as",
"$",
"const",
")",
"{",
"self",
"::",
"$",
"constNameToIds",
"[",
"$",
"prefix",
"]",
"[",
"$",
"const",
"[",
"'name'",
"]",
"]",
"=",
"$",
"const",
"[",
"'id'",
"]",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"constNameToIds",
"[",
"$",
"prefix",
"]",
";",
"}"
] |
Returns the name to id map
@param string $prefix
@return array
|
[
"Returns",
"the",
"name",
"to",
"id",
"map"
] |
f287a1e6c97abba6f06906255b8c26e8ab0afe61
|
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/ConstTrait.php#L127-L136
|
25,191
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.between
|
public static function between($input, $min, $max) {
$length = mb_strlen($input);
return ($length <= $max && $length >= $min);
}
|
php
|
public static function between($input, $min, $max) {
$length = mb_strlen($input);
return ($length <= $max && $length >= $min);
}
|
[
"public",
"static",
"function",
"between",
"(",
"$",
"input",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"input",
")",
";",
"return",
"(",
"$",
"length",
"<=",
"$",
"max",
"&&",
"$",
"length",
">=",
"$",
"min",
")",
";",
"}"
] |
Validate input string length is between the min and max.
@param string $input
@param int $min
@param int $max
@return bool
|
[
"Validate",
"input",
"string",
"length",
"is",
"between",
"the",
"min",
"and",
"max",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L75-L79
|
25,192
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.comparison
|
public static function comparison($input, $check, $mode) {
switch (mb_strtolower($mode)) {
case 'greater':
case 'gt':
case '>':
return ($input > $check);
break;
case 'greaterorequal':
case 'gte':
case '>=':
return ($input >= $check);
break;
case 'less':
case 'lt':
case '<':
return ($input < $check);
break;
case 'lessorequal':
case 'lte':
case '<=':
return ($input <= $check);
break;
case 'equal':
case 'eq':
case '==':
case '=':
return ($input == $check);
break;
case 'notequal':
case 'neq':
case 'ne':
case '!=':
return ($input != $check);
break;
default:
throw new InvalidArgumentException(sprintf('Unsupported mode %s for %s', $mode, __METHOD__));
break;
}
}
|
php
|
public static function comparison($input, $check, $mode) {
switch (mb_strtolower($mode)) {
case 'greater':
case 'gt':
case '>':
return ($input > $check);
break;
case 'greaterorequal':
case 'gte':
case '>=':
return ($input >= $check);
break;
case 'less':
case 'lt':
case '<':
return ($input < $check);
break;
case 'lessorequal':
case 'lte':
case '<=':
return ($input <= $check);
break;
case 'equal':
case 'eq':
case '==':
case '=':
return ($input == $check);
break;
case 'notequal':
case 'neq':
case 'ne':
case '!=':
return ($input != $check);
break;
default:
throw new InvalidArgumentException(sprintf('Unsupported mode %s for %s', $mode, __METHOD__));
break;
}
}
|
[
"public",
"static",
"function",
"comparison",
"(",
"$",
"input",
",",
"$",
"check",
",",
"$",
"mode",
")",
"{",
"switch",
"(",
"mb_strtolower",
"(",
"$",
"mode",
")",
")",
"{",
"case",
"'greater'",
":",
"case",
"'gt'",
":",
"case",
"'>'",
":",
"return",
"(",
"$",
"input",
">",
"$",
"check",
")",
";",
"break",
";",
"case",
"'greaterorequal'",
":",
"case",
"'gte'",
":",
"case",
"'>='",
":",
"return",
"(",
"$",
"input",
">=",
"$",
"check",
")",
";",
"break",
";",
"case",
"'less'",
":",
"case",
"'lt'",
":",
"case",
"'<'",
":",
"return",
"(",
"$",
"input",
"<",
"$",
"check",
")",
";",
"break",
";",
"case",
"'lessorequal'",
":",
"case",
"'lte'",
":",
"case",
"'<='",
":",
"return",
"(",
"$",
"input",
"<=",
"$",
"check",
")",
";",
"break",
";",
"case",
"'equal'",
":",
"case",
"'eq'",
":",
"case",
"'=='",
":",
"case",
"'='",
":",
"return",
"(",
"$",
"input",
"==",
"$",
"check",
")",
";",
"break",
";",
"case",
"'notequal'",
":",
"case",
"'neq'",
":",
"case",
"'ne'",
":",
"case",
"'!='",
":",
"return",
"(",
"$",
"input",
"!=",
"$",
"check",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unsupported mode %s for %s'",
",",
"$",
"mode",
",",
"__METHOD__",
")",
")",
";",
"break",
";",
"}",
"}"
] |
Compare two numerical values.
@param int $input
@param int $check
@param string $mode
@return bool
@throws \Titon\Utility\Exception\InvalidArgumentException
|
[
"Compare",
"two",
"numerical",
"values",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L111-L149
|
25,193
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.date
|
public static function date($input) {
$input = Time::toUnix($input);
if (!$input) {
return false;
}
list($m, $d, $y) = explode('/', date('m/d/Y', $input));
return checkdate($m, $d, $y);
}
|
php
|
public static function date($input) {
$input = Time::toUnix($input);
if (!$input) {
return false;
}
list($m, $d, $y) = explode('/', date('m/d/Y', $input));
return checkdate($m, $d, $y);
}
|
[
"public",
"static",
"function",
"date",
"(",
"$",
"input",
")",
"{",
"$",
"input",
"=",
"Time",
"::",
"toUnix",
"(",
"$",
"input",
")",
";",
"if",
"(",
"!",
"$",
"input",
")",
"{",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"m",
",",
"$",
"d",
",",
"$",
"y",
")",
"=",
"explode",
"(",
"'/'",
",",
"date",
"(",
"'m/d/Y'",
",",
"$",
"input",
")",
")",
";",
"return",
"checkdate",
"(",
"$",
"m",
",",
"$",
"d",
",",
"$",
"y",
")",
";",
"}"
] |
Validate input is a real date.
@uses Titon\Utility\Time
@param string $input
@return bool
|
[
"Validate",
"input",
"is",
"a",
"real",
"date",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L235-L245
|
25,194
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.decimal
|
public static function decimal($input, $places = 2) {
if (!$places) {
$regex = '/^[-+]?[0-9]*\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/';
} else {
$regex = '/^[-+]?[0-9]*\.{1}[0-9]{' . $places . '}$/';
}
return static::custom($input, $regex);
}
|
php
|
public static function decimal($input, $places = 2) {
if (!$places) {
$regex = '/^[-+]?[0-9]*\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/';
} else {
$regex = '/^[-+]?[0-9]*\.{1}[0-9]{' . $places . '}$/';
}
return static::custom($input, $regex);
}
|
[
"public",
"static",
"function",
"decimal",
"(",
"$",
"input",
",",
"$",
"places",
"=",
"2",
")",
"{",
"if",
"(",
"!",
"$",
"places",
")",
"{",
"$",
"regex",
"=",
"'/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/'",
";",
"}",
"else",
"{",
"$",
"regex",
"=",
"'/^[-+]?[0-9]*\\.{1}[0-9]{'",
".",
"$",
"places",
".",
"'}$/'",
";",
"}",
"return",
"static",
"::",
"custom",
"(",
"$",
"input",
",",
"$",
"regex",
")",
";",
"}"
] |
Validate input is a decimal.
@param string $input
@param int $places
@return bool
|
[
"Validate",
"input",
"is",
"a",
"decimal",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L254-L262
|
25,195
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.dimensions
|
public static function dimensions($input, $type, $size) {
if (static::file($input)) {
$input = $input['tmp_name'];
}
if (!file_exists($input)) {
return false;
}
if ($file = getimagesize($input)) {
$width = $file[0];
$height = $file[1];
switch ($type) {
case 'width': return ($width == $size);
case 'height': return ($height == $size);
case 'maxWidth': return ($width <= $size);
case 'maxHeight': return ($height <= $size);
case 'minWidth': return ($width >= $size);
case 'minHeight': return ($height >= $size);
}
}
return false;
}
|
php
|
public static function dimensions($input, $type, $size) {
if (static::file($input)) {
$input = $input['tmp_name'];
}
if (!file_exists($input)) {
return false;
}
if ($file = getimagesize($input)) {
$width = $file[0];
$height = $file[1];
switch ($type) {
case 'width': return ($width == $size);
case 'height': return ($height == $size);
case 'maxWidth': return ($width <= $size);
case 'maxHeight': return ($height <= $size);
case 'minWidth': return ($width >= $size);
case 'minHeight': return ($height >= $size);
}
}
return false;
}
|
[
"public",
"static",
"function",
"dimensions",
"(",
"$",
"input",
",",
"$",
"type",
",",
"$",
"size",
")",
"{",
"if",
"(",
"static",
"::",
"file",
"(",
"$",
"input",
")",
")",
"{",
"$",
"input",
"=",
"$",
"input",
"[",
"'tmp_name'",
"]",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"input",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"file",
"=",
"getimagesize",
"(",
"$",
"input",
")",
")",
"{",
"$",
"width",
"=",
"$",
"file",
"[",
"0",
"]",
";",
"$",
"height",
"=",
"$",
"file",
"[",
"1",
"]",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'width'",
":",
"return",
"(",
"$",
"width",
"==",
"$",
"size",
")",
";",
"case",
"'height'",
":",
"return",
"(",
"$",
"height",
"==",
"$",
"size",
")",
";",
"case",
"'maxWidth'",
":",
"return",
"(",
"$",
"width",
"<=",
"$",
"size",
")",
";",
"case",
"'maxHeight'",
":",
"return",
"(",
"$",
"height",
"<=",
"$",
"size",
")",
";",
"case",
"'minWidth'",
":",
"return",
"(",
"$",
"width",
">=",
"$",
"size",
")",
";",
"case",
"'minHeight'",
":",
"return",
"(",
"$",
"height",
">=",
"$",
"size",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Validate an images dimensions.
@param array $input
@param string $type
@param int $size
@return bool
|
[
"Validate",
"an",
"images",
"dimensions",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L272-L296
|
25,196
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.ext
|
public static function ext($input, $extensions = array('gif', 'jpeg', 'png', 'jpg')) {
if (is_array($input) && isset($input['name'])) {
$input = $input['name'];
}
return in_array(Path::ext($input), (array) $extensions, true);
}
|
php
|
public static function ext($input, $extensions = array('gif', 'jpeg', 'png', 'jpg')) {
if (is_array($input) && isset($input['name'])) {
$input = $input['name'];
}
return in_array(Path::ext($input), (array) $extensions, true);
}
|
[
"public",
"static",
"function",
"ext",
"(",
"$",
"input",
",",
"$",
"extensions",
"=",
"array",
"(",
"'gif'",
",",
"'jpeg'",
",",
"'png'",
",",
"'jpg'",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"input",
")",
"&&",
"isset",
"(",
"$",
"input",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"input",
"=",
"$",
"input",
"[",
"'name'",
"]",
";",
"}",
"return",
"in_array",
"(",
"Path",
"::",
"ext",
"(",
"$",
"input",
")",
",",
"(",
"array",
")",
"$",
"extensions",
",",
"true",
")",
";",
"}"
] |
Validate input has an extension and is in the whitelist.
@uses Titon\Utility\Loader
@param string $input
@param string|array $extensions
@return bool
|
[
"Validate",
"input",
"has",
"an",
"extension",
"and",
"is",
"in",
"the",
"whitelist",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L370-L376
|
25,197
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.luhn
|
public static function luhn($input) {
if ($input == 0) {
return false;
}
$sum = 0;
$length = mb_strlen($input);
for ($position = 1 - ($length % 2); $position < $length; $position += 2) {
$sum += $input[$position];
}
for ($position = ($length % 2); $position < $length; $position += 2) {
$number = $input[$position] * 2;
$sum += ($number < 10) ? $number : $number - 9;
}
return ($sum % 10 == 0);
}
|
php
|
public static function luhn($input) {
if ($input == 0) {
return false;
}
$sum = 0;
$length = mb_strlen($input);
for ($position = 1 - ($length % 2); $position < $length; $position += 2) {
$sum += $input[$position];
}
for ($position = ($length % 2); $position < $length; $position += 2) {
$number = $input[$position] * 2;
$sum += ($number < 10) ? $number : $number - 9;
}
return ($sum % 10 == 0);
}
|
[
"public",
"static",
"function",
"luhn",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"$",
"input",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"sum",
"=",
"0",
";",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"input",
")",
";",
"for",
"(",
"$",
"position",
"=",
"1",
"-",
"(",
"$",
"length",
"%",
"2",
")",
";",
"$",
"position",
"<",
"$",
"length",
";",
"$",
"position",
"+=",
"2",
")",
"{",
"$",
"sum",
"+=",
"$",
"input",
"[",
"$",
"position",
"]",
";",
"}",
"for",
"(",
"$",
"position",
"=",
"(",
"$",
"length",
"%",
"2",
")",
";",
"$",
"position",
"<",
"$",
"length",
";",
"$",
"position",
"+=",
"2",
")",
"{",
"$",
"number",
"=",
"$",
"input",
"[",
"$",
"position",
"]",
"*",
"2",
";",
"$",
"sum",
"+=",
"(",
"$",
"number",
"<",
"10",
")",
"?",
"$",
"number",
":",
"$",
"number",
"-",
"9",
";",
"}",
"return",
"(",
"$",
"sum",
"%",
"10",
"==",
"0",
")",
";",
"}"
] |
Luhn algorithm.
@param string $input
@return bool
@link http://en.wikipedia.org/wiki/Luhn_algorithm
|
[
"Luhn",
"algorithm",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L440-L458
|
25,198
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.mimeType
|
public static function mimeType($input, $mimes) {
if (static::file($input)) {
$input = $input['tmp_name'];
}
if (!file_exists($input)) {
return false;
}
$file = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($file, $input);
finfo_close($file);
return in_array($type, (array) $mimes);
}
|
php
|
public static function mimeType($input, $mimes) {
if (static::file($input)) {
$input = $input['tmp_name'];
}
if (!file_exists($input)) {
return false;
}
$file = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($file, $input);
finfo_close($file);
return in_array($type, (array) $mimes);
}
|
[
"public",
"static",
"function",
"mimeType",
"(",
"$",
"input",
",",
"$",
"mimes",
")",
"{",
"if",
"(",
"static",
"::",
"file",
"(",
"$",
"input",
")",
")",
"{",
"$",
"input",
"=",
"$",
"input",
"[",
"'tmp_name'",
"]",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"input",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"file",
"=",
"finfo_open",
"(",
"FILEINFO_MIME_TYPE",
")",
";",
"$",
"type",
"=",
"finfo_file",
"(",
"$",
"file",
",",
"$",
"input",
")",
";",
"finfo_close",
"(",
"$",
"file",
")",
";",
"return",
"in_array",
"(",
"$",
"type",
",",
"(",
"array",
")",
"$",
"mimes",
")",
";",
"}"
] |
Validate a files mime type is in the whitelist.
@param string $input
@param string|array $mimes
@return bool
|
[
"Validate",
"a",
"files",
"mime",
"type",
"is",
"in",
"the",
"whitelist",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L467-L481
|
25,199
|
vpg/titon.utility
|
src/Titon/Utility/Validate.php
|
Validate.minFilesize
|
public static function minFilesize($input, $min) {
if (static::file($input)) {
$size = $input['size'];
} else if (file_exists($input)) {
$size = filesize($input);
} else {
return false;
}
return ($size >= Number::bytesFrom($min));
}
|
php
|
public static function minFilesize($input, $min) {
if (static::file($input)) {
$size = $input['size'];
} else if (file_exists($input)) {
$size = filesize($input);
} else {
return false;
}
return ($size >= Number::bytesFrom($min));
}
|
[
"public",
"static",
"function",
"minFilesize",
"(",
"$",
"input",
",",
"$",
"min",
")",
"{",
"if",
"(",
"static",
"::",
"file",
"(",
"$",
"input",
")",
")",
"{",
"$",
"size",
"=",
"$",
"input",
"[",
"'size'",
"]",
";",
"}",
"else",
"if",
"(",
"file_exists",
"(",
"$",
"input",
")",
")",
"{",
"$",
"size",
"=",
"filesize",
"(",
"$",
"input",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"$",
"size",
">=",
"Number",
"::",
"bytesFrom",
"(",
"$",
"min",
")",
")",
";",
"}"
] |
Validate an images file size is above the minimum.
@param array $input
@param int $min
@return bool
|
[
"Validate",
"an",
"images",
"file",
"size",
"is",
"above",
"the",
"minimum",
"."
] |
8a77eb9e7b8baacf41cc25487289779d8319cd3a
|
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validate.php#L490-L502
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.