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 |
---|---|---|---|---|---|---|---|---|---|---|---|
cyberspectrum/i18n-contao | src/ContaoTableDictionary.php | ContaoTableDictionary.createValueWriter | protected function createValueWriter(
int $sourceId,
int $targetId,
ExtractorInterface $extractor,
string $trail
): WritableTranslationValueInterface {
return new WritableTranslationValue($this, $sourceId, $targetId, $extractor, $trail);
} | php | protected function createValueWriter(
int $sourceId,
int $targetId,
ExtractorInterface $extractor,
string $trail
): WritableTranslationValueInterface {
return new WritableTranslationValue($this, $sourceId, $targetId, $extractor, $trail);
} | [
"protected",
"function",
"createValueWriter",
"(",
"int",
"$",
"sourceId",
",",
"int",
"$",
"targetId",
",",
"ExtractorInterface",
"$",
"extractor",
",",
"string",
"$",
"trail",
")",
":",
"WritableTranslationValueInterface",
"{",
"return",
"new",
"WritableTranslationValue",
"(",
"$",
"this",
",",
"$",
"sourceId",
",",
"$",
"targetId",
",",
"$",
"extractor",
",",
"$",
"trail",
")",
";",
"}"
] | Create a value writer instance.
@param int $sourceId The source id.
@param int $targetId The target id.
@param ExtractorInterface $extractor The extractor to use.
@param string $trail The trailing sub path.
@return WritableTranslationValueInterface | [
"Create",
"a",
"value",
"writer",
"instance",
"."
] | 038cf6ea9c609a734d7476fba256bc4b0db236b7 | https://github.com/cyberspectrum/i18n-contao/blob/038cf6ea9c609a734d7476fba256bc4b0db236b7/src/ContaoTableDictionary.php#L359-L366 | train |
atelierspierrot/internationalization | src/I18n/Loader.php | Loader.addPath | public function addPath($db_filename = null, $db_directory = null, $file = null)
{
if (!empty($db_filename) && !in_array($db_filename, $this->_paths['language_strings_db_filename'])) {
$this->_paths['language_strings_db_filename'][] = $db_filename;
}
if (!empty($db_directory) && !in_array($db_directory, $this->_paths['language_strings_db_directory'])) {
$this->_paths['language_strings_db_directory'][] = $db_directory;
}
if (!empty($file) && !in_array($file, $this->_paths['loaded_files'])) {
$this->_paths['loaded_files'][] = $file;
}
return $this;
} | php | public function addPath($db_filename = null, $db_directory = null, $file = null)
{
if (!empty($db_filename) && !in_array($db_filename, $this->_paths['language_strings_db_filename'])) {
$this->_paths['language_strings_db_filename'][] = $db_filename;
}
if (!empty($db_directory) && !in_array($db_directory, $this->_paths['language_strings_db_directory'])) {
$this->_paths['language_strings_db_directory'][] = $db_directory;
}
if (!empty($file) && !in_array($file, $this->_paths['loaded_files'])) {
$this->_paths['loaded_files'][] = $file;
}
return $this;
} | [
"public",
"function",
"addPath",
"(",
"$",
"db_filename",
"=",
"null",
",",
"$",
"db_directory",
"=",
"null",
",",
"$",
"file",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"db_filename",
")",
"&&",
"!",
"in_array",
"(",
"$",
"db_filename",
",",
"$",
"this",
"->",
"_paths",
"[",
"'language_strings_db_filename'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_paths",
"[",
"'language_strings_db_filename'",
"]",
"[",
"]",
"=",
"$",
"db_filename",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"db_directory",
")",
"&&",
"!",
"in_array",
"(",
"$",
"db_directory",
",",
"$",
"this",
"->",
"_paths",
"[",
"'language_strings_db_directory'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_paths",
"[",
"'language_strings_db_directory'",
"]",
"[",
"]",
"=",
"$",
"db_directory",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
"&&",
"!",
"in_array",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"_paths",
"[",
"'loaded_files'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_paths",
"[",
"'loaded_files'",
"]",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a path to the registry
@param null|string $db_filename
@param null|string $db_directory
@param null|string $file
@return $this | [
"Add",
"a",
"path",
"to",
"the",
"registry"
] | 334ebf75020d9e66b4b38a1eeab7b411f1ffe198 | https://github.com/atelierspierrot/internationalization/blob/334ebf75020d9e66b4b38a1eeab7b411f1ffe198/src/I18n/Loader.php#L88-L100 | train |
atelierspierrot/internationalization | src/I18n/Loader.php | Loader.getParsedOption | public function getParsedOption($name, $lang = null, $default = null)
{
$val = $this->getOption($name, $default);
if (false!==strpos($val, '%s')) {
if (is_null($lang)) {
$i18n = I18n::getInstance();
$lang = $i18n->getLanguage();
}
if (is_array($lang)) {
array_unshift($lang, $val);
$val = call_user_func_array('sprintf', $lang);
} else {
$val = sprintf($val, $lang);
}
}
return $val;
} | php | public function getParsedOption($name, $lang = null, $default = null)
{
$val = $this->getOption($name, $default);
if (false!==strpos($val, '%s')) {
if (is_null($lang)) {
$i18n = I18n::getInstance();
$lang = $i18n->getLanguage();
}
if (is_array($lang)) {
array_unshift($lang, $val);
$val = call_user_func_array('sprintf', $lang);
} else {
$val = sprintf($val, $lang);
}
}
return $val;
} | [
"public",
"function",
"getParsedOption",
"(",
"$",
"name",
",",
"$",
"lang",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"getOption",
"(",
"$",
"name",
",",
"$",
"default",
")",
";",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"val",
",",
"'%s'",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"lang",
")",
")",
"{",
"$",
"i18n",
"=",
"I18n",
"::",
"getInstance",
"(",
")",
";",
"$",
"lang",
"=",
"$",
"i18n",
"->",
"getLanguage",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"lang",
")",
")",
"{",
"array_unshift",
"(",
"$",
"lang",
",",
"$",
"val",
")",
";",
"$",
"val",
"=",
"call_user_func_array",
"(",
"'sprintf'",
",",
"$",
"lang",
")",
";",
"}",
"else",
"{",
"$",
"val",
"=",
"sprintf",
"(",
"$",
"val",
",",
"$",
"lang",
")",
";",
"}",
"}",
"return",
"$",
"val",
";",
"}"
] | Parse an option value replacing `%s` by the actual language code
@param string $name The option name
@param string|array $lang The language code to use or an array to pass to
the 'sprintf()' method
@param mixed $default The value to return if the option can't be found
@return mixed The value of the option if found, with replacement if so | [
"Parse",
"an",
"option",
"value",
"replacing",
"%s",
"by",
"the",
"actual",
"language",
"code"
] | 334ebf75020d9e66b4b38a1eeab7b411f1ffe198 | https://github.com/atelierspierrot/internationalization/blob/334ebf75020d9e66b4b38a1eeab7b411f1ffe198/src/I18n/Loader.php#L111-L127 | train |
atelierspierrot/internationalization | src/I18n/Loader.php | Loader.buildLanguageFileName | public function buildLanguageFileName($lang, $db_filename = null)
{
if (empty($db_filename)) {
$db_filename = $this->getParsedOption('language_strings_db_filename');
}
$filename = pathinfo($db_filename, PATHINFO_FILENAME);
return $this->getParsedOption('language_filename', array($filename, $lang));
} | php | public function buildLanguageFileName($lang, $db_filename = null)
{
if (empty($db_filename)) {
$db_filename = $this->getParsedOption('language_strings_db_filename');
}
$filename = pathinfo($db_filename, PATHINFO_FILENAME);
return $this->getParsedOption('language_filename', array($filename, $lang));
} | [
"public",
"function",
"buildLanguageFileName",
"(",
"$",
"lang",
",",
"$",
"db_filename",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"db_filename",
")",
")",
"{",
"$",
"db_filename",
"=",
"$",
"this",
"->",
"getParsedOption",
"(",
"'language_strings_db_filename'",
")",
";",
"}",
"$",
"filename",
"=",
"pathinfo",
"(",
"$",
"db_filename",
",",
"PATHINFO_FILENAME",
")",
";",
"return",
"$",
"this",
"->",
"getParsedOption",
"(",
"'language_filename'",
",",
"array",
"(",
"$",
"filename",
",",
"$",
"lang",
")",
")",
";",
"}"
] | Build the file name for the language database
@param string $lang The language code to use
@param string $db_filename A base filename to use
@return string The file name for the concerned language | [
"Build",
"the",
"file",
"name",
"for",
"the",
"language",
"database"
] | 334ebf75020d9e66b4b38a1eeab7b411f1ffe198 | https://github.com/atelierspierrot/internationalization/blob/334ebf75020d9e66b4b38a1eeab7b411f1ffe198/src/I18n/Loader.php#L140-L147 | train |
armazon/armazon | src/Armazon/Http/Respuesta.php | Respuesta.agregarCabecera | public function agregarCabecera($nombre, $valor)
{
if (isset($this->cabeceras[$nombre])) {
$this->cabeceras[$nombre][] = $valor;
} else {
$this->cabeceras[$nombre] = [$valor];
}
} | php | public function agregarCabecera($nombre, $valor)
{
if (isset($this->cabeceras[$nombre])) {
$this->cabeceras[$nombre][] = $valor;
} else {
$this->cabeceras[$nombre] = [$valor];
}
} | [
"public",
"function",
"agregarCabecera",
"(",
"$",
"nombre",
",",
"$",
"valor",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cabeceras",
"[",
"$",
"nombre",
"]",
")",
")",
"{",
"$",
"this",
"->",
"cabeceras",
"[",
"$",
"nombre",
"]",
"[",
"]",
"=",
"$",
"valor",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cabeceras",
"[",
"$",
"nombre",
"]",
"=",
"[",
"$",
"valor",
"]",
";",
"}",
"}"
] | Agrega una cabecera a la respuesta.
@param string $nombre
@param string $valor | [
"Agrega",
"una",
"cabecera",
"a",
"la",
"respuesta",
"."
] | ec76385ff80ce1659d81bc4050ef9483ab0ebe52 | https://github.com/armazon/armazon/blob/ec76385ff80ce1659d81bc4050ef9483ab0ebe52/src/Armazon/Http/Respuesta.php#L65-L73 | train |
armazon/armazon | src/Armazon/Http/Respuesta.php | Respuesta.agregarGalleta | public function agregarGalleta($nombre, $valor, $expira = 0, $camino = '/', $dominio = null, $seguro = false, $soloHttp = false)
{
$extras = '';
if ($expira) {
$extras .= ';Expires=' . gmdate('D, d M Y H:i:s \G\M\T', $expira);
}
if ($camino) {
$extras .= ';Path=' . $camino;
}
if ($dominio) {
$extras .= ';Domain=' . $dominio;
}
if ($seguro) {
$extras .= ';Secure';
}
if ($soloHttp) {
$extras .= ';HttpOnly';
}
$this->agregarCabecera('Set-Cookie', "{$nombre}={$valor}{$extras}");
} | php | public function agregarGalleta($nombre, $valor, $expira = 0, $camino = '/', $dominio = null, $seguro = false, $soloHttp = false)
{
$extras = '';
if ($expira) {
$extras .= ';Expires=' . gmdate('D, d M Y H:i:s \G\M\T', $expira);
}
if ($camino) {
$extras .= ';Path=' . $camino;
}
if ($dominio) {
$extras .= ';Domain=' . $dominio;
}
if ($seguro) {
$extras .= ';Secure';
}
if ($soloHttp) {
$extras .= ';HttpOnly';
}
$this->agregarCabecera('Set-Cookie', "{$nombre}={$valor}{$extras}");
} | [
"public",
"function",
"agregarGalleta",
"(",
"$",
"nombre",
",",
"$",
"valor",
",",
"$",
"expira",
"=",
"0",
",",
"$",
"camino",
"=",
"'/'",
",",
"$",
"dominio",
"=",
"null",
",",
"$",
"seguro",
"=",
"false",
",",
"$",
"soloHttp",
"=",
"false",
")",
"{",
"$",
"extras",
"=",
"''",
";",
"if",
"(",
"$",
"expira",
")",
"{",
"$",
"extras",
".=",
"';Expires='",
".",
"gmdate",
"(",
"'D, d M Y H:i:s \\G\\M\\T'",
",",
"$",
"expira",
")",
";",
"}",
"if",
"(",
"$",
"camino",
")",
"{",
"$",
"extras",
".=",
"';Path='",
".",
"$",
"camino",
";",
"}",
"if",
"(",
"$",
"dominio",
")",
"{",
"$",
"extras",
".=",
"';Domain='",
".",
"$",
"dominio",
";",
"}",
"if",
"(",
"$",
"seguro",
")",
"{",
"$",
"extras",
".=",
"';Secure'",
";",
"}",
"if",
"(",
"$",
"soloHttp",
")",
"{",
"$",
"extras",
".=",
"';HttpOnly'",
";",
"}",
"$",
"this",
"->",
"agregarCabecera",
"(",
"'Set-Cookie'",
",",
"\"{$nombre}={$valor}{$extras}\"",
")",
";",
"}"
] | Agrega una galleta a la respuesta.
@param $nombre
@param $valor
@param int $expira
@param string $camino
@param string $dominio
@param bool $seguro
@param bool $soloHttp | [
"Agrega",
"una",
"galleta",
"a",
"la",
"respuesta",
"."
] | ec76385ff80ce1659d81bc4050ef9483ab0ebe52 | https://github.com/armazon/armazon/blob/ec76385ff80ce1659d81bc4050ef9483ab0ebe52/src/Armazon/Http/Respuesta.php#L86-L106 | train |
armazon/armazon | src/Armazon/Http/Respuesta.php | Respuesta.enviarArchivo | public function enviarArchivo($nombre)
{
$this->definirCabecera('Pragma', 'public');
$this->definirCabecera('Expires', '0');
$this->definirCabecera('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
$this->definirCabecera('Content-Length', (function_exists('mb_strlen') ? mb_strlen($this->contenido, '8bit') : strlen($this->contenido)));
$this->definirCabecera('Content-Disposition', 'attachment; filename="' . $nombre . '"');
$this->definirCabecera('Content-Transfer-Encoding', 'binary');
$this->enviar();
} | php | public function enviarArchivo($nombre)
{
$this->definirCabecera('Pragma', 'public');
$this->definirCabecera('Expires', '0');
$this->definirCabecera('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
$this->definirCabecera('Content-Length', (function_exists('mb_strlen') ? mb_strlen($this->contenido, '8bit') : strlen($this->contenido)));
$this->definirCabecera('Content-Disposition', 'attachment; filename="' . $nombre . '"');
$this->definirCabecera('Content-Transfer-Encoding', 'binary');
$this->enviar();
} | [
"public",
"function",
"enviarArchivo",
"(",
"$",
"nombre",
")",
"{",
"$",
"this",
"->",
"definirCabecera",
"(",
"'Pragma'",
",",
"'public'",
")",
";",
"$",
"this",
"->",
"definirCabecera",
"(",
"'Expires'",
",",
"'0'",
")",
";",
"$",
"this",
"->",
"definirCabecera",
"(",
"'Cache-Control'",
",",
"'must-revalidate, post-check=0, pre-check=0'",
")",
";",
"$",
"this",
"->",
"definirCabecera",
"(",
"'Content-Length'",
",",
"(",
"function_exists",
"(",
"'mb_strlen'",
")",
"?",
"mb_strlen",
"(",
"$",
"this",
"->",
"contenido",
",",
"'8bit'",
")",
":",
"strlen",
"(",
"$",
"this",
"->",
"contenido",
")",
")",
")",
";",
"$",
"this",
"->",
"definirCabecera",
"(",
"'Content-Disposition'",
",",
"'attachment; filename=\"'",
".",
"$",
"nombre",
".",
"'\"'",
")",
";",
"$",
"this",
"->",
"definirCabecera",
"(",
"'Content-Transfer-Encoding'",
",",
"'binary'",
")",
";",
"$",
"this",
"->",
"enviar",
"(",
")",
";",
"}"
] | Envia un archivo al navegador.
@param string $nombre | [
"Envia",
"un",
"archivo",
"al",
"navegador",
"."
] | ec76385ff80ce1659d81bc4050ef9483ab0ebe52 | https://github.com/armazon/armazon/blob/ec76385ff80ce1659d81bc4050ef9483ab0ebe52/src/Armazon/Http/Respuesta.php#L214-L224 | train |
armazon/armazon | src/Armazon/Http/Respuesta.php | Respuesta.redirigir | public function redirigir($url, $estadoHttp = 302)
{
$this->definirCabecera('Location', $url);
$this->definirEstadoHttp($estadoHttp);
$this->definirContenido(null);
return $this;
} | php | public function redirigir($url, $estadoHttp = 302)
{
$this->definirCabecera('Location', $url);
$this->definirEstadoHttp($estadoHttp);
$this->definirContenido(null);
return $this;
} | [
"public",
"function",
"redirigir",
"(",
"$",
"url",
",",
"$",
"estadoHttp",
"=",
"302",
")",
"{",
"$",
"this",
"->",
"definirCabecera",
"(",
"'Location'",
",",
"$",
"url",
")",
";",
"$",
"this",
"->",
"definirEstadoHttp",
"(",
"$",
"estadoHttp",
")",
";",
"$",
"this",
"->",
"definirContenido",
"(",
"null",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Redirige el navegador a la URL especificada.
@param string $url
@param int $estadoHttp
@return self | [
"Redirige",
"el",
"navegador",
"a",
"la",
"URL",
"especificada",
"."
] | ec76385ff80ce1659d81bc4050ef9483ab0ebe52 | https://github.com/armazon/armazon/blob/ec76385ff80ce1659d81bc4050ef9483ab0ebe52/src/Armazon/Http/Respuesta.php#L233-L239 | train |
bruno-barros/w.eloquent-framework | src/weloquent/Core/Application.php | Application.run | public function run(SymfonyRequest $request = null)
{
/**
* On testing environment the WordPress helpers
* will not have context. So we stop here.
*/
if(defined('WELOQUENT_TEST_ENV') && WELOQUENT_TEST_ENV)
{
return;
}
$request = $request ?: $this['request'];
$response = with($stack = $this->getStackedClient())->handle($request);
// just set headers, but the content
if(! is_admin())
{
$response->sendHeaders();
}
if ('cli' !== PHP_SAPI)
{
$response::closeOutputBuffers(0, false);
}
/**
* Save the session data until the application dies
*/
add_action('wp_footer', function () use ($stack, $request, $response)
{
$stack->terminate($request, $response);
Session::save('wp_footer');
});
} | php | public function run(SymfonyRequest $request = null)
{
/**
* On testing environment the WordPress helpers
* will not have context. So we stop here.
*/
if(defined('WELOQUENT_TEST_ENV') && WELOQUENT_TEST_ENV)
{
return;
}
$request = $request ?: $this['request'];
$response = with($stack = $this->getStackedClient())->handle($request);
// just set headers, but the content
if(! is_admin())
{
$response->sendHeaders();
}
if ('cli' !== PHP_SAPI)
{
$response::closeOutputBuffers(0, false);
}
/**
* Save the session data until the application dies
*/
add_action('wp_footer', function () use ($stack, $request, $response)
{
$stack->terminate($request, $response);
Session::save('wp_footer');
});
} | [
"public",
"function",
"run",
"(",
"SymfonyRequest",
"$",
"request",
"=",
"null",
")",
"{",
"/**\n\t\t * On testing environment the WordPress helpers\n\t\t * will not have context. So we stop here.\n\t\t */",
"if",
"(",
"defined",
"(",
"'WELOQUENT_TEST_ENV'",
")",
"&&",
"WELOQUENT_TEST_ENV",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"request",
"?",
":",
"$",
"this",
"[",
"'request'",
"]",
";",
"$",
"response",
"=",
"with",
"(",
"$",
"stack",
"=",
"$",
"this",
"->",
"getStackedClient",
"(",
")",
")",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"// just set headers, but the content",
"if",
"(",
"!",
"is_admin",
"(",
")",
")",
"{",
"$",
"response",
"->",
"sendHeaders",
"(",
")",
";",
"}",
"if",
"(",
"'cli'",
"!==",
"PHP_SAPI",
")",
"{",
"$",
"response",
"::",
"closeOutputBuffers",
"(",
"0",
",",
"false",
")",
";",
"}",
"/**\n\t\t * Save the session data until the application dies\n\t\t */",
"add_action",
"(",
"'wp_footer'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"stack",
",",
"$",
"request",
",",
"$",
"response",
")",
"{",
"$",
"stack",
"->",
"terminate",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"Session",
"::",
"save",
"(",
"'wp_footer'",
")",
";",
"}",
")",
";",
"}"
] | Run the application and save headers.
The response is up to WordPress
@param \Symfony\Component\HttpFoundation\Request $request
@return void | [
"Run",
"the",
"application",
"and",
"save",
"headers",
".",
"The",
"response",
"is",
"up",
"to",
"WordPress"
] | d252dcb1ba1b6b1cecf67877d7d6d3ba57ebedbd | https://github.com/bruno-barros/w.eloquent-framework/blob/d252dcb1ba1b6b1cecf67877d7d6d3ba57ebedbd/src/weloquent/Core/Application.php#L44-L82 | train |
gregorybesson/PlaygroundFlow | src/Form/Admin/StoryMapping.php | StoryMapping.getLeaderboardTypes | public function getLeaderboardTypes()
{
$leaderboardTypesArray = array();
$leaderboardTypesService = $this->getServiceManager()->get('playgroundreward_leaderboardtype_service');
$leaderboardTypes = $leaderboardTypesService->getLeaderboardTypeMapper()->findAll();
foreach ($leaderboardTypes as $leaderboardType) {
$leaderboardTypesArray[$leaderboardType->getId()] = $leaderboardType->getName();
}
return $leaderboardTypesArray;
} | php | public function getLeaderboardTypes()
{
$leaderboardTypesArray = array();
$leaderboardTypesService = $this->getServiceManager()->get('playgroundreward_leaderboardtype_service');
$leaderboardTypes = $leaderboardTypesService->getLeaderboardTypeMapper()->findAll();
foreach ($leaderboardTypes as $leaderboardType) {
$leaderboardTypesArray[$leaderboardType->getId()] = $leaderboardType->getName();
}
return $leaderboardTypesArray;
} | [
"public",
"function",
"getLeaderboardTypes",
"(",
")",
"{",
"$",
"leaderboardTypesArray",
"=",
"array",
"(",
")",
";",
"$",
"leaderboardTypesService",
"=",
"$",
"this",
"->",
"getServiceManager",
"(",
")",
"->",
"get",
"(",
"'playgroundreward_leaderboardtype_service'",
")",
";",
"$",
"leaderboardTypes",
"=",
"$",
"leaderboardTypesService",
"->",
"getLeaderboardTypeMapper",
"(",
")",
"->",
"findAll",
"(",
")",
";",
"foreach",
"(",
"$",
"leaderboardTypes",
"as",
"$",
"leaderboardType",
")",
"{",
"$",
"leaderboardTypesArray",
"[",
"$",
"leaderboardType",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"leaderboardType",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"leaderboardTypesArray",
";",
"}"
] | retrieve all leaderboard type for associate to storyMapping
@return array $leaderboardTypesArray | [
"retrieve",
"all",
"leaderboard",
"type",
"for",
"associate",
"to",
"storyMapping"
] | f97493f8527e425d46223ac7b5c41331ab8b3022 | https://github.com/gregorybesson/PlaygroundFlow/blob/f97493f8527e425d46223ac7b5c41331ab8b3022/src/Form/Admin/StoryMapping.php#L317-L328 | train |
schpill/thin | src/Inflector.php | Inflector.rules | public static function rules($type, $config = array())
{
$var = '_' . $type;
if (!isset(static::${$var})) {
return null;
}
if (empty($config)) {
return static::${$var};
}
switch ($type) {
case 'transliteration':
$_config = array();
foreach ($config as $key => $val) {
if ($key[0] != '/') {
$key = '/' . join('|', array_filter(preg_split('//u', $key))) . '/';
}
$_config[$key] = $val;
}
static::$_transliteration = array_merge(
$_config, static::$_transliteration, $_config
);
break;
case 'uninflected':
static::$_uninflected = array_merge(static::$_uninflected, (array) $config);
static::$_plural['regexUninflected'] = null;
static::$_singular['regexUninflected'] = null;
foreach ((array) $config as $word) {
unset(static::$_singularized[$word], static::$_pluralized[$word]);
}
break;
case 'singular':
case 'plural':
if (isset(static::${$var}[key($config)])) {
foreach ($config as $rType => $set) {
static::${$var}[$rType] = array_merge($set, static::${$var}[$rType], $set);
if ($rType == 'irregular') {
$swap = ($type == 'singular' ? '_plural' : '_singular');
static::${$swap}[$rType] = array_flip(static::${$var}[$rType]);
}
}
} else {
static::${$var}['rules'] = array_merge(
$config, static::${$var}['rules'], $config
);
}
break;
}
} | php | public static function rules($type, $config = array())
{
$var = '_' . $type;
if (!isset(static::${$var})) {
return null;
}
if (empty($config)) {
return static::${$var};
}
switch ($type) {
case 'transliteration':
$_config = array();
foreach ($config as $key => $val) {
if ($key[0] != '/') {
$key = '/' . join('|', array_filter(preg_split('//u', $key))) . '/';
}
$_config[$key] = $val;
}
static::$_transliteration = array_merge(
$_config, static::$_transliteration, $_config
);
break;
case 'uninflected':
static::$_uninflected = array_merge(static::$_uninflected, (array) $config);
static::$_plural['regexUninflected'] = null;
static::$_singular['regexUninflected'] = null;
foreach ((array) $config as $word) {
unset(static::$_singularized[$word], static::$_pluralized[$word]);
}
break;
case 'singular':
case 'plural':
if (isset(static::${$var}[key($config)])) {
foreach ($config as $rType => $set) {
static::${$var}[$rType] = array_merge($set, static::${$var}[$rType], $set);
if ($rType == 'irregular') {
$swap = ($type == 'singular' ? '_plural' : '_singular');
static::${$swap}[$rType] = array_flip(static::${$var}[$rType]);
}
}
} else {
static::${$var}['rules'] = array_merge(
$config, static::${$var}['rules'], $config
);
}
break;
}
} | [
"public",
"static",
"function",
"rules",
"(",
"$",
"type",
",",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"$",
"var",
"=",
"'_'",
".",
"$",
"type",
";",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"{",
"$",
"var",
"}",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"config",
")",
")",
"{",
"return",
"static",
"::",
"$",
"{",
"$",
"var",
"}",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'transliteration'",
":",
"$",
"_config",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"[",
"0",
"]",
"!=",
"'/'",
")",
"{",
"$",
"key",
"=",
"'/'",
".",
"join",
"(",
"'|'",
",",
"array_filter",
"(",
"preg_split",
"(",
"'//u'",
",",
"$",
"key",
")",
")",
")",
".",
"'/'",
";",
"}",
"$",
"_config",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"static",
"::",
"$",
"_transliteration",
"=",
"array_merge",
"(",
"$",
"_config",
",",
"static",
"::",
"$",
"_transliteration",
",",
"$",
"_config",
")",
";",
"break",
";",
"case",
"'uninflected'",
":",
"static",
"::",
"$",
"_uninflected",
"=",
"array_merge",
"(",
"static",
"::",
"$",
"_uninflected",
",",
"(",
"array",
")",
"$",
"config",
")",
";",
"static",
"::",
"$",
"_plural",
"[",
"'regexUninflected'",
"]",
"=",
"null",
";",
"static",
"::",
"$",
"_singular",
"[",
"'regexUninflected'",
"]",
"=",
"null",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"config",
"as",
"$",
"word",
")",
"{",
"unset",
"(",
"static",
"::",
"$",
"_singularized",
"[",
"$",
"word",
"]",
",",
"static",
"::",
"$",
"_pluralized",
"[",
"$",
"word",
"]",
")",
";",
"}",
"break",
";",
"case",
"'singular'",
":",
"case",
"'plural'",
":",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"{",
"$",
"var",
"}",
"[",
"key",
"(",
"$",
"config",
")",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
"rType",
"=>",
"$",
"set",
")",
"{",
"static",
"::",
"$",
"{",
"$",
"var",
"}",
"[",
"$",
"rType",
"]",
"=",
"array_merge",
"(",
"$",
"set",
",",
"static",
"::",
"$",
"{",
"$",
"var",
"}",
"[",
"$",
"rType",
"]",
",",
"$",
"set",
")",
";",
"if",
"(",
"$",
"rType",
"==",
"'irregular'",
")",
"{",
"$",
"swap",
"=",
"(",
"$",
"type",
"==",
"'singular'",
"?",
"'_plural'",
":",
"'_singular'",
")",
";",
"static",
"::",
"$",
"{",
"$",
"swap",
"}",
"[",
"$",
"rType",
"]",
"=",
"array_flip",
"(",
"static",
"::",
"$",
"{",
"$",
"var",
"}",
"[",
"$",
"rType",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"static",
"::",
"$",
"{",
"$",
"var",
"}",
"[",
"'rules'",
"]",
"=",
"array_merge",
"(",
"$",
"config",
",",
"static",
"::",
"$",
"{",
"$",
"var",
"}",
"[",
"'rules'",
"]",
",",
"$",
"config",
")",
";",
"}",
"break",
";",
"}",
"}"
] | Gets or adds inflection and transliteration rules.
@param string $type Either `'transliteration'`, `'uninflected'`, `'singular'` or `'plural'`.
@param array $config
@return mixed If `$config` is empty, returns the rules list specified
by `$type`, otherwise returns `null`. | [
"Gets",
"or",
"adds",
"inflection",
"and",
"transliteration",
"rules",
"."
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Inflector.php#L221-L275 | train |
schpill/thin | src/Inflector.php | Inflector.pluralize | public static function pluralize($word)
{
if (isset(static::$_pluralized[$word])) {
return static::$_pluralized[$word];
}
extract(static::$_plural);
if (!isset($regexUninflected) || !isset($regexIrregular)) {
$regexUninflected = static::_enclose(join('|', $uninflected + static::$_uninflected));
$regexIrregular = static::_enclose(join('|', array_keys($irregular)));
static::$_plural += compact('regexUninflected', 'regexIrregular');
}
if (preg_match('/(' . $regexUninflected . ')$/i', $word, $regs)) {
return static::$_pluralized[$word] = $word;
}
if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) {
$plural = substr($word, 0, 1) . substr($irregular[static::lower($regs[2])], 1);
return static::$_pluralized[$word] = $regs[1] . $plural;
}
foreach ($rules as $rule => $replacement) {
if (preg_match($rule, $word)) {
return static::$_pluralized[$word] = preg_replace($rule, $replacement, $word);
}
}
return static::$_pluralized[$word] = $word;
} | php | public static function pluralize($word)
{
if (isset(static::$_pluralized[$word])) {
return static::$_pluralized[$word];
}
extract(static::$_plural);
if (!isset($regexUninflected) || !isset($regexIrregular)) {
$regexUninflected = static::_enclose(join('|', $uninflected + static::$_uninflected));
$regexIrregular = static::_enclose(join('|', array_keys($irregular)));
static::$_plural += compact('regexUninflected', 'regexIrregular');
}
if (preg_match('/(' . $regexUninflected . ')$/i', $word, $regs)) {
return static::$_pluralized[$word] = $word;
}
if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) {
$plural = substr($word, 0, 1) . substr($irregular[static::lower($regs[2])], 1);
return static::$_pluralized[$word] = $regs[1] . $plural;
}
foreach ($rules as $rule => $replacement) {
if (preg_match($rule, $word)) {
return static::$_pluralized[$word] = preg_replace($rule, $replacement, $word);
}
}
return static::$_pluralized[$word] = $word;
} | [
"public",
"static",
"function",
"pluralize",
"(",
"$",
"word",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_pluralized",
"[",
"$",
"word",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_pluralized",
"[",
"$",
"word",
"]",
";",
"}",
"extract",
"(",
"static",
"::",
"$",
"_plural",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"regexUninflected",
")",
"||",
"!",
"isset",
"(",
"$",
"regexIrregular",
")",
")",
"{",
"$",
"regexUninflected",
"=",
"static",
"::",
"_enclose",
"(",
"join",
"(",
"'|'",
",",
"$",
"uninflected",
"+",
"static",
"::",
"$",
"_uninflected",
")",
")",
";",
"$",
"regexIrregular",
"=",
"static",
"::",
"_enclose",
"(",
"join",
"(",
"'|'",
",",
"array_keys",
"(",
"$",
"irregular",
")",
")",
")",
";",
"static",
"::",
"$",
"_plural",
"+=",
"compact",
"(",
"'regexUninflected'",
",",
"'regexIrregular'",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/('",
".",
"$",
"regexUninflected",
".",
"')$/i'",
",",
"$",
"word",
",",
"$",
"regs",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_pluralized",
"[",
"$",
"word",
"]",
"=",
"$",
"word",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/(.*)\\\\b('",
".",
"$",
"regexIrregular",
".",
"')$/i'",
",",
"$",
"word",
",",
"$",
"regs",
")",
")",
"{",
"$",
"plural",
"=",
"substr",
"(",
"$",
"word",
",",
"0",
",",
"1",
")",
".",
"substr",
"(",
"$",
"irregular",
"[",
"static",
"::",
"lower",
"(",
"$",
"regs",
"[",
"2",
"]",
")",
"]",
",",
"1",
")",
";",
"return",
"static",
"::",
"$",
"_pluralized",
"[",
"$",
"word",
"]",
"=",
"$",
"regs",
"[",
"1",
"]",
".",
"$",
"plural",
";",
"}",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
"=>",
"$",
"replacement",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"rule",
",",
"$",
"word",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_pluralized",
"[",
"$",
"word",
"]",
"=",
"preg_replace",
"(",
"$",
"rule",
",",
"$",
"replacement",
",",
"$",
"word",
")",
";",
"}",
"}",
"return",
"static",
"::",
"$",
"_pluralized",
"[",
"$",
"word",
"]",
"=",
"$",
"word",
";",
"}"
] | Changes the form of a word from singular to plural.
@param string $word Word in singular form.
@return string Word in plural form. | [
"Changes",
"the",
"form",
"of",
"a",
"word",
"from",
"singular",
"to",
"plural",
"."
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Inflector.php#L283-L315 | train |
schpill/thin | src/Inflector.php | Inflector.limitExact | public static function limitExact($value, $limit = 100, $end = '...')
{
if (static::length($value) <= $limit) {
return $value;
}
$limit -= static::length($end);
return static::limit($value, $limit, $end);
} | php | public static function limitExact($value, $limit = 100, $end = '...')
{
if (static::length($value) <= $limit) {
return $value;
}
$limit -= static::length($end);
return static::limit($value, $limit, $end);
} | [
"public",
"static",
"function",
"limitExact",
"(",
"$",
"value",
",",
"$",
"limit",
"=",
"100",
",",
"$",
"end",
"=",
"'...'",
")",
"{",
"if",
"(",
"static",
"::",
"length",
"(",
"$",
"value",
")",
"<=",
"$",
"limit",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"limit",
"-=",
"static",
"::",
"length",
"(",
"$",
"end",
")",
";",
"return",
"static",
"::",
"limit",
"(",
"$",
"value",
",",
"$",
"limit",
",",
"$",
"end",
")",
";",
"}"
] | Limit the number of chracters in a string including custom ending
<code>
// Returns "hello..."
echo Inflector::limitExact('hello word', 9);
// Limit the number of characters and append a custom ending
echo Inflector::limitExact('hello word', 9, '---');
</code>
@param string $value
@param int $limit
@param string $end
@return string | [
"Limit",
"the",
"number",
"of",
"chracters",
"in",
"a",
"string",
"including",
"custom",
"ending"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Inflector.php#L985-L994 | train |
Phpillip/phpillip | src/Console/Model/Logger.php | Logger.getProgress | public function getProgress($total = null)
{
if (!$this->progress || $this->progress->getMaxSteps() === $this->progress->getProgress()) {
$this->progress = new ProgressBar($this->output, $total);
}
return $this->progress;
} | php | public function getProgress($total = null)
{
if (!$this->progress || $this->progress->getMaxSteps() === $this->progress->getProgress()) {
$this->progress = new ProgressBar($this->output, $total);
}
return $this->progress;
} | [
"public",
"function",
"getProgress",
"(",
"$",
"total",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"progress",
"||",
"$",
"this",
"->",
"progress",
"->",
"getMaxSteps",
"(",
")",
"===",
"$",
"this",
"->",
"progress",
"->",
"getProgress",
"(",
")",
")",
"{",
"$",
"this",
"->",
"progress",
"=",
"new",
"ProgressBar",
"(",
"$",
"this",
"->",
"output",
",",
"$",
"total",
")",
";",
"}",
"return",
"$",
"this",
"->",
"progress",
";",
"}"
] | Get progress bar instance
@param integer $total
@return ProgressBar | [
"Get",
"progress",
"bar",
"instance"
] | c37afaafb536361e7e0b564659f1cd5b80b98be9 | https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/Console/Model/Logger.php#L67-L74 | train |
Phpillip/phpillip | src/Console/Model/Logger.php | Logger.flush | public function flush()
{
if (!$this->progress) {
$this->log('');
foreach ($this->logs as $message) {
$this->log($message);
}
$this->logs = [];
}
} | php | public function flush()
{
if (!$this->progress) {
$this->log('');
foreach ($this->logs as $message) {
$this->log($message);
}
$this->logs = [];
}
} | [
"public",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"progress",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"''",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"logs",
"as",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"message",
")",
";",
"}",
"$",
"this",
"->",
"logs",
"=",
"[",
"]",
";",
"}",
"}"
] | Flush message queue | [
"Flush",
"message",
"queue"
] | c37afaafb536361e7e0b564659f1cd5b80b98be9 | https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/Console/Model/Logger.php#L111-L122 | train |
phramework/phramework | src/Authentication/Manager.php | Manager.register | public static function register($implementation)
{
$object = new $implementation();
if (!($object instanceof \Phramework\Authentication\IAuthentication)) {
throw new \Exception(
'Class is not implementing \Phramework\Authentication\IAuthentication'
);
}
self::$implementations[] = $object;
} | php | public static function register($implementation)
{
$object = new $implementation();
if (!($object instanceof \Phramework\Authentication\IAuthentication)) {
throw new \Exception(
'Class is not implementing \Phramework\Authentication\IAuthentication'
);
}
self::$implementations[] = $object;
} | [
"public",
"static",
"function",
"register",
"(",
"$",
"implementation",
")",
"{",
"$",
"object",
"=",
"new",
"$",
"implementation",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"object",
"instanceof",
"\\",
"Phramework",
"\\",
"Authentication",
"\\",
"IAuthentication",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Class is not implementing \\Phramework\\Authentication\\IAuthentication'",
")",
";",
"}",
"self",
"::",
"$",
"implementations",
"[",
"]",
"=",
"$",
"object",
";",
"}"
] | Register an authentication implementation.
Implementation must implement
`\Phramework\Authentication\IAuthentication` interface
@param string $implementation implementation class
@throws Exception | [
"Register",
"an",
"authentication",
"implementation",
".",
"Implementation",
"must",
"implement",
"\\",
"Phramework",
"\\",
"Authentication",
"\\",
"IAuthentication",
"interface"
] | 40041d1ef23b1f8cdbd26fb112448d6a3dbef012 | https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Authentication/Manager.php#L31-L41 | train |
phramework/phramework | src/Authentication/Manager.php | Manager.check | public static function check($params, $method, $headers)
{
if (count(self::$implementations) !== 0 && !self::$userGetByEmailMethod) {
throw new \Phramework\Exceptions\ServerException(
'getUserByEmail method is not set'
);
}
foreach (self::$implementations as $implementation) {
if ($implementation->testProvidedMethod($params, $method, $headers)) {
return $implementation->check($params, $method, $headers);
}
}
return false; //Not found
} | php | public static function check($params, $method, $headers)
{
if (count(self::$implementations) !== 0 && !self::$userGetByEmailMethod) {
throw new \Phramework\Exceptions\ServerException(
'getUserByEmail method is not set'
);
}
foreach (self::$implementations as $implementation) {
if ($implementation->testProvidedMethod($params, $method, $headers)) {
return $implementation->check($params, $method, $headers);
}
}
return false; //Not found
} | [
"public",
"static",
"function",
"check",
"(",
"$",
"params",
",",
"$",
"method",
",",
"$",
"headers",
")",
"{",
"if",
"(",
"count",
"(",
"self",
"::",
"$",
"implementations",
")",
"!==",
"0",
"&&",
"!",
"self",
"::",
"$",
"userGetByEmailMethod",
")",
"{",
"throw",
"new",
"\\",
"Phramework",
"\\",
"Exceptions",
"\\",
"ServerException",
"(",
"'getUserByEmail method is not set'",
")",
";",
"}",
"foreach",
"(",
"self",
"::",
"$",
"implementations",
"as",
"$",
"implementation",
")",
"{",
"if",
"(",
"$",
"implementation",
"->",
"testProvidedMethod",
"(",
"$",
"params",
",",
"$",
"method",
",",
"$",
"headers",
")",
")",
"{",
"return",
"$",
"implementation",
"->",
"check",
"(",
"$",
"params",
",",
"$",
"method",
",",
"$",
"headers",
")",
";",
"}",
"}",
"return",
"false",
";",
"//Not found",
"}"
] | Check user's authentication
This method iterates through all available authentication implementations
tests in priorioty order which of them might be provided and executes
@param array $params Request parameters
@param string $method Request method
@param array $headers Request headers
@return array|false Returns false on error or the user object on success
@throws Phramework\Exceptions\ServerException | [
"Check",
"user",
"s",
"authentication",
"This",
"method",
"iterates",
"through",
"all",
"available",
"authentication",
"implementations",
"tests",
"in",
"priorioty",
"order",
"which",
"of",
"them",
"might",
"be",
"provided",
"and",
"executes"
] | 40041d1ef23b1f8cdbd26fb112448d6a3dbef012 | https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Authentication/Manager.php#L61-L76 | train |
lechimp-p/flightcontrol | src/Recursor.php | Recursor.filter | public function filter(\Closure $predicate) {
$filter = array();
$filter[0] = function(FixedFDirectory $obj) use ($predicate, &$filter) {
return $obj
->filter($predicate)
->map(function(FSObject $obj) use ($predicate, &$filter) {
if ($obj->isFile()) {
return $obj;
}
return $filter[0]($obj);
});
};
return new Recursor($filter[0]($this->directory));
} | php | public function filter(\Closure $predicate) {
$filter = array();
$filter[0] = function(FixedFDirectory $obj) use ($predicate, &$filter) {
return $obj
->filter($predicate)
->map(function(FSObject $obj) use ($predicate, &$filter) {
if ($obj->isFile()) {
return $obj;
}
return $filter[0]($obj);
});
};
return new Recursor($filter[0]($this->directory));
} | [
"public",
"function",
"filter",
"(",
"\\",
"Closure",
"$",
"predicate",
")",
"{",
"$",
"filter",
"=",
"array",
"(",
")",
";",
"$",
"filter",
"[",
"0",
"]",
"=",
"function",
"(",
"FixedFDirectory",
"$",
"obj",
")",
"use",
"(",
"$",
"predicate",
",",
"&",
"$",
"filter",
")",
"{",
"return",
"$",
"obj",
"->",
"filter",
"(",
"$",
"predicate",
")",
"->",
"map",
"(",
"function",
"(",
"FSObject",
"$",
"obj",
")",
"use",
"(",
"$",
"predicate",
",",
"&",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"isFile",
"(",
")",
")",
"{",
"return",
"$",
"obj",
";",
"}",
"return",
"$",
"filter",
"[",
"0",
"]",
"(",
"$",
"obj",
")",
";",
"}",
")",
";",
"}",
";",
"return",
"new",
"Recursor",
"(",
"$",
"filter",
"[",
"0",
"]",
"(",
"$",
"this",
"->",
"directory",
")",
")",
";",
"}"
] | Get a recursor that folds all files in this recursor that match the
provided predicate and the objects below that match the predicate as
well.
Won't recurse over directories that do not match the predicate!
@param \Closure $predicate (FSObject -> Bool)
@return Recursor | [
"Get",
"a",
"recursor",
"that",
"folds",
"all",
"files",
"in",
"this",
"recursor",
"that",
"match",
"the",
"provided",
"predicate",
"and",
"the",
"objects",
"below",
"that",
"match",
"the",
"predicate",
"as",
"well",
"."
] | be7698183b44787f1b3d4a16d739655388e569ae | https://github.com/lechimp-p/flightcontrol/blob/be7698183b44787f1b3d4a16d739655388e569ae/src/Recursor.php#L39-L52 | train |
lechimp-p/flightcontrol | src/Recursor.php | Recursor.cata | public function cata(\Closure $trans) {
return $trans( $this->directory->unfix()->fmap(function(FSObject $obj) use ($trans) {
if ($obj->isFile()) {
return $trans($obj);
}
assert($obj instanceof FixedFDirectory);
return $obj->cata($trans);
}));
} | php | public function cata(\Closure $trans) {
return $trans( $this->directory->unfix()->fmap(function(FSObject $obj) use ($trans) {
if ($obj->isFile()) {
return $trans($obj);
}
assert($obj instanceof FixedFDirectory);
return $obj->cata($trans);
}));
} | [
"public",
"function",
"cata",
"(",
"\\",
"Closure",
"$",
"trans",
")",
"{",
"return",
"$",
"trans",
"(",
"$",
"this",
"->",
"directory",
"->",
"unfix",
"(",
")",
"->",
"fmap",
"(",
"function",
"(",
"FSObject",
"$",
"obj",
")",
"use",
"(",
"$",
"trans",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"isFile",
"(",
")",
")",
"{",
"return",
"$",
"trans",
"(",
"$",
"obj",
")",
";",
"}",
"assert",
"(",
"$",
"obj",
"instanceof",
"FixedFDirectory",
")",
";",
"return",
"$",
"obj",
"->",
"cata",
"(",
"$",
"trans",
")",
";",
"}",
")",
")",
";",
"}"
] | We could also use the catamorphism on this to do recursion, as we
have an unfix and an underlying fmap from the FDirectory.
Supply a function $trans from File|FDirectory a to a that flattens
(folds) a directory. Will start the directories where only files are
included, folds them and then proceeds upwards.
The return type should be 'a' (from the function $trans) instead
of mixed, but we can't express that fact correctly in the docstring
typing.
@param \Closure $trans File|FDirectory a -> a
@return mixed | [
"We",
"could",
"also",
"use",
"the",
"catamorphism",
"on",
"this",
"to",
"do",
"recursion",
"as",
"we",
"have",
"an",
"unfix",
"and",
"an",
"underlying",
"fmap",
"from",
"the",
"FDirectory",
"."
] | be7698183b44787f1b3d4a16d739655388e569ae | https://github.com/lechimp-p/flightcontrol/blob/be7698183b44787f1b3d4a16d739655388e569ae/src/Recursor.php#L69-L77 | train |
lechimp-p/flightcontrol | src/Recursor.php | Recursor.foldFiles | public function foldFiles($start_value, \Closure $fold_with) {
foreach ($this->allFiles() as $file) {
$start_value = $fold_with($start_value, $file);
}
return $start_value;
} | php | public function foldFiles($start_value, \Closure $fold_with) {
foreach ($this->allFiles() as $file) {
$start_value = $fold_with($start_value, $file);
}
return $start_value;
} | [
"public",
"function",
"foldFiles",
"(",
"$",
"start_value",
",",
"\\",
"Closure",
"$",
"fold_with",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"allFiles",
"(",
")",
"as",
"$",
"file",
")",
"{",
"$",
"start_value",
"=",
"$",
"fold_with",
"(",
"$",
"start_value",
",",
"$",
"file",
")",
";",
"}",
"return",
"$",
"start_value",
";",
"}"
] | Fold over all files in this directory and subjacent directories.
Start with an initial value of some type and a function from that type
and File to a new value of the type. Will successively feed all files
and the resulting values to that function.
@param mixed $start_value
@param \Closure $fold_with a -> File -> a
@return Recursor | [
"Fold",
"over",
"all",
"files",
"in",
"this",
"directory",
"and",
"subjacent",
"directories",
"."
] | be7698183b44787f1b3d4a16d739655388e569ae | https://github.com/lechimp-p/flightcontrol/blob/be7698183b44787f1b3d4a16d739655388e569ae/src/Recursor.php#L100-L105 | train |
lechimp-p/flightcontrol | src/Recursor.php | Recursor.allFiles | public function allFiles() {
return $this->cata(function(FSObject $obj) {
if ($obj->isFile()) {
return array($obj);
}
assert($obj instanceof FDirectory);
$fcontents = $obj->fcontents();
if (empty($fcontents)) {
return $fcontents;
}
return call_user_func_array("array_merge", $fcontents);
});
} | php | public function allFiles() {
return $this->cata(function(FSObject $obj) {
if ($obj->isFile()) {
return array($obj);
}
assert($obj instanceof FDirectory);
$fcontents = $obj->fcontents();
if (empty($fcontents)) {
return $fcontents;
}
return call_user_func_array("array_merge", $fcontents);
});
} | [
"public",
"function",
"allFiles",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"cata",
"(",
"function",
"(",
"FSObject",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"isFile",
"(",
")",
")",
"{",
"return",
"array",
"(",
"$",
"obj",
")",
";",
"}",
"assert",
"(",
"$",
"obj",
"instanceof",
"FDirectory",
")",
";",
"$",
"fcontents",
"=",
"$",
"obj",
"->",
"fcontents",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"fcontents",
")",
")",
"{",
"return",
"$",
"fcontents",
";",
"}",
"return",
"call_user_func_array",
"(",
"\"array_merge\"",
",",
"$",
"fcontents",
")",
";",
"}",
")",
";",
"}"
] | Get a list of all files in the directory and subjacent directories.
@return File[] | [
"Get",
"a",
"list",
"of",
"all",
"files",
"in",
"the",
"directory",
"and",
"subjacent",
"directories",
"."
] | be7698183b44787f1b3d4a16d739655388e569ae | https://github.com/lechimp-p/flightcontrol/blob/be7698183b44787f1b3d4a16d739655388e569ae/src/Recursor.php#L112-L125 | train |
Ekstazi/yii2-crud-actions | src/actions/Action.php | Action.ensureAccess | protected function ensureAccess($params = [])
{
if (!isset($this->checkAccess))
return;
$params['action'] = $this;
if (call_user_func($this->checkAccess, $params))
return;
$user = \Yii::$app->user;
if ($user->getIsGuest())
$user->loginRequired();
else
throw new ForbiddenHttpException(\Yii::t(
Constants::MSG_CATEGORY_NAME,
'You are not allowed to perform this action.'
));
} | php | protected function ensureAccess($params = [])
{
if (!isset($this->checkAccess))
return;
$params['action'] = $this;
if (call_user_func($this->checkAccess, $params))
return;
$user = \Yii::$app->user;
if ($user->getIsGuest())
$user->loginRequired();
else
throw new ForbiddenHttpException(\Yii::t(
Constants::MSG_CATEGORY_NAME,
'You are not allowed to perform this action.'
));
} | [
"protected",
"function",
"ensureAccess",
"(",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"checkAccess",
")",
")",
"return",
";",
"$",
"params",
"[",
"'action'",
"]",
"=",
"$",
"this",
";",
"if",
"(",
"call_user_func",
"(",
"$",
"this",
"->",
"checkAccess",
",",
"$",
"params",
")",
")",
"return",
";",
"$",
"user",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
";",
"if",
"(",
"$",
"user",
"->",
"getIsGuest",
"(",
")",
")",
"$",
"user",
"->",
"loginRequired",
"(",
")",
";",
"else",
"throw",
"new",
"ForbiddenHttpException",
"(",
"\\",
"Yii",
"::",
"t",
"(",
"Constants",
"::",
"MSG_CATEGORY_NAME",
",",
"'You are not allowed to perform this action.'",
")",
")",
";",
"}"
] | Ensure this action is allowed for current user
@param array $params Params to be passed to {$this->checkAccess}
@throws ForbiddenHttpException | [
"Ensure",
"this",
"action",
"is",
"allowed",
"for",
"current",
"user"
] | 38029fcfc1fac662604b3cabc08ec6ccacb94c57 | https://github.com/Ekstazi/yii2-crud-actions/blob/38029fcfc1fac662604b3cabc08ec6ccacb94c57/src/actions/Action.php#L66-L86 | train |
tigron/skeleton-error | lib/Skeleton/Error/Detector/Whoops.php | Whoops.detect | public static function detect($html, &$error = '') {
if (!class_exists('Whoops\Run')) {
return false;
}
if (strpos($html, 'class="Whoops container"') != false) {
// temporarily disables libxml warnings
libxml_use_internal_errors(true);
$dom = new \DOMDocument();
$dom->loadHTML($html);
$xpath = new \DOMXpath($dom);
$results = $xpath->query("//span[@id='plain-exception']");
libxml_use_internal_errors(false);
if (!is_null($results)) {
$error = $results[0]->nodeValue;
}
return true;
}
return false;
} | php | public static function detect($html, &$error = '') {
if (!class_exists('Whoops\Run')) {
return false;
}
if (strpos($html, 'class="Whoops container"') != false) {
// temporarily disables libxml warnings
libxml_use_internal_errors(true);
$dom = new \DOMDocument();
$dom->loadHTML($html);
$xpath = new \DOMXpath($dom);
$results = $xpath->query("//span[@id='plain-exception']");
libxml_use_internal_errors(false);
if (!is_null($results)) {
$error = $results[0]->nodeValue;
}
return true;
}
return false;
} | [
"public",
"static",
"function",
"detect",
"(",
"$",
"html",
",",
"&",
"$",
"error",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'Whoops\\Run'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"html",
",",
"'class=\"Whoops container\"'",
")",
"!=",
"false",
")",
"{",
"// temporarily disables libxml warnings",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"dom",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"dom",
"->",
"loadHTML",
"(",
"$",
"html",
")",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXpath",
"(",
"$",
"dom",
")",
";",
"$",
"results",
"=",
"$",
"xpath",
"->",
"query",
"(",
"\"//span[@id='plain-exception']\"",
")",
";",
"libxml_use_internal_errors",
"(",
"false",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"results",
")",
")",
"{",
"$",
"error",
"=",
"$",
"results",
"[",
"0",
"]",
"->",
"nodeValue",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Function detect
Takes care of detecting if a Whoops error was passed and if true
extracting the error code to return it by reference
@access public
@param string $html code of the page to be analyzed
@param string $error the error code found (if any)
@return bool does the page contain an error | [
"Function",
"detect",
"Takes",
"care",
"of",
"detecting",
"if",
"a",
"Whoops",
"error",
"was",
"passed",
"and",
"if",
"true",
"extracting",
"the",
"error",
"code",
"to",
"return",
"it",
"by",
"reference"
] | c0671ad52a4386d95179f1c47bedfdf754ee3611 | https://github.com/tigron/skeleton-error/blob/c0671ad52a4386d95179f1c47bedfdf754ee3611/lib/Skeleton/Error/Detector/Whoops.php#L25-L47 | train |
pmdevelopment/tool-bundle | Framework/Model/SendMailFormModel.php | SendMailFormModel.getSwiftMessage | public function getSwiftMessage()
{
$message = \Swift_Message::newInstance();
if (true === is_array($this->getRecipient())) {
$recipient = $this->getRecipient();
} else {
$recipient = [
$this->getRecipient(),
];
};
$message
->setSubject($this->getSubject())
->setFrom(
[
$this->getSender(),
]
)
->setTo($recipient)
->setBody($this->getMessage());
if (0 < count($this->getAttachments())) {
foreach ($this->getAttachments() as $attachment) {
$message->attach($attachment);
}
}
return $message;
} | php | public function getSwiftMessage()
{
$message = \Swift_Message::newInstance();
if (true === is_array($this->getRecipient())) {
$recipient = $this->getRecipient();
} else {
$recipient = [
$this->getRecipient(),
];
};
$message
->setSubject($this->getSubject())
->setFrom(
[
$this->getSender(),
]
)
->setTo($recipient)
->setBody($this->getMessage());
if (0 < count($this->getAttachments())) {
foreach ($this->getAttachments() as $attachment) {
$message->attach($attachment);
}
}
return $message;
} | [
"public",
"function",
"getSwiftMessage",
"(",
")",
"{",
"$",
"message",
"=",
"\\",
"Swift_Message",
"::",
"newInstance",
"(",
")",
";",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"this",
"->",
"getRecipient",
"(",
")",
")",
")",
"{",
"$",
"recipient",
"=",
"$",
"this",
"->",
"getRecipient",
"(",
")",
";",
"}",
"else",
"{",
"$",
"recipient",
"=",
"[",
"$",
"this",
"->",
"getRecipient",
"(",
")",
",",
"]",
";",
"}",
";",
"$",
"message",
"->",
"setSubject",
"(",
"$",
"this",
"->",
"getSubject",
"(",
")",
")",
"->",
"setFrom",
"(",
"[",
"$",
"this",
"->",
"getSender",
"(",
")",
",",
"]",
")",
"->",
"setTo",
"(",
"$",
"recipient",
")",
"->",
"setBody",
"(",
"$",
"this",
"->",
"getMessage",
"(",
")",
")",
";",
"if",
"(",
"0",
"<",
"count",
"(",
"$",
"this",
"->",
"getAttachments",
"(",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getAttachments",
"(",
")",
"as",
"$",
"attachment",
")",
"{",
"$",
"message",
"->",
"attach",
"(",
"$",
"attachment",
")",
";",
"}",
"}",
"return",
"$",
"message",
";",
"}"
] | Get Swift Message
@return Swift_Mime_Message | [
"Get",
"Swift",
"Message"
] | 2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129 | https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Framework/Model/SendMailFormModel.php#L161-L190 | train |
zbox/UnifiedPush | src/Zbox/UnifiedPush/NotificationService/GCM/Response.php | Response.checkMessageStatus | private function checkMessageStatus($message)
{
if (!$message || $message->success == 0 || $message->failure > 0) {
throw new DispatchMessageException(
sprintf("%d messages could not be processed", $message->failure)
);
}
} | php | private function checkMessageStatus($message)
{
if (!$message || $message->success == 0 || $message->failure > 0) {
throw new DispatchMessageException(
sprintf("%d messages could not be processed", $message->failure)
);
}
} | [
"private",
"function",
"checkMessageStatus",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"message",
"||",
"$",
"message",
"->",
"success",
"==",
"0",
"||",
"$",
"message",
"->",
"failure",
">",
"0",
")",
"{",
"throw",
"new",
"DispatchMessageException",
"(",
"sprintf",
"(",
"\"%d messages could not be processed\"",
",",
"$",
"message",
"->",
"failure",
")",
")",
";",
"}",
"}"
] | Checks message status
@param \stdClass $message | [
"Checks",
"message",
"status"
] | 47da2d0577b18ac709cd947c68541014001e1866 | https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/NotificationService/GCM/Response.php#L119-L126 | train |
zbox/UnifiedPush | src/Zbox/UnifiedPush/NotificationService/GCM/Response.php | Response.checkMessageResult | private function checkMessageResult($message, \ArrayIterator $recipients)
{
$hasDeviceError = false;
$recipientCount = $recipients->count();
for ($i = 0; $i <= $recipientCount; $i++) {
if (isset($message->results[$i]['registration_id'])) {
$hasDeviceError = true;
$recipients->offsetGet($i)->setIdentifierToReplaceTo($message->results[$i]['registration_id']);
}
if (isset($message->results[$i]['error'])) {
$hasDeviceError = true;
$error = $message->results[$i]['error'];
$this->processError($error, $recipients->offsetGet($i));
}
}
if ($hasDeviceError) {
throw new InvalidRecipientException("Device identifier error status", $recipients);
}
} | php | private function checkMessageResult($message, \ArrayIterator $recipients)
{
$hasDeviceError = false;
$recipientCount = $recipients->count();
for ($i = 0; $i <= $recipientCount; $i++) {
if (isset($message->results[$i]['registration_id'])) {
$hasDeviceError = true;
$recipients->offsetGet($i)->setIdentifierToReplaceTo($message->results[$i]['registration_id']);
}
if (isset($message->results[$i]['error'])) {
$hasDeviceError = true;
$error = $message->results[$i]['error'];
$this->processError($error, $recipients->offsetGet($i));
}
}
if ($hasDeviceError) {
throw new InvalidRecipientException("Device identifier error status", $recipients);
}
} | [
"private",
"function",
"checkMessageResult",
"(",
"$",
"message",
",",
"\\",
"ArrayIterator",
"$",
"recipients",
")",
"{",
"$",
"hasDeviceError",
"=",
"false",
";",
"$",
"recipientCount",
"=",
"$",
"recipients",
"->",
"count",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"$",
"recipientCount",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"message",
"->",
"results",
"[",
"$",
"i",
"]",
"[",
"'registration_id'",
"]",
")",
")",
"{",
"$",
"hasDeviceError",
"=",
"true",
";",
"$",
"recipients",
"->",
"offsetGet",
"(",
"$",
"i",
")",
"->",
"setIdentifierToReplaceTo",
"(",
"$",
"message",
"->",
"results",
"[",
"$",
"i",
"]",
"[",
"'registration_id'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"message",
"->",
"results",
"[",
"$",
"i",
"]",
"[",
"'error'",
"]",
")",
")",
"{",
"$",
"hasDeviceError",
"=",
"true",
";",
"$",
"error",
"=",
"$",
"message",
"->",
"results",
"[",
"$",
"i",
"]",
"[",
"'error'",
"]",
";",
"$",
"this",
"->",
"processError",
"(",
"$",
"error",
",",
"$",
"recipients",
"->",
"offsetGet",
"(",
"$",
"i",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"hasDeviceError",
")",
"{",
"throw",
"new",
"InvalidRecipientException",
"(",
"\"Device identifier error status\"",
",",
"$",
"recipients",
")",
";",
"}",
"}"
] | Check message result
@param \stdClass $message
@param \ArrayIterator $recipients | [
"Check",
"message",
"result"
] | 47da2d0577b18ac709cd947c68541014001e1866 | https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/NotificationService/GCM/Response.php#L134-L156 | train |
diasbruno/stc | lib/stc/Config.php | Config.getOptional | public function getOptional($key, $defaultValue = null)
{
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
}
return $defaultValue;
} | php | public function getOptional($key, $defaultValue = null)
{
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
}
return $defaultValue;
} | [
"public",
"function",
"getOptional",
"(",
"$",
"key",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"defaultValue",
";",
"}"
] | Use this method for optional values.
@param $key string | The key name.
@return object | [
"Use",
"this",
"method",
"for",
"optional",
"values",
"."
] | 43f62c3b28167bff76274f954e235413a9e9c707 | https://github.com/diasbruno/stc/blob/43f62c3b28167bff76274f954e235413a9e9c707/lib/stc/Config.php#L82-L88 | train |
bruno-barros/w.eloquent-framework | src/weloquent/Providers/OptimizeServiceProvider.php | OptimizeServiceProvider.registerOptimizeCommand | protected function registerOptimizeCommand()
{
$this->app->bindShared('command.optimize', function($app)
{
return new \Weloquent\Core\Console\OptimizeCommand($app['composer']);
});
} | php | protected function registerOptimizeCommand()
{
$this->app->bindShared('command.optimize', function($app)
{
return new \Weloquent\Core\Console\OptimizeCommand($app['composer']);
});
} | [
"protected",
"function",
"registerOptimizeCommand",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bindShared",
"(",
"'command.optimize'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Weloquent",
"\\",
"Core",
"\\",
"Console",
"\\",
"OptimizeCommand",
"(",
"$",
"app",
"[",
"'composer'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Register the optimize command.
@return void | [
"Register",
"the",
"optimize",
"command",
"."
] | d252dcb1ba1b6b1cecf67877d7d6d3ba57ebedbd | https://github.com/bruno-barros/w.eloquent-framework/blob/d252dcb1ba1b6b1cecf67877d7d6d3ba57ebedbd/src/weloquent/Providers/OptimizeServiceProvider.php#L35-L41 | train |
PhoxPHP/Glider | src/Events/EventManager.php | EventManager.listenTo | public static function listenTo(String $eventId, $callback)
{
if (!in_array(gettype($callback), ['array', 'object', 'closure'])) {
return false;
}
EventManager::$listeners[$eventId][] = $callback;
} | php | public static function listenTo(String $eventId, $callback)
{
if (!in_array(gettype($callback), ['array', 'object', 'closure'])) {
return false;
}
EventManager::$listeners[$eventId][] = $callback;
} | [
"public",
"static",
"function",
"listenTo",
"(",
"String",
"$",
"eventId",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"gettype",
"(",
"$",
"callback",
")",
",",
"[",
"'array'",
",",
"'object'",
",",
"'closure'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"EventManager",
"::",
"$",
"listeners",
"[",
"$",
"eventId",
"]",
"[",
"]",
"=",
"$",
"callback",
";",
"}"
] | Creates a new listener. Two parameters are required. The eventId that will be used
to track the current event and the callback which can be either an array or a closure.
@param $eventId <String>
@param $callback <Mixed>
@access public
@static
@return <void> | [
"Creates",
"a",
"new",
"listener",
".",
"Two",
"parameters",
"are",
"required",
".",
"The",
"eventId",
"that",
"will",
"be",
"used",
"to",
"track",
"the",
"current",
"event",
"and",
"the",
"callback",
"which",
"can",
"be",
"either",
"an",
"array",
"or",
"a",
"closure",
"."
] | 17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042 | https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Events/EventManager.php#L75-L82 | train |
PhoxPHP/Glider | src/Events/EventManager.php | EventManager.attachSubscriber | public function attachSubscriber(Subscriber $subscriber)
{
$listeners = $subscriber->getRegisteredEvents();
foreach($listeners as $id => $listener) {
EventManager::listenTo($id, array($subscriber, $listener));
}
} | php | public function attachSubscriber(Subscriber $subscriber)
{
$listeners = $subscriber->getRegisteredEvents();
foreach($listeners as $id => $listener) {
EventManager::listenTo($id, array($subscriber, $listener));
}
} | [
"public",
"function",
"attachSubscriber",
"(",
"Subscriber",
"$",
"subscriber",
")",
"{",
"$",
"listeners",
"=",
"$",
"subscriber",
"->",
"getRegisteredEvents",
"(",
")",
";",
"foreach",
"(",
"$",
"listeners",
"as",
"$",
"id",
"=>",
"$",
"listener",
")",
"{",
"EventManager",
"::",
"listenTo",
"(",
"$",
"id",
",",
"array",
"(",
"$",
"subscriber",
",",
"$",
"listener",
")",
")",
";",
"}",
"}"
] | This method attaches an event through it's subscribe object. List of events
are loaded from the subscriber and added to the listeners.
@param $subscriber <Kit\Glider\Events\Contract\Subcriber>
@access public
@return <void> | [
"This",
"method",
"attaches",
"an",
"event",
"through",
"it",
"s",
"subscribe",
"object",
".",
"List",
"of",
"events",
"are",
"loaded",
"from",
"the",
"subscriber",
"and",
"added",
"to",
"the",
"listeners",
"."
] | 17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042 | https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Events/EventManager.php#L109-L115 | train |
eloquent/endec | src/Endec.php | Endec.registerFilters | public static function registerFilters(Isolator $isolator = null)
{
$isolator = Isolator::get($isolator);
$isolator->stream_filter_register(
'endec.base16-encode',
'Eloquent\Endec\Base16\Base16EncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base16-decode',
'Eloquent\Endec\Base16\Base16DecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base32-encode',
'Eloquent\Endec\Base32\Base32EncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base32-decode',
'Eloquent\Endec\Base32\Base32DecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base32hex-encode',
'Eloquent\Endec\Base32\Base32HexEncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base32hex-decode',
'Eloquent\Endec\Base32\Base32HexDecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64-encode',
'Eloquent\Endec\Base64\Base64EncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64-decode',
'Eloquent\Endec\Base64\Base64DecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64mime-encode',
'Eloquent\Endec\Base64\Base64MimeEncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64mime-decode',
'Eloquent\Endec\Base64\Base64MimeDecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64url-encode',
'Eloquent\Endec\Base64\Base64UrlEncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64url-decode',
'Eloquent\Endec\Base64\Base64UrlDecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.uri-encode',
'Eloquent\Endec\Uri\UriEncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.uri-decode',
'Eloquent\Endec\Uri\UriDecodeNativeStreamFilter'
);
} | php | public static function registerFilters(Isolator $isolator = null)
{
$isolator = Isolator::get($isolator);
$isolator->stream_filter_register(
'endec.base16-encode',
'Eloquent\Endec\Base16\Base16EncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base16-decode',
'Eloquent\Endec\Base16\Base16DecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base32-encode',
'Eloquent\Endec\Base32\Base32EncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base32-decode',
'Eloquent\Endec\Base32\Base32DecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base32hex-encode',
'Eloquent\Endec\Base32\Base32HexEncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base32hex-decode',
'Eloquent\Endec\Base32\Base32HexDecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64-encode',
'Eloquent\Endec\Base64\Base64EncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64-decode',
'Eloquent\Endec\Base64\Base64DecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64mime-encode',
'Eloquent\Endec\Base64\Base64MimeEncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64mime-decode',
'Eloquent\Endec\Base64\Base64MimeDecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64url-encode',
'Eloquent\Endec\Base64\Base64UrlEncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.base64url-decode',
'Eloquent\Endec\Base64\Base64UrlDecodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.uri-encode',
'Eloquent\Endec\Uri\UriEncodeNativeStreamFilter'
);
$isolator->stream_filter_register(
'endec.uri-decode',
'Eloquent\Endec\Uri\UriDecodeNativeStreamFilter'
);
} | [
"public",
"static",
"function",
"registerFilters",
"(",
"Isolator",
"$",
"isolator",
"=",
"null",
")",
"{",
"$",
"isolator",
"=",
"Isolator",
"::",
"get",
"(",
"$",
"isolator",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base16-encode'",
",",
"'Eloquent\\Endec\\Base16\\Base16EncodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base16-decode'",
",",
"'Eloquent\\Endec\\Base16\\Base16DecodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base32-encode'",
",",
"'Eloquent\\Endec\\Base32\\Base32EncodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base32-decode'",
",",
"'Eloquent\\Endec\\Base32\\Base32DecodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base32hex-encode'",
",",
"'Eloquent\\Endec\\Base32\\Base32HexEncodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base32hex-decode'",
",",
"'Eloquent\\Endec\\Base32\\Base32HexDecodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base64-encode'",
",",
"'Eloquent\\Endec\\Base64\\Base64EncodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base64-decode'",
",",
"'Eloquent\\Endec\\Base64\\Base64DecodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base64mime-encode'",
",",
"'Eloquent\\Endec\\Base64\\Base64MimeEncodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base64mime-decode'",
",",
"'Eloquent\\Endec\\Base64\\Base64MimeDecodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base64url-encode'",
",",
"'Eloquent\\Endec\\Base64\\Base64UrlEncodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.base64url-decode'",
",",
"'Eloquent\\Endec\\Base64\\Base64UrlDecodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.uri-encode'",
",",
"'Eloquent\\Endec\\Uri\\UriEncodeNativeStreamFilter'",
")",
";",
"$",
"isolator",
"->",
"stream_filter_register",
"(",
"'endec.uri-decode'",
",",
"'Eloquent\\Endec\\Uri\\UriDecodeNativeStreamFilter'",
")",
";",
"}"
] | Register Endec's native stream filters.
@param Isolator|null $isolator The isolator to use. | [
"Register",
"Endec",
"s",
"native",
"stream",
"filters",
"."
] | 90043a26439739d6bac631cc57dab3ecf5cafdc3 | https://github.com/eloquent/endec/blob/90043a26439739d6bac631cc57dab3ecf5cafdc3/src/Endec.php#L26-L86 | train |
kmfk/slowdb | src/Collection.php | Collection.get | public function get($key)
{
$position = $this->getPosition($key);
if (false !== $position) {
return [$key => $this->file->read($position)];
}
return false;
} | php | public function get($key)
{
$position = $this->getPosition($key);
if (false !== $position) {
return [$key => $this->file->read($position)];
}
return false;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"getPosition",
"(",
"$",
"key",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"position",
")",
"{",
"return",
"[",
"$",
"key",
"=>",
"$",
"this",
"->",
"file",
"->",
"read",
"(",
"$",
"position",
")",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Retrieves the value based on the key
@param mixed $key The key to fetch data for
@return array | [
"Retrieves",
"the",
"value",
"based",
"on",
"the",
"key"
] | 7461771b8ddc0c9887e2ee69a76ff5ffc763974c | https://github.com/kmfk/slowdb/blob/7461771b8ddc0c9887e2ee69a76ff5ffc763974c/src/Collection.php#L83-L91 | train |
kmfk/slowdb | src/Collection.php | Collection.query | public function query($match)
{
$keys = $this->index->getKeys();
$matches = array_filter($keys, function($key) use ($match) {
return preg_match("/{$match}/i", $key);
});
$results = [];
foreach ($matches as $match) {
$result = $this->get($match);
$results[key($result)] = current($result);
}
return $results;
} | php | public function query($match)
{
$keys = $this->index->getKeys();
$matches = array_filter($keys, function($key) use ($match) {
return preg_match("/{$match}/i", $key);
});
$results = [];
foreach ($matches as $match) {
$result = $this->get($match);
$results[key($result)] = current($result);
}
return $results;
} | [
"public",
"function",
"query",
"(",
"$",
"match",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"index",
"->",
"getKeys",
"(",
")",
";",
"$",
"matches",
"=",
"array_filter",
"(",
"$",
"keys",
",",
"function",
"(",
"$",
"key",
")",
"use",
"(",
"$",
"match",
")",
"{",
"return",
"preg_match",
"(",
"\"/{$match}/i\"",
",",
"$",
"key",
")",
";",
"}",
")",
";",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"match",
")",
";",
"$",
"results",
"[",
"key",
"(",
"$",
"result",
")",
"]",
"=",
"current",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Queries for Keys matching a case insensitive expression
@param string $match The expression to match against
@return array | [
"Queries",
"for",
"Keys",
"matching",
"a",
"case",
"insensitive",
"expression"
] | 7461771b8ddc0c9887e2ee69a76ff5ffc763974c | https://github.com/kmfk/slowdb/blob/7461771b8ddc0c9887e2ee69a76ff5ffc763974c/src/Collection.php#L130-L144 | train |
kmfk/slowdb | src/Collection.php | Collection.remove | public function remove($key)
{
$position = $this->getPosition($key);
if (false !== $position) {
$this->file->remove($position);
$this->rebuildIndex();
return true;
}
return false;
} | php | public function remove($key)
{
$position = $this->getPosition($key);
if (false !== $position) {
$this->file->remove($position);
$this->rebuildIndex();
return true;
}
return false;
} | [
"public",
"function",
"remove",
"(",
"$",
"key",
")",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"getPosition",
"(",
"$",
"key",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"position",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"remove",
"(",
"$",
"position",
")",
";",
"$",
"this",
"->",
"rebuildIndex",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Remove a Value based on its Key
@param mixed $key The key to remove
@return bool | [
"Remove",
"a",
"Value",
"based",
"on",
"its",
"Key"
] | 7461771b8ddc0c9887e2ee69a76ff5ffc763974c | https://github.com/kmfk/slowdb/blob/7461771b8ddc0c9887e2ee69a76ff5ffc763974c/src/Collection.php#L175-L186 | train |
kmfk/slowdb | src/Collection.php | Collection.drop | public function drop()
{
$filepath = $this->file->getFilePath();
unset($this->file);
if (!file_exists($filepath)) {
unlink($filepath);
}
return true;
} | php | public function drop()
{
$filepath = $this->file->getFilePath();
unset($this->file);
if (!file_exists($filepath)) {
unlink($filepath);
}
return true;
} | [
"public",
"function",
"drop",
"(",
")",
"{",
"$",
"filepath",
"=",
"$",
"this",
"->",
"file",
"->",
"getFilePath",
"(",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"file",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filepath",
")",
")",
"{",
"unlink",
"(",
"$",
"filepath",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Removes the Collection database file
@return bool | [
"Removes",
"the",
"Collection",
"database",
"file"
] | 7461771b8ddc0c9887e2ee69a76ff5ffc763974c | https://github.com/kmfk/slowdb/blob/7461771b8ddc0c9887e2ee69a76ff5ffc763974c/src/Collection.php#L206-L217 | train |
wdbo/webdocbook | src/WebDocBook/FrontController.php | FrontController.boot | protected function boot()
{
try {
Kernel::boot();
// Kernel::debug();
// the actual manifest
if (true===file_exists(Kernel::getPath('app_manifest_filepath'))) {
$manifest_data = FilesystemHelper::parseJson(Kernel::getPath('app_manifest_filepath'));
if ($manifest_data) {
Kernel::setConfig($manifest_data, 'manifest');
} else {
throw new \Exception(
sprintf('Can not parse app manifest "%s" JSON content!', Kernel::getPath('app_manifest_filepath', true))
);
}
} else {
throw new \Exception(
sprintf('App manifest "%s" not found or is empty!', Kernel::getPath('app_manifest_filepath', true))
);
}
} catch (\Exception $e) {
// hard die for startup errors
header('Content-Type: text/plain');
echo PHP_EOL.'[WebDocBook startup error] : '.PHP_EOL;
echo PHP_EOL."\t".$e->getMessage().PHP_EOL;
echo PHP_EOL.'-------------------------'.PHP_EOL;
echo 'For more info, see the documentation online at <http://webdocbook.com/>.'.PHP_EOL;
exit(1);
}
} | php | protected function boot()
{
try {
Kernel::boot();
// Kernel::debug();
// the actual manifest
if (true===file_exists(Kernel::getPath('app_manifest_filepath'))) {
$manifest_data = FilesystemHelper::parseJson(Kernel::getPath('app_manifest_filepath'));
if ($manifest_data) {
Kernel::setConfig($manifest_data, 'manifest');
} else {
throw new \Exception(
sprintf('Can not parse app manifest "%s" JSON content!', Kernel::getPath('app_manifest_filepath', true))
);
}
} else {
throw new \Exception(
sprintf('App manifest "%s" not found or is empty!', Kernel::getPath('app_manifest_filepath', true))
);
}
} catch (\Exception $e) {
// hard die for startup errors
header('Content-Type: text/plain');
echo PHP_EOL.'[WebDocBook startup error] : '.PHP_EOL;
echo PHP_EOL."\t".$e->getMessage().PHP_EOL;
echo PHP_EOL.'-------------------------'.PHP_EOL;
echo 'For more info, see the documentation online at <http://webdocbook.com/>.'.PHP_EOL;
exit(1);
}
} | [
"protected",
"function",
"boot",
"(",
")",
"{",
"try",
"{",
"Kernel",
"::",
"boot",
"(",
")",
";",
"// Kernel::debug();",
"// the actual manifest",
"if",
"(",
"true",
"===",
"file_exists",
"(",
"Kernel",
"::",
"getPath",
"(",
"'app_manifest_filepath'",
")",
")",
")",
"{",
"$",
"manifest_data",
"=",
"FilesystemHelper",
"::",
"parseJson",
"(",
"Kernel",
"::",
"getPath",
"(",
"'app_manifest_filepath'",
")",
")",
";",
"if",
"(",
"$",
"manifest_data",
")",
"{",
"Kernel",
"::",
"setConfig",
"(",
"$",
"manifest_data",
",",
"'manifest'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Can not parse app manifest \"%s\" JSON content!'",
",",
"Kernel",
"::",
"getPath",
"(",
"'app_manifest_filepath'",
",",
"true",
")",
")",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'App manifest \"%s\" not found or is empty!'",
",",
"Kernel",
"::",
"getPath",
"(",
"'app_manifest_filepath'",
",",
"true",
")",
")",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// hard die for startup errors",
"header",
"(",
"'Content-Type: text/plain'",
")",
";",
"echo",
"PHP_EOL",
".",
"'[WebDocBook startup error] : '",
".",
"PHP_EOL",
";",
"echo",
"PHP_EOL",
".",
"\"\\t\"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"PHP_EOL",
";",
"echo",
"PHP_EOL",
".",
"'-------------------------'",
".",
"PHP_EOL",
";",
"echo",
"'For more info, see the documentation online at <http://webdocbook.com/>.'",
".",
"PHP_EOL",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | This must boot the system
If an error occurred, a message is written "as is" on screen
and the run stops here.
@return void
@see \WebDocBook\Kernel::boot() | [
"This",
"must",
"boot",
"the",
"system"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/FrontController.php#L94-L125 | train |
wdbo/webdocbook | src/WebDocBook/FrontController.php | FrontController.distribute | public function distribute($return = false)
{
$this->processSessionValues();
try {
$routing = $this->request
->parseWDBRequest()
->getWDBRouting();
} catch (NotFoundException $e) {
throw $e;
}
$this->processQueryArguments();
$input_file = $this->getInputFile();
if (empty($input_file)) {
$input_path = $this->getInputPath();
if (!empty($input_path)) {
$input_file = Kernel::getPath('web').trim($input_path, '/');
}
}
$result = null;
if (!empty($routing)) {
$ctrl_cls = $routing['controller_classname'];
/* @var \WebDocBook\Abstracts\AbstractController $ctrl_obj */
$ctrl_obj = new $ctrl_cls();
$this->setController($ctrl_obj);
$result = Helper::fetchArguments(
$this->getController(), $routing['action'], array('path'=>$input_file)
);
}
if (empty($result) || !is_array($result) || (count($result)!=2 && count($result)!=3)) {
$str = gettype($result);
if (is_array($result)) {
$str .= ' length '.count($result);
}
throw new RuntimeException(
sprintf('A controller action must return a two or three entries array like [ template file , content (, params) ]! Received %s from class "%s::%s()".',
$str, $routing['controller_classname'], $routing['action'])
);
} else {
$template = $result[0];
$content = $result[1];
$params = isset($result[2]) ? $result[2] : array();
}
// debug if so
if (!empty($_GET) && isset($_GET['debug'])) {
Kernel::debug($this);
}
$this->display($content, $template, $params, true);
} | php | public function distribute($return = false)
{
$this->processSessionValues();
try {
$routing = $this->request
->parseWDBRequest()
->getWDBRouting();
} catch (NotFoundException $e) {
throw $e;
}
$this->processQueryArguments();
$input_file = $this->getInputFile();
if (empty($input_file)) {
$input_path = $this->getInputPath();
if (!empty($input_path)) {
$input_file = Kernel::getPath('web').trim($input_path, '/');
}
}
$result = null;
if (!empty($routing)) {
$ctrl_cls = $routing['controller_classname'];
/* @var \WebDocBook\Abstracts\AbstractController $ctrl_obj */
$ctrl_obj = new $ctrl_cls();
$this->setController($ctrl_obj);
$result = Helper::fetchArguments(
$this->getController(), $routing['action'], array('path'=>$input_file)
);
}
if (empty($result) || !is_array($result) || (count($result)!=2 && count($result)!=3)) {
$str = gettype($result);
if (is_array($result)) {
$str .= ' length '.count($result);
}
throw new RuntimeException(
sprintf('A controller action must return a two or three entries array like [ template file , content (, params) ]! Received %s from class "%s::%s()".',
$str, $routing['controller_classname'], $routing['action'])
);
} else {
$template = $result[0];
$content = $result[1];
$params = isset($result[2]) ? $result[2] : array();
}
// debug if so
if (!empty($_GET) && isset($_GET['debug'])) {
Kernel::debug($this);
}
$this->display($content, $template, $params, true);
} | [
"public",
"function",
"distribute",
"(",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"processSessionValues",
"(",
")",
";",
"try",
"{",
"$",
"routing",
"=",
"$",
"this",
"->",
"request",
"->",
"parseWDBRequest",
"(",
")",
"->",
"getWDBRouting",
"(",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"processQueryArguments",
"(",
")",
";",
"$",
"input_file",
"=",
"$",
"this",
"->",
"getInputFile",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"input_file",
")",
")",
"{",
"$",
"input_path",
"=",
"$",
"this",
"->",
"getInputPath",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"input_path",
")",
")",
"{",
"$",
"input_file",
"=",
"Kernel",
"::",
"getPath",
"(",
"'web'",
")",
".",
"trim",
"(",
"$",
"input_path",
",",
"'/'",
")",
";",
"}",
"}",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"routing",
")",
")",
"{",
"$",
"ctrl_cls",
"=",
"$",
"routing",
"[",
"'controller_classname'",
"]",
";",
"/* @var \\WebDocBook\\Abstracts\\AbstractController $ctrl_obj */",
"$",
"ctrl_obj",
"=",
"new",
"$",
"ctrl_cls",
"(",
")",
";",
"$",
"this",
"->",
"setController",
"(",
"$",
"ctrl_obj",
")",
";",
"$",
"result",
"=",
"Helper",
"::",
"fetchArguments",
"(",
"$",
"this",
"->",
"getController",
"(",
")",
",",
"$",
"routing",
"[",
"'action'",
"]",
",",
"array",
"(",
"'path'",
"=>",
"$",
"input_file",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
"||",
"!",
"is_array",
"(",
"$",
"result",
")",
"||",
"(",
"count",
"(",
"$",
"result",
")",
"!=",
"2",
"&&",
"count",
"(",
"$",
"result",
")",
"!=",
"3",
")",
")",
"{",
"$",
"str",
"=",
"gettype",
"(",
"$",
"result",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
")",
"{",
"$",
"str",
".=",
"' length '",
".",
"count",
"(",
"$",
"result",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'A controller action must return a two or three entries array like [ template file , content (, params) ]! Received %s from class \"%s::%s()\".'",
",",
"$",
"str",
",",
"$",
"routing",
"[",
"'controller_classname'",
"]",
",",
"$",
"routing",
"[",
"'action'",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"template",
"=",
"$",
"result",
"[",
"0",
"]",
";",
"$",
"content",
"=",
"$",
"result",
"[",
"1",
"]",
";",
"$",
"params",
"=",
"isset",
"(",
"$",
"result",
"[",
"2",
"]",
")",
"?",
"$",
"result",
"[",
"2",
"]",
":",
"array",
"(",
")",
";",
"}",
"// debug if so",
"if",
"(",
"!",
"empty",
"(",
"$",
"_GET",
")",
"&&",
"isset",
"(",
"$",
"_GET",
"[",
"'debug'",
"]",
")",
")",
"{",
"Kernel",
"::",
"debug",
"(",
"$",
"this",
")",
";",
"}",
"$",
"this",
"->",
"display",
"(",
"$",
"content",
",",
"$",
"template",
",",
"$",
"params",
",",
"true",
")",
";",
"}"
] | This will distribute the request and return the response
@param bool $return
@throws \WebDocBook\Exception\NotFoundException
@throws \WebDocBook\Exception\RuntimeException if the controller action does not return a valid array
@return void | [
"This",
"will",
"distribute",
"the",
"request",
"and",
"return",
"the",
"response"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/FrontController.php#L238-L290 | train |
stonedz/pff2 | src/modules/encryption/Encryption.php | Encryption.decrypt | public function decrypt($crypttext, $key = null) {
if(null !== $key) {
$this->_key = md5($key);
}
$crypttext = base64_decode($crypttext);
$plaintext = '';
$td = mcrypt_module_open($this->_cypher, '', self::MODE, '');
$ivsize = mcrypt_enc_get_iv_size($td);
$iv = substr($crypttext, 0, $ivsize);
$crypttext = substr($crypttext, $ivsize);
if ($iv) {
mcrypt_generic_init($td, $this->_key, $iv);
$plaintext = mdecrypt_generic($td, $crypttext);
}
return trim($plaintext);
} | php | public function decrypt($crypttext, $key = null) {
if(null !== $key) {
$this->_key = md5($key);
}
$crypttext = base64_decode($crypttext);
$plaintext = '';
$td = mcrypt_module_open($this->_cypher, '', self::MODE, '');
$ivsize = mcrypt_enc_get_iv_size($td);
$iv = substr($crypttext, 0, $ivsize);
$crypttext = substr($crypttext, $ivsize);
if ($iv) {
mcrypt_generic_init($td, $this->_key, $iv);
$plaintext = mdecrypt_generic($td, $crypttext);
}
return trim($plaintext);
} | [
"public",
"function",
"decrypt",
"(",
"$",
"crypttext",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"_key",
"=",
"md5",
"(",
"$",
"key",
")",
";",
"}",
"$",
"crypttext",
"=",
"base64_decode",
"(",
"$",
"crypttext",
")",
";",
"$",
"plaintext",
"=",
"''",
";",
"$",
"td",
"=",
"mcrypt_module_open",
"(",
"$",
"this",
"->",
"_cypher",
",",
"''",
",",
"self",
"::",
"MODE",
",",
"''",
")",
";",
"$",
"ivsize",
"=",
"mcrypt_enc_get_iv_size",
"(",
"$",
"td",
")",
";",
"$",
"iv",
"=",
"substr",
"(",
"$",
"crypttext",
",",
"0",
",",
"$",
"ivsize",
")",
";",
"$",
"crypttext",
"=",
"substr",
"(",
"$",
"crypttext",
",",
"$",
"ivsize",
")",
";",
"if",
"(",
"$",
"iv",
")",
"{",
"mcrypt_generic_init",
"(",
"$",
"td",
",",
"$",
"this",
"->",
"_key",
",",
"$",
"iv",
")",
";",
"$",
"plaintext",
"=",
"mdecrypt_generic",
"(",
"$",
"td",
",",
"$",
"crypttext",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"plaintext",
")",
";",
"}"
] | Decrypt a previously encrypted text
@param string $crypttext
@param null|string $key User specified key
@return string | [
"Decrypt",
"a",
"previously",
"encrypted",
"text"
] | ec3b087d4d4732816f61ac487f0cb25511e0da88 | https://github.com/stonedz/pff2/blob/ec3b087d4d4732816f61ac487f0cb25511e0da88/src/modules/encryption/Encryption.php#L70-L86 | train |
zbox/UnifiedPush | src/Zbox/UnifiedPush/NotificationService/ServiceClientFactory.php | ServiceClientFactory.getServiceURL | public function getServiceURL($serviceName, $isFeedback = false)
{
$serviceName = NotificationServices::validateServiceName($serviceName);
$serviceType = $isFeedback ? self::FEEDBACK_SERVICE : self::PUSH_SERVICE;
$environment = $this->getEnvironment();
$serviceConfig = $this->getServiceConfig();
if (empty($serviceConfig[$serviceName][$serviceType][static::ENVIRONMENT_DEVELOPMENT])) {
$environment = static::ENVIRONMENT_PRODUCTION;
}
if (empty($serviceConfig[$serviceName][$serviceType][$environment])) {
throw new DomainException("Service url is not defined");
}
return $serviceConfig[$serviceName][$serviceType][$environment];
} | php | public function getServiceURL($serviceName, $isFeedback = false)
{
$serviceName = NotificationServices::validateServiceName($serviceName);
$serviceType = $isFeedback ? self::FEEDBACK_SERVICE : self::PUSH_SERVICE;
$environment = $this->getEnvironment();
$serviceConfig = $this->getServiceConfig();
if (empty($serviceConfig[$serviceName][$serviceType][static::ENVIRONMENT_DEVELOPMENT])) {
$environment = static::ENVIRONMENT_PRODUCTION;
}
if (empty($serviceConfig[$serviceName][$serviceType][$environment])) {
throw new DomainException("Service url is not defined");
}
return $serviceConfig[$serviceName][$serviceType][$environment];
} | [
"public",
"function",
"getServiceURL",
"(",
"$",
"serviceName",
",",
"$",
"isFeedback",
"=",
"false",
")",
"{",
"$",
"serviceName",
"=",
"NotificationServices",
"::",
"validateServiceName",
"(",
"$",
"serviceName",
")",
";",
"$",
"serviceType",
"=",
"$",
"isFeedback",
"?",
"self",
"::",
"FEEDBACK_SERVICE",
":",
"self",
"::",
"PUSH_SERVICE",
";",
"$",
"environment",
"=",
"$",
"this",
"->",
"getEnvironment",
"(",
")",
";",
"$",
"serviceConfig",
"=",
"$",
"this",
"->",
"getServiceConfig",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"serviceConfig",
"[",
"$",
"serviceName",
"]",
"[",
"$",
"serviceType",
"]",
"[",
"static",
"::",
"ENVIRONMENT_DEVELOPMENT",
"]",
")",
")",
"{",
"$",
"environment",
"=",
"static",
"::",
"ENVIRONMENT_PRODUCTION",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"serviceConfig",
"[",
"$",
"serviceName",
"]",
"[",
"$",
"serviceType",
"]",
"[",
"$",
"environment",
"]",
")",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"\"Service url is not defined\"",
")",
";",
"}",
"return",
"$",
"serviceConfig",
"[",
"$",
"serviceName",
"]",
"[",
"$",
"serviceType",
"]",
"[",
"$",
"environment",
"]",
";",
"}"
] | Gets notification service url by service name
@param string $serviceName
@param bool $isFeedback
@return array | [
"Gets",
"notification",
"service",
"url",
"by",
"service",
"name"
] | 47da2d0577b18ac709cd947c68541014001e1866 | https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/NotificationService/ServiceClientFactory.php#L148-L165 | train |
zbox/UnifiedPush | src/Zbox/UnifiedPush/NotificationService/ServiceClientFactory.php | ServiceClientFactory.createServiceClient | public function createServiceClient($serviceName, $isFeedback = false)
{
$serviceUrl = $this->getServiceURL($serviceName, $isFeedback);
$clientClass = sprintf(
'Zbox\UnifiedPush\NotificationService\%s\%s',
$serviceName,
$isFeedback ? 'ServiceFeedbackClient' : 'ServiceClient'
);
$credentials = $this->credentialsFactory->getCredentialsByService($serviceName);
$clientConnection = new $clientClass($serviceUrl, $credentials);
return $clientConnection;
} | php | public function createServiceClient($serviceName, $isFeedback = false)
{
$serviceUrl = $this->getServiceURL($serviceName, $isFeedback);
$clientClass = sprintf(
'Zbox\UnifiedPush\NotificationService\%s\%s',
$serviceName,
$isFeedback ? 'ServiceFeedbackClient' : 'ServiceClient'
);
$credentials = $this->credentialsFactory->getCredentialsByService($serviceName);
$clientConnection = new $clientClass($serviceUrl, $credentials);
return $clientConnection;
} | [
"public",
"function",
"createServiceClient",
"(",
"$",
"serviceName",
",",
"$",
"isFeedback",
"=",
"false",
")",
"{",
"$",
"serviceUrl",
"=",
"$",
"this",
"->",
"getServiceURL",
"(",
"$",
"serviceName",
",",
"$",
"isFeedback",
")",
";",
"$",
"clientClass",
"=",
"sprintf",
"(",
"'Zbox\\UnifiedPush\\NotificationService\\%s\\%s'",
",",
"$",
"serviceName",
",",
"$",
"isFeedback",
"?",
"'ServiceFeedbackClient'",
":",
"'ServiceClient'",
")",
";",
"$",
"credentials",
"=",
"$",
"this",
"->",
"credentialsFactory",
"->",
"getCredentialsByService",
"(",
"$",
"serviceName",
")",
";",
"$",
"clientConnection",
"=",
"new",
"$",
"clientClass",
"(",
"$",
"serviceUrl",
",",
"$",
"credentials",
")",
";",
"return",
"$",
"clientConnection",
";",
"}"
] | Creates client server connection by service name and sender credentials
@param string $serviceName
@param bool $isFeedback
@return ServiceClientInterface | [
"Creates",
"client",
"server",
"connection",
"by",
"service",
"name",
"and",
"sender",
"credentials"
] | 47da2d0577b18ac709cd947c68541014001e1866 | https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/NotificationService/ServiceClientFactory.php#L174-L188 | train |
zbox/UnifiedPush | src/Zbox/UnifiedPush/NotificationService/ServiceClientFactory.php | ServiceClientFactory.loadServicesConfig | public function loadServicesConfig()
{
$configPath = $this->serviceConfigPath;
if (!file_exists($configPath)) {
throw new InvalidArgumentException(
sprintf(
"Service config file '%s' doesn`t exists",
$configPath
)
);
}
$config = json_decode(file_get_contents($configPath), true);
if (!is_array($config)) {
throw new RuntimeException('Empty credentials config');
}
$this->serviceConfig = $config;
return $this;
} | php | public function loadServicesConfig()
{
$configPath = $this->serviceConfigPath;
if (!file_exists($configPath)) {
throw new InvalidArgumentException(
sprintf(
"Service config file '%s' doesn`t exists",
$configPath
)
);
}
$config = json_decode(file_get_contents($configPath), true);
if (!is_array($config)) {
throw new RuntimeException('Empty credentials config');
}
$this->serviceConfig = $config;
return $this;
} | [
"public",
"function",
"loadServicesConfig",
"(",
")",
"{",
"$",
"configPath",
"=",
"$",
"this",
"->",
"serviceConfigPath",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"configPath",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Service config file '%s' doesn`t exists\"",
",",
"$",
"configPath",
")",
")",
";",
"}",
"$",
"config",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"configPath",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Empty credentials config'",
")",
";",
"}",
"$",
"this",
"->",
"serviceConfig",
"=",
"$",
"config",
";",
"return",
"$",
"this",
";",
"}"
] | Load notification services connection data
@return $this | [
"Load",
"notification",
"services",
"connection",
"data"
] | 47da2d0577b18ac709cd947c68541014001e1866 | https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/NotificationService/ServiceClientFactory.php#L195-L217 | train |
newestindustry/ginger-rest | src/Ginger/Format.php | Format.getFormatByAcceptHeader | public static function getFormatByAcceptHeader($header)
{
if(isset(self::$mimeMapper[$header])) {
return self::$mimeMapper[$header];
} else {
return self::$format;
}
} | php | public static function getFormatByAcceptHeader($header)
{
if(isset(self::$mimeMapper[$header])) {
return self::$mimeMapper[$header];
} else {
return self::$format;
}
} | [
"public",
"static",
"function",
"getFormatByAcceptHeader",
"(",
"$",
"header",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"mimeMapper",
"[",
"$",
"header",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"mimeMapper",
"[",
"$",
"header",
"]",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"$",
"format",
";",
"}",
"}"
] | getFormatByAcceptHeader function.
@access public
@static
@param mixed $header
@return void | [
"getFormatByAcceptHeader",
"function",
"."
] | 482b77dc122a60ab0bf143a3c4a1e67168985c83 | https://github.com/newestindustry/ginger-rest/blob/482b77dc122a60ab0bf143a3c4a1e67168985c83/src/Ginger/Format.php#L89-L96 | train |
hermajan/dobine | src/Connections/Environment.php | Environment.load | public static function load(string $filename) {
if(class_exists(Dotenv::class)) {
$dotenv = new Dotenv($filename);
$dotenv->load();
}
} | php | public static function load(string $filename) {
if(class_exists(Dotenv::class)) {
$dotenv = new Dotenv($filename);
$dotenv->load();
}
} | [
"public",
"static",
"function",
"load",
"(",
"string",
"$",
"filename",
")",
"{",
"if",
"(",
"class_exists",
"(",
"Dotenv",
"::",
"class",
")",
")",
"{",
"$",
"dotenv",
"=",
"new",
"Dotenv",
"(",
"$",
"filename",
")",
";",
"$",
"dotenv",
"->",
"load",
"(",
")",
";",
"}",
"}"
] | Loads environment variables.
@param string $filename Path to the .env file. | [
"Loads",
"environment",
"variables",
"."
] | 0f18727923cfe06abbbfcd1d39b897633586ad05 | https://github.com/hermajan/dobine/blob/0f18727923cfe06abbbfcd1d39b897633586ad05/src/Connections/Environment.php#L15-L20 | train |
hermajan/dobine | src/Connections/Environment.php | Environment.choose | public static function choose($environment = null) {
if (!isset($environment)) {
if(isset($_ENV["APP_ENV"])) {
switch($_ENV["APP_ENV"]) {
case "dev": case "development": default:
$environment = Environment::DEVELOPMENT; break;
case "stage":
$environment = Environment::STAGE; break;
case "prod": case "production":
$environment = Environment::PRODUCTION; break;
}
} else {
switch($_SERVER["SERVER_NAME"]) {
case "localhost":
$environment = Environment::DEVELOPMENT; break;
default:
$environment = Environment::PRODUCTION; break;
}
}
} else {
$environment = Environment::DEVELOPMENT;
}
return $environment;
} | php | public static function choose($environment = null) {
if (!isset($environment)) {
if(isset($_ENV["APP_ENV"])) {
switch($_ENV["APP_ENV"]) {
case "dev": case "development": default:
$environment = Environment::DEVELOPMENT; break;
case "stage":
$environment = Environment::STAGE; break;
case "prod": case "production":
$environment = Environment::PRODUCTION; break;
}
} else {
switch($_SERVER["SERVER_NAME"]) {
case "localhost":
$environment = Environment::DEVELOPMENT; break;
default:
$environment = Environment::PRODUCTION; break;
}
}
} else {
$environment = Environment::DEVELOPMENT;
}
return $environment;
} | [
"public",
"static",
"function",
"choose",
"(",
"$",
"environment",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"environment",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_ENV",
"[",
"\"APP_ENV\"",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"_ENV",
"[",
"\"APP_ENV\"",
"]",
")",
"{",
"case",
"\"dev\"",
":",
"case",
"\"development\"",
":",
"default",
":",
"$",
"environment",
"=",
"Environment",
"::",
"DEVELOPMENT",
";",
"break",
";",
"case",
"\"stage\"",
":",
"$",
"environment",
"=",
"Environment",
"::",
"STAGE",
";",
"break",
";",
"case",
"\"prod\"",
":",
"case",
"\"production\"",
":",
"$",
"environment",
"=",
"Environment",
"::",
"PRODUCTION",
";",
"break",
";",
"}",
"}",
"else",
"{",
"switch",
"(",
"$",
"_SERVER",
"[",
"\"SERVER_NAME\"",
"]",
")",
"{",
"case",
"\"localhost\"",
":",
"$",
"environment",
"=",
"Environment",
"::",
"DEVELOPMENT",
";",
"break",
";",
"default",
":",
"$",
"environment",
"=",
"Environment",
"::",
"PRODUCTION",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"environment",
"=",
"Environment",
"::",
"DEVELOPMENT",
";",
"}",
"return",
"$",
"environment",
";",
"}"
] | Chooses environment.
@param null|string $environment
@return string | [
"Chooses",
"environment",
"."
] | 0f18727923cfe06abbbfcd1d39b897633586ad05 | https://github.com/hermajan/dobine/blob/0f18727923cfe06abbbfcd1d39b897633586ad05/src/Connections/Environment.php#L27-L51 | train |
villermen/runescape-lookup-commons | src/ActivityFeed/ActivityFeed.php | ActivityFeed.getItemsAfter | public function getItemsAfter(ActivityFeedItem $targetItem): array
{
$newerItems = [];
foreach($this->getItems() as $item) {
if ($item->equals($targetItem)) {
break;
}
$newerItems[] = $item;
}
return $newerItems;
} | php | public function getItemsAfter(ActivityFeedItem $targetItem): array
{
$newerItems = [];
foreach($this->getItems() as $item) {
if ($item->equals($targetItem)) {
break;
}
$newerItems[] = $item;
}
return $newerItems;
} | [
"public",
"function",
"getItemsAfter",
"(",
"ActivityFeedItem",
"$",
"targetItem",
")",
":",
"array",
"{",
"$",
"newerItems",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getItems",
"(",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"equals",
"(",
"$",
"targetItem",
")",
")",
"{",
"break",
";",
"}",
"$",
"newerItems",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"$",
"newerItems",
";",
"}"
] | Returns all feed items in this feed that occur after the given item.
@param ActivityFeedItem $targetItem
@return ActivityFeedItem[] | [
"Returns",
"all",
"feed",
"items",
"in",
"this",
"feed",
"that",
"occur",
"after",
"the",
"given",
"item",
"."
] | 3e24dadbdc5e20b755280e5110f4ca0a1758b04c | https://github.com/villermen/runescape-lookup-commons/blob/3e24dadbdc5e20b755280e5110f4ca0a1758b04c/src/ActivityFeed/ActivityFeed.php#L32-L45 | train |
villermen/runescape-lookup-commons | src/ActivityFeed/ActivityFeed.php | ActivityFeed.merge | public function merge(ActivityFeed $newerFeed): ActivityFeed
{
if (count($this->getItems()) > 0) {
$prepend = $newerFeed->getItemsAfter($this->getItems()[0]);
} else {
$prepend = $newerFeed->getItems();
}
return new ActivityFeed(array_merge($prepend, $this->getItems()));
} | php | public function merge(ActivityFeed $newerFeed): ActivityFeed
{
if (count($this->getItems()) > 0) {
$prepend = $newerFeed->getItemsAfter($this->getItems()[0]);
} else {
$prepend = $newerFeed->getItems();
}
return new ActivityFeed(array_merge($prepend, $this->getItems()));
} | [
"public",
"function",
"merge",
"(",
"ActivityFeed",
"$",
"newerFeed",
")",
":",
"ActivityFeed",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"getItems",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"prepend",
"=",
"$",
"newerFeed",
"->",
"getItemsAfter",
"(",
"$",
"this",
"->",
"getItems",
"(",
")",
"[",
"0",
"]",
")",
";",
"}",
"else",
"{",
"$",
"prepend",
"=",
"$",
"newerFeed",
"->",
"getItems",
"(",
")",
";",
"}",
"return",
"new",
"ActivityFeed",
"(",
"array_merge",
"(",
"$",
"prepend",
",",
"$",
"this",
"->",
"getItems",
"(",
")",
")",
")",
";",
"}"
] | Merges this ActivityFeed with a newer feed.
Returns a new feed with all new items from the newerFeed prepended to it.
@param ActivityFeed $newerFeed
@return ActivityFeed | [
"Merges",
"this",
"ActivityFeed",
"with",
"a",
"newer",
"feed",
".",
"Returns",
"a",
"new",
"feed",
"with",
"all",
"new",
"items",
"from",
"the",
"newerFeed",
"prepended",
"to",
"it",
"."
] | 3e24dadbdc5e20b755280e5110f4ca0a1758b04c | https://github.com/villermen/runescape-lookup-commons/blob/3e24dadbdc5e20b755280e5110f4ca0a1758b04c/src/ActivityFeed/ActivityFeed.php#L54-L63 | train |
apishka/easy-extend | source/Broker.php | Broker.getRouter | public function getRouter(string $router): RouterAbstract
{
if (!array_key_exists($router, $this->_routers))
$this->_routers[$router] = $this->getItem($router);
return $this->_routers[$router];
} | php | public function getRouter(string $router): RouterAbstract
{
if (!array_key_exists($router, $this->_routers))
$this->_routers[$router] = $this->getItem($router);
return $this->_routers[$router];
} | [
"public",
"function",
"getRouter",
"(",
"string",
"$",
"router",
")",
":",
"RouterAbstract",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"router",
",",
"$",
"this",
"->",
"_routers",
")",
")",
"$",
"this",
"->",
"_routers",
"[",
"$",
"router",
"]",
"=",
"$",
"this",
"->",
"getItem",
"(",
"$",
"router",
")",
";",
"return",
"$",
"this",
"->",
"_routers",
"[",
"$",
"router",
"]",
";",
"}"
] | Get router instance
@param string $router
@return RouterAbstract | [
"Get",
"router",
"instance"
] | 5e5c63c2509377abc3db6956e353623683703e09 | https://github.com/apishka/easy-extend/blob/5e5c63c2509377abc3db6956e353623683703e09/source/Broker.php#L60-L66 | train |
apishka/easy-extend | source/Broker.php | Broker.isCorrectItem | protected function isCorrectItem(\ReflectionClass $reflector): bool
{
if ($reflector->isInstance($this))
return false;
if (!$reflector->isSubclassOf(RouterAbstract::class))
return false;
return true;
} | php | protected function isCorrectItem(\ReflectionClass $reflector): bool
{
if ($reflector->isInstance($this))
return false;
if (!$reflector->isSubclassOf(RouterAbstract::class))
return false;
return true;
} | [
"protected",
"function",
"isCorrectItem",
"(",
"\\",
"ReflectionClass",
"$",
"reflector",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"reflector",
"->",
"isInstance",
"(",
"$",
"this",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"$",
"reflector",
"->",
"isSubclassOf",
"(",
"RouterAbstract",
"::",
"class",
")",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] | Is correct item
@param \ReflectionClass $reflector
@return bool | [
"Is",
"correct",
"item"
] | 5e5c63c2509377abc3db6956e353623683703e09 | https://github.com/apishka/easy-extend/blob/5e5c63c2509377abc3db6956e353623683703e09/source/Broker.php#L97-L106 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager.generalServiceManager | public static function generalServiceManager(Iterable $serviceConfig = NULL, $selfRefNames= []) {
if(!static::$serviceManager) {
if(is_null($serviceConfig))
throw new ServiceException(sprintf("First call of %s must pass a service configuration", __METHOD__), 13);
/** @var ServiceManager $man */
$man = static::$serviceManager = new static($serviceConfig);
$man->selfReferenceNames = array_merge($man->selfReferenceNames, $selfRefNames);
if($n = self::getGlobalVariableName())
$GLOBALS[$n] = $man;
}
return static::$serviceManager;
} | php | public static function generalServiceManager(Iterable $serviceConfig = NULL, $selfRefNames= []) {
if(!static::$serviceManager) {
if(is_null($serviceConfig))
throw new ServiceException(sprintf("First call of %s must pass a service configuration", __METHOD__), 13);
/** @var ServiceManager $man */
$man = static::$serviceManager = new static($serviceConfig);
$man->selfReferenceNames = array_merge($man->selfReferenceNames, $selfRefNames);
if($n = self::getGlobalVariableName())
$GLOBALS[$n] = $man;
}
return static::$serviceManager;
} | [
"public",
"static",
"function",
"generalServiceManager",
"(",
"Iterable",
"$",
"serviceConfig",
"=",
"NULL",
",",
"$",
"selfRefNames",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"serviceManager",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"serviceConfig",
")",
")",
"throw",
"new",
"ServiceException",
"(",
"sprintf",
"(",
"\"First call of %s must pass a service configuration\"",
",",
"__METHOD__",
")",
",",
"13",
")",
";",
"/** @var ServiceManager $man */",
"$",
"man",
"=",
"static",
"::",
"$",
"serviceManager",
"=",
"new",
"static",
"(",
"$",
"serviceConfig",
")",
";",
"$",
"man",
"->",
"selfReferenceNames",
"=",
"array_merge",
"(",
"$",
"man",
"->",
"selfReferenceNames",
",",
"$",
"selfRefNames",
")",
";",
"if",
"(",
"$",
"n",
"=",
"self",
"::",
"getGlobalVariableName",
"(",
")",
")",
"$",
"GLOBALS",
"[",
"$",
"n",
"]",
"=",
"$",
"man",
";",
"}",
"return",
"static",
"::",
"$",
"serviceManager",
";",
"}"
] | Returns the service manager. The first call of this method should pass a service config info.
@param iterable|NULL $serviceConfig
@return ServiceManager | [
"Returns",
"the",
"service",
"manager",
".",
"The",
"first",
"call",
"of",
"this",
"method",
"should",
"pass",
"a",
"service",
"config",
"info",
"."
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L72-L85 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager.get | public function get($serviceName) {
$container = $this->serviceData[$serviceName] ?? NULL;
if($container) {
return $container->getInstance();
}
if(in_array($serviceName, $this->getSelfReferenceNames()))
return $this;
$e = new UnknownServiceException("Service $serviceName is not registered", E_USER_ERROR);
$e->setServiceName($serviceName);
throw $e;
} | php | public function get($serviceName) {
$container = $this->serviceData[$serviceName] ?? NULL;
if($container) {
return $container->getInstance();
}
if(in_array($serviceName, $this->getSelfReferenceNames()))
return $this;
$e = new UnknownServiceException("Service $serviceName is not registered", E_USER_ERROR);
$e->setServiceName($serviceName);
throw $e;
} | [
"public",
"function",
"get",
"(",
"$",
"serviceName",
")",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"serviceData",
"[",
"$",
"serviceName",
"]",
"??",
"NULL",
";",
"if",
"(",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"->",
"getInstance",
"(",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"serviceName",
",",
"$",
"this",
"->",
"getSelfReferenceNames",
"(",
")",
")",
")",
"return",
"$",
"this",
";",
"$",
"e",
"=",
"new",
"UnknownServiceException",
"(",
"\"Service $serviceName is not registered\"",
",",
"E_USER_ERROR",
")",
";",
"$",
"e",
"->",
"setServiceName",
"(",
"$",
"serviceName",
")",
";",
"throw",
"$",
"e",
";",
"}"
] | Returns the instance of a requested service
This method call fails if the service does not exist or something else went wrong during creating the service instance.
@param string $serviceName
@return object|null
@throws UnknownServiceException | [
"Returns",
"the",
"instance",
"of",
"a",
"requested",
"service",
"This",
"method",
"call",
"fails",
"if",
"the",
"service",
"does",
"not",
"exist",
"or",
"something",
"else",
"went",
"wrong",
"during",
"creating",
"the",
"service",
"instance",
"."
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L187-L199 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager.set | public function set(string $serviceName, $object) {
if(isset($this->serviceData[$serviceName]) || in_array($serviceName, $this->getSelfReferenceNames())) {
if($this->replaceExistingServices()) {
trigger_error("Service $serviceName is already registered", E_USER_NOTICE);
} else {
$e = new ServiceException("Service $serviceName is already registered");
$e->setServiceName($serviceName);
throw $e;
}
}
if(is_callable($object)) {
$object = new CallbackContainer($object);
} elseif (is_array($object)) {
$object = new ConfiguredServiceContainer($serviceName, $object, $this);
} elseif(!is_object($object)) {
throw new ServiceException("Service Manager only allows objects to be service instances!");
} elseif(!($object instanceof ContainerInterface)) {
$object = new StaticContainer($object);
}
$this->serviceData[$serviceName] = $object;
} | php | public function set(string $serviceName, $object) {
if(isset($this->serviceData[$serviceName]) || in_array($serviceName, $this->getSelfReferenceNames())) {
if($this->replaceExistingServices()) {
trigger_error("Service $serviceName is already registered", E_USER_NOTICE);
} else {
$e = new ServiceException("Service $serviceName is already registered");
$e->setServiceName($serviceName);
throw $e;
}
}
if(is_callable($object)) {
$object = new CallbackContainer($object);
} elseif (is_array($object)) {
$object = new ConfiguredServiceContainer($serviceName, $object, $this);
} elseif(!is_object($object)) {
throw new ServiceException("Service Manager only allows objects to be service instances!");
} elseif(!($object instanceof ContainerInterface)) {
$object = new StaticContainer($object);
}
$this->serviceData[$serviceName] = $object;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"serviceName",
",",
"$",
"object",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"serviceData",
"[",
"$",
"serviceName",
"]",
")",
"||",
"in_array",
"(",
"$",
"serviceName",
",",
"$",
"this",
"->",
"getSelfReferenceNames",
"(",
")",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"replaceExistingServices",
"(",
")",
")",
"{",
"trigger_error",
"(",
"\"Service $serviceName is already registered\"",
",",
"E_USER_NOTICE",
")",
";",
"}",
"else",
"{",
"$",
"e",
"=",
"new",
"ServiceException",
"(",
"\"Service $serviceName is already registered\"",
")",
";",
"$",
"e",
"->",
"setServiceName",
"(",
"$",
"serviceName",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"object",
")",
")",
"{",
"$",
"object",
"=",
"new",
"CallbackContainer",
"(",
"$",
"object",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"object",
")",
")",
"{",
"$",
"object",
"=",
"new",
"ConfiguredServiceContainer",
"(",
"$",
"serviceName",
",",
"$",
"object",
",",
"$",
"this",
")",
";",
"}",
"elseif",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"ServiceException",
"(",
"\"Service Manager only allows objects to be service instances!\"",
")",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"object",
"instanceof",
"ContainerInterface",
")",
")",
"{",
"$",
"object",
"=",
"new",
"StaticContainer",
"(",
"$",
"object",
")",
";",
"}",
"$",
"this",
"->",
"serviceData",
"[",
"$",
"serviceName",
"]",
"=",
"$",
"object",
";",
"}"
] | Sets a service
Accepted are:
- Objects that implement ContainerInterface, their getInstance method call will be the service instance
- A callback (note! Objects implementing __invoke are also callbacks!) to obtain the service instance
- An array to load configured service
- Any other object directly as service
If replaceExistingServices() returns false, this method call fails with an already registered service.
@param string $serviceName
@param object|callable|ContainerInterface $object
@throws ServiceException
@see ServiceManager::replaceExistingServices()
@see ServiceManager::__get() | [
"Sets",
"a",
"service"
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L231-L254 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager.serviceExists | public function serviceExists(string $serviceName): bool {
return isset($this->serviceData[$serviceName]) || in_array($serviceName, $this->getSelfReferenceNames()) ? true : false;
} | php | public function serviceExists(string $serviceName): bool {
return isset($this->serviceData[$serviceName]) || in_array($serviceName, $this->getSelfReferenceNames()) ? true : false;
} | [
"public",
"function",
"serviceExists",
"(",
"string",
"$",
"serviceName",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"serviceData",
"[",
"$",
"serviceName",
"]",
")",
"||",
"in_array",
"(",
"$",
"serviceName",
",",
"$",
"this",
"->",
"getSelfReferenceNames",
"(",
")",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Looks, if a service with the given name is available
@param string $serviceName
@return bool | [
"Looks",
"if",
"a",
"service",
"with",
"the",
"given",
"name",
"is",
"available"
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L261-L263 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager.isServiceLoaded | public function isServiceLoaded(string $serviceName): bool {
if($this->serviceExists($serviceName)) {
if(in_array($serviceName, $this->getSelfReferenceNames()))
return true;
/** @var ContainerInterface $container */
$container = $this->serviceData[$serviceName];
return $container->isInstanceLoaded();
}
return false;
} | php | public function isServiceLoaded(string $serviceName): bool {
if($this->serviceExists($serviceName)) {
if(in_array($serviceName, $this->getSelfReferenceNames()))
return true;
/** @var ContainerInterface $container */
$container = $this->serviceData[$serviceName];
return $container->isInstanceLoaded();
}
return false;
} | [
"public",
"function",
"isServiceLoaded",
"(",
"string",
"$",
"serviceName",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"serviceExists",
"(",
"$",
"serviceName",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"serviceName",
",",
"$",
"this",
"->",
"getSelfReferenceNames",
"(",
")",
")",
")",
"return",
"true",
";",
"/** @var ContainerInterface $container */",
"$",
"container",
"=",
"$",
"this",
"->",
"serviceData",
"[",
"$",
"serviceName",
"]",
";",
"return",
"$",
"container",
"->",
"isInstanceLoaded",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Looks, if a service with the given name is available and already is loaded.
@param string $serviceName
@return bool
@see ServiceManager::serviceExists() | [
"Looks",
"if",
"a",
"service",
"with",
"the",
"given",
"name",
"is",
"available",
"and",
"already",
"is",
"loaded",
"."
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L271-L281 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager._getMapValueHandler | private function _getMapValueHandler() {
return function($key, $value) {
foreach($this->customArgumentHandler as $name => $callable) {
if(is_callable($callable)) {
$value = $callable($key, $value);
} else
trigger_error("Custom argument handler $name is not callable", E_USER_WARNING);
}
return $value;
};
} | php | private function _getMapValueHandler() {
return function($key, $value) {
foreach($this->customArgumentHandler as $name => $callable) {
if(is_callable($callable)) {
$value = $callable($key, $value);
} else
trigger_error("Custom argument handler $name is not callable", E_USER_WARNING);
}
return $value;
};
} | [
"private",
"function",
"_getMapValueHandler",
"(",
")",
"{",
"return",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"customArgumentHandler",
"as",
"$",
"name",
"=>",
"$",
"callable",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"callable",
")",
")",
"{",
"$",
"value",
"=",
"$",
"callable",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"else",
"trigger_error",
"(",
"\"Custom argument handler $name is not callable\"",
",",
"E_USER_WARNING",
")",
";",
"}",
"return",
"$",
"value",
";",
"}",
";",
"}"
] | Creates the replacement handler for parameters and service instances
@return \Closure | [
"Creates",
"the",
"replacement",
"handler",
"for",
"parameters",
"and",
"service",
"instances"
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L403-L413 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager.makeServiceInstance | public function makeServiceInstance(string $className, $arguments = NULL, $configuration = NULL) {
$instance = NULL;
$implInterfaces = class_implements($className);
if(in_array(ConstructorAwareServiceInterface::class, $implInterfaces)) {
/** @var ConstructorAwareServiceInterface $className */
if($args = $className::getConstructorArguments()) {
$newArguments = [];
foreach($args as $argName => $argValue) {
$newArguments[] = is_null($argValue) ? ($arguments[$argName] ?? NULL) : $argValue;
}
$arguments = $newArguments;
}
}
if($arguments)
$arguments = $this->mapArray( AbstractCollection::makeArray($arguments), true);
if(in_array(StaticConstructorServiceInterface::class, $implInterfaces)) {
$instance = new $className($arguments, $this);
} elseif (in_array(DynamicConstructorServiceInterface::class, $implInterfaces)) {
$sig = SignatureService::getSignatureService()->getMethodSignature($className, "__construct");
$args = [];
foreach($sig as $name => $type) {
}
$instance = new $className(...$args);
} else {
$instance = $arguments ? new $className(...array_values($arguments)) : new $className();
}
if($configuration && method_exists($instance, 'setConfiguration')) {
$configuration = $this->mapArray( $configuration );
$instance->setConfiguration($configuration);
}
return $instance;
} | php | public function makeServiceInstance(string $className, $arguments = NULL, $configuration = NULL) {
$instance = NULL;
$implInterfaces = class_implements($className);
if(in_array(ConstructorAwareServiceInterface::class, $implInterfaces)) {
/** @var ConstructorAwareServiceInterface $className */
if($args = $className::getConstructorArguments()) {
$newArguments = [];
foreach($args as $argName => $argValue) {
$newArguments[] = is_null($argValue) ? ($arguments[$argName] ?? NULL) : $argValue;
}
$arguments = $newArguments;
}
}
if($arguments)
$arguments = $this->mapArray( AbstractCollection::makeArray($arguments), true);
if(in_array(StaticConstructorServiceInterface::class, $implInterfaces)) {
$instance = new $className($arguments, $this);
} elseif (in_array(DynamicConstructorServiceInterface::class, $implInterfaces)) {
$sig = SignatureService::getSignatureService()->getMethodSignature($className, "__construct");
$args = [];
foreach($sig as $name => $type) {
}
$instance = new $className(...$args);
} else {
$instance = $arguments ? new $className(...array_values($arguments)) : new $className();
}
if($configuration && method_exists($instance, 'setConfiguration')) {
$configuration = $this->mapArray( $configuration );
$instance->setConfiguration($configuration);
}
return $instance;
} | [
"public",
"function",
"makeServiceInstance",
"(",
"string",
"$",
"className",
",",
"$",
"arguments",
"=",
"NULL",
",",
"$",
"configuration",
"=",
"NULL",
")",
"{",
"$",
"instance",
"=",
"NULL",
";",
"$",
"implInterfaces",
"=",
"class_implements",
"(",
"$",
"className",
")",
";",
"if",
"(",
"in_array",
"(",
"ConstructorAwareServiceInterface",
"::",
"class",
",",
"$",
"implInterfaces",
")",
")",
"{",
"/** @var ConstructorAwareServiceInterface $className */",
"if",
"(",
"$",
"args",
"=",
"$",
"className",
"::",
"getConstructorArguments",
"(",
")",
")",
"{",
"$",
"newArguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"argName",
"=>",
"$",
"argValue",
")",
"{",
"$",
"newArguments",
"[",
"]",
"=",
"is_null",
"(",
"$",
"argValue",
")",
"?",
"(",
"$",
"arguments",
"[",
"$",
"argName",
"]",
"??",
"NULL",
")",
":",
"$",
"argValue",
";",
"}",
"$",
"arguments",
"=",
"$",
"newArguments",
";",
"}",
"}",
"if",
"(",
"$",
"arguments",
")",
"$",
"arguments",
"=",
"$",
"this",
"->",
"mapArray",
"(",
"AbstractCollection",
"::",
"makeArray",
"(",
"$",
"arguments",
")",
",",
"true",
")",
";",
"if",
"(",
"in_array",
"(",
"StaticConstructorServiceInterface",
"::",
"class",
",",
"$",
"implInterfaces",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
"$",
"arguments",
",",
"$",
"this",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"DynamicConstructorServiceInterface",
"::",
"class",
",",
"$",
"implInterfaces",
")",
")",
"{",
"$",
"sig",
"=",
"SignatureService",
"::",
"getSignatureService",
"(",
")",
"->",
"getMethodSignature",
"(",
"$",
"className",
",",
"\"__construct\"",
")",
";",
"$",
"args",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sig",
"as",
"$",
"name",
"=>",
"$",
"type",
")",
"{",
"}",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
"...",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"instance",
"=",
"$",
"arguments",
"?",
"new",
"$",
"className",
"(",
"...",
"array_values",
"(",
"$",
"arguments",
")",
")",
":",
"new",
"$",
"className",
"(",
")",
";",
"}",
"if",
"(",
"$",
"configuration",
"&&",
"method_exists",
"(",
"$",
"instance",
",",
"'setConfiguration'",
")",
")",
"{",
"$",
"configuration",
"=",
"$",
"this",
"->",
"mapArray",
"(",
"$",
"configuration",
")",
";",
"$",
"instance",
"->",
"setConfiguration",
"(",
"$",
"configuration",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | This method should be used to create service instances. It will check implementations and create it the requested manner.
@param string $className
@param array|iterable|null $arguments
@param array|iterable|null $configuration
@return object|null | [
"This",
"method",
"should",
"be",
"used",
"to",
"create",
"service",
"instances",
".",
"It",
"will",
"check",
"implementations",
"and",
"create",
"it",
"the",
"requested",
"manner",
"."
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L423-L462 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager.getServiceClass | public function getServiceClass(string $serviceName, bool $forced = true): ?string {
if(!isset($this->serviceClassNames[$serviceName])) {
if($this->serviceExists($serviceName)) {
/** @var ContainerInterface $container */
$container = $this->serviceData[$serviceName];
if($container->isInstanceLoaded()) {
$this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
goto finish;
}
if($container instanceof ServiceAwareContainerInterface) {
$this->serviceClassNames[$serviceName] = $container->getServiceClass();
goto finish;
} elseif($container instanceof ConfiguredServiceContainer) {
$cfg = $container->getConfiguration();
// In case of a direct instance fonciguration, get this classname
if($cn = $cfg[AbstractFileConfiguration::SERVICE_CLASS] ?? NULL) {
$this->serviceClassNames[$serviceName] = $cn;
goto finish;
} elseif($cn = $cfg[AbstractFileConfiguration::CONFIG_SERVICE_TYPE_KEY] ?? NULL) {
// If the developer defined the class by configuration in case of container or file initialisation, use this.
$this->serviceClassNames[$serviceName] = $cn;
goto finish;
}
}
// If nothing worked before, finally load the instance
if($forced)
$this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
} else {
// Mark as not existing
$this->serviceClassNames[$serviceName] = false;
}
}
finish:
return $this->serviceClassNames[$serviceName] ?: NULL;
} | php | public function getServiceClass(string $serviceName, bool $forced = true): ?string {
if(!isset($this->serviceClassNames[$serviceName])) {
if($this->serviceExists($serviceName)) {
/** @var ContainerInterface $container */
$container = $this->serviceData[$serviceName];
if($container->isInstanceLoaded()) {
$this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
goto finish;
}
if($container instanceof ServiceAwareContainerInterface) {
$this->serviceClassNames[$serviceName] = $container->getServiceClass();
goto finish;
} elseif($container instanceof ConfiguredServiceContainer) {
$cfg = $container->getConfiguration();
// In case of a direct instance fonciguration, get this classname
if($cn = $cfg[AbstractFileConfiguration::SERVICE_CLASS] ?? NULL) {
$this->serviceClassNames[$serviceName] = $cn;
goto finish;
} elseif($cn = $cfg[AbstractFileConfiguration::CONFIG_SERVICE_TYPE_KEY] ?? NULL) {
// If the developer defined the class by configuration in case of container or file initialisation, use this.
$this->serviceClassNames[$serviceName] = $cn;
goto finish;
}
}
// If nothing worked before, finally load the instance
if($forced)
$this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
} else {
// Mark as not existing
$this->serviceClassNames[$serviceName] = false;
}
}
finish:
return $this->serviceClassNames[$serviceName] ?: NULL;
} | [
"public",
"function",
"getServiceClass",
"(",
"string",
"$",
"serviceName",
",",
"bool",
"$",
"forced",
"=",
"true",
")",
":",
"?",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"serviceClassNames",
"[",
"$",
"serviceName",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"serviceExists",
"(",
"$",
"serviceName",
")",
")",
"{",
"/** @var ContainerInterface $container */",
"$",
"container",
"=",
"$",
"this",
"->",
"serviceData",
"[",
"$",
"serviceName",
"]",
";",
"if",
"(",
"$",
"container",
"->",
"isInstanceLoaded",
"(",
")",
")",
"{",
"$",
"this",
"->",
"serviceClassNames",
"[",
"$",
"serviceName",
"]",
"=",
"get_class",
"(",
"$",
"container",
"->",
"getInstance",
"(",
")",
")",
";",
"goto",
"finish",
";",
"}",
"if",
"(",
"$",
"container",
"instanceof",
"ServiceAwareContainerInterface",
")",
"{",
"$",
"this",
"->",
"serviceClassNames",
"[",
"$",
"serviceName",
"]",
"=",
"$",
"container",
"->",
"getServiceClass",
"(",
")",
";",
"goto",
"finish",
";",
"}",
"elseif",
"(",
"$",
"container",
"instanceof",
"ConfiguredServiceContainer",
")",
"{",
"$",
"cfg",
"=",
"$",
"container",
"->",
"getConfiguration",
"(",
")",
";",
"// In case of a direct instance fonciguration, get this classname",
"if",
"(",
"$",
"cn",
"=",
"$",
"cfg",
"[",
"AbstractFileConfiguration",
"::",
"SERVICE_CLASS",
"]",
"??",
"NULL",
")",
"{",
"$",
"this",
"->",
"serviceClassNames",
"[",
"$",
"serviceName",
"]",
"=",
"$",
"cn",
";",
"goto",
"finish",
";",
"}",
"elseif",
"(",
"$",
"cn",
"=",
"$",
"cfg",
"[",
"AbstractFileConfiguration",
"::",
"CONFIG_SERVICE_TYPE_KEY",
"]",
"??",
"NULL",
")",
"{",
"// If the developer defined the class by configuration in case of container or file initialisation, use this.",
"$",
"this",
"->",
"serviceClassNames",
"[",
"$",
"serviceName",
"]",
"=",
"$",
"cn",
";",
"goto",
"finish",
";",
"}",
"}",
"// If nothing worked before, finally load the instance",
"if",
"(",
"$",
"forced",
")",
"$",
"this",
"->",
"serviceClassNames",
"[",
"$",
"serviceName",
"]",
"=",
"get_class",
"(",
"$",
"container",
"->",
"getInstance",
"(",
")",
")",
";",
"}",
"else",
"{",
"// Mark as not existing",
"$",
"this",
"->",
"serviceClassNames",
"[",
"$",
"serviceName",
"]",
"=",
"false",
";",
"}",
"}",
"finish",
":",
"return",
"$",
"this",
"->",
"serviceClassNames",
"[",
"$",
"serviceName",
"]",
"?",
":",
"NULL",
";",
"}"
] | Gets the class of a service instance
@param string $serviceName
@param bool $forced // If set, it will until load the service to get its class name
@return string|null | [
"Gets",
"the",
"class",
"of",
"a",
"service",
"instance"
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L487-L526 | train |
tasoftch/php-service-manager | src/ServiceManager.php | ServiceManager.yieldServices | public function yieldServices(array $serviceNames, array $classNames, bool $includeSubclasses = true, bool $forceClassDetection = true) {
$matchClass = function($className) use ($includeSubclasses, $classNames) {
if(in_array($className, $classNames))
return true;
if($includeSubclasses) {
foreach($classNames as $cn) {
if(is_subclass_of($className, $cn))
return true;
}
}
return false;
};
/**
* @var string $serviceName
* @var ContainerInterface $container
*/
foreach($this->serviceData as $serviceName => $container) {
if(in_array($serviceName, $serviceNames) || $matchClass($this->getServiceClass($serviceName, $forceClassDetection))) {
yield $serviceName => new ServicePromise(function() use($container) {return $container->getInstance();});
}
}
} | php | public function yieldServices(array $serviceNames, array $classNames, bool $includeSubclasses = true, bool $forceClassDetection = true) {
$matchClass = function($className) use ($includeSubclasses, $classNames) {
if(in_array($className, $classNames))
return true;
if($includeSubclasses) {
foreach($classNames as $cn) {
if(is_subclass_of($className, $cn))
return true;
}
}
return false;
};
/**
* @var string $serviceName
* @var ContainerInterface $container
*/
foreach($this->serviceData as $serviceName => $container) {
if(in_array($serviceName, $serviceNames) || $matchClass($this->getServiceClass($serviceName, $forceClassDetection))) {
yield $serviceName => new ServicePromise(function() use($container) {return $container->getInstance();});
}
}
} | [
"public",
"function",
"yieldServices",
"(",
"array",
"$",
"serviceNames",
",",
"array",
"$",
"classNames",
",",
"bool",
"$",
"includeSubclasses",
"=",
"true",
",",
"bool",
"$",
"forceClassDetection",
"=",
"true",
")",
"{",
"$",
"matchClass",
"=",
"function",
"(",
"$",
"className",
")",
"use",
"(",
"$",
"includeSubclasses",
",",
"$",
"classNames",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"className",
",",
"$",
"classNames",
")",
")",
"return",
"true",
";",
"if",
"(",
"$",
"includeSubclasses",
")",
"{",
"foreach",
"(",
"$",
"classNames",
"as",
"$",
"cn",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"className",
",",
"$",
"cn",
")",
")",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
";",
"/**\n * @var string $serviceName\n * @var ContainerInterface $container\n */",
"foreach",
"(",
"$",
"this",
"->",
"serviceData",
"as",
"$",
"serviceName",
"=>",
"$",
"container",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"serviceName",
",",
"$",
"serviceNames",
")",
"||",
"$",
"matchClass",
"(",
"$",
"this",
"->",
"getServiceClass",
"(",
"$",
"serviceName",
",",
"$",
"forceClassDetection",
")",
")",
")",
"{",
"yield",
"$",
"serviceName",
"=>",
"new",
"ServicePromise",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"->",
"getInstance",
"(",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] | Yields all services that match required service names or required class names.
@param array $serviceNames
@param array $classNames
@param bool $includeSubclasses
@param bool $forceClassDetection
@return \Generator | [
"Yields",
"all",
"services",
"that",
"match",
"required",
"service",
"names",
"or",
"required",
"class",
"names",
"."
] | 5f627d81457356f6c087398cd1e8f8e4f9d14822 | https://github.com/tasoftch/php-service-manager/blob/5f627d81457356f6c087398cd1e8f8e4f9d14822/src/ServiceManager.php#L538-L561 | train |
UnionOfRAD/li3_quality | extensions/command/Syntax.php | Syntax._subjects | protected function _subjects($path) {
if (is_file($path)) {
$current = new SplFileInfo($path);
return $current->getExtension() === 'php' ? array($current) : array();
}
$files = new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator($path),
function($current, $key, $iterator) {
$noDescend = array(
'.git',
'libraries',
'vendor'
);
if ($iterator->hasChildren()) {
if ($current->isDir() && in_array($current->getBasename(), $noDescend)) {
return false;
}
return true;
}
if ($current->isFile()) {
return $current->getExtension() === 'php';
}
return false;
}
);
return iterator_to_array(new RecursiveIteratorIterator($files));
} | php | protected function _subjects($path) {
if (is_file($path)) {
$current = new SplFileInfo($path);
return $current->getExtension() === 'php' ? array($current) : array();
}
$files = new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator($path),
function($current, $key, $iterator) {
$noDescend = array(
'.git',
'libraries',
'vendor'
);
if ($iterator->hasChildren()) {
if ($current->isDir() && in_array($current->getBasename(), $noDescend)) {
return false;
}
return true;
}
if ($current->isFile()) {
return $current->getExtension() === 'php';
}
return false;
}
);
return iterator_to_array(new RecursiveIteratorIterator($files));
} | [
"protected",
"function",
"_subjects",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"$",
"current",
"=",
"new",
"SplFileInfo",
"(",
"$",
"path",
")",
";",
"return",
"$",
"current",
"->",
"getExtension",
"(",
")",
"===",
"'php'",
"?",
"array",
"(",
"$",
"current",
")",
":",
"array",
"(",
")",
";",
"}",
"$",
"files",
"=",
"new",
"RecursiveCallbackFilterIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
")",
",",
"function",
"(",
"$",
"current",
",",
"$",
"key",
",",
"$",
"iterator",
")",
"{",
"$",
"noDescend",
"=",
"array",
"(",
"'.git'",
",",
"'libraries'",
",",
"'vendor'",
")",
";",
"if",
"(",
"$",
"iterator",
"->",
"hasChildren",
"(",
")",
")",
"{",
"if",
"(",
"$",
"current",
"->",
"isDir",
"(",
")",
"&&",
"in_array",
"(",
"$",
"current",
"->",
"getBasename",
"(",
")",
",",
"$",
"noDescend",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"current",
"->",
"isFile",
"(",
")",
")",
"{",
"return",
"$",
"current",
"->",
"getExtension",
"(",
")",
"===",
"'php'",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"return",
"iterator_to_array",
"(",
"new",
"RecursiveIteratorIterator",
"(",
"$",
"files",
")",
")",
";",
"}"
] | Retrieves subjects. Will return only PHP files.
@param string $path
@return array Returns an array of SplFieldInfo objects. | [
"Retrieves",
"subjects",
".",
"Will",
"return",
"only",
"PHP",
"files",
"."
] | acb72a43ae835e6d200bc0eba1a61aee610e36bf | https://github.com/UnionOfRAD/li3_quality/blob/acb72a43ae835e6d200bc0eba1a61aee610e36bf/extensions/command/Syntax.php#L150-L176 | train |
UnionOfRAD/li3_quality | extensions/command/Syntax.php | Syntax._rules | protected function _rules() {
$rules = new Rules();
$files = array(
$this->config,
Libraries::get('li3_quality', 'path') . '/config/syntax.json'
);
foreach ($files as $file) {
if (file_exists($file)) {
$this->out("Loading configuration file `{$file}`...");
$config = json_decode(file_get_contents($file), true) + array(
'name' => null,
'rules' => array(),
'options' => array()
);
break;
}
}
foreach ($config['rules'] as $ruleName) {
$class = Libraries::locate('rules.syntax', $ruleName);
$rules->add(new $class());
}
if ($config['options']) {
$rules->options($config['options']);
}
return $rules;
} | php | protected function _rules() {
$rules = new Rules();
$files = array(
$this->config,
Libraries::get('li3_quality', 'path') . '/config/syntax.json'
);
foreach ($files as $file) {
if (file_exists($file)) {
$this->out("Loading configuration file `{$file}`...");
$config = json_decode(file_get_contents($file), true) + array(
'name' => null,
'rules' => array(),
'options' => array()
);
break;
}
}
foreach ($config['rules'] as $ruleName) {
$class = Libraries::locate('rules.syntax', $ruleName);
$rules->add(new $class());
}
if ($config['options']) {
$rules->options($config['options']);
}
return $rules;
} | [
"protected",
"function",
"_rules",
"(",
")",
"{",
"$",
"rules",
"=",
"new",
"Rules",
"(",
")",
";",
"$",
"files",
"=",
"array",
"(",
"$",
"this",
"->",
"config",
",",
"Libraries",
"::",
"get",
"(",
"'li3_quality'",
",",
"'path'",
")",
".",
"'/config/syntax.json'",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"\"Loading configuration file `{$file}`...\"",
")",
";",
"$",
"config",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
",",
"true",
")",
"+",
"array",
"(",
"'name'",
"=>",
"null",
",",
"'rules'",
"=>",
"array",
"(",
")",
",",
"'options'",
"=>",
"array",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"foreach",
"(",
"$",
"config",
"[",
"'rules'",
"]",
"as",
"$",
"ruleName",
")",
"{",
"$",
"class",
"=",
"Libraries",
"::",
"locate",
"(",
"'rules.syntax'",
",",
"$",
"ruleName",
")",
";",
"$",
"rules",
"->",
"add",
"(",
"new",
"$",
"class",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
"{",
"$",
"rules",
"->",
"options",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
";",
"}",
"return",
"$",
"rules",
";",
"}"
] | Loads rules configuration.
@return object | [
"Loads",
"rules",
"configuration",
"."
] | acb72a43ae835e6d200bc0eba1a61aee610e36bf | https://github.com/UnionOfRAD/li3_quality/blob/acb72a43ae835e6d200bc0eba1a61aee610e36bf/extensions/command/Syntax.php#L183-L210 | train |
sulu/SuluSalesOrderBundle | Order/OrderDependencyManager.php | OrderDependencyManager.getWorkflows | public function getWorkflows($order)
{
$workflows = array();
$actions = array(
'confirm' => array(
'section' => $this->getName(),
'title' => 'salesorder.orders.confirm',
'event' => 'sulu.salesorder.order.confirm.clicked'
),
'edit' => array(
'section' => $this->getName(),
'title' => 'salesorder.orders.edit',
'event' => 'sulu.salesorder.order.edit.clicked'
),
'delete' => array(
'section' => $this->getName(),
'title' => 'salesorder.orders.delete',
'event' => 'sulu.salesorder.order.delete',
'parameters'=> array('id'=> $order->getId())
),
);
// define workflows by order's status
$orderStatusId = $order->getStatus()->getId();
// order is in created state
if ($orderStatusId === OrderStatus::STATUS_CREATED) {
$workflows[] = $actions['confirm'];
}
// order is confirmed
else if ($orderStatusId === OrderStatus::STATUS_CONFIRMED) {
$workflows[] = $actions['edit'];
}
// order is allowed to be deleted
if ($this->allowDelete($order)) {
$workflows[] = $actions['delete'];
}
// get workflows from dependencies
/** @var SalesDependencyClassInterface $dependency */
foreach ($this->dependencyClasses as $dependency) {
$workflows = array_merge($workflows, $dependency->getWorkflows($order));
}
return $workflows;
} | php | public function getWorkflows($order)
{
$workflows = array();
$actions = array(
'confirm' => array(
'section' => $this->getName(),
'title' => 'salesorder.orders.confirm',
'event' => 'sulu.salesorder.order.confirm.clicked'
),
'edit' => array(
'section' => $this->getName(),
'title' => 'salesorder.orders.edit',
'event' => 'sulu.salesorder.order.edit.clicked'
),
'delete' => array(
'section' => $this->getName(),
'title' => 'salesorder.orders.delete',
'event' => 'sulu.salesorder.order.delete',
'parameters'=> array('id'=> $order->getId())
),
);
// define workflows by order's status
$orderStatusId = $order->getStatus()->getId();
// order is in created state
if ($orderStatusId === OrderStatus::STATUS_CREATED) {
$workflows[] = $actions['confirm'];
}
// order is confirmed
else if ($orderStatusId === OrderStatus::STATUS_CONFIRMED) {
$workflows[] = $actions['edit'];
}
// order is allowed to be deleted
if ($this->allowDelete($order)) {
$workflows[] = $actions['delete'];
}
// get workflows from dependencies
/** @var SalesDependencyClassInterface $dependency */
foreach ($this->dependencyClasses as $dependency) {
$workflows = array_merge($workflows, $dependency->getWorkflows($order));
}
return $workflows;
} | [
"public",
"function",
"getWorkflows",
"(",
"$",
"order",
")",
"{",
"$",
"workflows",
"=",
"array",
"(",
")",
";",
"$",
"actions",
"=",
"array",
"(",
"'confirm'",
"=>",
"array",
"(",
"'section'",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'title'",
"=>",
"'salesorder.orders.confirm'",
",",
"'event'",
"=>",
"'sulu.salesorder.order.confirm.clicked'",
")",
",",
"'edit'",
"=>",
"array",
"(",
"'section'",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'title'",
"=>",
"'salesorder.orders.edit'",
",",
"'event'",
"=>",
"'sulu.salesorder.order.edit.clicked'",
")",
",",
"'delete'",
"=>",
"array",
"(",
"'section'",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'title'",
"=>",
"'salesorder.orders.delete'",
",",
"'event'",
"=>",
"'sulu.salesorder.order.delete'",
",",
"'parameters'",
"=>",
"array",
"(",
"'id'",
"=>",
"$",
"order",
"->",
"getId",
"(",
")",
")",
")",
",",
")",
";",
"// define workflows by order's status",
"$",
"orderStatusId",
"=",
"$",
"order",
"->",
"getStatus",
"(",
")",
"->",
"getId",
"(",
")",
";",
"// order is in created state",
"if",
"(",
"$",
"orderStatusId",
"===",
"OrderStatus",
"::",
"STATUS_CREATED",
")",
"{",
"$",
"workflows",
"[",
"]",
"=",
"$",
"actions",
"[",
"'confirm'",
"]",
";",
"}",
"// order is confirmed",
"else",
"if",
"(",
"$",
"orderStatusId",
"===",
"OrderStatus",
"::",
"STATUS_CONFIRMED",
")",
"{",
"$",
"workflows",
"[",
"]",
"=",
"$",
"actions",
"[",
"'edit'",
"]",
";",
"}",
"// order is allowed to be deleted",
"if",
"(",
"$",
"this",
"->",
"allowDelete",
"(",
"$",
"order",
")",
")",
"{",
"$",
"workflows",
"[",
"]",
"=",
"$",
"actions",
"[",
"'delete'",
"]",
";",
"}",
"// get workflows from dependencies",
"/** @var SalesDependencyClassInterface $dependency */",
"foreach",
"(",
"$",
"this",
"->",
"dependencyClasses",
"as",
"$",
"dependency",
")",
"{",
"$",
"workflows",
"=",
"array_merge",
"(",
"$",
"workflows",
",",
"$",
"dependency",
"->",
"getWorkflows",
"(",
"$",
"order",
")",
")",
";",
"}",
"return",
"$",
"workflows",
";",
"}"
] | returns all possible workflows for the current entity
@param Order $order
@return array | [
"returns",
"all",
"possible",
"workflows",
"for",
"the",
"current",
"entity"
] | 1de6d43e8e6d0cc1e703b687085445f50f97ecdc | https://github.com/sulu/SuluSalesOrderBundle/blob/1de6d43e8e6d0cc1e703b687085445f50f97ecdc/Order/OrderDependencyManager.php#L95-L139 | train |
ben-gibson/foursquare-venue-client | src/Factory/Venue/DetailFactory.php | DetailFactory.getCreatedAt | private function getCreatedAt(Description $description)
{
$createdAt = $description->getOptionalProperty('createdAt');
return ($createdAt !== null) ? (new \DateTimeImmutable())->setTimestamp($createdAt) : null;
} | php | private function getCreatedAt(Description $description)
{
$createdAt = $description->getOptionalProperty('createdAt');
return ($createdAt !== null) ? (new \DateTimeImmutable())->setTimestamp($createdAt) : null;
} | [
"private",
"function",
"getCreatedAt",
"(",
"Description",
"$",
"description",
")",
"{",
"$",
"createdAt",
"=",
"$",
"description",
"->",
"getOptionalProperty",
"(",
"'createdAt'",
")",
";",
"return",
"(",
"$",
"createdAt",
"!==",
"null",
")",
"?",
"(",
"new",
"\\",
"DateTimeImmutable",
"(",
")",
")",
"->",
"setTimestamp",
"(",
"$",
"createdAt",
")",
":",
"null",
";",
"}"
] | Get created at.
@param Description $description The venue details description.
@return \DateTimeImmutable|null | [
"Get",
"created",
"at",
"."
] | ce5e7c308f87d5ccc28ab8d27a9cb51bd106d969 | https://github.com/ben-gibson/foursquare-venue-client/blob/ce5e7c308f87d5ccc28ab8d27a9cb51bd106d969/src/Factory/Venue/DetailFactory.php#L60-L65 | train |
ben-gibson/foursquare-venue-client | src/Factory/Venue/DetailFactory.php | DetailFactory.getBestPhoto | private function getBestPhoto(Description $description)
{
$bestPhotoDescription = $description->getOptionalProperty('bestPhoto');
if ($bestPhotoDescription instanceof Description) {
return $this->photoFactory->create($bestPhotoDescription);
}
return null;
} | php | private function getBestPhoto(Description $description)
{
$bestPhotoDescription = $description->getOptionalProperty('bestPhoto');
if ($bestPhotoDescription instanceof Description) {
return $this->photoFactory->create($bestPhotoDescription);
}
return null;
} | [
"private",
"function",
"getBestPhoto",
"(",
"Description",
"$",
"description",
")",
"{",
"$",
"bestPhotoDescription",
"=",
"$",
"description",
"->",
"getOptionalProperty",
"(",
"'bestPhoto'",
")",
";",
"if",
"(",
"$",
"bestPhotoDescription",
"instanceof",
"Description",
")",
"{",
"return",
"$",
"this",
"->",
"photoFactory",
"->",
"create",
"(",
"$",
"bestPhotoDescription",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get best photo.
@param Description $description The venue details description.
@return Photo|null | [
"Get",
"best",
"photo",
"."
] | ce5e7c308f87d5ccc28ab8d27a9cb51bd106d969 | https://github.com/ben-gibson/foursquare-venue-client/blob/ce5e7c308f87d5ccc28ab8d27a9cb51bd106d969/src/Factory/Venue/DetailFactory.php#L74-L83 | train |
Clevis/Se34 | Se34/ElementComponent.php | ElementComponent.getRoot | private function getRoot()
{
if ($this->root === NULL)
{
$selector = reset($this->parameters);
$strategy = key($this->parameters);
if ($selector instanceof Element)
{
$this->root = $selector;
}
else
{
$this->root = $this->parent->findElement($strategy, $selector);
}
$expectedTagName = next($this->parameters);
$expectedAttributes = next($this->parameters);
if ($expectedTagName !== FALSE)
{
$actualTagName = $this->root->name();
if ($actualTagName !== $expectedTagName)
{
throw new ViewStateException("Root element of '" . get_class($this) . "' is expected to be tag '$expectedTagName', but is '$actualTagName'.");
}
}
if ($expectedAttributes !== FALSE)
{
foreach ($expectedAttributes as $attributeName => $expectedAttributeValue)
{
$actualAttributeValue = $this->root->attribute($attributeName);
if ($actualAttributeValue !== $expectedAttributeValue)
{
throw new ViewStateException("Root element's attribute '$attributeName' is expected to be '$expectedAttributeValue', but is '$actualAttributeValue'.");
}
}
}
}
return $this->root;
} | php | private function getRoot()
{
if ($this->root === NULL)
{
$selector = reset($this->parameters);
$strategy = key($this->parameters);
if ($selector instanceof Element)
{
$this->root = $selector;
}
else
{
$this->root = $this->parent->findElement($strategy, $selector);
}
$expectedTagName = next($this->parameters);
$expectedAttributes = next($this->parameters);
if ($expectedTagName !== FALSE)
{
$actualTagName = $this->root->name();
if ($actualTagName !== $expectedTagName)
{
throw new ViewStateException("Root element of '" . get_class($this) . "' is expected to be tag '$expectedTagName', but is '$actualTagName'.");
}
}
if ($expectedAttributes !== FALSE)
{
foreach ($expectedAttributes as $attributeName => $expectedAttributeValue)
{
$actualAttributeValue = $this->root->attribute($attributeName);
if ($actualAttributeValue !== $expectedAttributeValue)
{
throw new ViewStateException("Root element's attribute '$attributeName' is expected to be '$expectedAttributeValue', but is '$actualAttributeValue'.");
}
}
}
}
return $this->root;
} | [
"private",
"function",
"getRoot",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"root",
"===",
"NULL",
")",
"{",
"$",
"selector",
"=",
"reset",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"$",
"strategy",
"=",
"key",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"if",
"(",
"$",
"selector",
"instanceof",
"Element",
")",
"{",
"$",
"this",
"->",
"root",
"=",
"$",
"selector",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"root",
"=",
"$",
"this",
"->",
"parent",
"->",
"findElement",
"(",
"$",
"strategy",
",",
"$",
"selector",
")",
";",
"}",
"$",
"expectedTagName",
"=",
"next",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"$",
"expectedAttributes",
"=",
"next",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"if",
"(",
"$",
"expectedTagName",
"!==",
"FALSE",
")",
"{",
"$",
"actualTagName",
"=",
"$",
"this",
"->",
"root",
"->",
"name",
"(",
")",
";",
"if",
"(",
"$",
"actualTagName",
"!==",
"$",
"expectedTagName",
")",
"{",
"throw",
"new",
"ViewStateException",
"(",
"\"Root element of '\"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\"' is expected to be tag '$expectedTagName', but is '$actualTagName'.\"",
")",
";",
"}",
"}",
"if",
"(",
"$",
"expectedAttributes",
"!==",
"FALSE",
")",
"{",
"foreach",
"(",
"$",
"expectedAttributes",
"as",
"$",
"attributeName",
"=>",
"$",
"expectedAttributeValue",
")",
"{",
"$",
"actualAttributeValue",
"=",
"$",
"this",
"->",
"root",
"->",
"attribute",
"(",
"$",
"attributeName",
")",
";",
"if",
"(",
"$",
"actualAttributeValue",
"!==",
"$",
"expectedAttributeValue",
")",
"{",
"throw",
"new",
"ViewStateException",
"(",
"\"Root element's attribute '$attributeName' is expected to be '$expectedAttributeValue', but is '$actualAttributeValue'.\"",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"root",
";",
"}"
] | Get root element of this component.
@return Element | [
"Get",
"root",
"element",
"of",
"this",
"component",
"."
] | c52d579a831ba5642dae464882da012b0409ae46 | https://github.com/Clevis/Se34/blob/c52d579a831ba5642dae464882da012b0409ae46/Se34/ElementComponent.php#L15-L52 | train |
ScreamingDev/phpsemver | lib/PHPSemVer/Config/RuleSet/Trigger.php | Trigger.getInstances | public function getInstances()
{
if (null === $this->instances) {
$this->instances = [];
foreach ($this->getAll() as $className) {
$className = '\\PHPSemVer\\Trigger\\' . str_replace('/', '\\', $className);
$this->instances[] = new $className();
}
}
return $this->instances;
} | php | public function getInstances()
{
if (null === $this->instances) {
$this->instances = [];
foreach ($this->getAll() as $className) {
$className = '\\PHPSemVer\\Trigger\\' . str_replace('/', '\\', $className);
$this->instances[] = new $className();
}
}
return $this->instances;
} | [
"public",
"function",
"getInstances",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"instances",
")",
"{",
"$",
"this",
"->",
"instances",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getAll",
"(",
")",
"as",
"$",
"className",
")",
"{",
"$",
"className",
"=",
"'\\\\PHPSemVer\\\\Trigger\\\\'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"className",
")",
";",
"$",
"this",
"->",
"instances",
"[",
"]",
"=",
"new",
"$",
"className",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"instances",
";",
"}"
] | Get all trigger instances from the config.
@return AbstractTrigger[] | [
"Get",
"all",
"trigger",
"instances",
"from",
"the",
"config",
"."
] | 11a4bc508f71dee73d4f5fee2e9d39e7984d3e15 | https://github.com/ScreamingDev/phpsemver/blob/11a4bc508f71dee73d4f5fee2e9d39e7984d3e15/lib/PHPSemVer/Config/RuleSet/Trigger.php#L44-L57 | train |
DBRisinajumi/d2company | controllers/CcmpCompanyController.php | CcmpCompanyController.actionResetPersonPassword | public function actionResetPersonPassword($ccmp_id,$person_id)
{
//only for validation acces
$model = $this->loadModel($ccmp_id);
yii::import('vendor.dbrisinajumi.person.PersonModule');
//if do not have user, create
$m = Person::model();
$m->resetPassword($person_id);
$this->redirect(array('adminCustomers', 'ccmp_id' => $ccmp_id));
} | php | public function actionResetPersonPassword($ccmp_id,$person_id)
{
//only for validation acces
$model = $this->loadModel($ccmp_id);
yii::import('vendor.dbrisinajumi.person.PersonModule');
//if do not have user, create
$m = Person::model();
$m->resetPassword($person_id);
$this->redirect(array('adminCustomers', 'ccmp_id' => $ccmp_id));
} | [
"public",
"function",
"actionResetPersonPassword",
"(",
"$",
"ccmp_id",
",",
"$",
"person_id",
")",
"{",
"//only for validation acces",
"$",
"model",
"=",
"$",
"this",
"->",
"loadModel",
"(",
"$",
"ccmp_id",
")",
";",
"yii",
"::",
"import",
"(",
"'vendor.dbrisinajumi.person.PersonModule'",
")",
";",
"//if do not have user, create",
"$",
"m",
"=",
"Person",
"::",
"model",
"(",
")",
";",
"$",
"m",
"->",
"resetPassword",
"(",
"$",
"person_id",
")",
";",
"$",
"this",
"->",
"redirect",
"(",
"array",
"(",
"'adminCustomers'",
",",
"'ccmp_id'",
"=>",
"$",
"ccmp_id",
")",
")",
";",
"}"
] | send to user new password
@return type | [
"send",
"to",
"user",
"new",
"password"
] | 20df0db96ac2c8e73471c4bab7d487b67ef4ed0a | https://github.com/DBRisinajumi/d2company/blob/20df0db96ac2c8e73471c4bab7d487b67ef4ed0a/controllers/CcmpCompanyController.php#L759-L771 | train |
garyr/memento | lib/Memento/Client.php | Client.getKeys | private function getKeys($argv)
{
$groupKey = null;
$key = null;
if (isset($argv[0])) {
if ($argv[0] instanceof Group\Key) {
$groupKey = $argv[0];
if (isset($argv[1])) {
if ($argv[1] instanceof Key) {
$key = $argv[1];
} else {
throw new \InvalidArgumentException("must be instance of Memento_Key");
}
}
} elseif ($argv[0] instanceof Key) {
$key = $argv[0];
} else {
throw new \InvalidArgumentException("argument 1 must be instance of Memento_Group_Key or Memento_Key");
}
}
return array($key, $groupKey);
} | php | private function getKeys($argv)
{
$groupKey = null;
$key = null;
if (isset($argv[0])) {
if ($argv[0] instanceof Group\Key) {
$groupKey = $argv[0];
if (isset($argv[1])) {
if ($argv[1] instanceof Key) {
$key = $argv[1];
} else {
throw new \InvalidArgumentException("must be instance of Memento_Key");
}
}
} elseif ($argv[0] instanceof Key) {
$key = $argv[0];
} else {
throw new \InvalidArgumentException("argument 1 must be instance of Memento_Group_Key or Memento_Key");
}
}
return array($key, $groupKey);
} | [
"private",
"function",
"getKeys",
"(",
"$",
"argv",
")",
"{",
"$",
"groupKey",
"=",
"null",
";",
"$",
"key",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"argv",
"[",
"0",
"]",
")",
")",
"{",
"if",
"(",
"$",
"argv",
"[",
"0",
"]",
"instanceof",
"Group",
"\\",
"Key",
")",
"{",
"$",
"groupKey",
"=",
"$",
"argv",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"argv",
"[",
"1",
"]",
")",
")",
"{",
"if",
"(",
"$",
"argv",
"[",
"1",
"]",
"instanceof",
"Key",
")",
"{",
"$",
"key",
"=",
"$",
"argv",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"must be instance of Memento_Key\"",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"argv",
"[",
"0",
"]",
"instanceof",
"Key",
")",
"{",
"$",
"key",
"=",
"$",
"argv",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"argument 1 must be instance of Memento_Group_Key or Memento_Key\"",
")",
";",
"}",
"}",
"return",
"array",
"(",
"$",
"key",
",",
"$",
"groupKey",
")",
";",
"}"
] | Returns an array to serve as a callable param
for call_user_func_array
@param array $argv Function argument array
@param string $source Method name from which the call was made
@return arrray Returns the method target callable array | [
"Returns",
"an",
"array",
"to",
"serve",
"as",
"a",
"callable",
"param",
"for",
"call_user_func_array"
] | d6cfa9ffec040f96b8361f822f11dcf6d5ff60b4 | https://github.com/garyr/memento/blob/d6cfa9ffec040f96b8361f822f11dcf6d5ff60b4/lib/Memento/Client.php#L32-L56 | train |
Laralum/Routes | src/RoutesServiceProvider.php | RoutesServiceProvider.registerPolicies | public function registerPolicies()
{
foreach ($this->policies as $key => $value) {
Gate::policy($key, $value);
}
} | php | public function registerPolicies()
{
foreach ($this->policies as $key => $value) {
Gate::policy($key, $value);
}
} | [
"public",
"function",
"registerPolicies",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"policies",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"Gate",
"::",
"policy",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | I cheated this comes from the AuthServiceProvider extended by the App\Providers\AuthServiceProvider.
Register the application's policies.
@return void | [
"I",
"cheated",
"this",
"comes",
"from",
"the",
"AuthServiceProvider",
"extended",
"by",
"the",
"App",
"\\",
"Providers",
"\\",
"AuthServiceProvider",
"."
] | 10db617db456839c5753294d268198aa65f0a3f0 | https://github.com/Laralum/Routes/blob/10db617db456839c5753294d268198aa65f0a3f0/src/RoutesServiceProvider.php#L62-L67 | train |
ntentan/atiaa | src/Descriptor.php | Descriptor.describe | public function describe()
{
$defaultSchema = $this->driver->getDefaultSchema();
$description = [
'schemata' => [],
];
$schemata = $this->getSchemata();
foreach ($schemata as $schema) {
if ($schema['name'] == $defaultSchema) {
$description['tables'] = $this->describeTables($defaultSchema);
$description['views'] = $this->describeViews($defaultSchema);
} else {
$description['schemata'][$schema['name']]['name'] = $schema['name'];
$description['schemata'][$schema['name']]['tables'] = $this->describeTables($schema['name']);
$description['schemata'][$schema['name']]['views'] = $this->describeViews($schema['name']);
}
}
return $description;
} | php | public function describe()
{
$defaultSchema = $this->driver->getDefaultSchema();
$description = [
'schemata' => [],
];
$schemata = $this->getSchemata();
foreach ($schemata as $schema) {
if ($schema['name'] == $defaultSchema) {
$description['tables'] = $this->describeTables($defaultSchema);
$description['views'] = $this->describeViews($defaultSchema);
} else {
$description['schemata'][$schema['name']]['name'] = $schema['name'];
$description['schemata'][$schema['name']]['tables'] = $this->describeTables($schema['name']);
$description['schemata'][$schema['name']]['views'] = $this->describeViews($schema['name']);
}
}
return $description;
} | [
"public",
"function",
"describe",
"(",
")",
"{",
"$",
"defaultSchema",
"=",
"$",
"this",
"->",
"driver",
"->",
"getDefaultSchema",
"(",
")",
";",
"$",
"description",
"=",
"[",
"'schemata'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"schemata",
"=",
"$",
"this",
"->",
"getSchemata",
"(",
")",
";",
"foreach",
"(",
"$",
"schemata",
"as",
"$",
"schema",
")",
"{",
"if",
"(",
"$",
"schema",
"[",
"'name'",
"]",
"==",
"$",
"defaultSchema",
")",
"{",
"$",
"description",
"[",
"'tables'",
"]",
"=",
"$",
"this",
"->",
"describeTables",
"(",
"$",
"defaultSchema",
")",
";",
"$",
"description",
"[",
"'views'",
"]",
"=",
"$",
"this",
"->",
"describeViews",
"(",
"$",
"defaultSchema",
")",
";",
"}",
"else",
"{",
"$",
"description",
"[",
"'schemata'",
"]",
"[",
"$",
"schema",
"[",
"'name'",
"]",
"]",
"[",
"'name'",
"]",
"=",
"$",
"schema",
"[",
"'name'",
"]",
";",
"$",
"description",
"[",
"'schemata'",
"]",
"[",
"$",
"schema",
"[",
"'name'",
"]",
"]",
"[",
"'tables'",
"]",
"=",
"$",
"this",
"->",
"describeTables",
"(",
"$",
"schema",
"[",
"'name'",
"]",
")",
";",
"$",
"description",
"[",
"'schemata'",
"]",
"[",
"$",
"schema",
"[",
"'name'",
"]",
"]",
"[",
"'views'",
"]",
"=",
"$",
"this",
"->",
"describeViews",
"(",
"$",
"schema",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"description",
";",
"}"
] | Returns the description of the database as an array.
@return array | [
"Returns",
"the",
"description",
"of",
"the",
"database",
"as",
"an",
"array",
"."
] | 2604fea83e9643adaa8d1fb65443fb214cfa60e6 | https://github.com/ntentan/atiaa/blob/2604fea83e9643adaa8d1fb65443fb214cfa60e6/src/Descriptor.php#L235-L256 | train |
ntentan/atiaa | src/Descriptor.php | Descriptor.throwTableExceptions | private function throwTableExceptions($tables, $requestedTables)
{
$foundTables = [];
foreach ($tables as $table) {
$foundTables[] = $table['name'];
}
foreach ($requestedTables as $requestedTable) {
if (array_search($requestedTable, $foundTables) === false) {
throw new exceptions\TableNotFoundException($requestedTable
? "$requestedTable not found on target database."
: 'Please specify a table name.'
);
}
}
} | php | private function throwTableExceptions($tables, $requestedTables)
{
$foundTables = [];
foreach ($tables as $table) {
$foundTables[] = $table['name'];
}
foreach ($requestedTables as $requestedTable) {
if (array_search($requestedTable, $foundTables) === false) {
throw new exceptions\TableNotFoundException($requestedTable
? "$requestedTable not found on target database."
: 'Please specify a table name.'
);
}
}
} | [
"private",
"function",
"throwTableExceptions",
"(",
"$",
"tables",
",",
"$",
"requestedTables",
")",
"{",
"$",
"foundTables",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"foundTables",
"[",
"]",
"=",
"$",
"table",
"[",
"'name'",
"]",
";",
"}",
"foreach",
"(",
"$",
"requestedTables",
"as",
"$",
"requestedTable",
")",
"{",
"if",
"(",
"array_search",
"(",
"$",
"requestedTable",
",",
"$",
"foundTables",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"exceptions",
"\\",
"TableNotFoundException",
"(",
"$",
"requestedTable",
"?",
"\"$requestedTable not found on target database.\"",
":",
"'Please specify a table name.'",
")",
";",
"}",
"}",
"}"
] | Throws exceptions for which are found in the list of requested tables
but not found in the list of found tables.
@param array $tables
@param array $requestedTables
@throws exceptions\TableNotFoundException | [
"Throws",
"exceptions",
"for",
"which",
"are",
"found",
"in",
"the",
"list",
"of",
"requested",
"tables",
"but",
"not",
"found",
"in",
"the",
"list",
"of",
"found",
"tables",
"."
] | 2604fea83e9643adaa8d1fb65443fb214cfa60e6 | https://github.com/ntentan/atiaa/blob/2604fea83e9643adaa8d1fb65443fb214cfa60e6/src/Descriptor.php#L272-L287 | train |
rnijveld/pgt | lib/Pgettext/Po.php | Po.toFile | public static function toFile(Stringset $set, $filename)
{
try {
$str = self::toString($set, $options);
if (!file_exists($filename) || is_writable($filename)) {
file_put_contents($filename, $str);
} else {
throw new Exception("Cannot write to file");
}
} catch (\Exception $e) {
throw $e;
}
} | php | public static function toFile(Stringset $set, $filename)
{
try {
$str = self::toString($set, $options);
if (!file_exists($filename) || is_writable($filename)) {
file_put_contents($filename, $str);
} else {
throw new Exception("Cannot write to file");
}
} catch (\Exception $e) {
throw $e;
}
} | [
"public",
"static",
"function",
"toFile",
"(",
"Stringset",
"$",
"set",
",",
"$",
"filename",
")",
"{",
"try",
"{",
"$",
"str",
"=",
"self",
"::",
"toString",
"(",
"$",
"set",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
"||",
"is_writable",
"(",
"$",
"filename",
")",
")",
"{",
"file_put_contents",
"(",
"$",
"filename",
",",
"$",
"str",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Cannot write to file\"",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}"
] | Takes a Stringset and a filename and writes a po formatted file.
@param Stringset $set
@param string $filename
@return void | [
"Takes",
"a",
"Stringset",
"and",
"a",
"filename",
"and",
"writes",
"a",
"po",
"formatted",
"file",
"."
] | 9d64b4858438a9833065265c2e6d2db94b7e6fcd | https://github.com/rnijveld/pgt/blob/9d64b4858438a9833065265c2e6d2db94b7e6fcd/lib/Pgettext/Po.php#L34-L46 | train |
rnijveld/pgt | lib/Pgettext/Po.php | Po.toString | public static function toString(Stringset $set)
{
$str = '';
for ($i = 0; $i < $set->size(); $i += 1) {
$item = $set->item($i);
if (count($item['flags']) > 0) {
$str .= "#, " . implode(", ", $item['flags']) . "\n";
}
if ($item['context'] !== null) {
$str .= "msgctxt " . '"' . $item['context'] . '"' . "\n";
}
$str .= "msgid " . '"' . self::escapeString($item['id']) . '"' . "\n";
if ($item['plural'] !== null) {
$str .= "msgid_plural " . '"' . self::escapeString($item['plural']) . '"' . "\n";
}
if (count($item['strings']) === 1) {
$str .= "msgstr " . '"' . self::escapeString($item['strings'][0]) . '"' . "\n";
} else {
for ($j = 0; $j < count($item['strings']); $j += 1) {
$str .= "msgstr[" . $i . "] " . '"' . self::escapeString($item['strings'][0]) . '"' . "\n";
}
}
$str .= "\n";
}
return $str;
} | php | public static function toString(Stringset $set)
{
$str = '';
for ($i = 0; $i < $set->size(); $i += 1) {
$item = $set->item($i);
if (count($item['flags']) > 0) {
$str .= "#, " . implode(", ", $item['flags']) . "\n";
}
if ($item['context'] !== null) {
$str .= "msgctxt " . '"' . $item['context'] . '"' . "\n";
}
$str .= "msgid " . '"' . self::escapeString($item['id']) . '"' . "\n";
if ($item['plural'] !== null) {
$str .= "msgid_plural " . '"' . self::escapeString($item['plural']) . '"' . "\n";
}
if (count($item['strings']) === 1) {
$str .= "msgstr " . '"' . self::escapeString($item['strings'][0]) . '"' . "\n";
} else {
for ($j = 0; $j < count($item['strings']); $j += 1) {
$str .= "msgstr[" . $i . "] " . '"' . self::escapeString($item['strings'][0]) . '"' . "\n";
}
}
$str .= "\n";
}
return $str;
} | [
"public",
"static",
"function",
"toString",
"(",
"Stringset",
"$",
"set",
")",
"{",
"$",
"str",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"set",
"->",
"size",
"(",
")",
";",
"$",
"i",
"+=",
"1",
")",
"{",
"$",
"item",
"=",
"$",
"set",
"->",
"item",
"(",
"$",
"i",
")",
";",
"if",
"(",
"count",
"(",
"$",
"item",
"[",
"'flags'",
"]",
")",
">",
"0",
")",
"{",
"$",
"str",
".=",
"\"#, \"",
".",
"implode",
"(",
"\", \"",
",",
"$",
"item",
"[",
"'flags'",
"]",
")",
".",
"\"\\n\"",
";",
"}",
"if",
"(",
"$",
"item",
"[",
"'context'",
"]",
"!==",
"null",
")",
"{",
"$",
"str",
".=",
"\"msgctxt \"",
".",
"'\"'",
".",
"$",
"item",
"[",
"'context'",
"]",
".",
"'\"'",
".",
"\"\\n\"",
";",
"}",
"$",
"str",
".=",
"\"msgid \"",
".",
"'\"'",
".",
"self",
"::",
"escapeString",
"(",
"$",
"item",
"[",
"'id'",
"]",
")",
".",
"'\"'",
".",
"\"\\n\"",
";",
"if",
"(",
"$",
"item",
"[",
"'plural'",
"]",
"!==",
"null",
")",
"{",
"$",
"str",
".=",
"\"msgid_plural \"",
".",
"'\"'",
".",
"self",
"::",
"escapeString",
"(",
"$",
"item",
"[",
"'plural'",
"]",
")",
".",
"'\"'",
".",
"\"\\n\"",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"item",
"[",
"'strings'",
"]",
")",
"===",
"1",
")",
"{",
"$",
"str",
".=",
"\"msgstr \"",
".",
"'\"'",
".",
"self",
"::",
"escapeString",
"(",
"$",
"item",
"[",
"'strings'",
"]",
"[",
"0",
"]",
")",
".",
"'\"'",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"count",
"(",
"$",
"item",
"[",
"'strings'",
"]",
")",
";",
"$",
"j",
"+=",
"1",
")",
"{",
"$",
"str",
".=",
"\"msgstr[\"",
".",
"$",
"i",
".",
"\"] \"",
".",
"'\"'",
".",
"self",
"::",
"escapeString",
"(",
"$",
"item",
"[",
"'strings'",
"]",
"[",
"0",
"]",
")",
".",
"'\"'",
".",
"\"\\n\"",
";",
"}",
"}",
"$",
"str",
".=",
"\"\\n\"",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Takes a Stringset and an array of options and creates a po formatted string.
@param Stringset $set
@return string | [
"Takes",
"a",
"Stringset",
"and",
"an",
"array",
"of",
"options",
"and",
"creates",
"a",
"po",
"formatted",
"string",
"."
] | 9d64b4858438a9833065265c2e6d2db94b7e6fcd | https://github.com/rnijveld/pgt/blob/9d64b4858438a9833065265c2e6d2db94b7e6fcd/lib/Pgettext/Po.php#L53-L82 | train |
rnijveld/pgt | lib/Pgettext/Po.php | Po.escapeString | private static function escapeString($str)
{
if (strlen($str) === 0) {
return $str;
}
$str = str_replace(array(
"\r",
"\t",
"\\",
"\$",
"\v",
"\e",
"\f",
"\""
), array(
'\r',
'\t',
'\\\\',
'\$',
'\v',
'\e',
'\f',
'\"'
), $str);
$str = str_replace("\n", "\\n\"\n\"", $str);
$result = '';
$str = str_split($str, 1);
foreach ($str as $chr) {
if (!ctype_print($chr) && $chr !== "\n") {
$result .= '\\' . decoct(ord($chr));
} else {
$result .= $chr;
}
}
if (substr($result, -5) === "\\n\"\n\"") {
$result = substr($result, 0, -5) . "\\n";
}
return $result;
} | php | private static function escapeString($str)
{
if (strlen($str) === 0) {
return $str;
}
$str = str_replace(array(
"\r",
"\t",
"\\",
"\$",
"\v",
"\e",
"\f",
"\""
), array(
'\r',
'\t',
'\\\\',
'\$',
'\v',
'\e',
'\f',
'\"'
), $str);
$str = str_replace("\n", "\\n\"\n\"", $str);
$result = '';
$str = str_split($str, 1);
foreach ($str as $chr) {
if (!ctype_print($chr) && $chr !== "\n") {
$result .= '\\' . decoct(ord($chr));
} else {
$result .= $chr;
}
}
if (substr($result, -5) === "\\n\"\n\"") {
$result = substr($result, 0, -5) . "\\n";
}
return $result;
} | [
"private",
"static",
"function",
"escapeString",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"str",
")",
"===",
"0",
")",
"{",
"return",
"$",
"str",
";",
"}",
"$",
"str",
"=",
"str_replace",
"(",
"array",
"(",
"\"\\r\"",
",",
"\"\\t\"",
",",
"\"\\\\\"",
",",
"\"\\$\"",
",",
"\"\\v\"",
",",
"\"\\e\"",
",",
"\"\\f\"",
",",
"\"\\\"\"",
")",
",",
"array",
"(",
"'\\r'",
",",
"'\\t'",
",",
"'\\\\\\\\'",
",",
"'\\$'",
",",
"'\\v'",
",",
"'\\e'",
",",
"'\\f'",
",",
"'\\\"'",
")",
",",
"$",
"str",
")",
";",
"$",
"str",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\\\\n\\\"\\n\\\"\"",
",",
"$",
"str",
")",
";",
"$",
"result",
"=",
"''",
";",
"$",
"str",
"=",
"str_split",
"(",
"$",
"str",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"str",
"as",
"$",
"chr",
")",
"{",
"if",
"(",
"!",
"ctype_print",
"(",
"$",
"chr",
")",
"&&",
"$",
"chr",
"!==",
"\"\\n\"",
")",
"{",
"$",
"result",
".=",
"'\\\\'",
".",
"decoct",
"(",
"ord",
"(",
"$",
"chr",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"$",
"chr",
";",
"}",
"}",
"if",
"(",
"substr",
"(",
"$",
"result",
",",
"-",
"5",
")",
"===",
"\"\\\\n\\\"\\n\\\"\"",
")",
"{",
"$",
"result",
"=",
"substr",
"(",
"$",
"result",
",",
"0",
",",
"-",
"5",
")",
".",
"\"\\\\n\"",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Adds escapes to characters that are in some way special.
@param string $str
@return string | [
"Adds",
"escapes",
"to",
"characters",
"that",
"are",
"in",
"some",
"way",
"special",
"."
] | 9d64b4858438a9833065265c2e6d2db94b7e6fcd | https://github.com/rnijveld/pgt/blob/9d64b4858438a9833065265c2e6d2db94b7e6fcd/lib/Pgettext/Po.php#L89-L130 | train |
rnijveld/pgt | lib/Pgettext/Po.php | Po.fromString | public static function fromString($str)
{
$stringset = new Stringset();
$entry = array();
$state = null;
$line = 1;
foreach (explode("\n", $str) as $line) {
$line = trim($line);
if (strlen($line) === 0) {
if (count($entry) > 0) {
$stringset->add($entry);
$entry = array();
$state = null;
}
continue;
}
if ($line[0] === '#' && $line[1] === ',') {
$entry['flags'] = array_map('trim', explode(',', substr($line, 2)));
} else if ($line[0] !== '#') {
// non-comment
list($key, $rest) = explode(' ', $line, 2);
switch ($key) {
case 'msgid':
case 'msgid_plural':
case 'msgstr':
case 'msgctxt':
if (strpos($state, 'msgstr') === 0 && $key !== 'msgstr' && count($entry) > 0) {
$stringset->add($entry);
$entry = array();
}
$state = $key;
$entry[$key] = self::parseString($rest);
break;
default:
if (strpos($key, 'msgstr[') === 0) {
$state = $key;
$entry[$key] = self::parseString($rest);
} else {
$entry[$state] .= self::parseString(trim($line));
}
}
}
$line += 1;
}
return $stringset;
} | php | public static function fromString($str)
{
$stringset = new Stringset();
$entry = array();
$state = null;
$line = 1;
foreach (explode("\n", $str) as $line) {
$line = trim($line);
if (strlen($line) === 0) {
if (count($entry) > 0) {
$stringset->add($entry);
$entry = array();
$state = null;
}
continue;
}
if ($line[0] === '#' && $line[1] === ',') {
$entry['flags'] = array_map('trim', explode(',', substr($line, 2)));
} else if ($line[0] !== '#') {
// non-comment
list($key, $rest) = explode(' ', $line, 2);
switch ($key) {
case 'msgid':
case 'msgid_plural':
case 'msgstr':
case 'msgctxt':
if (strpos($state, 'msgstr') === 0 && $key !== 'msgstr' && count($entry) > 0) {
$stringset->add($entry);
$entry = array();
}
$state = $key;
$entry[$key] = self::parseString($rest);
break;
default:
if (strpos($key, 'msgstr[') === 0) {
$state = $key;
$entry[$key] = self::parseString($rest);
} else {
$entry[$state] .= self::parseString(trim($line));
}
}
}
$line += 1;
}
return $stringset;
} | [
"public",
"static",
"function",
"fromString",
"(",
"$",
"str",
")",
"{",
"$",
"stringset",
"=",
"new",
"Stringset",
"(",
")",
";",
"$",
"entry",
"=",
"array",
"(",
")",
";",
"$",
"state",
"=",
"null",
";",
"$",
"line",
"=",
"1",
";",
"foreach",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"str",
")",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"line",
")",
"===",
"0",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"entry",
")",
">",
"0",
")",
"{",
"$",
"stringset",
"->",
"add",
"(",
"$",
"entry",
")",
";",
"$",
"entry",
"=",
"array",
"(",
")",
";",
"$",
"state",
"=",
"null",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"$",
"line",
"[",
"0",
"]",
"===",
"'#'",
"&&",
"$",
"line",
"[",
"1",
"]",
"===",
"','",
")",
"{",
"$",
"entry",
"[",
"'flags'",
"]",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"substr",
"(",
"$",
"line",
",",
"2",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"line",
"[",
"0",
"]",
"!==",
"'#'",
")",
"{",
"// non-comment",
"list",
"(",
"$",
"key",
",",
"$",
"rest",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"line",
",",
"2",
")",
";",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'msgid'",
":",
"case",
"'msgid_plural'",
":",
"case",
"'msgstr'",
":",
"case",
"'msgctxt'",
":",
"if",
"(",
"strpos",
"(",
"$",
"state",
",",
"'msgstr'",
")",
"===",
"0",
"&&",
"$",
"key",
"!==",
"'msgstr'",
"&&",
"count",
"(",
"$",
"entry",
")",
">",
"0",
")",
"{",
"$",
"stringset",
"->",
"add",
"(",
"$",
"entry",
")",
";",
"$",
"entry",
"=",
"array",
"(",
")",
";",
"}",
"$",
"state",
"=",
"$",
"key",
";",
"$",
"entry",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"parseString",
"(",
"$",
"rest",
")",
";",
"break",
";",
"default",
":",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'msgstr['",
")",
"===",
"0",
")",
"{",
"$",
"state",
"=",
"$",
"key",
";",
"$",
"entry",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"parseString",
"(",
"$",
"rest",
")",
";",
"}",
"else",
"{",
"$",
"entry",
"[",
"$",
"state",
"]",
".=",
"self",
"::",
"parseString",
"(",
"trim",
"(",
"$",
"line",
")",
")",
";",
"}",
"}",
"}",
"$",
"line",
"+=",
"1",
";",
"}",
"return",
"$",
"stringset",
";",
"}"
] | Takes a string in the format of a po file and returns a Stringset
@param string $str
@return Stringset | [
"Takes",
"a",
"string",
"in",
"the",
"format",
"of",
"a",
"po",
"file",
"and",
"returns",
"a",
"Stringset"
] | 9d64b4858438a9833065265c2e6d2db94b7e6fcd | https://github.com/rnijveld/pgt/blob/9d64b4858438a9833065265c2e6d2db94b7e6fcd/lib/Pgettext/Po.php#L137-L185 | train |
rnijveld/pgt | lib/Pgettext/Po.php | Po.parseString | private static function parseString($str)
{
if ($str[0] !== '"' || $str[strlen($str) - 1] !== '"') {
throw new Exception("Invalid string delimiters");
}
$result = '';
$start = str_split(substr($str, 1, -1), 1);
$escaped = false;
$data = null;
foreach ($start as $chr) {
if ($escaped === 'yes') {
$escaped = false;
switch ($chr) {
case 'n': $result .= "\n"; break;
case 'r': $result .= "\r"; break;
case 't': $result .= "\t"; break;
case 'v': $result .= "\v"; break;
case 'e': $result .= "\e"; break;
case 'f': $result .= "\f"; break;
case '\\': $result .= "\\"; break;
case '$': $result .= "\$"; break;
case '"': $result .= "\""; break;
case 'x':
$escaped = 'hex';
$data = '0x';
break;
default:
if (ctype_digit($chr) && (int)$chr < 8) {
$escaped = 'oct';
$data = $chr;
} else {
$result .= "\\" . $chr;
}
break;
}
} else if ($escaped === 'hex' && ctype_xdigit($chr)) {
$data .= $chr;
if (strlen($data) === 2) {
$escaped = false;
}
} else if ($escaped === 'oct' && ctype_digit($chr) && (int)$chr < 8) {
$data .= $chr;
if (strlen($data) === 3) {
$escaped = false;
}
} else {
if ($data !== null || $escaped === 'hex' || $escaped === 'oct') {
if (substr($data, 0, 2) === '0x') {
if (strlen($data) === 2) {
$result .= "\\x";
} else {
$result .= chr(hexdec($data));
}
} else {
$result .= chr(octdec($data));
}
$data = null;
}
if ($chr === '\\') {
$escaped = 'yes';
} else if ($chr === '"') {
throw new Exception("Unescaped string delimiter inside string");
} else {
$result .= $chr;
}
}
}
if ($escaped !== false) {
throw new Exception("Unfinished escape sequence");
}
return $result;
} | php | private static function parseString($str)
{
if ($str[0] !== '"' || $str[strlen($str) - 1] !== '"') {
throw new Exception("Invalid string delimiters");
}
$result = '';
$start = str_split(substr($str, 1, -1), 1);
$escaped = false;
$data = null;
foreach ($start as $chr) {
if ($escaped === 'yes') {
$escaped = false;
switch ($chr) {
case 'n': $result .= "\n"; break;
case 'r': $result .= "\r"; break;
case 't': $result .= "\t"; break;
case 'v': $result .= "\v"; break;
case 'e': $result .= "\e"; break;
case 'f': $result .= "\f"; break;
case '\\': $result .= "\\"; break;
case '$': $result .= "\$"; break;
case '"': $result .= "\""; break;
case 'x':
$escaped = 'hex';
$data = '0x';
break;
default:
if (ctype_digit($chr) && (int)$chr < 8) {
$escaped = 'oct';
$data = $chr;
} else {
$result .= "\\" . $chr;
}
break;
}
} else if ($escaped === 'hex' && ctype_xdigit($chr)) {
$data .= $chr;
if (strlen($data) === 2) {
$escaped = false;
}
} else if ($escaped === 'oct' && ctype_digit($chr) && (int)$chr < 8) {
$data .= $chr;
if (strlen($data) === 3) {
$escaped = false;
}
} else {
if ($data !== null || $escaped === 'hex' || $escaped === 'oct') {
if (substr($data, 0, 2) === '0x') {
if (strlen($data) === 2) {
$result .= "\\x";
} else {
$result .= chr(hexdec($data));
}
} else {
$result .= chr(octdec($data));
}
$data = null;
}
if ($chr === '\\') {
$escaped = 'yes';
} else if ($chr === '"') {
throw new Exception("Unescaped string delimiter inside string");
} else {
$result .= $chr;
}
}
}
if ($escaped !== false) {
throw new Exception("Unfinished escape sequence");
}
return $result;
} | [
"private",
"static",
"function",
"parseString",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"$",
"str",
"[",
"0",
"]",
"!==",
"'\"'",
"||",
"$",
"str",
"[",
"strlen",
"(",
"$",
"str",
")",
"-",
"1",
"]",
"!==",
"'\"'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid string delimiters\"",
")",
";",
"}",
"$",
"result",
"=",
"''",
";",
"$",
"start",
"=",
"str_split",
"(",
"substr",
"(",
"$",
"str",
",",
"1",
",",
"-",
"1",
")",
",",
"1",
")",
";",
"$",
"escaped",
"=",
"false",
";",
"$",
"data",
"=",
"null",
";",
"foreach",
"(",
"$",
"start",
"as",
"$",
"chr",
")",
"{",
"if",
"(",
"$",
"escaped",
"===",
"'yes'",
")",
"{",
"$",
"escaped",
"=",
"false",
";",
"switch",
"(",
"$",
"chr",
")",
"{",
"case",
"'n'",
":",
"$",
"result",
".=",
"\"\\n\"",
";",
"break",
";",
"case",
"'r'",
":",
"$",
"result",
".=",
"\"\\r\"",
";",
"break",
";",
"case",
"'t'",
":",
"$",
"result",
".=",
"\"\\t\"",
";",
"break",
";",
"case",
"'v'",
":",
"$",
"result",
".=",
"\"\\v\"",
";",
"break",
";",
"case",
"'e'",
":",
"$",
"result",
".=",
"\"\\e\"",
";",
"break",
";",
"case",
"'f'",
":",
"$",
"result",
".=",
"\"\\f\"",
";",
"break",
";",
"case",
"'\\\\'",
":",
"$",
"result",
".=",
"\"\\\\\"",
";",
"break",
";",
"case",
"'$'",
":",
"$",
"result",
".=",
"\"\\$\"",
";",
"break",
";",
"case",
"'\"'",
":",
"$",
"result",
".=",
"\"\\\"\"",
";",
"break",
";",
"case",
"'x'",
":",
"$",
"escaped",
"=",
"'hex'",
";",
"$",
"data",
"=",
"'0x'",
";",
"break",
";",
"default",
":",
"if",
"(",
"ctype_digit",
"(",
"$",
"chr",
")",
"&&",
"(",
"int",
")",
"$",
"chr",
"<",
"8",
")",
"{",
"$",
"escaped",
"=",
"'oct'",
";",
"$",
"data",
"=",
"$",
"chr",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"\"\\\\\"",
".",
"$",
"chr",
";",
"}",
"break",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"escaped",
"===",
"'hex'",
"&&",
"ctype_xdigit",
"(",
"$",
"chr",
")",
")",
"{",
"$",
"data",
".=",
"$",
"chr",
";",
"if",
"(",
"strlen",
"(",
"$",
"data",
")",
"===",
"2",
")",
"{",
"$",
"escaped",
"=",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"escaped",
"===",
"'oct'",
"&&",
"ctype_digit",
"(",
"$",
"chr",
")",
"&&",
"(",
"int",
")",
"$",
"chr",
"<",
"8",
")",
"{",
"$",
"data",
".=",
"$",
"chr",
";",
"if",
"(",
"strlen",
"(",
"$",
"data",
")",
"===",
"3",
")",
"{",
"$",
"escaped",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"data",
"!==",
"null",
"||",
"$",
"escaped",
"===",
"'hex'",
"||",
"$",
"escaped",
"===",
"'oct'",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"2",
")",
"===",
"'0x'",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"data",
")",
"===",
"2",
")",
"{",
"$",
"result",
".=",
"\"\\\\x\"",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"chr",
"(",
"hexdec",
"(",
"$",
"data",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"result",
".=",
"chr",
"(",
"octdec",
"(",
"$",
"data",
")",
")",
";",
"}",
"$",
"data",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"chr",
"===",
"'\\\\'",
")",
"{",
"$",
"escaped",
"=",
"'yes'",
";",
"}",
"else",
"if",
"(",
"$",
"chr",
"===",
"'\"'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unescaped string delimiter inside string\"",
")",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"$",
"chr",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"escaped",
"!==",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unfinished escape sequence\"",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | PHP String parsing without using eval.
@param string $str Unparsed double-quoted string with escape sequences.
@return string | [
"PHP",
"String",
"parsing",
"without",
"using",
"eval",
"."
] | 9d64b4858438a9833065265c2e6d2db94b7e6fcd | https://github.com/rnijveld/pgt/blob/9d64b4858438a9833065265c2e6d2db94b7e6fcd/lib/Pgettext/Po.php#L192-L266 | train |
newestindustry/ginger-rest | src/Ginger/Request.php | Request.go | public function go() {
if ($this->action == "options") {
$file = "options" . $this->getExtension();
} else {
// Check if handler file exists
if ($this->route->route == "/") {
$file = $this->getAction() . $this->getExtension();
} else {
$file = $this->route->resource . "/" . $this->getAction() . $this->getExtension();
}
}
$fullFilePath = stream_resolve_include_path($file);
if ($fullFilePath) {
include $fullFilePath;
} else {
throw new \Ginger\Exception("Not implemented", 501);
}
$this->getResponse()->send();
} | php | public function go() {
if ($this->action == "options") {
$file = "options" . $this->getExtension();
} else {
// Check if handler file exists
if ($this->route->route == "/") {
$file = $this->getAction() . $this->getExtension();
} else {
$file = $this->route->resource . "/" . $this->getAction() . $this->getExtension();
}
}
$fullFilePath = stream_resolve_include_path($file);
if ($fullFilePath) {
include $fullFilePath;
} else {
throw new \Ginger\Exception("Not implemented", 501);
}
$this->getResponse()->send();
} | [
"public",
"function",
"go",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"action",
"==",
"\"options\"",
")",
"{",
"$",
"file",
"=",
"\"options\"",
".",
"$",
"this",
"->",
"getExtension",
"(",
")",
";",
"}",
"else",
"{",
"// Check if handler file exists",
"if",
"(",
"$",
"this",
"->",
"route",
"->",
"route",
"==",
"\"/\"",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getAction",
"(",
")",
".",
"$",
"this",
"->",
"getExtension",
"(",
")",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"route",
"->",
"resource",
".",
"\"/\"",
".",
"$",
"this",
"->",
"getAction",
"(",
")",
".",
"$",
"this",
"->",
"getExtension",
"(",
")",
";",
"}",
"}",
"$",
"fullFilePath",
"=",
"stream_resolve_include_path",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"fullFilePath",
")",
"{",
"include",
"$",
"fullFilePath",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Ginger",
"\\",
"Exception",
"(",
"\"Not implemented\"",
",",
"501",
")",
";",
"}",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"send",
"(",
")",
";",
"}"
] | Load file and dispatch to response | [
"Load",
"file",
"and",
"dispatch",
"to",
"response"
] | 482b77dc122a60ab0bf143a3c4a1e67168985c83 | https://github.com/newestindustry/ginger-rest/blob/482b77dc122a60ab0bf143a3c4a1e67168985c83/src/Ginger/Request.php#L101-L121 | train |
newestindustry/ginger-rest | src/Ginger/Request.php | Request.getAction | public function getAction() {
if ($this->action) {
return $this->action;
} else {
$action = "index";
switch ($_SERVER['REQUEST_METHOD']) {
case "GET":
if (count($this->getFilterParameters()) == 0) {
$action = "index";
} else {
$action = "get";
}
break;
case "POST":
$action = "post";
break;
case "PUT":
$action = "put";
break;
case "DELETE":
$action = "delete";
break;
case "HEAD":
$action = "head";
break;
case "SEARCH":
$action = "search";
break;
case "OPTIONS":
$action = "options";
break;
}
return $action;
}
} | php | public function getAction() {
if ($this->action) {
return $this->action;
} else {
$action = "index";
switch ($_SERVER['REQUEST_METHOD']) {
case "GET":
if (count($this->getFilterParameters()) == 0) {
$action = "index";
} else {
$action = "get";
}
break;
case "POST":
$action = "post";
break;
case "PUT":
$action = "put";
break;
case "DELETE":
$action = "delete";
break;
case "HEAD":
$action = "head";
break;
case "SEARCH":
$action = "search";
break;
case "OPTIONS":
$action = "options";
break;
}
return $action;
}
} | [
"public",
"function",
"getAction",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"action",
")",
"{",
"return",
"$",
"this",
"->",
"action",
";",
"}",
"else",
"{",
"$",
"action",
"=",
"\"index\"",
";",
"switch",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
"{",
"case",
"\"GET\"",
":",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"getFilterParameters",
"(",
")",
")",
"==",
"0",
")",
"{",
"$",
"action",
"=",
"\"index\"",
";",
"}",
"else",
"{",
"$",
"action",
"=",
"\"get\"",
";",
"}",
"break",
";",
"case",
"\"POST\"",
":",
"$",
"action",
"=",
"\"post\"",
";",
"break",
";",
"case",
"\"PUT\"",
":",
"$",
"action",
"=",
"\"put\"",
";",
"break",
";",
"case",
"\"DELETE\"",
":",
"$",
"action",
"=",
"\"delete\"",
";",
"break",
";",
"case",
"\"HEAD\"",
":",
"$",
"action",
"=",
"\"head\"",
";",
"break",
";",
"case",
"\"SEARCH\"",
":",
"$",
"action",
"=",
"\"search\"",
";",
"break",
";",
"case",
"\"OPTIONS\"",
":",
"$",
"action",
"=",
"\"options\"",
";",
"break",
";",
"}",
"return",
"$",
"action",
";",
"}",
"}"
] | Return current action
@return string | [
"Return",
"current",
"action"
] | 482b77dc122a60ab0bf143a3c4a1e67168985c83 | https://github.com/newestindustry/ginger-rest/blob/482b77dc122a60ab0bf143a3c4a1e67168985c83/src/Ginger/Request.php#L195-L230 | train |
amarcinkowski/hospitalplugin | src/Twig/GetPropertiesExtension.php | GetPropertiesExtension.getProps | private static function getProps($class)
{
if ($class == NULL) {
return array();
}
$class = new \ReflectionClass($class);
$properties = array_filter($class->getProperties(), function ($prop) use($class)
{
return $prop->getDeclaringClass()->name == $class->name;
});
return $properties;
} | php | private static function getProps($class)
{
if ($class == NULL) {
return array();
}
$class = new \ReflectionClass($class);
$properties = array_filter($class->getProperties(), function ($prop) use($class)
{
return $prop->getDeclaringClass()->name == $class->name;
});
return $properties;
} | [
"private",
"static",
"function",
"getProps",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"class",
"==",
"NULL",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"properties",
"=",
"array_filter",
"(",
"$",
"class",
"->",
"getProperties",
"(",
")",
",",
"function",
"(",
"$",
"prop",
")",
"use",
"(",
"$",
"class",
")",
"{",
"return",
"$",
"prop",
"->",
"getDeclaringClass",
"(",
")",
"->",
"name",
"==",
"$",
"class",
"->",
"name",
";",
"}",
")",
";",
"return",
"$",
"properties",
";",
"}"
] | return props of a class
@param unknown $class
@return boolean|multitype: | [
"return",
"props",
"of",
"a",
"class"
] | acdc2be5157abfbdcafb4dcf6c6ba505e291263f | https://github.com/amarcinkowski/hospitalplugin/blob/acdc2be5157abfbdcafb4dcf6c6ba505e291263f/src/Twig/GetPropertiesExtension.php#L22-L33 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCNewService.php | HCNewService.createService | private function createService(stdClass $serviceData)
{
$this->comment('');
$this->comment('*************************************');
$this->comment('* Service creation *');
$this->comment('*************************************');
$this->comment($serviceData->serviceName);
$this->comment('*************************************');
$helpersList = [
'controller' => new HCServiceController(),
'translations' => new HCServiceTranslations(),
'models' => new HCServiceModels(),
'form-validators' => new HCServiceFormValidators(),
'forms' => new HCServiceForms(),
'routes' => new HCServiceRoutes(),
];
foreach ( $helpersList as $helper )
$serviceData = $helper->optimize($serviceData);
// finalizing destination
$serviceData->controllerDestination .= '/' . $serviceData->controllerName . '.php';
foreach ( $helpersList as $helper ) {
$files = $helper->generate($serviceData);
if( is_array($files) )
$this->createdFiles = array_merge($this->createdFiles, $files);
else
$this->createdFiles[] = $files;
}
if( $serviceData->rootDirectory != './' )
$this->call('hc:routes', ["directory" => $serviceData->rootDirectory]);
else
$this->call('hc:routes');
if( isset($serviceData->generateMigrations) && $serviceData->generateMigrations )
$this->call('migrate:generate', ["--path" => $serviceData->rootDirectory . 'database/migrations', "tables" => implode(",", $helpersList['models']->getTables())]);
$this->updateConfiguration($serviceData);
} | php | private function createService(stdClass $serviceData)
{
$this->comment('');
$this->comment('*************************************');
$this->comment('* Service creation *');
$this->comment('*************************************');
$this->comment($serviceData->serviceName);
$this->comment('*************************************');
$helpersList = [
'controller' => new HCServiceController(),
'translations' => new HCServiceTranslations(),
'models' => new HCServiceModels(),
'form-validators' => new HCServiceFormValidators(),
'forms' => new HCServiceForms(),
'routes' => new HCServiceRoutes(),
];
foreach ( $helpersList as $helper )
$serviceData = $helper->optimize($serviceData);
// finalizing destination
$serviceData->controllerDestination .= '/' . $serviceData->controllerName . '.php';
foreach ( $helpersList as $helper ) {
$files = $helper->generate($serviceData);
if( is_array($files) )
$this->createdFiles = array_merge($this->createdFiles, $files);
else
$this->createdFiles[] = $files;
}
if( $serviceData->rootDirectory != './' )
$this->call('hc:routes', ["directory" => $serviceData->rootDirectory]);
else
$this->call('hc:routes');
if( isset($serviceData->generateMigrations) && $serviceData->generateMigrations )
$this->call('migrate:generate', ["--path" => $serviceData->rootDirectory . 'database/migrations', "tables" => implode(",", $helpersList['models']->getTables())]);
$this->updateConfiguration($serviceData);
} | [
"private",
"function",
"createService",
"(",
"stdClass",
"$",
"serviceData",
")",
"{",
"$",
"this",
"->",
"comment",
"(",
"''",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'*************************************'",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'* Service creation *'",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'*************************************'",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"$",
"serviceData",
"->",
"serviceName",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'*************************************'",
")",
";",
"$",
"helpersList",
"=",
"[",
"'controller'",
"=>",
"new",
"HCServiceController",
"(",
")",
",",
"'translations'",
"=>",
"new",
"HCServiceTranslations",
"(",
")",
",",
"'models'",
"=>",
"new",
"HCServiceModels",
"(",
")",
",",
"'form-validators'",
"=>",
"new",
"HCServiceFormValidators",
"(",
")",
",",
"'forms'",
"=>",
"new",
"HCServiceForms",
"(",
")",
",",
"'routes'",
"=>",
"new",
"HCServiceRoutes",
"(",
")",
",",
"]",
";",
"foreach",
"(",
"$",
"helpersList",
"as",
"$",
"helper",
")",
"$",
"serviceData",
"=",
"$",
"helper",
"->",
"optimize",
"(",
"$",
"serviceData",
")",
";",
"// finalizing destination",
"$",
"serviceData",
"->",
"controllerDestination",
".=",
"'/'",
".",
"$",
"serviceData",
"->",
"controllerName",
".",
"'.php'",
";",
"foreach",
"(",
"$",
"helpersList",
"as",
"$",
"helper",
")",
"{",
"$",
"files",
"=",
"$",
"helper",
"->",
"generate",
"(",
"$",
"serviceData",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"files",
")",
")",
"$",
"this",
"->",
"createdFiles",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"createdFiles",
",",
"$",
"files",
")",
";",
"else",
"$",
"this",
"->",
"createdFiles",
"[",
"]",
"=",
"$",
"files",
";",
"}",
"if",
"(",
"$",
"serviceData",
"->",
"rootDirectory",
"!=",
"'./'",
")",
"$",
"this",
"->",
"call",
"(",
"'hc:routes'",
",",
"[",
"\"directory\"",
"=>",
"$",
"serviceData",
"->",
"rootDirectory",
"]",
")",
";",
"else",
"$",
"this",
"->",
"call",
"(",
"'hc:routes'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"serviceData",
"->",
"generateMigrations",
")",
"&&",
"$",
"serviceData",
"->",
"generateMigrations",
")",
"$",
"this",
"->",
"call",
"(",
"'migrate:generate'",
",",
"[",
"\"--path\"",
"=>",
"$",
"serviceData",
"->",
"rootDirectory",
".",
"'database/migrations'",
",",
"\"tables\"",
"=>",
"implode",
"(",
"\",\"",
",",
"$",
"helpersList",
"[",
"'models'",
"]",
"->",
"getTables",
"(",
")",
")",
"]",
")",
";",
"$",
"this",
"->",
"updateConfiguration",
"(",
"$",
"serviceData",
")",
";",
"}"
] | Generating service information
@param $serviceData | [
"Generating",
"service",
"information"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCNewService.php#L79-L121 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCNewService.php | HCNewService.loadConfiguration | private function loadConfiguration()
{
$allFiles = File::allFiles('_automate');
foreach ( $allFiles as $file )
if( strpos((string)$file, '.done') === false )
$this->configurationData[] = $this->optimizeData($file);
} | php | private function loadConfiguration()
{
$allFiles = File::allFiles('_automate');
foreach ( $allFiles as $file )
if( strpos((string)$file, '.done') === false )
$this->configurationData[] = $this->optimizeData($file);
} | [
"private",
"function",
"loadConfiguration",
"(",
")",
"{",
"$",
"allFiles",
"=",
"File",
"::",
"allFiles",
"(",
"'_automate'",
")",
";",
"foreach",
"(",
"$",
"allFiles",
"as",
"$",
"file",
")",
"if",
"(",
"strpos",
"(",
"(",
"string",
")",
"$",
"file",
",",
"'.done'",
")",
"===",
"false",
")",
"$",
"this",
"->",
"configurationData",
"[",
"]",
"=",
"$",
"this",
"->",
"optimizeData",
"(",
"$",
"file",
")",
";",
"}"
] | Loading configuration files
@return this | [
"Loading",
"configuration",
"files"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCNewService.php#L128-L136 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCNewService.php | HCNewService.checkPackage | private function checkPackage(stdClass $item)
{
if( ! file_exists($item->rootDirectory) )
$this->abort('Package ' . $item->directory . ' not existing, please create a repository and launch "php artisan hc:new-package" command');
} | php | private function checkPackage(stdClass $item)
{
if( ! file_exists($item->rootDirectory) )
$this->abort('Package ' . $item->directory . ' not existing, please create a repository and launch "php artisan hc:new-package" command');
} | [
"private",
"function",
"checkPackage",
"(",
"stdClass",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"item",
"->",
"rootDirectory",
")",
")",
"$",
"this",
"->",
"abort",
"(",
"'Package '",
".",
"$",
"item",
"->",
"directory",
".",
"' not existing, please create a repository and launch \"php artisan hc:new-package\" command'",
")",
";",
"}"
] | Checking package existence
@param $item | [
"Checking",
"package",
"existence"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCNewService.php#L169-L173 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCNewService.php | HCNewService.executeAfterAbort | protected function executeAfterAbort()
{
/*foreach ($this->originalFiles as $value)
{
$this->file->put($value['path'], $value['content']);
$this->comment('Restored: ' . $value['path']);
}*/
foreach ( $this->createdFiles as $value ) {
File::delete($value);
$this->error('Deleted: ' . $value);
}
} | php | protected function executeAfterAbort()
{
/*foreach ($this->originalFiles as $value)
{
$this->file->put($value['path'], $value['content']);
$this->comment('Restored: ' . $value['path']);
}*/
foreach ( $this->createdFiles as $value ) {
File::delete($value);
$this->error('Deleted: ' . $value);
}
} | [
"protected",
"function",
"executeAfterAbort",
"(",
")",
"{",
"/*foreach ($this->originalFiles as $value)\n {\n $this->file->put($value['path'], $value['content']);\n $this->comment('Restored: ' . $value['path']);\n }*/",
"foreach",
"(",
"$",
"this",
"->",
"createdFiles",
"as",
"$",
"value",
")",
"{",
"File",
"::",
"delete",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"error",
"(",
"'Deleted: '",
".",
"$",
"value",
")",
";",
"}",
"}"
] | Restoring changed files after the abort
Deleting create files
@return this | [
"Restoring",
"changed",
"files",
"after",
"the",
"abort",
"Deleting",
"create",
"files"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCNewService.php#L181-L193 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCNewService.php | HCNewService.updateActions | private function updateActions(stdClass $config, stdClass $serviceData)
{
$servicePermissions = [
"name" => "admin." . $serviceData->serviceRouteName,
"controller" => $serviceData->controllerNamespace . '\\' . $serviceData->controllerName,
"actions" => [
$serviceData->aclPrefix . "_list",
$serviceData->aclPrefix . "_create",
$serviceData->aclPrefix . "_update",
$serviceData->aclPrefix . "_delete",
$serviceData->aclPrefix . "_force_delete",
],
];
$contentChanged = false;
foreach ( $config->acl->permissions as &$value ) {
if( $value->name == "admin." . $serviceData->serviceRouteName ) {
if( $this->confirm('Duplicate ACL found ' . "admin." . $serviceData->serviceRouteName . ' Confirm override', 'no') ) {
$contentChanged = true;
$value = $servicePermissions;
break;
} else {
$this->abort('Can not override existing configuration. Aborting...');
return null;
}
}
}
if( ! $contentChanged )
$config->acl->permissions = array_merge($config->acl->permissions, [$servicePermissions]);
return $config;
} | php | private function updateActions(stdClass $config, stdClass $serviceData)
{
$servicePermissions = [
"name" => "admin." . $serviceData->serviceRouteName,
"controller" => $serviceData->controllerNamespace . '\\' . $serviceData->controllerName,
"actions" => [
$serviceData->aclPrefix . "_list",
$serviceData->aclPrefix . "_create",
$serviceData->aclPrefix . "_update",
$serviceData->aclPrefix . "_delete",
$serviceData->aclPrefix . "_force_delete",
],
];
$contentChanged = false;
foreach ( $config->acl->permissions as &$value ) {
if( $value->name == "admin." . $serviceData->serviceRouteName ) {
if( $this->confirm('Duplicate ACL found ' . "admin." . $serviceData->serviceRouteName . ' Confirm override', 'no') ) {
$contentChanged = true;
$value = $servicePermissions;
break;
} else {
$this->abort('Can not override existing configuration. Aborting...');
return null;
}
}
}
if( ! $contentChanged )
$config->acl->permissions = array_merge($config->acl->permissions, [$servicePermissions]);
return $config;
} | [
"private",
"function",
"updateActions",
"(",
"stdClass",
"$",
"config",
",",
"stdClass",
"$",
"serviceData",
")",
"{",
"$",
"servicePermissions",
"=",
"[",
"\"name\"",
"=>",
"\"admin.\"",
".",
"$",
"serviceData",
"->",
"serviceRouteName",
",",
"\"controller\"",
"=>",
"$",
"serviceData",
"->",
"controllerNamespace",
".",
"'\\\\'",
".",
"$",
"serviceData",
"->",
"controllerName",
",",
"\"actions\"",
"=>",
"[",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_list\"",
",",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_create\"",
",",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_update\"",
",",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_delete\"",
",",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_force_delete\"",
",",
"]",
",",
"]",
";",
"$",
"contentChanged",
"=",
"false",
";",
"foreach",
"(",
"$",
"config",
"->",
"acl",
"->",
"permissions",
"as",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"->",
"name",
"==",
"\"admin.\"",
".",
"$",
"serviceData",
"->",
"serviceRouteName",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"confirm",
"(",
"'Duplicate ACL found '",
".",
"\"admin.\"",
".",
"$",
"serviceData",
"->",
"serviceRouteName",
".",
"' Confirm override'",
",",
"'no'",
")",
")",
"{",
"$",
"contentChanged",
"=",
"true",
";",
"$",
"value",
"=",
"$",
"servicePermissions",
";",
"break",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"abort",
"(",
"'Can not override existing configuration. Aborting...'",
")",
";",
"return",
"null",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"contentChanged",
")",
"$",
"config",
"->",
"acl",
"->",
"permissions",
"=",
"array_merge",
"(",
"$",
"config",
"->",
"acl",
"->",
"permissions",
",",
"[",
"$",
"servicePermissions",
"]",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Updating service actions
@param $config
@param $serviceData
@return null | [
"Updating",
"service",
"actions"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCNewService.php#L221-L255 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCNewService.php | HCNewService.updateRolesActions | private function updateRolesActions(stdClass $config, stdClass $serviceData)
{
$rolesActions = [
"project-admin" =>
[$serviceData->aclPrefix . "_list",
$serviceData->aclPrefix . "_create",
$serviceData->aclPrefix . "_update",
$serviceData->aclPrefix . "_delete",
],
];
if( empty($config->acl->rolesActions) )
$config->acl->rolesActions = $rolesActions;
else
$config->acl->rolesActions->{"project-admin"} = array_unique(array_merge($config->acl->rolesActions->{"project-admin"}, $rolesActions['project-admin']));
return $config;
} | php | private function updateRolesActions(stdClass $config, stdClass $serviceData)
{
$rolesActions = [
"project-admin" =>
[$serviceData->aclPrefix . "_list",
$serviceData->aclPrefix . "_create",
$serviceData->aclPrefix . "_update",
$serviceData->aclPrefix . "_delete",
],
];
if( empty($config->acl->rolesActions) )
$config->acl->rolesActions = $rolesActions;
else
$config->acl->rolesActions->{"project-admin"} = array_unique(array_merge($config->acl->rolesActions->{"project-admin"}, $rolesActions['project-admin']));
return $config;
} | [
"private",
"function",
"updateRolesActions",
"(",
"stdClass",
"$",
"config",
",",
"stdClass",
"$",
"serviceData",
")",
"{",
"$",
"rolesActions",
"=",
"[",
"\"project-admin\"",
"=>",
"[",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_list\"",
",",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_create\"",
",",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_update\"",
",",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_delete\"",
",",
"]",
",",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"config",
"->",
"acl",
"->",
"rolesActions",
")",
")",
"$",
"config",
"->",
"acl",
"->",
"rolesActions",
"=",
"$",
"rolesActions",
";",
"else",
"$",
"config",
"->",
"acl",
"->",
"rolesActions",
"->",
"{",
"\"project-admin\"",
"}",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"config",
"->",
"acl",
"->",
"rolesActions",
"->",
"{",
"\"project-admin\"",
"}",
",",
"$",
"rolesActions",
"[",
"'project-admin'",
"]",
")",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Updating roles actions
@param $config
@param $serviceData
@return stdClass | [
"Updating",
"roles",
"actions"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCNewService.php#L264-L281 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCNewService.php | HCNewService.updateMenu | private function updateMenu(stdClass $config, stdClass $serviceData)
{
$menuItem = [
"route" => 'admin.' . $serviceData->serviceRouteName . '.index',
"translation" => $serviceData->translationsLocation . '.page_title',
"icon" => $serviceData->serviceIcon,
"aclPermission" => $serviceData->aclPrefix . "_list",
"priority" => 10,
];
$newMenu = true;
//TODO check if adminMenu exists if not create []
foreach ( $config->adminMenu as &$existingMenuItem ) {
if( $existingMenuItem->route == $menuItem['route'] ) {
if( $this->confirm('Duplicate Menu item found with ' . $existingMenuItem->path . ' path. Confirm override', 'no') ) {
$existingMenuItem = $menuItem;
$newMenu = false;
break;
} else {
$this->abort('Can not override existing configuration. Aborting...');
return null;
}
}
}
if ($newMenu)
$config->adminMenu = array_merge ($config->adminMenu, [$menuItem]);
return $config;
} | php | private function updateMenu(stdClass $config, stdClass $serviceData)
{
$menuItem = [
"route" => 'admin.' . $serviceData->serviceRouteName . '.index',
"translation" => $serviceData->translationsLocation . '.page_title',
"icon" => $serviceData->serviceIcon,
"aclPermission" => $serviceData->aclPrefix . "_list",
"priority" => 10,
];
$newMenu = true;
//TODO check if adminMenu exists if not create []
foreach ( $config->adminMenu as &$existingMenuItem ) {
if( $existingMenuItem->route == $menuItem['route'] ) {
if( $this->confirm('Duplicate Menu item found with ' . $existingMenuItem->path . ' path. Confirm override', 'no') ) {
$existingMenuItem = $menuItem;
$newMenu = false;
break;
} else {
$this->abort('Can not override existing configuration. Aborting...');
return null;
}
}
}
if ($newMenu)
$config->adminMenu = array_merge ($config->adminMenu, [$menuItem]);
return $config;
} | [
"private",
"function",
"updateMenu",
"(",
"stdClass",
"$",
"config",
",",
"stdClass",
"$",
"serviceData",
")",
"{",
"$",
"menuItem",
"=",
"[",
"\"route\"",
"=>",
"'admin.'",
".",
"$",
"serviceData",
"->",
"serviceRouteName",
".",
"'.index'",
",",
"\"translation\"",
"=>",
"$",
"serviceData",
"->",
"translationsLocation",
".",
"'.page_title'",
",",
"\"icon\"",
"=>",
"$",
"serviceData",
"->",
"serviceIcon",
",",
"\"aclPermission\"",
"=>",
"$",
"serviceData",
"->",
"aclPrefix",
".",
"\"_list\"",
",",
"\"priority\"",
"=>",
"10",
",",
"]",
";",
"$",
"newMenu",
"=",
"true",
";",
"//TODO check if adminMenu exists if not create []",
"foreach",
"(",
"$",
"config",
"->",
"adminMenu",
"as",
"&",
"$",
"existingMenuItem",
")",
"{",
"if",
"(",
"$",
"existingMenuItem",
"->",
"route",
"==",
"$",
"menuItem",
"[",
"'route'",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"confirm",
"(",
"'Duplicate Menu item found with '",
".",
"$",
"existingMenuItem",
"->",
"path",
".",
"' path. Confirm override'",
",",
"'no'",
")",
")",
"{",
"$",
"existingMenuItem",
"=",
"$",
"menuItem",
";",
"$",
"newMenu",
"=",
"false",
";",
"break",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"abort",
"(",
"'Can not override existing configuration. Aborting...'",
")",
";",
"return",
"null",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"newMenu",
")",
"$",
"config",
"->",
"adminMenu",
"=",
"array_merge",
"(",
"$",
"config",
"->",
"adminMenu",
",",
"[",
"$",
"menuItem",
"]",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Updating menu parameter
@param $config
@param $serviceData
@return null | [
"Updating",
"menu",
"parameter"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCNewService.php#L300-L331 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCNewService.php | HCNewService.updateFormManager | private function updateFormManager(stdClass $config, stdClass $serviceData)
{
$config->formData = json_decode(json_encode($config->formData), true);
if( ! isset($config->formData[$serviceData->formID]) )
$config->formData[$serviceData->formID] = $serviceData->formNameSpace . '\\' . $serviceData->formName;
return $config;
} | php | private function updateFormManager(stdClass $config, stdClass $serviceData)
{
$config->formData = json_decode(json_encode($config->formData), true);
if( ! isset($config->formData[$serviceData->formID]) )
$config->formData[$serviceData->formID] = $serviceData->formNameSpace . '\\' . $serviceData->formName;
return $config;
} | [
"private",
"function",
"updateFormManager",
"(",
"stdClass",
"$",
"config",
",",
"stdClass",
"$",
"serviceData",
")",
"{",
"$",
"config",
"->",
"formData",
"=",
"json_decode",
"(",
"json_encode",
"(",
"$",
"config",
"->",
"formData",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"->",
"formData",
"[",
"$",
"serviceData",
"->",
"formID",
"]",
")",
")",
"$",
"config",
"->",
"formData",
"[",
"$",
"serviceData",
"->",
"formID",
"]",
"=",
"$",
"serviceData",
"->",
"formNameSpace",
".",
"'\\\\'",
".",
"$",
"serviceData",
"->",
"formName",
";",
"return",
"$",
"config",
";",
"}"
] | Updating form manager
@param $config
@param $serviceData
@return mixed | [
"Updating",
"form",
"manager"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCNewService.php#L341-L349 | train |
Synapse-Cmf/synapse-cmf | src/Synapse/Cmf/Framework/Theme/Variation/Entity/Variation.php | Variation.getConfiguration | public function getConfiguration($namespace, $element, $key, $default = null)
{
$propertyPath = sprintf('[%s][%s][%s]', $namespace, $element, $key);
if ($value = $this->propertyAccessor->getValue($this->configurations, $propertyPath)) {
return $value;
}
return $default;
} | php | public function getConfiguration($namespace, $element, $key, $default = null)
{
$propertyPath = sprintf('[%s][%s][%s]', $namespace, $element, $key);
if ($value = $this->propertyAccessor->getValue($this->configurations, $propertyPath)) {
return $value;
}
return $default;
} | [
"public",
"function",
"getConfiguration",
"(",
"$",
"namespace",
",",
"$",
"element",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"propertyPath",
"=",
"sprintf",
"(",
"'[%s][%s][%s]'",
",",
"$",
"namespace",
",",
"$",
"element",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"this",
"->",
"configurations",
",",
"$",
"propertyPath",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Return configuration value under given property path into given namespace or default if not readable.
@see PropertyAccessorInterface::getValue()
@param sgring $namespace
@param string $path
@param string $element
@param mixed $default
@return mixed | [
"Return",
"configuration",
"value",
"under",
"given",
"property",
"path",
"into",
"given",
"namespace",
"or",
"default",
"if",
"not",
"readable",
"."
] | d8122a4150a83d5607289724425cf35c56a5e880 | https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Cmf/Framework/Theme/Variation/Entity/Variation.php#L46-L55 | train |
IftekherSunny/Planet-Framework | src/Sun/Session/Session.php | Session.startSession | protected function startSession()
{
if (session_status() == PHP_SESSION_NONE) {
session_start();
if(!$this->expireOnClose) {
setcookie('planet_session', session_id(), time() + ($this->expireTime * 60 ), '/', null, false, false);
}
}
} | php | protected function startSession()
{
if (session_status() == PHP_SESSION_NONE) {
session_start();
if(!$this->expireOnClose) {
setcookie('planet_session', session_id(), time() + ($this->expireTime * 60 ), '/', null, false, false);
}
}
} | [
"protected",
"function",
"startSession",
"(",
")",
"{",
"if",
"(",
"session_status",
"(",
")",
"==",
"PHP_SESSION_NONE",
")",
"{",
"session_start",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"expireOnClose",
")",
"{",
"setcookie",
"(",
"'planet_session'",
",",
"session_id",
"(",
")",
",",
"time",
"(",
")",
"+",
"(",
"$",
"this",
"->",
"expireTime",
"*",
"60",
")",
",",
"'/'",
",",
"null",
",",
"false",
",",
"false",
")",
";",
"}",
"}",
"}"
] | To start session | [
"To",
"start",
"session"
] | 530e772fb97695c1c4e1af73f81675f189474d9f | https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Session/Session.php#L54-L64 | train |
IftekherSunny/Planet-Framework | src/Sun/Session/Session.php | Session.pull | public function pull($name, $value = '')
{
$value = $this->get($name, $value);
$this->delete($name);
return $value;
} | php | public function pull($name, $value = '')
{
$value = $this->get($name, $value);
$this->delete($name);
return $value;
} | [
"public",
"function",
"pull",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"''",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"delete",
"(",
"$",
"name",
")",
";",
"return",
"$",
"value",
";",
"}"
] | To pull session data
@param string $name
@param string $value
@return mixed | [
"To",
"pull",
"session",
"data"
] | 530e772fb97695c1c4e1af73f81675f189474d9f | https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Session/Session.php#L156-L162 | train |
IftekherSunny/Planet-Framework | src/Sun/Session/Session.php | Session.pop | public function pop($name)
{
$previousValue = $this->get($name);
$value = array_pop($previousValue);
$this->create($name, $previousValue);
return $value;
} | php | public function pop($name)
{
$previousValue = $this->get($name);
$value = array_pop($previousValue);
$this->create($name, $previousValue);
return $value;
} | [
"public",
"function",
"pop",
"(",
"$",
"name",
")",
"{",
"$",
"previousValue",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"name",
")",
";",
"$",
"value",
"=",
"array_pop",
"(",
"$",
"previousValue",
")",
";",
"$",
"this",
"->",
"create",
"(",
"$",
"name",
",",
"$",
"previousValue",
")",
";",
"return",
"$",
"value",
";",
"}"
] | To pop session data from session array
@param string $name
@return string | [
"To",
"pop",
"session",
"data",
"from",
"session",
"array"
] | 530e772fb97695c1c4e1af73f81675f189474d9f | https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Session/Session.php#L188-L197 | train |
IftekherSunny/Planet-Framework | src/Sun/Session/Session.php | Session.shift | public function shift($name)
{
$previousValue = $this->get($name);
$value = array_shift($previousValue);
$this->create($name, $previousValue);
return $value;
} | php | public function shift($name)
{
$previousValue = $this->get($name);
$value = array_shift($previousValue);
$this->create($name, $previousValue);
return $value;
} | [
"public",
"function",
"shift",
"(",
"$",
"name",
")",
"{",
"$",
"previousValue",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"name",
")",
";",
"$",
"value",
"=",
"array_shift",
"(",
"$",
"previousValue",
")",
";",
"$",
"this",
"->",
"create",
"(",
"$",
"name",
",",
"$",
"previousValue",
")",
";",
"return",
"$",
"value",
";",
"}"
] | To shift session data from session array
@param string $name
@return string | [
"To",
"shift",
"session",
"data",
"from",
"session",
"array"
] | 530e772fb97695c1c4e1af73f81675f189474d9f | https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Session/Session.php#L206-L215 | train |
Elephant418/Staq | src/Staq/Autoloader.php | Autoloader.getRealClass | protected function getRealClass($stack, $extensionNamespace)
{
$stackPath = \Staq\Util::convertNamespaceToPath($stack);
$absolutePath = realpath($this->extensions[$extensionNamespace] . '/Stack/' . $stackPath . '.php');
if (is_file($absolutePath)) {
$realClass = $extensionNamespace . '\\Stack\\' . $stack;
return $realClass;
}
} | php | protected function getRealClass($stack, $extensionNamespace)
{
$stackPath = \Staq\Util::convertNamespaceToPath($stack);
$absolutePath = realpath($this->extensions[$extensionNamespace] . '/Stack/' . $stackPath . '.php');
if (is_file($absolutePath)) {
$realClass = $extensionNamespace . '\\Stack\\' . $stack;
return $realClass;
}
} | [
"protected",
"function",
"getRealClass",
"(",
"$",
"stack",
",",
"$",
"extensionNamespace",
")",
"{",
"$",
"stackPath",
"=",
"\\",
"Staq",
"\\",
"Util",
"::",
"convertNamespaceToPath",
"(",
"$",
"stack",
")",
";",
"$",
"absolutePath",
"=",
"realpath",
"(",
"$",
"this",
"->",
"extensions",
"[",
"$",
"extensionNamespace",
"]",
".",
"'/Stack/'",
".",
"$",
"stackPath",
".",
"'.php'",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"absolutePath",
")",
")",
"{",
"$",
"realClass",
"=",
"$",
"extensionNamespace",
".",
"'\\\\Stack\\\\'",
".",
"$",
"stack",
";",
"return",
"$",
"realClass",
";",
"}",
"}"
] | "stack" is now a part of the namespace, there is no burgers left at my bakery | [
"stack",
"is",
"now",
"a",
"part",
"of",
"the",
"namespace",
"there",
"is",
"no",
"burgers",
"left",
"at",
"my",
"bakery"
] | b96110eb069a2b3fd992d3e56327a54a308b68b2 | https://github.com/Elephant418/Staq/blob/b96110eb069a2b3fd992d3e56327a54a308b68b2/src/Staq/Autoloader.php#L76-L84 | train |
schpill/thin | src/Filter/Striptags.php | Striptags.filter | public function filter($value)
{
// start by stripping the comments, if necessary
if(!$this->allowComments) {
$value = preg_replace('/<!\-\-.*\-\->/U', '', $value);
}
// strip unallowed tags
$allowed = '';
foreach($this->allowedTags as $tag) {
$allowed .= "<{$tag}>";
}
$value = strip_tags($value, $allowed);
// strip unallowed attributes - only if there are allowed tags,
// otherwise all attributes have already been removed with the tags
if(!empty($this->allowedTags)) {
$allowed = $this->allowedAttributes;
do {
$old = $value;
$value = preg_replace_callback('/<[a-zA-Z]+ *(([a-zA-Z_:][\-a-zA-Z0-9_:\.]+) *=.*["\'].*["\']).*>/U', function($matches) use($allowed) {
if(in_array($matches[2], $allowed)) {
return $matches[0];
} else {
return repl(' ' . $matches[1], '', $matches[0]);
}
}, $value);
} while($old != $value);
}
// we're left with the filtered value
return $value;
} | php | public function filter($value)
{
// start by stripping the comments, if necessary
if(!$this->allowComments) {
$value = preg_replace('/<!\-\-.*\-\->/U', '', $value);
}
// strip unallowed tags
$allowed = '';
foreach($this->allowedTags as $tag) {
$allowed .= "<{$tag}>";
}
$value = strip_tags($value, $allowed);
// strip unallowed attributes - only if there are allowed tags,
// otherwise all attributes have already been removed with the tags
if(!empty($this->allowedTags)) {
$allowed = $this->allowedAttributes;
do {
$old = $value;
$value = preg_replace_callback('/<[a-zA-Z]+ *(([a-zA-Z_:][\-a-zA-Z0-9_:\.]+) *=.*["\'].*["\']).*>/U', function($matches) use($allowed) {
if(in_array($matches[2], $allowed)) {
return $matches[0];
} else {
return repl(' ' . $matches[1], '', $matches[0]);
}
}, $value);
} while($old != $value);
}
// we're left with the filtered value
return $value;
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"// start by stripping the comments, if necessary",
"if",
"(",
"!",
"$",
"this",
"->",
"allowComments",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"'/<!\\-\\-.*\\-\\->/U'",
",",
"''",
",",
"$",
"value",
")",
";",
"}",
"// strip unallowed tags",
"$",
"allowed",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"allowedTags",
"as",
"$",
"tag",
")",
"{",
"$",
"allowed",
".=",
"\"<{$tag}>\"",
";",
"}",
"$",
"value",
"=",
"strip_tags",
"(",
"$",
"value",
",",
"$",
"allowed",
")",
";",
"// strip unallowed attributes - only if there are allowed tags,",
"// otherwise all attributes have already been removed with the tags",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"allowedTags",
")",
")",
"{",
"$",
"allowed",
"=",
"$",
"this",
"->",
"allowedAttributes",
";",
"do",
"{",
"$",
"old",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"preg_replace_callback",
"(",
"'/<[a-zA-Z]+ *(([a-zA-Z_:][\\-a-zA-Z0-9_:\\.]+) *=.*[\"\\'].*[\"\\']).*>/U'",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"allowed",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"matches",
"[",
"2",
"]",
",",
"$",
"allowed",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"return",
"repl",
"(",
"' '",
".",
"$",
"matches",
"[",
"1",
"]",
",",
"''",
",",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"}",
"}",
",",
"$",
"value",
")",
";",
"}",
"while",
"(",
"$",
"old",
"!=",
"$",
"value",
")",
";",
"}",
"// we're left with the filtered value",
"return",
"$",
"value",
";",
"}"
] | Strip the undesired HTML markup
@param string $value The input string with HTML markup
@return string Filtered string | [
"Strip",
"the",
"undesired",
"HTML",
"markup"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Filter/Striptags.php#L33-L65 | train |
schpill/thin | src/Filter/Striptags.php | Striptags.setAllowedTags | public function setAllowedTags($tags)
{
if(!is_array($tags)) {
$tags = [$tags];
}
$this->allowedTags = $tags;
return $this;
} | php | public function setAllowedTags($tags)
{
if(!is_array($tags)) {
$tags = [$tags];
}
$this->allowedTags = $tags;
return $this;
} | [
"public",
"function",
"setAllowedTags",
"(",
"$",
"tags",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"tags",
")",
")",
"{",
"$",
"tags",
"=",
"[",
"$",
"tags",
"]",
";",
"}",
"$",
"this",
"->",
"allowedTags",
"=",
"$",
"tags",
";",
"return",
"$",
"this",
";",
"}"
] | Set the HTML tags that should be left in the input string
@param array|string $tags The allowed tags: either an array or a string with a single tag.
@return \Thin\Filter\StripTags Provides a fluent interface | [
"Set",
"the",
"HTML",
"tags",
"that",
"should",
"be",
"left",
"in",
"the",
"input",
"string"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Filter/Striptags.php#L76-L83 | train |
schpill/thin | src/Filter/Striptags.php | Striptags.setAllowedAttributes | public function setAllowedAttributes($attributes)
{
if(!is_array($attributes)) {
$attributes = [$attributes];
}
$this->allowedAttributes = $attributes;
return $this;
} | php | public function setAllowedAttributes($attributes)
{
if(!is_array($attributes)) {
$attributes = [$attributes];
}
$this->allowedAttributes = $attributes;
return $this;
} | [
"public",
"function",
"setAllowedAttributes",
"(",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"attributes",
"=",
"[",
"$",
"attributes",
"]",
";",
"}",
"$",
"this",
"->",
"allowedAttributes",
"=",
"$",
"attributes",
";",
"return",
"$",
"this",
";",
"}"
] | Set the HTML attributes that should be left in the unstripped tags in the input string
@param array $attributes The allowed attributes: either an array or a string with a single attribute.
@return \Thin\Filter\StripTags Provides a fluent interface | [
"Set",
"the",
"HTML",
"attributes",
"that",
"should",
"be",
"left",
"in",
"the",
"unstripped",
"tags",
"in",
"the",
"input",
"string"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Filter/Striptags.php#L94-L101 | train |
phPoirot/Stream | Streamable.php | Streamable.write | function write($content, $inByte = null)
{
$this->_assertWritable();
$stream = $this->resource()->getRHandler();
$inByte = ($inByte === null)
? $this->getBuffer()
: $inByte;
$content = (string) $content;
if (null === $inByte)
$ret = fwrite($stream, $content);
else
$ret = fwrite($stream, $content, $inByte);
if (false === $ret)
throw new \RuntimeException('Cannot write on stream.');
$transCount = $inByte;
if ($transCount === null) {
if (function_exists('mb_strlen'))
$transCount = mb_strlen($content, '8bit');
else
$transCount = strlen($content);
}
$this->_resetTransCount($transCount);
return $this;
} | php | function write($content, $inByte = null)
{
$this->_assertWritable();
$stream = $this->resource()->getRHandler();
$inByte = ($inByte === null)
? $this->getBuffer()
: $inByte;
$content = (string) $content;
if (null === $inByte)
$ret = fwrite($stream, $content);
else
$ret = fwrite($stream, $content, $inByte);
if (false === $ret)
throw new \RuntimeException('Cannot write on stream.');
$transCount = $inByte;
if ($transCount === null) {
if (function_exists('mb_strlen'))
$transCount = mb_strlen($content, '8bit');
else
$transCount = strlen($content);
}
$this->_resetTransCount($transCount);
return $this;
} | [
"function",
"write",
"(",
"$",
"content",
",",
"$",
"inByte",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_assertWritable",
"(",
")",
";",
"$",
"stream",
"=",
"$",
"this",
"->",
"resource",
"(",
")",
"->",
"getRHandler",
"(",
")",
";",
"$",
"inByte",
"=",
"(",
"$",
"inByte",
"===",
"null",
")",
"?",
"$",
"this",
"->",
"getBuffer",
"(",
")",
":",
"$",
"inByte",
";",
"$",
"content",
"=",
"(",
"string",
")",
"$",
"content",
";",
"if",
"(",
"null",
"===",
"$",
"inByte",
")",
"$",
"ret",
"=",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"content",
")",
";",
"else",
"$",
"ret",
"=",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"content",
",",
"$",
"inByte",
")",
";",
"if",
"(",
"false",
"===",
"$",
"ret",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot write on stream.'",
")",
";",
"$",
"transCount",
"=",
"$",
"inByte",
";",
"if",
"(",
"$",
"transCount",
"===",
"null",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mb_strlen'",
")",
")",
"$",
"transCount",
"=",
"mb_strlen",
"(",
"$",
"content",
",",
"'8bit'",
")",
";",
"else",
"$",
"transCount",
"=",
"strlen",
"(",
"$",
"content",
")",
";",
"}",
"$",
"this",
"->",
"_resetTransCount",
"(",
"$",
"transCount",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Writes the contents of string to the file stream
@param string $content The string that is to be written
@param int $inByte Writing will stop after length bytes
have been written or the end of string
is reached
@return $this | [
"Writes",
"the",
"contents",
"of",
"string",
"to",
"the",
"file",
"stream"
] | db448ee0528c2a5b07c594b8a30e2543fbc15f57 | https://github.com/phPoirot/Stream/blob/db448ee0528c2a5b07c594b8a30e2543fbc15f57/Streamable.php#L244-L274 | train |
phPoirot/Stream | Streamable.php | Streamable.sendData | function sendData($data, $flags = null)
{
$rHandler = $this->resource()->getRHandler();
if ($flags === null) {
if ($this->resource()->meta()->getStreamType() == 'udp_socket')
// STREAM_OOB data not provided on udp sockets
$flags = STREAM_PEEK;
else
$flags = STREAM_SOCK_RDM;
}
$ret = @stream_socket_sendto($rHandler, $data, $flags);
if ($ret == -1) {
$lerror = error_get_last();
throw new \RuntimeException(sprintf(
'Cannot send data on stream, %s.',
$lerror['message']
));
}
$this->_resetTransCount($ret);
return $this;
} | php | function sendData($data, $flags = null)
{
$rHandler = $this->resource()->getRHandler();
if ($flags === null) {
if ($this->resource()->meta()->getStreamType() == 'udp_socket')
// STREAM_OOB data not provided on udp sockets
$flags = STREAM_PEEK;
else
$flags = STREAM_SOCK_RDM;
}
$ret = @stream_socket_sendto($rHandler, $data, $flags);
if ($ret == -1) {
$lerror = error_get_last();
throw new \RuntimeException(sprintf(
'Cannot send data on stream, %s.',
$lerror['message']
));
}
$this->_resetTransCount($ret);
return $this;
} | [
"function",
"sendData",
"(",
"$",
"data",
",",
"$",
"flags",
"=",
"null",
")",
"{",
"$",
"rHandler",
"=",
"$",
"this",
"->",
"resource",
"(",
")",
"->",
"getRHandler",
"(",
")",
";",
"if",
"(",
"$",
"flags",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resource",
"(",
")",
"->",
"meta",
"(",
")",
"->",
"getStreamType",
"(",
")",
"==",
"'udp_socket'",
")",
"// STREAM_OOB data not provided on udp sockets",
"$",
"flags",
"=",
"STREAM_PEEK",
";",
"else",
"$",
"flags",
"=",
"STREAM_SOCK_RDM",
";",
"}",
"$",
"ret",
"=",
"@",
"stream_socket_sendto",
"(",
"$",
"rHandler",
",",
"$",
"data",
",",
"$",
"flags",
")",
";",
"if",
"(",
"$",
"ret",
"==",
"-",
"1",
")",
"{",
"$",
"lerror",
"=",
"error_get_last",
"(",
")",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Cannot send data on stream, %s.'",
",",
"$",
"lerror",
"[",
"'message'",
"]",
")",
")",
";",
"}",
"$",
"this",
"->",
"_resetTransCount",
"(",
"$",
"ret",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sends the specified data through the socket,
whether it is connected or not
@param string $data The data to be sent
@param int|null $flags Provides a RDM (Reliably-delivered messages) socket
The value of flags can be any combination of the following:
- STREAM_SOCK_RDM
- STREAM_PEEK
- STREAM_OOB process OOB (out-of-band) data
- null auto choose the value
@return $this | [
"Sends",
"the",
"specified",
"data",
"through",
"the",
"socket",
"whether",
"it",
"is",
"connected",
"or",
"not"
] | db448ee0528c2a5b07c594b8a30e2543fbc15f57 | https://github.com/phPoirot/Stream/blob/db448ee0528c2a5b07c594b8a30e2543fbc15f57/Streamable.php#L305-L331 | train |
phPoirot/Stream | Streamable.php | Streamable.rewind | function rewind()
{
$this->_assertSeekable();
$stream = $this->resource()->getRHandler();
if (false === rewind($stream))
throw new \RuntimeException('Cannot rewind stream');
return $this;
} | php | function rewind()
{
$this->_assertSeekable();
$stream = $this->resource()->getRHandler();
if (false === rewind($stream))
throw new \RuntimeException('Cannot rewind stream');
return $this;
} | [
"function",
"rewind",
"(",
")",
"{",
"$",
"this",
"->",
"_assertSeekable",
"(",
")",
";",
"$",
"stream",
"=",
"$",
"this",
"->",
"resource",
"(",
")",
"->",
"getRHandler",
"(",
")",
";",
"if",
"(",
"false",
"===",
"rewind",
"(",
"$",
"stream",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot rewind stream'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Move the file pointer to the beginning of the stream
! php doesn't support seek/rewind on non-local streams
we can using temp/cache piped stream.
! If you have opened the file in append ("a" or "a+") mode,
any data you write to the file will always be appended,
regardless of the file position.
@return $this | [
"Move",
"the",
"file",
"pointer",
"to",
"the",
"beginning",
"of",
"the",
"stream"
] | db448ee0528c2a5b07c594b8a30e2543fbc15f57 | https://github.com/phPoirot/Stream/blob/db448ee0528c2a5b07c594b8a30e2543fbc15f57/Streamable.php#L429-L439 | train |
hal-platform/hal-core | src/Repository/System/VersionControlProviderRepository.php | VersionControlProviderRepository.getPagedResults | public function getPagedResults($limit = 50, $page = 0)
{
$dql = sprintf(self::DQL_GET_VCSS, VersionControlProvider::class);
return $this->getPaginator($dql, $limit, $page);
} | php | public function getPagedResults($limit = 50, $page = 0)
{
$dql = sprintf(self::DQL_GET_VCSS, VersionControlProvider::class);
return $this->getPaginator($dql, $limit, $page);
} | [
"public",
"function",
"getPagedResults",
"(",
"$",
"limit",
"=",
"50",
",",
"$",
"page",
"=",
"0",
")",
"{",
"$",
"dql",
"=",
"sprintf",
"(",
"self",
"::",
"DQL_GET_VCSS",
",",
"VersionControlProvider",
"::",
"class",
")",
";",
"return",
"$",
"this",
"->",
"getPaginator",
"(",
"$",
"dql",
",",
"$",
"limit",
",",
"$",
"page",
")",
";",
"}"
] | Get all VCSs, paged.
@param int $limit
@param int $page
@return Paginator | [
"Get",
"all",
"VCSs",
"paged",
"."
] | 30d456f8392fc873301ad4217d2ae90436c67090 | https://github.com/hal-platform/hal-core/blob/30d456f8392fc873301ad4217d2ae90436c67090/src/Repository/System/VersionControlProviderRepository.php#L60-L65 | train |
iron-bound-designs/wp-notifications | src/Template/Listener.php | Listener.get_callback_reflection | public function get_callback_reflection() {
if ( is_array( $this->callback ) ) {
return new \ReflectionMethod( $this->callback[0], $this->callback[1] );
} else {
return new \ReflectionFunction( $this->callback );
}
} | php | public function get_callback_reflection() {
if ( is_array( $this->callback ) ) {
return new \ReflectionMethod( $this->callback[0], $this->callback[1] );
} else {
return new \ReflectionFunction( $this->callback );
}
} | [
"public",
"function",
"get_callback_reflection",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"callback",
")",
")",
"{",
"return",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"this",
"->",
"callback",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"callback",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"return",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"this",
"->",
"callback",
")",
";",
"}",
"}"
] | Get a reflection object for the callback function.
@since 1.0
@return \ReflectionFunctionAbstract | [
"Get",
"a",
"reflection",
"object",
"for",
"the",
"callback",
"function",
"."
] | 4fdf67d28d194576d35f86245b2f539c4815cde2 | https://github.com/iron-bound-designs/wp-notifications/blob/4fdf67d28d194576d35f86245b2f539c4815cde2/src/Template/Listener.php#L50-L56 | train |
apishka/easy-extend | source/RouterAbstract.php | RouterAbstract.pushClassData | protected function pushClassData(array $data, \ReflectionClass $reflector): array
{
return $this->collectClassData(
$reflector->newInstanceWithoutConstructor(),
$data,
$reflector
);
} | php | protected function pushClassData(array $data, \ReflectionClass $reflector): array
{
return $this->collectClassData(
$reflector->newInstanceWithoutConstructor(),
$data,
$reflector
);
} | [
"protected",
"function",
"pushClassData",
"(",
"array",
"$",
"data",
",",
"\\",
"ReflectionClass",
"$",
"reflector",
")",
":",
"array",
"{",
"return",
"$",
"this",
"->",
"collectClassData",
"(",
"$",
"reflector",
"->",
"newInstanceWithoutConstructor",
"(",
")",
",",
"$",
"data",
",",
"$",
"reflector",
")",
";",
"}"
] | Push class data
@param array $data
@param \ReflectionClass $reflector
@return array | [
"Push",
"class",
"data"
] | 5e5c63c2509377abc3db6956e353623683703e09 | https://github.com/apishka/easy-extend/blob/5e5c63c2509377abc3db6956e353623683703e09/source/RouterAbstract.php#L73-L80 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.