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 |
---|---|---|---|---|---|---|---|---|---|---|---|
vegas-cmf/oauth | src/OAuth/Storage/Session.php | Session.clearAuthorizationState | public function clearAuthorizationState($service)
{
$service = $this->normalizeServiceName($service);
$states = $this->sessionScope->get(self::SESSION_STATE);
if (array_key_exists($service, $states)) {
unset($states, $service);
}
$this->sessionScope->set(self::SESSION_STATE, $states);
return $this;
} | php | public function clearAuthorizationState($service)
{
$service = $this->normalizeServiceName($service);
$states = $this->sessionScope->get(self::SESSION_STATE);
if (array_key_exists($service, $states)) {
unset($states, $service);
}
$this->sessionScope->set(self::SESSION_STATE, $states);
return $this;
} | [
"public",
"function",
"clearAuthorizationState",
"(",
"$",
"service",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"normalizeServiceName",
"(",
"$",
"service",
")",
";",
"$",
"states",
"=",
"$",
"this",
"->",
"sessionScope",
"->",
"get",
"(",
"self",
"::",
"SESSION_STATE",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"service",
",",
"$",
"states",
")",
")",
"{",
"unset",
"(",
"$",
"states",
",",
"$",
"service",
")",
";",
"}",
"$",
"this",
"->",
"sessionScope",
"->",
"set",
"(",
"self",
"::",
"SESSION_STATE",
",",
"$",
"states",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Clear the authorization state of a given service
@param string $service
@return TokenStorageInterface | [
"Clear",
"the",
"authorization",
"state",
"of",
"a",
"given",
"service"
] | 5183a60d02cdf3b7db9f3168be1c0bbe1306cddf | https://github.com/vegas-cmf/oauth/blob/5183a60d02cdf3b7db9f3168be1c0bbe1306cddf/src/OAuth/Storage/Session.php#L202-L213 | train |
kambalabs/KmbPmProxy | src/KmbPmProxy/Model/PuppetClass.php | PuppetClass.getParameterDefinition | public function getParameterDefinition($name)
{
if ($this->hasParametersDefinitions()) {
foreach ($this->getParametersDefinitions() as $parameterDefinition) {
if ($parameterDefinition->name === $name) {
return $parameterDefinition;
}
}
}
return null;
} | php | public function getParameterDefinition($name)
{
if ($this->hasParametersDefinitions()) {
foreach ($this->getParametersDefinitions() as $parameterDefinition) {
if ($parameterDefinition->name === $name) {
return $parameterDefinition;
}
}
}
return null;
} | [
"public",
"function",
"getParameterDefinition",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasParametersDefinitions",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getParametersDefinitions",
"(",
")",
"as",
"$",
"parameterDefinition",
")",
"{",
"if",
"(",
"$",
"parameterDefinition",
"->",
"name",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"parameterDefinition",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Get specified parameter definition.
@param string $name
@return \stdClass | [
"Get",
"specified",
"parameter",
"definition",
"."
] | b4c664ae8b6f29e4e8768461ed99e1b0b80bde18 | https://github.com/kambalabs/KmbPmProxy/blob/b4c664ae8b6f29e4e8768461ed99e1b0b80bde18/src/KmbPmProxy/Model/PuppetClass.php#L116-L126 | train |
kambalabs/KmbPmProxy | src/KmbPmProxy/Model/PuppetClass.php | PuppetClass.getParameterTemplate | public function getParameterTemplate($name)
{
if ($this->hasParametersTemplates()) {
foreach ($this->getParametersTemplates() as $parameterTemplate) {
if ($parameterTemplate->name === $name) {
return $parameterTemplate;
}
}
}
return null;
} | php | public function getParameterTemplate($name)
{
if ($this->hasParametersTemplates()) {
foreach ($this->getParametersTemplates() as $parameterTemplate) {
if ($parameterTemplate->name === $name) {
return $parameterTemplate;
}
}
}
return null;
} | [
"public",
"function",
"getParameterTemplate",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasParametersTemplates",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getParametersTemplates",
"(",
")",
"as",
"$",
"parameterTemplate",
")",
"{",
"if",
"(",
"$",
"parameterTemplate",
"->",
"name",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"parameterTemplate",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Get specified parameter template.
@param string $name
@return \stdClass | [
"Get",
"specified",
"parameter",
"template",
"."
] | b4c664ae8b6f29e4e8768461ed99e1b0b80bde18 | https://github.com/kambalabs/KmbPmProxy/blob/b4c664ae8b6f29e4e8768461ed99e1b0b80bde18/src/KmbPmProxy/Model/PuppetClass.php#L183-L193 | train |
WellCommerce/PageBundle | Form/Admin/PageFormBuilder.php | PageFormBuilder.addShopFieldset | private function addShopFieldset(FormInterface $form)
{
$shopsData = $form->addChild($this->getElement('nested_fieldset', [
'name' => 'shops_data',
'label' => $this->trans('common.fieldset.shops')
]));
$shopsData->addChild($this->getElement('multi_select', [
'name' => 'shops',
'label' => $this->trans('common.label.shops'),
'options' => $this->get('shop.dataset.admin')->getResult('select'),
'transformer' => $this->getRepositoryTransformer('collection', $this->get('shop.repository'))
]));
} | php | private function addShopFieldset(FormInterface $form)
{
$shopsData = $form->addChild($this->getElement('nested_fieldset', [
'name' => 'shops_data',
'label' => $this->trans('common.fieldset.shops')
]));
$shopsData->addChild($this->getElement('multi_select', [
'name' => 'shops',
'label' => $this->trans('common.label.shops'),
'options' => $this->get('shop.dataset.admin')->getResult('select'),
'transformer' => $this->getRepositoryTransformer('collection', $this->get('shop.repository'))
]));
} | [
"private",
"function",
"addShopFieldset",
"(",
"FormInterface",
"$",
"form",
")",
"{",
"$",
"shopsData",
"=",
"$",
"form",
"->",
"addChild",
"(",
"$",
"this",
"->",
"getElement",
"(",
"'nested_fieldset'",
",",
"[",
"'name'",
"=>",
"'shops_data'",
",",
"'label'",
"=>",
"$",
"this",
"->",
"trans",
"(",
"'common.fieldset.shops'",
")",
"]",
")",
")",
";",
"$",
"shopsData",
"->",
"addChild",
"(",
"$",
"this",
"->",
"getElement",
"(",
"'multi_select'",
",",
"[",
"'name'",
"=>",
"'shops'",
",",
"'label'",
"=>",
"$",
"this",
"->",
"trans",
"(",
"'common.label.shops'",
")",
",",
"'options'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'shop.dataset.admin'",
")",
"->",
"getResult",
"(",
"'select'",
")",
",",
"'transformer'",
"=>",
"$",
"this",
"->",
"getRepositoryTransformer",
"(",
"'collection'",
",",
"$",
"this",
"->",
"get",
"(",
"'shop.repository'",
")",
")",
"]",
")",
")",
";",
"}"
] | Adds shop selector fieldset to form
@param FormInterface $form | [
"Adds",
"shop",
"selector",
"fieldset",
"to",
"form"
] | c9a1e8c8c52177e3b82f246fd38a4598214aa222 | https://github.com/WellCommerce/PageBundle/blob/c9a1e8c8c52177e3b82f246fd38a4598214aa222/Form/Admin/PageFormBuilder.php#L194-L207 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Message/MessageFactory.php | MessageFactory.fromMessage | public function fromMessage($message)
{
static $parser;
if (!$parser) {
$parser = new MessageParser();
}
// Parse a response
if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
$data = $parser->parseResponse($message);
return $this->createResponse(
$data['code'],
$data['headers'],
$data['body'] === '' ? null : $data['body'],
$data
);
}
// Parse a request
if (!($data = ($parser->parseRequest($message)))) {
throw new \InvalidArgumentException('Unable to parse request');
}
return $this->createRequest(
$data['method'],
Url::buildUrl($data['request_url']),
[
'headers' => $data['headers'],
'body' => $data['body'] === '' ? null : $data['body'],
'config' => [
'protocol_version' => $data['protocol_version']
]
]
);
} | php | public function fromMessage($message)
{
static $parser;
if (!$parser) {
$parser = new MessageParser();
}
// Parse a response
if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
$data = $parser->parseResponse($message);
return $this->createResponse(
$data['code'],
$data['headers'],
$data['body'] === '' ? null : $data['body'],
$data
);
}
// Parse a request
if (!($data = ($parser->parseRequest($message)))) {
throw new \InvalidArgumentException('Unable to parse request');
}
return $this->createRequest(
$data['method'],
Url::buildUrl($data['request_url']),
[
'headers' => $data['headers'],
'body' => $data['body'] === '' ? null : $data['body'],
'config' => [
'protocol_version' => $data['protocol_version']
]
]
);
} | [
"public",
"function",
"fromMessage",
"(",
"$",
"message",
")",
"{",
"static",
"$",
"parser",
";",
"if",
"(",
"!",
"$",
"parser",
")",
"{",
"$",
"parser",
"=",
"new",
"MessageParser",
"(",
")",
";",
"}",
"// Parse a response",
"if",
"(",
"strtoupper",
"(",
"substr",
"(",
"$",
"message",
",",
"0",
",",
"4",
")",
")",
"==",
"'HTTP'",
")",
"{",
"$",
"data",
"=",
"$",
"parser",
"->",
"parseResponse",
"(",
"$",
"message",
")",
";",
"return",
"$",
"this",
"->",
"createResponse",
"(",
"$",
"data",
"[",
"'code'",
"]",
",",
"$",
"data",
"[",
"'headers'",
"]",
",",
"$",
"data",
"[",
"'body'",
"]",
"===",
"''",
"?",
"null",
":",
"$",
"data",
"[",
"'body'",
"]",
",",
"$",
"data",
")",
";",
"}",
"// Parse a request",
"if",
"(",
"!",
"(",
"$",
"data",
"=",
"(",
"$",
"parser",
"->",
"parseRequest",
"(",
"$",
"message",
")",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unable to parse request'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createRequest",
"(",
"$",
"data",
"[",
"'method'",
"]",
",",
"Url",
"::",
"buildUrl",
"(",
"$",
"data",
"[",
"'request_url'",
"]",
")",
",",
"[",
"'headers'",
"=>",
"$",
"data",
"[",
"'headers'",
"]",
",",
"'body'",
"=>",
"$",
"data",
"[",
"'body'",
"]",
"===",
"''",
"?",
"null",
":",
"$",
"data",
"[",
"'body'",
"]",
",",
"'config'",
"=>",
"[",
"'protocol_version'",
"=>",
"$",
"data",
"[",
"'protocol_version'",
"]",
"]",
"]",
")",
";",
"}"
] | Create a request or response object from an HTTP message string
@param string $message Message to parse
@return RequestInterface|ResponseInterface
@throws \InvalidArgumentException if unable to parse a message | [
"Create",
"a",
"request",
"or",
"response",
"object",
"from",
"an",
"HTTP",
"message",
"string"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/MessageFactory.php#L89-L123 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Message/MessageFactory.php | MessageFactory.addPostData | protected function addPostData(RequestInterface $request, array $body)
{
static $fields = ['string' => true, 'array' => true, 'NULL' => true,
'boolean' => true, 'double' => true, 'integer' => true];
$post = new PostBody();
foreach ($body as $key => $value) {
if (isset($fields[gettype($value)])) {
$post->setField($key, $value);
} elseif ($value instanceof PostFileInterface) {
$post->addFile($value);
} else {
$post->addFile(new PostFile($key, $value));
}
}
if ($request->getHeader('Content-Type') == 'multipart/form-data') {
$post->forceMultipartUpload(true);
}
$request->setBody($post);
} | php | protected function addPostData(RequestInterface $request, array $body)
{
static $fields = ['string' => true, 'array' => true, 'NULL' => true,
'boolean' => true, 'double' => true, 'integer' => true];
$post = new PostBody();
foreach ($body as $key => $value) {
if (isset($fields[gettype($value)])) {
$post->setField($key, $value);
} elseif ($value instanceof PostFileInterface) {
$post->addFile($value);
} else {
$post->addFile(new PostFile($key, $value));
}
}
if ($request->getHeader('Content-Type') == 'multipart/form-data') {
$post->forceMultipartUpload(true);
}
$request->setBody($post);
} | [
"protected",
"function",
"addPostData",
"(",
"RequestInterface",
"$",
"request",
",",
"array",
"$",
"body",
")",
"{",
"static",
"$",
"fields",
"=",
"[",
"'string'",
"=>",
"true",
",",
"'array'",
"=>",
"true",
",",
"'NULL'",
"=>",
"true",
",",
"'boolean'",
"=>",
"true",
",",
"'double'",
"=>",
"true",
",",
"'integer'",
"=>",
"true",
"]",
";",
"$",
"post",
"=",
"new",
"PostBody",
"(",
")",
";",
"foreach",
"(",
"$",
"body",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fields",
"[",
"gettype",
"(",
"$",
"value",
")",
"]",
")",
")",
"{",
"$",
"post",
"->",
"setField",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"PostFileInterface",
")",
"{",
"$",
"post",
"->",
"addFile",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"post",
"->",
"addFile",
"(",
"new",
"PostFile",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"request",
"->",
"getHeader",
"(",
"'Content-Type'",
")",
"==",
"'multipart/form-data'",
")",
"{",
"$",
"post",
"->",
"forceMultipartUpload",
"(",
"true",
")",
";",
"}",
"$",
"request",
"->",
"setBody",
"(",
"$",
"post",
")",
";",
"}"
] | Apply POST fields and files to a request to attempt to give an accurate
representation.
@param RequestInterface $request Request to update
@param array $body Body to apply | [
"Apply",
"POST",
"fields",
"and",
"files",
"to",
"a",
"request",
"to",
"attempt",
"to",
"give",
"an",
"accurate",
"representation",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/MessageFactory.php#L132-L153 | train |
bheisig/cli | src/JSONFile.php | JSONFile.read | public static function read($file, $force = false) {
if (!is_readable($file)) {
if ($force === true) {
return [];
} else {
throw new Exception(sprintf(
'Unable to read file "%s"',
$file
), ExitApp::RUNTIME_ERROR);
}
}
$fileContent = file_get_contents($file);
if ($fileContent === false) {
throw new Exception(sprintf(
'Unable to read file "%s"',
$file
), ExitApp::RUNTIME_ERROR);
}
$result = json_decode(
trim($fileContent),
true
);
if ($result === false) {
throw new Exception(sprintf(
'File "%s" contains invalid JSON data.',
ExitApp::RUNTIME_ERROR
));
}
return $result;
} | php | public static function read($file, $force = false) {
if (!is_readable($file)) {
if ($force === true) {
return [];
} else {
throw new Exception(sprintf(
'Unable to read file "%s"',
$file
), ExitApp::RUNTIME_ERROR);
}
}
$fileContent = file_get_contents($file);
if ($fileContent === false) {
throw new Exception(sprintf(
'Unable to read file "%s"',
$file
), ExitApp::RUNTIME_ERROR);
}
$result = json_decode(
trim($fileContent),
true
);
if ($result === false) {
throw new Exception(sprintf(
'File "%s" contains invalid JSON data.',
ExitApp::RUNTIME_ERROR
));
}
return $result;
} | [
"public",
"static",
"function",
"read",
"(",
"$",
"file",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"$",
"force",
"===",
"true",
")",
"{",
"return",
"[",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Unable to read file \"%s\"'",
",",
"$",
"file",
")",
",",
"ExitApp",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"}",
"$",
"fileContent",
"=",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"fileContent",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Unable to read file \"%s\"'",
",",
"$",
"file",
")",
",",
"ExitApp",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"$",
"result",
"=",
"json_decode",
"(",
"trim",
"(",
"$",
"fileContent",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'File \"%s\" contains invalid JSON data.'",
",",
"ExitApp",
"::",
"RUNTIME_ERROR",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Parse a JSON file
@param string $file File path
@param bool $force If "true" and file is not readable ignore it, otherwise throw an exception. Defaults to
"false".
@return array Return content as an array
@throws Exception on error | [
"Parse",
"a",
"JSON",
"file"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/JSONFile.php#L45-L79 | train |
bheisig/cli | src/JSONFile.php | JSONFile.write | public static function write($file, array $content) {
$jsonString = json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
if ($jsonString === false) {
throw new Exception('Unable to convert array to JSON string', ExitApp::RUNTIME_ERROR);
}
$status = file_put_contents(
$file,
$jsonString . PHP_EOL
);
if ($status === false) {
throw new Exception(sprintf(
'Unable to write JSON-formatted content to file %s',
$file
), ExitApp::RUNTIME_ERROR);
}
} | php | public static function write($file, array $content) {
$jsonString = json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
if ($jsonString === false) {
throw new Exception('Unable to convert array to JSON string', ExitApp::RUNTIME_ERROR);
}
$status = file_put_contents(
$file,
$jsonString . PHP_EOL
);
if ($status === false) {
throw new Exception(sprintf(
'Unable to write JSON-formatted content to file %s',
$file
), ExitApp::RUNTIME_ERROR);
}
} | [
"public",
"static",
"function",
"write",
"(",
"$",
"file",
",",
"array",
"$",
"content",
")",
"{",
"$",
"jsonString",
"=",
"json_encode",
"(",
"$",
"content",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
";",
"if",
"(",
"$",
"jsonString",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to convert array to JSON string'",
",",
"ExitApp",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"$",
"status",
"=",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"jsonString",
".",
"PHP_EOL",
")",
";",
"if",
"(",
"$",
"status",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Unable to write JSON-formatted content to file %s'",
",",
"$",
"file",
")",
",",
"ExitApp",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"}"
] | Write JSON-formatted content to file
@param string $file File path
@param array $content Content
@throws Exception on error | [
"Write",
"JSON",
"-",
"formatted",
"content",
"to",
"file"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/JSONFile.php#L89-L107 | train |
railken/lem | src/Generator.php | Generator.generate | public function generate(string $path, string $namespace, string $name)
{
$name = $this->camelize($name);
$vars = [
'NAMESPACE' => $namespace,
'NAME' => $name,
'NAME:CAMELIZED' => $name,
'NAME:UNDERSCORE' => $this->underscore($name),
'NAME:UPPERCASE' => strtoupper($name),
];
$this->put('/Models/Model.php.stub', $path.'/Models/'.$name.'.php', $vars);
$this->put('/Managers/Manager.php.stub', $path.'/Managers/'.$name.'Manager.php', $vars);
$this->put('/Schemas/Schema.php.stub', $path.'/Schemas/'.$name.'Schema.php', $vars);
$this->put('/Repositories/Repository.php.stub', $path.'/Repositories/'.$name.'Repository.php', $vars);
$this->put('/Validators/Validator.php.stub', $path.'/Validators/'.$name.'Validator.php', $vars);
$this->put('/Serializers/Serializer.php.stub', $path.'/Serializers/'.$name.'Serializer.php', $vars);
$this->put('/Authorizers/Authorizer.php.stub', $path.'/Authorizers/'.$name.'Authorizer.php', $vars);
$this->put('/Fakers/Faker.php.stub', $path.'/Fakers/'.$name.'Faker.php', $vars);
} | php | public function generate(string $path, string $namespace, string $name)
{
$name = $this->camelize($name);
$vars = [
'NAMESPACE' => $namespace,
'NAME' => $name,
'NAME:CAMELIZED' => $name,
'NAME:UNDERSCORE' => $this->underscore($name),
'NAME:UPPERCASE' => strtoupper($name),
];
$this->put('/Models/Model.php.stub', $path.'/Models/'.$name.'.php', $vars);
$this->put('/Managers/Manager.php.stub', $path.'/Managers/'.$name.'Manager.php', $vars);
$this->put('/Schemas/Schema.php.stub', $path.'/Schemas/'.$name.'Schema.php', $vars);
$this->put('/Repositories/Repository.php.stub', $path.'/Repositories/'.$name.'Repository.php', $vars);
$this->put('/Validators/Validator.php.stub', $path.'/Validators/'.$name.'Validator.php', $vars);
$this->put('/Serializers/Serializer.php.stub', $path.'/Serializers/'.$name.'Serializer.php', $vars);
$this->put('/Authorizers/Authorizer.php.stub', $path.'/Authorizers/'.$name.'Authorizer.php', $vars);
$this->put('/Fakers/Faker.php.stub', $path.'/Fakers/'.$name.'Faker.php', $vars);
} | [
"public",
"function",
"generate",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"namespace",
",",
"string",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"camelize",
"(",
"$",
"name",
")",
";",
"$",
"vars",
"=",
"[",
"'NAMESPACE'",
"=>",
"$",
"namespace",
",",
"'NAME'",
"=>",
"$",
"name",
",",
"'NAME:CAMELIZED'",
"=>",
"$",
"name",
",",
"'NAME:UNDERSCORE'",
"=>",
"$",
"this",
"->",
"underscore",
"(",
"$",
"name",
")",
",",
"'NAME:UPPERCASE'",
"=>",
"strtoupper",
"(",
"$",
"name",
")",
",",
"]",
";",
"$",
"this",
"->",
"put",
"(",
"'/Models/Model.php.stub'",
",",
"$",
"path",
".",
"'/Models/'",
".",
"$",
"name",
".",
"'.php'",
",",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'/Managers/Manager.php.stub'",
",",
"$",
"path",
".",
"'/Managers/'",
".",
"$",
"name",
".",
"'Manager.php'",
",",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'/Schemas/Schema.php.stub'",
",",
"$",
"path",
".",
"'/Schemas/'",
".",
"$",
"name",
".",
"'Schema.php'",
",",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'/Repositories/Repository.php.stub'",
",",
"$",
"path",
".",
"'/Repositories/'",
".",
"$",
"name",
".",
"'Repository.php'",
",",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'/Validators/Validator.php.stub'",
",",
"$",
"path",
".",
"'/Validators/'",
".",
"$",
"name",
".",
"'Validator.php'",
",",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'/Serializers/Serializer.php.stub'",
",",
"$",
"path",
".",
"'/Serializers/'",
".",
"$",
"name",
".",
"'Serializer.php'",
",",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'/Authorizers/Authorizer.php.stub'",
",",
"$",
"path",
".",
"'/Authorizers/'",
".",
"$",
"name",
".",
"'Authorizer.php'",
",",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'/Fakers/Faker.php.stub'",
",",
"$",
"path",
".",
"'/Fakers/'",
".",
"$",
"name",
".",
"'Faker.php'",
",",
"$",
"vars",
")",
";",
"}"
] | Generate a new ModelStructure folder.
@param string $path
@param string $namespace
@param string $name | [
"Generate",
"a",
"new",
"ModelStructure",
"folder",
"."
] | cff1efcd090a9504b2faf5594121885786dea67a | https://github.com/railken/lem/blob/cff1efcd090a9504b2faf5594121885786dea67a/src/Generator.php#L45-L65 | train |
pryley/castor-framework | src/Forms/Field.php | Field.getField | public function getField( array $args = [] )
{
if( empty( $args )) {
$args = $this->args;
}
$className = sprintf( 'GeminiLabs\Castor\Forms\Fields\%s', ucfirst( $args['type'] ));
if( !class_exists( $className )) {
throw new ReflectionException( "Class does not exist: {$className}" );
}
return (new $className( $args ));
} | php | public function getField( array $args = [] )
{
if( empty( $args )) {
$args = $this->args;
}
$className = sprintf( 'GeminiLabs\Castor\Forms\Fields\%s', ucfirst( $args['type'] ));
if( !class_exists( $className )) {
throw new ReflectionException( "Class does not exist: {$className}" );
}
return (new $className( $args ));
} | [
"public",
"function",
"getField",
"(",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"args",
")",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"args",
";",
"}",
"$",
"className",
"=",
"sprintf",
"(",
"'GeminiLabs\\Castor\\Forms\\Fields\\%s'",
",",
"ucfirst",
"(",
"$",
"args",
"[",
"'type'",
"]",
")",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"ReflectionException",
"(",
"\"Class does not exist: {$className}\"",
")",
";",
"}",
"return",
"(",
"new",
"$",
"className",
"(",
"$",
"args",
")",
")",
";",
"}"
] | Get a specific Field
@return mixed GeminiLabs\SiteReviews\Html\Fields\* | [
"Get",
"a",
"specific",
"Field"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L48-L61 | train |
pryley/castor-framework | src/Forms/Field.php | Field.normalize | public function normalize( array $args = [] )
{
$defaults = [
'after' => '',
'attributes' => '',
'before' => '',
'class' => '',
'default' => null,
'depends' => null,
'desc' => '',
'errors' => [],
'inline' => false,
'label' => '',
'name' => '',
'options' => [],
'path' => '',
'placeholder' => '',
'prefix' => '',
'render' => true,
'suffix' => null,
'type' => 'text',
'value' => '',
];
$args = $atts = wp_parse_args( $args, $defaults );
$args['attributes'] = $this->parseAttributes( $atts );
$args['id'] = $this->parseId( $atts );
$args['inline'] = $this->parseInline( $atts );
$args['type'] = $this->parseType( $atts );
$args['name'] = $this->parseName( $atts );
$args['options'] = (array) $atts['options']; // make sure this is always an array
$args['path'] = $atts['name'];
$args['prefix'] = $this->parsePrefix( $atts );
$args['value'] = $this->parseValue( $atts );
$this->args = $args;
$this->dependencies = $this->getField( $args )->dependencies;
$this->setDataDepends();
$this->checkForErrors( $atts );
return $this;
} | php | public function normalize( array $args = [] )
{
$defaults = [
'after' => '',
'attributes' => '',
'before' => '',
'class' => '',
'default' => null,
'depends' => null,
'desc' => '',
'errors' => [],
'inline' => false,
'label' => '',
'name' => '',
'options' => [],
'path' => '',
'placeholder' => '',
'prefix' => '',
'render' => true,
'suffix' => null,
'type' => 'text',
'value' => '',
];
$args = $atts = wp_parse_args( $args, $defaults );
$args['attributes'] = $this->parseAttributes( $atts );
$args['id'] = $this->parseId( $atts );
$args['inline'] = $this->parseInline( $atts );
$args['type'] = $this->parseType( $atts );
$args['name'] = $this->parseName( $atts );
$args['options'] = (array) $atts['options']; // make sure this is always an array
$args['path'] = $atts['name'];
$args['prefix'] = $this->parsePrefix( $atts );
$args['value'] = $this->parseValue( $atts );
$this->args = $args;
$this->dependencies = $this->getField( $args )->dependencies;
$this->setDataDepends();
$this->checkForErrors( $atts );
return $this;
} | [
"public",
"function",
"normalize",
"(",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'after'",
"=>",
"''",
",",
"'attributes'",
"=>",
"''",
",",
"'before'",
"=>",
"''",
",",
"'class'",
"=>",
"''",
",",
"'default'",
"=>",
"null",
",",
"'depends'",
"=>",
"null",
",",
"'desc'",
"=>",
"''",
",",
"'errors'",
"=>",
"[",
"]",
",",
"'inline'",
"=>",
"false",
",",
"'label'",
"=>",
"''",
",",
"'name'",
"=>",
"''",
",",
"'options'",
"=>",
"[",
"]",
",",
"'path'",
"=>",
"''",
",",
"'placeholder'",
"=>",
"''",
",",
"'prefix'",
"=>",
"''",
",",
"'render'",
"=>",
"true",
",",
"'suffix'",
"=>",
"null",
",",
"'type'",
"=>",
"'text'",
",",
"'value'",
"=>",
"''",
",",
"]",
";",
"$",
"args",
"=",
"$",
"atts",
"=",
"wp_parse_args",
"(",
"$",
"args",
",",
"$",
"defaults",
")",
";",
"$",
"args",
"[",
"'attributes'",
"]",
"=",
"$",
"this",
"->",
"parseAttributes",
"(",
"$",
"atts",
")",
";",
"$",
"args",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"parseId",
"(",
"$",
"atts",
")",
";",
"$",
"args",
"[",
"'inline'",
"]",
"=",
"$",
"this",
"->",
"parseInline",
"(",
"$",
"atts",
")",
";",
"$",
"args",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"parseType",
"(",
"$",
"atts",
")",
";",
"$",
"args",
"[",
"'name'",
"]",
"=",
"$",
"this",
"->",
"parseName",
"(",
"$",
"atts",
")",
";",
"$",
"args",
"[",
"'options'",
"]",
"=",
"(",
"array",
")",
"$",
"atts",
"[",
"'options'",
"]",
";",
"// make sure this is always an array",
"$",
"args",
"[",
"'path'",
"]",
"=",
"$",
"atts",
"[",
"'name'",
"]",
";",
"$",
"args",
"[",
"'prefix'",
"]",
"=",
"$",
"this",
"->",
"parsePrefix",
"(",
"$",
"atts",
")",
";",
"$",
"args",
"[",
"'value'",
"]",
"=",
"$",
"this",
"->",
"parseValue",
"(",
"$",
"atts",
")",
";",
"$",
"this",
"->",
"args",
"=",
"$",
"args",
";",
"$",
"this",
"->",
"dependencies",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"args",
")",
"->",
"dependencies",
";",
"$",
"this",
"->",
"setDataDepends",
"(",
")",
";",
"$",
"this",
"->",
"checkForErrors",
"(",
"$",
"atts",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Normalize the field arguments
@return $this | [
"Normalize",
"the",
"field",
"arguments"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L68-L111 | train |
pryley/castor-framework | src/Forms/Field.php | Field.render | public function render( $print = true )
{
if( $this->args['render'] === false )return;
$field = $this->getField();
$class = 'glsr-field';
$class .= $this->args['errors'] ? ' glsr-has-error' : '';
$renderedString = '%s';
if( ( isset( $field->args['required'] ) && $field->args['required'] )
|| ( isset( $field->args['attributes']['required'] ) || in_array( 'required', $field->args['attributes'] )) ) {
$class .= ' glsr-required';
}
if( $field->args['type'] !== 'hidden' ) {
$renderedString = sprintf( '<div class="%s">%%s</div>', $class );
}
$rendered = sprintf( $renderedString,
$this->args['before'] .
$field->generateLabel() .
$field->render() .
$this->args['after'] .
$this->args['errors']
);
$rendered = apply_filters( 'castor/rendered/field', $rendered, $field->args['type'] );
if( !!$print && $print !== 'return' ) {
echo $rendered;
}
return $rendered;
} | php | public function render( $print = true )
{
if( $this->args['render'] === false )return;
$field = $this->getField();
$class = 'glsr-field';
$class .= $this->args['errors'] ? ' glsr-has-error' : '';
$renderedString = '%s';
if( ( isset( $field->args['required'] ) && $field->args['required'] )
|| ( isset( $field->args['attributes']['required'] ) || in_array( 'required', $field->args['attributes'] )) ) {
$class .= ' glsr-required';
}
if( $field->args['type'] !== 'hidden' ) {
$renderedString = sprintf( '<div class="%s">%%s</div>', $class );
}
$rendered = sprintf( $renderedString,
$this->args['before'] .
$field->generateLabel() .
$field->render() .
$this->args['after'] .
$this->args['errors']
);
$rendered = apply_filters( 'castor/rendered/field', $rendered, $field->args['type'] );
if( !!$print && $print !== 'return' ) {
echo $rendered;
}
return $rendered;
} | [
"public",
"function",
"render",
"(",
"$",
"print",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"args",
"[",
"'render'",
"]",
"===",
"false",
")",
"return",
";",
"$",
"field",
"=",
"$",
"this",
"->",
"getField",
"(",
")",
";",
"$",
"class",
"=",
"'glsr-field'",
";",
"$",
"class",
".=",
"$",
"this",
"->",
"args",
"[",
"'errors'",
"]",
"?",
"' glsr-has-error'",
":",
"''",
";",
"$",
"renderedString",
"=",
"'%s'",
";",
"if",
"(",
"(",
"isset",
"(",
"$",
"field",
"->",
"args",
"[",
"'required'",
"]",
")",
"&&",
"$",
"field",
"->",
"args",
"[",
"'required'",
"]",
")",
"||",
"(",
"isset",
"(",
"$",
"field",
"->",
"args",
"[",
"'attributes'",
"]",
"[",
"'required'",
"]",
")",
"||",
"in_array",
"(",
"'required'",
",",
"$",
"field",
"->",
"args",
"[",
"'attributes'",
"]",
")",
")",
")",
"{",
"$",
"class",
".=",
"' glsr-required'",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"args",
"[",
"'type'",
"]",
"!==",
"'hidden'",
")",
"{",
"$",
"renderedString",
"=",
"sprintf",
"(",
"'<div class=\"%s\">%%s</div>'",
",",
"$",
"class",
")",
";",
"}",
"$",
"rendered",
"=",
"sprintf",
"(",
"$",
"renderedString",
",",
"$",
"this",
"->",
"args",
"[",
"'before'",
"]",
".",
"$",
"field",
"->",
"generateLabel",
"(",
")",
".",
"$",
"field",
"->",
"render",
"(",
")",
".",
"$",
"this",
"->",
"args",
"[",
"'after'",
"]",
".",
"$",
"this",
"->",
"args",
"[",
"'errors'",
"]",
")",
";",
"$",
"rendered",
"=",
"apply_filters",
"(",
"'castor/rendered/field'",
",",
"$",
"rendered",
",",
"$",
"field",
"->",
"args",
"[",
"'type'",
"]",
")",
";",
"if",
"(",
"!",
"!",
"$",
"print",
"&&",
"$",
"print",
"!==",
"'return'",
")",
"{",
"echo",
"$",
"rendered",
";",
"}",
"return",
"$",
"rendered",
";",
"}"
] | Render the field
@param mixed $print
@return string|void | [
"Render",
"the",
"field"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L120-L155 | train |
pryley/castor-framework | src/Forms/Field.php | Field.checkForErrors | protected function checkForErrors( array $atts )
{
$args = $this->args;
if( !array_key_exists( $atts['name'], $args['errors'] )) {
$this->args['errors'] = ''; // set to an empty string
return;
}
$field_errors = $args['errors'][ $atts['name'] ];
$errors = array_reduce( $field_errors['errors'], function( $carry, $error ) {
return $carry . sprintf( '<span>%s</span> ', $error );
});
$this->args['errors'] = sprintf( '<span class="glsr-field-errors">%s</span>', $errors );
} | php | protected function checkForErrors( array $atts )
{
$args = $this->args;
if( !array_key_exists( $atts['name'], $args['errors'] )) {
$this->args['errors'] = ''; // set to an empty string
return;
}
$field_errors = $args['errors'][ $atts['name'] ];
$errors = array_reduce( $field_errors['errors'], function( $carry, $error ) {
return $carry . sprintf( '<span>%s</span> ', $error );
});
$this->args['errors'] = sprintf( '<span class="glsr-field-errors">%s</span>', $errors );
} | [
"protected",
"function",
"checkForErrors",
"(",
"array",
"$",
"atts",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"args",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"atts",
"[",
"'name'",
"]",
",",
"$",
"args",
"[",
"'errors'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"args",
"[",
"'errors'",
"]",
"=",
"''",
";",
"// set to an empty string",
"return",
";",
"}",
"$",
"field_errors",
"=",
"$",
"args",
"[",
"'errors'",
"]",
"[",
"$",
"atts",
"[",
"'name'",
"]",
"]",
";",
"$",
"errors",
"=",
"array_reduce",
"(",
"$",
"field_errors",
"[",
"'errors'",
"]",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"error",
")",
"{",
"return",
"$",
"carry",
".",
"sprintf",
"(",
"'<span>%s</span> '",
",",
"$",
"error",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"args",
"[",
"'errors'",
"]",
"=",
"sprintf",
"(",
"'<span class=\"glsr-field-errors\">%s</span>'",
",",
"$",
"errors",
")",
";",
"}"
] | Check for form submission field errors
@return void | [
"Check",
"for",
"form",
"submission",
"field",
"errors"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L174-L190 | train |
pryley/castor-framework | src/Forms/Field.php | Field.parseAttributes | protected function parseAttributes( array $args )
{
if( empty( $args['attributes'] )) {
return [];
}
$attributes = (array) $args['attributes'];
foreach( $attributes as $key => $value ) {
if( is_string( $key ))continue;
unset( $attributes[ $key ] );
if( !isset( $attributes[ $value ] )) {
$attributes[ $value ] = '';
}
}
return $attributes;
} | php | protected function parseAttributes( array $args )
{
if( empty( $args['attributes'] )) {
return [];
}
$attributes = (array) $args['attributes'];
foreach( $attributes as $key => $value ) {
if( is_string( $key ))continue;
unset( $attributes[ $key ] );
if( !isset( $attributes[ $value ] )) {
$attributes[ $value ] = '';
}
}
return $attributes;
} | [
"protected",
"function",
"parseAttributes",
"(",
"array",
"$",
"args",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"args",
"[",
"'attributes'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"attributes",
"=",
"(",
"array",
")",
"$",
"args",
"[",
"'attributes'",
"]",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"continue",
";",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"attributes",
"[",
"$",
"value",
"]",
"=",
"''",
";",
"}",
"}",
"return",
"$",
"attributes",
";",
"}"
] | Parse the field attributes and convert to an array if needed
@return array | [
"Parse",
"the",
"field",
"attributes",
"and",
"convert",
"to",
"an",
"array",
"if",
"needed"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L197-L214 | train |
pryley/castor-framework | src/Forms/Field.php | Field.parseId | protected function parseId( array $args )
{
if( isset( $args['id'] ) && !$args['id'] )return;
!$args['suffix'] ?: $args['suffix'] = "-{$args['suffix']}";
return str_replace( ['[]','[',']','.'], ['','-','','-'], $this->parseName( $args ) . $args['suffix'] );
} | php | protected function parseId( array $args )
{
if( isset( $args['id'] ) && !$args['id'] )return;
!$args['suffix'] ?: $args['suffix'] = "-{$args['suffix']}";
return str_replace( ['[]','[',']','.'], ['','-','','-'], $this->parseName( $args ) . $args['suffix'] );
} | [
"protected",
"function",
"parseId",
"(",
"array",
"$",
"args",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'id'",
"]",
")",
"&&",
"!",
"$",
"args",
"[",
"'id'",
"]",
")",
"return",
";",
"!",
"$",
"args",
"[",
"'suffix'",
"]",
"?",
":",
"$",
"args",
"[",
"'suffix'",
"]",
"=",
"\"-{$args['suffix']}\"",
";",
"return",
"str_replace",
"(",
"[",
"'[]'",
",",
"'['",
",",
"']'",
",",
"'.'",
"]",
",",
"[",
"''",
",",
"'-'",
",",
"''",
",",
"'-'",
"]",
",",
"$",
"this",
"->",
"parseName",
"(",
"$",
"args",
")",
".",
"$",
"args",
"[",
"'suffix'",
"]",
")",
";",
"}"
] | Parse the field ID from the field path
@return null|string | [
"Parse",
"the",
"field",
"ID",
"from",
"the",
"field",
"path"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L221-L228 | train |
pryley/castor-framework | src/Forms/Field.php | Field.parseName | protected function parseName( array $args )
{
$name = $args['name'];
$prefix = $this->parsePrefix( $args );
if( $prefix === false ) {
return $name;
}
$paths = explode( '.', $name );
return array_reduce( $paths, function( $result, $value ) {
return $result .= "[$value]";
}, $prefix );
} | php | protected function parseName( array $args )
{
$name = $args['name'];
$prefix = $this->parsePrefix( $args );
if( $prefix === false ) {
return $name;
}
$paths = explode( '.', $name );
return array_reduce( $paths, function( $result, $value ) {
return $result .= "[$value]";
}, $prefix );
} | [
"protected",
"function",
"parseName",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"name",
"=",
"$",
"args",
"[",
"'name'",
"]",
";",
"$",
"prefix",
"=",
"$",
"this",
"->",
"parsePrefix",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"prefix",
"===",
"false",
")",
"{",
"return",
"$",
"name",
";",
"}",
"$",
"paths",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"return",
"array_reduce",
"(",
"$",
"paths",
",",
"function",
"(",
"$",
"result",
",",
"$",
"value",
")",
"{",
"return",
"$",
"result",
".=",
"\"[$value]\"",
";",
"}",
",",
"$",
"prefix",
")",
";",
"}"
] | Parse the field name
@return string | [
"Parse",
"the",
"field",
"name"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L247-L261 | train |
pryley/castor-framework | src/Forms/Field.php | Field.parseType | protected function parseType( array $args )
{
$type = $args['type'];
return false !== stripos( $type, '_inline' )
? str_replace( '_inline', '', $type )
: $type;
} | php | protected function parseType( array $args )
{
$type = $args['type'];
return false !== stripos( $type, '_inline' )
? str_replace( '_inline', '', $type )
: $type;
} | [
"protected",
"function",
"parseType",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"type",
"=",
"$",
"args",
"[",
"'type'",
"]",
";",
"return",
"false",
"!==",
"stripos",
"(",
"$",
"type",
",",
"'_inline'",
")",
"?",
"str_replace",
"(",
"'_inline'",
",",
"''",
",",
"$",
"type",
")",
":",
"$",
"type",
";",
"}"
] | Parse the field type
@return string | [
"Parse",
"the",
"field",
"type"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L278-L285 | train |
pryley/castor-framework | src/Forms/Field.php | Field.parseValue | protected function parseValue( array $args )
{
$default = $args['default'];
$name = $args['name'];
$prefix = $args['prefix'];
$value = $args['value'];
if( $default == ':placeholder' ) {
$default = '';
}
return ( !empty( $value ) || !$name || $prefix === false )
? $value
: $default;
} | php | protected function parseValue( array $args )
{
$default = $args['default'];
$name = $args['name'];
$prefix = $args['prefix'];
$value = $args['value'];
if( $default == ':placeholder' ) {
$default = '';
}
return ( !empty( $value ) || !$name || $prefix === false )
? $value
: $default;
} | [
"protected",
"function",
"parseValue",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"default",
"=",
"$",
"args",
"[",
"'default'",
"]",
";",
"$",
"name",
"=",
"$",
"args",
"[",
"'name'",
"]",
";",
"$",
"prefix",
"=",
"$",
"args",
"[",
"'prefix'",
"]",
";",
"$",
"value",
"=",
"$",
"args",
"[",
"'value'",
"]",
";",
"if",
"(",
"$",
"default",
"==",
"':placeholder'",
")",
"{",
"$",
"default",
"=",
"''",
";",
"}",
"return",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"||",
"!",
"$",
"name",
"||",
"$",
"prefix",
"===",
"false",
")",
"?",
"$",
"value",
":",
"$",
"default",
";",
"}"
] | Parse the field value
@return string | [
"Parse",
"the",
"field",
"value"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Field.php#L292-L306 | train |
nicodevs/laito | src/Laito/Http/Response.php | Response.output | public function output($response)
{
// Set format
switch ($this->format) {
case 'json':
$response = array_merge_recursive($response, $this->extra);
$this->header('Content-type: application/json; charset=utf-8');
$response = json_encode($response);
// Replace string numbers for integers
$response = preg_replace('/(")([0-9]+)(")/is', '\\2', $response);
break;
case 'html':
$this->header('Content-type: text/html; charset=utf-8');
$response = $this->html($response);
break;
}
// Set cookies
foreach ($this->cookies as $key => $value) {
setcookie($key, $value, time() + 3600, '/');
}
// Set headers
foreach ($this->headers as $header) {
header($header);
}
// Return response
echo $response;
exit;
} | php | public function output($response)
{
// Set format
switch ($this->format) {
case 'json':
$response = array_merge_recursive($response, $this->extra);
$this->header('Content-type: application/json; charset=utf-8');
$response = json_encode($response);
// Replace string numbers for integers
$response = preg_replace('/(")([0-9]+)(")/is', '\\2', $response);
break;
case 'html':
$this->header('Content-type: text/html; charset=utf-8');
$response = $this->html($response);
break;
}
// Set cookies
foreach ($this->cookies as $key => $value) {
setcookie($key, $value, time() + 3600, '/');
}
// Set headers
foreach ($this->headers as $header) {
header($header);
}
// Return response
echo $response;
exit;
} | [
"public",
"function",
"output",
"(",
"$",
"response",
")",
"{",
"// Set format",
"switch",
"(",
"$",
"this",
"->",
"format",
")",
"{",
"case",
"'json'",
":",
"$",
"response",
"=",
"array_merge_recursive",
"(",
"$",
"response",
",",
"$",
"this",
"->",
"extra",
")",
";",
"$",
"this",
"->",
"header",
"(",
"'Content-type: application/json; charset=utf-8'",
")",
";",
"$",
"response",
"=",
"json_encode",
"(",
"$",
"response",
")",
";",
"// Replace string numbers for integers",
"$",
"response",
"=",
"preg_replace",
"(",
"'/(\")([0-9]+)(\")/is'",
",",
"'\\\\2'",
",",
"$",
"response",
")",
";",
"break",
";",
"case",
"'html'",
":",
"$",
"this",
"->",
"header",
"(",
"'Content-type: text/html; charset=utf-8'",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"html",
"(",
"$",
"response",
")",
";",
"break",
";",
"}",
"// Set cookies",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"setcookie",
"(",
"$",
"key",
",",
"$",
"value",
",",
"time",
"(",
")",
"+",
"3600",
",",
"'/'",
")",
";",
"}",
"// Set headers",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"header",
")",
"{",
"header",
"(",
"$",
"header",
")",
";",
"}",
"// Return response",
"echo",
"$",
"response",
";",
"exit",
";",
"}"
] | Echoes out the response
@param array $response Response data
@return string HTTP Response | [
"Echoes",
"out",
"the",
"response"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Http/Response.php#L99-L130 | train |
nicodevs/laito | src/Laito/Http/Response.php | Response.error | public function error($code, $message, $extra = [])
{
$response['success'] = false;
$this->extra($extra);
if (!in_array($code, array_keys($this->errors))) {
$code = 500;
}
$response['error']['code'] = $code;
$this->header($this->errors[$code]);
$response['error']['status'] = $this->errors[$code];
$response['error']['message'] = $message;
return $this->output($response);
} | php | public function error($code, $message, $extra = [])
{
$response['success'] = false;
$this->extra($extra);
if (!in_array($code, array_keys($this->errors))) {
$code = 500;
}
$response['error']['code'] = $code;
$this->header($this->errors[$code]);
$response['error']['status'] = $this->errors[$code];
$response['error']['message'] = $message;
return $this->output($response);
} | [
"public",
"function",
"error",
"(",
"$",
"code",
",",
"$",
"message",
",",
"$",
"extra",
"=",
"[",
"]",
")",
"{",
"$",
"response",
"[",
"'success'",
"]",
"=",
"false",
";",
"$",
"this",
"->",
"extra",
"(",
"$",
"extra",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"code",
",",
"array_keys",
"(",
"$",
"this",
"->",
"errors",
")",
")",
")",
"{",
"$",
"code",
"=",
"500",
";",
"}",
"$",
"response",
"[",
"'error'",
"]",
"[",
"'code'",
"]",
"=",
"$",
"code",
";",
"$",
"this",
"->",
"header",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"code",
"]",
")",
";",
"$",
"response",
"[",
"'error'",
"]",
"[",
"'status'",
"]",
"=",
"$",
"this",
"->",
"errors",
"[",
"$",
"code",
"]",
";",
"$",
"response",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"=",
"$",
"message",
";",
"return",
"$",
"this",
"->",
"output",
"(",
"$",
"response",
")",
";",
"}"
] | Sets an error header and echoes out the response
@param int $code Error code
@param string $message Error message
@return string HTTP Response | [
"Sets",
"an",
"error",
"header",
"and",
"echoes",
"out",
"the",
"response"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Http/Response.php#L139-L151 | train |
nicodevs/laito | src/Laito/Http/Response.php | Response.html | private function html($data)
{
if (!is_array($data)) {
return $data;
}
$return = '';
foreach ($data as $key => $value) {
$return .= '<li>' . $key . ': ' . (is_array($value) ? $this->html($value) : $value) . '</li>';
}
return '<ul>' . $return . '</ul>';
} | php | private function html($data)
{
if (!is_array($data)) {
return $data;
}
$return = '';
foreach ($data as $key => $value) {
$return .= '<li>' . $key . ': ' . (is_array($value) ? $this->html($value) : $value) . '</li>';
}
return '<ul>' . $return . '</ul>';
} | [
"private",
"function",
"html",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"return",
"=",
"''",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"return",
".=",
"'<li>'",
".",
"$",
"key",
".",
"': '",
".",
"(",
"is_array",
"(",
"$",
"value",
")",
"?",
"$",
"this",
"->",
"html",
"(",
"$",
"value",
")",
":",
"$",
"value",
")",
".",
"'</li>'",
";",
"}",
"return",
"'<ul>'",
".",
"$",
"return",
".",
"'</ul>'",
";",
"}"
] | Transforms an array into an HTML list
@param array $data Array of data to transform
@return string HTML list | [
"Transforms",
"an",
"array",
"into",
"an",
"HTML",
"list"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Http/Response.php#L159-L169 | train |
zewadesign/framework | Zewa/HTTP/Session.php | Session.flashManagement | private function flashManagement()
{
$flashdata = $_SESSION[$this->flashdataId] ?? null;
if ($flashdata !== null) {
$flashdata = unserialize(base64_decode($flashdata));
unset($_SESSION[$this->flashdataId]);
if (!empty($flashdata)) {
$this->flashdata = $flashdata;
$this->incrementFlashStorage();
}
}
} | php | private function flashManagement()
{
$flashdata = $_SESSION[$this->flashdataId] ?? null;
if ($flashdata !== null) {
$flashdata = unserialize(base64_decode($flashdata));
unset($_SESSION[$this->flashdataId]);
if (!empty($flashdata)) {
$this->flashdata = $flashdata;
$this->incrementFlashStorage();
}
}
} | [
"private",
"function",
"flashManagement",
"(",
")",
"{",
"$",
"flashdata",
"=",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"flashdataId",
"]",
"??",
"null",
";",
"if",
"(",
"$",
"flashdata",
"!==",
"null",
")",
"{",
"$",
"flashdata",
"=",
"unserialize",
"(",
"base64_decode",
"(",
"$",
"flashdata",
")",
")",
";",
"unset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"flashdataId",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"flashdata",
")",
")",
"{",
"$",
"this",
"->",
"flashdata",
"=",
"$",
"flashdata",
";",
"$",
"this",
"->",
"incrementFlashStorage",
"(",
")",
";",
"}",
"}",
"}"
] | Processes current requests flashdata, recycles old.
@access private | [
"Processes",
"current",
"requests",
"flashdata",
"recycles",
"old",
"."
] | be74e41c674ac2c2ef924752ed310cfbaafe33b8 | https://github.com/zewadesign/framework/blob/be74e41c674ac2c2ef924752ed310cfbaafe33b8/Zewa/HTTP/Session.php#L33-L45 | train |
zewadesign/framework | Zewa/HTTP/Session.php | Session.set | public function set(string $key, $value)
{
$key = $this->security->normalize($key);
$value = $this->security->normalize($value);
parent::set($key, $value); // TODO: Change the autogenerated stub
$_SESSION[$key] = $value;
} | php | public function set(string $key, $value)
{
$key = $this->security->normalize($key);
$value = $this->security->normalize($value);
parent::set($key, $value); // TODO: Change the autogenerated stub
$_SESSION[$key] = $value;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"security",
"->",
"normalize",
"(",
"$",
"key",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"security",
"->",
"normalize",
"(",
"$",
"value",
")",
";",
"parent",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"// TODO: Change the autogenerated stub",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | In addition, most superglobals are immuteable, whereas session is not | [
"In",
"addition",
"most",
"superglobals",
"are",
"immuteable",
"whereas",
"session",
"is",
"not"
] | be74e41c674ac2c2ef924752ed310cfbaafe33b8 | https://github.com/zewadesign/framework/blob/be74e41c674ac2c2ef924752ed310cfbaafe33b8/Zewa/HTTP/Session.php#L66-L72 | train |
zewadesign/framework | Zewa/HTTP/Session.php | Session.destroy | public function destroy()
{
$_SESSION = [];
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
$time = time() - 42000;
$path = $params['path'];
$domain = $params['domain'];
$secure = $params['secure'];
$http = $params['httponly'];
setcookie(session_name(), '', $time, $path, $domain, $secure, $http);
}
$this->container->remove('Session');
session_destroy();
} | php | public function destroy()
{
$_SESSION = [];
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
$time = time() - 42000;
$path = $params['path'];
$domain = $params['domain'];
$secure = $params['secure'];
$http = $params['httponly'];
setcookie(session_name(), '', $time, $path, $domain, $secure, $http);
}
$this->container->remove('Session');
session_destroy();
} | [
"public",
"function",
"destroy",
"(",
")",
"{",
"$",
"_SESSION",
"=",
"[",
"]",
";",
"if",
"(",
"ini_get",
"(",
"\"session.use_cookies\"",
")",
")",
"{",
"$",
"params",
"=",
"session_get_cookie_params",
"(",
")",
";",
"$",
"time",
"=",
"time",
"(",
")",
"-",
"42000",
";",
"$",
"path",
"=",
"$",
"params",
"[",
"'path'",
"]",
";",
"$",
"domain",
"=",
"$",
"params",
"[",
"'domain'",
"]",
";",
"$",
"secure",
"=",
"$",
"params",
"[",
"'secure'",
"]",
";",
"$",
"http",
"=",
"$",
"params",
"[",
"'httponly'",
"]",
";",
"setcookie",
"(",
"session_name",
"(",
")",
",",
"''",
",",
"$",
"time",
",",
"$",
"path",
",",
"$",
"domain",
",",
"$",
"secure",
",",
"$",
"http",
")",
";",
"}",
"$",
"this",
"->",
"container",
"->",
"remove",
"(",
"'Session'",
")",
";",
"session_destroy",
"(",
")",
";",
"}"
] | destroys a session and related cookies | [
"destroys",
"a",
"session",
"and",
"related",
"cookies"
] | be74e41c674ac2c2ef924752ed310cfbaafe33b8 | https://github.com/zewadesign/framework/blob/be74e41c674ac2c2ef924752ed310cfbaafe33b8/Zewa/HTTP/Session.php#L102-L120 | train |
itcreator/custom-cmf | Module/Component/src/Cmf/Component/Grid/Pager.php | Pager.loadItemsForCurrentPage | protected function loadItemsForCurrentPage()
{
$items = $this->adapter->getItems($this->getOffset(), $this->itemsCountPerPage, $this->sort);
if (!($items instanceof \Traversable)) {
$this->items = new \ArrayIterator($items);
} else {
$this->items = $items;
}
} | php | protected function loadItemsForCurrentPage()
{
$items = $this->adapter->getItems($this->getOffset(), $this->itemsCountPerPage, $this->sort);
if (!($items instanceof \Traversable)) {
$this->items = new \ArrayIterator($items);
} else {
$this->items = $items;
}
} | [
"protected",
"function",
"loadItemsForCurrentPage",
"(",
")",
"{",
"$",
"items",
"=",
"$",
"this",
"->",
"adapter",
"->",
"getItems",
"(",
"$",
"this",
"->",
"getOffset",
"(",
")",
",",
"$",
"this",
"->",
"itemsCountPerPage",
",",
"$",
"this",
"->",
"sort",
")",
";",
"if",
"(",
"!",
"(",
"$",
"items",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"items",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"items",
"=",
"$",
"items",
";",
"}",
"}"
] | Method load items for current page
@return void | [
"Method",
"load",
"items",
"for",
"current",
"page"
] | 42fc0535dfa0f641856f06673f6ab596b2020c40 | https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/Component/src/Cmf/Component/Grid/Pager.php#L102-L110 | train |
brightnucleus/options-store | src/OptionRepository/AbstractOptionRepository.php | AbstractOptionRepository.initialize | protected function initialize(array $options)
{
foreach ($options as $option) {
if (! $option instanceof Option) {
throw InvalidOption::fromOption($option);
}
$option = $this->identityMap->put($option, $this);
$this->schema[$option->getKey()] = $option;
}
} | php | protected function initialize(array $options)
{
foreach ($options as $option) {
if (! $option instanceof Option) {
throw InvalidOption::fromOption($option);
}
$option = $this->identityMap->put($option, $this);
$this->schema[$option->getKey()] = $option;
}
} | [
"protected",
"function",
"initialize",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"$",
"option",
"instanceof",
"Option",
")",
"{",
"throw",
"InvalidOption",
"::",
"fromOption",
"(",
"$",
"option",
")",
";",
"}",
"$",
"option",
"=",
"$",
"this",
"->",
"identityMap",
"->",
"put",
"(",
"$",
"option",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"schema",
"[",
"$",
"option",
"->",
"getKey",
"(",
")",
"]",
"=",
"$",
"option",
";",
"}",
"}"
] | Initialize the internal state of the repository.
@since 0.1.0
@param array $options | [
"Initialize",
"the",
"internal",
"state",
"of",
"the",
"repository",
"."
] | 9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1 | https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/OptionRepository/AbstractOptionRepository.php#L82-L93 | train |
squareproton/Bond | src/Bond/Pg/ConnectionSettings.php | ConnectionSettings.getConnectionString | public function getConnectionString()
{
$settings = $this->connectionInfo;
unset( $settings['search_path'] );
foreach ($settings as $key => &$value) {
$value = sprintf(
"%s='%s'",
$key,
$value
);
}
return implode(' ', $settings);
} | php | public function getConnectionString()
{
$settings = $this->connectionInfo;
unset( $settings['search_path'] );
foreach ($settings as $key => &$value) {
$value = sprintf(
"%s='%s'",
$key,
$value
);
}
return implode(' ', $settings);
} | [
"public",
"function",
"getConnectionString",
"(",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"connectionInfo",
";",
"unset",
"(",
"$",
"settings",
"[",
"'search_path'",
"]",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"sprintf",
"(",
"\"%s='%s'\"",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"settings",
")",
";",
"}"
] | Generate a property formatted postgres connection string
@param array $settings array( 'host' =>, 'port' =>, 'dbname' =>, 'user' => , 'password' => )
@return string a pg_connect compatable connectio string | [
"Generate",
"a",
"property",
"formatted",
"postgres",
"connection",
"string"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/ConnectionSettings.php#L41-L57 | train |
fulgurio/LightCMSBundle | Repository/MediaRepository.php | MediaRepository.findAllWithPagination | public function findAllWithPagination($filters, $limit, $offset, $resultInArray = FALSE)
{
$where = $this->getQueryFilter($filters);
$query = $this->getEntityManager()->createQuery('SELECT m FROM FulgurioLightCMSBundle:Media m ' . $where . ' ORDER BY m.created_at DESC')->setMaxResults($limit)->setFirstResult($offset);
if (!empty($filters))
{
foreach ($filters as $filterKey => $filterValue)
{
$query->setParameter($filterKey, $filterValue);
}
}
if ($resultInArray)
{
return $query->getArrayResult();
}
return $query->getResult();
} | php | public function findAllWithPagination($filters, $limit, $offset, $resultInArray = FALSE)
{
$where = $this->getQueryFilter($filters);
$query = $this->getEntityManager()->createQuery('SELECT m FROM FulgurioLightCMSBundle:Media m ' . $where . ' ORDER BY m.created_at DESC')->setMaxResults($limit)->setFirstResult($offset);
if (!empty($filters))
{
foreach ($filters as $filterKey => $filterValue)
{
$query->setParameter($filterKey, $filterValue);
}
}
if ($resultInArray)
{
return $query->getArrayResult();
}
return $query->getResult();
} | [
"public",
"function",
"findAllWithPagination",
"(",
"$",
"filters",
",",
"$",
"limit",
",",
"$",
"offset",
",",
"$",
"resultInArray",
"=",
"FALSE",
")",
"{",
"$",
"where",
"=",
"$",
"this",
"->",
"getQueryFilter",
"(",
"$",
"filters",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"createQuery",
"(",
"'SELECT m FROM FulgurioLightCMSBundle:Media m '",
".",
"$",
"where",
".",
"' ORDER BY m.created_at DESC'",
")",
"->",
"setMaxResults",
"(",
"$",
"limit",
")",
"->",
"setFirstResult",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filters",
")",
")",
"{",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filterKey",
"=>",
"$",
"filterValue",
")",
"{",
"$",
"query",
"->",
"setParameter",
"(",
"$",
"filterKey",
",",
"$",
"filterValue",
")",
";",
"}",
"}",
"if",
"(",
"$",
"resultInArray",
")",
"{",
"return",
"$",
"query",
"->",
"getArrayResult",
"(",
")",
";",
"}",
"return",
"$",
"query",
"->",
"getResult",
"(",
")",
";",
"}"
] | Find media with pagination
@param array $filters
@param number $limit
@param number $offset
@param boolean $resultInArray
@return array | [
"Find",
"media",
"with",
"pagination"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Repository/MediaRepository.php#L33-L49 | train |
fulgurio/LightCMSBundle | Repository/MediaRepository.php | MediaRepository.count | public function count($filters)
{
$where = $this->getQueryFilter($filters);
$query = $this->getEntityManager()->createQuery('SELECT COUNT(m) FROM FulgurioLightCMSBundle:Media m' . $where);
if (!empty($filters))
{
foreach ($filters as $filterKey => $filterValue)
{
$query->setParameter($filterKey, $filterValue);
}
}
return $query->getSingleScalarResult();
} | php | public function count($filters)
{
$where = $this->getQueryFilter($filters);
$query = $this->getEntityManager()->createQuery('SELECT COUNT(m) FROM FulgurioLightCMSBundle:Media m' . $where);
if (!empty($filters))
{
foreach ($filters as $filterKey => $filterValue)
{
$query->setParameter($filterKey, $filterValue);
}
}
return $query->getSingleScalarResult();
} | [
"public",
"function",
"count",
"(",
"$",
"filters",
")",
"{",
"$",
"where",
"=",
"$",
"this",
"->",
"getQueryFilter",
"(",
"$",
"filters",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"createQuery",
"(",
"'SELECT COUNT(m) FROM FulgurioLightCMSBundle:Media m'",
".",
"$",
"where",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filters",
")",
")",
"{",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filterKey",
"=>",
"$",
"filterValue",
")",
"{",
"$",
"query",
"->",
"setParameter",
"(",
"$",
"filterKey",
",",
"$",
"filterValue",
")",
";",
"}",
"}",
"return",
"$",
"query",
"->",
"getSingleScalarResult",
"(",
")",
";",
"}"
] | Count number of result
@param array $filters
@return Ambigous <\Doctrine\ORM\mixed, mixed, \Doctrine\ORM\Internal\Hydration\mixed, \Doctrine\DBAL\Driver\Statement> | [
"Count",
"number",
"of",
"result"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Repository/MediaRepository.php#L57-L69 | train |
fulgurio/LightCMSBundle | Repository/MediaRepository.php | MediaRepository.getQueryFilter | private function getQueryFilter($filters)
{
$where = '';
if (!empty($filters))
{
foreach ($filters as $filterKey => $filterValue)
{
$where .= ' AND m.' . $filterKey . ' LIKE :' . $filterKey;
}
$where = ' WHERE ' . substr($where, 4);
}
return $where;
} | php | private function getQueryFilter($filters)
{
$where = '';
if (!empty($filters))
{
foreach ($filters as $filterKey => $filterValue)
{
$where .= ' AND m.' . $filterKey . ' LIKE :' . $filterKey;
}
$where = ' WHERE ' . substr($where, 4);
}
return $where;
} | [
"private",
"function",
"getQueryFilter",
"(",
"$",
"filters",
")",
"{",
"$",
"where",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filters",
")",
")",
"{",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filterKey",
"=>",
"$",
"filterValue",
")",
"{",
"$",
"where",
".=",
"' AND m.'",
".",
"$",
"filterKey",
".",
"' LIKE :'",
".",
"$",
"filterKey",
";",
"}",
"$",
"where",
"=",
"' WHERE '",
".",
"substr",
"(",
"$",
"where",
",",
"4",
")",
";",
"}",
"return",
"$",
"where",
";",
"}"
] | Make query filter string, from given filters
@param array $filters
@return string | [
"Make",
"query",
"filter",
"string",
"from",
"given",
"filters"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Repository/MediaRepository.php#L77-L89 | train |
mtils/file-db | src/FileDB/Model/EmsFileDBModel.php | EmsFileDBModel.removeDeletedFsChildrenFromDb | protected function removeDeletedFsChildrenFromDb($dbChildren)
{
$existingChildren = [];
// First delete all children that do not exist in fs
foreach ($dbChildren as $child) {
if (!$this->filesystem->exists($child->getPath())) {
$this->nodeRepository->delete($child);
continue;
}
$existingChildren[] = $child;
}
return $existingChildren;
} | php | protected function removeDeletedFsChildrenFromDb($dbChildren)
{
$existingChildren = [];
// First delete all children that do not exist in fs
foreach ($dbChildren as $child) {
if (!$this->filesystem->exists($child->getPath())) {
$this->nodeRepository->delete($child);
continue;
}
$existingChildren[] = $child;
}
return $existingChildren;
} | [
"protected",
"function",
"removeDeletedFsChildrenFromDb",
"(",
"$",
"dbChildren",
")",
"{",
"$",
"existingChildren",
"=",
"[",
"]",
";",
"// First delete all children that do not exist in fs",
"foreach",
"(",
"$",
"dbChildren",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"exists",
"(",
"$",
"child",
"->",
"getPath",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"nodeRepository",
"->",
"delete",
"(",
"$",
"child",
")",
";",
"continue",
";",
"}",
"$",
"existingChildren",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"return",
"$",
"existingChildren",
";",
"}"
] | Delete the non existing
@param CanHaveParent[] $dbChildren
@return array | [
"Delete",
"the",
"non",
"existing"
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Model/EmsFileDBModel.php#L414-L429 | train |
mtils/file-db | src/FileDB/Model/EmsFileDBModel.php | EmsFileDBModel.absoluteToFilesystemPath | protected function absoluteToFilesystemPath($filePath)
{
if (!$this->isWithinFilesystem($filePath)) {
return $filePath;
}
$fsPath = (string)$this->filesystem->url()->path;
return str_replace($fsPath,'', $filePath);
} | php | protected function absoluteToFilesystemPath($filePath)
{
if (!$this->isWithinFilesystem($filePath)) {
return $filePath;
}
$fsPath = (string)$this->filesystem->url()->path;
return str_replace($fsPath,'', $filePath);
} | [
"protected",
"function",
"absoluteToFilesystemPath",
"(",
"$",
"filePath",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isWithinFilesystem",
"(",
"$",
"filePath",
")",
")",
"{",
"return",
"$",
"filePath",
";",
"}",
"$",
"fsPath",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"filesystem",
"->",
"url",
"(",
")",
"->",
"path",
";",
"return",
"str_replace",
"(",
"$",
"fsPath",
",",
"''",
",",
"$",
"filePath",
")",
";",
"}"
] | Cat the absolute part of a file path off to make a relative filesystem
path
@param string $filePath
@return string | [
"Cat",
"the",
"absolute",
"part",
"of",
"a",
"file",
"path",
"off",
"to",
"make",
"a",
"relative",
"filesystem",
"path"
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Model/EmsFileDBModel.php#L538-L549 | train |
mtils/file-db | src/FileDB/Model/EmsFileDBModel.php | EmsFileDBModel.isExcludedFromDb | protected function isExcludedFromDb($basename)
{
if (in_array(mb_strtolower($basename), $this->excludeFromDb)) {
return true;
}
return Helper::startsWith($basename, '.') || Helper::startsWith($basename, '_');
} | php | protected function isExcludedFromDb($basename)
{
if (in_array(mb_strtolower($basename), $this->excludeFromDb)) {
return true;
}
return Helper::startsWith($basename, '.') || Helper::startsWith($basename, '_');
} | [
"protected",
"function",
"isExcludedFromDb",
"(",
"$",
"basename",
")",
"{",
"if",
"(",
"in_array",
"(",
"mb_strtolower",
"(",
"$",
"basename",
")",
",",
"$",
"this",
"->",
"excludeFromDb",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"Helper",
"::",
"startsWith",
"(",
"$",
"basename",
",",
"'.'",
")",
"||",
"Helper",
"::",
"startsWith",
"(",
"$",
"basename",
",",
"'_'",
")",
";",
"}"
] | Return true if the passed file should not be mirrored in the db.
@param string $basename
@return bool | [
"Return",
"true",
"if",
"the",
"passed",
"file",
"should",
"not",
"be",
"mirrored",
"in",
"the",
"db",
"."
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Model/EmsFileDBModel.php#L801-L809 | train |
mtils/cmsable | src/Cmsable/Routing/ControllerCreator.php | ControllerCreator.createController | public function createController($name, SiteTreeNodeInterface $page=null)
{
$this->page = $page;
$controller = $this->makeController($name);
$this->modifyController($controller, $page);
return $controller;
} | php | public function createController($name, SiteTreeNodeInterface $page=null)
{
$this->page = $page;
$controller = $this->makeController($name);
$this->modifyController($controller, $page);
return $controller;
} | [
"public",
"function",
"createController",
"(",
"$",
"name",
",",
"SiteTreeNodeInterface",
"$",
"page",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"page",
"=",
"$",
"page",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"makeController",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"modifyController",
"(",
"$",
"controller",
",",
"$",
"page",
")",
";",
"return",
"$",
"controller",
";",
"}"
] | Creates a controller while routing to a page. This method is used
to configure dependencies of you controller according to a page.
You can also configure your controller directly like setting a
a layout
@param string $controllerName The classname of the routed controller
@param \Cmsable\Model\SiteTreeNodeInterface $page (optional) Null if no match
@return \Illuminate\Routing\Controller | [
"Creates",
"a",
"controller",
"while",
"routing",
"to",
"a",
"page",
".",
"This",
"method",
"is",
"used",
"to",
"configure",
"dependencies",
"of",
"you",
"controller",
"according",
"to",
"a",
"page",
".",
"You",
"can",
"also",
"configure",
"your",
"controller",
"directly",
"like",
"setting",
"a",
"a",
"layout"
] | 03ae84ee3c7d46146f2a1cf687e5c29d6de4286d | https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Routing/ControllerCreator.php#L42-L53 | train |
battis/simplecache | src/HierarchicalSimpleCache.php | HierarchicalSimpleCache.pushKey | public function pushKey($layer)
{
$this->base .= $this->delimiter . str_replace($this->delimiter, $this->placeholder, $layer);
return $this->getBase();
} | php | public function pushKey($layer)
{
$this->base .= $this->delimiter . str_replace($this->delimiter, $this->placeholder, $layer);
return $this->getBase();
} | [
"public",
"function",
"pushKey",
"(",
"$",
"layer",
")",
"{",
"$",
"this",
"->",
"base",
".=",
"$",
"this",
"->",
"delimiter",
".",
"str_replace",
"(",
"$",
"this",
"->",
"delimiter",
",",
"$",
"this",
"->",
"placeholder",
",",
"$",
"layer",
")",
";",
"return",
"$",
"this",
"->",
"getBase",
"(",
")",
";",
"}"
] | Add a layer of depth to the key hierarchy
@param string $layer
@return string The new base key | [
"Add",
"a",
"layer",
"of",
"depth",
"to",
"the",
"key",
"hierarchy"
] | edda1bee5994fcc2a7b4a10e868d161d8dcddf3b | https://github.com/battis/simplecache/blob/edda1bee5994fcc2a7b4a10e868d161d8dcddf3b/src/HierarchicalSimpleCache.php#L64-L68 | train |
battis/simplecache | src/HierarchicalSimpleCache.php | HierarchicalSimpleCache.popKey | public function popKey()
{
if (strlen($this->base)) {
$layers = explode($this->delimiter, $this->base);
$last = count($layers) - 1;
$layer = $layers[$last];
if ($last > 0) {
unset ($layers[$last]);
$this->base = implode($this->delimiter, $layers);
} else {
$this->base = '';
}
return $layer;
}
return null;
} | php | public function popKey()
{
if (strlen($this->base)) {
$layers = explode($this->delimiter, $this->base);
$last = count($layers) - 1;
$layer = $layers[$last];
if ($last > 0) {
unset ($layers[$last]);
$this->base = implode($this->delimiter, $layers);
} else {
$this->base = '';
}
return $layer;
}
return null;
} | [
"public",
"function",
"popKey",
"(",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"base",
")",
")",
"{",
"$",
"layers",
"=",
"explode",
"(",
"$",
"this",
"->",
"delimiter",
",",
"$",
"this",
"->",
"base",
")",
";",
"$",
"last",
"=",
"count",
"(",
"$",
"layers",
")",
"-",
"1",
";",
"$",
"layer",
"=",
"$",
"layers",
"[",
"$",
"last",
"]",
";",
"if",
"(",
"$",
"last",
">",
"0",
")",
"{",
"unset",
"(",
"$",
"layers",
"[",
"$",
"last",
"]",
")",
";",
"$",
"this",
"->",
"base",
"=",
"implode",
"(",
"$",
"this",
"->",
"delimiter",
",",
"$",
"layers",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"base",
"=",
"''",
";",
"}",
"return",
"$",
"layer",
";",
"}",
"return",
"null",
";",
"}"
] | Remove a layer of depth from the key hierarchy
@return string|null The layer that was removed from the hierarchy (`NULL`
if no layers exist) | [
"Remove",
"a",
"layer",
"of",
"depth",
"from",
"the",
"key",
"hierarchy"
] | edda1bee5994fcc2a7b4a10e868d161d8dcddf3b | https://github.com/battis/simplecache/blob/edda1bee5994fcc2a7b4a10e868d161d8dcddf3b/src/HierarchicalSimpleCache.php#L76-L92 | train |
togucms/MediaBundle | Controller/GalleryController.php | GalleryController.postGalleryAction | public function postGalleryAction() {
$serializer = $this->get("tpg_extjs.phpcr_serializer");
$entity = $serializer->deserialize(
$this->getRequest()->getContent(),
'Togu\MediaBundle\Document\Gallery',
'json',
DeserializationContext::create()->setGroups(array("Default", "post"))
);
$validator = $this->get('validator');
$validations = $validator->validate($entity, array('Default', 'post'));
if ($validations->count() === 0) {
$manager = $this->get('doctrine_phpcr.odm.default_document_manager');
$manager->persist($entity);
try {
$manager->flush();
} catch (DBALException $e) {
return $this->handleView(
View::create(array('errors'=>array($e->getMessage())), 400)
);
}
return $this->handleView(
View::create(array(
"success" => true,
"records" => array($entity)
), 200)->setSerializationContext($this->getSerializerContext())
);
} else {
return $this->handleView(
View::create(array('errors'=>$validations), 400)
);
}
} | php | public function postGalleryAction() {
$serializer = $this->get("tpg_extjs.phpcr_serializer");
$entity = $serializer->deserialize(
$this->getRequest()->getContent(),
'Togu\MediaBundle\Document\Gallery',
'json',
DeserializationContext::create()->setGroups(array("Default", "post"))
);
$validator = $this->get('validator');
$validations = $validator->validate($entity, array('Default', 'post'));
if ($validations->count() === 0) {
$manager = $this->get('doctrine_phpcr.odm.default_document_manager');
$manager->persist($entity);
try {
$manager->flush();
} catch (DBALException $e) {
return $this->handleView(
View::create(array('errors'=>array($e->getMessage())), 400)
);
}
return $this->handleView(
View::create(array(
"success" => true,
"records" => array($entity)
), 200)->setSerializationContext($this->getSerializerContext())
);
} else {
return $this->handleView(
View::create(array('errors'=>$validations), 400)
);
}
} | [
"public",
"function",
"postGalleryAction",
"(",
")",
"{",
"$",
"serializer",
"=",
"$",
"this",
"->",
"get",
"(",
"\"tpg_extjs.phpcr_serializer\"",
")",
";",
"$",
"entity",
"=",
"$",
"serializer",
"->",
"deserialize",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getContent",
"(",
")",
",",
"'Togu\\MediaBundle\\Document\\Gallery'",
",",
"'json'",
",",
"DeserializationContext",
"::",
"create",
"(",
")",
"->",
"setGroups",
"(",
"array",
"(",
"\"Default\"",
",",
"\"post\"",
")",
")",
")",
";",
"$",
"validator",
"=",
"$",
"this",
"->",
"get",
"(",
"'validator'",
")",
";",
"$",
"validations",
"=",
"$",
"validator",
"->",
"validate",
"(",
"$",
"entity",
",",
"array",
"(",
"'Default'",
",",
"'post'",
")",
")",
";",
"if",
"(",
"$",
"validations",
"->",
"count",
"(",
")",
"===",
"0",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"get",
"(",
"'doctrine_phpcr.odm.default_document_manager'",
")",
";",
"$",
"manager",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"try",
"{",
"$",
"manager",
"->",
"flush",
"(",
")",
";",
"}",
"catch",
"(",
"DBALException",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"handleView",
"(",
"View",
"::",
"create",
"(",
"array",
"(",
"'errors'",
"=>",
"array",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
",",
"400",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"View",
"::",
"create",
"(",
"array",
"(",
"\"success\"",
"=>",
"true",
",",
"\"records\"",
"=>",
"array",
"(",
"$",
"entity",
")",
")",
",",
"200",
")",
"->",
"setSerializationContext",
"(",
"$",
"this",
"->",
"getSerializerContext",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"handleView",
"(",
"View",
"::",
"create",
"(",
"array",
"(",
"'errors'",
"=>",
"$",
"validations",
")",
",",
"400",
")",
")",
";",
"}",
"}"
] | Create a new Gallery record
@return \Symfony\Component\HttpFoundation\Response | [
"Create",
"a",
"new",
"Gallery",
"record"
] | 42065d5fa419654540a52ae8f0047708eac9930b | https://github.com/togucms/MediaBundle/blob/42065d5fa419654540a52ae8f0047708eac9930b/Controller/GalleryController.php#L225-L256 | train |
stellaqua/Waltz.Stagehand | src/Waltz/Stagehand/CuiUtility/DecorationsObject.php | DecorationsObject.getBackgroundColorEscapeSequence | public function getBackgroundColorEscapeSequence ( $colorName = '' ) {
if ( $this->_isDefinedColor($colorName) === true ) {
$colors = self::getDefinedColors();
list($textColor, $backgroundColor) = $colors[$colorName];
return $backgroundColor;
}
return '';
} | php | public function getBackgroundColorEscapeSequence ( $colorName = '' ) {
if ( $this->_isDefinedColor($colorName) === true ) {
$colors = self::getDefinedColors();
list($textColor, $backgroundColor) = $colors[$colorName];
return $backgroundColor;
}
return '';
} | [
"public",
"function",
"getBackgroundColorEscapeSequence",
"(",
"$",
"colorName",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_isDefinedColor",
"(",
"$",
"colorName",
")",
"===",
"true",
")",
"{",
"$",
"colors",
"=",
"self",
"::",
"getDefinedColors",
"(",
")",
";",
"list",
"(",
"$",
"textColor",
",",
"$",
"backgroundColor",
")",
"=",
"$",
"colors",
"[",
"$",
"colorName",
"]",
";",
"return",
"$",
"backgroundColor",
";",
"}",
"return",
"''",
";",
"}"
] | Get Background color escape sequence
@param string $color Color name
@return string background color escape sequence | [
"Get",
"Background",
"color",
"escape",
"sequence"
] | 01df286751f5b9a5c90c47138dca3709e5bc383b | https://github.com/stellaqua/Waltz.Stagehand/blob/01df286751f5b9a5c90c47138dca3709e5bc383b/src/Waltz/Stagehand/CuiUtility/DecorationsObject.php#L117-L124 | train |
stellaqua/Waltz.Stagehand | src/Waltz/Stagehand/CuiUtility/DecorationsObject.php | DecorationsObject.setIsBold | public function setIsBold ( $isBold ) {
if ( $isBold === true ) {
$this->_isBold = true;
} else {
$this->_isBold = false;
}
} | php | public function setIsBold ( $isBold ) {
if ( $isBold === true ) {
$this->_isBold = true;
} else {
$this->_isBold = false;
}
} | [
"public",
"function",
"setIsBold",
"(",
"$",
"isBold",
")",
"{",
"if",
"(",
"$",
"isBold",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"_isBold",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_isBold",
"=",
"false",
";",
"}",
"}"
] | Set which is bold
@param bool $isBold | [
"Set",
"which",
"is",
"bold"
] | 01df286751f5b9a5c90c47138dca3709e5bc383b | https://github.com/stellaqua/Waltz.Stagehand/blob/01df286751f5b9a5c90c47138dca3709e5bc383b/src/Waltz/Stagehand/CuiUtility/DecorationsObject.php#L161-L167 | train |
stellaqua/Waltz.Stagehand | src/Waltz/Stagehand/CuiUtility/DecorationsObject.php | DecorationsObject.setIsUnderlined | public function setIsUnderlined ( $isUnderlined ) {
if ( $isUnderlined === true ) {
$this->_isUnderlined = true;
} else {
$this->_isUnderlined = false;
}
} | php | public function setIsUnderlined ( $isUnderlined ) {
if ( $isUnderlined === true ) {
$this->_isUnderlined = true;
} else {
$this->_isUnderlined = false;
}
} | [
"public",
"function",
"setIsUnderlined",
"(",
"$",
"isUnderlined",
")",
"{",
"if",
"(",
"$",
"isUnderlined",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"_isUnderlined",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_isUnderlined",
"=",
"false",
";",
"}",
"}"
] | Set which is underlined
@param bool $isUnderlined | [
"Set",
"which",
"is",
"underlined"
] | 01df286751f5b9a5c90c47138dca3709e5bc383b | https://github.com/stellaqua/Waltz.Stagehand/blob/01df286751f5b9a5c90c47138dca3709e5bc383b/src/Waltz/Stagehand/CuiUtility/DecorationsObject.php#L193-L199 | train |
stellaqua/Waltz.Stagehand | src/Waltz/Stagehand/CuiUtility/DecorationsObject.php | DecorationsObject._isDefinedColor | private function _isDefinedColor ( $colorName ) {
$colors = self::getDefinedColors();
$colorNames = array_keys($colors);
return in_array($colorName, $colorNames);
} | php | private function _isDefinedColor ( $colorName ) {
$colors = self::getDefinedColors();
$colorNames = array_keys($colors);
return in_array($colorName, $colorNames);
} | [
"private",
"function",
"_isDefinedColor",
"(",
"$",
"colorName",
")",
"{",
"$",
"colors",
"=",
"self",
"::",
"getDefinedColors",
"(",
")",
";",
"$",
"colorNames",
"=",
"array_keys",
"(",
"$",
"colors",
")",
";",
"return",
"in_array",
"(",
"$",
"colorName",
",",
"$",
"colorNames",
")",
";",
"}"
] | Which is defined color
@param string $colorName Color name
@return bool Which is defined color | [
"Which",
"is",
"defined",
"color"
] | 01df286751f5b9a5c90c47138dca3709e5bc383b | https://github.com/stellaqua/Waltz.Stagehand/blob/01df286751f5b9a5c90c47138dca3709e5bc383b/src/Waltz/Stagehand/CuiUtility/DecorationsObject.php#L217-L221 | train |
shgysk8zer0/core_api | traits/events.php | Events.triggerEvent | final protected static function triggerEvent($event, array $context = array())
{
if (array_key_exists($event, static::$registered_events)) {
array_map(function($handler) use ($context)
{
call_user_func($handler, $context);
}, static::$registered_events[$event]);
}
} | php | final protected static function triggerEvent($event, array $context = array())
{
if (array_key_exists($event, static::$registered_events)) {
array_map(function($handler) use ($context)
{
call_user_func($handler, $context);
}, static::$registered_events[$event]);
}
} | [
"final",
"protected",
"static",
"function",
"triggerEvent",
"(",
"$",
"event",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"event",
",",
"static",
"::",
"$",
"registered_events",
")",
")",
"{",
"array_map",
"(",
"function",
"(",
"$",
"handler",
")",
"use",
"(",
"$",
"context",
")",
"{",
"call_user_func",
"(",
"$",
"handler",
",",
"$",
"context",
")",
";",
"}",
",",
"static",
"::",
"$",
"registered_events",
"[",
"$",
"event",
"]",
")",
";",
"}",
"}"
] | Trigger an event an call its callback if any exist. Otherwise, nothing
@param string $event Name of event. E.G. "Error"
@param array $context An array of paramaters to pass to the callback
@return void | [
"Trigger",
"an",
"event",
"an",
"call",
"its",
"callback",
"if",
"any",
"exist",
".",
"Otherwise",
"nothing"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/events.php#L60-L68 | train |
lanfisis/deflection | src/Deflection/Element/Param.php | Param.getElement | public function getElement()
{
if ($this->getDocblock()) {
$this->setLines($this->getDocblock()->getElement());
}
$name = '';
if ($this->getName() and !is_array($this->getValue())) {
$name = ($this->getType() ? $this->getType().' ' : '')
.'$'.$this->getName().
($this->getValue() ? ' = '.$this->getValue() : '').';';
$this->addLine($name);
} else if ($this->getName() and is_array($this->getValue())) {
$value = $this->getValue();
$begin = array_shift($value);
$end = array_pop($value);
$value[] = $end.';';
$this->addLine(($this->getType() ? $this->getType().' ' : '').'$'.$this->getName().' = '.$begin);
$this->addLine($value);
}
return $this->getLines();
} | php | public function getElement()
{
if ($this->getDocblock()) {
$this->setLines($this->getDocblock()->getElement());
}
$name = '';
if ($this->getName() and !is_array($this->getValue())) {
$name = ($this->getType() ? $this->getType().' ' : '')
.'$'.$this->getName().
($this->getValue() ? ' = '.$this->getValue() : '').';';
$this->addLine($name);
} else if ($this->getName() and is_array($this->getValue())) {
$value = $this->getValue();
$begin = array_shift($value);
$end = array_pop($value);
$value[] = $end.';';
$this->addLine(($this->getType() ? $this->getType().' ' : '').'$'.$this->getName().' = '.$begin);
$this->addLine($value);
}
return $this->getLines();
} | [
"public",
"function",
"getElement",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getDocblock",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setLines",
"(",
"$",
"this",
"->",
"getDocblock",
"(",
")",
"->",
"getElement",
"(",
")",
")",
";",
"}",
"$",
"name",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
"and",
"!",
"is_array",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"$",
"name",
"=",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
"?",
"$",
"this",
"->",
"getType",
"(",
")",
".",
"' '",
":",
"''",
")",
".",
"'$'",
".",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
"?",
"' = '",
".",
"$",
"this",
"->",
"getValue",
"(",
")",
":",
"''",
")",
".",
"';'",
";",
"$",
"this",
"->",
"addLine",
"(",
"$",
"name",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
"and",
"is_array",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"$",
"begin",
"=",
"array_shift",
"(",
"$",
"value",
")",
";",
"$",
"end",
"=",
"array_pop",
"(",
"$",
"value",
")",
";",
"$",
"value",
"[",
"]",
"=",
"$",
"end",
".",
"';'",
";",
"$",
"this",
"->",
"addLine",
"(",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
"?",
"$",
"this",
"->",
"getType",
"(",
")",
".",
"' '",
":",
"''",
")",
".",
"'$'",
".",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"' = '",
".",
"$",
"begin",
")",
";",
"$",
"this",
"->",
"addLine",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getLines",
"(",
")",
";",
"}"
] | Return param content
@return array | [
"Return",
"param",
"content"
] | 31deaf7f085d6456d8a323e7ac3cc9914fbe49a9 | https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Element/Param.php#L163-L186 | train |
buflix/SimpleCollection | src/SimpleCollection/Entity/AbstractEntityCollection.php | AbstractEntityCollection.offsetSet | public function offsetSet($mOffset, $oEntity)
{
$this->checkClass($oEntity);
return parent::offsetSet($mOffset, $oEntity);
} | php | public function offsetSet($mOffset, $oEntity)
{
$this->checkClass($oEntity);
return parent::offsetSet($mOffset, $oEntity);
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"mOffset",
",",
"$",
"oEntity",
")",
"{",
"$",
"this",
"->",
"checkClass",
"(",
"$",
"oEntity",
")",
";",
"return",
"parent",
"::",
"offsetSet",
"(",
"$",
"mOffset",
",",
"$",
"oEntity",
")",
";",
"}"
] | set the entity by the given offset
@param string|int $mOffset Offset
@param EntityInterface $oEntity ProxyServer
@return $this
@throws \InvalidArgumentException | [
"set",
"the",
"entity",
"by",
"the",
"given",
"offset"
] | 405504d8be6415a872a5a49ce8223c22a932831a | https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/Entity/AbstractEntityCollection.php#L38-L43 | train |
buflix/SimpleCollection | src/SimpleCollection/Entity/AbstractEntityCollection.php | AbstractEntityCollection.toArray | public function toArray()
{
$aReturn = array();
foreach ($this->values as $sKey => $oEntity) {
/* @var EntityInterface $oEntity */
$aReturn[$sKey] = $oEntity->toArray();
}
return $aReturn;
} | php | public function toArray()
{
$aReturn = array();
foreach ($this->values as $sKey => $oEntity) {
/* @var EntityInterface $oEntity */
$aReturn[$sKey] = $oEntity->toArray();
}
return $aReturn;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"aReturn",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"sKey",
"=>",
"$",
"oEntity",
")",
"{",
"/* @var EntityInterface $oEntity */",
"$",
"aReturn",
"[",
"$",
"sKey",
"]",
"=",
"$",
"oEntity",
"->",
"toArray",
"(",
")",
";",
"}",
"return",
"$",
"aReturn",
";",
"}"
] | return this collection as array
@return array | [
"return",
"this",
"collection",
"as",
"array"
] | 405504d8be6415a872a5a49ce8223c22a932831a | https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/Entity/AbstractEntityCollection.php#L65-L75 | train |
drdplusinfo/drdplus-profession-levels | DrdPlus/Person/ProfessionLevels/ProfessionFirstLevel.php | ProfessionFirstLevel.checkPropertyIncrement | protected function checkPropertyIncrement(BaseProperty $baseProperty, Profession $profession)
{
$propertyFirstLevelModifier = static::getBasePropertyFirstLevelModifier(
PropertyCode::getIt($baseProperty->getCode()),
$profession
);
if ($baseProperty->getValue() !== $propertyFirstLevelModifier) {
throw new Exceptions\InvalidFirstLevelPropertyValue(
"On first level has to be {$baseProperty->getCode()} of value {$propertyFirstLevelModifier}"
. ", got {$baseProperty->getValue()}"
);
}
} | php | protected function checkPropertyIncrement(BaseProperty $baseProperty, Profession $profession)
{
$propertyFirstLevelModifier = static::getBasePropertyFirstLevelModifier(
PropertyCode::getIt($baseProperty->getCode()),
$profession
);
if ($baseProperty->getValue() !== $propertyFirstLevelModifier) {
throw new Exceptions\InvalidFirstLevelPropertyValue(
"On first level has to be {$baseProperty->getCode()} of value {$propertyFirstLevelModifier}"
. ", got {$baseProperty->getValue()}"
);
}
} | [
"protected",
"function",
"checkPropertyIncrement",
"(",
"BaseProperty",
"$",
"baseProperty",
",",
"Profession",
"$",
"profession",
")",
"{",
"$",
"propertyFirstLevelModifier",
"=",
"static",
"::",
"getBasePropertyFirstLevelModifier",
"(",
"PropertyCode",
"::",
"getIt",
"(",
"$",
"baseProperty",
"->",
"getCode",
"(",
")",
")",
",",
"$",
"profession",
")",
";",
"if",
"(",
"$",
"baseProperty",
"->",
"getValue",
"(",
")",
"!==",
"$",
"propertyFirstLevelModifier",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"InvalidFirstLevelPropertyValue",
"(",
"\"On first level has to be {$baseProperty->getCode()} of value {$propertyFirstLevelModifier}\"",
".",
"\", got {$baseProperty->getValue()}\"",
")",
";",
"}",
"}"
] | It is only the increment based on first level of specific profession.
There are other increments like race, size etc., solved in different library.
@param BaseProperty $baseProperty
@param Profession $profession
@throws \DrdPlus\Person\ProfessionLevels\Exceptions\InvalidFirstLevelPropertyValue | [
"It",
"is",
"only",
"the",
"increment",
"based",
"on",
"first",
"level",
"of",
"specific",
"profession",
".",
"There",
"are",
"other",
"increments",
"like",
"race",
"size",
"etc",
".",
"solved",
"in",
"different",
"library",
"."
] | c8c07b98dd47412f9770456a97e4728106d2c5fc | https://github.com/drdplusinfo/drdplus-profession-levels/blob/c8c07b98dd47412f9770456a97e4728106d2c5fc/DrdPlus/Person/ProfessionLevels/ProfessionFirstLevel.php#L67-L79 | train |
Waryway/PhpTraitsLibrary | src/Singleton.php | Singleton.instance | final public static function instance() {
$c = get_called_class();
if( ! isset( self::$instances[$c] ) )
{
self::$instances[$c] = new $c;
}
return self::$instances[$c];
} | php | final public static function instance() {
$c = get_called_class();
if( ! isset( self::$instances[$c] ) )
{
self::$instances[$c] = new $c;
}
return self::$instances[$c];
} | [
"final",
"public",
"static",
"function",
"instance",
"(",
")",
"{",
"$",
"c",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"c",
"]",
")",
")",
"{",
"self",
"::",
"$",
"instances",
"[",
"$",
"c",
"]",
"=",
"new",
"$",
"c",
";",
"}",
"return",
"self",
"::",
"$",
"instances",
"[",
"$",
"c",
"]",
";",
"}"
] | Grab an instance of the singleton.
@return self | [
"Grab",
"an",
"instance",
"of",
"the",
"singleton",
"."
] | 90c02e09b92e94664669b020b47a20a1590c4a4a | https://github.com/Waryway/PhpTraitsLibrary/blob/90c02e09b92e94664669b020b47a20a1590c4a4a/src/Singleton.php#L39-L48 | train |
bheisig/cli | src/IO.php | IO.out | public static function out($line, ...$args) {
if (count($args) > 0) {
$line = call_user_func_array(
'sprintf',
array_merge([$line], $args)
);
}
fwrite(STDOUT, $line . PHP_EOL);
} | php | public static function out($line, ...$args) {
if (count($args) > 0) {
$line = call_user_func_array(
'sprintf',
array_merge([$line], $args)
);
}
fwrite(STDOUT, $line . PHP_EOL);
} | [
"public",
"static",
"function",
"out",
"(",
"$",
"line",
",",
"...",
"$",
"args",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"0",
")",
"{",
"$",
"line",
"=",
"call_user_func_array",
"(",
"'sprintf'",
",",
"array_merge",
"(",
"[",
"$",
"line",
"]",
",",
"$",
"args",
")",
")",
";",
"}",
"fwrite",
"(",
"STDOUT",
",",
"$",
"line",
".",
"PHP_EOL",
")",
";",
"}"
] | Write line to STDOUT
@param string $line Line
@param mixed ...$args (Optional) One or more arguments | [
"Write",
"line",
"to",
"STDOUT"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/IO.php#L40-L49 | train |
bheisig/cli | src/IO.php | IO.err | public static function err($message, ...$args) {
if (count($args) > 0) {
$message = call_user_func_array(
'sprintf',
array_merge([$message], $args)
);
}
fwrite(STDERR, $message . PHP_EOL);
} | php | public static function err($message, ...$args) {
if (count($args) > 0) {
$message = call_user_func_array(
'sprintf',
array_merge([$message], $args)
);
}
fwrite(STDERR, $message . PHP_EOL);
} | [
"public",
"static",
"function",
"err",
"(",
"$",
"message",
",",
"...",
"$",
"args",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"0",
")",
"{",
"$",
"message",
"=",
"call_user_func_array",
"(",
"'sprintf'",
",",
"array_merge",
"(",
"[",
"$",
"message",
"]",
",",
"$",
"args",
")",
")",
";",
"}",
"fwrite",
"(",
"STDERR",
",",
"$",
"message",
".",
"PHP_EOL",
")",
";",
"}"
] | Write message to STDERR
@param string $message Message
@param mixed ...$args (Optional) One or more arguments | [
"Write",
"message",
"to",
"STDERR"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/IO.php#L57-L66 | train |
bheisig/cli | src/IO.php | IO.in | public static function in($message, ...$args) {
if ($message !== '') {
if (count($args) > 0) {
$message = call_user_func_array(
'sprintf',
array_merge([$message], $args)
);
}
$message .= ' ';
}
fwrite(STDERR, $message);
$input = fgets(STDIN);
if ($input === false) {
throw new Exception('Unable to read from STDIN');
}
return trim($input);
} | php | public static function in($message, ...$args) {
if ($message !== '') {
if (count($args) > 0) {
$message = call_user_func_array(
'sprintf',
array_merge([$message], $args)
);
}
$message .= ' ';
}
fwrite(STDERR, $message);
$input = fgets(STDIN);
if ($input === false) {
throw new Exception('Unable to read from STDIN');
}
return trim($input);
} | [
"public",
"static",
"function",
"in",
"(",
"$",
"message",
",",
"...",
"$",
"args",
")",
"{",
"if",
"(",
"$",
"message",
"!==",
"''",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"0",
")",
"{",
"$",
"message",
"=",
"call_user_func_array",
"(",
"'sprintf'",
",",
"array_merge",
"(",
"[",
"$",
"message",
"]",
",",
"$",
"args",
")",
")",
";",
"}",
"$",
"message",
".=",
"' '",
";",
"}",
"fwrite",
"(",
"STDERR",
",",
"$",
"message",
")",
";",
"$",
"input",
"=",
"fgets",
"(",
"STDIN",
")",
";",
"if",
"(",
"$",
"input",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to read from STDIN'",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"input",
")",
";",
"}"
] | Read from STDIN
@param string $message Message
@param mixed ...$args (Optional) One or more arguments
@return string User input
@throws Exception on error | [
"Read",
"from",
"STDIN"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/IO.php#L78-L99 | train |
SergioMadness/pwf-helpers | src/Validator.php | Validator.validate | public static function validate($type, $paramName, $data, array $params = [])
{
$data = (array) $data;
switch ($type) {
case self::VALIDATOR_USER:
return static::validateByCallback($paramName, $data, $params);
case self::VALIDATOR_EMAIL:
return static::validateEmail($paramName, $data);
case self::VALIDATOR_LENGTH:
return static::validateLength($paramName, $data, $params);
case self::VALIDATOR_EQUAL:
return static::validateEquality($paramName, $data, $params);
default:
throw new \Exception('Unknown validator');
}
} | php | public static function validate($type, $paramName, $data, array $params = [])
{
$data = (array) $data;
switch ($type) {
case self::VALIDATOR_USER:
return static::validateByCallback($paramName, $data, $params);
case self::VALIDATOR_EMAIL:
return static::validateEmail($paramName, $data);
case self::VALIDATOR_LENGTH:
return static::validateLength($paramName, $data, $params);
case self::VALIDATOR_EQUAL:
return static::validateEquality($paramName, $data, $params);
default:
throw new \Exception('Unknown validator');
}
} | [
"public",
"static",
"function",
"validate",
"(",
"$",
"type",
",",
"$",
"paramName",
",",
"$",
"data",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"data",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"self",
"::",
"VALIDATOR_USER",
":",
"return",
"static",
"::",
"validateByCallback",
"(",
"$",
"paramName",
",",
"$",
"data",
",",
"$",
"params",
")",
";",
"case",
"self",
"::",
"VALIDATOR_EMAIL",
":",
"return",
"static",
"::",
"validateEmail",
"(",
"$",
"paramName",
",",
"$",
"data",
")",
";",
"case",
"self",
"::",
"VALIDATOR_LENGTH",
":",
"return",
"static",
"::",
"validateLength",
"(",
"$",
"paramName",
",",
"$",
"data",
",",
"$",
"params",
")",
";",
"case",
"self",
"::",
"VALIDATOR_EQUAL",
":",
"return",
"static",
"::",
"validateEquality",
"(",
"$",
"paramName",
",",
"$",
"data",
",",
"$",
"params",
")",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unknown validator'",
")",
";",
"}",
"}"
] | Validate by type
@param string $type
@param string $paramName
@param array $data
@param array $params
@return mixed
@throws \Exception | [
"Validate",
"by",
"type"
] | d6cd44807c120356d60618cb08f237841c35e293 | https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/Validator.php#L37-L52 | train |
SergioMadness/pwf-helpers | src/Validator.php | Validator.validateEmail | public static function validateEmail($paramName, array $data)
{
$result = false;
if (isset($data[$paramName])) {
$result = filter_var($data[$paramName], FILTER_VALIDATE_EMAIL) !== false;
} else {
throw new \Exception('Parameter is not set');
}
return $result;
} | php | public static function validateEmail($paramName, array $data)
{
$result = false;
if (isset($data[$paramName])) {
$result = filter_var($data[$paramName], FILTER_VALIDATE_EMAIL) !== false;
} else {
throw new \Exception('Parameter is not set');
}
return $result;
} | [
"public",
"static",
"function",
"validateEmail",
"(",
"$",
"paramName",
",",
"array",
"$",
"data",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"paramName",
"]",
")",
")",
"{",
"$",
"result",
"=",
"filter_var",
"(",
"$",
"data",
"[",
"$",
"paramName",
"]",
",",
"FILTER_VALIDATE_EMAIL",
")",
"!==",
"false",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Parameter is not set'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Validate e-mail
@param string $paramName
@param array $data
@return bool
@throws \Exception | [
"Validate",
"e",
"-",
"mail"
] | d6cd44807c120356d60618cb08f237841c35e293 | https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/Validator.php#L119-L128 | train |
SergioMadness/pwf-helpers | src/Validator.php | Validator.validateByCallback | public static function validateByCallback($paramName, array $data,
array $params)
{
if (isset($params['callback'])) {
return $params['callback']($paramName, $data);
} else {
throw new \Exception('Callback parameter is required');
}
} | php | public static function validateByCallback($paramName, array $data,
array $params)
{
if (isset($params['callback'])) {
return $params['callback']($paramName, $data);
} else {
throw new \Exception('Callback parameter is required');
}
} | [
"public",
"static",
"function",
"validateByCallback",
"(",
"$",
"paramName",
",",
"array",
"$",
"data",
",",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'callback'",
"]",
")",
")",
"{",
"return",
"$",
"params",
"[",
"'callback'",
"]",
"(",
"$",
"paramName",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Callback parameter is required'",
")",
";",
"}",
"}"
] | Validate by user function
@param string $paramName
@param mixed $data
@param array $params
@return mixed
@throws \Exception | [
"Validate",
"by",
"user",
"function"
] | d6cd44807c120356d60618cb08f237841c35e293 | https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/Validator.php#L139-L147 | train |
kambalabs/KmbZendDbInfrastructure | src/KmbZendDbInfrastructure/Service/RevisionService.php | RevisionService.release | public function release(RevisionInterface $revision, UserInterface $user, $comment)
{
$connection = $this->revisionRepository->getDbAdapter()->getDriver()->getConnection()->beginTransaction();
try {
if ($revision->getReleasedAt() != null) {
$this->revisionRepository->remove($revision->getEnvironment()->getCurrentRevision());
$revision = clone $revision;
$revision->setReleasedAt($this->dateTimeFactory->now());
$revision->setReleasedBy($user->getName());
$revision->setComment($comment);
$this->revisionRepository->add($revision);
} else {
$revision->setReleasedAt($this->dateTimeFactory->now());
$revision->setReleasedBy($user->getName());
$revision->setComment($comment);
$this->revisionRepository->update($revision);
}
$newCurrentRevision = clone $revision;
$this->revisionRepository->add($newCurrentRevision);
} catch (ExceptionInterface $e) {
$connection->rollback();
throw $e;
}
$connection->commit();
return $this;
} | php | public function release(RevisionInterface $revision, UserInterface $user, $comment)
{
$connection = $this->revisionRepository->getDbAdapter()->getDriver()->getConnection()->beginTransaction();
try {
if ($revision->getReleasedAt() != null) {
$this->revisionRepository->remove($revision->getEnvironment()->getCurrentRevision());
$revision = clone $revision;
$revision->setReleasedAt($this->dateTimeFactory->now());
$revision->setReleasedBy($user->getName());
$revision->setComment($comment);
$this->revisionRepository->add($revision);
} else {
$revision->setReleasedAt($this->dateTimeFactory->now());
$revision->setReleasedBy($user->getName());
$revision->setComment($comment);
$this->revisionRepository->update($revision);
}
$newCurrentRevision = clone $revision;
$this->revisionRepository->add($newCurrentRevision);
} catch (ExceptionInterface $e) {
$connection->rollback();
throw $e;
}
$connection->commit();
return $this;
} | [
"public",
"function",
"release",
"(",
"RevisionInterface",
"$",
"revision",
",",
"UserInterface",
"$",
"user",
",",
"$",
"comment",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"revisionRepository",
"->",
"getDbAdapter",
"(",
")",
"->",
"getDriver",
"(",
")",
"->",
"getConnection",
"(",
")",
"->",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"if",
"(",
"$",
"revision",
"->",
"getReleasedAt",
"(",
")",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"revisionRepository",
"->",
"remove",
"(",
"$",
"revision",
"->",
"getEnvironment",
"(",
")",
"->",
"getCurrentRevision",
"(",
")",
")",
";",
"$",
"revision",
"=",
"clone",
"$",
"revision",
";",
"$",
"revision",
"->",
"setReleasedAt",
"(",
"$",
"this",
"->",
"dateTimeFactory",
"->",
"now",
"(",
")",
")",
";",
"$",
"revision",
"->",
"setReleasedBy",
"(",
"$",
"user",
"->",
"getName",
"(",
")",
")",
";",
"$",
"revision",
"->",
"setComment",
"(",
"$",
"comment",
")",
";",
"$",
"this",
"->",
"revisionRepository",
"->",
"add",
"(",
"$",
"revision",
")",
";",
"}",
"else",
"{",
"$",
"revision",
"->",
"setReleasedAt",
"(",
"$",
"this",
"->",
"dateTimeFactory",
"->",
"now",
"(",
")",
")",
";",
"$",
"revision",
"->",
"setReleasedBy",
"(",
"$",
"user",
"->",
"getName",
"(",
")",
")",
";",
"$",
"revision",
"->",
"setComment",
"(",
"$",
"comment",
")",
";",
"$",
"this",
"->",
"revisionRepository",
"->",
"update",
"(",
"$",
"revision",
")",
";",
"}",
"$",
"newCurrentRevision",
"=",
"clone",
"$",
"revision",
";",
"$",
"this",
"->",
"revisionRepository",
"->",
"add",
"(",
"$",
"newCurrentRevision",
")",
";",
"}",
"catch",
"(",
"ExceptionInterface",
"$",
"e",
")",
"{",
"$",
"connection",
"->",
"rollback",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"connection",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Release specified revision and create a current revision from it.
If the revision had already been released, the current revision should be removed first.
@param RevisionInterface $revision
@param UserInterface $user
@param string $comment
@throws \Zend\Db\Exception\ExceptionInterface
@return RevisionService | [
"Release",
"specified",
"revision",
"and",
"create",
"a",
"current",
"revision",
"from",
"it",
".",
"If",
"the",
"revision",
"had",
"already",
"been",
"released",
"the",
"current",
"revision",
"should",
"be",
"removed",
"first",
"."
] | 9bf4df4272d2064965202d0e689f944d56a4c6bb | https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Service/RevisionService.php#L47-L72 | train |
kambalabs/KmbZendDbInfrastructure | src/KmbZendDbInfrastructure/Service/RevisionService.php | RevisionService.remove | public function remove(RevisionInterface $revision)
{
$connection = $this->revisionRepository->getDbAdapter()->getDriver()->getConnection()->beginTransaction();
try {
$this->revisionRepository->remove($revision);
if ($revision->getReleasedAt() == null) {
$lastReleasedRevision = $revision->getEnvironment()->getLastReleasedRevision();
$this->revisionRepository->add(clone $lastReleasedRevision);
}
} catch (ExceptionInterface $e) {
$connection->rollback();
throw $e;
}
$connection->commit();
return $this;
} | php | public function remove(RevisionInterface $revision)
{
$connection = $this->revisionRepository->getDbAdapter()->getDriver()->getConnection()->beginTransaction();
try {
$this->revisionRepository->remove($revision);
if ($revision->getReleasedAt() == null) {
$lastReleasedRevision = $revision->getEnvironment()->getLastReleasedRevision();
$this->revisionRepository->add(clone $lastReleasedRevision);
}
} catch (ExceptionInterface $e) {
$connection->rollback();
throw $e;
}
$connection->commit();
return $this;
} | [
"public",
"function",
"remove",
"(",
"RevisionInterface",
"$",
"revision",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"revisionRepository",
"->",
"getDbAdapter",
"(",
")",
"->",
"getDriver",
"(",
")",
"->",
"getConnection",
"(",
")",
"->",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"revisionRepository",
"->",
"remove",
"(",
"$",
"revision",
")",
";",
"if",
"(",
"$",
"revision",
"->",
"getReleasedAt",
"(",
")",
"==",
"null",
")",
"{",
"$",
"lastReleasedRevision",
"=",
"$",
"revision",
"->",
"getEnvironment",
"(",
")",
"->",
"getLastReleasedRevision",
"(",
")",
";",
"$",
"this",
"->",
"revisionRepository",
"->",
"add",
"(",
"clone",
"$",
"lastReleasedRevision",
")",
";",
"}",
"}",
"catch",
"(",
"ExceptionInterface",
"$",
"e",
")",
"{",
"$",
"connection",
"->",
"rollback",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"connection",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Remove specified revision.
If it's the current revision, another current revision should be recreate from last released revision.
@param RevisionInterface $revision
@throws \Zend\Db\Exception\ExceptionInterface
@return RevisionService | [
"Remove",
"specified",
"revision",
".",
"If",
"it",
"s",
"the",
"current",
"revision",
"another",
"current",
"revision",
"should",
"be",
"recreate",
"from",
"last",
"released",
"revision",
"."
] | 9bf4df4272d2064965202d0e689f944d56a4c6bb | https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Service/RevisionService.php#L82-L97 | train |
DreadLabs/typo3-cms-phing-helper | Classes/Tasks/GenerateLocalConfigurationTask.php | GenerateLocalConfigurationTask.transformPropertiesToArray | protected function transformPropertiesToArray()
{
$properties = $this->project->getProperties();
foreach ($properties as $propertyName => $propertyValue) {
if (0 !== strpos($propertyName, $this->propertyPrefix . '.')) {
continue;
}
list(, $mainKey, $subKey) = $this->splitPropertyName($propertyName);
$this->addLocalConfigurationValue($mainKey, $subKey, $propertyValue);
}
} | php | protected function transformPropertiesToArray()
{
$properties = $this->project->getProperties();
foreach ($properties as $propertyName => $propertyValue) {
if (0 !== strpos($propertyName, $this->propertyPrefix . '.')) {
continue;
}
list(, $mainKey, $subKey) = $this->splitPropertyName($propertyName);
$this->addLocalConfigurationValue($mainKey, $subKey, $propertyValue);
}
} | [
"protected",
"function",
"transformPropertiesToArray",
"(",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"project",
"->",
"getProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"propertyName",
"=>",
"$",
"propertyValue",
")",
"{",
"if",
"(",
"0",
"!==",
"strpos",
"(",
"$",
"propertyName",
",",
"$",
"this",
"->",
"propertyPrefix",
".",
"'.'",
")",
")",
"{",
"continue",
";",
"}",
"list",
"(",
",",
"$",
"mainKey",
",",
"$",
"subKey",
")",
"=",
"$",
"this",
"->",
"splitPropertyName",
"(",
"$",
"propertyName",
")",
";",
"$",
"this",
"->",
"addLocalConfigurationValue",
"(",
"$",
"mainKey",
",",
"$",
"subKey",
",",
"$",
"propertyValue",
")",
";",
"}",
"}"
] | transforms the flat property list into a local configuration array
Example
Given
LocalConfiguration.DB.database=my_database_name
Result
$this->localConfiguration = array(
'DB' => array(
'database' => 'my_database_name'
)
);
@return void | [
"transforms",
"the",
"flat",
"property",
"list",
"into",
"a",
"local",
"configuration",
"array"
] | b6606102c4702a92bc1872eba962febceaa0e645 | https://github.com/DreadLabs/typo3-cms-phing-helper/blob/b6606102c4702a92bc1872eba962febceaa0e645/Classes/Tasks/GenerateLocalConfigurationTask.php#L153-L166 | train |
ZFury/framework | library/Grid/AbstractGrid.php | AbstractGrid.processRequest | protected function processRequest()
{
/** @var \Zend\Http\PhpEnvironment\Request $request */
$request = $this->sm->get('Request');
$url = explode('?', $request->getRequestUri());
$this->url = $url[0];
$params = $request->getQuery();
if ($params->get('page')) {
//set page
$this->setPage((int)$params->get('page'));
}
if ($params->get('limit')) {
//set limit
$this->setLimit((int)$params->get('limit'));
}
foreach ($this->allowedOrders as $column) {
$columnMod = str_replace('.', '_', $column);
$order = $params->get('order-' . $columnMod);
if ($order) {
$this->setOrder([
$column => $order
]);
}
}
foreach ($this->allowedFilters as $column) {
$columnMod = str_replace('.', '_', $column);
$filter = $params->get('filter-' . $columnMod);
if ($filter) {
$this->setFilter([$column => $filter]);
}
}
} | php | protected function processRequest()
{
/** @var \Zend\Http\PhpEnvironment\Request $request */
$request = $this->sm->get('Request');
$url = explode('?', $request->getRequestUri());
$this->url = $url[0];
$params = $request->getQuery();
if ($params->get('page')) {
//set page
$this->setPage((int)$params->get('page'));
}
if ($params->get('limit')) {
//set limit
$this->setLimit((int)$params->get('limit'));
}
foreach ($this->allowedOrders as $column) {
$columnMod = str_replace('.', '_', $column);
$order = $params->get('order-' . $columnMod);
if ($order) {
$this->setOrder([
$column => $order
]);
}
}
foreach ($this->allowedFilters as $column) {
$columnMod = str_replace('.', '_', $column);
$filter = $params->get('filter-' . $columnMod);
if ($filter) {
$this->setFilter([$column => $filter]);
}
}
} | [
"protected",
"function",
"processRequest",
"(",
")",
"{",
"/** @var \\Zend\\Http\\PhpEnvironment\\Request $request */",
"$",
"request",
"=",
"$",
"this",
"->",
"sm",
"->",
"get",
"(",
"'Request'",
")",
";",
"$",
"url",
"=",
"explode",
"(",
"'?'",
",",
"$",
"request",
"->",
"getRequestUri",
"(",
")",
")",
";",
"$",
"this",
"->",
"url",
"=",
"$",
"url",
"[",
"0",
"]",
";",
"$",
"params",
"=",
"$",
"request",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"$",
"params",
"->",
"get",
"(",
"'page'",
")",
")",
"{",
"//set page",
"$",
"this",
"->",
"setPage",
"(",
"(",
"int",
")",
"$",
"params",
"->",
"get",
"(",
"'page'",
")",
")",
";",
"}",
"if",
"(",
"$",
"params",
"->",
"get",
"(",
"'limit'",
")",
")",
"{",
"//set limit",
"$",
"this",
"->",
"setLimit",
"(",
"(",
"int",
")",
"$",
"params",
"->",
"get",
"(",
"'limit'",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"allowedOrders",
"as",
"$",
"column",
")",
"{",
"$",
"columnMod",
"=",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"column",
")",
";",
"$",
"order",
"=",
"$",
"params",
"->",
"get",
"(",
"'order-'",
".",
"$",
"columnMod",
")",
";",
"if",
"(",
"$",
"order",
")",
"{",
"$",
"this",
"->",
"setOrder",
"(",
"[",
"$",
"column",
"=>",
"$",
"order",
"]",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"allowedFilters",
"as",
"$",
"column",
")",
"{",
"$",
"columnMod",
"=",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"column",
")",
";",
"$",
"filter",
"=",
"$",
"params",
"->",
"get",
"(",
"'filter-'",
".",
"$",
"columnMod",
")",
";",
"if",
"(",
"$",
"filter",
")",
"{",
"$",
"this",
"->",
"setFilter",
"(",
"[",
"$",
"column",
"=>",
"$",
"filter",
"]",
")",
";",
"}",
"}",
"}"
] | Parses request and sets grid params | [
"Parses",
"request",
"and",
"sets",
"grid",
"params"
] | eee4ca2a64d2d65490777b08be56c4c9b67bc892 | https://github.com/ZFury/framework/blob/eee4ca2a64d2d65490777b08be56c4c9b67bc892/library/Grid/AbstractGrid.php#L151-L186 | train |
ZFury/framework | library/Grid/AbstractGrid.php | AbstractGrid.countTotalRows | protected function countTotalRows()
{
$source = $this->getSource();
/** @var \Doctrine\ORM\Query\Expr\Select $select */
$source->resetDQLPart('select')->setFirstResult(0)->select('count(' . $this->entityAlias . ')');
return (int)$source->getQuery()->getSingleScalarResult();
} | php | protected function countTotalRows()
{
$source = $this->getSource();
/** @var \Doctrine\ORM\Query\Expr\Select $select */
$source->resetDQLPart('select')->setFirstResult(0)->select('count(' . $this->entityAlias . ')');
return (int)$source->getQuery()->getSingleScalarResult();
} | [
"protected",
"function",
"countTotalRows",
"(",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"getSource",
"(",
")",
";",
"/** @var \\Doctrine\\ORM\\Query\\Expr\\Select $select */",
"$",
"source",
"->",
"resetDQLPart",
"(",
"'select'",
")",
"->",
"setFirstResult",
"(",
"0",
")",
"->",
"select",
"(",
"'count('",
".",
"$",
"this",
"->",
"entityAlias",
".",
"')'",
")",
";",
"return",
"(",
"int",
")",
"$",
"source",
"->",
"getQuery",
"(",
")",
"->",
"getSingleScalarResult",
"(",
")",
";",
"}"
] | Get total rows in result ignoring limit
@return int | [
"Get",
"total",
"rows",
"in",
"result",
"ignoring",
"limit"
] | eee4ca2a64d2d65490777b08be56c4c9b67bc892 | https://github.com/ZFury/framework/blob/eee4ca2a64d2d65490777b08be56c4c9b67bc892/library/Grid/AbstractGrid.php#L491-L497 | train |
ZFury/framework | library/Grid/AbstractGrid.php | AbstractGrid.order | public function order($column)
{
if (!in_array($column, $this->allowedOrders)) {
return null;
}
if (isset($this->order[$column])) {
$order = strtolower($this->order[$column]) == self::ORDER_ASC ? self::ORDER_DESC : self::ORDER_ASC;
} else {
$order = self::ORDER_ASC;
}
return $this->getUrl(['order-' . $column => $order]);
} | php | public function order($column)
{
if (!in_array($column, $this->allowedOrders)) {
return null;
}
if (isset($this->order[$column])) {
$order = strtolower($this->order[$column]) == self::ORDER_ASC ? self::ORDER_DESC : self::ORDER_ASC;
} else {
$order = self::ORDER_ASC;
}
return $this->getUrl(['order-' . $column => $order]);
} | [
"public",
"function",
"order",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"column",
",",
"$",
"this",
"->",
"allowedOrders",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"order",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"order",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"order",
"[",
"$",
"column",
"]",
")",
"==",
"self",
"::",
"ORDER_ASC",
"?",
"self",
"::",
"ORDER_DESC",
":",
"self",
"::",
"ORDER_ASC",
";",
"}",
"else",
"{",
"$",
"order",
"=",
"self",
"::",
"ORDER_ASC",
";",
"}",
"return",
"$",
"this",
"->",
"getUrl",
"(",
"[",
"'order-'",
".",
"$",
"column",
"=>",
"$",
"order",
"]",
")",
";",
"}"
] | Get url for order by column name
@param $column
@return string | [
"Get",
"url",
"for",
"order",
"by",
"column",
"name"
] | eee4ca2a64d2d65490777b08be56c4c9b67bc892 | https://github.com/ZFury/framework/blob/eee4ca2a64d2d65490777b08be56c4c9b67bc892/library/Grid/AbstractGrid.php#L643-L656 | train |
ptlis/grep-db | src/Metadata/MySQL/MetadataFactory.php | MetadataFactory.getServerMetadata | public function getServerMetadata(
Connection $connection
) {
// Attempt to list databases, ignoring internal databases
try {
$statement = $connection->query('SHOW DATABASES WHERE `Database` NOT IN ("information_schema", "performance_schema", "sys", "mysql");');
} catch (\Throwable $e) {
throw new \RuntimeException('Failed to list databases: ' . $e->getMessage());
}
$databaseMetadataList = [];
/** @var string $databaseName */
while ($databaseName = $statement->fetchColumn(0)) {
$databaseMetadataList[] = $this->getDatabaseMetadata($connection, $databaseName);
}
return new ServerMetadata($connection->getHost(), $databaseMetadataList);
} | php | public function getServerMetadata(
Connection $connection
) {
// Attempt to list databases, ignoring internal databases
try {
$statement = $connection->query('SHOW DATABASES WHERE `Database` NOT IN ("information_schema", "performance_schema", "sys", "mysql");');
} catch (\Throwable $e) {
throw new \RuntimeException('Failed to list databases: ' . $e->getMessage());
}
$databaseMetadataList = [];
/** @var string $databaseName */
while ($databaseName = $statement->fetchColumn(0)) {
$databaseMetadataList[] = $this->getDatabaseMetadata($connection, $databaseName);
}
return new ServerMetadata($connection->getHost(), $databaseMetadataList);
} | [
"public",
"function",
"getServerMetadata",
"(",
"Connection",
"$",
"connection",
")",
"{",
"// Attempt to list databases, ignoring internal databases",
"try",
"{",
"$",
"statement",
"=",
"$",
"connection",
"->",
"query",
"(",
"'SHOW DATABASES WHERE `Database` NOT IN (\"information_schema\", \"performance_schema\", \"sys\", \"mysql\");'",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Failed to list databases: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"databaseMetadataList",
"=",
"[",
"]",
";",
"/** @var string $databaseName */",
"while",
"(",
"$",
"databaseName",
"=",
"$",
"statement",
"->",
"fetchColumn",
"(",
"0",
")",
")",
"{",
"$",
"databaseMetadataList",
"[",
"]",
"=",
"$",
"this",
"->",
"getDatabaseMetadata",
"(",
"$",
"connection",
",",
"$",
"databaseName",
")",
";",
"}",
"return",
"new",
"ServerMetadata",
"(",
"$",
"connection",
"->",
"getHost",
"(",
")",
",",
"$",
"databaseMetadataList",
")",
";",
"}"
] | Query the server and build server metadata DTO. | [
"Query",
"the",
"server",
"and",
"build",
"server",
"metadata",
"DTO",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Metadata/MySQL/MetadataFactory.php#L21-L38 | train |
ptlis/grep-db | src/Metadata/MySQL/MetadataFactory.php | MetadataFactory.getDatabaseMetadata | public function getDatabaseMetadata(
Connection $connection,
string $databaseName
): DatabaseMetadata {
// Get a list of table names
$tableNameStatement = $connection
->createQueryBuilder()
->select([
'tables.TABLE_NAME AS name'
])
->from('information_schema.TABLES', 'tables')
->where('TABLE_SCHEMA = :schema')
->andWhere('TABLE_TYPE = "BASE TABLE"')
->setParameter('schema', $databaseName)
->execute();
// Build table metadata
$tableMetadataList = [];
while ($tableName = $tableNameStatement->fetchColumn(0)) {
$tableMetadataList[] = $this->getTableMetadata($connection, $databaseName, $tableName);
}
return new DatabaseMetadata($databaseName, $tableMetadataList);
} | php | public function getDatabaseMetadata(
Connection $connection,
string $databaseName
): DatabaseMetadata {
// Get a list of table names
$tableNameStatement = $connection
->createQueryBuilder()
->select([
'tables.TABLE_NAME AS name'
])
->from('information_schema.TABLES', 'tables')
->where('TABLE_SCHEMA = :schema')
->andWhere('TABLE_TYPE = "BASE TABLE"')
->setParameter('schema', $databaseName)
->execute();
// Build table metadata
$tableMetadataList = [];
while ($tableName = $tableNameStatement->fetchColumn(0)) {
$tableMetadataList[] = $this->getTableMetadata($connection, $databaseName, $tableName);
}
return new DatabaseMetadata($databaseName, $tableMetadataList);
} | [
"public",
"function",
"getDatabaseMetadata",
"(",
"Connection",
"$",
"connection",
",",
"string",
"$",
"databaseName",
")",
":",
"DatabaseMetadata",
"{",
"// Get a list of table names",
"$",
"tableNameStatement",
"=",
"$",
"connection",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"[",
"'tables.TABLE_NAME AS name'",
"]",
")",
"->",
"from",
"(",
"'information_schema.TABLES'",
",",
"'tables'",
")",
"->",
"where",
"(",
"'TABLE_SCHEMA = :schema'",
")",
"->",
"andWhere",
"(",
"'TABLE_TYPE = \"BASE TABLE\"'",
")",
"->",
"setParameter",
"(",
"'schema'",
",",
"$",
"databaseName",
")",
"->",
"execute",
"(",
")",
";",
"// Build table metadata",
"$",
"tableMetadataList",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"tableName",
"=",
"$",
"tableNameStatement",
"->",
"fetchColumn",
"(",
"0",
")",
")",
"{",
"$",
"tableMetadataList",
"[",
"]",
"=",
"$",
"this",
"->",
"getTableMetadata",
"(",
"$",
"connection",
",",
"$",
"databaseName",
",",
"$",
"tableName",
")",
";",
"}",
"return",
"new",
"DatabaseMetadata",
"(",
"$",
"databaseName",
",",
"$",
"tableMetadataList",
")",
";",
"}"
] | Query the server and build database metadata DTO. | [
"Query",
"the",
"server",
"and",
"build",
"database",
"metadata",
"DTO",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Metadata/MySQL/MetadataFactory.php#L43-L66 | train |
ptlis/grep-db | src/Metadata/MySQL/MetadataFactory.php | MetadataFactory.getTableMetadata | public function getTableMetadata(
Connection $connection,
string $databaseName,
string $tableName
): TableMetadata {
// Get top-level table information
$tableStatement = $connection
->createQueryBuilder()
->select([
'tables.TABLE_NAME AS name',
'tables.ENGINE AS engine',
'tables.TABLE_COLLATION AS collation',
'tables.TABLE_ROWS AS row_count',
'charset.CHARACTER_SET_NAME AS charset'
])
->from('information_schema.TABLES', 'tables')
->leftJoin(
'tables',
'information_schema.COLLATION_CHARACTER_SET_APPLICABILITY',
'charset',
'tables.TABLE_COLLATION = charset.COLLATION_NAME'
)
->where('TABLE_NAME = :table_name')
->setParameter('table_name', $tableName)
->execute();
$tableRow = $tableStatement->fetch(\PDO::FETCH_ASSOC);
// Get column information
$columnsStatement = $connection
->createQueryBuilder()
->select([
'columns.COLUMN_NAME AS name',
'columns.COLUMN_TYPE AS type',
'columns.CHARACTER_MAXIMUM_LENGTH AS max_length',
'"PRI" = columns.COLUMN_KEY AS is_primary_key',
'"YES" = columns.IS_NULLABLE AS is_nullable',
'(
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = :schema
AND TABLE_NAME = :table_name
AND COLUMN_NAME = columns.COLUMN_NAME
) AS is_indexed'
])
->from('information_schema.COLUMNS', 'columns')
->where('TABLE_SCHEMA = :schema')
->andWhere('TABLE_NAME = :table_name')
->setParameters([
'schema' => $databaseName,
'table_name' => $tableName
])
->execute();
// Build column metadata
$columnMetadataList = [];
foreach ($columnsStatement->fetchAll(\PDO::FETCH_ASSOC) as $columnsRow) {
$columnMetadataList[] = new ColumnMetadata(
$databaseName,
$tableName,
$columnsRow['name'],
$columnsRow['type'],
is_null($columnsRow['max_length']) ? null : intval($columnsRow['max_length']),
boolval($columnsRow['is_primary_key']),
boolval($columnsRow['is_nullable']),
boolval($columnsRow['is_indexed'])
);
}
return new TableMetadata(
$databaseName,
$tableName,
$tableRow['engine'],
$tableRow['collation'],
$tableRow['charset'],
intval($tableRow['row_count']),
$columnMetadataList
);
} | php | public function getTableMetadata(
Connection $connection,
string $databaseName,
string $tableName
): TableMetadata {
// Get top-level table information
$tableStatement = $connection
->createQueryBuilder()
->select([
'tables.TABLE_NAME AS name',
'tables.ENGINE AS engine',
'tables.TABLE_COLLATION AS collation',
'tables.TABLE_ROWS AS row_count',
'charset.CHARACTER_SET_NAME AS charset'
])
->from('information_schema.TABLES', 'tables')
->leftJoin(
'tables',
'information_schema.COLLATION_CHARACTER_SET_APPLICABILITY',
'charset',
'tables.TABLE_COLLATION = charset.COLLATION_NAME'
)
->where('TABLE_NAME = :table_name')
->setParameter('table_name', $tableName)
->execute();
$tableRow = $tableStatement->fetch(\PDO::FETCH_ASSOC);
// Get column information
$columnsStatement = $connection
->createQueryBuilder()
->select([
'columns.COLUMN_NAME AS name',
'columns.COLUMN_TYPE AS type',
'columns.CHARACTER_MAXIMUM_LENGTH AS max_length',
'"PRI" = columns.COLUMN_KEY AS is_primary_key',
'"YES" = columns.IS_NULLABLE AS is_nullable',
'(
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = :schema
AND TABLE_NAME = :table_name
AND COLUMN_NAME = columns.COLUMN_NAME
) AS is_indexed'
])
->from('information_schema.COLUMNS', 'columns')
->where('TABLE_SCHEMA = :schema')
->andWhere('TABLE_NAME = :table_name')
->setParameters([
'schema' => $databaseName,
'table_name' => $tableName
])
->execute();
// Build column metadata
$columnMetadataList = [];
foreach ($columnsStatement->fetchAll(\PDO::FETCH_ASSOC) as $columnsRow) {
$columnMetadataList[] = new ColumnMetadata(
$databaseName,
$tableName,
$columnsRow['name'],
$columnsRow['type'],
is_null($columnsRow['max_length']) ? null : intval($columnsRow['max_length']),
boolval($columnsRow['is_primary_key']),
boolval($columnsRow['is_nullable']),
boolval($columnsRow['is_indexed'])
);
}
return new TableMetadata(
$databaseName,
$tableName,
$tableRow['engine'],
$tableRow['collation'],
$tableRow['charset'],
intval($tableRow['row_count']),
$columnMetadataList
);
} | [
"public",
"function",
"getTableMetadata",
"(",
"Connection",
"$",
"connection",
",",
"string",
"$",
"databaseName",
",",
"string",
"$",
"tableName",
")",
":",
"TableMetadata",
"{",
"// Get top-level table information",
"$",
"tableStatement",
"=",
"$",
"connection",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"[",
"'tables.TABLE_NAME AS name'",
",",
"'tables.ENGINE AS engine'",
",",
"'tables.TABLE_COLLATION AS collation'",
",",
"'tables.TABLE_ROWS AS row_count'",
",",
"'charset.CHARACTER_SET_NAME AS charset'",
"]",
")",
"->",
"from",
"(",
"'information_schema.TABLES'",
",",
"'tables'",
")",
"->",
"leftJoin",
"(",
"'tables'",
",",
"'information_schema.COLLATION_CHARACTER_SET_APPLICABILITY'",
",",
"'charset'",
",",
"'tables.TABLE_COLLATION = charset.COLLATION_NAME'",
")",
"->",
"where",
"(",
"'TABLE_NAME = :table_name'",
")",
"->",
"setParameter",
"(",
"'table_name'",
",",
"$",
"tableName",
")",
"->",
"execute",
"(",
")",
";",
"$",
"tableRow",
"=",
"$",
"tableStatement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"// Get column information",
"$",
"columnsStatement",
"=",
"$",
"connection",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"[",
"'columns.COLUMN_NAME AS name'",
",",
"'columns.COLUMN_TYPE AS type'",
",",
"'columns.CHARACTER_MAXIMUM_LENGTH AS max_length'",
",",
"'\"PRI\" = columns.COLUMN_KEY AS is_primary_key'",
",",
"'\"YES\" = columns.IS_NULLABLE AS is_nullable'",
",",
"'(\n SELECT COUNT(*) \n FROM INFORMATION_SCHEMA.STATISTICS \n WHERE TABLE_SCHEMA = :schema \n AND TABLE_NAME = :table_name \n AND COLUMN_NAME = columns.COLUMN_NAME\n ) AS is_indexed'",
"]",
")",
"->",
"from",
"(",
"'information_schema.COLUMNS'",
",",
"'columns'",
")",
"->",
"where",
"(",
"'TABLE_SCHEMA = :schema'",
")",
"->",
"andWhere",
"(",
"'TABLE_NAME = :table_name'",
")",
"->",
"setParameters",
"(",
"[",
"'schema'",
"=>",
"$",
"databaseName",
",",
"'table_name'",
"=>",
"$",
"tableName",
"]",
")",
"->",
"execute",
"(",
")",
";",
"// Build column metadata",
"$",
"columnMetadataList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columnsStatement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
"as",
"$",
"columnsRow",
")",
"{",
"$",
"columnMetadataList",
"[",
"]",
"=",
"new",
"ColumnMetadata",
"(",
"$",
"databaseName",
",",
"$",
"tableName",
",",
"$",
"columnsRow",
"[",
"'name'",
"]",
",",
"$",
"columnsRow",
"[",
"'type'",
"]",
",",
"is_null",
"(",
"$",
"columnsRow",
"[",
"'max_length'",
"]",
")",
"?",
"null",
":",
"intval",
"(",
"$",
"columnsRow",
"[",
"'max_length'",
"]",
")",
",",
"boolval",
"(",
"$",
"columnsRow",
"[",
"'is_primary_key'",
"]",
")",
",",
"boolval",
"(",
"$",
"columnsRow",
"[",
"'is_nullable'",
"]",
")",
",",
"boolval",
"(",
"$",
"columnsRow",
"[",
"'is_indexed'",
"]",
")",
")",
";",
"}",
"return",
"new",
"TableMetadata",
"(",
"$",
"databaseName",
",",
"$",
"tableName",
",",
"$",
"tableRow",
"[",
"'engine'",
"]",
",",
"$",
"tableRow",
"[",
"'collation'",
"]",
",",
"$",
"tableRow",
"[",
"'charset'",
"]",
",",
"intval",
"(",
"$",
"tableRow",
"[",
"'row_count'",
"]",
")",
",",
"$",
"columnMetadataList",
")",
";",
"}"
] | Query the server and build table metadata DTO. | [
"Query",
"the",
"server",
"and",
"build",
"table",
"metadata",
"DTO",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Metadata/MySQL/MetadataFactory.php#L71-L149 | train |
rzajac/phptools | src/Helper/Debug.php | Debug.getCallStack | public static function getCallStack($asArray = false)
{
$i = 0;
$resp = [];
if (!$asArray) {
$resp[] = str_repeat('=', 50);
}
foreach (debug_backtrace() as $node) {
$file = Arr::get($node, 'file', '');
$file = $file ?: 'no_file';
$fn = $node['function'];
$line = Arr::get($node, 'line', -1);
$i = $asArray ? '' : "$i.";
$resp[] = $i.$file.':'.$fn.' '.$line;
++$i;
}
return $asArray ? $resp : implode("\n", $resp);
} | php | public static function getCallStack($asArray = false)
{
$i = 0;
$resp = [];
if (!$asArray) {
$resp[] = str_repeat('=', 50);
}
foreach (debug_backtrace() as $node) {
$file = Arr::get($node, 'file', '');
$file = $file ?: 'no_file';
$fn = $node['function'];
$line = Arr::get($node, 'line', -1);
$i = $asArray ? '' : "$i.";
$resp[] = $i.$file.':'.$fn.' '.$line;
++$i;
}
return $asArray ? $resp : implode("\n", $resp);
} | [
"public",
"static",
"function",
"getCallStack",
"(",
"$",
"asArray",
"=",
"false",
")",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"resp",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"asArray",
")",
"{",
"$",
"resp",
"[",
"]",
"=",
"str_repeat",
"(",
"'='",
",",
"50",
")",
";",
"}",
"foreach",
"(",
"debug_backtrace",
"(",
")",
"as",
"$",
"node",
")",
"{",
"$",
"file",
"=",
"Arr",
"::",
"get",
"(",
"$",
"node",
",",
"'file'",
",",
"''",
")",
";",
"$",
"file",
"=",
"$",
"file",
"?",
":",
"'no_file'",
";",
"$",
"fn",
"=",
"$",
"node",
"[",
"'function'",
"]",
";",
"$",
"line",
"=",
"Arr",
"::",
"get",
"(",
"$",
"node",
",",
"'line'",
",",
"-",
"1",
")",
";",
"$",
"i",
"=",
"$",
"asArray",
"?",
"''",
":",
"\"$i.\"",
";",
"$",
"resp",
"[",
"]",
"=",
"$",
"i",
".",
"$",
"file",
".",
"':'",
".",
"$",
"fn",
".",
"' '",
".",
"$",
"line",
";",
"++",
"$",
"i",
";",
"}",
"return",
"$",
"asArray",
"?",
"$",
"resp",
":",
"implode",
"(",
"\"\\n\"",
",",
"$",
"resp",
")",
";",
"}"
] | Prints stack trace.
@param bool $asArray
@return string | [
"Prints",
"stack",
"trace",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Debug.php#L34-L57 | train |
vaniocz/stdlib | src/LinkedHashSet.php | LinkedHashSet.add | public function add($value): bool
{
if (isset($this->hashMap[$value])) {
return false;
}
$this->hashMap[$value] = 1;
return true;
} | php | public function add($value): bool
{
if (isset($this->hashMap[$value])) {
return false;
}
$this->hashMap[$value] = 1;
return true;
} | [
"public",
"function",
"add",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hashMap",
"[",
"$",
"value",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"hashMap",
"[",
"$",
"value",
"]",
"=",
"1",
";",
"return",
"true",
";",
"}"
] | Add the given value to the set if it is not already present.
@param mixed $value The value to be added.
@return bool True if the value was not present in the set, false otherwise. | [
"Add",
"the",
"given",
"value",
"to",
"the",
"set",
"if",
"it",
"is",
"not",
"already",
"present",
"."
] | 06a8343c42829d8fdeecad2bb5c30946fbd73e74 | https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/LinkedHashSet.php#L29-L38 | train |
vaniocz/stdlib | src/LinkedHashSet.php | LinkedHashSet.remove | public function remove($value): bool
{
if (!isset($this->hashMap[$value])) {
return false;
}
unset($this->hashMap[$value]);
return true;
} | php | public function remove($value): bool
{
if (!isset($this->hashMap[$value])) {
return false;
}
unset($this->hashMap[$value]);
return true;
} | [
"public",
"function",
"remove",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"hashMap",
"[",
"$",
"value",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"hashMap",
"[",
"$",
"value",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Remove the given value if it's present in the set.
@param mixed $value The value to be removed.
@return bool True if the value was present in the set, false otherwise. | [
"Remove",
"the",
"given",
"value",
"if",
"it",
"s",
"present",
"in",
"the",
"set",
"."
] | 06a8343c42829d8fdeecad2bb5c30946fbd73e74 | https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/LinkedHashSet.php#L59-L68 | train |
agentmedia/phine-core | src/Core/Modules/Backend/AjaxSelectPage.php | AjaxSelectPage.HasPages | protected function HasPages(Site $site)
{
$this->site = $site;
$this->tree = new PageTreeProvider($site);
$this->page = $this->tree->TopMost();
return (bool) $this->page;
} | php | protected function HasPages(Site $site)
{
$this->site = $site;
$this->tree = new PageTreeProvider($site);
$this->page = $this->tree->TopMost();
return (bool) $this->page;
} | [
"protected",
"function",
"HasPages",
"(",
"Site",
"$",
"site",
")",
"{",
"$",
"this",
"->",
"site",
"=",
"$",
"site",
";",
"$",
"this",
"->",
"tree",
"=",
"new",
"PageTreeProvider",
"(",
"$",
"site",
")",
";",
"$",
"this",
"->",
"page",
"=",
"$",
"this",
"->",
"tree",
"->",
"TopMost",
"(",
")",
";",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"page",
";",
"}"
] | Sets the site as current site and returns true if it has pages below
@param Site $site The site to set and check for pages
@return boolean Returns true if the site has pages | [
"Sets",
"the",
"site",
"as",
"current",
"site",
"and",
"returns",
"true",
"if",
"it",
"has",
"pages",
"below"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/AjaxSelectPage.php#L100-L106 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/TableGateway.php | TableGateway.getTable | public function getTable() {
if(false === isset($this -> table)) {
$cl = new \ReflectionClass($this);
return trigger_error(sprintf('No table specified in "%s" class', $cl -> getFileName()), E_USER_ERROR);
}
return $this -> table;
} | php | public function getTable() {
if(false === isset($this -> table)) {
$cl = new \ReflectionClass($this);
return trigger_error(sprintf('No table specified in "%s" class', $cl -> getFileName()), E_USER_ERROR);
}
return $this -> table;
} | [
"public",
"function",
"getTable",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"table",
")",
")",
"{",
"$",
"cl",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'No table specified in \"%s\" class'",
",",
"$",
"cl",
"->",
"getFileName",
"(",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"$",
"this",
"->",
"table",
";",
"}"
] | Returns the table
@return string | [
"Returns",
"the",
"table"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/TableGateway.php#L63-L72 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/TableGateway.php | TableGateway.rows | public function rows($column = '*', $where = null, $params = []) {
if(null === $this -> getAdapter()) {
return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
}
if(false === is_string($column)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($column)), E_USER_ERROR);
}
if(null !== $where && false === is_string($where)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($where)), E_USER_ERROR);
}
if(false === is_array($params)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
}
$query = [];
//Select
$query[] = sprintf('SELECT COUNT(%s) AS amount FROM %s', $this -> getAdapter() -> escape($column), $this -> getAdapter() -> escape($this -> getTable()));
//Where
if(null !== $where) {
$query[] = sprintf('WHERE %s', $this -> getAdapter() -> escape($where));
}
$statement = $this -> getAdapter() -> query(implode(' ', $query), $params) -> execute();
if(true === $statement) {
$amount = $this -> getAdapter() -> toArray();
if(true === isset($amount[0]['amount'])) {
return $amount[0]['amount'];
}
}
return false;
} | php | public function rows($column = '*', $where = null, $params = []) {
if(null === $this -> getAdapter()) {
return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
}
if(false === is_string($column)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($column)), E_USER_ERROR);
}
if(null !== $where && false === is_string($where)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($where)), E_USER_ERROR);
}
if(false === is_array($params)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
}
$query = [];
//Select
$query[] = sprintf('SELECT COUNT(%s) AS amount FROM %s', $this -> getAdapter() -> escape($column), $this -> getAdapter() -> escape($this -> getTable()));
//Where
if(null !== $where) {
$query[] = sprintf('WHERE %s', $this -> getAdapter() -> escape($where));
}
$statement = $this -> getAdapter() -> query(implode(' ', $query), $params) -> execute();
if(true === $statement) {
$amount = $this -> getAdapter() -> toArray();
if(true === isset($amount[0]['amount'])) {
return $amount[0]['amount'];
}
}
return false;
} | [
"public",
"function",
"rows",
"(",
"$",
"column",
"=",
"'*'",
",",
"$",
"where",
"=",
"null",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getAdapter",
"(",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'No database adapter was set in \"%s\"'",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"column",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"column",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"where",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"where",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"where",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 3 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"params",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"query",
"=",
"[",
"]",
";",
"//Select\r",
"$",
"query",
"[",
"]",
"=",
"sprintf",
"(",
"'SELECT COUNT(%s) AS amount FROM %s'",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"escape",
"(",
"$",
"column",
")",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"escape",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
")",
";",
"//Where\r",
"if",
"(",
"null",
"!==",
"$",
"where",
")",
"{",
"$",
"query",
"[",
"]",
"=",
"sprintf",
"(",
"'WHERE %s'",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"escape",
"(",
"$",
"where",
")",
")",
";",
"}",
"$",
"statement",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"query",
"(",
"implode",
"(",
"' '",
",",
"$",
"query",
")",
",",
"$",
"params",
")",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"true",
"===",
"$",
"statement",
")",
"{",
"$",
"amount",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"amount",
"[",
"0",
"]",
"[",
"'amount'",
"]",
")",
")",
"{",
"return",
"$",
"amount",
"[",
"0",
"]",
"[",
"'amount'",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Retrieve the number of rows
@param string $column
@param string $where
@param array $params
@return int|boolean | [
"Retrieve",
"the",
"number",
"of",
"rows"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/TableGateway.php#L82-L122 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/TableGateway.php | TableGateway.call | public function call($function, $params) {
if(null === $this -> getAdapter()) {
return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
}
if(null !== $function && false === is_string($function)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($function)), E_USER_ERROR);
}
if(false === is_array($params)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
}
$query = sprintf('CALL %s(%s)', $function, implode(array_fill(0, count($params), '?'), ','));
$output = $this -> getAdapter() -> query($query, $params) -> execute();
return $output;
} | php | public function call($function, $params) {
if(null === $this -> getAdapter()) {
return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
}
if(null !== $function && false === is_string($function)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($function)), E_USER_ERROR);
}
if(false === is_array($params)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
}
$query = sprintf('CALL %s(%s)', $function, implode(array_fill(0, count($params), '?'), ','));
$output = $this -> getAdapter() -> query($query, $params) -> execute();
return $output;
} | [
"public",
"function",
"call",
"(",
"$",
"function",
",",
"$",
"params",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getAdapter",
"(",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'No database adapter was set in \"%s\"'",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"function",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"function",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"function",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"params",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"query",
"=",
"sprintf",
"(",
"'CALL %s(%s)'",
",",
"$",
"function",
",",
"implode",
"(",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"params",
")",
",",
"'?'",
")",
",",
"','",
")",
")",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"query",
"(",
"$",
"query",
",",
"$",
"params",
")",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Call stored procedure
@param string $function
@param array $params
@return boolean | [
"Call",
"stored",
"procedure"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/TableGateway.php#L319-L337 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/TableGateway.php | TableGateway.select | public function select($query, $params = [], $type = null) {
$type = $type === null ? $this -> getEntityNamespace($this -> getTable()) : $type;
if(null === $this -> getAdapter()) {
return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
}
return new ResultSet($this -> getAdapter() -> query($query, $params) -> toArray(), $type, $this -> getAdapter());
} | php | public function select($query, $params = [], $type = null) {
$type = $type === null ? $this -> getEntityNamespace($this -> getTable()) : $type;
if(null === $this -> getAdapter()) {
return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
}
return new ResultSet($this -> getAdapter() -> query($query, $params) -> toArray(), $type, $this -> getAdapter());
} | [
"public",
"function",
"select",
"(",
"$",
"query",
",",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"type",
"=",
"$",
"type",
"===",
"null",
"?",
"$",
"this",
"->",
"getEntityNamespace",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
":",
"$",
"type",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getAdapter",
"(",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'No database adapter was set in \"%s\"'",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"new",
"ResultSet",
"(",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"query",
"(",
"$",
"query",
",",
"$",
"params",
")",
"->",
"toArray",
"(",
")",
",",
"$",
"type",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
")",
";",
"}"
] | Execute select statement and returns a ResultSet
@param string $query
@param array $params
@param boolean $toEntity
@return sFire\Adapter\MySQL\ResultSet | [
"Execute",
"select",
"statement",
"and",
"returns",
"a",
"ResultSet"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/TableGateway.php#L347-L356 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/TableGateway.php | TableGateway.getEntityNamespace | private function getEntityNamespace($table) {
if(false === is_string($table)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($table)), E_USER_ERROR);
}
$path = $this -> getNamespace($this, ['directory', 'dbtable'], ['directory', 'entity']) . Application :: get(['prefix', 'entity']) . NameConvert :: toCamelCase($table, true);
$path = str_replace(DIRECTORY_SEPARATOR, '\\', $path);
return $path;
} | php | private function getEntityNamespace($table) {
if(false === is_string($table)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($table)), E_USER_ERROR);
}
$path = $this -> getNamespace($this, ['directory', 'dbtable'], ['directory', 'entity']) . Application :: get(['prefix', 'entity']) . NameConvert :: toCamelCase($table, true);
$path = str_replace(DIRECTORY_SEPARATOR, '\\', $path);
return $path;
} | [
"private",
"function",
"getEntityNamespace",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"table",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"table",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"getNamespace",
"(",
"$",
"this",
",",
"[",
"'directory'",
",",
"'dbtable'",
"]",
",",
"[",
"'directory'",
",",
"'entity'",
"]",
")",
".",
"Application",
"::",
"get",
"(",
"[",
"'prefix'",
",",
"'entity'",
"]",
")",
".",
"NameConvert",
"::",
"toCamelCase",
"(",
"$",
"table",
",",
"true",
")",
";",
"$",
"path",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
",",
"$",
"path",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Loads entity table name
@param string $table
@return string | [
"Loads",
"entity",
"table",
"name"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/TableGateway.php#L399-L409 | train |
Kris-Kuiper/sFire-Framework | src/Form/Types/Selectrange.php | Selectrange.range | public function range($min, $max, $steps = 1, $round = 0) {
if(false === is_numeric($min)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type float or integer, "%s" given', __METHOD__, gettype($min)), E_USER_ERROR);
}
if(false === is_numeric($max)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type float or integer, "%s" given', __METHOD__, gettype($max)), E_USER_ERROR);
}
if(false === is_numeric($steps)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type float or integer, "%s" given', __METHOD__, gettype($steps)), E_USER_ERROR);
}
if(false === ('-' . intval($round) == '-' . $round)) {
return trigger_error(sprintf('Argument 4 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($round)), E_USER_ERROR);
}
$this -> min = $min;
$this -> max = $max;
$this -> steps = $steps;
$this -> round = $round;
return $this;
} | php | public function range($min, $max, $steps = 1, $round = 0) {
if(false === is_numeric($min)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type float or integer, "%s" given', __METHOD__, gettype($min)), E_USER_ERROR);
}
if(false === is_numeric($max)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type float or integer, "%s" given', __METHOD__, gettype($max)), E_USER_ERROR);
}
if(false === is_numeric($steps)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type float or integer, "%s" given', __METHOD__, gettype($steps)), E_USER_ERROR);
}
if(false === ('-' . intval($round) == '-' . $round)) {
return trigger_error(sprintf('Argument 4 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($round)), E_USER_ERROR);
}
$this -> min = $min;
$this -> max = $max;
$this -> steps = $steps;
$this -> round = $round;
return $this;
} | [
"public",
"function",
"range",
"(",
"$",
"min",
",",
"$",
"max",
",",
"$",
"steps",
"=",
"1",
",",
"$",
"round",
"=",
"0",
")",
"{",
"if",
"(",
"false",
"===",
"is_numeric",
"(",
"$",
"min",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type float or integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"min",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_numeric",
"(",
"$",
"max",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type float or integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"max",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_numeric",
"(",
"$",
"steps",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 3 passed to %s() must be of the type float or integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"steps",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"round",
")",
"==",
"'-'",
".",
"$",
"round",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 4 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"round",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"min",
"=",
"$",
"min",
";",
"$",
"this",
"->",
"max",
"=",
"$",
"max",
";",
"$",
"this",
"->",
"steps",
"=",
"$",
"steps",
";",
"$",
"this",
"->",
"round",
"=",
"$",
"round",
";",
"return",
"$",
"this",
";",
"}"
] | Set the min. and max. number to iterate. The min will increase by the steps and can be formatted with the round parameter
@param float $min
@param float $max
@param float $steps
@param int $round
@return sFire\Form\Types\Selectrange | [
"Set",
"the",
"min",
".",
"and",
"max",
".",
"number",
"to",
"iterate",
".",
"The",
"min",
"will",
"increase",
"by",
"the",
"steps",
"and",
"can",
"be",
"formatted",
"with",
"the",
"round",
"parameter"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Form/Types/Selectrange.php#L54-L78 | train |
sergeymakinen/tests | src/Util/ExtensionTrait.php | ExtensionTrait.getProperty | protected function getProperty($object, $name)
{
$class = new \ReflectionClass($object);
while (!$class->hasProperty($name)) {
$class = $class->getParentClass();
}
return $class->getProperty($name);
} | php | protected function getProperty($object, $name)
{
$class = new \ReflectionClass($object);
while (!$class->hasProperty($name)) {
$class = $class->getParentClass();
}
return $class->getProperty($name);
} | [
"protected",
"function",
"getProperty",
"(",
"$",
"object",
",",
"$",
"name",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"object",
")",
";",
"while",
"(",
"!",
"$",
"class",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"class",
"=",
"$",
"class",
"->",
"getParentClass",
"(",
")",
";",
"}",
"return",
"$",
"class",
"->",
"getProperty",
"(",
"$",
"name",
")",
";",
"}"
] | Returns the reflected property.
@param object|string $object
@param string $name
@return \ReflectionProperty | [
"Returns",
"the",
"reflected",
"property",
"."
] | 6ad901d0caaa76cd1d891e10c1218654c0178bed | https://github.com/sergeymakinen/tests/blob/6ad901d0caaa76cd1d891e10c1218654c0178bed/src/Util/ExtensionTrait.php#L21-L28 | train |
hiqsol-attic/composer-extension-plugin | src/Plugin.php | Plugin.onPostAutoloadDump | public function onPostAutoloadDump(Event $event)
{
$this->io->writeError('<info>Generating extensions files</info>');
foreach ($this->getPackages() as $package) {
if ($package instanceof \Composer\Package\CompletePackageInterface) {
$this->processPackage($package);
}
}
$this->processPackage($this->composer->getPackage());
foreach ($this->data as $name => $data) {
$this->saveFile($this->buildOutputPath($name), $data);
}
} | php | public function onPostAutoloadDump(Event $event)
{
$this->io->writeError('<info>Generating extensions files</info>');
foreach ($this->getPackages() as $package) {
if ($package instanceof \Composer\Package\CompletePackageInterface) {
$this->processPackage($package);
}
}
$this->processPackage($this->composer->getPackage());
foreach ($this->data as $name => $data) {
$this->saveFile($this->buildOutputPath($name), $data);
}
} | [
"public",
"function",
"onPostAutoloadDump",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"'<info>Generating extensions files</info>'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getPackages",
"(",
")",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"$",
"package",
"instanceof",
"\\",
"Composer",
"\\",
"Package",
"\\",
"CompletePackageInterface",
")",
"{",
"$",
"this",
"->",
"processPackage",
"(",
"$",
"package",
")",
";",
"}",
"}",
"$",
"this",
"->",
"processPackage",
"(",
"$",
"this",
"->",
"composer",
"->",
"getPackage",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"name",
"=>",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"saveFile",
"(",
"$",
"this",
"->",
"buildOutputPath",
"(",
"$",
"name",
")",
",",
"$",
"data",
")",
";",
"}",
"}"
] | Simply rewrites extensions file from scratch.
@param Event $event | [
"Simply",
"rewrites",
"extensions",
"file",
"from",
"scratch",
"."
] | 3e4a5384ca368f43debe277c606846e4299d2bf4 | https://github.com/hiqsol-attic/composer-extension-plugin/blob/3e4a5384ca368f43debe277c606846e4299d2bf4/src/Plugin.php#L103-L116 | train |
hiqsol-attic/composer-extension-plugin | src/Plugin.php | Plugin.processPackage | public function processPackage(PackageInterface $package)
{
$extra = $package->getExtra();
$files = isset($extra[self::EXTRA_OPTION_NAME]) ? $extra[self::EXTRA_OPTION_NAME] : null;
if ($package->getType() !== self::PACKAGE_TYPE && is_null($files)) {
return;
}
$extension = [
'name' => $package->getName(),
'version' => $package->getVersion(),
];
if ($package->getVersion() === '9999999-dev') {
$reference = $package->getSourceReference() ?: $package->getDistReference();
if ($reference) {
$extension['reference'] = $reference;
}
}
$this->data['extensions'][$package->getName()] = $extension;
$aliases = array_merge(
$this->prepareAliases($package, 'psr-0'),
$this->prepareAliases($package, 'psr-4')
);
$this->data['aliases'] = array_merge($this->data['aliases'], $aliases);
foreach ((array) $files as $name => $path) {
$config = $this->readExtensionConfig($package, $path);
$config['aliases'] = array_merge(
$aliases,
isset($config['aliases']) ? (array) $config['aliases'] : []
);
$this->data['aliases'] = array_merge($this->data['aliases'], $config['aliases']);
$this->data[$name] = isset($this->data[$name]) ? Helper::mergeConfig($this->data[$name], $config) : $config;
}
} | php | public function processPackage(PackageInterface $package)
{
$extra = $package->getExtra();
$files = isset($extra[self::EXTRA_OPTION_NAME]) ? $extra[self::EXTRA_OPTION_NAME] : null;
if ($package->getType() !== self::PACKAGE_TYPE && is_null($files)) {
return;
}
$extension = [
'name' => $package->getName(),
'version' => $package->getVersion(),
];
if ($package->getVersion() === '9999999-dev') {
$reference = $package->getSourceReference() ?: $package->getDistReference();
if ($reference) {
$extension['reference'] = $reference;
}
}
$this->data['extensions'][$package->getName()] = $extension;
$aliases = array_merge(
$this->prepareAliases($package, 'psr-0'),
$this->prepareAliases($package, 'psr-4')
);
$this->data['aliases'] = array_merge($this->data['aliases'], $aliases);
foreach ((array) $files as $name => $path) {
$config = $this->readExtensionConfig($package, $path);
$config['aliases'] = array_merge(
$aliases,
isset($config['aliases']) ? (array) $config['aliases'] : []
);
$this->data['aliases'] = array_merge($this->data['aliases'], $config['aliases']);
$this->data[$name] = isset($this->data[$name]) ? Helper::mergeConfig($this->data[$name], $config) : $config;
}
} | [
"public",
"function",
"processPackage",
"(",
"PackageInterface",
"$",
"package",
")",
"{",
"$",
"extra",
"=",
"$",
"package",
"->",
"getExtra",
"(",
")",
";",
"$",
"files",
"=",
"isset",
"(",
"$",
"extra",
"[",
"self",
"::",
"EXTRA_OPTION_NAME",
"]",
")",
"?",
"$",
"extra",
"[",
"self",
"::",
"EXTRA_OPTION_NAME",
"]",
":",
"null",
";",
"if",
"(",
"$",
"package",
"->",
"getType",
"(",
")",
"!==",
"self",
"::",
"PACKAGE_TYPE",
"&&",
"is_null",
"(",
"$",
"files",
")",
")",
"{",
"return",
";",
"}",
"$",
"extension",
"=",
"[",
"'name'",
"=>",
"$",
"package",
"->",
"getName",
"(",
")",
",",
"'version'",
"=>",
"$",
"package",
"->",
"getVersion",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"package",
"->",
"getVersion",
"(",
")",
"===",
"'9999999-dev'",
")",
"{",
"$",
"reference",
"=",
"$",
"package",
"->",
"getSourceReference",
"(",
")",
"?",
":",
"$",
"package",
"->",
"getDistReference",
"(",
")",
";",
"if",
"(",
"$",
"reference",
")",
"{",
"$",
"extension",
"[",
"'reference'",
"]",
"=",
"$",
"reference",
";",
"}",
"}",
"$",
"this",
"->",
"data",
"[",
"'extensions'",
"]",
"[",
"$",
"package",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"extension",
";",
"$",
"aliases",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"prepareAliases",
"(",
"$",
"package",
",",
"'psr-0'",
")",
",",
"$",
"this",
"->",
"prepareAliases",
"(",
"$",
"package",
",",
"'psr-4'",
")",
")",
";",
"$",
"this",
"->",
"data",
"[",
"'aliases'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"data",
"[",
"'aliases'",
"]",
",",
"$",
"aliases",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"files",
"as",
"$",
"name",
"=>",
"$",
"path",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"readExtensionConfig",
"(",
"$",
"package",
",",
"$",
"path",
")",
";",
"$",
"config",
"[",
"'aliases'",
"]",
"=",
"array_merge",
"(",
"$",
"aliases",
",",
"isset",
"(",
"$",
"config",
"[",
"'aliases'",
"]",
")",
"?",
"(",
"array",
")",
"$",
"config",
"[",
"'aliases'",
"]",
":",
"[",
"]",
")",
";",
"$",
"this",
"->",
"data",
"[",
"'aliases'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"data",
"[",
"'aliases'",
"]",
",",
"$",
"config",
"[",
"'aliases'",
"]",
")",
";",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
")",
"?",
"Helper",
"::",
"mergeConfig",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
",",
"$",
"config",
")",
":",
"$",
"config",
";",
"}",
"}"
] | Scans the given package and collects extensions data.
@param PackageInterface $package | [
"Scans",
"the",
"given",
"package",
"and",
"collects",
"extensions",
"data",
"."
] | 3e4a5384ca368f43debe277c606846e4299d2bf4 | https://github.com/hiqsol-attic/composer-extension-plugin/blob/3e4a5384ca368f43debe277c606846e4299d2bf4/src/Plugin.php#L142-L176 | train |
hiqsol-attic/composer-extension-plugin | src/Plugin.php | Plugin.readExtensionConfig | protected function readExtensionConfig(PackageInterface $package, $file)
{
$path = $this->preparePath($package, $file);
if (!file_exists($path)) {
$this->io->writeError('<error>Non existent extension config file</error> ' . $file . ' in ' . $package->getName());
exit(1);
}
return require $path;
} | php | protected function readExtensionConfig(PackageInterface $package, $file)
{
$path = $this->preparePath($package, $file);
if (!file_exists($path)) {
$this->io->writeError('<error>Non existent extension config file</error> ' . $file . ' in ' . $package->getName());
exit(1);
}
return require $path;
} | [
"protected",
"function",
"readExtensionConfig",
"(",
"PackageInterface",
"$",
"package",
",",
"$",
"file",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"preparePath",
"(",
"$",
"package",
",",
"$",
"file",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"'<error>Non existent extension config file</error> '",
".",
"$",
"file",
".",
"' in '",
".",
"$",
"package",
"->",
"getName",
"(",
")",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"return",
"require",
"$",
"path",
";",
"}"
] | Read extra config.
@param string $file
@return array | [
"Read",
"extra",
"config",
"."
] | 3e4a5384ca368f43debe277c606846e4299d2bf4 | https://github.com/hiqsol-attic/composer-extension-plugin/blob/3e4a5384ca368f43debe277c606846e4299d2bf4/src/Plugin.php#L183-L191 | train |
cmsgears/module-community | common/models/resources/GroupMessage.php | GroupMessage.getGroup | public function getGroup() {
$groupTable = CmnTables::getTableName( CmnTables::TABLE_GROUP );
return $this->hasOne( Group::class, [ 'id' => 'groupId' ] )->from( "$groupTable group" );
} | php | public function getGroup() {
$groupTable = CmnTables::getTableName( CmnTables::TABLE_GROUP );
return $this->hasOne( Group::class, [ 'id' => 'groupId' ] )->from( "$groupTable group" );
} | [
"public",
"function",
"getGroup",
"(",
")",
"{",
"$",
"groupTable",
"=",
"CmnTables",
"::",
"getTableName",
"(",
"CmnTables",
"::",
"TABLE_GROUP",
")",
";",
"return",
"$",
"this",
"->",
"hasOne",
"(",
"Group",
"::",
"class",
",",
"[",
"'id'",
"=>",
"'groupId'",
"]",
")",
"->",
"from",
"(",
"\"$groupTable group\"",
")",
";",
"}"
] | Returns the corresponding group.
@return \cmsgears\community\common\models\entities\Group | [
"Returns",
"the",
"corresponding",
"group",
"."
] | 0ca9cf0aa0cee395a4788bd6085f291e10728555 | https://github.com/cmsgears/module-community/blob/0ca9cf0aa0cee395a4788bd6085f291e10728555/common/models/resources/GroupMessage.php#L194-L199 | train |
jenskooij/cloudcontrol | src/storage/storage/ValuelistsStorage.php | ValuelistsStorage.saveValuelist | public function saveValuelist($slug, $postValues)
{
$valuelistObject = ValuelistFactory::createValuelistFromPostValues($postValues);
$valuelists = $this->repository->valuelists;
foreach ($valuelists as $key => $valuelist) {
if ($valuelist->slug == $slug) {
$valuelists[$key] = $valuelistObject;
}
}
$this->repository->valuelists = $valuelists;
$this->save();
} | php | public function saveValuelist($slug, $postValues)
{
$valuelistObject = ValuelistFactory::createValuelistFromPostValues($postValues);
$valuelists = $this->repository->valuelists;
foreach ($valuelists as $key => $valuelist) {
if ($valuelist->slug == $slug) {
$valuelists[$key] = $valuelistObject;
}
}
$this->repository->valuelists = $valuelists;
$this->save();
} | [
"public",
"function",
"saveValuelist",
"(",
"$",
"slug",
",",
"$",
"postValues",
")",
"{",
"$",
"valuelistObject",
"=",
"ValuelistFactory",
"::",
"createValuelistFromPostValues",
"(",
"$",
"postValues",
")",
";",
"$",
"valuelists",
"=",
"$",
"this",
"->",
"repository",
"->",
"valuelists",
";",
"foreach",
"(",
"$",
"valuelists",
"as",
"$",
"key",
"=>",
"$",
"valuelist",
")",
"{",
"if",
"(",
"$",
"valuelist",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"$",
"valuelists",
"[",
"$",
"key",
"]",
"=",
"$",
"valuelistObject",
";",
"}",
"}",
"$",
"this",
"->",
"repository",
"->",
"valuelists",
"=",
"$",
"valuelists",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Save changes to a valuelist
@param $slug
@param $postValues
@throws \Exception | [
"Save",
"changes",
"to",
"a",
"valuelist"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/ValuelistsStorage.php#L47-L59 | train |
jenskooij/cloudcontrol | src/storage/storage/ValuelistsStorage.php | ValuelistsStorage.getValuelistBySlug | public function getValuelistBySlug($slug)
{
$valuelists = $this->repository->valuelists;
foreach ($valuelists as $valuelist) {
if ($valuelist->slug == $slug) {
return $valuelist;
}
}
return null;
} | php | public function getValuelistBySlug($slug)
{
$valuelists = $this->repository->valuelists;
foreach ($valuelists as $valuelist) {
if ($valuelist->slug == $slug) {
return $valuelist;
}
}
return null;
} | [
"public",
"function",
"getValuelistBySlug",
"(",
"$",
"slug",
")",
"{",
"$",
"valuelists",
"=",
"$",
"this",
"->",
"repository",
"->",
"valuelists",
";",
"foreach",
"(",
"$",
"valuelists",
"as",
"$",
"valuelist",
")",
"{",
"if",
"(",
"$",
"valuelist",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"return",
"$",
"valuelist",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get a valuelist by its slug
@param $slug
@return \stdClass | [
"Get",
"a",
"valuelist",
"by",
"its",
"slug"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/ValuelistsStorage.php#L68-L78 | train |
devlabmtl/haven-security | Controller/LoginController.php | LoginController.resetConfirmationAction | public function resetConfirmationAction($uuid) {
$em = $this->container->get("doctrine")->getEntityManager();
$request = $this->container->get("request");
$confirm_data = $request->get("haven_bundle_securitybundle_confirmtype");
$user_reset = $em->getRepository("HavenSecurityBundle:UserReset")->findOneBy(array("uuid" => $uuid));
if (null == $user_reset) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException("page.pas.trouve");
}
$confirm_form = $this->container->get("form.factory")->create(new \Haven\SecurityBundle\Form\ConfirmType());
$templating = $this->container->get("templating");
$render = null;
if ($request->getMethod() == "POST") {
$confirm_form->bind($confirm_data);
if ($confirm_form->isValid()) {
if ($user_reset->getConfirmation() == $confirm_data["confirmation"] && !null == $user_reset->getUser()) {
$factory = $this->container->get('security.encoder_factory');
$user = $user_reset->getUser();
$encoder = $factory->getEncoder($user);
$user->setPassword($encoder->encodePassword($confirm_data["plainPassword"]["first"], $user->getSalt()));
} else {
$this->get('session')->getFlashBag()->add("error", "confirmation.invalid");
return array("confirm_form" => $confirm_form->createView(), "uuid" => $uuid);
// throw new \Exception("L'utilisateur n'existe pas ou n'a pas fait de demande de réinitialisation");
}
$em->persist($user);
$em->remove($user_reset);
$em->flush();
// $this->get('session')->getFlashBag()->add("success", "activation.reussi");
return new \Symfony\Component\HttpFoundation\RedirectResponse($this->container->get("router")->generate("haven_security_login_login", array("_locale", $request->get("_locale"))));
}
}
return array("confirm_form" => $confirm_form->createView(), "uuid" => $uuid);
} | php | public function resetConfirmationAction($uuid) {
$em = $this->container->get("doctrine")->getEntityManager();
$request = $this->container->get("request");
$confirm_data = $request->get("haven_bundle_securitybundle_confirmtype");
$user_reset = $em->getRepository("HavenSecurityBundle:UserReset")->findOneBy(array("uuid" => $uuid));
if (null == $user_reset) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException("page.pas.trouve");
}
$confirm_form = $this->container->get("form.factory")->create(new \Haven\SecurityBundle\Form\ConfirmType());
$templating = $this->container->get("templating");
$render = null;
if ($request->getMethod() == "POST") {
$confirm_form->bind($confirm_data);
if ($confirm_form->isValid()) {
if ($user_reset->getConfirmation() == $confirm_data["confirmation"] && !null == $user_reset->getUser()) {
$factory = $this->container->get('security.encoder_factory');
$user = $user_reset->getUser();
$encoder = $factory->getEncoder($user);
$user->setPassword($encoder->encodePassword($confirm_data["plainPassword"]["first"], $user->getSalt()));
} else {
$this->get('session')->getFlashBag()->add("error", "confirmation.invalid");
return array("confirm_form" => $confirm_form->createView(), "uuid" => $uuid);
// throw new \Exception("L'utilisateur n'existe pas ou n'a pas fait de demande de réinitialisation");
}
$em->persist($user);
$em->remove($user_reset);
$em->flush();
// $this->get('session')->getFlashBag()->add("success", "activation.reussi");
return new \Symfony\Component\HttpFoundation\RedirectResponse($this->container->get("router")->generate("haven_security_login_login", array("_locale", $request->get("_locale"))));
}
}
return array("confirm_form" => $confirm_form->createView(), "uuid" => $uuid);
} | [
"public",
"function",
"resetConfirmationAction",
"(",
"$",
"uuid",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"\"doctrine\"",
")",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"\"request\"",
")",
";",
"$",
"confirm_data",
"=",
"$",
"request",
"->",
"get",
"(",
"\"haven_bundle_securitybundle_confirmtype\"",
")",
";",
"$",
"user_reset",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"\"HavenSecurityBundle:UserReset\"",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"\"uuid\"",
"=>",
"$",
"uuid",
")",
")",
";",
"if",
"(",
"null",
"==",
"$",
"user_reset",
")",
"{",
"throw",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"HttpKernel",
"\\",
"Exception",
"\\",
"NotFoundHttpException",
"(",
"\"page.pas.trouve\"",
")",
";",
"}",
"$",
"confirm_form",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"\"form.factory\"",
")",
"->",
"create",
"(",
"new",
"\\",
"Haven",
"\\",
"SecurityBundle",
"\\",
"Form",
"\\",
"ConfirmType",
"(",
")",
")",
";",
"$",
"templating",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"\"templating\"",
")",
";",
"$",
"render",
"=",
"null",
";",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"\"POST\"",
")",
"{",
"$",
"confirm_form",
"->",
"bind",
"(",
"$",
"confirm_data",
")",
";",
"if",
"(",
"$",
"confirm_form",
"->",
"isValid",
"(",
")",
")",
"{",
"if",
"(",
"$",
"user_reset",
"->",
"getConfirmation",
"(",
")",
"==",
"$",
"confirm_data",
"[",
"\"confirmation\"",
"]",
"&&",
"!",
"null",
"==",
"$",
"user_reset",
"->",
"getUser",
"(",
")",
")",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'security.encoder_factory'",
")",
";",
"$",
"user",
"=",
"$",
"user_reset",
"->",
"getUser",
"(",
")",
";",
"$",
"encoder",
"=",
"$",
"factory",
"->",
"getEncoder",
"(",
"$",
"user",
")",
";",
"$",
"user",
"->",
"setPassword",
"(",
"$",
"encoder",
"->",
"encodePassword",
"(",
"$",
"confirm_data",
"[",
"\"plainPassword\"",
"]",
"[",
"\"first\"",
"]",
",",
"$",
"user",
"->",
"getSalt",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"\"error\"",
",",
"\"confirmation.invalid\"",
")",
";",
"return",
"array",
"(",
"\"confirm_form\"",
"=>",
"$",
"confirm_form",
"->",
"createView",
"(",
")",
",",
"\"uuid\"",
"=>",
"$",
"uuid",
")",
";",
"// throw new \\Exception(\"L'utilisateur n'existe pas ou n'a pas fait de demande de réinitialisation\");",
"}",
"$",
"em",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"user_reset",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"// $this->get('session')->getFlashBag()->add(\"success\", \"activation.reussi\");",
"return",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"HttpFoundation",
"\\",
"RedirectResponse",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"\"router\"",
")",
"->",
"generate",
"(",
"\"haven_security_login_login\"",
",",
"array",
"(",
"\"_locale\"",
",",
"$",
"request",
"->",
"get",
"(",
"\"_locale\"",
")",
")",
")",
")",
";",
"}",
"}",
"return",
"array",
"(",
"\"confirm_form\"",
"=>",
"$",
"confirm_form",
"->",
"createView",
"(",
")",
",",
"\"uuid\"",
"=>",
"$",
"uuid",
")",
";",
"}"
] | reset confirmation by the user
@Route("/{_locale}/auth/confirmation/{uuid}")
@Template() | [
"reset",
"confirmation",
"by",
"the",
"user"
] | 8e53d57e3d5680e97ad8c0b9f37d34e8e478ce10 | https://github.com/devlabmtl/haven-security/blob/8e53d57e3d5680e97ad8c0b9f37d34e8e478ce10/Controller/LoginController.php#L212-L246 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.get | public function get($key, $default = null) {
$this->check();
$value = $this->readValue($key);
return is_null($value) ? $default : $value;
} | php | public function get($key, $default = null) {
$this->check();
$value = $this->readValue($key);
return is_null($value) ? $default : $value;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"check",
"(",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"readValue",
"(",
"$",
"key",
")",
";",
"return",
"is_null",
"(",
"$",
"value",
")",
"?",
"$",
"default",
":",
"$",
"value",
";",
"}"
] | Get value from storage
@param string $key
@return mixed | [
"Get",
"value",
"from",
"storage"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L89-L93 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.has | public function has($key) {
$this->check();
$data = $this->readData();
return isset($data[$key]);
} | php | public function has($key) {
$this->check();
$data = $this->readData();
return isset($data[$key]);
} | [
"public",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"check",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"readData",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}"
] | Check if storage has given key
@return bool | [
"Check",
"if",
"storage",
"has",
"given",
"key"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L118-L122 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.destroy | public function destroy() {
if (false === shmop_delete($this->shm)) {
throw new RuntimeException(sprintf('Unable to destroy shared memory segment id: %s', $this->shm));
}
$this->destroyed = true;
} | php | public function destroy() {
if (false === shmop_delete($this->shm)) {
throw new RuntimeException(sprintf('Unable to destroy shared memory segment id: %s', $this->shm));
}
$this->destroyed = true;
} | [
"public",
"function",
"destroy",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"shmop_delete",
"(",
"$",
"this",
"->",
"shm",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to destroy shared memory segment id: %s'",
",",
"$",
"this",
"->",
"shm",
")",
")",
";",
"}",
"$",
"this",
"->",
"destroyed",
"=",
"true",
";",
"}"
] | Destroy shared memory segment
@throws RuntimeException | [
"Destroy",
"shared",
"memory",
"segment"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L136-L142 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.setupSegment | protected function setupSegment() {
// Attempt to open shm segment
$this->shm = @shmop_open($this->getIdentifier(), self::SHM_OPEN_MODE, 0, 0);
// If segment doesn't exist init new segment
if (false === $this->shm) {
$this->createSegment();
}
} | php | protected function setupSegment() {
// Attempt to open shm segment
$this->shm = @shmop_open($this->getIdentifier(), self::SHM_OPEN_MODE, 0, 0);
// If segment doesn't exist init new segment
if (false === $this->shm) {
$this->createSegment();
}
} | [
"protected",
"function",
"setupSegment",
"(",
")",
"{",
"// Attempt to open shm segment",
"$",
"this",
"->",
"shm",
"=",
"@",
"shmop_open",
"(",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
",",
"self",
"::",
"SHM_OPEN_MODE",
",",
"0",
",",
"0",
")",
";",
"// If segment doesn't exist init new segment",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"shm",
")",
"{",
"$",
"this",
"->",
"createSegment",
"(",
")",
";",
"}",
"}"
] | Create or open shared memory segment using current key | [
"Create",
"or",
"open",
"shared",
"memory",
"segment",
"using",
"current",
"key"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L157-L165 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.createSegment | protected function createSegment() {
$this->shm = shmop_open(
$this->getIdentifier(),
self::SHM_CREATE_MODE,
self::SHM_CREATE_PERMISSIONS,
$this->size
);
if (false === $this->shm) {
throw new RuntimeException(sprintf('Unable to create shared memory segment with key: %s', $this->getIdentifier()));
}
$this->updateSize(0);
} | php | protected function createSegment() {
$this->shm = shmop_open(
$this->getIdentifier(),
self::SHM_CREATE_MODE,
self::SHM_CREATE_PERMISSIONS,
$this->size
);
if (false === $this->shm) {
throw new RuntimeException(sprintf('Unable to create shared memory segment with key: %s', $this->getIdentifier()));
}
$this->updateSize(0);
} | [
"protected",
"function",
"createSegment",
"(",
")",
"{",
"$",
"this",
"->",
"shm",
"=",
"shmop_open",
"(",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
",",
"self",
"::",
"SHM_CREATE_MODE",
",",
"self",
"::",
"SHM_CREATE_PERMISSIONS",
",",
"$",
"this",
"->",
"size",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"shm",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to create shared memory segment with key: %s'",
",",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"updateSize",
"(",
"0",
")",
";",
"}"
] | Create new shm segment and write base meta data | [
"Create",
"new",
"shm",
"segment",
"and",
"write",
"base",
"meta",
"data"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L170-L183 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.updateSize | protected function updateSize($size) {
$size = sprintf('%' . self::SHM_DATA_OFFSET . 'd', intval($size));
return !!$this->write(0, $size);
} | php | protected function updateSize($size) {
$size = sprintf('%' . self::SHM_DATA_OFFSET . 'd', intval($size));
return !!$this->write(0, $size);
} | [
"protected",
"function",
"updateSize",
"(",
"$",
"size",
")",
"{",
"$",
"size",
"=",
"sprintf",
"(",
"'%'",
".",
"self",
"::",
"SHM_DATA_OFFSET",
".",
"'d'",
",",
"intval",
"(",
"$",
"size",
")",
")",
";",
"return",
"!",
"!",
"$",
"this",
"->",
"write",
"(",
"0",
",",
"$",
"size",
")",
";",
"}"
] | Update size field
@param int size | [
"Update",
"size",
"field"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L189-L192 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.writeValue | protected function writeValue($key, $value) {
$data = $this->readData();
$data[$key] = $this->encode($value);
if ($this->writeData($data)) {
return $value;
}
return false;
} | php | protected function writeValue($key, $value) {
$data = $this->readData();
$data[$key] = $this->encode($value);
if ($this->writeData($data)) {
return $value;
}
return false;
} | [
"protected",
"function",
"writeValue",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"readData",
"(",
")",
";",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"encode",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"writeData",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"false",
";",
"}"
] | Write value to shm segment
@param string $key
@param string $value | [
"Write",
"value",
"to",
"shm",
"segment"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L207-L216 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.unsetValue | protected function unsetValue($key) {
$data = $this->readData();
unset($data[$key]);
return $this->writeData($data);
} | php | protected function unsetValue($key) {
$data = $this->readData();
unset($data[$key]);
return $this->writeData($data);
} | [
"protected",
"function",
"unsetValue",
"(",
"$",
"key",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"readData",
"(",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"return",
"$",
"this",
"->",
"writeData",
"(",
"$",
"data",
")",
";",
"}"
] | Removes item from storage
@param string $key | [
"Removes",
"item",
"from",
"storage"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L222-L226 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.readValue | protected function readValue($key) {
$data = $this->readData();
return isset($data[$key]) ? $this->decode($data[$key]) : null;
} | php | protected function readValue($key) {
$data = $this->readData();
return isset($data[$key]) ? $this->decode($data[$key]) : null;
} | [
"protected",
"function",
"readValue",
"(",
"$",
"key",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"readData",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"decode",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
":",
"null",
";",
"}"
] | Read value from shm segment
@param string key
@return string | null if field doesn't exist | [
"Read",
"value",
"from",
"shm",
"segment"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L233-L236 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.writeData | protected function writeData(array $data) {
$size = $this->write(self::SHM_DATA_OFFSET, json_encode($data));
return $this->updateSize($size);
} | php | protected function writeData(array $data) {
$size = $this->write(self::SHM_DATA_OFFSET, json_encode($data));
return $this->updateSize($size);
} | [
"protected",
"function",
"writeData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"size",
"=",
"$",
"this",
"->",
"write",
"(",
"self",
"::",
"SHM_DATA_OFFSET",
",",
"json_encode",
"(",
"$",
"data",
")",
")",
";",
"return",
"$",
"this",
"->",
"updateSize",
"(",
"$",
"size",
")",
";",
"}"
] | Write data to shm segment
@param array $data | [
"Write",
"data",
"to",
"shm",
"segment"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L242-L245 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.readData | protected function readData() {
$used = $this->readSize();
return 0 === $used ? array() : json_decode($this->read(self::SHM_DATA_OFFSET, $used), true);
} | php | protected function readData() {
$used = $this->readSize();
return 0 === $used ? array() : json_decode($this->read(self::SHM_DATA_OFFSET, $used), true);
} | [
"protected",
"function",
"readData",
"(",
")",
"{",
"$",
"used",
"=",
"$",
"this",
"->",
"readSize",
"(",
")",
";",
"return",
"0",
"===",
"$",
"used",
"?",
"array",
"(",
")",
":",
"json_decode",
"(",
"$",
"this",
"->",
"read",
"(",
"self",
"::",
"SHM_DATA_OFFSET",
",",
"$",
"used",
")",
",",
"true",
")",
";",
"}"
] | Read data from shm segment
@param string $key
@return string | [
"Read",
"data",
"from",
"shm",
"segment"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L252-L255 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.encode | protected function encode($val) {
switch (true) {
case is_array($val):
return self::T_ARRAY . json_encode($val);
case is_int($val):
return self::T_INT . $val;
case is_bool($val):
return self::T_BOOLEAN . $val;
case is_float($val):
return self::T_DOUBLE . $val;
case is_object($val):
return self::T_OBJECT . serialize($val);
default:
return self::T_STRING . $val;
}
} | php | protected function encode($val) {
switch (true) {
case is_array($val):
return self::T_ARRAY . json_encode($val);
case is_int($val):
return self::T_INT . $val;
case is_bool($val):
return self::T_BOOLEAN . $val;
case is_float($val):
return self::T_DOUBLE . $val;
case is_object($val):
return self::T_OBJECT . serialize($val);
default:
return self::T_STRING . $val;
}
} | [
"protected",
"function",
"encode",
"(",
"$",
"val",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"is_array",
"(",
"$",
"val",
")",
":",
"return",
"self",
"::",
"T_ARRAY",
".",
"json_encode",
"(",
"$",
"val",
")",
";",
"case",
"is_int",
"(",
"$",
"val",
")",
":",
"return",
"self",
"::",
"T_INT",
".",
"$",
"val",
";",
"case",
"is_bool",
"(",
"$",
"val",
")",
":",
"return",
"self",
"::",
"T_BOOLEAN",
".",
"$",
"val",
";",
"case",
"is_float",
"(",
"$",
"val",
")",
":",
"return",
"self",
"::",
"T_DOUBLE",
".",
"$",
"val",
";",
"case",
"is_object",
"(",
"$",
"val",
")",
":",
"return",
"self",
"::",
"T_OBJECT",
".",
"serialize",
"(",
"$",
"val",
")",
";",
"default",
":",
"return",
"self",
"::",
"T_STRING",
".",
"$",
"val",
";",
"}",
"}"
] | Serialize value with type prefix
@param mixed $value
@return string encoded value | [
"Serialize",
"value",
"with",
"type",
"prefix"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L282-L297 | train |
boo1ean/shared | src/Shared/Storage.php | Storage.decode | protected function decode($encoded) {
$val = substr($encoded, 1);
switch ($encoded[0]) {
case self::T_ARRAY:
return json_decode($val, true);
case self::T_INT:
return intval($val);
case self::T_BOOLEAN:
return !!$val;
case self::T_DOUBLE:
return floatval($val);
case self::T_OBJECT:
return unserialize($val);
default:
return $val;
}
} | php | protected function decode($encoded) {
$val = substr($encoded, 1);
switch ($encoded[0]) {
case self::T_ARRAY:
return json_decode($val, true);
case self::T_INT:
return intval($val);
case self::T_BOOLEAN:
return !!$val;
case self::T_DOUBLE:
return floatval($val);
case self::T_OBJECT:
return unserialize($val);
default:
return $val;
}
} | [
"protected",
"function",
"decode",
"(",
"$",
"encoded",
")",
"{",
"$",
"val",
"=",
"substr",
"(",
"$",
"encoded",
",",
"1",
")",
";",
"switch",
"(",
"$",
"encoded",
"[",
"0",
"]",
")",
"{",
"case",
"self",
"::",
"T_ARRAY",
":",
"return",
"json_decode",
"(",
"$",
"val",
",",
"true",
")",
";",
"case",
"self",
"::",
"T_INT",
":",
"return",
"intval",
"(",
"$",
"val",
")",
";",
"case",
"self",
"::",
"T_BOOLEAN",
":",
"return",
"!",
"!",
"$",
"val",
";",
"case",
"self",
"::",
"T_DOUBLE",
":",
"return",
"floatval",
"(",
"$",
"val",
")",
";",
"case",
"self",
"::",
"T_OBJECT",
":",
"return",
"unserialize",
"(",
"$",
"val",
")",
";",
"default",
":",
"return",
"$",
"val",
";",
"}",
"}"
] | Unserialize value from storage
@param string $encoded
@return mixed | [
"Unserialize",
"value",
"from",
"storage"
] | 92c6309a9af21e280179b4de161dbe74bc764f22 | https://github.com/boo1ean/shared/blob/92c6309a9af21e280179b4de161dbe74bc764f22/src/Shared/Storage.php#L304-L320 | train |
lasallecms/lasallecms-l5-shortmessageservice-pkg | src/Twilio/UseTwilio.php | UseTwilio.getTwilioConfig | public function getTwilioConfig($connection='twilio')
{
$twilioconfig = config('twilio.twilio');
$configSettings = [];
$configSettings['sid'] = $twilioconfig['connections'][$connection]['sid'];
$configSettings['token'] = $twilioconfig['connections'][$connection]['token'];
$configSettings['fromNumber'] = $twilioconfig['connections'][$connection]['from'];
return $configSettings;
} | php | public function getTwilioConfig($connection='twilio')
{
$twilioconfig = config('twilio.twilio');
$configSettings = [];
$configSettings['sid'] = $twilioconfig['connections'][$connection]['sid'];
$configSettings['token'] = $twilioconfig['connections'][$connection]['token'];
$configSettings['fromNumber'] = $twilioconfig['connections'][$connection]['from'];
return $configSettings;
} | [
"public",
"function",
"getTwilioConfig",
"(",
"$",
"connection",
"=",
"'twilio'",
")",
"{",
"$",
"twilioconfig",
"=",
"config",
"(",
"'twilio.twilio'",
")",
";",
"$",
"configSettings",
"=",
"[",
"]",
";",
"$",
"configSettings",
"[",
"'sid'",
"]",
"=",
"$",
"twilioconfig",
"[",
"'connections'",
"]",
"[",
"$",
"connection",
"]",
"[",
"'sid'",
"]",
";",
"$",
"configSettings",
"[",
"'token'",
"]",
"=",
"$",
"twilioconfig",
"[",
"'connections'",
"]",
"[",
"$",
"connection",
"]",
"[",
"'token'",
"]",
";",
"$",
"configSettings",
"[",
"'fromNumber'",
"]",
"=",
"$",
"twilioconfig",
"[",
"'connections'",
"]",
"[",
"$",
"connection",
"]",
"[",
"'from'",
"]",
";",
"return",
"$",
"configSettings",
";",
"}"
] | Get the Twilio config settings from the laravel-twilio package
@param string $conection The connection to fetch. Can have multiple Twilio connections in the config.
@return array | [
"Get",
"the",
"Twilio",
"config",
"settings",
"from",
"the",
"laravel",
"-",
"twilio",
"package"
] | 0562046af8f60a80947bada451fde2f0859b3812 | https://github.com/lasallecms/lasallecms-l5-shortmessageservice-pkg/blob/0562046af8f60a80947bada451fde2f0859b3812/src/Twilio/UseTwilio.php#L100-L110 | train |
kaiohken1982/Watermarker | src/Watermarker/Watermarker/Watermarker.php | Watermarker.watermarkDimensionCoords | public function watermarkDimensionCoords()
{
$watermarkInfo = $this->getWatermarkInfo();
$imageInfo = $this->getImageInfo();
switch ($this->getType()) :
case self::WATERMARK_TYPE_FULLWIDTH:
default:
$resizedWatermarkWidth = number_format($imageInfo['width'], 0, ',', '');
$resizedWatermarkHeight =
number_format($resizedWatermarkWidth * $watermarkInfo['height'] /
$watermarkInfo['width'], 0, ',', '');
$destX = 0;
$destY = number_format(($imageInfo['height']/2 - $resizedWatermarkHeight/2 ), 0, ',', '');
break;
endswitch;
return array($resizedWatermarkWidth, $resizedWatermarkHeight, $destX, $destY);
} | php | public function watermarkDimensionCoords()
{
$watermarkInfo = $this->getWatermarkInfo();
$imageInfo = $this->getImageInfo();
switch ($this->getType()) :
case self::WATERMARK_TYPE_FULLWIDTH:
default:
$resizedWatermarkWidth = number_format($imageInfo['width'], 0, ',', '');
$resizedWatermarkHeight =
number_format($resizedWatermarkWidth * $watermarkInfo['height'] /
$watermarkInfo['width'], 0, ',', '');
$destX = 0;
$destY = number_format(($imageInfo['height']/2 - $resizedWatermarkHeight/2 ), 0, ',', '');
break;
endswitch;
return array($resizedWatermarkWidth, $resizedWatermarkHeight, $destX, $destY);
} | [
"public",
"function",
"watermarkDimensionCoords",
"(",
")",
"{",
"$",
"watermarkInfo",
"=",
"$",
"this",
"->",
"getWatermarkInfo",
"(",
")",
";",
"$",
"imageInfo",
"=",
"$",
"this",
"->",
"getImageInfo",
"(",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
")",
":",
"case",
"self",
"::",
"WATERMARK_TYPE_FULLWIDTH",
":",
"default",
":",
"$",
"resizedWatermarkWidth",
"=",
"number_format",
"(",
"$",
"imageInfo",
"[",
"'width'",
"]",
",",
"0",
",",
"','",
",",
"''",
")",
";",
"$",
"resizedWatermarkHeight",
"=",
"number_format",
"(",
"$",
"resizedWatermarkWidth",
"*",
"$",
"watermarkInfo",
"[",
"'height'",
"]",
"/",
"$",
"watermarkInfo",
"[",
"'width'",
"]",
",",
"0",
",",
"','",
",",
"''",
")",
";",
"$",
"destX",
"=",
"0",
";",
"$",
"destY",
"=",
"number_format",
"(",
"(",
"$",
"imageInfo",
"[",
"'height'",
"]",
"/",
"2",
"-",
"$",
"resizedWatermarkHeight",
"/",
"2",
")",
",",
"0",
",",
"','",
",",
"''",
")",
";",
"break",
";",
"endswitch",
";",
"return",
"array",
"(",
"$",
"resizedWatermarkWidth",
",",
"$",
"resizedWatermarkHeight",
",",
"$",
"destX",
",",
"$",
"destY",
")",
";",
"}"
] | Get watermark type dimension from a type
@param array
@param array
@param int
@return array | [
"Get",
"watermark",
"type",
"dimension",
"from",
"a",
"type"
] | 95b14bbcd0d7b070070b3c1730360445bc52788c | https://github.com/kaiohken1982/Watermarker/blob/95b14bbcd0d7b070070b3c1730360445bc52788c/src/Watermarker/Watermarker/Watermarker.php#L297-L315 | train |
kaiohken1982/Watermarker | src/Watermarker/Watermarker/Watermarker.php | Watermarker.setWatermarkTmpDir | public function setWatermarkTmpDir($watermarkTmpDir)
{
$watermarkTmpDirCopy = $watermarkTmpDir;
$watermarkTmpDir = realpath($watermarkTmpDir);
// If the provided tmpDir is empty throw exception
if (empty($watermarkTmpDir)) {
throw new \RuntimeException("Watermark directory is empty. This can be due to the provided directory '" . $watermarkTmpDirCopy . "' not exists, please check.");
}
// Adding the trailing slash
$watermarkTmpDir = substr($watermarkTmpDir, -1) == DIRECTORY_SEPARATOR ?
$watermarkTmpDir : $watermarkTmpDir . DIRECTORY_SEPARATOR;
$this->watermarkTmpDir = $watermarkTmpDir;
return $this;
} | php | public function setWatermarkTmpDir($watermarkTmpDir)
{
$watermarkTmpDirCopy = $watermarkTmpDir;
$watermarkTmpDir = realpath($watermarkTmpDir);
// If the provided tmpDir is empty throw exception
if (empty($watermarkTmpDir)) {
throw new \RuntimeException("Watermark directory is empty. This can be due to the provided directory '" . $watermarkTmpDirCopy . "' not exists, please check.");
}
// Adding the trailing slash
$watermarkTmpDir = substr($watermarkTmpDir, -1) == DIRECTORY_SEPARATOR ?
$watermarkTmpDir : $watermarkTmpDir . DIRECTORY_SEPARATOR;
$this->watermarkTmpDir = $watermarkTmpDir;
return $this;
} | [
"public",
"function",
"setWatermarkTmpDir",
"(",
"$",
"watermarkTmpDir",
")",
"{",
"$",
"watermarkTmpDirCopy",
"=",
"$",
"watermarkTmpDir",
";",
"$",
"watermarkTmpDir",
"=",
"realpath",
"(",
"$",
"watermarkTmpDir",
")",
";",
"// If the provided tmpDir is empty throw exception",
"if",
"(",
"empty",
"(",
"$",
"watermarkTmpDir",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Watermark directory is empty. This can be due to the provided directory '\"",
".",
"$",
"watermarkTmpDirCopy",
".",
"\"' not exists, please check.\"",
")",
";",
"}",
"// Adding the trailing slash",
"$",
"watermarkTmpDir",
"=",
"substr",
"(",
"$",
"watermarkTmpDir",
",",
"-",
"1",
")",
"==",
"DIRECTORY_SEPARATOR",
"?",
"$",
"watermarkTmpDir",
":",
"$",
"watermarkTmpDir",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"this",
"->",
"watermarkTmpDir",
"=",
"$",
"watermarkTmpDir",
";",
"return",
"$",
"this",
";",
"}"
] | Set the watermark directory
@param string
@throws \RuntimeException
@return \Watermarker\Watermarker\Watermarker | [
"Set",
"the",
"watermark",
"directory"
] | 95b14bbcd0d7b070070b3c1730360445bc52788c | https://github.com/kaiohken1982/Watermarker/blob/95b14bbcd0d7b070070b3c1730360445bc52788c/src/Watermarker/Watermarker/Watermarker.php#L324-L341 | train |
linguisticteam/json-ld | src/Generators/schema_org.php | Thing.check_type | private function check_type(){
$this_class = new \ReflectionClass( $this );
$type = $this_class->getShortName();
if ($type == 'Thing') {
$type = $this->get_type();
unset($this->type);
}
if(!is_null($this->realType)){
$type = $this->realType;
unset($this->realType);
}
return $type;
} | php | private function check_type(){
$this_class = new \ReflectionClass( $this );
$type = $this_class->getShortName();
if ($type == 'Thing') {
$type = $this->get_type();
unset($this->type);
}
if(!is_null($this->realType)){
$type = $this->realType;
unset($this->realType);
}
return $type;
} | [
"private",
"function",
"check_type",
"(",
")",
"{",
"$",
"this_class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"$",
"type",
"=",
"$",
"this_class",
"->",
"getShortName",
"(",
")",
";",
"if",
"(",
"$",
"type",
"==",
"'Thing'",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"get_type",
"(",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"type",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"realType",
")",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"realType",
";",
"unset",
"(",
"$",
"this",
"->",
"realType",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | In most cases, the name of the object withing json-ld markup will be the class name.
Sometimes though we create a custom object on the fly with an array of properties, but we can't have
the object appear as a "Thing" so we have to set the type manually.
When classes are extended by implementing code, the namespace might be entirely different so we need
a mechanism to only create classes whose names exist within the schema.org namespace. The code doesn't
do namespace checks, we assume that implementing devs know what they're doing.
@return string | [
"In",
"most",
"cases",
"the",
"name",
"of",
"the",
"object",
"withing",
"json",
"-",
"ld",
"markup",
"will",
"be",
"the",
"class",
"name",
"."
] | 354fd518aff5fa52635f435888056fe0bd926566 | https://github.com/linguisticteam/json-ld/blob/354fd518aff5fa52635f435888056fe0bd926566/src/Generators/schema_org.php#L87-L101 | train |
linguisticteam/json-ld | src/Generators/schema_org.php | Thing.format | public function format()
{
$result = array();
$result["@type"] = $this->check_type();
$values = array_filter( get_object_vars( $this ) );
foreach ($values as $key => $value) {
if ($value instanceof ICanBecomeJSONLD) {
$formatted = $value->format();
if ( ! empty( $formatted )) {
$result[$key] = $formatted;
}
} else {
$result[$key] = $value;
}
}
return $result;
} | php | public function format()
{
$result = array();
$result["@type"] = $this->check_type();
$values = array_filter( get_object_vars( $this ) );
foreach ($values as $key => $value) {
if ($value instanceof ICanBecomeJSONLD) {
$formatted = $value->format();
if ( ! empty( $formatted )) {
$result[$key] = $formatted;
}
} else {
$result[$key] = $value;
}
}
return $result;
} | [
"public",
"function",
"format",
"(",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"result",
"[",
"\"@type\"",
"]",
"=",
"$",
"this",
"->",
"check_type",
"(",
")",
";",
"$",
"values",
"=",
"array_filter",
"(",
"get_object_vars",
"(",
"$",
"this",
")",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"ICanBecomeJSONLD",
")",
"{",
"$",
"formatted",
"=",
"$",
"value",
"->",
"format",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"formatted",
")",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"formatted",
";",
"}",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Creates an array of schema.org attribute ready to be json encoded.
Grabs all properties from the class and uses those that aren't empty.
@return array | [
"Creates",
"an",
"array",
"of",
"schema",
".",
"org",
"attribute",
"ready",
"to",
"be",
"json",
"encoded",
"."
] | 354fd518aff5fa52635f435888056fe0bd926566 | https://github.com/linguisticteam/json-ld/blob/354fd518aff5fa52635f435888056fe0bd926566/src/Generators/schema_org.php#L111-L130 | train |
linguisticteam/json-ld | src/Generators/schema_org.php | Thing.addPotentialAction | protected function addPotentialAction()
{
$class = static::$helper->get_search_action_type();
if (class_exists( $class )) {
$class_test = new \ReflectionClass( $class );
if ($class_test->implementsInterface( 'Lti\Seo\Generators\ICanSearch' )) {
$this->potentialAction = new $class( static::$helper );
}
}
} | php | protected function addPotentialAction()
{
$class = static::$helper->get_search_action_type();
if (class_exists( $class )) {
$class_test = new \ReflectionClass( $class );
if ($class_test->implementsInterface( 'Lti\Seo\Generators\ICanSearch' )) {
$this->potentialAction = new $class( static::$helper );
}
}
} | [
"protected",
"function",
"addPotentialAction",
"(",
")",
"{",
"$",
"class",
"=",
"static",
"::",
"$",
"helper",
"->",
"get_search_action_type",
"(",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class_test",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"$",
"class_test",
"->",
"implementsInterface",
"(",
"'Lti\\Seo\\Generators\\ICanSearch'",
")",
")",
"{",
"$",
"this",
"->",
"potentialAction",
"=",
"new",
"$",
"class",
"(",
"static",
"::",
"$",
"helper",
")",
";",
"}",
"}",
"}"
] | Adds a search potential action if the website supports it. | [
"Adds",
"a",
"search",
"potential",
"action",
"if",
"the",
"website",
"supports",
"it",
"."
] | 354fd518aff5fa52635f435888056fe0bd926566 | https://github.com/linguisticteam/json-ld/blob/354fd518aff5fa52635f435888056fe0bd926566/src/Generators/schema_org.php#L135-L144 | train |
Xsaven/laravel-intelect-admin | src/Addons/GoogleTranslate/Tokens/GoogleTokenGenerator.php | GoogleTokenGenerator.charCodeAt | private function charCodeAt($str, $index)
{
$char = mb_substr($str, $index, 1, 'UTF-8');
if (mb_check_encoding($char, 'UTF-8')) {
$ret = mb_convert_encoding($char, 'UTF-32BE', 'UTF-8');
$result = hexdec(bin2hex($ret));
return $result;
}
return;
} | php | private function charCodeAt($str, $index)
{
$char = mb_substr($str, $index, 1, 'UTF-8');
if (mb_check_encoding($char, 'UTF-8')) {
$ret = mb_convert_encoding($char, 'UTF-32BE', 'UTF-8');
$result = hexdec(bin2hex($ret));
return $result;
}
return;
} | [
"private",
"function",
"charCodeAt",
"(",
"$",
"str",
",",
"$",
"index",
")",
"{",
"$",
"char",
"=",
"mb_substr",
"(",
"$",
"str",
",",
"$",
"index",
",",
"1",
",",
"'UTF-8'",
")",
";",
"if",
"(",
"mb_check_encoding",
"(",
"$",
"char",
",",
"'UTF-8'",
")",
")",
"{",
"$",
"ret",
"=",
"mb_convert_encoding",
"(",
"$",
"char",
",",
"'UTF-32BE'",
",",
"'UTF-8'",
")",
";",
"$",
"result",
"=",
"hexdec",
"(",
"bin2hex",
"(",
"$",
"ret",
")",
")",
";",
"return",
"$",
"result",
";",
"}",
"return",
";",
"}"
] | Get the Unicode of the character at the specified index in a string.
@param string $str
@param int $index
@return null|number | [
"Get",
"the",
"Unicode",
"of",
"the",
"character",
"at",
"the",
"specified",
"index",
"in",
"a",
"string",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/GoogleTranslate/Tokens/GoogleTokenGenerator.php#L148-L159 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.