repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
NukaCode/core | src/NukaCode/Core/Http/Controllers/BaseController.php | BaseController.setJavascriptData | protected function setJavascriptData($key, $value = null)
{
if (is_array($key)) {
JavaScriptFacade::put($key);
} else {
JavaScriptFacade::put([$key => $value]);
}
} | php | protected function setJavascriptData($key, $value = null)
{
if (is_array($key)) {
JavaScriptFacade::put($key);
} else {
JavaScriptFacade::put([$key => $value]);
}
} | [
"protected",
"function",
"setJavascriptData",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"JavaScriptFacade",
"::",
"put",
"(",
"$",
"key",
")",
";",
"}",
"else",
"{",
"JavaScriptFacade",
"::",
"put",
"(",
"[",
"$",
"key",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"}"
] | Pass data directly to Javascript.
@link https://github.com/laracasts/PHP-Vars-To-Js-Transformer
@param mixed $key
@param mixed $value
@return $this | [
"Pass",
"data",
"directly",
"to",
"Javascript",
"."
] | 75b20903fb068a7df22cdec34ae729279fbaab3c | https://github.com/NukaCode/core/blob/75b20903fb068a7df22cdec34ae729279fbaab3c/src/NukaCode/Core/Http/Controllers/BaseController.php#L75-L82 | train |
ddrv-test/firmapi-core | src/Object/Company.php | Company.actionAdd | protected function actionAdd($params=array())
{
$response = array(
'errors' => array(),
'data' => array(),
);
$values = $this->company->prepareParams($params);
if (empty($values['name'])) {
$response['errors'][] = 'cmp01';
}
if (empty($values['build'])) {
$response['errors'][] = 'cmp02';
}
if (!$this->checkBuildExists($values['build'])) {
$response['errors'][] = 'cmp03';
}
if ($this->checkCompanyExists($values['id'])) {
$response['errors'][] = 'cmp04';
$response['data']['id'] = $values['id'];
}
if (!empty($response['errors'])) {
return $response;
}
$result = $this->company->add($values);
if ($result) {
$response['data']['id'] = $values['id'];
} else {
$response['errors'][] = 'err01';
}
return $response;
} | php | protected function actionAdd($params=array())
{
$response = array(
'errors' => array(),
'data' => array(),
);
$values = $this->company->prepareParams($params);
if (empty($values['name'])) {
$response['errors'][] = 'cmp01';
}
if (empty($values['build'])) {
$response['errors'][] = 'cmp02';
}
if (!$this->checkBuildExists($values['build'])) {
$response['errors'][] = 'cmp03';
}
if ($this->checkCompanyExists($values['id'])) {
$response['errors'][] = 'cmp04';
$response['data']['id'] = $values['id'];
}
if (!empty($response['errors'])) {
return $response;
}
$result = $this->company->add($values);
if ($result) {
$response['data']['id'] = $values['id'];
} else {
$response['errors'][] = 'err01';
}
return $response;
} | [
"protected",
"function",
"actionAdd",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"response",
"=",
"array",
"(",
"'errors'",
"=>",
"array",
"(",
")",
",",
"'data'",
"=>",
"array",
"(",
")",
",",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"company",
"->",
"prepareParams",
"(",
"$",
"params",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"values",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"response",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"'cmp01'",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"values",
"[",
"'build'",
"]",
")",
")",
"{",
"$",
"response",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"'cmp02'",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"checkBuildExists",
"(",
"$",
"values",
"[",
"'build'",
"]",
")",
")",
"{",
"$",
"response",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"'cmp03'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"checkCompanyExists",
"(",
"$",
"values",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"response",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"'cmp04'",
";",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'id'",
"]",
"=",
"$",
"values",
"[",
"'id'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
"[",
"'errors'",
"]",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"company",
"->",
"add",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'id'",
"]",
"=",
"$",
"values",
"[",
"'id'",
"]",
";",
"}",
"else",
"{",
"$",
"response",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"'err01'",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Add company.
@param array $params
@return array | [
"Add",
"company",
"."
] | 8f8843f0fb134568e7764cabd5039e15c579976d | https://github.com/ddrv-test/firmapi-core/blob/8f8843f0fb134568e7764cabd5039e15c579976d/src/Object/Company.php#L75-L107 | train |
Weblab-nl/restclient | src/RESTClient.php | RESTClient.put | public function put($url, $params, $options = [], $headers = []) {
return $this->update('put', $url, $params, $options, $headers);
} | php | public function put($url, $params, $options = [], $headers = []) {
return $this->update('put', $url, $params, $options, $headers);
} | [
"public",
"function",
"put",
"(",
"$",
"url",
",",
"$",
"params",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"update",
"(",
"'put'",
",",
"$",
"url",
",",
"$",
"params",
",",
"$",
"options",
",",
"$",
"headers",
")",
";",
"}"
] | Do a PUT request
@param string $url
@param array $params
@param array $options
@param array $headers
@return mixed
@throws \Exception | [
"Do",
"a",
"PUT",
"request"
] | 6bc4e7890580b7b31e78032e40be5a67122b0dd0 | https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/RESTClient.php#L115-L117 | train |
Weblab-nl/restclient | src/RESTClient.php | RESTClient.update | protected function update($type, $url, $params, $options = [], $headers = []) {
return $this->makeCall($type, $url, $params, $options, $headers);
} | php | protected function update($type, $url, $params, $options = [], $headers = []) {
return $this->makeCall($type, $url, $params, $options, $headers);
} | [
"protected",
"function",
"update",
"(",
"$",
"type",
",",
"$",
"url",
",",
"$",
"params",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"makeCall",
"(",
"$",
"type",
",",
"$",
"url",
",",
"$",
"params",
",",
"$",
"options",
",",
"$",
"headers",
")",
";",
"}"
] | Proxy function for both edit requests types
@param string $type
@param string $url
@param array $params
@param array $options
@param array $headers
@return mixed
@throws \Exception | [
"Proxy",
"function",
"for",
"both",
"edit",
"requests",
"types"
] | 6bc4e7890580b7b31e78032e40be5a67122b0dd0 | https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/RESTClient.php#L144-L146 | train |
Weblab-nl/restclient | src/RESTClient.php | RESTClient.makeCall | protected function makeCall($type, $url, $params, $options, $headers) {
// Throw exception when adapter is not set
if (!isset($this->adapter)) {
throw new NoAdapterException('No adapter set');
}
// Remove potential leading slashes
if (substr($url, 0, 1) === '/') {
$url = substr($url, 1);
}
// Call adapter to make request
$result = $this->adapter->doRequest($type, $this->baseURL . $url, $params, $options, $headers);
// Run the the response handler
return $this->runResponseHandler($result, $type, $url, $params);
} | php | protected function makeCall($type, $url, $params, $options, $headers) {
// Throw exception when adapter is not set
if (!isset($this->adapter)) {
throw new NoAdapterException('No adapter set');
}
// Remove potential leading slashes
if (substr($url, 0, 1) === '/') {
$url = substr($url, 1);
}
// Call adapter to make request
$result = $this->adapter->doRequest($type, $this->baseURL . $url, $params, $options, $headers);
// Run the the response handler
return $this->runResponseHandler($result, $type, $url, $params);
} | [
"protected",
"function",
"makeCall",
"(",
"$",
"type",
",",
"$",
"url",
",",
"$",
"params",
",",
"$",
"options",
",",
"$",
"headers",
")",
"{",
"// Throw exception when adapter is not set",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"adapter",
")",
")",
"{",
"throw",
"new",
"NoAdapterException",
"(",
"'No adapter set'",
")",
";",
"}",
"// Remove potential leading slashes",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"1",
")",
"===",
"'/'",
")",
"{",
"$",
"url",
"=",
"substr",
"(",
"$",
"url",
",",
"1",
")",
";",
"}",
"// Call adapter to make request",
"$",
"result",
"=",
"$",
"this",
"->",
"adapter",
"->",
"doRequest",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"baseURL",
".",
"$",
"url",
",",
"$",
"params",
",",
"$",
"options",
",",
"$",
"headers",
")",
";",
"// Run the the response handler",
"return",
"$",
"this",
"->",
"runResponseHandler",
"(",
"$",
"result",
",",
"$",
"type",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"}"
] | Calls the adapter which will perform the request
@param string $type
@param string $url
@param array $params
@param array $options
@param array $headers
@return Result
@throws NoAdapterException
@throws \Exception | [
"Calls",
"the",
"adapter",
"which",
"will",
"perform",
"the",
"request"
] | 6bc4e7890580b7b31e78032e40be5a67122b0dd0 | https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/RESTClient.php#L174-L190 | train |
Weblab-nl/restclient | src/RESTClient.php | RESTClient.runResponseHandler | protected function runResponseHandler(Result $result, $type, $url, $params) {
// Check if a status specific handler isset or else fallback to the default
if (isset($this->responseHandlers[$result->getStatus()])) {
$handler = $this->responseHandlers[$result->getStatus()];
} else {
$handler = $this->responseHandlers['default'];
}
// If the handler is a callable run the handler and return the result
if (is_callable($handler)) {
return $handler($result, $type, $url, $params);
}
// If the handler does not exists, throw exception
else if (!method_exists($this, $handler)) {
throw new ResponseHandlerNotFoundException('Response handler not found: ' . $handler);
}
// Run the handler and return the result
return $this->$handler($result, $type, $url, $params);
} | php | protected function runResponseHandler(Result $result, $type, $url, $params) {
// Check if a status specific handler isset or else fallback to the default
if (isset($this->responseHandlers[$result->getStatus()])) {
$handler = $this->responseHandlers[$result->getStatus()];
} else {
$handler = $this->responseHandlers['default'];
}
// If the handler is a callable run the handler and return the result
if (is_callable($handler)) {
return $handler($result, $type, $url, $params);
}
// If the handler does not exists, throw exception
else if (!method_exists($this, $handler)) {
throw new ResponseHandlerNotFoundException('Response handler not found: ' . $handler);
}
// Run the handler and return the result
return $this->$handler($result, $type, $url, $params);
} | [
"protected",
"function",
"runResponseHandler",
"(",
"Result",
"$",
"result",
",",
"$",
"type",
",",
"$",
"url",
",",
"$",
"params",
")",
"{",
"// Check if a status specific handler isset or else fallback to the default",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"responseHandlers",
"[",
"$",
"result",
"->",
"getStatus",
"(",
")",
"]",
")",
")",
"{",
"$",
"handler",
"=",
"$",
"this",
"->",
"responseHandlers",
"[",
"$",
"result",
"->",
"getStatus",
"(",
")",
"]",
";",
"}",
"else",
"{",
"$",
"handler",
"=",
"$",
"this",
"->",
"responseHandlers",
"[",
"'default'",
"]",
";",
"}",
"// If the handler is a callable run the handler and return the result",
"if",
"(",
"is_callable",
"(",
"$",
"handler",
")",
")",
"{",
"return",
"$",
"handler",
"(",
"$",
"result",
",",
"$",
"type",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"}",
"// If the handler does not exists, throw exception",
"else",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"handler",
")",
")",
"{",
"throw",
"new",
"ResponseHandlerNotFoundException",
"(",
"'Response handler not found: '",
".",
"$",
"handler",
")",
";",
"}",
"// Run the handler and return the result",
"return",
"$",
"this",
"->",
"$",
"handler",
"(",
"$",
"result",
",",
"$",
"type",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"}"
] | Run the correct response handler function
@param Result $result
@param string $type
@param string $url
@param array $params
@return Result
@throws \Exception | [
"Run",
"the",
"correct",
"response",
"handler",
"function"
] | 6bc4e7890580b7b31e78032e40be5a67122b0dd0 | https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/RESTClient.php#L215-L234 | train |
proem-components/service | AssetManager.php | AssetManager.set | public function set($index, AssetInterface $asset)
{
$this->data[$index] = $asset;
$this->provides[] = $asset->is();
return $this;
} | php | public function set($index, AssetInterface $asset)
{
$this->data[$index] = $asset;
$this->provides[] = $asset->is();
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"index",
",",
"AssetInterface",
"$",
"asset",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"index",
"]",
"=",
"$",
"asset",
";",
"$",
"this",
"->",
"provides",
"[",
"]",
"=",
"$",
"asset",
"->",
"is",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Store an Asset container by named index.
@param string $index The index the asset will be referenced by.
@param Proem\Service\AssetInterface $asset
@return Proem\Service\AssetManagerInterface | [
"Store",
"an",
"Asset",
"container",
"by",
"named",
"index",
"."
] | 8c8e9547f16ecaa2789482f34947618f96e453cc | https://github.com/proem-components/service/blob/8c8e9547f16ecaa2789482f34947618f96e453cc/AssetManager.php#L75-L80 | train |
proem-components/service | AssetManager.php | AssetManager.get | public function get($index, array $params = [], $asAsset = false)
{
if (!$asAsset) {
return isset($this->data[$index]) ? $this->data[$index]->fetch($params, $this) : null;
}
return isset($this->data[$index]) ? $this->data[$index] : null;
} | php | public function get($index, array $params = [], $asAsset = false)
{
if (!$asAsset) {
return isset($this->data[$index]) ? $this->data[$index]->fetch($params, $this) : null;
}
return isset($this->data[$index]) ? $this->data[$index] : null;
} | [
"public",
"function",
"get",
"(",
"$",
"index",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"asAsset",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"asAsset",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"index",
"]",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"$",
"index",
"]",
"->",
"fetch",
"(",
"$",
"params",
",",
"$",
"this",
")",
":",
"null",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"index",
"]",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"$",
"index",
"]",
":",
"null",
";",
"}"
] | Retrieve an asset.
Returns an instantiated obejct by default or optionaly the
asset container itself.
@param string $index The index the asset is referenced by
@param array $params Allow last minute setting of parameters.
@param bool Wether or not to return the asset's object or container
@return object The object provided by the asset container | [
"Retrieve",
"an",
"asset",
"."
] | 8c8e9547f16ecaa2789482f34947618f96e453cc | https://github.com/proem-components/service/blob/8c8e9547f16ecaa2789482f34947618f96e453cc/AssetManager.php#L93-L100 | train |
lassodatasystems/LassoMailParserBundle | Parser.php | Parser.parse | public function parse($mail)
{
// Initial
/** @var Part $mailPart */
$mailPart = $this->workAroundMissingBoundary(
$this->partFactory->getPart($mail),
$mail
);
$partTreeFactory = new PartTreeFactory($this->partFactory);
$partTree = $partTreeFactory->make($mailPart);
/** @var Part[] $parts */
$parts = $partTree->flattenParts();
/** @var Part $envelopedEmail */
$envelopedEmail = $partTree->getEnvelopedEmail();
// Everything else
$loggingEmails = $this->getLoggingEmails($mailPart, $parts);
// All email addresses as a hash in the form $allEmailAddressesByField[field] = [];
$allEmailAddressesByField = $this->getAllEmailAddresses($parts);
return new ParsedMail(
$mail,
$mailPart,
$parts,
$loggingEmails,
$allEmailAddressesByField,
$envelopedEmail
);
} | php | public function parse($mail)
{
// Initial
/** @var Part $mailPart */
$mailPart = $this->workAroundMissingBoundary(
$this->partFactory->getPart($mail),
$mail
);
$partTreeFactory = new PartTreeFactory($this->partFactory);
$partTree = $partTreeFactory->make($mailPart);
/** @var Part[] $parts */
$parts = $partTree->flattenParts();
/** @var Part $envelopedEmail */
$envelopedEmail = $partTree->getEnvelopedEmail();
// Everything else
$loggingEmails = $this->getLoggingEmails($mailPart, $parts);
// All email addresses as a hash in the form $allEmailAddressesByField[field] = [];
$allEmailAddressesByField = $this->getAllEmailAddresses($parts);
return new ParsedMail(
$mail,
$mailPart,
$parts,
$loggingEmails,
$allEmailAddressesByField,
$envelopedEmail
);
} | [
"public",
"function",
"parse",
"(",
"$",
"mail",
")",
"{",
"// Initial",
"/** @var Part $mailPart */",
"$",
"mailPart",
"=",
"$",
"this",
"->",
"workAroundMissingBoundary",
"(",
"$",
"this",
"->",
"partFactory",
"->",
"getPart",
"(",
"$",
"mail",
")",
",",
"$",
"mail",
")",
";",
"$",
"partTreeFactory",
"=",
"new",
"PartTreeFactory",
"(",
"$",
"this",
"->",
"partFactory",
")",
";",
"$",
"partTree",
"=",
"$",
"partTreeFactory",
"->",
"make",
"(",
"$",
"mailPart",
")",
";",
"/** @var Part[] $parts */",
"$",
"parts",
"=",
"$",
"partTree",
"->",
"flattenParts",
"(",
")",
";",
"/** @var Part $envelopedEmail */",
"$",
"envelopedEmail",
"=",
"$",
"partTree",
"->",
"getEnvelopedEmail",
"(",
")",
";",
"// Everything else",
"$",
"loggingEmails",
"=",
"$",
"this",
"->",
"getLoggingEmails",
"(",
"$",
"mailPart",
",",
"$",
"parts",
")",
";",
"// All email addresses as a hash in the form $allEmailAddressesByField[field] = [];",
"$",
"allEmailAddressesByField",
"=",
"$",
"this",
"->",
"getAllEmailAddresses",
"(",
"$",
"parts",
")",
";",
"return",
"new",
"ParsedMail",
"(",
"$",
"mail",
",",
"$",
"mailPart",
",",
"$",
"parts",
",",
"$",
"loggingEmails",
",",
"$",
"allEmailAddressesByField",
",",
"$",
"envelopedEmail",
")",
";",
"}"
] | Accepts the raw email as a string, including headers and body. Has to be called before the other functions
are available.
@param string $mail
@return ParsedMail | [
"Accepts",
"the",
"raw",
"email",
"as",
"a",
"string",
"including",
"headers",
"and",
"body",
".",
"Has",
"to",
"be",
"called",
"before",
"the",
"other",
"functions",
"are",
"available",
"."
] | c7d2bde3034462fd305e38481cfb737b50eede0a | https://github.com/lassodatasystems/LassoMailParserBundle/blob/c7d2bde3034462fd305e38481cfb737b50eede0a/Parser.php#L57-L88 | train |
lassodatasystems/LassoMailParserBundle | Parser.php | Parser.workAroundMissingBoundary | private function workAroundMissingBoundary(Part $part, $rawMailBody)
{
try {
$part->countParts();
} catch (RuntimeException $e) {
if (count($part->getHeaders()) > 0
&& $part->getHeaders()->has('Content-Type')
&& array_key_exists('boundary', $this->getContentType($part)->getParameters())
) {
$boundary = $part
->getHeaders()
->get('Content-Type')
->getParameter('boundary');
$content = trim($rawMailBody);
$content .= "\n--{$boundary}--";
$part = $this->partFactory->getPart($content);
}
}
return $part;
} | php | private function workAroundMissingBoundary(Part $part, $rawMailBody)
{
try {
$part->countParts();
} catch (RuntimeException $e) {
if (count($part->getHeaders()) > 0
&& $part->getHeaders()->has('Content-Type')
&& array_key_exists('boundary', $this->getContentType($part)->getParameters())
) {
$boundary = $part
->getHeaders()
->get('Content-Type')
->getParameter('boundary');
$content = trim($rawMailBody);
$content .= "\n--{$boundary}--";
$part = $this->partFactory->getPart($content);
}
}
return $part;
} | [
"private",
"function",
"workAroundMissingBoundary",
"(",
"Part",
"$",
"part",
",",
"$",
"rawMailBody",
")",
"{",
"try",
"{",
"$",
"part",
"->",
"countParts",
"(",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"part",
"->",
"getHeaders",
"(",
")",
")",
">",
"0",
"&&",
"$",
"part",
"->",
"getHeaders",
"(",
")",
"->",
"has",
"(",
"'Content-Type'",
")",
"&&",
"array_key_exists",
"(",
"'boundary'",
",",
"$",
"this",
"->",
"getContentType",
"(",
"$",
"part",
")",
"->",
"getParameters",
"(",
")",
")",
")",
"{",
"$",
"boundary",
"=",
"$",
"part",
"->",
"getHeaders",
"(",
")",
"->",
"get",
"(",
"'Content-Type'",
")",
"->",
"getParameter",
"(",
"'boundary'",
")",
";",
"$",
"content",
"=",
"trim",
"(",
"$",
"rawMailBody",
")",
";",
"$",
"content",
".=",
"\"\\n--{$boundary}--\"",
";",
"$",
"part",
"=",
"$",
"this",
"->",
"partFactory",
"->",
"getPart",
"(",
"$",
"content",
")",
";",
"}",
"}",
"return",
"$",
"part",
";",
"}"
] | Some emails are missing a MIME closing boundary. This violations the standard,
but most software still handles it well - except the Zend Framework, who rather
don't want to accommodate broken emails.
Since they don't provide any meaningful way to test if the message was decoded
correctly (like a $part->test() method or something), the only recourse is to
call some function on the part and handle the exception that's thrown when the
closing boundary is missing.
Then append the boundary and re-parse the email.
@param Part $part
@param string $rawMailBody
@return Part | [
"Some",
"emails",
"are",
"missing",
"a",
"MIME",
"closing",
"boundary",
".",
"This",
"violations",
"the",
"standard",
"but",
"most",
"software",
"still",
"handles",
"it",
"well",
"-",
"except",
"the",
"Zend",
"Framework",
"who",
"rather",
"don",
"t",
"want",
"to",
"accommodate",
"broken",
"emails",
"."
] | c7d2bde3034462fd305e38481cfb737b50eede0a | https://github.com/lassodatasystems/LassoMailParserBundle/blob/c7d2bde3034462fd305e38481cfb737b50eede0a/Parser.php#L106-L128 | train |
lassodatasystems/LassoMailParserBundle | Parser.php | Parser.getLoggingEmails | private function getLoggingEmails($mail, $parts)
{
$emailAddresses = $this->flattenEmailAddresses(
$this->getAllEmailAddresses($parts)
);
$messageIds = [];
$headers = $mail->getHeaders();
if (!empty($headers) && $headers->has('message-id')) {
$messageId = $headers->get('message-id');
if ($messageId instanceof ArrayIterator) {
foreach ($messageId as $header) {
/** @var $header HeaderInterface */
$messageIds[] = $header->getFieldValue();
}
} elseif ($messageId instanceof HeaderInterface) {
$messageIds = [$messageId->getFieldValue()];
}
}
/*
* Also strip < and > from message id to only return the email-like id
*/
$messageIds = array_map(function ($messageId) {
return trim($messageId, " \t\n\r\0\x0B<>");
}, $messageIds);
return array_merge($emailAddresses, $messageIds);
} | php | private function getLoggingEmails($mail, $parts)
{
$emailAddresses = $this->flattenEmailAddresses(
$this->getAllEmailAddresses($parts)
);
$messageIds = [];
$headers = $mail->getHeaders();
if (!empty($headers) && $headers->has('message-id')) {
$messageId = $headers->get('message-id');
if ($messageId instanceof ArrayIterator) {
foreach ($messageId as $header) {
/** @var $header HeaderInterface */
$messageIds[] = $header->getFieldValue();
}
} elseif ($messageId instanceof HeaderInterface) {
$messageIds = [$messageId->getFieldValue()];
}
}
/*
* Also strip < and > from message id to only return the email-like id
*/
$messageIds = array_map(function ($messageId) {
return trim($messageId, " \t\n\r\0\x0B<>");
}, $messageIds);
return array_merge($emailAddresses, $messageIds);
} | [
"private",
"function",
"getLoggingEmails",
"(",
"$",
"mail",
",",
"$",
"parts",
")",
"{",
"$",
"emailAddresses",
"=",
"$",
"this",
"->",
"flattenEmailAddresses",
"(",
"$",
"this",
"->",
"getAllEmailAddresses",
"(",
"$",
"parts",
")",
")",
";",
"$",
"messageIds",
"=",
"[",
"]",
";",
"$",
"headers",
"=",
"$",
"mail",
"->",
"getHeaders",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"headers",
")",
"&&",
"$",
"headers",
"->",
"has",
"(",
"'message-id'",
")",
")",
"{",
"$",
"messageId",
"=",
"$",
"headers",
"->",
"get",
"(",
"'message-id'",
")",
";",
"if",
"(",
"$",
"messageId",
"instanceof",
"ArrayIterator",
")",
"{",
"foreach",
"(",
"$",
"messageId",
"as",
"$",
"header",
")",
"{",
"/** @var $header HeaderInterface */",
"$",
"messageIds",
"[",
"]",
"=",
"$",
"header",
"->",
"getFieldValue",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"messageId",
"instanceof",
"HeaderInterface",
")",
"{",
"$",
"messageIds",
"=",
"[",
"$",
"messageId",
"->",
"getFieldValue",
"(",
")",
"]",
";",
"}",
"}",
"/*\n * Also strip < and > from message id to only return the email-like id\n */",
"$",
"messageIds",
"=",
"array_map",
"(",
"function",
"(",
"$",
"messageId",
")",
"{",
"return",
"trim",
"(",
"$",
"messageId",
",",
"\" \\t\\n\\r\\0\\x0B<>\"",
")",
";",
"}",
",",
"$",
"messageIds",
")",
";",
"return",
"array_merge",
"(",
"$",
"emailAddresses",
",",
"$",
"messageIds",
")",
";",
"}"
] | Returns a list of all emails in the parser, including
the message id. This is mostly useful for logging.
@param Part $mail
@param Part[] $parts
@return array | [
"Returns",
"a",
"list",
"of",
"all",
"emails",
"in",
"the",
"parser",
"including",
"the",
"message",
"id",
".",
"This",
"is",
"mostly",
"useful",
"for",
"logging",
"."
] | c7d2bde3034462fd305e38481cfb737b50eede0a | https://github.com/lassodatasystems/LassoMailParserBundle/blob/c7d2bde3034462fd305e38481cfb737b50eede0a/Parser.php#L141-L169 | train |
lassodatasystems/LassoMailParserBundle | Parser.php | Parser.flattenEmailAddresses | private function flattenEmailAddresses($emailAddressesByField) {
$flattened = [];
foreach ($emailAddressesByField as $field => $emailAddresses) {
foreach ($emailAddresses as $emailAddress) {
$flattened[] = $emailAddress;
}
}
return array_unique($flattened);
} | php | private function flattenEmailAddresses($emailAddressesByField) {
$flattened = [];
foreach ($emailAddressesByField as $field => $emailAddresses) {
foreach ($emailAddresses as $emailAddress) {
$flattened[] = $emailAddress;
}
}
return array_unique($flattened);
} | [
"private",
"function",
"flattenEmailAddresses",
"(",
"$",
"emailAddressesByField",
")",
"{",
"$",
"flattened",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"emailAddressesByField",
"as",
"$",
"field",
"=>",
"$",
"emailAddresses",
")",
"{",
"foreach",
"(",
"$",
"emailAddresses",
"as",
"$",
"emailAddress",
")",
"{",
"$",
"flattened",
"[",
"]",
"=",
"$",
"emailAddress",
";",
"}",
"}",
"return",
"array_unique",
"(",
"$",
"flattened",
")",
";",
"}"
] | Takes the hash of email address and the field they were found in and
returns a flattened array of those email addresses.
@param $emailAddressesByField
@return array | [
"Takes",
"the",
"hash",
"of",
"email",
"address",
"and",
"the",
"field",
"they",
"were",
"found",
"in",
"and",
"returns",
"a",
"flattened",
"array",
"of",
"those",
"email",
"addresses",
"."
] | c7d2bde3034462fd305e38481cfb737b50eede0a | https://github.com/lassodatasystems/LassoMailParserBundle/blob/c7d2bde3034462fd305e38481cfb737b50eede0a/Parser.php#L179-L188 | train |
lassodatasystems/LassoMailParserBundle | Parser.php | Parser.getAddressesFromFieldInPart | private function getAddressesFromFieldInPart($field, Part $part)
{
$addresses = [];
$headers = $part->getHeaders();
if (empty($headers)) {
return $addresses;
}
if (!$headers->has($field)) {
return $addresses;
}
/** @var AbstractAddressList $addressList */
$addressList = null;
try {
$addressList = $part->getHeader($field);
} catch (InvalidArgumentException $e) {
return $addresses;
}
if (!$addressList instanceof AbstractAddressList) {
return $addresses;
}
foreach ($addressList->getAddressList() as $address) {
$addresses[] = strtolower($address->getEmail());
}
return $addresses;
} | php | private function getAddressesFromFieldInPart($field, Part $part)
{
$addresses = [];
$headers = $part->getHeaders();
if (empty($headers)) {
return $addresses;
}
if (!$headers->has($field)) {
return $addresses;
}
/** @var AbstractAddressList $addressList */
$addressList = null;
try {
$addressList = $part->getHeader($field);
} catch (InvalidArgumentException $e) {
return $addresses;
}
if (!$addressList instanceof AbstractAddressList) {
return $addresses;
}
foreach ($addressList->getAddressList() as $address) {
$addresses[] = strtolower($address->getEmail());
}
return $addresses;
} | [
"private",
"function",
"getAddressesFromFieldInPart",
"(",
"$",
"field",
",",
"Part",
"$",
"part",
")",
"{",
"$",
"addresses",
"=",
"[",
"]",
";",
"$",
"headers",
"=",
"$",
"part",
"->",
"getHeaders",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"headers",
")",
")",
"{",
"return",
"$",
"addresses",
";",
"}",
"if",
"(",
"!",
"$",
"headers",
"->",
"has",
"(",
"$",
"field",
")",
")",
"{",
"return",
"$",
"addresses",
";",
"}",
"/** @var AbstractAddressList $addressList */",
"$",
"addressList",
"=",
"null",
";",
"try",
"{",
"$",
"addressList",
"=",
"$",
"part",
"->",
"getHeader",
"(",
"$",
"field",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"return",
"$",
"addresses",
";",
"}",
"if",
"(",
"!",
"$",
"addressList",
"instanceof",
"AbstractAddressList",
")",
"{",
"return",
"$",
"addresses",
";",
"}",
"foreach",
"(",
"$",
"addressList",
"->",
"getAddressList",
"(",
")",
"as",
"$",
"address",
")",
"{",
"$",
"addresses",
"[",
"]",
"=",
"strtolower",
"(",
"$",
"address",
"->",
"getEmail",
"(",
")",
")",
";",
"}",
"return",
"$",
"addresses",
";",
"}"
] | Retrieves the addresses from a specific field in a part
@param string $field
@param Part $part
@return array | [
"Retrieves",
"the",
"addresses",
"from",
"a",
"specific",
"field",
"in",
"a",
"part"
] | c7d2bde3034462fd305e38481cfb737b50eede0a | https://github.com/lassodatasystems/LassoMailParserBundle/blob/c7d2bde3034462fd305e38481cfb737b50eede0a/Parser.php#L223-L254 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php | AlterTableSQLCollector.init | public function init()
{
$this->renameTableQueries = array();
$this->dropCheckQueries = array();
$this->dropForeignKeyQueries = array();
$this->dropIndexQueries = array();
$this->dropPrimaryKeyQueries = array();
$this->dropColumnQueries = array();
$this->alterColumnQueries = array();
$this->createColumnQueries = array();
$this->createPrimaryKeyQueries = array();
$this->createIndexQueries = array();
$this->createForeignKeyQueries = array();
$this->createCheckQueries = array();
} | php | public function init()
{
$this->renameTableQueries = array();
$this->dropCheckQueries = array();
$this->dropForeignKeyQueries = array();
$this->dropIndexQueries = array();
$this->dropPrimaryKeyQueries = array();
$this->dropColumnQueries = array();
$this->alterColumnQueries = array();
$this->createColumnQueries = array();
$this->createPrimaryKeyQueries = array();
$this->createIndexQueries = array();
$this->createForeignKeyQueries = array();
$this->createCheckQueries = array();
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"renameTableQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"dropCheckQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"dropForeignKeyQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"dropIndexQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"dropPrimaryKeyQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"dropColumnQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"alterColumnQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"createColumnQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"createPrimaryKeyQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"createIndexQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"createForeignKeyQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"createCheckQueries",
"=",
"array",
"(",
")",
";",
"}"
] | Reinitilizes SQL collector. | [
"Reinitilizes",
"SQL",
"collector",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php#L112-L126 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php | AlterTableSQLCollector.collect | public function collect(TableDiff $tableDiff)
{
if ($tableDiff->getOldAsset()->getName() !== $tableDiff->getNewAsset()->getName()) {
$this->renameTableQueries = array_merge(
$this->renameTableQueries,
$this->platform->getRenameTableSQLQueries($tableDiff)
);
}
$this->collectColumns($tableDiff);
$this->collectPrimaryKeys($tableDiff);
$this->collectForeignKeys($tableDiff);
$this->collectIndexes($tableDiff);
$this->collectChecks($tableDiff);
} | php | public function collect(TableDiff $tableDiff)
{
if ($tableDiff->getOldAsset()->getName() !== $tableDiff->getNewAsset()->getName()) {
$this->renameTableQueries = array_merge(
$this->renameTableQueries,
$this->platform->getRenameTableSQLQueries($tableDiff)
);
}
$this->collectColumns($tableDiff);
$this->collectPrimaryKeys($tableDiff);
$this->collectForeignKeys($tableDiff);
$this->collectIndexes($tableDiff);
$this->collectChecks($tableDiff);
} | [
"public",
"function",
"collect",
"(",
"TableDiff",
"$",
"tableDiff",
")",
"{",
"if",
"(",
"$",
"tableDiff",
"->",
"getOldAsset",
"(",
")",
"->",
"getName",
"(",
")",
"!==",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"this",
"->",
"renameTableQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"renameTableQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getRenameTableSQLQueries",
"(",
"$",
"tableDiff",
")",
")",
";",
"}",
"$",
"this",
"->",
"collectColumns",
"(",
"$",
"tableDiff",
")",
";",
"$",
"this",
"->",
"collectPrimaryKeys",
"(",
"$",
"tableDiff",
")",
";",
"$",
"this",
"->",
"collectForeignKeys",
"(",
"$",
"tableDiff",
")",
";",
"$",
"this",
"->",
"collectIndexes",
"(",
"$",
"tableDiff",
")",
";",
"$",
"this",
"->",
"collectChecks",
"(",
"$",
"tableDiff",
")",
";",
"}"
] | Collects queries to alter tables.
@param \Fridge\DBAL\Schema\Diff\TableDiff $tableDiff The table difference. | [
"Collects",
"queries",
"to",
"alter",
"tables",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php#L133-L147 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php | AlterTableSQLCollector.getQueries | public function getQueries()
{
return array_merge(
$this->getRenameTableQueries(),
$this->getDropCheckQueries(),
$this->getDropForeignKeyQueries(),
$this->getDropIndexQueries(),
$this->getDropPrimaryKeyQueries(),
$this->getDropColumnQueries(),
$this->getAlterColumnQueries(),
$this->getCreateColumnQueries(),
$this->getCreatePrimaryKeyQueries(),
$this->getCreateIndexQueries(),
$this->getCreateForeignKeyQueries(),
$this->getCreateCheckQueries()
);
} | php | public function getQueries()
{
return array_merge(
$this->getRenameTableQueries(),
$this->getDropCheckQueries(),
$this->getDropForeignKeyQueries(),
$this->getDropIndexQueries(),
$this->getDropPrimaryKeyQueries(),
$this->getDropColumnQueries(),
$this->getAlterColumnQueries(),
$this->getCreateColumnQueries(),
$this->getCreatePrimaryKeyQueries(),
$this->getCreateIndexQueries(),
$this->getCreateForeignKeyQueries(),
$this->getCreateCheckQueries()
);
} | [
"public",
"function",
"getQueries",
"(",
")",
"{",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"getRenameTableQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropCheckQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropForeignKeyQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropIndexQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropPrimaryKeyQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropColumnQueries",
"(",
")",
",",
"$",
"this",
"->",
"getAlterColumnQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateColumnQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreatePrimaryKeyQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateIndexQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateForeignKeyQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateCheckQueries",
"(",
")",
")",
";",
"}"
] | Gets the queries collected to alter the table.
@return array The queries collected to alter the table. | [
"Gets",
"the",
"queries",
"collected",
"to",
"alter",
"the",
"table",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php#L274-L290 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php | AlterTableSQLCollector.collectColumns | private function collectColumns(TableDiff $tableDiff)
{
foreach ($tableDiff->getCreatedColumns() as $column) {
$this->createColumnQueries = array_merge(
$this->createColumnQueries,
$this->platform->getCreateColumnSQLQueries($column, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getDroppedColumns() as $column) {
$this->dropColumnQueries = array_merge(
$this->dropColumnQueries,
$this->platform->getDropColumnSQLQueries($column, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getAlteredColumns() as $columnDiff) {
$this->alterColumnQueries = array_merge(
$this->alterColumnQueries,
$this->platform->getAlterColumnSQLQueries($columnDiff, $tableDiff->getNewAsset()->getName())
);
}
} | php | private function collectColumns(TableDiff $tableDiff)
{
foreach ($tableDiff->getCreatedColumns() as $column) {
$this->createColumnQueries = array_merge(
$this->createColumnQueries,
$this->platform->getCreateColumnSQLQueries($column, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getDroppedColumns() as $column) {
$this->dropColumnQueries = array_merge(
$this->dropColumnQueries,
$this->platform->getDropColumnSQLQueries($column, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getAlteredColumns() as $columnDiff) {
$this->alterColumnQueries = array_merge(
$this->alterColumnQueries,
$this->platform->getAlterColumnSQLQueries($columnDiff, $tableDiff->getNewAsset()->getName())
);
}
} | [
"private",
"function",
"collectColumns",
"(",
"TableDiff",
"$",
"tableDiff",
")",
"{",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getCreatedColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"createColumnQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"createColumnQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getCreateColumnSQLQueries",
"(",
"$",
"column",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getDroppedColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"dropColumnQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dropColumnQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getDropColumnSQLQueries",
"(",
"$",
"column",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getAlteredColumns",
"(",
")",
"as",
"$",
"columnDiff",
")",
"{",
"$",
"this",
"->",
"alterColumnQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"alterColumnQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getAlterColumnSQLQueries",
"(",
"$",
"columnDiff",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}"
] | Collects queries about column to alter a table.
@param \Fridge\DBAL\Schema\Diff\TableDiff $tableDiff The table difference. | [
"Collects",
"queries",
"about",
"column",
"to",
"alter",
"a",
"table",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php#L297-L319 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php | AlterTableSQLCollector.collectPrimaryKeys | private function collectPrimaryKeys(TableDiff $tableDiff)
{
if ($tableDiff->getCreatedPrimaryKey() !== null) {
$this->createPrimaryKeyQueries = array_merge(
$this->createPrimaryKeyQueries,
$this->platform->getCreatePrimaryKeySQLQueries(
$tableDiff->getCreatedPrimaryKey(),
$tableDiff->getNewAsset()->getName()
)
);
}
if ($tableDiff->getDroppedPrimaryKey() !== null) {
$this->dropPrimaryKeyQueries = array_merge(
$this->dropPrimaryKeyQueries,
$this->platform->getDropPrimaryKeySQLQueries(
$tableDiff->getDroppedPrimaryKey(),
$tableDiff->getNewAsset()->getName()
)
);
}
} | php | private function collectPrimaryKeys(TableDiff $tableDiff)
{
if ($tableDiff->getCreatedPrimaryKey() !== null) {
$this->createPrimaryKeyQueries = array_merge(
$this->createPrimaryKeyQueries,
$this->platform->getCreatePrimaryKeySQLQueries(
$tableDiff->getCreatedPrimaryKey(),
$tableDiff->getNewAsset()->getName()
)
);
}
if ($tableDiff->getDroppedPrimaryKey() !== null) {
$this->dropPrimaryKeyQueries = array_merge(
$this->dropPrimaryKeyQueries,
$this->platform->getDropPrimaryKeySQLQueries(
$tableDiff->getDroppedPrimaryKey(),
$tableDiff->getNewAsset()->getName()
)
);
}
} | [
"private",
"function",
"collectPrimaryKeys",
"(",
"TableDiff",
"$",
"tableDiff",
")",
"{",
"if",
"(",
"$",
"tableDiff",
"->",
"getCreatedPrimaryKey",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"createPrimaryKeyQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"createPrimaryKeyQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getCreatePrimaryKeySQLQueries",
"(",
"$",
"tableDiff",
"->",
"getCreatedPrimaryKey",
"(",
")",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"tableDiff",
"->",
"getDroppedPrimaryKey",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"dropPrimaryKeyQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dropPrimaryKeyQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getDropPrimaryKeySQLQueries",
"(",
"$",
"tableDiff",
"->",
"getDroppedPrimaryKey",
"(",
")",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}"
] | Collect queries about primary keys to alter a table.
@param \Fridge\DBAL\Schema\Diff\TableDiff $tableDiff The table difference. | [
"Collect",
"queries",
"about",
"primary",
"keys",
"to",
"alter",
"a",
"table",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php#L326-L347 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php | AlterTableSQLCollector.collectForeignKeys | private function collectForeignKeys(TableDiff $tableDiff)
{
foreach ($tableDiff->getCreatedForeignKeys() as $foreignKey) {
$this->createForeignKeyQueries = array_merge(
$this->createForeignKeyQueries,
$this->platform->getCreateForeignKeySQLQueries($foreignKey, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getDroppedForeignKeys() as $foreignKey) {
$this->dropForeignKeyQueries = array_merge(
$this->dropForeignKeyQueries,
$this->platform->getDropForeignKeySQLQueries($foreignKey, $tableDiff->getNewAsset()->getName())
);
}
} | php | private function collectForeignKeys(TableDiff $tableDiff)
{
foreach ($tableDiff->getCreatedForeignKeys() as $foreignKey) {
$this->createForeignKeyQueries = array_merge(
$this->createForeignKeyQueries,
$this->platform->getCreateForeignKeySQLQueries($foreignKey, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getDroppedForeignKeys() as $foreignKey) {
$this->dropForeignKeyQueries = array_merge(
$this->dropForeignKeyQueries,
$this->platform->getDropForeignKeySQLQueries($foreignKey, $tableDiff->getNewAsset()->getName())
);
}
} | [
"private",
"function",
"collectForeignKeys",
"(",
"TableDiff",
"$",
"tableDiff",
")",
"{",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getCreatedForeignKeys",
"(",
")",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"this",
"->",
"createForeignKeyQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"createForeignKeyQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getCreateForeignKeySQLQueries",
"(",
"$",
"foreignKey",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getDroppedForeignKeys",
"(",
")",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"this",
"->",
"dropForeignKeyQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dropForeignKeyQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getDropForeignKeySQLQueries",
"(",
"$",
"foreignKey",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}"
] | Collects queries about foreign keys to alter a table.
@param \Fridge\DBAL\Schema\Diff\TableDiff $tableDiff The table difference. | [
"Collects",
"queries",
"about",
"foreign",
"keys",
"to",
"alter",
"a",
"table",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php#L354-L369 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php | AlterTableSQLCollector.collectIndexes | private function collectIndexes(TableDiff $tableDiff)
{
foreach ($tableDiff->getCreatedIndexes() as $index) {
$this->createIndexQueries = array_merge(
$this->createIndexQueries,
$this->platform->getCreateIndexSQLQueries($index, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getDroppedIndexes() as $index) {
$this->dropIndexQueries = array_merge(
$this->dropIndexQueries,
$this->platform->getDropIndexSQLQueries($index, $tableDiff->getNewAsset()->getName())
);
}
} | php | private function collectIndexes(TableDiff $tableDiff)
{
foreach ($tableDiff->getCreatedIndexes() as $index) {
$this->createIndexQueries = array_merge(
$this->createIndexQueries,
$this->platform->getCreateIndexSQLQueries($index, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getDroppedIndexes() as $index) {
$this->dropIndexQueries = array_merge(
$this->dropIndexQueries,
$this->platform->getDropIndexSQLQueries($index, $tableDiff->getNewAsset()->getName())
);
}
} | [
"private",
"function",
"collectIndexes",
"(",
"TableDiff",
"$",
"tableDiff",
")",
"{",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getCreatedIndexes",
"(",
")",
"as",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"createIndexQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"createIndexQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getCreateIndexSQLQueries",
"(",
"$",
"index",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getDroppedIndexes",
"(",
")",
"as",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"dropIndexQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dropIndexQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getDropIndexSQLQueries",
"(",
"$",
"index",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}"
] | Collects queries about indexes to alter a table.
@param \Fridge\DBAL\Schema\Diff\TableDiff $tableDiff The table difference. | [
"Collects",
"queries",
"about",
"indexes",
"to",
"alter",
"a",
"table",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php#L376-L391 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php | AlterTableSQLCollector.collectChecks | private function collectChecks(TableDiff $tableDiff)
{
foreach ($tableDiff->getCreatedChecks() as $check) {
$this->createCheckQueries = array_merge(
$this->createCheckQueries,
$this->platform->getCreateCheckSQLQueries($check, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getDroppedChecks() as $check) {
$this->dropCheckQueries = array_merge(
$this->dropCheckQueries,
$this->platform->getDropCheckSQLQueries($check, $tableDiff->getNewAsset()->getName())
);
}
} | php | private function collectChecks(TableDiff $tableDiff)
{
foreach ($tableDiff->getCreatedChecks() as $check) {
$this->createCheckQueries = array_merge(
$this->createCheckQueries,
$this->platform->getCreateCheckSQLQueries($check, $tableDiff->getNewAsset()->getName())
);
}
foreach ($tableDiff->getDroppedChecks() as $check) {
$this->dropCheckQueries = array_merge(
$this->dropCheckQueries,
$this->platform->getDropCheckSQLQueries($check, $tableDiff->getNewAsset()->getName())
);
}
} | [
"private",
"function",
"collectChecks",
"(",
"TableDiff",
"$",
"tableDiff",
")",
"{",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getCreatedChecks",
"(",
")",
"as",
"$",
"check",
")",
"{",
"$",
"this",
"->",
"createCheckQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"createCheckQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getCreateCheckSQLQueries",
"(",
"$",
"check",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"tableDiff",
"->",
"getDroppedChecks",
"(",
")",
"as",
"$",
"check",
")",
"{",
"$",
"this",
"->",
"dropCheckQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dropCheckQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getDropCheckSQLQueries",
"(",
"$",
"check",
",",
"$",
"tableDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}"
] | Collects queries about checks to alter a table.
@param \Fridge\DBAL\Schema\Diff\TableDiff $tableDiff The table difference. | [
"Collects",
"queries",
"about",
"checks",
"to",
"alter",
"a",
"table",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterTableSQLCollector.php#L398-L413 | train |
SlaxWeb/Hooks | src/Factory.php | Factory.init | public static function init(Config $config): Container
{
$logger = Logger::init($config);
return new Container($logger);
} | php | public static function init(Config $config): Container
{
$logger = Logger::init($config);
return new Container($logger);
} | [
"public",
"static",
"function",
"init",
"(",
"Config",
"$",
"config",
")",
":",
"Container",
"{",
"$",
"logger",
"=",
"Logger",
"::",
"init",
"(",
"$",
"config",
")",
";",
"return",
"new",
"Container",
"(",
"$",
"logger",
")",
";",
"}"
] | Initiate Hooks Container
Init the logger through its own factory and create an object of the Hooks
container, and return it to the caller. For this the configuration
component is required, so the logger can be instantiated.
@param \SlaxWeb\Config\Container $config Configuration component
@return \SlaxWeb\Hooks\Container | [
"Initiate",
"Hooks",
"Container"
] | 678f4d5425c27e0dd2a61b68d59bfb2793955b91 | https://github.com/SlaxWeb/Hooks/blob/678f4d5425c27e0dd2a61b68d59bfb2793955b91/src/Factory.php#L32-L36 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Event/RequestEvents.php | RequestEvents.emitBefore | public static function emitBefore(TransactionInterface $transaction)
{
$request = $transaction->getRequest();
try {
$request->getEmitter()->emit(
'before',
new BeforeEvent($transaction)
);
} catch (RequestException $e) {
// When a RequestException has been emitted through emitError, the
// exception is marked as "emitted". This means that the exception
// had a chance to be rescued but was not. In this case, this method
// must not emit the error again, but rather throw the exception.
// This prevents RequestExceptions encountered during the before
// event from being emitted to listeners twice.
if ($e->emittedError()) {
throw $e;
}
self::emitError($transaction, $e);
} catch (\Exception $e) {
self::emitError($transaction, $e);
}
} | php | public static function emitBefore(TransactionInterface $transaction)
{
$request = $transaction->getRequest();
try {
$request->getEmitter()->emit(
'before',
new BeforeEvent($transaction)
);
} catch (RequestException $e) {
// When a RequestException has been emitted through emitError, the
// exception is marked as "emitted". This means that the exception
// had a chance to be rescued but was not. In this case, this method
// must not emit the error again, but rather throw the exception.
// This prevents RequestExceptions encountered during the before
// event from being emitted to listeners twice.
if ($e->emittedError()) {
throw $e;
}
self::emitError($transaction, $e);
} catch (\Exception $e) {
self::emitError($transaction, $e);
}
} | [
"public",
"static",
"function",
"emitBefore",
"(",
"TransactionInterface",
"$",
"transaction",
")",
"{",
"$",
"request",
"=",
"$",
"transaction",
"->",
"getRequest",
"(",
")",
";",
"try",
"{",
"$",
"request",
"->",
"getEmitter",
"(",
")",
"->",
"emit",
"(",
"'before'",
",",
"new",
"BeforeEvent",
"(",
"$",
"transaction",
")",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"e",
")",
"{",
"// When a RequestException has been emitted through emitError, the",
"// exception is marked as \"emitted\". This means that the exception",
"// had a chance to be rescued but was not. In this case, this method",
"// must not emit the error again, but rather throw the exception.",
"// This prevents RequestExceptions encountered during the before",
"// event from being emitted to listeners twice.",
"if",
"(",
"$",
"e",
"->",
"emittedError",
"(",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"self",
"::",
"emitError",
"(",
"$",
"transaction",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"self",
"::",
"emitError",
"(",
"$",
"transaction",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Emits the before send event for a request and emits an error
event if an error is encountered during the before send.
@param TransactionInterface $transaction
@throws RequestException | [
"Emits",
"the",
"before",
"send",
"event",
"for",
"a",
"request",
"and",
"emits",
"an",
"error",
"event",
"if",
"an",
"error",
"is",
"encountered",
"during",
"the",
"before",
"send",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Event/RequestEvents.php#L33-L55 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Event/RequestEvents.php | RequestEvents.emitComplete | public static function emitComplete(
TransactionInterface $transaction,
array $stats = []
) {
$request = $transaction->getRequest();
$transaction->getResponse()->setEffectiveUrl($request->getUrl());
try {
$request->getEmitter()->emit(
'complete',
new CompleteEvent($transaction, $stats)
);
} catch (RequestException $e) {
self::emitError($transaction, $e, $stats);
}
} | php | public static function emitComplete(
TransactionInterface $transaction,
array $stats = []
) {
$request = $transaction->getRequest();
$transaction->getResponse()->setEffectiveUrl($request->getUrl());
try {
$request->getEmitter()->emit(
'complete',
new CompleteEvent($transaction, $stats)
);
} catch (RequestException $e) {
self::emitError($transaction, $e, $stats);
}
} | [
"public",
"static",
"function",
"emitComplete",
"(",
"TransactionInterface",
"$",
"transaction",
",",
"array",
"$",
"stats",
"=",
"[",
"]",
")",
"{",
"$",
"request",
"=",
"$",
"transaction",
"->",
"getRequest",
"(",
")",
";",
"$",
"transaction",
"->",
"getResponse",
"(",
")",
"->",
"setEffectiveUrl",
"(",
"$",
"request",
"->",
"getUrl",
"(",
")",
")",
";",
"try",
"{",
"$",
"request",
"->",
"getEmitter",
"(",
")",
"->",
"emit",
"(",
"'complete'",
",",
"new",
"CompleteEvent",
"(",
"$",
"transaction",
",",
"$",
"stats",
")",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"e",
")",
"{",
"self",
"::",
"emitError",
"(",
"$",
"transaction",
",",
"$",
"e",
",",
"$",
"stats",
")",
";",
"}",
"}"
] | Emits the complete event for a request and emits an error
event if an error is encountered during the after send.
@param TransactionInterface $transaction Transaction to emit for
@param array $stats Transfer stats
@throws RequestException | [
"Emits",
"the",
"complete",
"event",
"for",
"a",
"request",
"and",
"emits",
"an",
"error",
"event",
"if",
"an",
"error",
"is",
"encountered",
"during",
"the",
"after",
"send",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Event/RequestEvents.php#L66-L80 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Event/RequestEvents.php | RequestEvents.emitError | public static function emitError(
TransactionInterface $transaction,
\Exception $e,
array $stats = []
) {
$request = $transaction->getRequest();
// Convert non-request exception to a wrapped exception
if (!($e instanceof RequestException)) {
$e = new RequestException($e->getMessage(), $request, null, $e);
}
// Mark the exception as having been emitted for an error event. This
// works in tandem with the emitBefore method to prevent the error
// event from being triggered twice for the same exception.
$e->emittedError(true);
// Dispatch an event and allow interception
if (!$request->getEmitter()->emit(
'error',
new ErrorEvent($transaction, $e, $stats)
)->isPropagationStopped()) {
throw $e;
}
} | php | public static function emitError(
TransactionInterface $transaction,
\Exception $e,
array $stats = []
) {
$request = $transaction->getRequest();
// Convert non-request exception to a wrapped exception
if (!($e instanceof RequestException)) {
$e = new RequestException($e->getMessage(), $request, null, $e);
}
// Mark the exception as having been emitted for an error event. This
// works in tandem with the emitBefore method to prevent the error
// event from being triggered twice for the same exception.
$e->emittedError(true);
// Dispatch an event and allow interception
if (!$request->getEmitter()->emit(
'error',
new ErrorEvent($transaction, $e, $stats)
)->isPropagationStopped()) {
throw $e;
}
} | [
"public",
"static",
"function",
"emitError",
"(",
"TransactionInterface",
"$",
"transaction",
",",
"\\",
"Exception",
"$",
"e",
",",
"array",
"$",
"stats",
"=",
"[",
"]",
")",
"{",
"$",
"request",
"=",
"$",
"transaction",
"->",
"getRequest",
"(",
")",
";",
"// Convert non-request exception to a wrapped exception",
"if",
"(",
"!",
"(",
"$",
"e",
"instanceof",
"RequestException",
")",
")",
"{",
"$",
"e",
"=",
"new",
"RequestException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"request",
",",
"null",
",",
"$",
"e",
")",
";",
"}",
"// Mark the exception as having been emitted for an error event. This",
"// works in tandem with the emitBefore method to prevent the error",
"// event from being triggered twice for the same exception.",
"$",
"e",
"->",
"emittedError",
"(",
"true",
")",
";",
"// Dispatch an event and allow interception",
"if",
"(",
"!",
"$",
"request",
"->",
"getEmitter",
"(",
")",
"->",
"emit",
"(",
"'error'",
",",
"new",
"ErrorEvent",
"(",
"$",
"transaction",
",",
"$",
"e",
",",
"$",
"stats",
")",
")",
"->",
"isPropagationStopped",
"(",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}"
] | Emits an error event for a request and accounts for the propagation
of an error event being stopped to prevent the exception from being
thrown.
@param TransactionInterface $transaction
@param \Exception $e
@param array $stats
@throws \GuzzleHttp\Exception\RequestException | [
"Emits",
"an",
"error",
"event",
"for",
"a",
"request",
"and",
"accounts",
"for",
"the",
"propagation",
"of",
"an",
"error",
"event",
"being",
"stopped",
"to",
"prevent",
"the",
"exception",
"from",
"being",
"thrown",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Event/RequestEvents.php#L106-L130 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Event/RequestEvents.php | RequestEvents.convertEventArray | public static function convertEventArray(
array $options,
array $events,
$handler
) {
foreach ($events as $name) {
if (!isset($options[$name])) {
$options[$name] = [$handler];
} elseif (is_callable($options[$name])) {
$options[$name] = [$options[$name], $handler];
} elseif (is_array($options[$name])) {
if (isset($options[$name]['fn'])) {
$options[$name] = [$options[$name], $handler];
} else {
$options[$name][] = $handler;
}
} else {
throw new \InvalidArgumentException('Invalid event format');
}
}
return $options;
} | php | public static function convertEventArray(
array $options,
array $events,
$handler
) {
foreach ($events as $name) {
if (!isset($options[$name])) {
$options[$name] = [$handler];
} elseif (is_callable($options[$name])) {
$options[$name] = [$options[$name], $handler];
} elseif (is_array($options[$name])) {
if (isset($options[$name]['fn'])) {
$options[$name] = [$options[$name], $handler];
} else {
$options[$name][] = $handler;
}
} else {
throw new \InvalidArgumentException('Invalid event format');
}
}
return $options;
} | [
"public",
"static",
"function",
"convertEventArray",
"(",
"array",
"$",
"options",
",",
"array",
"$",
"events",
",",
"$",
"handler",
")",
"{",
"foreach",
"(",
"$",
"events",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"options",
"[",
"$",
"name",
"]",
"=",
"[",
"$",
"handler",
"]",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"options",
"[",
"$",
"name",
"]",
"=",
"[",
"$",
"options",
"[",
"$",
"name",
"]",
",",
"$",
"handler",
"]",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
"[",
"'fn'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"$",
"name",
"]",
"=",
"[",
"$",
"options",
"[",
"$",
"name",
"]",
",",
"$",
"handler",
"]",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"handler",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid event format'",
")",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] | Converts an array of event options into a formatted array of valid event
configuration.
@param array $options Event array to convert
@param array $events Event names to convert in the options array.
@param mixed $handler Event handler to utilize
@return array
@throws \InvalidArgumentException if the event config is invalid
@internal | [
"Converts",
"an",
"array",
"of",
"event",
"options",
"into",
"a",
"formatted",
"array",
"of",
"valid",
"event",
"configuration",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Event/RequestEvents.php#L144-L166 | train |
Raphhh/puppy-application | src/Controller/FrontController.php | FrontController.addController | public function addController($uriPattern, callable $controller, $method='', $contentType='')
{
$routeBuilder = new RouteBuilder();
$routeBuilder
->addUriPattern($uriPattern)
->addController($controller, $this->getAppController())
->addMethod($method)
->addContentType($contentType);
$route = $routeBuilder->getRoute();
$this->getRouter()->addRoute($route);
return $route;
} | php | public function addController($uriPattern, callable $controller, $method='', $contentType='')
{
$routeBuilder = new RouteBuilder();
$routeBuilder
->addUriPattern($uriPattern)
->addController($controller, $this->getAppController())
->addMethod($method)
->addContentType($contentType);
$route = $routeBuilder->getRoute();
$this->getRouter()->addRoute($route);
return $route;
} | [
"public",
"function",
"addController",
"(",
"$",
"uriPattern",
",",
"callable",
"$",
"controller",
",",
"$",
"method",
"=",
"''",
",",
"$",
"contentType",
"=",
"''",
")",
"{",
"$",
"routeBuilder",
"=",
"new",
"RouteBuilder",
"(",
")",
";",
"$",
"routeBuilder",
"->",
"addUriPattern",
"(",
"$",
"uriPattern",
")",
"->",
"addController",
"(",
"$",
"controller",
",",
"$",
"this",
"->",
"getAppController",
"(",
")",
")",
"->",
"addMethod",
"(",
"$",
"method",
")",
"->",
"addContentType",
"(",
"$",
"contentType",
")",
";",
"$",
"route",
"=",
"$",
"routeBuilder",
"->",
"getRoute",
"(",
")",
";",
"$",
"this",
"->",
"getRouter",
"(",
")",
"->",
"addRoute",
"(",
"$",
"route",
")",
";",
"return",
"$",
"route",
";",
"}"
] | Adds a controller to the list of observed controllers.
@param string $uriPattern
@param callable $controller
@param string $method
@param string $contentType
@return \Puppy\Route\Route | [
"Adds",
"a",
"controller",
"to",
"the",
"list",
"of",
"observed",
"controllers",
"."
] | 9291543cd28e19a2986abd7fb146898ca5f5f5da | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Controller/FrontController.php#L44-L56 | train |
Raphhh/puppy-application | src/Controller/FrontController.php | FrontController.call | public function call(Request $request)
{
if($request !== $this->getRequestStack()->getCurrentRequest()){
$this->getRequestStack()->push($request);
}
if(!$request->getRequestFormat(null) && $request->getAcceptableContentTypes()){
$request->setRequestFormat($request->getFormat($request->getAcceptableContentTypes()[0]));
}
$response = $this->getRouter()
->find($request)
->call($this->getServices());
if($response instanceof Response){
return $response;
}
return new Response($response);
} | php | public function call(Request $request)
{
if($request !== $this->getRequestStack()->getCurrentRequest()){
$this->getRequestStack()->push($request);
}
if(!$request->getRequestFormat(null) && $request->getAcceptableContentTypes()){
$request->setRequestFormat($request->getFormat($request->getAcceptableContentTypes()[0]));
}
$response = $this->getRouter()
->find($request)
->call($this->getServices());
if($response instanceof Response){
return $response;
}
return new Response($response);
} | [
"public",
"function",
"call",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"!==",
"$",
"this",
"->",
"getRequestStack",
"(",
")",
"->",
"getCurrentRequest",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getRequestStack",
"(",
")",
"->",
"push",
"(",
"$",
"request",
")",
";",
"}",
"if",
"(",
"!",
"$",
"request",
"->",
"getRequestFormat",
"(",
"null",
")",
"&&",
"$",
"request",
"->",
"getAcceptableContentTypes",
"(",
")",
")",
"{",
"$",
"request",
"->",
"setRequestFormat",
"(",
"$",
"request",
"->",
"getFormat",
"(",
"$",
"request",
"->",
"getAcceptableContentTypes",
"(",
")",
"[",
"0",
"]",
")",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getRouter",
"(",
")",
"->",
"find",
"(",
"$",
"request",
")",
"->",
"call",
"(",
"$",
"this",
"->",
"getServices",
"(",
")",
")",
";",
"if",
"(",
"$",
"response",
"instanceof",
"Response",
")",
"{",
"return",
"$",
"response",
";",
"}",
"return",
"new",
"Response",
"(",
"$",
"response",
")",
";",
"}"
] | Calls the controller matched with the request uri.
@param Request $request
@return Response | [
"Calls",
"the",
"controller",
"matched",
"with",
"the",
"request",
"uri",
"."
] | 9291543cd28e19a2986abd7fb146898ca5f5f5da | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Controller/FrontController.php#L64-L82 | train |
ValkSystems/bootbuilder | src/bootbuilder/Controls/TextArea.php | TextArea.renderBasic | public function renderBasic() {
$html = "<textarea rows='$this->rows'";
$html .= " " . $this->getCompiledAttributes("form-control");
$html .= ">";
$html .= $this->value;
$html .= "</textarea>";
return $html;
} | php | public function renderBasic() {
$html = "<textarea rows='$this->rows'";
$html .= " " . $this->getCompiledAttributes("form-control");
$html .= ">";
$html .= $this->value;
$html .= "</textarea>";
return $html;
} | [
"public",
"function",
"renderBasic",
"(",
")",
"{",
"$",
"html",
"=",
"\"<textarea rows='$this->rows'\"",
";",
"$",
"html",
".=",
"\" \"",
".",
"$",
"this",
"->",
"getCompiledAttributes",
"(",
"\"form-control\"",
")",
";",
"$",
"html",
".=",
"\">\"",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"value",
";",
"$",
"html",
".=",
"\"</textarea>\"",
";",
"return",
"$",
"html",
";",
"}"
] | Render basics of textarea | [
"Render",
"basics",
"of",
"textarea"
] | 7601a403f42eba47ce4cf02a3c852d5196b1d860 | https://github.com/ValkSystems/bootbuilder/blob/7601a403f42eba47ce4cf02a3c852d5196b1d860/src/bootbuilder/Controls/TextArea.php#L26-L33 | train |
SlaxWeb/Router | src/Response.php | Response.addContent | public function addContent(string $content): \Symfony\Component\HttpFoundation\Response
{
return $this->setContent($this->getContent() . $content);
} | php | public function addContent(string $content): \Symfony\Component\HttpFoundation\Response
{
return $this->setContent($this->getContent() . $content);
} | [
"public",
"function",
"addContent",
"(",
"string",
"$",
"content",
")",
":",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"HttpFoundation",
"\\",
"Response",
"{",
"return",
"$",
"this",
"->",
"setContent",
"(",
"$",
"this",
"->",
"getContent",
"(",
")",
".",
"$",
"content",
")",
";",
"}"
] | Add To Content
Add retrieved input to the end of already existing content in the
Response object.
@param string $content Content to be added.
@return \Symfony\Component\HttpFoundation\Response | [
"Add",
"To",
"Content"
] | b4a25655710638c71787a8498d267a663ef2e819 | https://github.com/SlaxWeb/Router/blob/b4a25655710638c71787a8498d267a663ef2e819/src/Response.php#L39-L42 | train |
nicolasdewez/webhome-common | Client/AbstractClient.php | AbstractClient.deserialize | protected function deserialize(ResponseInterface $response, $type, $format = 'json')
{
try {
return $this->serializer->deserialize(
(string) $response->getBody(),
$type,
$format
);
} catch (\Exception $exception) {
$this->logger->error(
'[WebServiceClient] Deserialization problem on webservice call.',
array(
'response' => (string) $response->getBody(),
'exception' => $exception,
)
);
throw $exception;
}
} | php | protected function deserialize(ResponseInterface $response, $type, $format = 'json')
{
try {
return $this->serializer->deserialize(
(string) $response->getBody(),
$type,
$format
);
} catch (\Exception $exception) {
$this->logger->error(
'[WebServiceClient] Deserialization problem on webservice call.',
array(
'response' => (string) $response->getBody(),
'exception' => $exception,
)
);
throw $exception;
}
} | [
"protected",
"function",
"deserialize",
"(",
"ResponseInterface",
"$",
"response",
",",
"$",
"type",
",",
"$",
"format",
"=",
"'json'",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"serializer",
"->",
"deserialize",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"$",
"type",
",",
"$",
"format",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"'[WebServiceClient] Deserialization problem on webservice call.'",
",",
"array",
"(",
"'response'",
"=>",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"'exception'",
"=>",
"$",
"exception",
",",
")",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"}"
] | Deserializes request content.
@param ResponseInterface $response
@param string $type
@param string $format
@return mixed
@throws \Exception | [
"Deserializes",
"request",
"content",
"."
] | a9f6f83fa929ebd0510818c388cfb1ed44b87205 | https://github.com/nicolasdewez/webhome-common/blob/a9f6f83fa929ebd0510818c388cfb1ed44b87205/Client/AbstractClient.php#L95-L114 | train |
Subscribo/psr-http-message-tools | src/Factories/RequestFactory.php | RequestFactory.make | public static function make($uri, $data = null, array $queryParameters = [], array $headers = [], $method = null, $contentType = null, $contentCharset = null)
{
if (is_null($method)) {
$method = is_null($data) ? static::METHOD_GET : static::METHOD_POST;
}
$uri = UriFactory::make($uri, $queryParameters);
$stream = new Stream('php://memory', 'r+');
$request = new Request($uri, $method, $stream, $headers);
$contentType = $contentType ?: $request->getHeaderLine('Content-Type');
$contentType = $contentType ?: static::DEFAULT_CONTENT_TYPE;
$contentTypeParts = explode(';', $contentType);
$mimeType = trim(array_shift($contentTypeParts));
if (is_null($data)) {
$body = null;
} elseif (is_string($data)) {
$body = $data;
} elseif (is_array($data)) {
$body = static::format($data, $mimeType);
} else {
throw new InvalidArgumentException('Data should be either null, string or array');
}
if ( ! is_null($body)) {
$contentCharset = $contentCharset ?: static::extractCharset($contentTypeParts);
$contentCharset = $contentCharset ?: static::DEFAULT_CONTENT_CHARSET;
$contentTypeReassembled = $mimeType.'; charset='.$contentCharset;
$request = $request->withHeader('Content-Type', $contentTypeReassembled);
$request->getBody()->write($body);
}
return $request;
} | php | public static function make($uri, $data = null, array $queryParameters = [], array $headers = [], $method = null, $contentType = null, $contentCharset = null)
{
if (is_null($method)) {
$method = is_null($data) ? static::METHOD_GET : static::METHOD_POST;
}
$uri = UriFactory::make($uri, $queryParameters);
$stream = new Stream('php://memory', 'r+');
$request = new Request($uri, $method, $stream, $headers);
$contentType = $contentType ?: $request->getHeaderLine('Content-Type');
$contentType = $contentType ?: static::DEFAULT_CONTENT_TYPE;
$contentTypeParts = explode(';', $contentType);
$mimeType = trim(array_shift($contentTypeParts));
if (is_null($data)) {
$body = null;
} elseif (is_string($data)) {
$body = $data;
} elseif (is_array($data)) {
$body = static::format($data, $mimeType);
} else {
throw new InvalidArgumentException('Data should be either null, string or array');
}
if ( ! is_null($body)) {
$contentCharset = $contentCharset ?: static::extractCharset($contentTypeParts);
$contentCharset = $contentCharset ?: static::DEFAULT_CONTENT_CHARSET;
$contentTypeReassembled = $mimeType.'; charset='.$contentCharset;
$request = $request->withHeader('Content-Type', $contentTypeReassembled);
$request->getBody()->write($body);
}
return $request;
} | [
"public",
"static",
"function",
"make",
"(",
"$",
"uri",
",",
"$",
"data",
"=",
"null",
",",
"array",
"$",
"queryParameters",
"=",
"[",
"]",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"method",
"=",
"null",
",",
"$",
"contentType",
"=",
"null",
",",
"$",
"contentCharset",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"method",
")",
")",
"{",
"$",
"method",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"static",
"::",
"METHOD_GET",
":",
"static",
"::",
"METHOD_POST",
";",
"}",
"$",
"uri",
"=",
"UriFactory",
"::",
"make",
"(",
"$",
"uri",
",",
"$",
"queryParameters",
")",
";",
"$",
"stream",
"=",
"new",
"Stream",
"(",
"'php://memory'",
",",
"'r+'",
")",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"uri",
",",
"$",
"method",
",",
"$",
"stream",
",",
"$",
"headers",
")",
";",
"$",
"contentType",
"=",
"$",
"contentType",
"?",
":",
"$",
"request",
"->",
"getHeaderLine",
"(",
"'Content-Type'",
")",
";",
"$",
"contentType",
"=",
"$",
"contentType",
"?",
":",
"static",
"::",
"DEFAULT_CONTENT_TYPE",
";",
"$",
"contentTypeParts",
"=",
"explode",
"(",
"';'",
",",
"$",
"contentType",
")",
";",
"$",
"mimeType",
"=",
"trim",
"(",
"array_shift",
"(",
"$",
"contentTypeParts",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"$",
"body",
"=",
"null",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"$",
"body",
"=",
"$",
"data",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"body",
"=",
"static",
"::",
"format",
"(",
"$",
"data",
",",
"$",
"mimeType",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Data should be either null, string or array'",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"body",
")",
")",
"{",
"$",
"contentCharset",
"=",
"$",
"contentCharset",
"?",
":",
"static",
"::",
"extractCharset",
"(",
"$",
"contentTypeParts",
")",
";",
"$",
"contentCharset",
"=",
"$",
"contentCharset",
"?",
":",
"static",
"::",
"DEFAULT_CONTENT_CHARSET",
";",
"$",
"contentTypeReassembled",
"=",
"$",
"mimeType",
".",
"'; charset='",
".",
"$",
"contentCharset",
";",
"$",
"request",
"=",
"$",
"request",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"$",
"contentTypeReassembled",
")",
";",
"$",
"request",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"$",
"body",
")",
";",
"}",
"return",
"$",
"request",
";",
"}"
] | Makes PSR-7 compliant Request object from provided parameters
@param UriInterface|string $uri
@param null|string|array $data
@param array $queryParameters
@param array $headers
@param null|string $method
@param null|string $contentType
@param null|string $contentCharset
@return RequestInterface
@throws InvalidArgumentException | [
"Makes",
"PSR",
"-",
"7",
"compliant",
"Request",
"object",
"from",
"provided",
"parameters"
] | b1dfa0b1dd646f353634b5c9603fd6c75a7b73bd | https://github.com/Subscribo/psr-http-message-tools/blob/b1dfa0b1dd646f353634b5c9603fd6c75a7b73bd/src/Factories/RequestFactory.php#L40-L71 | train |
Subscribo/psr-http-message-tools | src/Factories/RequestFactory.php | RequestFactory.extractCharset | private static function extractCharset(array $contentTypeParts)
{
foreach ($contentTypeParts as $part) {
$elements = explode('=', $part);
$key = trim(array_shift($elements));
if (strtolower($key) === 'charset') {
$value = trim(reset($elements));
return $value ?: null;
}
}
return null;
} | php | private static function extractCharset(array $contentTypeParts)
{
foreach ($contentTypeParts as $part) {
$elements = explode('=', $part);
$key = trim(array_shift($elements));
if (strtolower($key) === 'charset') {
$value = trim(reset($elements));
return $value ?: null;
}
}
return null;
} | [
"private",
"static",
"function",
"extractCharset",
"(",
"array",
"$",
"contentTypeParts",
")",
"{",
"foreach",
"(",
"$",
"contentTypeParts",
"as",
"$",
"part",
")",
"{",
"$",
"elements",
"=",
"explode",
"(",
"'='",
",",
"$",
"part",
")",
";",
"$",
"key",
"=",
"trim",
"(",
"array_shift",
"(",
"$",
"elements",
")",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"key",
")",
"===",
"'charset'",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"reset",
"(",
"$",
"elements",
")",
")",
";",
"return",
"$",
"value",
"?",
":",
"null",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Tries to extract charset from pre-parsed part of Content-Type value
@param array $contentTypeParts
@return null|string | [
"Tries",
"to",
"extract",
"charset",
"from",
"pre",
"-",
"parsed",
"part",
"of",
"Content",
"-",
"Type",
"value"
] | b1dfa0b1dd646f353634b5c9603fd6c75a7b73bd | https://github.com/Subscribo/psr-http-message-tools/blob/b1dfa0b1dd646f353634b5c9603fd6c75a7b73bd/src/Factories/RequestFactory.php#L100-L111 | train |
gmazzap/HooksMock | src/HooksMock.php | HooksMock.hasAction | public static function hasAction($hook = '', callable $callback = null, $priority = null)
{
return static::hasHook('action', $hook, $callback, $priority);
} | php | public static function hasAction($hook = '', callable $callback = null, $priority = null)
{
return static::hasHook('action', $hook, $callback, $priority);
} | [
"public",
"static",
"function",
"hasAction",
"(",
"$",
"hook",
"=",
"''",
",",
"callable",
"$",
"callback",
"=",
"null",
",",
"$",
"priority",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"hasHook",
"(",
"'action'",
",",
"$",
"hook",
",",
"$",
"callback",
",",
"$",
"priority",
")",
";",
"}"
] | Check if an action hook is added. Optionally check a specific callback and and priority.
@param string $hook Hook to check
@param callable $callback Callback to check
@param int $priority Priority to check
@return boolean | [
"Check",
"if",
"an",
"action",
"hook",
"is",
"added",
".",
"Optionally",
"check",
"a",
"specific",
"callback",
"and",
"and",
"priority",
"."
] | b34b5819b96876f23daea9b7fde1b58925da6eab | https://github.com/gmazzap/HooksMock/blob/b34b5819b96876f23daea9b7fde1b58925da6eab/src/HooksMock.php#L159-L162 | train |
gmazzap/HooksMock | src/HooksMock.php | HooksMock.hasFilter | public static function hasFilter($hook = '', callable $callback = null, $priority = null)
{
return static::hasHook('filter', $hook, $callback, $priority);
} | php | public static function hasFilter($hook = '', callable $callback = null, $priority = null)
{
return static::hasHook('filter', $hook, $callback, $priority);
} | [
"public",
"static",
"function",
"hasFilter",
"(",
"$",
"hook",
"=",
"''",
",",
"callable",
"$",
"callback",
"=",
"null",
",",
"$",
"priority",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"hasHook",
"(",
"'filter'",
",",
"$",
"hook",
",",
"$",
"callback",
",",
"$",
"priority",
")",
";",
"}"
] | Check if an filter hook is added. Optionally check a specific callback and and priority.
@param string $hook Hook to check
@param callable $callback Callback to check
@param int $priority Priority to check
@return boolean | [
"Check",
"if",
"an",
"filter",
"hook",
"is",
"added",
".",
"Optionally",
"check",
"a",
"specific",
"callback",
"and",
"and",
"priority",
"."
] | b34b5819b96876f23daea9b7fde1b58925da6eab | https://github.com/gmazzap/HooksMock/blob/b34b5819b96876f23daea9b7fde1b58925da6eab/src/HooksMock.php#L172-L175 | train |
gmazzap/HooksMock | src/HooksMock.php | HooksMock.hasHookFired | public static function hasHookFired($type = 'action', $hook = null)
{
if (! in_array($type, ['action', 'filter'], true)) {
$type = 'action';
}
$target = $type === 'filter' ? 'filters' : 'actions';
if (empty($hook) || ! is_string($hook)) {
$msg = __METHOD__.' needs a valid hook to check.';
throw new InvalidArgumentException($msg);
}
return array_key_exists($hook, static::$hooks_done[$target]);
} | php | public static function hasHookFired($type = 'action', $hook = null)
{
if (! in_array($type, ['action', 'filter'], true)) {
$type = 'action';
}
$target = $type === 'filter' ? 'filters' : 'actions';
if (empty($hook) || ! is_string($hook)) {
$msg = __METHOD__.' needs a valid hook to check.';
throw new InvalidArgumentException($msg);
}
return array_key_exists($hook, static::$hooks_done[$target]);
} | [
"public",
"static",
"function",
"hasHookFired",
"(",
"$",
"type",
"=",
"'action'",
",",
"$",
"hook",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"[",
"'action'",
",",
"'filter'",
"]",
",",
"true",
")",
")",
"{",
"$",
"type",
"=",
"'action'",
";",
"}",
"$",
"target",
"=",
"$",
"type",
"===",
"'filter'",
"?",
"'filters'",
":",
"'actions'",
";",
"if",
"(",
"empty",
"(",
"$",
"hook",
")",
"||",
"!",
"is_string",
"(",
"$",
"hook",
")",
")",
"{",
"$",
"msg",
"=",
"__METHOD__",
".",
"' needs a valid hook to check.'",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"return",
"array_key_exists",
"(",
"$",
"hook",
",",
"static",
"::",
"$",
"hooks_done",
"[",
"$",
"target",
"]",
")",
";",
"}"
] | Check if an hook is was fired.
@param string $type Type of hook, 'action' or 'filter'
@param string $hook Filter hook to check
@return boolean | [
"Check",
"if",
"an",
"hook",
"is",
"was",
"fired",
"."
] | b34b5819b96876f23daea9b7fde1b58925da6eab | https://github.com/gmazzap/HooksMock/blob/b34b5819b96876f23daea9b7fde1b58925da6eab/src/HooksMock.php#L184-L196 | train |
gmazzap/HooksMock | src/HooksMock.php | HooksMock.assertActionAdded | public static function assertActionAdded(
$hook = '',
$callback = null,
$priority = null,
$argsNum = null
) {
static::assertHookAdded('action', $hook, $callback, $priority, $argsNum);
} | php | public static function assertActionAdded(
$hook = '',
$callback = null,
$priority = null,
$argsNum = null
) {
static::assertHookAdded('action', $hook, $callback, $priority, $argsNum);
} | [
"public",
"static",
"function",
"assertActionAdded",
"(",
"$",
"hook",
"=",
"''",
",",
"$",
"callback",
"=",
"null",
",",
"$",
"priority",
"=",
"null",
",",
"$",
"argsNum",
"=",
"null",
")",
"{",
"static",
"::",
"assertHookAdded",
"(",
"'action'",
",",
"$",
"hook",
",",
"$",
"callback",
",",
"$",
"priority",
",",
"$",
"argsNum",
")",
";",
"}"
] | Check if an action is added and throws a exceptions otherwise.
@param string $hook Action hook to check
@param callable $callback Callback to check
@param int $priority Priority to check
@param int $argsNum Number of accepted arguments to check | [
"Check",
"if",
"an",
"action",
"is",
"added",
"and",
"throws",
"a",
"exceptions",
"otherwise",
"."
] | b34b5819b96876f23daea9b7fde1b58925da6eab | https://github.com/gmazzap/HooksMock/blob/b34b5819b96876f23daea9b7fde1b58925da6eab/src/HooksMock.php#L228-L235 | train |
gmazzap/HooksMock | src/HooksMock.php | HooksMock.assertFilterAdded | public static function assertFilterAdded(
$hook = '',
callable $callback = null,
$priority = null,
$numArgs = null
) {
static::assertHookAdded('filter', $hook, $callback, $priority, $numArgs);
} | php | public static function assertFilterAdded(
$hook = '',
callable $callback = null,
$priority = null,
$numArgs = null
) {
static::assertHookAdded('filter', $hook, $callback, $priority, $numArgs);
} | [
"public",
"static",
"function",
"assertFilterAdded",
"(",
"$",
"hook",
"=",
"''",
",",
"callable",
"$",
"callback",
"=",
"null",
",",
"$",
"priority",
"=",
"null",
",",
"$",
"numArgs",
"=",
"null",
")",
"{",
"static",
"::",
"assertHookAdded",
"(",
"'filter'",
",",
"$",
"hook",
",",
"$",
"callback",
",",
"$",
"priority",
",",
"$",
"numArgs",
")",
";",
"}"
] | Check if a filter is added and throws an exceptions otherwise.
@param string $hook Filter hook to check
@param callable $callback Callback to check
@param int $priority Priority to check
@param int $numArgs Number of accepted arguments to check | [
"Check",
"if",
"a",
"filter",
"is",
"added",
"and",
"throws",
"an",
"exceptions",
"otherwise",
"."
] | b34b5819b96876f23daea9b7fde1b58925da6eab | https://github.com/gmazzap/HooksMock/blob/b34b5819b96876f23daea9b7fde1b58925da6eab/src/HooksMock.php#L245-L252 | train |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImage.php | ResponsiveImage.getSrcsetAttributeValue | public function getSrcsetAttributeValue()
{
$srcset = [];
foreach ($this->versions as $id) {
$srcset[] = sprintf('%s %sw', $id->getUrl(), $id->getWidth());
}
return join(', ', $srcset);
} | php | public function getSrcsetAttributeValue()
{
$srcset = [];
foreach ($this->versions as $id) {
$srcset[] = sprintf('%s %sw', $id->getUrl(), $id->getWidth());
}
return join(', ', $srcset);
} | [
"public",
"function",
"getSrcsetAttributeValue",
"(",
")",
"{",
"$",
"srcset",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"versions",
"as",
"$",
"id",
")",
"{",
"$",
"srcset",
"[",
"]",
"=",
"sprintf",
"(",
"'%s %sw'",
",",
"$",
"id",
"->",
"getUrl",
"(",
")",
",",
"$",
"id",
"->",
"getWidth",
"(",
")",
")",
";",
"}",
"return",
"join",
"(",
"', '",
",",
"$",
"srcset",
")",
";",
"}"
] | Get the value for the "srcset" HTML attribute
@return string | [
"Get",
"the",
"value",
"for",
"the",
"srcset",
"HTML",
"attribute"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImage.php#L87-L94 | train |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImage.php | ResponsiveImage.getDefaultImageInfo | public function getDefaultImageInfo()
{
if (isset($this->versions[$this->class->getDefaultWidth()])) {
return $this->versions[$this->class->getDefaultWidth()];
} else {
// if the image is smaller than the class default width,
// $this->versions[$this->class->getDefaultWidth()] will not be defined.
//
// return the first available image version instead
return reset($this->versions);
}
} | php | public function getDefaultImageInfo()
{
if (isset($this->versions[$this->class->getDefaultWidth()])) {
return $this->versions[$this->class->getDefaultWidth()];
} else {
// if the image is smaller than the class default width,
// $this->versions[$this->class->getDefaultWidth()] will not be defined.
//
// return the first available image version instead
return reset($this->versions);
}
} | [
"public",
"function",
"getDefaultImageInfo",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"versions",
"[",
"$",
"this",
"->",
"class",
"->",
"getDefaultWidth",
"(",
")",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"versions",
"[",
"$",
"this",
"->",
"class",
"->",
"getDefaultWidth",
"(",
")",
"]",
";",
"}",
"else",
"{",
"// if the image is smaller than the class default width,",
"// $this->versions[$this->class->getDefaultWidth()] will not be defined.",
"//",
"// return the first available image version instead",
"return",
"reset",
"(",
"$",
"this",
"->",
"versions",
")",
";",
"}",
"}"
] | Get WebImageInfo object for the default image size
@return \Wa72\AdaptImage\WebImageInfo | [
"Get",
"WebImageInfo",
"object",
"for",
"the",
"default",
"image",
"size"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImage.php#L121-L132 | train |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImage.php | ResponsiveImage.createResizedVersions | public function createResizedVersions(ImageResizer $resizer)
{
foreach ($this->class->getImageResizeDefinitions() as $ird) {
$resizer->resize($ird, $this->original_ifi, true);
}
} | php | public function createResizedVersions(ImageResizer $resizer)
{
foreach ($this->class->getImageResizeDefinitions() as $ird) {
$resizer->resize($ird, $this->original_ifi, true);
}
} | [
"public",
"function",
"createResizedVersions",
"(",
"ImageResizer",
"$",
"resizer",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"class",
"->",
"getImageResizeDefinitions",
"(",
")",
"as",
"$",
"ird",
")",
"{",
"$",
"resizer",
"->",
"resize",
"(",
"$",
"ird",
",",
"$",
"this",
"->",
"original_ifi",
",",
"true",
")",
";",
"}",
"}"
] | Really create all resized versions of this image
@param ImageResizer $resizer
@throws \Exception | [
"Really",
"create",
"all",
"resized",
"versions",
"of",
"this",
"image"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImage.php#L140-L145 | train |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImage.php | ResponsiveImage.getResizedVersion | public function getResizedVersion(ImageResizer $resizer, $width)
{
if (!$this->class->hasWidth($width)) {
throw new WidthNotAllowedException($width);
}
return $resizer->resize(
$this->class->getImageResizeDefinitionByWidth($width),
$this->original_ifi,
true
);
} | php | public function getResizedVersion(ImageResizer $resizer, $width)
{
if (!$this->class->hasWidth($width)) {
throw new WidthNotAllowedException($width);
}
return $resizer->resize(
$this->class->getImageResizeDefinitionByWidth($width),
$this->original_ifi,
true
);
} | [
"public",
"function",
"getResizedVersion",
"(",
"ImageResizer",
"$",
"resizer",
",",
"$",
"width",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"class",
"->",
"hasWidth",
"(",
"$",
"width",
")",
")",
"{",
"throw",
"new",
"WidthNotAllowedException",
"(",
"$",
"width",
")",
";",
"}",
"return",
"$",
"resizer",
"->",
"resize",
"(",
"$",
"this",
"->",
"class",
"->",
"getImageResizeDefinitionByWidth",
"(",
"$",
"width",
")",
",",
"$",
"this",
"->",
"original_ifi",
",",
"true",
")",
";",
"}"
] | Resize the image to a defined width and return the corresponding ImageFileInfo object
@param ImageResizer $resizer
@param int $width The desired width; it must be a width that is availaible in the image class
@return ImageFileInfo The ImageFileInfo object pointing to the resized image file
@throws \Exception | [
"Resize",
"the",
"image",
"to",
"a",
"defined",
"width",
"and",
"return",
"the",
"corresponding",
"ImageFileInfo",
"object"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImage.php#L155-L165 | train |
ezra-obiwale/dSCore | src/Core/ACore.php | ACore.className | protected function className($suffix = '') {
$exp = explode('\\', $this->getClass());
return (!empty($suffix) &&
substr($exp[count($exp) - 1], (strlen($exp[count($exp) - 1]) - strlen($suffix))) === $suffix) ?
substr($exp[count($exp) - 1], 0, (strlen($exp[count($exp) - 1]) - strlen($suffix))) :
$exp[count($exp) - 1];
} | php | protected function className($suffix = '') {
$exp = explode('\\', $this->getClass());
return (!empty($suffix) &&
substr($exp[count($exp) - 1], (strlen($exp[count($exp) - 1]) - strlen($suffix))) === $suffix) ?
substr($exp[count($exp) - 1], 0, (strlen($exp[count($exp) - 1]) - strlen($suffix))) :
$exp[count($exp) - 1];
} | [
"protected",
"function",
"className",
"(",
"$",
"suffix",
"=",
"''",
")",
"{",
"$",
"exp",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"this",
"->",
"getClass",
"(",
")",
")",
";",
"return",
"(",
"!",
"empty",
"(",
"$",
"suffix",
")",
"&&",
"substr",
"(",
"$",
"exp",
"[",
"count",
"(",
"$",
"exp",
")",
"-",
"1",
"]",
",",
"(",
"strlen",
"(",
"$",
"exp",
"[",
"count",
"(",
"$",
"exp",
")",
"-",
"1",
"]",
")",
"-",
"strlen",
"(",
"$",
"suffix",
")",
")",
")",
"===",
"$",
"suffix",
")",
"?",
"substr",
"(",
"$",
"exp",
"[",
"count",
"(",
"$",
"exp",
")",
"-",
"1",
"]",
",",
"0",
",",
"(",
"strlen",
"(",
"$",
"exp",
"[",
"count",
"(",
"$",
"exp",
")",
"-",
"1",
"]",
")",
"-",
"strlen",
"(",
"$",
"suffix",
")",
")",
")",
":",
"$",
"exp",
"[",
"count",
"(",
"$",
"exp",
")",
"-",
"1",
"]",
";",
"}"
] | Fetches the class name
@param string $suffix
@access protected
@return string | [
"Fetches",
"the",
"class",
"name"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/ACore.php#L21-L28 | train |
ezra-obiwale/dSCore | src/Core/ACore.php | ACore.getNamespace | protected function getNamespace() {
$np = explode('\\', $this->getClass());
unset($np[count($np) - 1]);
return join('\\', $np);
} | php | protected function getNamespace() {
$np = explode('\\', $this->getClass());
unset($np[count($np) - 1]);
return join('\\', $np);
} | [
"protected",
"function",
"getNamespace",
"(",
")",
"{",
"$",
"np",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"this",
"->",
"getClass",
"(",
")",
")",
";",
"unset",
"(",
"$",
"np",
"[",
"count",
"(",
"$",
"np",
")",
"-",
"1",
"]",
")",
";",
"return",
"join",
"(",
"'\\\\'",
",",
"$",
"np",
")",
";",
"}"
] | Fetches the namespace of the current class
@return string | [
"Fetches",
"the",
"namespace",
"of",
"the",
"current",
"class"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/ACore.php#L34-L38 | train |
shgysk8zer0/core_api | traits/xml_exception.php | XML_Exception.ExceptionAsXML | final protected function ExceptionAsXML(\Exception $e, \DOMNode &$par)
{
//echo $e . PHP_EOL . print_r($par, true);
$exc = $par->appendChild($this->createElement('Exception'));
$exc->appendChild($this->createElement('File', $e->getFile()));
$exc->appendChild($this->createElement('Line', $e->getLine()));
$exc->appendChild($this->createElement('Code', $e->getCode()));
$exc->appendChild(
$this->createElement('Message', $e->getMessage())
);
array_reduce(
$e->getTrace(),
function($parent, $el)
{
$trace = $this->createElement('Trace');
$parent->appendChild($trace);
$trace->appendChild($this->createElement('File', $el['file']));
$trace->appendChild($this->createElement('Line', $el['line']));
$trace->appendChild(
$this->createElement('Function', $el['function'])
);
$trace->appendChild($this->createElement('Type', $el['type']));
$args = $trace->appendChild($this->createElement('Args'));
foreach ($el['args'] as $arg) {
$args->appendChild(
$this->createElement('Arg', print_r($arg, true))
);
}
return $parent;
},
$exc->appendChild($this->createElement('StackTrace'))
);
} | php | final protected function ExceptionAsXML(\Exception $e, \DOMNode &$par)
{
//echo $e . PHP_EOL . print_r($par, true);
$exc = $par->appendChild($this->createElement('Exception'));
$exc->appendChild($this->createElement('File', $e->getFile()));
$exc->appendChild($this->createElement('Line', $e->getLine()));
$exc->appendChild($this->createElement('Code', $e->getCode()));
$exc->appendChild(
$this->createElement('Message', $e->getMessage())
);
array_reduce(
$e->getTrace(),
function($parent, $el)
{
$trace = $this->createElement('Trace');
$parent->appendChild($trace);
$trace->appendChild($this->createElement('File', $el['file']));
$trace->appendChild($this->createElement('Line', $el['line']));
$trace->appendChild(
$this->createElement('Function', $el['function'])
);
$trace->appendChild($this->createElement('Type', $el['type']));
$args = $trace->appendChild($this->createElement('Args'));
foreach ($el['args'] as $arg) {
$args->appendChild(
$this->createElement('Arg', print_r($arg, true))
);
}
return $parent;
},
$exc->appendChild($this->createElement('StackTrace'))
);
} | [
"final",
"protected",
"function",
"ExceptionAsXML",
"(",
"\\",
"Exception",
"$",
"e",
",",
"\\",
"DOMNode",
"&",
"$",
"par",
")",
"{",
"//echo $e . PHP_EOL . print_r($par, true);",
"$",
"exc",
"=",
"$",
"par",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Exception'",
")",
")",
";",
"$",
"exc",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'File'",
",",
"$",
"e",
"->",
"getFile",
"(",
")",
")",
")",
";",
"$",
"exc",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Line'",
",",
"$",
"e",
"->",
"getLine",
"(",
")",
")",
")",
";",
"$",
"exc",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Code'",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
")",
";",
"$",
"exc",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Message'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"array_reduce",
"(",
"$",
"e",
"->",
"getTrace",
"(",
")",
",",
"function",
"(",
"$",
"parent",
",",
"$",
"el",
")",
"{",
"$",
"trace",
"=",
"$",
"this",
"->",
"createElement",
"(",
"'Trace'",
")",
";",
"$",
"parent",
"->",
"appendChild",
"(",
"$",
"trace",
")",
";",
"$",
"trace",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'File'",
",",
"$",
"el",
"[",
"'file'",
"]",
")",
")",
";",
"$",
"trace",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Line'",
",",
"$",
"el",
"[",
"'line'",
"]",
")",
")",
";",
"$",
"trace",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Function'",
",",
"$",
"el",
"[",
"'function'",
"]",
")",
")",
";",
"$",
"trace",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Type'",
",",
"$",
"el",
"[",
"'type'",
"]",
")",
")",
";",
"$",
"args",
"=",
"$",
"trace",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Args'",
")",
")",
";",
"foreach",
"(",
"$",
"el",
"[",
"'args'",
"]",
"as",
"$",
"arg",
")",
"{",
"$",
"args",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Arg'",
",",
"print_r",
"(",
"$",
"arg",
",",
"true",
")",
")",
")",
";",
"}",
"return",
"$",
"parent",
";",
"}",
",",
"$",
"exc",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'StackTrace'",
")",
")",
")",
";",
"}"
] | Converts a PHP Exception into a populated XML node
@param Exception $e The exception thrown & caught
@param DOMNode $par The parent node to be appending to
@return void $par is a pointer | [
"Converts",
"a",
"PHP",
"Exception",
"into",
"a",
"populated",
"XML",
"node"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/xml_exception.php#L32-L66 | train |
vainproject/vain-user | src/User/Auth/Access/Traits/PermissionTrait.php | PermissionTrait.boot | public static function boot()
{
parent::boot();
static::deleting(function ($permission) {
if (!method_exists(config('access.permission'), 'bootSoftDeletes')) {
$permission->roles()->sync([]);
}
return true;
});
} | php | public static function boot()
{
parent::boot();
static::deleting(function ($permission) {
if (!method_exists(config('access.permission'), 'bootSoftDeletes')) {
$permission->roles()->sync([]);
}
return true;
});
} | [
"public",
"static",
"function",
"boot",
"(",
")",
"{",
"parent",
"::",
"boot",
"(",
")",
";",
"static",
"::",
"deleting",
"(",
"function",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"config",
"(",
"'access.permission'",
")",
",",
"'bootSoftDeletes'",
")",
")",
"{",
"$",
"permission",
"->",
"roles",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"}"
] | Boot the permission model
Attach event listener to remove the many-to-many records when trying to delete
Will NOT delete any records if the permission model uses soft deletes.
@return void|bool | [
"Boot",
"the",
"permission",
"model",
"Attach",
"event",
"listener",
"to",
"remove",
"the",
"many",
"-",
"to",
"-",
"many",
"records",
"when",
"trying",
"to",
"delete",
"Will",
"NOT",
"delete",
"any",
"records",
"if",
"the",
"permission",
"model",
"uses",
"soft",
"deletes",
"."
] | 1c059faa61ebf289fcaea39a90b4523cfc9d6efc | https://github.com/vainproject/vain-user/blob/1c059faa61ebf289fcaea39a90b4523cfc9d6efc/src/User/Auth/Access/Traits/PermissionTrait.php#L24-L34 | train |
mwyatt/core | src/Pagination.php | Pagination.getLimit | public function getLimit($end = false)
{
$bottom = ($this->maxPerPage * ($this->pageCurrent - 1));
$top = $this->maxPerPage;
if ($end === false) {
return array($bottom, $top);
}
if ($end === 0) {
return $bottom;
}
if ($end === 1) {
return $top;
}
} | php | public function getLimit($end = false)
{
$bottom = ($this->maxPerPage * ($this->pageCurrent - 1));
$top = $this->maxPerPage;
if ($end === false) {
return array($bottom, $top);
}
if ($end === 0) {
return $bottom;
}
if ($end === 1) {
return $top;
}
} | [
"public",
"function",
"getLimit",
"(",
"$",
"end",
"=",
"false",
")",
"{",
"$",
"bottom",
"=",
"(",
"$",
"this",
"->",
"maxPerPage",
"*",
"(",
"$",
"this",
"->",
"pageCurrent",
"-",
"1",
")",
")",
";",
"$",
"top",
"=",
"$",
"this",
"->",
"maxPerPage",
";",
"if",
"(",
"$",
"end",
"===",
"false",
")",
"{",
"return",
"array",
"(",
"$",
"bottom",
",",
"$",
"top",
")",
";",
"}",
"if",
"(",
"$",
"end",
"===",
"0",
")",
"{",
"return",
"$",
"bottom",
";",
"}",
"if",
"(",
"$",
"end",
"===",
"1",
")",
"{",
"return",
"$",
"top",
";",
"}",
"}"
] | get a limit array usable in an sql query
@param boolean $end ?
@return array|int | [
"get",
"a",
"limit",
"array",
"usable",
"in",
"an",
"sql",
"query"
] | 8ea9d67cc84fe6aff17a469c703d5492dbcd93ed | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Pagination.php#L79-L92 | train |
mwyatt/core | src/Pagination.php | Pagination.generate | public function generate($pageCurrent, $totalRows)
{
$this->totalRows = $totalRows;
$this->setPossiblePages();
$this->setPageCurrent($pageCurrent);
if ($this->possiblePages < 2) {
return;
}
$pageCurrent = $this->pageCurrent;
$pagination = $this->getPaginationContainer();
// previous
if ($pageCurrent > 1) {
$pagination['previous'] = $this->getPaginationPage($this->urlBuildPageLink($pageCurrent - 1));
}
for ($index = 1; $index <= $this->possiblePages; $index ++) {
$pagination['pages'][$index] = $this->getPaginationPage($this->urlBuildPageLink($index), ($pageCurrent == $index ? true : false));
}
// next
if ($pageCurrent < $this->possiblePages) {
$pagination['next'] = $this->getPaginationPage($this->urlBuildPageLink($pageCurrent + 1));
}
return $pagination;
} | php | public function generate($pageCurrent, $totalRows)
{
$this->totalRows = $totalRows;
$this->setPossiblePages();
$this->setPageCurrent($pageCurrent);
if ($this->possiblePages < 2) {
return;
}
$pageCurrent = $this->pageCurrent;
$pagination = $this->getPaginationContainer();
// previous
if ($pageCurrent > 1) {
$pagination['previous'] = $this->getPaginationPage($this->urlBuildPageLink($pageCurrent - 1));
}
for ($index = 1; $index <= $this->possiblePages; $index ++) {
$pagination['pages'][$index] = $this->getPaginationPage($this->urlBuildPageLink($index), ($pageCurrent == $index ? true : false));
}
// next
if ($pageCurrent < $this->possiblePages) {
$pagination['next'] = $this->getPaginationPage($this->urlBuildPageLink($pageCurrent + 1));
}
return $pagination;
} | [
"public",
"function",
"generate",
"(",
"$",
"pageCurrent",
",",
"$",
"totalRows",
")",
"{",
"$",
"this",
"->",
"totalRows",
"=",
"$",
"totalRows",
";",
"$",
"this",
"->",
"setPossiblePages",
"(",
")",
";",
"$",
"this",
"->",
"setPageCurrent",
"(",
"$",
"pageCurrent",
")",
";",
"if",
"(",
"$",
"this",
"->",
"possiblePages",
"<",
"2",
")",
"{",
"return",
";",
"}",
"$",
"pageCurrent",
"=",
"$",
"this",
"->",
"pageCurrent",
";",
"$",
"pagination",
"=",
"$",
"this",
"->",
"getPaginationContainer",
"(",
")",
";",
"// previous",
"if",
"(",
"$",
"pageCurrent",
">",
"1",
")",
"{",
"$",
"pagination",
"[",
"'previous'",
"]",
"=",
"$",
"this",
"->",
"getPaginationPage",
"(",
"$",
"this",
"->",
"urlBuildPageLink",
"(",
"$",
"pageCurrent",
"-",
"1",
")",
")",
";",
"}",
"for",
"(",
"$",
"index",
"=",
"1",
";",
"$",
"index",
"<=",
"$",
"this",
"->",
"possiblePages",
";",
"$",
"index",
"++",
")",
"{",
"$",
"pagination",
"[",
"'pages'",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"getPaginationPage",
"(",
"$",
"this",
"->",
"urlBuildPageLink",
"(",
"$",
"index",
")",
",",
"(",
"$",
"pageCurrent",
"==",
"$",
"index",
"?",
"true",
":",
"false",
")",
")",
";",
"}",
"// next",
"if",
"(",
"$",
"pageCurrent",
"<",
"$",
"this",
"->",
"possiblePages",
")",
"{",
"$",
"pagination",
"[",
"'next'",
"]",
"=",
"$",
"this",
"->",
"getPaginationPage",
"(",
"$",
"this",
"->",
"urlBuildPageLink",
"(",
"$",
"pageCurrent",
"+",
"1",
")",
")",
";",
"}",
"return",
"$",
"pagination",
";",
"}"
] | build the pagination array
@return array | [
"build",
"the",
"pagination",
"array"
] | 8ea9d67cc84fe6aff17a469c703d5492dbcd93ed | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Pagination.php#L99-L127 | train |
mwyatt/core | src/Pagination.php | Pagination.urlBuildPageLink | protected function urlBuildPageLink($page)
{
$url = $this->url;
$urlBase = $url->generate() . $url->getPath();
$queryParts = $url->getQueryArray();
$queryParts['page'] = $page;
return $urlBase . '?' . http_build_query($queryParts);
} | php | protected function urlBuildPageLink($page)
{
$url = $this->url;
$urlBase = $url->generate() . $url->getPath();
$queryParts = $url->getQueryArray();
$queryParts['page'] = $page;
return $urlBase . '?' . http_build_query($queryParts);
} | [
"protected",
"function",
"urlBuildPageLink",
"(",
"$",
"page",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"url",
";",
"$",
"urlBase",
"=",
"$",
"url",
"->",
"generate",
"(",
")",
".",
"$",
"url",
"->",
"getPath",
"(",
")",
";",
"$",
"queryParts",
"=",
"$",
"url",
"->",
"getQueryArray",
"(",
")",
";",
"$",
"queryParts",
"[",
"'page'",
"]",
"=",
"$",
"page",
";",
"return",
"$",
"urlBase",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"queryParts",
")",
";",
"}"
] | add the page to the query string
create an absolute url
@param int $page
@return string absolute url | [
"add",
"the",
"page",
"to",
"the",
"query",
"string",
"create",
"an",
"absolute",
"url"
] | 8ea9d67cc84fe6aff17a469c703d5492dbcd93ed | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Pagination.php#L165-L172 | train |
mwyatt/core | src/Pagination.php | Pagination.setPageCurrent | protected function setPageCurrent($page)
{
// need both of these?
$page += 0;
$page = (int) $page;
// cant be below 1
$page = $page ? $page : 1;
// cant be above possible
if ($page > $this->possiblePages) {
$page = $this->possiblePages;
}
$this->pageCurrent = $page;
} | php | protected function setPageCurrent($page)
{
// need both of these?
$page += 0;
$page = (int) $page;
// cant be below 1
$page = $page ? $page : 1;
// cant be above possible
if ($page > $this->possiblePages) {
$page = $this->possiblePages;
}
$this->pageCurrent = $page;
} | [
"protected",
"function",
"setPageCurrent",
"(",
"$",
"page",
")",
"{",
"// need both of these?",
"$",
"page",
"+=",
"0",
";",
"$",
"page",
"=",
"(",
"int",
")",
"$",
"page",
";",
"// cant be below 1",
"$",
"page",
"=",
"$",
"page",
"?",
"$",
"page",
":",
"1",
";",
"// cant be above possible",
"if",
"(",
"$",
"page",
">",
"$",
"this",
"->",
"possiblePages",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"possiblePages",
";",
"}",
"$",
"this",
"->",
"pageCurrent",
"=",
"$",
"page",
";",
"}"
] | page is set within the constraints of lowest and highest value
@param int $page | [
"page",
"is",
"set",
"within",
"the",
"constraints",
"of",
"lowest",
"and",
"highest",
"value"
] | 8ea9d67cc84fe6aff17a469c703d5492dbcd93ed | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Pagination.php#L179-L195 | train |
zapheus/zapheus | src/Routing/Route.php | Route.regex | public function regex()
{
// Turn "(/)" into "/?"
$uri = preg_replace('#\(/\)#', '/?', $this->uri);
// Create capture group for ":parameter", replaces ":parameter"
$uri = $this->capture($uri, '/:(' . self::ALLOWED_REGEX . ')/');
// Create capture group for '{parameter}', replaces "{parameter}"
$uri = $this->capture($uri, '/{(' . self::ALLOWED_REGEX . ')}/');
// Add start and end matching
return (string) '@^' . $uri . '$@D';
} | php | public function regex()
{
// Turn "(/)" into "/?"
$uri = preg_replace('#\(/\)#', '/?', $this->uri);
// Create capture group for ":parameter", replaces ":parameter"
$uri = $this->capture($uri, '/:(' . self::ALLOWED_REGEX . ')/');
// Create capture group for '{parameter}', replaces "{parameter}"
$uri = $this->capture($uri, '/{(' . self::ALLOWED_REGEX . ')}/');
// Add start and end matching
return (string) '@^' . $uri . '$@D';
} | [
"public",
"function",
"regex",
"(",
")",
"{",
"// Turn \"(/)\" into \"/?\"",
"$",
"uri",
"=",
"preg_replace",
"(",
"'#\\(/\\)#'",
",",
"'/?'",
",",
"$",
"this",
"->",
"uri",
")",
";",
"// Create capture group for \":parameter\", replaces \":parameter\"",
"$",
"uri",
"=",
"$",
"this",
"->",
"capture",
"(",
"$",
"uri",
",",
"'/:('",
".",
"self",
"::",
"ALLOWED_REGEX",
".",
"')/'",
")",
";",
"// Create capture group for '{parameter}', replaces \"{parameter}\"",
"$",
"uri",
"=",
"$",
"this",
"->",
"capture",
"(",
"$",
"uri",
",",
"'/{('",
".",
"self",
"::",
"ALLOWED_REGEX",
".",
"')}/'",
")",
";",
"// Add start and end matching",
"return",
"(",
"string",
")",
"'@^'",
".",
"$",
"uri",
".",
"'$@D'",
";",
"}"
] | Returns a regular expression pattern from the given URI.
@link https://stackoverflow.com/q/30130913
@return string | [
"Returns",
"a",
"regular",
"expression",
"pattern",
"from",
"the",
"given",
"URI",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Route.php#L112-L125 | train |
zapheus/zapheus | src/Routing/Route.php | Route.capture | protected function capture($pattern, $search)
{
$replace = '(?<$1>' . self::ALLOWED_REGEX . ')';
return preg_replace($search, $replace, $pattern);
} | php | protected function capture($pattern, $search)
{
$replace = '(?<$1>' . self::ALLOWED_REGEX . ')';
return preg_replace($search, $replace, $pattern);
} | [
"protected",
"function",
"capture",
"(",
"$",
"pattern",
",",
"$",
"search",
")",
"{",
"$",
"replace",
"=",
"'(?<$1>'",
".",
"self",
"::",
"ALLOWED_REGEX",
".",
"')'",
";",
"return",
"preg_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"pattern",
")",
";",
"}"
] | Capture the specified regular expressions.
@param string $pattern
@param string $search
@return string | [
"Capture",
"the",
"specified",
"regular",
"expressions",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Route.php#L144-L149 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.addField | public function addField(Field $field)
{
$name = $field->getName();
if (array_key_exists($name, $this->fields)) {
throw new DuplicateFieldNameException($name);
}
$this->fields[$name] = $field;
foreach ($field->getAliases() as $alias) {
if (array_key_exists($alias, $this->fieldAliases)) {
throw new DuplicateFieldAliasException($alias);
}
$this->fieldAliases[$alias] = $name;
}
return $this;
} | php | public function addField(Field $field)
{
$name = $field->getName();
if (array_key_exists($name, $this->fields)) {
throw new DuplicateFieldNameException($name);
}
$this->fields[$name] = $field;
foreach ($field->getAliases() as $alias) {
if (array_key_exists($alias, $this->fieldAliases)) {
throw new DuplicateFieldAliasException($alias);
}
$this->fieldAliases[$alias] = $name;
}
return $this;
} | [
"public",
"function",
"addField",
"(",
"Field",
"$",
"field",
")",
"{",
"$",
"name",
"=",
"$",
"field",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"fields",
")",
")",
"{",
"throw",
"new",
"DuplicateFieldNameException",
"(",
"$",
"name",
")",
";",
"}",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
"=",
"$",
"field",
";",
"foreach",
"(",
"$",
"field",
"->",
"getAliases",
"(",
")",
"as",
"$",
"alias",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"alias",
",",
"$",
"this",
"->",
"fieldAliases",
")",
")",
"{",
"throw",
"new",
"DuplicateFieldAliasException",
"(",
"$",
"alias",
")",
";",
"}",
"$",
"this",
"->",
"fieldAliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"name",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Define a field
@param \sndsgd\Field $field The field to define
@return \sndsgd\field\Collection | [
"Define",
"a",
"field"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L102-L117 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.removeField | public function removeField($name)
{
if (($field = $this->getField($name)) === null) {
return false;
}
foreach ($field->getAliases() as $alias) {
unset($this->fieldAliases[$alias]);
}
unset($this->fields[$name]);
return true;
} | php | public function removeField($name)
{
if (($field = $this->getField($name)) === null) {
return false;
}
foreach ($field->getAliases() as $alias) {
unset($this->fieldAliases[$alias]);
}
unset($this->fields[$name]);
return true;
} | [
"public",
"function",
"removeField",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"(",
"$",
"field",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"name",
")",
")",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"field",
"->",
"getAliases",
"(",
")",
"as",
"$",
"alias",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"fieldAliases",
"[",
"$",
"alias",
"]",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Remove a field from the collection
@param string $name A field name or alias
@return boolean Whether or not a field was removed | [
"Remove",
"a",
"field",
"from",
"the",
"collection"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L139-L150 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.getField | public function getField($name)
{
if (array_key_exists($name, $this->fields)) {
return $this->fields[$name];
}
else if (array_key_exists($name, $this->fieldAliases)) {
$name = $this->fieldAliases[$name];
return $this->fields[$name];
}
return null;
} | php | public function getField($name)
{
if (array_key_exists($name, $this->fields)) {
return $this->fields[$name];
}
else if (array_key_exists($name, $this->fieldAliases)) {
$name = $this->fieldAliases[$name];
return $this->fields[$name];
}
return null;
} | [
"public",
"function",
"getField",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"fields",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"fieldAliases",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"fieldAliases",
"[",
"$",
"name",
"]",
";",
"return",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Get a field instance
@param string $name An alias or name of the field to get
@return \sndsgd\Field|null
@return \sndsgd\Field The field was found
@return null The field was NOT found | [
"Get",
"a",
"field",
"instance"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L160-L170 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.getFields | public function getFields($visibility = Field::VISIBILITY_PUBLIC)
{
$ret = [];
foreach ($this->fields as $name => $field) {
if ($field->getVisibility() & $visibility) {
$ret[$name] = $field;
}
}
return $ret;
} | php | public function getFields($visibility = Field::VISIBILITY_PUBLIC)
{
$ret = [];
foreach ($this->fields as $name => $field) {
if ($field->getVisibility() & $visibility) {
$ret[$name] = $field;
}
}
return $ret;
} | [
"public",
"function",
"getFields",
"(",
"$",
"visibility",
"=",
"Field",
"::",
"VISIBILITY_PUBLIC",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"getVisibility",
"(",
")",
"&",
"$",
"visibility",
")",
"{",
"$",
"ret",
"[",
"$",
"name",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get an associative array of the fields in this collection
@param integer $visibility A bitmask to filter fields by visibility
@return array<string,sndsgd\Field> | [
"Get",
"an",
"associative",
"array",
"of",
"the",
"fields",
"in",
"this",
"collection"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L178-L187 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.addValues | public function addValues(array $fieldValues)
{
foreach ($fieldValues as $fieldName => $values) {
$values = Arr::cast($values);
if (null === ($field = $this->getField($fieldName))) {
$message = "unknown field";
$len = count($values);
if ($len !== 1) {
$message .= " (encountered $len values)";
}
$error = new Error($message);
$error->setName($fieldName);
$this->addError($error);
}
else {
foreach ($values as $index => $value) {
$field->addValue($value, $index);
}
}
}
} | php | public function addValues(array $fieldValues)
{
foreach ($fieldValues as $fieldName => $values) {
$values = Arr::cast($values);
if (null === ($field = $this->getField($fieldName))) {
$message = "unknown field";
$len = count($values);
if ($len !== 1) {
$message .= " (encountered $len values)";
}
$error = new Error($message);
$error->setName($fieldName);
$this->addError($error);
}
else {
foreach ($values as $index => $value) {
$field->addValue($value, $index);
}
}
}
} | [
"public",
"function",
"addValues",
"(",
"array",
"$",
"fieldValues",
")",
"{",
"foreach",
"(",
"$",
"fieldValues",
"as",
"$",
"fieldName",
"=>",
"$",
"values",
")",
"{",
"$",
"values",
"=",
"Arr",
"::",
"cast",
"(",
"$",
"values",
")",
";",
"if",
"(",
"null",
"===",
"(",
"$",
"field",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"fieldName",
")",
")",
")",
"{",
"$",
"message",
"=",
"\"unknown field\"",
";",
"$",
"len",
"=",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"len",
"!==",
"1",
")",
"{",
"$",
"message",
".=",
"\" (encountered $len values)\"",
";",
"}",
"$",
"error",
"=",
"new",
"Error",
"(",
"$",
"message",
")",
";",
"$",
"error",
"->",
"setName",
"(",
"$",
"fieldName",
")",
";",
"$",
"this",
"->",
"addError",
"(",
"$",
"error",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"field",
"->",
"addValue",
"(",
"$",
"value",
",",
"$",
"index",
")",
";",
"}",
"}",
"}",
"}"
] | Add values to the fields in the collection
@param array<string,mixed> $fieldValues | [
"Add",
"values",
"to",
"the",
"fields",
"in",
"the",
"collection"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L194-L214 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.validate | public function validate()
{
# addValues adds validation errors for unknown values
$errs = count($this->errors);
$dataKey = constant(get_called_class()."::EVENT_DATA_KEY");
if ($this->beforeValidate() !== true) {
return false;
}
foreach ($this->fields as $field) {
if ($field->validate($this) === false) {
foreach ($field->getErrors() as $error) {
$this->addError($error);
$errs++;
}
}
}
return (
$errs > 0 ||
$this->afterValidate() !== true ||
count($this->errors) > 0
) ? false : true;
} | php | public function validate()
{
# addValues adds validation errors for unknown values
$errs = count($this->errors);
$dataKey = constant(get_called_class()."::EVENT_DATA_KEY");
if ($this->beforeValidate() !== true) {
return false;
}
foreach ($this->fields as $field) {
if ($field->validate($this) === false) {
foreach ($field->getErrors() as $error) {
$this->addError($error);
$errs++;
}
}
}
return (
$errs > 0 ||
$this->afterValidate() !== true ||
count($this->errors) > 0
) ? false : true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"# addValues adds validation errors for unknown values",
"$",
"errs",
"=",
"count",
"(",
"$",
"this",
"->",
"errors",
")",
";",
"$",
"dataKey",
"=",
"constant",
"(",
"get_called_class",
"(",
")",
".",
"\"::EVENT_DATA_KEY\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"beforeValidate",
"(",
")",
"!==",
"true",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"validate",
"(",
"$",
"this",
")",
"===",
"false",
")",
"{",
"foreach",
"(",
"$",
"field",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"error",
")",
";",
"$",
"errs",
"++",
";",
"}",
"}",
"}",
"return",
"(",
"$",
"errs",
">",
"0",
"||",
"$",
"this",
"->",
"afterValidate",
"(",
")",
"!==",
"true",
"||",
"count",
"(",
"$",
"this",
"->",
"errors",
")",
">",
"0",
")",
"?",
"false",
":",
"true",
";",
"}"
] | Validate the all the fields
@return boolean | [
"Validate",
"the",
"all",
"the",
"fields"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L221-L244 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.addError | public function addError(Error $error, $prepend = false)
{
if ($prepend === true) {
array_unshift($this->errors, $error);
}
else {
$this->errors[] = $error;
}
return count($this->errors);
} | php | public function addError(Error $error, $prepend = false)
{
if ($prepend === true) {
array_unshift($this->errors, $error);
}
else {
$this->errors[] = $error;
}
return count($this->errors);
} | [
"public",
"function",
"addError",
"(",
"Error",
"$",
"error",
",",
"$",
"prepend",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"prepend",
"===",
"true",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"errors",
",",
"$",
"error",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"$",
"error",
";",
"}",
"return",
"count",
"(",
"$",
"this",
"->",
"errors",
")",
";",
"}"
] | Add a validation error
@param \sndsgd\field\Error $error
@param boolean $prepend Add the error to the beginning
@return integer The total number of validation errors | [
"Add",
"a",
"validation",
"error"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L253-L262 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.getErrors | public function getErrors($name = null)
{
if ($name === null) {
return $this->errors;
}
$ret = [];
foreach ($this->errors as $error) {
if ($error->getName() === $name) {
$ret[] = $error;
}
}
return $ret;
} | php | public function getErrors($name = null)
{
if ($name === null) {
return $this->errors;
}
$ret = [];
foreach ($this->errors as $error) {
if ($error->getName() === $name) {
$ret[] = $error;
}
}
return $ret;
} | [
"public",
"function",
"getErrors",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"errors",
";",
"}",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"errors",
"as",
"$",
"error",
")",
"{",
"if",
"(",
"$",
"error",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"error",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get validation errors for one or all fields
@param string|null $name The name of a field to get validation errors for
@return array<\sndsgd\field\Error> | [
"Get",
"validation",
"errors",
"for",
"one",
"or",
"all",
"fields"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L280-L293 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.exportErrors | public function exportErrors()
{
$ret = [];
foreach ($this->errors as $error) {
$ret[] = $error->export();
}
return $ret;
} | php | public function exportErrors()
{
$ret = [];
foreach ($this->errors as $error) {
$ret[] = $error->export();
}
return $ret;
} | [
"public",
"function",
"exportErrors",
"(",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"errors",
"as",
"$",
"error",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"error",
"->",
"export",
"(",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Export validation errors for all fields
@return array<string,mixed> | [
"Export",
"validation",
"errors",
"for",
"all",
"fields"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L300-L307 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.exportFieldValue | public function exportFieldValue($name, $exportHandler = null)
{
if (!is_string($name)) {
throw new InvalidArgumentException(
"invalid value provided for 'name'; ".
"expecting a field name as string"
);
}
else if (($field = $this->getField($name)) == null) {
throw new UnknownFieldException($name);
}
return $field->exportValue($exportHandler);
} | php | public function exportFieldValue($name, $exportHandler = null)
{
if (!is_string($name)) {
throw new InvalidArgumentException(
"invalid value provided for 'name'; ".
"expecting a field name as string"
);
}
else if (($field = $this->getField($name)) == null) {
throw new UnknownFieldException($name);
}
return $field->exportValue($exportHandler);
} | [
"public",
"function",
"exportFieldValue",
"(",
"$",
"name",
",",
"$",
"exportHandler",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"invalid value provided for 'name'; \"",
".",
"\"expecting a field name as string\"",
")",
";",
"}",
"else",
"if",
"(",
"(",
"$",
"field",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"name",
")",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"UnknownFieldException",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"field",
"->",
"exportValue",
"(",
"$",
"exportHandler",
")",
";",
"}"
] | Convenience method to get a particular field value
@param string $name The field name
@param integer|null $exportHandler AN export handler
@return mixed
@throws \InvalidArgumentException If provided name does not exist | [
"Convenience",
"method",
"to",
"get",
"a",
"particular",
"field",
"value"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L317-L329 | train |
sndsgd/sndsgd-field | src/field/Collection.php | Collection.exportValues | public function exportValues()
{
$ret = [];
foreach ($this->fields as $field) {
if ($field->getExportHandler() !== Field::EXPORT_SKIP) {
$ret[$field->getName()] = $field->exportValue();
}
}
return $ret;
} | php | public function exportValues()
{
$ret = [];
foreach ($this->fields as $field) {
if ($field->getExportHandler() !== Field::EXPORT_SKIP) {
$ret[$field->getName()] = $field->exportValue();
}
}
return $ret;
} | [
"public",
"function",
"exportValues",
"(",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"getExportHandler",
"(",
")",
"!==",
"Field",
"::",
"EXPORT_SKIP",
")",
"{",
"$",
"ret",
"[",
"$",
"field",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"field",
"->",
"exportValue",
"(",
")",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get all field values using their respective export handlers
@return array<string,mixed> | [
"Get",
"all",
"field",
"values",
"using",
"their",
"respective",
"export",
"handlers"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Collection.php#L336-L345 | train |
DreadLabs/VantomasWebsite | src/Twitter/AccessControl/Authorization/BearerToken.php | BearerToken.initializeCredentials | private function initializeCredentials()
{
$this->credentials = base64_encode(
sprintf(
'%s:%s',
urlencode($this->configuration->getConsumerKey()),
urlencode($this->configuration->getConsumerSecret())
)
);
} | php | private function initializeCredentials()
{
$this->credentials = base64_encode(
sprintf(
'%s:%s',
urlencode($this->configuration->getConsumerKey()),
urlencode($this->configuration->getConsumerSecret())
)
);
} | [
"private",
"function",
"initializeCredentials",
"(",
")",
"{",
"$",
"this",
"->",
"credentials",
"=",
"base64_encode",
"(",
"sprintf",
"(",
"'%s:%s'",
",",
"urlencode",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getConsumerKey",
"(",
")",
")",
",",
"urlencode",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getConsumerSecret",
"(",
")",
")",
")",
")",
";",
"}"
] | Initializes the bearer token credentials in the expected format
@see https://dev.twitter.com/docs/auth/application-only-auth
@return void | [
"Initializes",
"the",
"bearer",
"token",
"credentials",
"in",
"the",
"expected",
"format"
] | 7f85f2b45bdf5ed9fa9d320c805c416bf99cd668 | https://github.com/DreadLabs/VantomasWebsite/blob/7f85f2b45bdf5ed9fa9d320c805c416bf99cd668/src/Twitter/AccessControl/Authorization/BearerToken.php#L86-L95 | train |
kambalabs/KmbPuppetDb | src/KmbPuppetDb/Service/FactNames.php | FactNames.getAll | public function getAll()
{
$request = new KmbPuppetDb\Request('/fact-names');
$response = $this->getPuppetDbClient()->send($request);
return (array) $response->getData();
} | php | public function getAll()
{
$request = new KmbPuppetDb\Request('/fact-names');
$response = $this->getPuppetDbClient()->send($request);
return (array) $response->getData();
} | [
"public",
"function",
"getAll",
"(",
")",
"{",
"$",
"request",
"=",
"new",
"KmbPuppetDb",
"\\",
"Request",
"(",
"'/fact-names'",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getPuppetDbClient",
"(",
")",
"->",
"send",
"(",
"$",
"request",
")",
";",
"return",
"(",
"array",
")",
"$",
"response",
"->",
"getData",
"(",
")",
";",
"}"
] | Get all fact names.
@return array | [
"Get",
"all",
"fact",
"names",
"."
] | df56a275cf00f4402cf121a2e99149168f1f8b2d | https://github.com/kambalabs/KmbPuppetDb/blob/df56a275cf00f4402cf121a2e99149168f1f8b2d/src/KmbPuppetDb/Service/FactNames.php#L35-L40 | train |
phossa/phossa-di | src/Phossa/Di/Definition/DefinitionAwareTrait.php | DefinitionAwareTrait.getParameter | protected function getParameter(/*# string */ $name)
{
if ($this->hasResolver()) {
$found = $this->getResolver()->get($name);
} else {
// break into parts by '.'
$parts = explode('.', $name);
$found = $this->parameters;
while (null !== ($part = array_shift($parts))) {
if (!isset($found[$part])) {
$found = null;
break;
}
$found = $found[$part];
}
}
if (null === $found) {
throw new NotFoundException(
Message::get(Message::PARAMETER_NOT_FOUND, $name),
Message::PARAMETER_NOT_FOUND
);
}
return $found;
} | php | protected function getParameter(/*# string */ $name)
{
if ($this->hasResolver()) {
$found = $this->getResolver()->get($name);
} else {
// break into parts by '.'
$parts = explode('.', $name);
$found = $this->parameters;
while (null !== ($part = array_shift($parts))) {
if (!isset($found[$part])) {
$found = null;
break;
}
$found = $found[$part];
}
}
if (null === $found) {
throw new NotFoundException(
Message::get(Message::PARAMETER_NOT_FOUND, $name),
Message::PARAMETER_NOT_FOUND
);
}
return $found;
} | [
"protected",
"function",
"getParameter",
"(",
"/*# string */",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasResolver",
"(",
")",
")",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"getResolver",
"(",
")",
"->",
"get",
"(",
"$",
"name",
")",
";",
"}",
"else",
"{",
"// break into parts by '.'",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"$",
"found",
"=",
"$",
"this",
"->",
"parameters",
";",
"while",
"(",
"null",
"!==",
"(",
"$",
"part",
"=",
"array_shift",
"(",
"$",
"parts",
")",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"found",
"[",
"$",
"part",
"]",
")",
")",
"{",
"$",
"found",
"=",
"null",
";",
"break",
";",
"}",
"$",
"found",
"=",
"$",
"found",
"[",
"$",
"part",
"]",
";",
"}",
"}",
"if",
"(",
"null",
"===",
"$",
"found",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"PARAMETER_NOT_FOUND",
",",
"$",
"name",
")",
",",
"Message",
"::",
"PARAMETER_NOT_FOUND",
")",
";",
"}",
"return",
"$",
"found",
";",
"}"
] | Get this paramter's value either a string or an associate array
```php
$this->set('cache.dir', '/var/tmp');
// will return an array ['dir' => '/var/tmp'];
$result = $this->getParameter('cache');
// will return a string, 'var/tmp'
$result = $this->getParameter('cache.dir');
```
@param string $name parameter name
@return string|array
@throws NotFoundException if not found
@access protected | [
"Get",
"this",
"paramter",
"s",
"value",
"either",
"a",
"string",
"or",
"an",
"associate",
"array"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Definition/DefinitionAwareTrait.php#L350-L375 | train |
phossa/phossa-di | src/Phossa/Di/Definition/DefinitionAwareTrait.php | DefinitionAwareTrait.fixServices | protected function fixServices(array &$definitions)
{
foreach ($definitions as $id => $def) {
if (is_array($def)) {
if (!isset($def['class'])) {
$def = ['class' => $def];
} elseif (!is_array($def['class'])) {
$def['class'] = [ $def['class'] ];
}
} else {
$def = ['class' => [ $def ]];
}
$definitions[$id] = $def;
}
} | php | protected function fixServices(array &$definitions)
{
foreach ($definitions as $id => $def) {
if (is_array($def)) {
if (!isset($def['class'])) {
$def = ['class' => $def];
} elseif (!is_array($def['class'])) {
$def['class'] = [ $def['class'] ];
}
} else {
$def = ['class' => [ $def ]];
}
$definitions[$id] = $def;
}
} | [
"protected",
"function",
"fixServices",
"(",
"array",
"&",
"$",
"definitions",
")",
"{",
"foreach",
"(",
"$",
"definitions",
"as",
"$",
"id",
"=>",
"$",
"def",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"def",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"def",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"def",
"=",
"[",
"'class'",
"=>",
"$",
"def",
"]",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"def",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"def",
"[",
"'class'",
"]",
"=",
"[",
"$",
"def",
"[",
"'class'",
"]",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"def",
"=",
"[",
"'class'",
"=>",
"[",
"$",
"def",
"]",
"]",
";",
"}",
"$",
"definitions",
"[",
"$",
"id",
"]",
"=",
"$",
"def",
";",
"}",
"}"
] | Normalize service definitions
@param array &$definitions
@return void
@access protected | [
"Normalize",
"service",
"definitions"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Definition/DefinitionAwareTrait.php#L384-L398 | train |
danielgp/common-lib | source/MySQLiByDanielGPtypes.php | MySQLiByDanielGPtypes.getMySQLqueryType | protected function getMySQLqueryType($sQuery)
{
$queryPieces = explode(' ', $sQuery);
$statementTypes = $this->listOfMySQLqueryStatementType($queryPieces[0]);
if (in_array($queryPieces[0], $statementTypes['keys'])) {
$type = $statementTypes['value']['Type'];
$ar1 = ['1st Keyword Within Query' => $queryPieces[0]];
$lnT = $this->listOfMySQLqueryLanguageType($type);
$aReturn = array_merge($ar1, $lnT, $statementTypes['value']);
ksort($aReturn);
return $aReturn;
}
return [
'detected1stKeywordWithinQuery' => $queryPieces[0],
'unknown' => ['standsFor' => 'unknown', 'description' => 'unknown'],
'Type' => 'unknown',
'Description' => 'unknown',
];
} | php | protected function getMySQLqueryType($sQuery)
{
$queryPieces = explode(' ', $sQuery);
$statementTypes = $this->listOfMySQLqueryStatementType($queryPieces[0]);
if (in_array($queryPieces[0], $statementTypes['keys'])) {
$type = $statementTypes['value']['Type'];
$ar1 = ['1st Keyword Within Query' => $queryPieces[0]];
$lnT = $this->listOfMySQLqueryLanguageType($type);
$aReturn = array_merge($ar1, $lnT, $statementTypes['value']);
ksort($aReturn);
return $aReturn;
}
return [
'detected1stKeywordWithinQuery' => $queryPieces[0],
'unknown' => ['standsFor' => 'unknown', 'description' => 'unknown'],
'Type' => 'unknown',
'Description' => 'unknown',
];
} | [
"protected",
"function",
"getMySQLqueryType",
"(",
"$",
"sQuery",
")",
"{",
"$",
"queryPieces",
"=",
"explode",
"(",
"' '",
",",
"$",
"sQuery",
")",
";",
"$",
"statementTypes",
"=",
"$",
"this",
"->",
"listOfMySQLqueryStatementType",
"(",
"$",
"queryPieces",
"[",
"0",
"]",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"queryPieces",
"[",
"0",
"]",
",",
"$",
"statementTypes",
"[",
"'keys'",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"statementTypes",
"[",
"'value'",
"]",
"[",
"'Type'",
"]",
";",
"$",
"ar1",
"=",
"[",
"'1st Keyword Within Query'",
"=>",
"$",
"queryPieces",
"[",
"0",
"]",
"]",
";",
"$",
"lnT",
"=",
"$",
"this",
"->",
"listOfMySQLqueryLanguageType",
"(",
"$",
"type",
")",
";",
"$",
"aReturn",
"=",
"array_merge",
"(",
"$",
"ar1",
",",
"$",
"lnT",
",",
"$",
"statementTypes",
"[",
"'value'",
"]",
")",
";",
"ksort",
"(",
"$",
"aReturn",
")",
";",
"return",
"$",
"aReturn",
";",
"}",
"return",
"[",
"'detected1stKeywordWithinQuery'",
"=>",
"$",
"queryPieces",
"[",
"0",
"]",
",",
"'unknown'",
"=>",
"[",
"'standsFor'",
"=>",
"'unknown'",
",",
"'description'",
"=>",
"'unknown'",
"]",
",",
"'Type'",
"=>",
"'unknown'",
",",
"'Description'",
"=>",
"'unknown'",
",",
"]",
";",
"}"
] | Returns the Query language type by scanning the 1st keyword from a given query
@param string $sQuery | [
"Returns",
"the",
"Query",
"language",
"type",
"by",
"scanning",
"the",
"1st",
"keyword",
"from",
"a",
"given",
"query"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtypes.php#L44-L62 | train |
danielgp/common-lib | source/MySQLiByDanielGPtypes.php | MySQLiByDanielGPtypes.listOfMySQLqueryLanguageType | private function listOfMySQLqueryLanguageType($qType)
{
$keyForReturn = 'Type ' . $qType . ' stands for';
$vMap = ['DCL', 'DDL', 'DML', 'DQL', 'DTL'];
if (in_array($qType, $vMap)) {
$valForReturn = $this->readTypeFromJsonFile('MySQLiLanguageTypes')[$qType];
return [$keyForReturn => $valForReturn[0] . ' (' . $valForReturn[1] . ')'];
}
return [$keyForReturn => 'unknown'];
} | php | private function listOfMySQLqueryLanguageType($qType)
{
$keyForReturn = 'Type ' . $qType . ' stands for';
$vMap = ['DCL', 'DDL', 'DML', 'DQL', 'DTL'];
if (in_array($qType, $vMap)) {
$valForReturn = $this->readTypeFromJsonFile('MySQLiLanguageTypes')[$qType];
return [$keyForReturn => $valForReturn[0] . ' (' . $valForReturn[1] . ')'];
}
return [$keyForReturn => 'unknown'];
} | [
"private",
"function",
"listOfMySQLqueryLanguageType",
"(",
"$",
"qType",
")",
"{",
"$",
"keyForReturn",
"=",
"'Type '",
".",
"$",
"qType",
".",
"' stands for'",
";",
"$",
"vMap",
"=",
"[",
"'DCL'",
",",
"'DDL'",
",",
"'DML'",
",",
"'DQL'",
",",
"'DTL'",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"qType",
",",
"$",
"vMap",
")",
")",
"{",
"$",
"valForReturn",
"=",
"$",
"this",
"->",
"readTypeFromJsonFile",
"(",
"'MySQLiLanguageTypes'",
")",
"[",
"$",
"qType",
"]",
";",
"return",
"[",
"$",
"keyForReturn",
"=>",
"$",
"valForReturn",
"[",
"0",
"]",
".",
"' ('",
".",
"$",
"valForReturn",
"[",
"1",
"]",
".",
"')'",
"]",
";",
"}",
"return",
"[",
"$",
"keyForReturn",
"=>",
"'unknown'",
"]",
";",
"}"
] | Just to keep a list of type of language as array
@return array | [
"Just",
"to",
"keep",
"a",
"list",
"of",
"type",
"of",
"language",
"as",
"array"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtypes.php#L69-L78 | train |
danielgp/common-lib | source/MySQLiByDanielGPtypes.php | MySQLiByDanielGPtypes.listOfMySQLqueryStatementType | private function listOfMySQLqueryStatementType($firstKwordWQuery)
{
$statmentsArray = $this->readTypeFromJsonFile('MySQLiStatementTypes');
return [
'keys' => array_keys($statmentsArray),
'value' => [
'Description' => $statmentsArray[$firstKwordWQuery][1],
'Type' => $statmentsArray[$firstKwordWQuery][0],
],
];
} | php | private function listOfMySQLqueryStatementType($firstKwordWQuery)
{
$statmentsArray = $this->readTypeFromJsonFile('MySQLiStatementTypes');
return [
'keys' => array_keys($statmentsArray),
'value' => [
'Description' => $statmentsArray[$firstKwordWQuery][1],
'Type' => $statmentsArray[$firstKwordWQuery][0],
],
];
} | [
"private",
"function",
"listOfMySQLqueryStatementType",
"(",
"$",
"firstKwordWQuery",
")",
"{",
"$",
"statmentsArray",
"=",
"$",
"this",
"->",
"readTypeFromJsonFile",
"(",
"'MySQLiStatementTypes'",
")",
";",
"return",
"[",
"'keys'",
"=>",
"array_keys",
"(",
"$",
"statmentsArray",
")",
",",
"'value'",
"=>",
"[",
"'Description'",
"=>",
"$",
"statmentsArray",
"[",
"$",
"firstKwordWQuery",
"]",
"[",
"1",
"]",
",",
"'Type'",
"=>",
"$",
"statmentsArray",
"[",
"$",
"firstKwordWQuery",
"]",
"[",
"0",
"]",
",",
"]",
",",
"]",
";",
"}"
] | Just to keep a list of statement types as array
@param string $firstKwordWQuery
@return array | [
"Just",
"to",
"keep",
"a",
"list",
"of",
"statement",
"types",
"as",
"array"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtypes.php#L86-L96 | train |
buflix/SimpleCollection | src/SimpleCollection/Entity/EntityAssocCollection.php | EntityAssocCollection.add | public function add($oEntity)
{
$this->checkClass($oEntity);
$this->values[$oEntity->getCollectionIndex()] = $oEntity;
return $this;
} | php | public function add($oEntity)
{
$this->checkClass($oEntity);
$this->values[$oEntity->getCollectionIndex()] = $oEntity;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"oEntity",
")",
"{",
"$",
"this",
"->",
"checkClass",
"(",
"$",
"oEntity",
")",
";",
"$",
"this",
"->",
"values",
"[",
"$",
"oEntity",
"->",
"getCollectionIndex",
"(",
")",
"]",
"=",
"$",
"oEntity",
";",
"return",
"$",
"this",
";",
"}"
] | Add Entity to collection
@param AssocEntityInterface $oEntity
@return $this | [
"Add",
"Entity",
"to",
"collection"
] | 405504d8be6415a872a5a49ce8223c22a932831a | https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/Entity/EntityAssocCollection.php#L56-L62 | train |
buflix/SimpleCollection | src/SimpleCollection/Entity/EntityAssocCollection.php | EntityAssocCollection.indexEntities | protected function indexEntities(array $aEntities)
{
$aIndexEntities = array();
foreach ($aEntities as $oEntity) {
$aIndexEntities[$oEntity->getCollectionIndex()] = $oEntity;
}
return $aIndexEntities;
} | php | protected function indexEntities(array $aEntities)
{
$aIndexEntities = array();
foreach ($aEntities as $oEntity) {
$aIndexEntities[$oEntity->getCollectionIndex()] = $oEntity;
}
return $aIndexEntities;
} | [
"protected",
"function",
"indexEntities",
"(",
"array",
"$",
"aEntities",
")",
"{",
"$",
"aIndexEntities",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"aEntities",
"as",
"$",
"oEntity",
")",
"{",
"$",
"aIndexEntities",
"[",
"$",
"oEntity",
"->",
"getCollectionIndex",
"(",
")",
"]",
"=",
"$",
"oEntity",
";",
"}",
"return",
"$",
"aIndexEntities",
";",
"}"
] | Create index array
@param AssocEntityInterface[] $aEntities
@return array | [
"Create",
"index",
"array"
] | 405504d8be6415a872a5a49ce8223c22a932831a | https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/Entity/EntityAssocCollection.php#L71-L79 | train |
SlabPHP/controllers | src/Feed.php | Feed.determineFeedType | protected function determineFeedType()
{
$feedType = strtolower($this->getRoutedParameter('feedType', static::TYPE_JSON));
if ($feedType == static::TYPE_JSON) {
$this->displayResolver = static::RESOLVER_JSON;
if (empty($this->callback))
{
$this->contentType = static::CONTENT_TYPE_JSON;
}
else
{
$this->contentType = static::CONTENT_TYPE_JSONP;
}
return;
}
if ($feedType == static::TYPE_XML)
{
$this->displayResolver = static::RESOLVER_XML;
$this->contentType = static::CONTENT_TYPE_XML;
return;
}
$this->setNotReady("Please specify a valid feed type in the parameter feedType.");
} | php | protected function determineFeedType()
{
$feedType = strtolower($this->getRoutedParameter('feedType', static::TYPE_JSON));
if ($feedType == static::TYPE_JSON) {
$this->displayResolver = static::RESOLVER_JSON;
if (empty($this->callback))
{
$this->contentType = static::CONTENT_TYPE_JSON;
}
else
{
$this->contentType = static::CONTENT_TYPE_JSONP;
}
return;
}
if ($feedType == static::TYPE_XML)
{
$this->displayResolver = static::RESOLVER_XML;
$this->contentType = static::CONTENT_TYPE_XML;
return;
}
$this->setNotReady("Please specify a valid feed type in the parameter feedType.");
} | [
"protected",
"function",
"determineFeedType",
"(",
")",
"{",
"$",
"feedType",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"getRoutedParameter",
"(",
"'feedType'",
",",
"static",
"::",
"TYPE_JSON",
")",
")",
";",
"if",
"(",
"$",
"feedType",
"==",
"static",
"::",
"TYPE_JSON",
")",
"{",
"$",
"this",
"->",
"displayResolver",
"=",
"static",
"::",
"RESOLVER_JSON",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"callback",
")",
")",
"{",
"$",
"this",
"->",
"contentType",
"=",
"static",
"::",
"CONTENT_TYPE_JSON",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"contentType",
"=",
"static",
"::",
"CONTENT_TYPE_JSONP",
";",
"}",
"return",
";",
"}",
"if",
"(",
"$",
"feedType",
"==",
"static",
"::",
"TYPE_XML",
")",
"{",
"$",
"this",
"->",
"displayResolver",
"=",
"static",
"::",
"RESOLVER_XML",
";",
"$",
"this",
"->",
"contentType",
"=",
"static",
"::",
"CONTENT_TYPE_XML",
";",
"return",
";",
"}",
"$",
"this",
"->",
"setNotReady",
"(",
"\"Please specify a valid feed type in the parameter feedType.\"",
")",
";",
"}"
] | Determine feed type | [
"Determine",
"feed",
"type"
] | a1c4fded0265100a85904dd664b972a7f8687652 | https://github.com/SlabPHP/controllers/blob/a1c4fded0265100a85904dd664b972a7f8687652/src/Feed.php#L59-L84 | train |
covex-nn/JooS | src/JooS/Log/Log.php | Log.getWriters | public static function getWriters()
{
if (is_null(self::$_writers)) {
$writers = Config::getInstance("JooS_Log")->writers;
/* @var $writers JooS_Config */
if (!is_null($writers)) {
foreach ($writers->valueOf() as $name) {
$name = ucfirst(strtolower($name));
$className = Loader::getClassName(__NAMESPACE__ . "\\", $name);
if (Loader::loadClass($className)) {
$writer = new $className();
if ($writer instanceof Log_Interface) {
self::addWriter($writer);
}
}
}
} else {
self::$_writers = array();
}
}
return self::$_writers;
} | php | public static function getWriters()
{
if (is_null(self::$_writers)) {
$writers = Config::getInstance("JooS_Log")->writers;
/* @var $writers JooS_Config */
if (!is_null($writers)) {
foreach ($writers->valueOf() as $name) {
$name = ucfirst(strtolower($name));
$className = Loader::getClassName(__NAMESPACE__ . "\\", $name);
if (Loader::loadClass($className)) {
$writer = new $className();
if ($writer instanceof Log_Interface) {
self::addWriter($writer);
}
}
}
} else {
self::$_writers = array();
}
}
return self::$_writers;
} | [
"public",
"static",
"function",
"getWriters",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"_writers",
")",
")",
"{",
"$",
"writers",
"=",
"Config",
"::",
"getInstance",
"(",
"\"JooS_Log\"",
")",
"->",
"writers",
";",
"/* @var $writers JooS_Config */",
"if",
"(",
"!",
"is_null",
"(",
"$",
"writers",
")",
")",
"{",
"foreach",
"(",
"$",
"writers",
"->",
"valueOf",
"(",
")",
"as",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"name",
")",
")",
";",
"$",
"className",
"=",
"Loader",
"::",
"getClassName",
"(",
"__NAMESPACE__",
".",
"\"\\\\\"",
",",
"$",
"name",
")",
";",
"if",
"(",
"Loader",
"::",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"$",
"writer",
"=",
"new",
"$",
"className",
"(",
")",
";",
"if",
"(",
"$",
"writer",
"instanceof",
"Log_Interface",
")",
"{",
"self",
"::",
"addWriter",
"(",
"$",
"writer",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"self",
"::",
"$",
"_writers",
"=",
"array",
"(",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"_writers",
";",
"}"
] | Return log writers
@return array | [
"Return",
"log",
"writers"
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Log/Log.php#L45-L66 | train |
covex-nn/JooS | src/JooS/Log/Log.php | Log.addWriter | public static function addWriter(Log_Interface $writer)
{
if (is_null(self::$_writers)) {
self::$_writers = array();
}
$key = get_class($writer);
if (!isset(self::$_writers[$key])) {
self::$_writers[$key] = $writer;
$result = true;
} else {
$result = false;
}
return $result;
} | php | public static function addWriter(Log_Interface $writer)
{
if (is_null(self::$_writers)) {
self::$_writers = array();
}
$key = get_class($writer);
if (!isset(self::$_writers[$key])) {
self::$_writers[$key] = $writer;
$result = true;
} else {
$result = false;
}
return $result;
} | [
"public",
"static",
"function",
"addWriter",
"(",
"Log_Interface",
"$",
"writer",
")",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"_writers",
")",
")",
"{",
"self",
"::",
"$",
"_writers",
"=",
"array",
"(",
")",
";",
"}",
"$",
"key",
"=",
"get_class",
"(",
"$",
"writer",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_writers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_writers",
"[",
"$",
"key",
"]",
"=",
"$",
"writer",
";",
"$",
"result",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Add new writer
@param Log_Interface $writer Log writer
@return boolean | [
"Add",
"new",
"writer"
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Log/Log.php#L75-L90 | train |
linpax/microphp-framework | src/cli/Console.php | Console.action | public function action($name)
{
$command = '\\App\\Consoles\\'.ucfirst($name).'ConsoleCommand';
$command = class_exists($command) ? $command : '\\Micro\\Cli\\Consoles\\'.ucfirst($name).'ConsoleCommand';
if (!class_exists($command)) {
throw new Exception('Command `'.$name.'` not found');
}
/** @var ConsoleCommand $command */
$command = new $command();
$command->execute();
$response = (new ResponseInjector)->build();
$response = $response->withHeader('status', (string)(int)$command->result);
$stream = $response->getBody();
$stream->write($command->message);
return $response->withBody($stream);
} | php | public function action($name)
{
$command = '\\App\\Consoles\\'.ucfirst($name).'ConsoleCommand';
$command = class_exists($command) ? $command : '\\Micro\\Cli\\Consoles\\'.ucfirst($name).'ConsoleCommand';
if (!class_exists($command)) {
throw new Exception('Command `'.$name.'` not found');
}
/** @var ConsoleCommand $command */
$command = new $command();
$command->execute();
$response = (new ResponseInjector)->build();
$response = $response->withHeader('status', (string)(int)$command->result);
$stream = $response->getBody();
$stream->write($command->message);
return $response->withBody($stream);
} | [
"public",
"function",
"action",
"(",
"$",
"name",
")",
"{",
"$",
"command",
"=",
"'\\\\App\\\\Consoles\\\\'",
".",
"ucfirst",
"(",
"$",
"name",
")",
".",
"'ConsoleCommand'",
";",
"$",
"command",
"=",
"class_exists",
"(",
"$",
"command",
")",
"?",
"$",
"command",
":",
"'\\\\Micro\\\\Cli\\\\Consoles\\\\'",
".",
"ucfirst",
"(",
"$",
"name",
")",
".",
"'ConsoleCommand'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"command",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Command `'",
".",
"$",
"name",
".",
"'` not found'",
")",
";",
"}",
"/** @var ConsoleCommand $command */",
"$",
"command",
"=",
"new",
"$",
"command",
"(",
")",
";",
"$",
"command",
"->",
"execute",
"(",
")",
";",
"$",
"response",
"=",
"(",
"new",
"ResponseInjector",
")",
"->",
"build",
"(",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"'status'",
",",
"(",
"string",
")",
"(",
"int",
")",
"$",
"command",
"->",
"result",
")",
";",
"$",
"stream",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"$",
"stream",
"->",
"write",
"(",
"$",
"command",
"->",
"message",
")",
";",
"return",
"$",
"response",
"->",
"withBody",
"(",
"$",
"stream",
")",
";",
"}"
] | Run action of console command by name
@access public
@param string $name Command name
@return ResponseInterface
@throws \RuntimeException|\InvalidArgumentException|Exception | [
"Run",
"action",
"of",
"console",
"command",
"by",
"name"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/cli/Console.php#L48-L68 | train |
damianociarla/DCSSecurityCoreBundle | src/Event/AuthenticatedTokenEvent.php | AuthenticatedTokenEvent.regenerateUsernamePasswordTokenWithRoles | public function regenerateUsernamePasswordTokenWithRoles(array $roles, $mergeWithExistingRoles = true)
{
$user = $this->token->getUser();
$credentials = $this->token->getCredentials();
$providerKey = $this->token->getProviderKey();
if ($mergeWithExistingRoles) {
$roles = array_merge($roles, $this->token->getRoles());
}
$this->token = new UsernamePasswordToken($user, $credentials, $providerKey, $roles);
} | php | public function regenerateUsernamePasswordTokenWithRoles(array $roles, $mergeWithExistingRoles = true)
{
$user = $this->token->getUser();
$credentials = $this->token->getCredentials();
$providerKey = $this->token->getProviderKey();
if ($mergeWithExistingRoles) {
$roles = array_merge($roles, $this->token->getRoles());
}
$this->token = new UsernamePasswordToken($user, $credentials, $providerKey, $roles);
} | [
"public",
"function",
"regenerateUsernamePasswordTokenWithRoles",
"(",
"array",
"$",
"roles",
",",
"$",
"mergeWithExistingRoles",
"=",
"true",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"token",
"->",
"getUser",
"(",
")",
";",
"$",
"credentials",
"=",
"$",
"this",
"->",
"token",
"->",
"getCredentials",
"(",
")",
";",
"$",
"providerKey",
"=",
"$",
"this",
"->",
"token",
"->",
"getProviderKey",
"(",
")",
";",
"if",
"(",
"$",
"mergeWithExistingRoles",
")",
"{",
"$",
"roles",
"=",
"array_merge",
"(",
"$",
"roles",
",",
"$",
"this",
"->",
"token",
"->",
"getRoles",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"token",
"=",
"new",
"UsernamePasswordToken",
"(",
"$",
"user",
",",
"$",
"credentials",
",",
"$",
"providerKey",
",",
"$",
"roles",
")",
";",
"}"
] | Regenerate same instance of this token with another roles
@param array $roles
@param bool $mergeWithExistingRoles | [
"Regenerate",
"same",
"instance",
"of",
"this",
"token",
"with",
"another",
"roles"
] | cf061017674e6add1cb5b79389be6018f8722733 | https://github.com/damianociarla/DCSSecurityCoreBundle/blob/cf061017674e6add1cb5b79389be6018f8722733/src/Event/AuthenticatedTokenEvent.php#L47-L58 | train |
praxigento/mobi_mod_pv | Helper/Customer.php | Customer.canSeePv | public function canSeePv($gid = null)
{
$result = false;
if (is_null($gid)) {
$gid = $this->session->getCustomerGroupId();
}
if (!isset($this->cacheCanSeeByGid[$gid])) {
$item = $this->daoPvCustGroup->getById($gid);
if ($item) $result = (bool)$item->getCanSeePv();
$this->cacheCanSeeByGid[$gid] = $result;
} else {
$result = $this->cacheCanSeeByGid[$gid];
}
return $result;
} | php | public function canSeePv($gid = null)
{
$result = false;
if (is_null($gid)) {
$gid = $this->session->getCustomerGroupId();
}
if (!isset($this->cacheCanSeeByGid[$gid])) {
$item = $this->daoPvCustGroup->getById($gid);
if ($item) $result = (bool)$item->getCanSeePv();
$this->cacheCanSeeByGid[$gid] = $result;
} else {
$result = $this->cacheCanSeeByGid[$gid];
}
return $result;
} | [
"public",
"function",
"canSeePv",
"(",
"$",
"gid",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"is_null",
"(",
"$",
"gid",
")",
")",
"{",
"$",
"gid",
"=",
"$",
"this",
"->",
"session",
"->",
"getCustomerGroupId",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cacheCanSeeByGid",
"[",
"$",
"gid",
"]",
")",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"daoPvCustGroup",
"->",
"getById",
"(",
"$",
"gid",
")",
";",
"if",
"(",
"$",
"item",
")",
"$",
"result",
"=",
"(",
"bool",
")",
"$",
"item",
"->",
"getCanSeePv",
"(",
")",
";",
"$",
"this",
"->",
"cacheCanSeeByGid",
"[",
"$",
"gid",
"]",
"=",
"$",
"result",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"cacheCanSeeByGid",
"[",
"$",
"gid",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Cached accessor for 'Can See PV' flag.
@param int|null $gid customer group ID, if 'null' - group for current customer is used.
@return bool | [
"Cached",
"accessor",
"for",
"Can",
"See",
"PV",
"flag",
"."
] | d1540b7e94264527006e8b9fa68904a72a63928e | https://github.com/praxigento/mobi_mod_pv/blob/d1540b7e94264527006e8b9fa68904a72a63928e/Helper/Customer.php#L34-L48 | train |
taylornetwork/make-html | src/HTMLGenerator.php | HTMLGenerator.makeLinks | public function makeLinks($text)
{
$pattern = '~(?xi)
(?:
((ht|f)tps?://) # scheme://
| # or
www\d{0,3}\. # "www.", "www1.", "www2." ... "www999."
| # or
www\- # "www-"
| # or
[a-z0-9.\-]+\.[a-z]{2,4}(?=/) # looks like domain name followed by a slash
)
(?: # Zero or more:
[^\s()<>]+ # Run of non-space, non-()<>
| # or
\(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
)*
(?: # End with:
\(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
| # or
[^\s`!\-()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars
)
~';
$callback = function ($urlMatch) {
$url = $urlMatch[0];
// Look for protocol
preg_match('~^(ht|f)tps?://~', $url, $protocolMatch);
if ($protocolMatch) {
$protocol = $protocolMatch[0];
} else {
$protocol = 'http://';
$url = $protocol.$url;
}
// Start building caption, remove protocol from url
$noProtocol = substr($url, strlen($protocol));
// Check for a variation of www
preg_match('/www\d{0,3}\./', $noProtocol, $wwwMatch);
if ($wwwMatch) {
// Remove www
$noProtocol = substr($noProtocol, strlen($wwwMatch[0]));
}
// Only use domain name as caption
$caption = explode('/', $noProtocol)[0];
return $this->generateTag('a', $this->linkAttributes + ['href' => $url, $this->externalKey => $caption]);
};
return preg_replace_callback($pattern, $callback, $text);
} | php | public function makeLinks($text)
{
$pattern = '~(?xi)
(?:
((ht|f)tps?://) # scheme://
| # or
www\d{0,3}\. # "www.", "www1.", "www2." ... "www999."
| # or
www\- # "www-"
| # or
[a-z0-9.\-]+\.[a-z]{2,4}(?=/) # looks like domain name followed by a slash
)
(?: # Zero or more:
[^\s()<>]+ # Run of non-space, non-()<>
| # or
\(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
)*
(?: # End with:
\(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
| # or
[^\s`!\-()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars
)
~';
$callback = function ($urlMatch) {
$url = $urlMatch[0];
// Look for protocol
preg_match('~^(ht|f)tps?://~', $url, $protocolMatch);
if ($protocolMatch) {
$protocol = $protocolMatch[0];
} else {
$protocol = 'http://';
$url = $protocol.$url;
}
// Start building caption, remove protocol from url
$noProtocol = substr($url, strlen($protocol));
// Check for a variation of www
preg_match('/www\d{0,3}\./', $noProtocol, $wwwMatch);
if ($wwwMatch) {
// Remove www
$noProtocol = substr($noProtocol, strlen($wwwMatch[0]));
}
// Only use domain name as caption
$caption = explode('/', $noProtocol)[0];
return $this->generateTag('a', $this->linkAttributes + ['href' => $url, $this->externalKey => $caption]);
};
return preg_replace_callback($pattern, $callback, $text);
} | [
"public",
"function",
"makeLinks",
"(",
"$",
"text",
")",
"{",
"$",
"pattern",
"=",
"'~(?xi)\n (?:\n ((ht|f)tps?://) # scheme://\n | # or\n www\\d{0,3}\\. # \"www.\", \"www1.\", \"www2.\" ... \"www999.\"\n | # or\n www\\- # \"www-\"\n | # or\n [a-z0-9.\\-]+\\.[a-z]{2,4}(?=/) # looks like domain name followed by a slash\n )\n (?: # Zero or more:\n [^\\s()<>]+ # Run of non-space, non-()<>\n | # or\n \\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\) # balanced parens, up to 2 levels\n )*\n (?: # End with:\n \\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\) # balanced parens, up to 2 levels\n | # or\n [^\\s`!\\-()\\[\\]{};:\\'\".,<>?«»“”‘’] # not a space or one of these punct chars\n )\n ~'",
";",
"$",
"callback",
"=",
"function",
"(",
"$",
"urlMatch",
")",
"{",
"$",
"url",
"=",
"$",
"urlMatch",
"[",
"0",
"]",
";",
"// Look for protocol",
"preg_match",
"(",
"'~^(ht|f)tps?://~'",
",",
"$",
"url",
",",
"$",
"protocolMatch",
")",
";",
"if",
"(",
"$",
"protocolMatch",
")",
"{",
"$",
"protocol",
"=",
"$",
"protocolMatch",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"protocol",
"=",
"'http://'",
";",
"$",
"url",
"=",
"$",
"protocol",
".",
"$",
"url",
";",
"}",
"// Start building caption, remove protocol from url",
"$",
"noProtocol",
"=",
"substr",
"(",
"$",
"url",
",",
"strlen",
"(",
"$",
"protocol",
")",
")",
";",
"// Check for a variation of www",
"preg_match",
"(",
"'/www\\d{0,3}\\./'",
",",
"$",
"noProtocol",
",",
"$",
"wwwMatch",
")",
";",
"if",
"(",
"$",
"wwwMatch",
")",
"{",
"// Remove www",
"$",
"noProtocol",
"=",
"substr",
"(",
"$",
"noProtocol",
",",
"strlen",
"(",
"$",
"wwwMatch",
"[",
"0",
"]",
")",
")",
";",
"}",
"// Only use domain name as caption",
"$",
"caption",
"=",
"explode",
"(",
"'/'",
",",
"$",
"noProtocol",
")",
"[",
"0",
"]",
";",
"return",
"$",
"this",
"->",
"generateTag",
"(",
"'a'",
",",
"$",
"this",
"->",
"linkAttributes",
"+",
"[",
"'href'",
"=>",
"$",
"url",
",",
"$",
"this",
"->",
"externalKey",
"=>",
"$",
"caption",
"]",
")",
";",
"}",
";",
"return",
"preg_replace_callback",
"(",
"$",
"pattern",
",",
"$",
"callback",
",",
"$",
"text",
")",
";",
"}"
] | Make the links clickable.
@param $text
@return string | [
"Make",
"the",
"links",
"clickable",
"."
] | 216308d5ba8c9d2412dc787fb6db1a837c20b820 | https://github.com/taylornetwork/make-html/blob/216308d5ba8c9d2412dc787fb6db1a837c20b820/src/HTMLGenerator.php#L80-L135 | train |
taylornetwork/make-html | src/HTMLGenerator.php | HTMLGenerator.makeHTML | public function makeHTML($text)
{
$html = $text;
if ($this->defaultActions['makeLinks']) {
$html = $this->makeLinks($html);
}
if ($this->defaultActions['convertLineEndings']) {
$html = $this->convertLineEndings($html);
}
return $html;
} | php | public function makeHTML($text)
{
$html = $text;
if ($this->defaultActions['makeLinks']) {
$html = $this->makeLinks($html);
}
if ($this->defaultActions['convertLineEndings']) {
$html = $this->convertLineEndings($html);
}
return $html;
} | [
"public",
"function",
"makeHTML",
"(",
"$",
"text",
")",
"{",
"$",
"html",
"=",
"$",
"text",
";",
"if",
"(",
"$",
"this",
"->",
"defaultActions",
"[",
"'makeLinks'",
"]",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"makeLinks",
"(",
"$",
"html",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"defaultActions",
"[",
"'convertLineEndings'",
"]",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"convertLineEndings",
"(",
"$",
"html",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] | The main function to use instead of calling everything individually.
@param $text
@return string | [
"The",
"main",
"function",
"to",
"use",
"instead",
"of",
"calling",
"everything",
"individually",
"."
] | 216308d5ba8c9d2412dc787fb6db1a837c20b820 | https://github.com/taylornetwork/make-html/blob/216308d5ba8c9d2412dc787fb6db1a837c20b820/src/HTMLGenerator.php#L156-L169 | train |
taylornetwork/make-html | src/HTMLGenerator.php | HTMLGenerator.generateTag | public function generateTag($tag, $attributes, $closeTag = true)
{
$openPattern = replace_variables($this->openTagPattern, compact('tag'));
$external = '';
if (in_array($tag, $this->voidTags) && !empty($this->voidTagPattern) && $this->voidTagPattern != $this->openTagPattern) {
$openPattern = replace_variables($this->voidTagPattern, compact('tag'));
}
if (array_key_exists($this->externalKey, $attributes)) {
$external = $attributes[$this->externalKey];
unset($attributes[$this->externalKey]);
}
$html = replace_variables($openPattern, ['attr' => associative_implode('=', ' ', $attributes)]);
if (!in_array($tag, $this->voidTags)) {
$html .= $external;
if ($closeTag) {
$html .= $this->closeTag($tag);
}
}
return $html;
} | php | public function generateTag($tag, $attributes, $closeTag = true)
{
$openPattern = replace_variables($this->openTagPattern, compact('tag'));
$external = '';
if (in_array($tag, $this->voidTags) && !empty($this->voidTagPattern) && $this->voidTagPattern != $this->openTagPattern) {
$openPattern = replace_variables($this->voidTagPattern, compact('tag'));
}
if (array_key_exists($this->externalKey, $attributes)) {
$external = $attributes[$this->externalKey];
unset($attributes[$this->externalKey]);
}
$html = replace_variables($openPattern, ['attr' => associative_implode('=', ' ', $attributes)]);
if (!in_array($tag, $this->voidTags)) {
$html .= $external;
if ($closeTag) {
$html .= $this->closeTag($tag);
}
}
return $html;
} | [
"public",
"function",
"generateTag",
"(",
"$",
"tag",
",",
"$",
"attributes",
",",
"$",
"closeTag",
"=",
"true",
")",
"{",
"$",
"openPattern",
"=",
"replace_variables",
"(",
"$",
"this",
"->",
"openTagPattern",
",",
"compact",
"(",
"'tag'",
")",
")",
";",
"$",
"external",
"=",
"''",
";",
"if",
"(",
"in_array",
"(",
"$",
"tag",
",",
"$",
"this",
"->",
"voidTags",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"voidTagPattern",
")",
"&&",
"$",
"this",
"->",
"voidTagPattern",
"!=",
"$",
"this",
"->",
"openTagPattern",
")",
"{",
"$",
"openPattern",
"=",
"replace_variables",
"(",
"$",
"this",
"->",
"voidTagPattern",
",",
"compact",
"(",
"'tag'",
")",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"externalKey",
",",
"$",
"attributes",
")",
")",
"{",
"$",
"external",
"=",
"$",
"attributes",
"[",
"$",
"this",
"->",
"externalKey",
"]",
";",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"this",
"->",
"externalKey",
"]",
")",
";",
"}",
"$",
"html",
"=",
"replace_variables",
"(",
"$",
"openPattern",
",",
"[",
"'attr'",
"=>",
"associative_implode",
"(",
"'='",
",",
"' '",
",",
"$",
"attributes",
")",
"]",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"tag",
",",
"$",
"this",
"->",
"voidTags",
")",
")",
"{",
"$",
"html",
".=",
"$",
"external",
";",
"if",
"(",
"$",
"closeTag",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"closeTag",
"(",
"$",
"tag",
")",
";",
"}",
"}",
"return",
"$",
"html",
";",
"}"
] | Generate an HTML tag.
@param $tag
@param $attributes
@param $closeTag
@return string | [
"Generate",
"an",
"HTML",
"tag",
"."
] | 216308d5ba8c9d2412dc787fb6db1a837c20b820 | https://github.com/taylornetwork/make-html/blob/216308d5ba8c9d2412dc787fb6db1a837c20b820/src/HTMLGenerator.php#L180-L205 | train |
taylornetwork/make-html | src/HTMLGenerator.php | HTMLGenerator.closeTag | public function closeTag($tag)
{
if (!in_array($tag, $this->voidTags)) {
return replace_variables($this->closeTagPattern, compact('tag'));
}
return '';
} | php | public function closeTag($tag)
{
if (!in_array($tag, $this->voidTags)) {
return replace_variables($this->closeTagPattern, compact('tag'));
}
return '';
} | [
"public",
"function",
"closeTag",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"tag",
",",
"$",
"this",
"->",
"voidTags",
")",
")",
"{",
"return",
"replace_variables",
"(",
"$",
"this",
"->",
"closeTagPattern",
",",
"compact",
"(",
"'tag'",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
] | Close an HTML tag.
@param $tag
@return string | [
"Close",
"an",
"HTML",
"tag",
"."
] | 216308d5ba8c9d2412dc787fb6db1a837c20b820 | https://github.com/taylornetwork/make-html/blob/216308d5ba8c9d2412dc787fb6db1a837c20b820/src/HTMLGenerator.php#L214-L221 | train |
jenskooij/cloudcontrol | src/cc/application/ApplicationRenderer.php | ApplicationRenderer.setCachingHeaders | public function setCachingHeaders($intervalString = CachableBaseComponent::DEFAULT_MAXAGE)
{
$expires = new \DateTime();
$interval = new \DateInterval($intervalString);
$maxAge = date_create('@0')->add($interval)->getTimestamp();
$expires = $expires->add($interval);
ResponseHeaders::add(ResponseHeaders::HEADER_EXPIRES, gmdate('D, d M Y H:i:s \G\M\T', $expires->getTimestamp()));
ResponseHeaders::add(ResponseHeaders::HEADER_CACHE_CONTROL, 'max-age=' . $maxAge);
ResponseHeaders::add(ResponseHeaders::HEADER_PRAGMA, ResponseHeaders::HEADER_PRAGMA_CONTENT_CACHE);
} | php | public function setCachingHeaders($intervalString = CachableBaseComponent::DEFAULT_MAXAGE)
{
$expires = new \DateTime();
$interval = new \DateInterval($intervalString);
$maxAge = date_create('@0')->add($interval)->getTimestamp();
$expires = $expires->add($interval);
ResponseHeaders::add(ResponseHeaders::HEADER_EXPIRES, gmdate('D, d M Y H:i:s \G\M\T', $expires->getTimestamp()));
ResponseHeaders::add(ResponseHeaders::HEADER_CACHE_CONTROL, 'max-age=' . $maxAge);
ResponseHeaders::add(ResponseHeaders::HEADER_PRAGMA, ResponseHeaders::HEADER_PRAGMA_CONTENT_CACHE);
} | [
"public",
"function",
"setCachingHeaders",
"(",
"$",
"intervalString",
"=",
"CachableBaseComponent",
"::",
"DEFAULT_MAXAGE",
")",
"{",
"$",
"expires",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"interval",
"=",
"new",
"\\",
"DateInterval",
"(",
"$",
"intervalString",
")",
";",
"$",
"maxAge",
"=",
"date_create",
"(",
"'@0'",
")",
"->",
"add",
"(",
"$",
"interval",
")",
"->",
"getTimestamp",
"(",
")",
";",
"$",
"expires",
"=",
"$",
"expires",
"->",
"add",
"(",
"$",
"interval",
")",
";",
"ResponseHeaders",
"::",
"add",
"(",
"ResponseHeaders",
"::",
"HEADER_EXPIRES",
",",
"gmdate",
"(",
"'D, d M Y H:i:s \\G\\M\\T'",
",",
"$",
"expires",
"->",
"getTimestamp",
"(",
")",
")",
")",
";",
"ResponseHeaders",
"::",
"add",
"(",
"ResponseHeaders",
"::",
"HEADER_CACHE_CONTROL",
",",
"'max-age='",
".",
"$",
"maxAge",
")",
";",
"ResponseHeaders",
"::",
"add",
"(",
"ResponseHeaders",
"::",
"HEADER_PRAGMA",
",",
"ResponseHeaders",
"::",
"HEADER_PRAGMA_CONTENT_CACHE",
")",
";",
"}"
] | Set the default caching of pages
@param string $intervalString
@throws \Exception | [
"Set",
"the",
"default",
"caching",
"of",
"pages"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/cc/application/ApplicationRenderer.php#L67-L76 | train |
jenskooij/cloudcontrol | src/cc/application/ApplicationRenderer.php | ApplicationRenderer.setNotCachingHeaders | public function setNotCachingHeaders()
{
ResponseHeaders::add(ResponseHeaders::HEADER_CACHE_CONTROL, ResponseHeaders::HEADER_CACHE_CONTROL_CONTENT_NO_STORE_NO_CACHE_MUST_REVALIDATE_MAX_AGE_0);
ResponseHeaders::add(ResponseHeaders::HEADER_PRAGMA, ResponseHeaders::HEADER_PRAGMA_CONTENT_NO_CACHE);
} | php | public function setNotCachingHeaders()
{
ResponseHeaders::add(ResponseHeaders::HEADER_CACHE_CONTROL, ResponseHeaders::HEADER_CACHE_CONTROL_CONTENT_NO_STORE_NO_CACHE_MUST_REVALIDATE_MAX_AGE_0);
ResponseHeaders::add(ResponseHeaders::HEADER_PRAGMA, ResponseHeaders::HEADER_PRAGMA_CONTENT_NO_CACHE);
} | [
"public",
"function",
"setNotCachingHeaders",
"(",
")",
"{",
"ResponseHeaders",
"::",
"add",
"(",
"ResponseHeaders",
"::",
"HEADER_CACHE_CONTROL",
",",
"ResponseHeaders",
"::",
"HEADER_CACHE_CONTROL_CONTENT_NO_STORE_NO_CACHE_MUST_REVALIDATE_MAX_AGE_0",
")",
";",
"ResponseHeaders",
"::",
"add",
"(",
"ResponseHeaders",
"::",
"HEADER_PRAGMA",
",",
"ResponseHeaders",
"::",
"HEADER_PRAGMA_CONTENT_NO_CACHE",
")",
";",
"}"
] | Set non caching
@throws \Exception | [
"Set",
"non",
"caching"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/cc/application/ApplicationRenderer.php#L82-L86 | train |
koolkode/meta | src/Annotation/AnnotationLexer.php | AnnotationLexer.tokenize | public function tokenize($input)
{
$tokens = [];
$exp = ltrim($input);
for($length = strlen($exp), $i = 0; $i < $length; $i++)
{
if(trim($exp[$i]) == '')
{
continue;
}
if(NULL !== ($token = $this->getTerminalToken($exp, $i)))
{
$tokens[] = $token;
continue;
}
if(NULL !== ($token = $this->getStringToken($exp, $length, $i)))
{
$tokens[] = $token;
continue;
}
$sub = substr($exp, $i);
$m = NULL;
if(preg_match(self::PATTERN_DECIMAL, $sub, $m))
{
$tokens[] = $this->getDecimalToken($m);
$i += strlen($m[1]) - 1;
continue;
}
if(preg_match(self::PATTERN_INTEGER, $sub, $m))
{
$tokens[] = $this->getIntegerToken($m);
$i += strlen($m[1]) - 1;
continue;
}
if(preg_match(self::PATTERN_IDENTIFIER, $sub, $m))
{
$tokens[] = $this->getIdentifierToken($m);
$i += strlen($m[0]) - 1;
continue;
}
}
return new AnnotationTokenSequence($tokens);
} | php | public function tokenize($input)
{
$tokens = [];
$exp = ltrim($input);
for($length = strlen($exp), $i = 0; $i < $length; $i++)
{
if(trim($exp[$i]) == '')
{
continue;
}
if(NULL !== ($token = $this->getTerminalToken($exp, $i)))
{
$tokens[] = $token;
continue;
}
if(NULL !== ($token = $this->getStringToken($exp, $length, $i)))
{
$tokens[] = $token;
continue;
}
$sub = substr($exp, $i);
$m = NULL;
if(preg_match(self::PATTERN_DECIMAL, $sub, $m))
{
$tokens[] = $this->getDecimalToken($m);
$i += strlen($m[1]) - 1;
continue;
}
if(preg_match(self::PATTERN_INTEGER, $sub, $m))
{
$tokens[] = $this->getIntegerToken($m);
$i += strlen($m[1]) - 1;
continue;
}
if(preg_match(self::PATTERN_IDENTIFIER, $sub, $m))
{
$tokens[] = $this->getIdentifierToken($m);
$i += strlen($m[0]) - 1;
continue;
}
}
return new AnnotationTokenSequence($tokens);
} | [
"public",
"function",
"tokenize",
"(",
"$",
"input",
")",
"{",
"$",
"tokens",
"=",
"[",
"]",
";",
"$",
"exp",
"=",
"ltrim",
"(",
"$",
"input",
")",
";",
"for",
"(",
"$",
"length",
"=",
"strlen",
"(",
"$",
"exp",
")",
",",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"exp",
"[",
"$",
"i",
"]",
")",
"==",
"''",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"NULL",
"!==",
"(",
"$",
"token",
"=",
"$",
"this",
"->",
"getTerminalToken",
"(",
"$",
"exp",
",",
"$",
"i",
")",
")",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"token",
";",
"continue",
";",
"}",
"if",
"(",
"NULL",
"!==",
"(",
"$",
"token",
"=",
"$",
"this",
"->",
"getStringToken",
"(",
"$",
"exp",
",",
"$",
"length",
",",
"$",
"i",
")",
")",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"token",
";",
"continue",
";",
"}",
"$",
"sub",
"=",
"substr",
"(",
"$",
"exp",
",",
"$",
"i",
")",
";",
"$",
"m",
"=",
"NULL",
";",
"if",
"(",
"preg_match",
"(",
"self",
"::",
"PATTERN_DECIMAL",
",",
"$",
"sub",
",",
"$",
"m",
")",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"this",
"->",
"getDecimalToken",
"(",
"$",
"m",
")",
";",
"$",
"i",
"+=",
"strlen",
"(",
"$",
"m",
"[",
"1",
"]",
")",
"-",
"1",
";",
"continue",
";",
"}",
"if",
"(",
"preg_match",
"(",
"self",
"::",
"PATTERN_INTEGER",
",",
"$",
"sub",
",",
"$",
"m",
")",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"this",
"->",
"getIntegerToken",
"(",
"$",
"m",
")",
";",
"$",
"i",
"+=",
"strlen",
"(",
"$",
"m",
"[",
"1",
"]",
")",
"-",
"1",
";",
"continue",
";",
"}",
"if",
"(",
"preg_match",
"(",
"self",
"::",
"PATTERN_IDENTIFIER",
",",
"$",
"sub",
",",
"$",
"m",
")",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"this",
"->",
"getIdentifierToken",
"(",
"$",
"m",
")",
";",
"$",
"i",
"+=",
"strlen",
"(",
"$",
"m",
"[",
"0",
"]",
")",
"-",
"1",
";",
"continue",
";",
"}",
"}",
"return",
"new",
"AnnotationTokenSequence",
"(",
"$",
"tokens",
")",
";",
"}"
] | Tokenize the given source string into annotation tokens and returns
the created token sequence.
@param string $input
@return AnnotationTokenSequence | [
"Tokenize",
"the",
"given",
"source",
"string",
"into",
"annotation",
"tokens",
"and",
"returns",
"the",
"created",
"token",
"sequence",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/Annotation/AnnotationLexer.php#L61-L116 | train |
koolkode/meta | src/Annotation/AnnotationLexer.php | AnnotationLexer.getStringToken | protected function getStringToken($exp, $length, & $i)
{
if($exp[$i] == '"' || $exp[$i] == "'")
{
$delim = $exp[$i++];
$buffer = '';
$terminated = false;
$escaped = false;
for(; $i < $length; $i++)
{
if($exp[$i] == '\\')
{
$escaped = !$escaped;
}
elseif($exp[$i] == $delim && !$escaped)
{
$terminated = true;
break;
}
else
{
$escaped = false;
}
$buffer .= $exp[$i];
}
if($terminated)
{
return new AnnotationToken(AnnotationToken::T_STRING, str_replace('\\' . $delim, $delim, $buffer));
}
}
} | php | protected function getStringToken($exp, $length, & $i)
{
if($exp[$i] == '"' || $exp[$i] == "'")
{
$delim = $exp[$i++];
$buffer = '';
$terminated = false;
$escaped = false;
for(; $i < $length; $i++)
{
if($exp[$i] == '\\')
{
$escaped = !$escaped;
}
elseif($exp[$i] == $delim && !$escaped)
{
$terminated = true;
break;
}
else
{
$escaped = false;
}
$buffer .= $exp[$i];
}
if($terminated)
{
return new AnnotationToken(AnnotationToken::T_STRING, str_replace('\\' . $delim, $delim, $buffer));
}
}
} | [
"protected",
"function",
"getStringToken",
"(",
"$",
"exp",
",",
"$",
"length",
",",
"&",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"exp",
"[",
"$",
"i",
"]",
"==",
"'\"'",
"||",
"$",
"exp",
"[",
"$",
"i",
"]",
"==",
"\"'\"",
")",
"{",
"$",
"delim",
"=",
"$",
"exp",
"[",
"$",
"i",
"++",
"]",
";",
"$",
"buffer",
"=",
"''",
";",
"$",
"terminated",
"=",
"false",
";",
"$",
"escaped",
"=",
"false",
";",
"for",
"(",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"exp",
"[",
"$",
"i",
"]",
"==",
"'\\\\'",
")",
"{",
"$",
"escaped",
"=",
"!",
"$",
"escaped",
";",
"}",
"elseif",
"(",
"$",
"exp",
"[",
"$",
"i",
"]",
"==",
"$",
"delim",
"&&",
"!",
"$",
"escaped",
")",
"{",
"$",
"terminated",
"=",
"true",
";",
"break",
";",
"}",
"else",
"{",
"$",
"escaped",
"=",
"false",
";",
"}",
"$",
"buffer",
".=",
"$",
"exp",
"[",
"$",
"i",
"]",
";",
"}",
"if",
"(",
"$",
"terminated",
")",
"{",
"return",
"new",
"AnnotationToken",
"(",
"AnnotationToken",
"::",
"T_STRING",
",",
"str_replace",
"(",
"'\\\\'",
".",
"$",
"delim",
",",
"$",
"delim",
",",
"$",
"buffer",
")",
")",
";",
"}",
"}",
"}"
] | Reads a string token from the source expression.
@param string $exp
@param integer $length
@param integer $i
@return AnnotationToken <code>NULL</code> if no string token was found. | [
"Reads",
"a",
"string",
"token",
"from",
"the",
"source",
"expression",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/Annotation/AnnotationLexer.php#L164-L199 | train |
koolkode/meta | src/Annotation/AnnotationLexer.php | AnnotationLexer.getIntegerToken | protected function getIntegerToken(array $m)
{
$sign = (isset($m['sign']) && $m['sign'] == '-') ? -1 : 1;
if(isset($m['oct']) && $m['oct'] != '')
{
return new AnnotationToken(AnnotationToken::T_INTEGER, $sign * intval($m['oct'], 8));
}
if(isset($m['bin']) && $m['bin'] != '')
{
return new AnnotationToken(AnnotationToken::T_INTEGER, $sign * intval($m['bin'], 2));
}
if(isset($m['hex']) && $m['hex'] != '')
{
return new AnnotationToken(AnnotationToken::T_INTEGER, $sign * intval($m['hex'], 16));
}
return new AnnotationToken(AnnotationToken::T_INTEGER, $sign * (int)$m['dec']);
} | php | protected function getIntegerToken(array $m)
{
$sign = (isset($m['sign']) && $m['sign'] == '-') ? -1 : 1;
if(isset($m['oct']) && $m['oct'] != '')
{
return new AnnotationToken(AnnotationToken::T_INTEGER, $sign * intval($m['oct'], 8));
}
if(isset($m['bin']) && $m['bin'] != '')
{
return new AnnotationToken(AnnotationToken::T_INTEGER, $sign * intval($m['bin'], 2));
}
if(isset($m['hex']) && $m['hex'] != '')
{
return new AnnotationToken(AnnotationToken::T_INTEGER, $sign * intval($m['hex'], 16));
}
return new AnnotationToken(AnnotationToken::T_INTEGER, $sign * (int)$m['dec']);
} | [
"protected",
"function",
"getIntegerToken",
"(",
"array",
"$",
"m",
")",
"{",
"$",
"sign",
"=",
"(",
"isset",
"(",
"$",
"m",
"[",
"'sign'",
"]",
")",
"&&",
"$",
"m",
"[",
"'sign'",
"]",
"==",
"'-'",
")",
"?",
"-",
"1",
":",
"1",
";",
"if",
"(",
"isset",
"(",
"$",
"m",
"[",
"'oct'",
"]",
")",
"&&",
"$",
"m",
"[",
"'oct'",
"]",
"!=",
"''",
")",
"{",
"return",
"new",
"AnnotationToken",
"(",
"AnnotationToken",
"::",
"T_INTEGER",
",",
"$",
"sign",
"*",
"intval",
"(",
"$",
"m",
"[",
"'oct'",
"]",
",",
"8",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"m",
"[",
"'bin'",
"]",
")",
"&&",
"$",
"m",
"[",
"'bin'",
"]",
"!=",
"''",
")",
"{",
"return",
"new",
"AnnotationToken",
"(",
"AnnotationToken",
"::",
"T_INTEGER",
",",
"$",
"sign",
"*",
"intval",
"(",
"$",
"m",
"[",
"'bin'",
"]",
",",
"2",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"m",
"[",
"'hex'",
"]",
")",
"&&",
"$",
"m",
"[",
"'hex'",
"]",
"!=",
"''",
")",
"{",
"return",
"new",
"AnnotationToken",
"(",
"AnnotationToken",
"::",
"T_INTEGER",
",",
"$",
"sign",
"*",
"intval",
"(",
"$",
"m",
"[",
"'hex'",
"]",
",",
"16",
")",
")",
";",
"}",
"return",
"new",
"AnnotationToken",
"(",
"AnnotationToken",
"::",
"T_INTEGER",
",",
"$",
"sign",
"*",
"(",
"int",
")",
"$",
"m",
"[",
"'dec'",
"]",
")",
";",
"}"
] | Builds an integer token from the given match of PATTERN_INTEGER.
@param array<string> $m
@return AnnotationToken | [
"Builds",
"an",
"integer",
"token",
"from",
"the",
"given",
"match",
"of",
"PATTERN_INTEGER",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/Annotation/AnnotationLexer.php#L218-L238 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Log/LoggableTrait.php | LoggableTrait.registerLogger | public function registerLogger(LoggerInterface $logger = null, $debug = false)
{
$this->logger = $logger ?: new NullLogger();
$this->debug = $debug;
return $this;
} | php | public function registerLogger(LoggerInterface $logger = null, $debug = false)
{
$this->logger = $logger ?: new NullLogger();
$this->debug = $debug;
return $this;
} | [
"public",
"function",
"registerLogger",
"(",
"LoggerInterface",
"$",
"logger",
"=",
"null",
",",
"$",
"debug",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"logger",
"=",
"$",
"logger",
"?",
":",
"new",
"NullLogger",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"=",
"$",
"debug",
";",
"return",
"$",
"this",
";",
"}"
] | register a logger and eventually debug mode into Loggable class
@param LoggerInterface $logger
@param boolean $debug
@return self | [
"register",
"a",
"logger",
"and",
"eventually",
"debug",
"mode",
"into",
"Loggable",
"class"
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Log/LoggableTrait.php#L31-L37 | train |
jabernardo/lollipop-php | Library/SQL/BuilderTrait.php | BuilderTrait.insert | public function insert($fields) {
// Create temporary variables for
// tokenized parameter
$_tmp_fields = [];
$_tmp_values = [];
if (is_array($fields)) {
foreach ($fields as $key => $value) {
array_push($_tmp_fields, $key);
if (is_string($value)) {
array_push($_tmp_values, '\'' . addslashes($value) . '\'');
} else {
array_push($_tmp_values, $value);
}
}
$this->_fields = implode($_tmp_fields, ', ');
$this->_values = implode($_tmp_values, ', ');
} else {
return false;
}
$sql_query = 'INSERT INTO ' . $this->_table .
'(' . $this->_fields . ')' .
' VALUES(' . $this->_values . ')';
// Set the query
$this->_sql_query = $sql_query;
// Execute query
return $this;
} | php | public function insert($fields) {
// Create temporary variables for
// tokenized parameter
$_tmp_fields = [];
$_tmp_values = [];
if (is_array($fields)) {
foreach ($fields as $key => $value) {
array_push($_tmp_fields, $key);
if (is_string($value)) {
array_push($_tmp_values, '\'' . addslashes($value) . '\'');
} else {
array_push($_tmp_values, $value);
}
}
$this->_fields = implode($_tmp_fields, ', ');
$this->_values = implode($_tmp_values, ', ');
} else {
return false;
}
$sql_query = 'INSERT INTO ' . $this->_table .
'(' . $this->_fields . ')' .
' VALUES(' . $this->_values . ')';
// Set the query
$this->_sql_query = $sql_query;
// Execute query
return $this;
} | [
"public",
"function",
"insert",
"(",
"$",
"fields",
")",
"{",
"// Create temporary variables for \r",
"// tokenized parameter\r",
"$",
"_tmp_fields",
"=",
"[",
"]",
";",
"$",
"_tmp_values",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"array_push",
"(",
"$",
"_tmp_fields",
",",
"$",
"key",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"array_push",
"(",
"$",
"_tmp_values",
",",
"'\\''",
".",
"addslashes",
"(",
"$",
"value",
")",
".",
"'\\''",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"_tmp_values",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_fields",
"=",
"implode",
"(",
"$",
"_tmp_fields",
",",
"', '",
")",
";",
"$",
"this",
"->",
"_values",
"=",
"implode",
"(",
"$",
"_tmp_values",
",",
"', '",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"$",
"sql_query",
"=",
"'INSERT INTO '",
".",
"$",
"this",
"->",
"_table",
".",
"'('",
".",
"$",
"this",
"->",
"_fields",
".",
"')'",
".",
"' VALUES('",
".",
"$",
"this",
"->",
"_values",
".",
"')'",
";",
"// Set the query\r",
"$",
"this",
"->",
"_sql_query",
"=",
"$",
"sql_query",
";",
"// Execute query\r",
"return",
"$",
"this",
";",
"}"
] | Insert data to table
@param array $fields Fields to put in data
@return mixed Returns $this when insert succeed and false on failure | [
"Insert",
"data",
"to",
"table"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/SQL/BuilderTrait.php#L333-L365 | train |
jabernardo/lollipop-php | Library/SQL/BuilderTrait.php | BuilderTrait.update | public function update($fields) {
if (is_array($fields)) {
foreach ($fields as $key => $value) {
if (is_string($value)) {
array_push($this->_updates, $key . ' = \'' . addslashes($value) . '\'');
} else {
array_push($this->_updates, $key . ' = ' . $value);
}
}
} else {
return false;
}
$sql_query = 'UPDATE ' . $this->_table .
' SET ' . implode($this->_updates, ', ');
// Where statements
if (count($this->_where)) {
$sql_query .= ' WHERE ';
$sql_query .= implode($this->_where, ' AND ');
// or statements
if (count($this->_or)) {
$sql_query .= ' OR ';
$sql_query .= implode($this->_or, ' AND ');
}
}
// Set the query
$this->_sql_query = $sql_query;
return $this;
} | php | public function update($fields) {
if (is_array($fields)) {
foreach ($fields as $key => $value) {
if (is_string($value)) {
array_push($this->_updates, $key . ' = \'' . addslashes($value) . '\'');
} else {
array_push($this->_updates, $key . ' = ' . $value);
}
}
} else {
return false;
}
$sql_query = 'UPDATE ' . $this->_table .
' SET ' . implode($this->_updates, ', ');
// Where statements
if (count($this->_where)) {
$sql_query .= ' WHERE ';
$sql_query .= implode($this->_where, ' AND ');
// or statements
if (count($this->_or)) {
$sql_query .= ' OR ';
$sql_query .= implode($this->_or, ' AND ');
}
}
// Set the query
$this->_sql_query = $sql_query;
return $this;
} | [
"public",
"function",
"update",
"(",
"$",
"fields",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"_updates",
",",
"$",
"key",
".",
"' = \\''",
".",
"addslashes",
"(",
"$",
"value",
")",
".",
"'\\''",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"_updates",
",",
"$",
"key",
".",
"' = '",
".",
"$",
"value",
")",
";",
"}",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"$",
"sql_query",
"=",
"'UPDATE '",
".",
"$",
"this",
"->",
"_table",
".",
"' SET '",
".",
"implode",
"(",
"$",
"this",
"->",
"_updates",
",",
"', '",
")",
";",
"// Where statements\r",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"_where",
")",
")",
"{",
"$",
"sql_query",
".=",
"' WHERE '",
";",
"$",
"sql_query",
".=",
"implode",
"(",
"$",
"this",
"->",
"_where",
",",
"' AND '",
")",
";",
"// or statements\r",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"_or",
")",
")",
"{",
"$",
"sql_query",
".=",
"' OR '",
";",
"$",
"sql_query",
".=",
"implode",
"(",
"$",
"this",
"->",
"_or",
",",
"' AND '",
")",
";",
"}",
"}",
"// Set the query\r",
"$",
"this",
"->",
"_sql_query",
"=",
"$",
"sql_query",
";",
"return",
"$",
"this",
";",
"}"
] | Update data from table
@param array $fields Fields to put in data
@return mixed Returns $this when insert succeed and false on failure | [
"Update",
"data",
"from",
"table"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/SQL/BuilderTrait.php#L407-L439 | train |
jabernardo/lollipop-php | Library/SQL/BuilderTrait.php | BuilderTrait.asc | public function asc($fields) {
if (is_array($fields)) {
$this->_order = ' ORDER BY ' . implode($fields, ', ') . ' ASC';
} else {
$this->_order = ' ORDER BY ' . $fields . ' ASC';
}
return $this;
} | php | public function asc($fields) {
if (is_array($fields)) {
$this->_order = ' ORDER BY ' . implode($fields, ', ') . ' ASC';
} else {
$this->_order = ' ORDER BY ' . $fields . ' ASC';
}
return $this;
} | [
"public",
"function",
"asc",
"(",
"$",
"fields",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"this",
"->",
"_order",
"=",
"' ORDER BY '",
".",
"implode",
"(",
"$",
"fields",
",",
"', '",
")",
".",
"' ASC'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_order",
"=",
"' ORDER BY '",
".",
"$",
"fields",
".",
"' ASC'",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Order by ascending
@param string/array $fields | [
"Order",
"by",
"ascending"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/SQL/BuilderTrait.php#L752-L760 | train |
jabernardo/lollipop-php | Library/SQL/BuilderTrait.php | BuilderTrait.desc | public function desc($fields) {
if (is_array($fields)) {
$this->_order = ' ORDER BY ' . implode($fields, ', ') . ' DESC';
} else {
$this->_order = ' ORDER BY ' . $fields . ' DESC';
}
return $this;
} | php | public function desc($fields) {
if (is_array($fields)) {
$this->_order = ' ORDER BY ' . implode($fields, ', ') . ' DESC';
} else {
$this->_order = ' ORDER BY ' . $fields . ' DESC';
}
return $this;
} | [
"public",
"function",
"desc",
"(",
"$",
"fields",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"this",
"->",
"_order",
"=",
"' ORDER BY '",
".",
"implode",
"(",
"$",
"fields",
",",
"', '",
")",
".",
"' DESC'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_order",
"=",
"' ORDER BY '",
".",
"$",
"fields",
".",
"' DESC'",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Order by descending
@param string/array $fields | [
"Order",
"by",
"descending"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/SQL/BuilderTrait.php#L768-L776 | train |
jabernardo/lollipop-php | Library/SQL/BuilderTrait.php | BuilderTrait.leftJoin | public function leftJoin($table, $field1, $operator, $field2) {
array_push($this->_joins, ' LEFT JOIN ' . $table . ' ON ' . $field1 . ' ' . $operator . ' ' . $field2 . ' ');
return $this;
} | php | public function leftJoin($table, $field1, $operator, $field2) {
array_push($this->_joins, ' LEFT JOIN ' . $table . ' ON ' . $field1 . ' ' . $operator . ' ' . $field2 . ' ');
return $this;
} | [
"public",
"function",
"leftJoin",
"(",
"$",
"table",
",",
"$",
"field1",
",",
"$",
"operator",
",",
"$",
"field2",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"_joins",
",",
"' LEFT JOIN '",
".",
"$",
"table",
".",
"' ON '",
".",
"$",
"field1",
".",
"' '",
".",
"$",
"operator",
".",
"' '",
".",
"$",
"field2",
".",
"' '",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Left Join Tables
@param string $table Table name
@param string $field1 Table.Fieldname
@param string $operator Operator
@param string $field2 Table.Fieldname
@example leftJoin('users', 'users.id', '=', 'login.id') | [
"Left",
"Join",
"Tables"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/SQL/BuilderTrait.php#L822-L826 | train |
jabernardo/lollipop-php | Library/SQL/BuilderTrait.php | BuilderTrait.rightJoin | public function rightJoin($table, $field1, $operator, $field2) {
array_push($this->_joins, ' RIGHT JOIN ' . $table . ' ON ' . $field1 . ' ' . $operator . ' ' . $field2 . ' ');
return $this;
} | php | public function rightJoin($table, $field1, $operator, $field2) {
array_push($this->_joins, ' RIGHT JOIN ' . $table . ' ON ' . $field1 . ' ' . $operator . ' ' . $field2 . ' ');
return $this;
} | [
"public",
"function",
"rightJoin",
"(",
"$",
"table",
",",
"$",
"field1",
",",
"$",
"operator",
",",
"$",
"field2",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"_joins",
",",
"' RIGHT JOIN '",
".",
"$",
"table",
".",
"' ON '",
".",
"$",
"field1",
".",
"' '",
".",
"$",
"operator",
".",
"' '",
".",
"$",
"field2",
".",
"' '",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Right Join Tables
@param string $table Table name
@param string $field1 Table.Fieldname
@param string $operator Operator
@param string $field2 Table.Fieldname
@example rightJoin('users', 'users.id', '=', 'login.id') | [
"Right",
"Join",
"Tables"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/SQL/BuilderTrait.php#L839-L843 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SiteForm.php | SiteForm.AddSitemapActiveField | private function AddSitemapActiveField()
{
$name = 'SitemapActive';
$field = new Checkbox($name);
if (!$this->site->Exists() || $this->site->GetSitemapActive())
{
$field->SetChecked();
}
$this->AddField($field);
} | php | private function AddSitemapActiveField()
{
$name = 'SitemapActive';
$field = new Checkbox($name);
if (!$this->site->Exists() || $this->site->GetSitemapActive())
{
$field->SetChecked();
}
$this->AddField($field);
} | [
"private",
"function",
"AddSitemapActiveField",
"(",
")",
"{",
"$",
"name",
"=",
"'SitemapActive'",
";",
"$",
"field",
"=",
"new",
"Checkbox",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"site",
"->",
"Exists",
"(",
")",
"||",
"$",
"this",
"->",
"site",
"->",
"GetSitemapActive",
"(",
")",
")",
"{",
"$",
"field",
"->",
"SetChecked",
"(",
")",
";",
"}",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the sitemap active checkbox | [
"Adds",
"the",
"sitemap",
"active",
"checkbox"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SiteForm.php#L92-L101 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SiteForm.php | SiteForm.OnSuccess | protected function OnSuccess()
{
$action = Action::Update();
if (!$this->site->Exists())
{
$action = Action::Create();
$this->site->SetUser(self::Guard()->GetUser());
}
$this->site->SetName($this->Value('Name'));
$this->site->SetUrl($this->Value('Url'));
$this->site->SetBaseUrl($this->Value('BaseUrl'));
$this->site->SetLanguage(Language::Schema()->ByID($this->Value('Language')));
$this->site->SetSitemapActive((bool)$this->Value('SitemapActive'));
$this->site->SetSitemapCacheLifetime((int)$this->Value('SitemapCacheLifetime'));
$this->site->Save();
$logger = new Logger(self::Guard()->GetUser());
$logger->ReportSiteAction($this->site, $action);
if ($this->CanAssignGroup())
{
$this->SaveRights();
}
Response::Redirect(BackendRouter::ModuleUrl(new SiteList()));
} | php | protected function OnSuccess()
{
$action = Action::Update();
if (!$this->site->Exists())
{
$action = Action::Create();
$this->site->SetUser(self::Guard()->GetUser());
}
$this->site->SetName($this->Value('Name'));
$this->site->SetUrl($this->Value('Url'));
$this->site->SetBaseUrl($this->Value('BaseUrl'));
$this->site->SetLanguage(Language::Schema()->ByID($this->Value('Language')));
$this->site->SetSitemapActive((bool)$this->Value('SitemapActive'));
$this->site->SetSitemapCacheLifetime((int)$this->Value('SitemapCacheLifetime'));
$this->site->Save();
$logger = new Logger(self::Guard()->GetUser());
$logger->ReportSiteAction($this->site, $action);
if ($this->CanAssignGroup())
{
$this->SaveRights();
}
Response::Redirect(BackendRouter::ModuleUrl(new SiteList()));
} | [
"protected",
"function",
"OnSuccess",
"(",
")",
"{",
"$",
"action",
"=",
"Action",
"::",
"Update",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"site",
"->",
"Exists",
"(",
")",
")",
"{",
"$",
"action",
"=",
"Action",
"::",
"Create",
"(",
")",
";",
"$",
"this",
"->",
"site",
"->",
"SetUser",
"(",
"self",
"::",
"Guard",
"(",
")",
"->",
"GetUser",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"site",
"->",
"SetName",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Name'",
")",
")",
";",
"$",
"this",
"->",
"site",
"->",
"SetUrl",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Url'",
")",
")",
";",
"$",
"this",
"->",
"site",
"->",
"SetBaseUrl",
"(",
"$",
"this",
"->",
"Value",
"(",
"'BaseUrl'",
")",
")",
";",
"$",
"this",
"->",
"site",
"->",
"SetLanguage",
"(",
"Language",
"::",
"Schema",
"(",
")",
"->",
"ByID",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Language'",
")",
")",
")",
";",
"$",
"this",
"->",
"site",
"->",
"SetSitemapActive",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"Value",
"(",
"'SitemapActive'",
")",
")",
";",
"$",
"this",
"->",
"site",
"->",
"SetSitemapCacheLifetime",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"Value",
"(",
"'SitemapCacheLifetime'",
")",
")",
";",
"$",
"this",
"->",
"site",
"->",
"Save",
"(",
")",
";",
"$",
"logger",
"=",
"new",
"Logger",
"(",
"self",
"::",
"Guard",
"(",
")",
"->",
"GetUser",
"(",
")",
")",
";",
"$",
"logger",
"->",
"ReportSiteAction",
"(",
"$",
"this",
"->",
"site",
",",
"$",
"action",
")",
";",
"if",
"(",
"$",
"this",
"->",
"CanAssignGroup",
"(",
")",
")",
"{",
"$",
"this",
"->",
"SaveRights",
"(",
")",
";",
"}",
"Response",
"::",
"Redirect",
"(",
"BackendRouter",
"::",
"ModuleUrl",
"(",
"new",
"SiteList",
"(",
")",
")",
")",
";",
"}"
] | Saves the site | [
"Saves",
"the",
"site"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SiteForm.php#L115-L137 | train |
phpffcms/ffcms-core | src/I18n/Translate.php | Translate.get | public function get(?string $index, string $text, ?array $params = null)
{
if (App::$Request->getLanguage() !== App::$Properties->get('baseLanguage')) {
if ($index && !Arr::in($index, $this->indexes)) {
$this->cached = Arr::merge($this->cached, $this->load($index));
$this->indexes[] = $index;
}
if ($this->cached && Any::isStr($text) && isset($this->cached[$text])) {
$text = $this->cached[$text];
}
}
if (Any::isArray($params) && count($params) > 0) {
foreach ($params as $var => $value) {
$text = Str::replace('%' . $var . '%', $value, $text);
}
}
return $text;
} | php | public function get(?string $index, string $text, ?array $params = null)
{
if (App::$Request->getLanguage() !== App::$Properties->get('baseLanguage')) {
if ($index && !Arr::in($index, $this->indexes)) {
$this->cached = Arr::merge($this->cached, $this->load($index));
$this->indexes[] = $index;
}
if ($this->cached && Any::isStr($text) && isset($this->cached[$text])) {
$text = $this->cached[$text];
}
}
if (Any::isArray($params) && count($params) > 0) {
foreach ($params as $var => $value) {
$text = Str::replace('%' . $var . '%', $value, $text);
}
}
return $text;
} | [
"public",
"function",
"get",
"(",
"?",
"string",
"$",
"index",
",",
"string",
"$",
"text",
",",
"?",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"if",
"(",
"App",
"::",
"$",
"Request",
"->",
"getLanguage",
"(",
")",
"!==",
"App",
"::",
"$",
"Properties",
"->",
"get",
"(",
"'baseLanguage'",
")",
")",
"{",
"if",
"(",
"$",
"index",
"&&",
"!",
"Arr",
"::",
"in",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"indexes",
")",
")",
"{",
"$",
"this",
"->",
"cached",
"=",
"Arr",
"::",
"merge",
"(",
"$",
"this",
"->",
"cached",
",",
"$",
"this",
"->",
"load",
"(",
"$",
"index",
")",
")",
";",
"$",
"this",
"->",
"indexes",
"[",
"]",
"=",
"$",
"index",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cached",
"&&",
"Any",
"::",
"isStr",
"(",
"$",
"text",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"cached",
"[",
"$",
"text",
"]",
")",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"cached",
"[",
"$",
"text",
"]",
";",
"}",
"}",
"if",
"(",
"Any",
"::",
"isArray",
"(",
"$",
"params",
")",
"&&",
"count",
"(",
"$",
"params",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"var",
"=>",
"$",
"value",
")",
"{",
"$",
"text",
"=",
"Str",
"::",
"replace",
"(",
"'%'",
".",
"$",
"var",
".",
"'%'",
",",
"$",
"value",
",",
"$",
"text",
")",
";",
"}",
"}",
"return",
"$",
"text",
";",
"}"
] | Get internalization of current text from i18n
@param string $index
@param string $text
@param array|null $params
@return string | [
"Get",
"internalization",
"of",
"current",
"text",
"from",
"i18n"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/I18n/Translate.php#L43-L62 | train |
phpffcms/ffcms-core | src/I18n/Translate.php | Translate.translate | public function translate(string $text, array $params = null)
{
$index = null;
$namespace = 'Apps\Controller\\' . env_name . '\\';
foreach (@debug_backtrace() as $caller) {
if (isset($caller['class']) && Str::startsWith($namespace, $caller['class'])) {
$index = Str::sub((string)$caller['class'], Str::length($namespace));
}
}
return $this->get($index, $text, $params);
} | php | public function translate(string $text, array $params = null)
{
$index = null;
$namespace = 'Apps\Controller\\' . env_name . '\\';
foreach (@debug_backtrace() as $caller) {
if (isset($caller['class']) && Str::startsWith($namespace, $caller['class'])) {
$index = Str::sub((string)$caller['class'], Str::length($namespace));
}
}
return $this->get($index, $text, $params);
} | [
"public",
"function",
"translate",
"(",
"string",
"$",
"text",
",",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"index",
"=",
"null",
";",
"$",
"namespace",
"=",
"'Apps\\Controller\\\\'",
".",
"env_name",
".",
"'\\\\'",
";",
"foreach",
"(",
"@",
"debug_backtrace",
"(",
")",
"as",
"$",
"caller",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"caller",
"[",
"'class'",
"]",
")",
"&&",
"Str",
"::",
"startsWith",
"(",
"$",
"namespace",
",",
"$",
"caller",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"index",
"=",
"Str",
"::",
"sub",
"(",
"(",
"string",
")",
"$",
"caller",
"[",
"'class'",
"]",
",",
"Str",
"::",
"length",
"(",
"$",
"namespace",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"index",
",",
"$",
"text",
",",
"$",
"params",
")",
";",
"}"
] | Get internalization based on called controller
@param string $text
@param array $params
@return string | [
"Get",
"internalization",
"based",
"on",
"called",
"controller"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/I18n/Translate.php#L70-L80 | train |
phpffcms/ffcms-core | src/I18n/Translate.php | Translate.load | protected function load(string $index): ?array
{
$file = root . '/I18n/' . env_name . '/' . App::$Request->getLanguage() . '/' . $index . '.php';
if (!File::exist($file)) {
return [];
}
return require($file);
} | php | protected function load(string $index): ?array
{
$file = root . '/I18n/' . env_name . '/' . App::$Request->getLanguage() . '/' . $index . '.php';
if (!File::exist($file)) {
return [];
}
return require($file);
} | [
"protected",
"function",
"load",
"(",
"string",
"$",
"index",
")",
":",
"?",
"array",
"{",
"$",
"file",
"=",
"root",
".",
"'/I18n/'",
".",
"env_name",
".",
"'/'",
".",
"App",
"::",
"$",
"Request",
"->",
"getLanguage",
"(",
")",
".",
"'/'",
".",
"$",
"index",
".",
"'.php'",
";",
"if",
"(",
"!",
"File",
"::",
"exist",
"(",
"$",
"file",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"require",
"(",
"$",
"file",
")",
";",
"}"
] | Load locale file from local storage
@param string $index
@return array|null | [
"Load",
"locale",
"file",
"from",
"local",
"storage"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/I18n/Translate.php#L87-L95 | train |
phpffcms/ffcms-core | src/I18n/Translate.php | Translate.append | public function append($path): bool
{
$path = Normalize::diskFullPath($path);
// check if file exist
if (!File::exist($path)) {
return false;
}
// load file translations
$addTranslation = require($path);
if (!Any::isArray($addTranslation)) {
return false;
}
// merge data
$this->cached = Arr::merge($this->cached, $addTranslation);
return true;
} | php | public function append($path): bool
{
$path = Normalize::diskFullPath($path);
// check if file exist
if (!File::exist($path)) {
return false;
}
// load file translations
$addTranslation = require($path);
if (!Any::isArray($addTranslation)) {
return false;
}
// merge data
$this->cached = Arr::merge($this->cached, $addTranslation);
return true;
} | [
"public",
"function",
"append",
"(",
"$",
"path",
")",
":",
"bool",
"{",
"$",
"path",
"=",
"Normalize",
"::",
"diskFullPath",
"(",
"$",
"path",
")",
";",
"// check if file exist",
"if",
"(",
"!",
"File",
"::",
"exist",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"// load file translations",
"$",
"addTranslation",
"=",
"require",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"Any",
"::",
"isArray",
"(",
"$",
"addTranslation",
")",
")",
"{",
"return",
"false",
";",
"}",
"// merge data",
"$",
"this",
"->",
"cached",
"=",
"Arr",
"::",
"merge",
"(",
"$",
"this",
"->",
"cached",
",",
"$",
"addTranslation",
")",
";",
"return",
"true",
";",
"}"
] | Append translation data from exist full path
@param string $path
@return bool | [
"Append",
"translation",
"data",
"from",
"exist",
"full",
"path"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/I18n/Translate.php#L102-L119 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.