repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Template/String.php | Dwoo_Template_String.templateFactory | public static function templateFactory(Dwoo $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
{
return new self($resourceId, $cacheTime, $cacheId, $compileId);
} | php | public static function templateFactory(Dwoo $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
{
return new self($resourceId, $cacheTime, $cacheId, $compileId);
} | [
"public",
"static",
"function",
"templateFactory",
"(",
"Dwoo",
"$",
"dwoo",
",",
"$",
"resourceId",
",",
"$",
"cacheTime",
"=",
"null",
",",
"$",
"cacheId",
"=",
"null",
",",
"$",
"compileId",
"=",
"null",
",",
"Dwoo_ITemplate",
"$",
"parentTemplate",
"=",
"null",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"resourceId",
",",
"$",
"cacheTime",
",",
"$",
"cacheId",
",",
"$",
"compileId",
")",
";",
"}"
] | returns a new template string object with the resource id being the template source code
@param Dwoo $dwoo the dwoo instance requiring it
@param mixed $resourceId the filename (relative to this template's dir) of the template to include
@param int $cacheTime duration of the cache validity for this template,
if null it defaults to the Dwoo instance that will
render this template
@param string $cacheId the unique cache identifier of this page or anything else that
makes this template's content unique, if null it defaults
to the current url
@param string $compileId the unique compiled identifier, which is used to distinguish this
template from others, if null it defaults to the filename+bits of the path
@param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through
an include, extends or any other plugin)
@return Dwoo_Template_String | [
"returns",
"a",
"new",
"template",
"string",
"object",
"with",
"the",
"resource",
"id",
"being",
"the",
"template",
"source",
"code"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Template/String.php#L407-L410 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Template/String.php | Dwoo_Template_String.getCompiledFilename | protected function getCompiledFilename(Dwoo $dwoo)
{
// no compile id was provided, set default
if ($this->compileId===null) {
$this->compileId = $this->name;
}
return $dwoo->getCompileDir() . $this->compileId.'.d'.Dwoo::RELEASE_TAG.'.php';
} | php | protected function getCompiledFilename(Dwoo $dwoo)
{
// no compile id was provided, set default
if ($this->compileId===null) {
$this->compileId = $this->name;
}
return $dwoo->getCompileDir() . $this->compileId.'.d'.Dwoo::RELEASE_TAG.'.php';
} | [
"protected",
"function",
"getCompiledFilename",
"(",
"Dwoo",
"$",
"dwoo",
")",
"{",
"// no compile id was provided, set default",
"if",
"(",
"$",
"this",
"->",
"compileId",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"compileId",
"=",
"$",
"this",
"->",
"name",
";",
"}",
"return",
"$",
"dwoo",
"->",
"getCompileDir",
"(",
")",
".",
"$",
"this",
"->",
"compileId",
".",
"'.d'",
".",
"Dwoo",
"::",
"RELEASE_TAG",
".",
"'.php'",
";",
"}"
] | returns the full compiled file name and assigns a default value to it if
required
@param Dwoo $dwoo the dwoo instance that requests the file name
@return string the full path to the compiled file | [
"returns",
"the",
"full",
"compiled",
"file",
"name",
"and",
"assigns",
"a",
"default",
"value",
"to",
"it",
"if",
"required"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Template/String.php#L419-L426 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Template/String.php | Dwoo_Template_String.getCacheFilename | protected function getCacheFilename(Dwoo $dwoo)
{
// no cache id provided, use request_uri as default
if ($this->cacheId === null) {
if (isset($_SERVER['REQUEST_URI']) === true) {
$cacheId = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['argv'])) {
$cacheId = $_SERVER['SCRIPT_FILENAME'].'-'.implode('-', $_SERVER['argv']);
} else {
$cacheId = '';
}
// force compiled id generation
$this->getCompiledFilename($dwoo);
$this->cacheId = str_replace('../', '__', $this->compileId . strtr($cacheId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
}
return $dwoo->getCacheDir() . $this->cacheId.'.html';
} | php | protected function getCacheFilename(Dwoo $dwoo)
{
// no cache id provided, use request_uri as default
if ($this->cacheId === null) {
if (isset($_SERVER['REQUEST_URI']) === true) {
$cacheId = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['argv'])) {
$cacheId = $_SERVER['SCRIPT_FILENAME'].'-'.implode('-', $_SERVER['argv']);
} else {
$cacheId = '';
}
// force compiled id generation
$this->getCompiledFilename($dwoo);
$this->cacheId = str_replace('../', '__', $this->compileId . strtr($cacheId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
}
return $dwoo->getCacheDir() . $this->cacheId.'.html';
} | [
"protected",
"function",
"getCacheFilename",
"(",
"Dwoo",
"$",
"dwoo",
")",
"{",
"// no cache id provided, use request_uri as default",
"if",
"(",
"$",
"this",
"->",
"cacheId",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
"===",
"true",
")",
"{",
"$",
"cacheId",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SCRIPT_FILENAME'",
"]",
")",
"&&",
"isset",
"(",
"$",
"_SERVER",
"[",
"'argv'",
"]",
")",
")",
"{",
"$",
"cacheId",
"=",
"$",
"_SERVER",
"[",
"'SCRIPT_FILENAME'",
"]",
".",
"'-'",
".",
"implode",
"(",
"'-'",
",",
"$",
"_SERVER",
"[",
"'argv'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"cacheId",
"=",
"''",
";",
"}",
"// force compiled id generation",
"$",
"this",
"->",
"getCompiledFilename",
"(",
"$",
"dwoo",
")",
";",
"$",
"this",
"->",
"cacheId",
"=",
"str_replace",
"(",
"'../'",
",",
"'__'",
",",
"$",
"this",
"->",
"compileId",
".",
"strtr",
"(",
"$",
"cacheId",
",",
"'\\\\%?=!:;'",
".",
"PATH_SEPARATOR",
",",
"'/-------'",
")",
")",
";",
"}",
"return",
"$",
"dwoo",
"->",
"getCacheDir",
"(",
")",
".",
"$",
"this",
"->",
"cacheId",
".",
"'.html'",
";",
"}"
] | returns the full cached file name and assigns a default value to it if
required
@param Dwoo $dwoo the dwoo instance that requests the file name
@return string the full path to the cached file | [
"returns",
"the",
"full",
"cached",
"file",
"name",
"and",
"assigns",
"a",
"default",
"value",
"to",
"it",
"if",
"required"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Template/String.php#L435-L452 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Template/String.php | Dwoo_Template_String.makeDirectory | protected function makeDirectory($path, $baseDir = null)
{
if (is_dir($path) === true) {
return;
}
if ($this->chmod === null) {
$chmod = 0777;
} else {
$chmod = $this->chmod;
}
mkdir($path, $chmod, true);
// enforce the correct mode for all directories created
if (strpos(PHP_OS, 'WIN') !== 0 && $baseDir !== null) {
$path = strtr(str_replace($baseDir, '', $path), '\\', '/');
$folders = explode('/', trim($path, '/'));
foreach ($folders as $folder) {
$baseDir .= $folder . DIRECTORY_SEPARATOR;
chmod($baseDir, $chmod);
}
}
} | php | protected function makeDirectory($path, $baseDir = null)
{
if (is_dir($path) === true) {
return;
}
if ($this->chmod === null) {
$chmod = 0777;
} else {
$chmod = $this->chmod;
}
mkdir($path, $chmod, true);
// enforce the correct mode for all directories created
if (strpos(PHP_OS, 'WIN') !== 0 && $baseDir !== null) {
$path = strtr(str_replace($baseDir, '', $path), '\\', '/');
$folders = explode('/', trim($path, '/'));
foreach ($folders as $folder) {
$baseDir .= $folder . DIRECTORY_SEPARATOR;
chmod($baseDir, $chmod);
}
}
} | [
"protected",
"function",
"makeDirectory",
"(",
"$",
"path",
",",
"$",
"baseDir",
"=",
"null",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
"===",
"true",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"chmod",
"===",
"null",
")",
"{",
"$",
"chmod",
"=",
"0777",
";",
"}",
"else",
"{",
"$",
"chmod",
"=",
"$",
"this",
"->",
"chmod",
";",
"}",
"mkdir",
"(",
"$",
"path",
",",
"$",
"chmod",
",",
"true",
")",
";",
"// enforce the correct mode for all directories created",
"if",
"(",
"strpos",
"(",
"PHP_OS",
",",
"'WIN'",
")",
"!==",
"0",
"&&",
"$",
"baseDir",
"!==",
"null",
")",
"{",
"$",
"path",
"=",
"strtr",
"(",
"str_replace",
"(",
"$",
"baseDir",
",",
"''",
",",
"$",
"path",
")",
",",
"'\\\\'",
",",
"'/'",
")",
";",
"$",
"folders",
"=",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"path",
",",
"'/'",
")",
")",
";",
"foreach",
"(",
"$",
"folders",
"as",
"$",
"folder",
")",
"{",
"$",
"baseDir",
".=",
"$",
"folder",
".",
"DIRECTORY_SEPARATOR",
";",
"chmod",
"(",
"$",
"baseDir",
",",
"$",
"chmod",
")",
";",
"}",
"}",
"}"
] | ensures the given path exists
@param string $path any path
@param string $baseDir the base directory where the directory is created
($path must still contain the full path, $baseDir
is only used for unix permissions) | [
"ensures",
"the",
"given",
"path",
"exists"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Template/String.php#L474-L496 |
bpolaszek/simple-dbal | src/Model/Adapter/Mysqli/Result.php | Result.resetResultset | private function resetResultset()
{
if (null !== $this->stmt) {
$this->stmt->execute();
$this->result = $this->stmt->get_result();
}
} | php | private function resetResultset()
{
if (null !== $this->stmt) {
$this->stmt->execute();
$this->result = $this->stmt->get_result();
}
} | [
"private",
"function",
"resetResultset",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"stmt",
")",
"{",
"$",
"this",
"->",
"stmt",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"result",
"=",
"$",
"this",
"->",
"stmt",
"->",
"get_result",
"(",
")",
";",
"}",
"}"
] | Reset the resultset. | [
"Reset",
"the",
"resultset",
"."
] | train | https://github.com/bpolaszek/simple-dbal/blob/52cb50d326ba5854191814b470f5e84950ebb6e6/src/Model/Adapter/Mysqli/Result.php#L226-L232 |
Smile-SA/EzUICronBundle | Controller/CronController.php | CronController.cronAction | public function cronAction($tabItem)
{
$this->performAccessChecks();
return $this->render('SmileEzUICronBundle:cron:index.html.twig', [
'tab_items' => $this->tabItems,
'tab_item_selected' => $tabItem,
'params' => array(),
'hasErrors' => false
]);
} | php | public function cronAction($tabItem)
{
$this->performAccessChecks();
return $this->render('SmileEzUICronBundle:cron:index.html.twig', [
'tab_items' => $this->tabItems,
'tab_item_selected' => $tabItem,
'params' => array(),
'hasErrors' => false
]);
} | [
"public",
"function",
"cronAction",
"(",
"$",
"tabItem",
")",
"{",
"$",
"this",
"->",
"performAccessChecks",
"(",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SmileEzUICronBundle:cron:index.html.twig'",
",",
"[",
"'tab_items'",
"=>",
"$",
"this",
"->",
"tabItems",
",",
"'tab_item_selected'",
"=>",
"$",
"tabItem",
",",
"'params'",
"=>",
"array",
"(",
")",
",",
"'hasErrors'",
"=>",
"false",
"]",
")",
";",
"}"
] | Render tab item content
@param string $tabItem tab item name
@return \Symfony\Component\HttpFoundation\Response | [
"Render",
"tab",
"item",
"content"
] | train | https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/Controller/CronController.php#L31-L41 |
wenbinye/PhalconX | src/Text/LineEditor.php | LineEditor.delete | public function delete($line, $lines)
{
foreach (range(0, $lines-1) as $offset) {
$this->lines[$line+$offset-1] = null;
}
return $this;
} | php | public function delete($line, $lines)
{
foreach (range(0, $lines-1) as $offset) {
$this->lines[$line+$offset-1] = null;
}
return $this;
} | [
"public",
"function",
"delete",
"(",
"$",
"line",
",",
"$",
"lines",
")",
"{",
"foreach",
"(",
"range",
"(",
"0",
",",
"$",
"lines",
"-",
"1",
")",
"as",
"$",
"offset",
")",
"{",
"$",
"this",
"->",
"lines",
"[",
"$",
"line",
"+",
"$",
"offset",
"-",
"1",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | deletes the content at $line
@param int $line
@param int $lines number of lines to delete | [
"deletes",
"the",
"content",
"at",
"$line"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Text/LineEditor.php#L64-L70 |
wenbinye/PhalconX | src/Text/LineEditor.php | LineEditor.replace | public function replace($line, $lines, $text)
{
if ($lines > 0) {
$this->delete($line, $lines);
}
return $this->insert($line, $text);
} | php | public function replace($line, $lines, $text)
{
if ($lines > 0) {
$this->delete($line, $lines);
}
return $this->insert($line, $text);
} | [
"public",
"function",
"replace",
"(",
"$",
"line",
",",
"$",
"lines",
",",
"$",
"text",
")",
"{",
"if",
"(",
"$",
"lines",
">",
"0",
")",
"{",
"$",
"this",
"->",
"delete",
"(",
"$",
"line",
",",
"$",
"lines",
")",
";",
"}",
"return",
"$",
"this",
"->",
"insert",
"(",
"$",
"line",
",",
"$",
"text",
")",
";",
"}"
] | replaces the content at $line
@param int $line
@param int $lines number of lines to replace
@param string text | [
"replaces",
"the",
"content",
"at",
"$line"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Text/LineEditor.php#L79-L85 |
wenbinye/PhalconX | src/Text/LineEditor.php | LineEditor.get | public function get($line)
{
return isset($this->lines[$line-1]) ? $this->lines[$line-1] : null;
} | php | public function get($line)
{
return isset($this->lines[$line-1]) ? $this->lines[$line-1] : null;
} | [
"public",
"function",
"get",
"(",
"$",
"line",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"lines",
"[",
"$",
"line",
"-",
"1",
"]",
")",
"?",
"$",
"this",
"->",
"lines",
"[",
"$",
"line",
"-",
"1",
"]",
":",
"null",
";",
"}"
] | Gets content of the line
@return string return null if content deleted | [
"Gets",
"content",
"of",
"the",
"line"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Text/LineEditor.php#L92-L95 |
Eresus/EresusCMS | src/core/CMS/Request.php | Eresus_CMS_Request.setSiteRoot | public function setSiteRoot($url)
{
$url = strval($url);
if ('' !== $url)
{
$url = rtrim(parse_url($url, PHP_URL_PATH), '/');
if (substr($url, 0, 1) != '/')
{
$url = '/' . $url;
}
}
$this->siteRoot = $url;
} | php | public function setSiteRoot($url)
{
$url = strval($url);
if ('' !== $url)
{
$url = rtrim(parse_url($url, PHP_URL_PATH), '/');
if (substr($url, 0, 1) != '/')
{
$url = '/' . $url;
}
}
$this->siteRoot = $url;
} | [
"public",
"function",
"setSiteRoot",
"(",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"strval",
"(",
"$",
"url",
")",
";",
"if",
"(",
"''",
"!==",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"rtrim",
"(",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_PATH",
")",
",",
"'/'",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"url",
"=",
"'/'",
".",
"$",
"url",
";",
"}",
"}",
"$",
"this",
"->",
"siteRoot",
"=",
"$",
"url",
";",
"}"
] | Задаёт корневой адрес сайта
Этот адрес будет вырезаться в таких методах как {@link getPath()}, {@link getDirectry()},
{@link getFile()}.
@param mixed $url корневой URL или только путь относительно корня домена
@since 3.01 | [
"Задаёт",
"корневой",
"адрес",
"сайта"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/CMS/Request.php#L85-L97 |
Eresus/EresusCMS | src/core/CMS/Request.php | Eresus_CMS_Request.getPath | public function getPath()
{
$path = parent::getPath();
if ('' == $path)
{
$path = '/';
}
if ($this->siteRoot)
{
$path = substr($path, strlen($this->siteRoot));
}
return $path;
} | php | public function getPath()
{
$path = parent::getPath();
if ('' == $path)
{
$path = '/';
}
if ($this->siteRoot)
{
$path = substr($path, strlen($this->siteRoot));
}
return $path;
} | [
"public",
"function",
"getPath",
"(",
")",
"{",
"$",
"path",
"=",
"parent",
"::",
"getPath",
"(",
")",
";",
"if",
"(",
"''",
"==",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"'/'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"siteRoot",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"this",
"->",
"siteRoot",
")",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Возвращает путь (папку и имя файла) из запроса
@return string
@since 3.01 | [
"Возвращает",
"путь",
"(",
"папку",
"и",
"имя",
"файла",
")",
"из",
"запроса"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/CMS/Request.php#L156-L168 |
oroinc/OroLayoutComponent | Templating/TextHelper.php | TextHelper.processText | public function processText($value, $domain = null)
{
if (empty($value)) {
return $value;
}
if (is_string($value)) {
return $this->translator->trans($value, [], $domain ?: self::DEFAULT_TRANS_DOMAIN);
}
if (is_array($value)) {
$this->processArray($value, $domain ?: self::DEFAULT_TRANS_DOMAIN);
}
return $value;
} | php | public function processText($value, $domain = null)
{
if (empty($value)) {
return $value;
}
if (is_string($value)) {
return $this->translator->trans($value, [], $domain ?: self::DEFAULT_TRANS_DOMAIN);
}
if (is_array($value)) {
$this->processArray($value, $domain ?: self::DEFAULT_TRANS_DOMAIN);
}
return $value;
} | [
"public",
"function",
"processText",
"(",
"$",
"value",
",",
"$",
"domain",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"value",
",",
"[",
"]",
",",
"$",
"domain",
"?",
":",
"self",
"::",
"DEFAULT_TRANS_DOMAIN",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"processArray",
"(",
"$",
"value",
",",
"$",
"domain",
"?",
":",
"self",
"::",
"DEFAULT_TRANS_DOMAIN",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Normalizes and translates (if needed) labels in the given value.
@param mixed $value
@param string|null $domain
@return array | [
"Normalizes",
"and",
"translates",
"(",
"if",
"needed",
")",
"labels",
"in",
"the",
"given",
"value",
"."
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Templating/TextHelper.php#L30-L44 |
oroinc/OroLayoutComponent | Templating/TextHelper.php | TextHelper.processArray | protected function processArray(&$value, $domain)
{
if (isset($value['label'])) {
$label = $value['label'];
if (is_string($label)) {
if (empty($label)) {
$value = $label;
} else {
$translatable = isset($value['translatable'])
? $value['translatable']
: true;
$transDomain = isset($value['translation_domain'])
? $value['translation_domain']
: $domain;
if (isset($value['parameters'])) {
$params = $value['parameters'];
if (!empty($params)) {
$this->processArray($params, $domain);
}
} else {
$params = [];
}
$value = $translatable
? $this->translator->trans($label, $params, $transDomain)
: strtr($label, $params);
}
} else {
foreach ($value as &$val) {
if (is_array($val)) {
$this->processArray($val, $domain);
}
}
}
} elseif (array_key_exists('label', $value)) {
$value = null;
} else {
foreach ($value as &$val) {
if (is_array($val)) {
$this->processArray($val, $domain);
}
}
}
} | php | protected function processArray(&$value, $domain)
{
if (isset($value['label'])) {
$label = $value['label'];
if (is_string($label)) {
if (empty($label)) {
$value = $label;
} else {
$translatable = isset($value['translatable'])
? $value['translatable']
: true;
$transDomain = isset($value['translation_domain'])
? $value['translation_domain']
: $domain;
if (isset($value['parameters'])) {
$params = $value['parameters'];
if (!empty($params)) {
$this->processArray($params, $domain);
}
} else {
$params = [];
}
$value = $translatable
? $this->translator->trans($label, $params, $transDomain)
: strtr($label, $params);
}
} else {
foreach ($value as &$val) {
if (is_array($val)) {
$this->processArray($val, $domain);
}
}
}
} elseif (array_key_exists('label', $value)) {
$value = null;
} else {
foreach ($value as &$val) {
if (is_array($val)) {
$this->processArray($val, $domain);
}
}
}
} | [
"protected",
"function",
"processArray",
"(",
"&",
"$",
"value",
",",
"$",
"domain",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'label'",
"]",
")",
")",
"{",
"$",
"label",
"=",
"$",
"value",
"[",
"'label'",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"label",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"label",
")",
")",
"{",
"$",
"value",
"=",
"$",
"label",
";",
"}",
"else",
"{",
"$",
"translatable",
"=",
"isset",
"(",
"$",
"value",
"[",
"'translatable'",
"]",
")",
"?",
"$",
"value",
"[",
"'translatable'",
"]",
":",
"true",
";",
"$",
"transDomain",
"=",
"isset",
"(",
"$",
"value",
"[",
"'translation_domain'",
"]",
")",
"?",
"$",
"value",
"[",
"'translation_domain'",
"]",
":",
"$",
"domain",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'parameters'",
"]",
")",
")",
"{",
"$",
"params",
"=",
"$",
"value",
"[",
"'parameters'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"processArray",
"(",
"$",
"params",
",",
"$",
"domain",
")",
";",
"}",
"}",
"else",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"}",
"$",
"value",
"=",
"$",
"translatable",
"?",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"label",
",",
"$",
"params",
",",
"$",
"transDomain",
")",
":",
"strtr",
"(",
"$",
"label",
",",
"$",
"params",
")",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"value",
"as",
"&",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"$",
"this",
"->",
"processArray",
"(",
"$",
"val",
",",
"$",
"domain",
")",
";",
"}",
"}",
"}",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"'label'",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"value",
"as",
"&",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"$",
"this",
"->",
"processArray",
"(",
"$",
"val",
",",
"$",
"domain",
")",
";",
"}",
"}",
"}",
"}"
] | @param array $value
@param string|null $domain
@SuppressWarnings(PHPMD.NPathComplexity) | [
"@param",
"array",
"$value",
"@param",
"string|null",
"$domain"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Templating/TextHelper.php#L52-L96 |
AOEpeople/Aoe_Layout | app/code/local/Aoe/Layout/Block/Widget/Grid/Column/Renderer/Select.php | Aoe_Layout_Block_Widget_Grid_Column_Renderer_Select.render | public function render(Varien_Object $row)
{
$name = trim($this->getColumn()->getNamePattern());
if (!empty($name)) {
$nameParams = array_map('trim', array_filter(explode(',', $this->getColumn()->getNameParams())));
if (count($nameParams)) {
$params = [$name];
foreach ($nameParams as $key) {
$params[] = $row->getDataUsingMethod($key);
}
$name = call_user_func_array([$this, '__'], $params);
}
$this->getColumn()->setName($name);
}
return parent::render($row);
} | php | public function render(Varien_Object $row)
{
$name = trim($this->getColumn()->getNamePattern());
if (!empty($name)) {
$nameParams = array_map('trim', array_filter(explode(',', $this->getColumn()->getNameParams())));
if (count($nameParams)) {
$params = [$name];
foreach ($nameParams as $key) {
$params[] = $row->getDataUsingMethod($key);
}
$name = call_user_func_array([$this, '__'], $params);
}
$this->getColumn()->setName($name);
}
return parent::render($row);
} | [
"public",
"function",
"render",
"(",
"Varien_Object",
"$",
"row",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"$",
"this",
"->",
"getColumn",
"(",
")",
"->",
"getNamePattern",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"nameParams",
"=",
"array_map",
"(",
"'trim'",
",",
"array_filter",
"(",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"getColumn",
"(",
")",
"->",
"getNameParams",
"(",
")",
")",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"nameParams",
")",
")",
"{",
"$",
"params",
"=",
"[",
"$",
"name",
"]",
";",
"foreach",
"(",
"$",
"nameParams",
"as",
"$",
"key",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"row",
"->",
"getDataUsingMethod",
"(",
"$",
"key",
")",
";",
"}",
"$",
"name",
"=",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'__'",
"]",
",",
"$",
"params",
")",
";",
"}",
"$",
"this",
"->",
"getColumn",
"(",
")",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"}",
"return",
"parent",
"::",
"render",
"(",
"$",
"row",
")",
";",
"}"
] | Renders grid column
@param Varien_Object $row
@return string | [
"Renders",
"grid",
"column"
] | train | https://github.com/AOEpeople/Aoe_Layout/blob/d88ba3406cf12dbaf09548477133c3cb27d155ed/app/code/local/Aoe/Layout/Block/Widget/Grid/Column/Renderer/Select.php#L12-L29 |
chubbyphp/chubbyphp-model-doctrine-dbal | src/Command/CreateDatabaseCommand.php | CreateDatabaseCommand.createDatabase | private function createDatabase(
OutputInterface $output,
Connection $tmpConnection,
string $name,
bool $shouldNotCreateDatabase
): int {
try {
if ($shouldNotCreateDatabase) {
$output->writeln(sprintf('<info>Database <comment>%s</comment> already exists.</info>', $name));
} else {
$tmpConnection->getSchemaManager()->createDatabase($name);
$output->writeln(sprintf('<info>Created database <comment>%s</comment>', $name));
}
return 0;
} catch (\Exception $e) {
$output->writeln(sprintf('<error>Could not create database <comment>%s</comment></error>', $name));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;
}
} | php | private function createDatabase(
OutputInterface $output,
Connection $tmpConnection,
string $name,
bool $shouldNotCreateDatabase
): int {
try {
if ($shouldNotCreateDatabase) {
$output->writeln(sprintf('<info>Database <comment>%s</comment> already exists.</info>', $name));
} else {
$tmpConnection->getSchemaManager()->createDatabase($name);
$output->writeln(sprintf('<info>Created database <comment>%s</comment>', $name));
}
return 0;
} catch (\Exception $e) {
$output->writeln(sprintf('<error>Could not create database <comment>%s</comment></error>', $name));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;
}
} | [
"private",
"function",
"createDatabase",
"(",
"OutputInterface",
"$",
"output",
",",
"Connection",
"$",
"tmpConnection",
",",
"string",
"$",
"name",
",",
"bool",
"$",
"shouldNotCreateDatabase",
")",
":",
"int",
"{",
"try",
"{",
"if",
"(",
"$",
"shouldNotCreateDatabase",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>Database <comment>%s</comment> already exists.</info>'",
",",
"$",
"name",
")",
")",
";",
"}",
"else",
"{",
"$",
"tmpConnection",
"->",
"getSchemaManager",
"(",
")",
"->",
"createDatabase",
"(",
"$",
"name",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>Created database <comment>%s</comment>'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"0",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<error>Could not create database <comment>%s</comment></error>'",
",",
"$",
"name",
")",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<error>%s</error>'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"return",
"1",
";",
"}",
"}"
] | @param OutputInterface $output
@param Connection $tmpConnection
@param string $name
@param bool $shouldNotCreateDatabase
@return int | [
"@param",
"OutputInterface",
"$output",
"@param",
"Connection",
"$tmpConnection",
"@param",
"string",
"$name",
"@param",
"bool",
"$shouldNotCreateDatabase"
] | train | https://github.com/chubbyphp/chubbyphp-model-doctrine-dbal/blob/1079c28f5bffc2e2bec04122742d5008464c167f/src/Command/CreateDatabaseCommand.php#L101-L122 |
krakphp/job | src/ProcessManager/LoggingProcessManager.php | LoggingProcessManager.reap | public function reap() {
$reaped = $this->manager->reap();
$this->logger->info('ProcessManager::reap', [
'reaped' => $reaped
]);
return $reaped;
} | php | public function reap() {
$reaped = $this->manager->reap();
$this->logger->info('ProcessManager::reap', [
'reaped' => $reaped
]);
return $reaped;
} | [
"public",
"function",
"reap",
"(",
")",
"{",
"$",
"reaped",
"=",
"$",
"this",
"->",
"manager",
"->",
"reap",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'ProcessManager::reap'",
",",
"[",
"'reaped'",
"=>",
"$",
"reaped",
"]",
")",
";",
"return",
"$",
"reaped",
";",
"}"
] | Go through and remove all of the jobs that have finished. Returns an array of 3-tuples
`[$pid, $success, $output, $meta]`.
- `$success` is flag of true for success or false for error.
- `$output` is just the raw string content | [
"Go",
"through",
"and",
"remove",
"all",
"of",
"the",
"jobs",
"that",
"have",
"finished",
".",
"Returns",
"an",
"array",
"of",
"3",
"-",
"tuples",
"[",
"$pid",
"$success",
"$output",
"$meta",
"]",
"."
] | train | https://github.com/krakphp/job/blob/0c16020c1baa13d91f819ecba8334861ba7c4d6c/src/ProcessManager/LoggingProcessManager.php#L36-L42 |
mothership-ec/composer | src/Composer/Json/JsonFile.php | JsonFile.read | public function read()
{
try {
if ($this->rfs) {
$json = $this->rfs->getContents($this->path, $this->path, false);
} else {
$json = file_get_contents($this->path);
}
} catch (TransportException $e) {
throw new \RuntimeException($e->getMessage(), 0, $e);
} catch (\Exception $e) {
throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage());
}
return static::parseJson($json, $this->path);
} | php | public function read()
{
try {
if ($this->rfs) {
$json = $this->rfs->getContents($this->path, $this->path, false);
} else {
$json = file_get_contents($this->path);
}
} catch (TransportException $e) {
throw new \RuntimeException($e->getMessage(), 0, $e);
} catch (\Exception $e) {
throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage());
}
return static::parseJson($json, $this->path);
} | [
"public",
"function",
"read",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"rfs",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"rfs",
"->",
"getContents",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"this",
"->",
"path",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"json",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"path",
")",
";",
"}",
"}",
"catch",
"(",
"TransportException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Could not read '",
".",
"$",
"this",
"->",
"path",
".",
"\"\\n\\n\"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"static",
"::",
"parseJson",
"(",
"$",
"json",
",",
"$",
"this",
"->",
"path",
")",
";",
"}"
] | Reads json file.
@throws \RuntimeException
@return mixed | [
"Reads",
"json",
"file",
"."
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Json/JsonFile.php#L80-L95 |
mothership-ec/composer | src/Composer/Json/JsonFile.php | JsonFile.validateSchema | public function validateSchema($schema = self::STRICT_SCHEMA)
{
$content = file_get_contents($this->path);
$data = json_decode($content);
if (null === $data && 'null' !== $content) {
self::validateSyntax($content, $this->path);
}
$schemaFile = __DIR__ . '/../../../res/composer-schema.json';
$schemaData = json_decode(file_get_contents($schemaFile));
if ($schema === self::LAX_SCHEMA) {
$schemaData->additionalProperties = true;
$schemaData->required = array();
}
$validator = new Validator();
$validator->check($data, $schemaData);
// TODO add more validation like check version constraints and such, perhaps build that into the arrayloader?
if (!$validator->isValid()) {
$errors = array();
foreach ((array) $validator->getErrors() as $error) {
$errors[] = ($error['property'] ? $error['property'].' : ' : '').$error['message'];
}
throw new JsonValidationException('"'.$this->path.'" does not match the expected JSON schema', $errors);
}
return true;
} | php | public function validateSchema($schema = self::STRICT_SCHEMA)
{
$content = file_get_contents($this->path);
$data = json_decode($content);
if (null === $data && 'null' !== $content) {
self::validateSyntax($content, $this->path);
}
$schemaFile = __DIR__ . '/../../../res/composer-schema.json';
$schemaData = json_decode(file_get_contents($schemaFile));
if ($schema === self::LAX_SCHEMA) {
$schemaData->additionalProperties = true;
$schemaData->required = array();
}
$validator = new Validator();
$validator->check($data, $schemaData);
// TODO add more validation like check version constraints and such, perhaps build that into the arrayloader?
if (!$validator->isValid()) {
$errors = array();
foreach ((array) $validator->getErrors() as $error) {
$errors[] = ($error['property'] ? $error['property'].' : ' : '').$error['message'];
}
throw new JsonValidationException('"'.$this->path.'" does not match the expected JSON schema', $errors);
}
return true;
} | [
"public",
"function",
"validateSchema",
"(",
"$",
"schema",
"=",
"self",
"::",
"STRICT_SCHEMA",
")",
"{",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"path",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"content",
")",
";",
"if",
"(",
"null",
"===",
"$",
"data",
"&&",
"'null'",
"!==",
"$",
"content",
")",
"{",
"self",
"::",
"validateSyntax",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"path",
")",
";",
"}",
"$",
"schemaFile",
"=",
"__DIR__",
".",
"'/../../../res/composer-schema.json'",
";",
"$",
"schemaData",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"schemaFile",
")",
")",
";",
"if",
"(",
"$",
"schema",
"===",
"self",
"::",
"LAX_SCHEMA",
")",
"{",
"$",
"schemaData",
"->",
"additionalProperties",
"=",
"true",
";",
"$",
"schemaData",
"->",
"required",
"=",
"array",
"(",
")",
";",
"}",
"$",
"validator",
"=",
"new",
"Validator",
"(",
")",
";",
"$",
"validator",
"->",
"check",
"(",
"$",
"data",
",",
"$",
"schemaData",
")",
";",
"// TODO add more validation like check version constraints and such, perhaps build that into the arrayloader?",
"if",
"(",
"!",
"$",
"validator",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"validator",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"(",
"$",
"error",
"[",
"'property'",
"]",
"?",
"$",
"error",
"[",
"'property'",
"]",
".",
"' : '",
":",
"''",
")",
".",
"$",
"error",
"[",
"'message'",
"]",
";",
"}",
"throw",
"new",
"JsonValidationException",
"(",
"'\"'",
".",
"$",
"this",
"->",
"path",
".",
"'\" does not match the expected JSON schema'",
",",
"$",
"errors",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Validates the schema of the current json file according to composer-schema.json rules
@param int $schema a JsonFile::*_SCHEMA constant
@return bool true on success
@throws JsonValidationException | [
"Validates",
"the",
"schema",
"of",
"the",
"current",
"json",
"file",
"according",
"to",
"composer",
"-",
"schema",
".",
"json",
"rules"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Json/JsonFile.php#L143-L174 |
gdbots/iam-php | src/UpdateRoleHandler.php | UpdateRoleHandler.beforePutEvents | protected function beforePutEvents(NodeUpdated $event, UpdateNode $command, Pbjx $pbjx): void
{
parent::beforePutEvents($event, $command, $pbjx);
/** @var Role $newNode */
$newNode = $event->get('new_node');
$newNode
// a role can only be "published"
->set('status', NodeStatus::PUBLISHED())
->set('title', (string)$newNode->get('_id'));
} | php | protected function beforePutEvents(NodeUpdated $event, UpdateNode $command, Pbjx $pbjx): void
{
parent::beforePutEvents($event, $command, $pbjx);
/** @var Role $newNode */
$newNode = $event->get('new_node');
$newNode
// a role can only be "published"
->set('status', NodeStatus::PUBLISHED())
->set('title', (string)$newNode->get('_id'));
} | [
"protected",
"function",
"beforePutEvents",
"(",
"NodeUpdated",
"$",
"event",
",",
"UpdateNode",
"$",
"command",
",",
"Pbjx",
"$",
"pbjx",
")",
":",
"void",
"{",
"parent",
"::",
"beforePutEvents",
"(",
"$",
"event",
",",
"$",
"command",
",",
"$",
"pbjx",
")",
";",
"/** @var Role $newNode */",
"$",
"newNode",
"=",
"$",
"event",
"->",
"get",
"(",
"'new_node'",
")",
";",
"$",
"newNode",
"// a role can only be \"published\"",
"->",
"set",
"(",
"'status'",
",",
"NodeStatus",
"::",
"PUBLISHED",
"(",
")",
")",
"->",
"set",
"(",
"'title'",
",",
"(",
"string",
")",
"$",
"newNode",
"->",
"get",
"(",
"'_id'",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/gdbots/iam-php/blob/3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3/src/UpdateRoleHandler.php#L29-L39 |
Innmind/Graphviz | src/Graph/Graph.php | Graph.nodes | public function nodes(): SetInterface
{
$map = $this->roots->reduce(
new Map('string', Node::class),
function(Map $nodes, Node $node): Map {
return $this->accumulateNodes($nodes, $node);
}
);
return Set::of(Node::class, ...$map->values());
} | php | public function nodes(): SetInterface
{
$map = $this->roots->reduce(
new Map('string', Node::class),
function(Map $nodes, Node $node): Map {
return $this->accumulateNodes($nodes, $node);
}
);
return Set::of(Node::class, ...$map->values());
} | [
"public",
"function",
"nodes",
"(",
")",
":",
"SetInterface",
"{",
"$",
"map",
"=",
"$",
"this",
"->",
"roots",
"->",
"reduce",
"(",
"new",
"Map",
"(",
"'string'",
",",
"Node",
"::",
"class",
")",
",",
"function",
"(",
"Map",
"$",
"nodes",
",",
"Node",
"$",
"node",
")",
":",
"Map",
"{",
"return",
"$",
"this",
"->",
"accumulateNodes",
"(",
"$",
"nodes",
",",
"$",
"node",
")",
";",
"}",
")",
";",
"return",
"Set",
"::",
"of",
"(",
"Node",
"::",
"class",
",",
"...",
"$",
"map",
"->",
"values",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Innmind/Graphviz/blob/6912f22a1482045e53e83477fcd04f29ad7cf85c/src/Graph/Graph.php#L100-L110 |
mvccore/ext-router-module | src/MvcCore/Ext/Routers/Module/PreAndPostRouting.php | PreAndPostRouting.routeDetectStrategy | protected function routeDetectStrategy () {
list($requestCtrlName, $requestActionName) = parent::routeDetectStrategy();
if (!$this->internalRequest) $this->domainRouting();
return [$requestCtrlName, $requestActionName];
} | php | protected function routeDetectStrategy () {
list($requestCtrlName, $requestActionName) = parent::routeDetectStrategy();
if (!$this->internalRequest) $this->domainRouting();
return [$requestCtrlName, $requestActionName];
} | [
"protected",
"function",
"routeDetectStrategy",
"(",
")",
"{",
"list",
"(",
"$",
"requestCtrlName",
",",
"$",
"requestActionName",
")",
"=",
"parent",
"::",
"routeDetectStrategy",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"internalRequest",
")",
"$",
"this",
"->",
"domainRouting",
"(",
")",
";",
"return",
"[",
"$",
"requestCtrlName",
",",
"$",
"requestActionName",
"]",
";",
"}"
] | Process normal route strategy detection from core router and than process
domain routing, if request is not internal.
Return array with possible query string controller name and action.
@throws \LogicException Route configuration property is missing.
@throws \InvalidArgumentException Wrong route pattern format.
@return array | [
"Process",
"normal",
"route",
"strategy",
"detection",
"from",
"core",
"router",
"and",
"than",
"process",
"domain",
"routing",
"if",
"request",
"is",
"not",
"internal",
".",
"Return",
"array",
"with",
"possible",
"query",
"string",
"controller",
"name",
"and",
"action",
"."
] | train | https://github.com/mvccore/ext-router-module/blob/7695784a451db86cca6a43c98d076803cd0a50a7/src/MvcCore/Ext/Routers/Module/PreAndPostRouting.php#L26-L30 |
mvccore/ext-router-module | src/MvcCore/Ext/Routers/Module/PreAndPostRouting.php | PreAndPostRouting.routeSetUpDefaultForHomeIfNoMatch | protected function routeSetUpDefaultForHomeIfNoMatch () {
/** @var $this \MvcCore\Ext\Routers\Module */
$domainRouteNamespace = NULL;
if ($this->currentDomainRoute !== NULL)
$domainRouteNamespace = $this->currentDomainRoute->GetNamespace();
if ($this->currentRoute === NULL) {
$request = & $this->request;
$requestIsHome = (
trim($request->GetPath(), '/') == '' ||
$request->GetPath() == $request->GetScriptName()
);
if ($requestIsHome || $this->routeToDefaultIfNotMatch) {
list($dfltCtrl, $dftlAction) = $this->application->GetDefaultControllerAndActionNames();
if ($domainRouteNamespace !== NULL) {
if (substr($dfltCtrl, 0, 2) != '//' && substr($dfltCtrl, 0, 1) != '\\')
$dfltCtrl = rtrim($domainRouteNamespace, '\\') . '\\' . $dfltCtrl;
}
$this->SetOrCreateDefaultRouteAsCurrent(
static::DEFAULT_ROUTE_NAME, $dfltCtrl, $dftlAction
);
// set up requested params from query string if there are any
// (and path if there is path from previous fn)
$requestParams = array_merge([], $this->request->GetParams(FALSE));
unset($requestParams[static::URL_PARAM_CONTROLLER], $requestParams[static::URL_PARAM_ACTION]);
$this->requestedParams = & $requestParams;
}
} else if ($domainRouteNamespace !== NULL) {
$currentRouteCtrl = $this->currentRoute->GetController();
if (substr($currentRouteCtrl, 0, 2) != '//' && substr($currentRouteCtrl, 0, 1) != '\\') {
$currentRouteCtrl = rtrim($domainRouteNamespace, '\\') . '\\' . $currentRouteCtrl;
$this->RedefineRoutedTarget($currentRouteCtrl, NULL, TRUE);
}
}
return $this;
} | php | protected function routeSetUpDefaultForHomeIfNoMatch () {
/** @var $this \MvcCore\Ext\Routers\Module */
$domainRouteNamespace = NULL;
if ($this->currentDomainRoute !== NULL)
$domainRouteNamespace = $this->currentDomainRoute->GetNamespace();
if ($this->currentRoute === NULL) {
$request = & $this->request;
$requestIsHome = (
trim($request->GetPath(), '/') == '' ||
$request->GetPath() == $request->GetScriptName()
);
if ($requestIsHome || $this->routeToDefaultIfNotMatch) {
list($dfltCtrl, $dftlAction) = $this->application->GetDefaultControllerAndActionNames();
if ($domainRouteNamespace !== NULL) {
if (substr($dfltCtrl, 0, 2) != '//' && substr($dfltCtrl, 0, 1) != '\\')
$dfltCtrl = rtrim($domainRouteNamespace, '\\') . '\\' . $dfltCtrl;
}
$this->SetOrCreateDefaultRouteAsCurrent(
static::DEFAULT_ROUTE_NAME, $dfltCtrl, $dftlAction
);
// set up requested params from query string if there are any
// (and path if there is path from previous fn)
$requestParams = array_merge([], $this->request->GetParams(FALSE));
unset($requestParams[static::URL_PARAM_CONTROLLER], $requestParams[static::URL_PARAM_ACTION]);
$this->requestedParams = & $requestParams;
}
} else if ($domainRouteNamespace !== NULL) {
$currentRouteCtrl = $this->currentRoute->GetController();
if (substr($currentRouteCtrl, 0, 2) != '//' && substr($currentRouteCtrl, 0, 1) != '\\') {
$currentRouteCtrl = rtrim($domainRouteNamespace, '\\') . '\\' . $currentRouteCtrl;
$this->RedefineRoutedTarget($currentRouteCtrl, NULL, TRUE);
}
}
return $this;
} | [
"protected",
"function",
"routeSetUpDefaultForHomeIfNoMatch",
"(",
")",
"{",
"/** @var $this \\MvcCore\\Ext\\Routers\\Module */",
"$",
"domainRouteNamespace",
"=",
"NULL",
";",
"if",
"(",
"$",
"this",
"->",
"currentDomainRoute",
"!==",
"NULL",
")",
"$",
"domainRouteNamespace",
"=",
"$",
"this",
"->",
"currentDomainRoute",
"->",
"GetNamespace",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"currentRoute",
"===",
"NULL",
")",
"{",
"$",
"request",
"=",
"&",
"$",
"this",
"->",
"request",
";",
"$",
"requestIsHome",
"=",
"(",
"trim",
"(",
"$",
"request",
"->",
"GetPath",
"(",
")",
",",
"'/'",
")",
"==",
"''",
"||",
"$",
"request",
"->",
"GetPath",
"(",
")",
"==",
"$",
"request",
"->",
"GetScriptName",
"(",
")",
")",
";",
"if",
"(",
"$",
"requestIsHome",
"||",
"$",
"this",
"->",
"routeToDefaultIfNotMatch",
")",
"{",
"list",
"(",
"$",
"dfltCtrl",
",",
"$",
"dftlAction",
")",
"=",
"$",
"this",
"->",
"application",
"->",
"GetDefaultControllerAndActionNames",
"(",
")",
";",
"if",
"(",
"$",
"domainRouteNamespace",
"!==",
"NULL",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"dfltCtrl",
",",
"0",
",",
"2",
")",
"!=",
"'//'",
"&&",
"substr",
"(",
"$",
"dfltCtrl",
",",
"0",
",",
"1",
")",
"!=",
"'\\\\'",
")",
"$",
"dfltCtrl",
"=",
"rtrim",
"(",
"$",
"domainRouteNamespace",
",",
"'\\\\'",
")",
".",
"'\\\\'",
".",
"$",
"dfltCtrl",
";",
"}",
"$",
"this",
"->",
"SetOrCreateDefaultRouteAsCurrent",
"(",
"static",
"::",
"DEFAULT_ROUTE_NAME",
",",
"$",
"dfltCtrl",
",",
"$",
"dftlAction",
")",
";",
"// set up requested params from query string if there are any ",
"// (and path if there is path from previous fn)",
"$",
"requestParams",
"=",
"array_merge",
"(",
"[",
"]",
",",
"$",
"this",
"->",
"request",
"->",
"GetParams",
"(",
"FALSE",
")",
")",
";",
"unset",
"(",
"$",
"requestParams",
"[",
"static",
"::",
"URL_PARAM_CONTROLLER",
"]",
",",
"$",
"requestParams",
"[",
"static",
"::",
"URL_PARAM_ACTION",
"]",
")",
";",
"$",
"this",
"->",
"requestedParams",
"=",
"&",
"$",
"requestParams",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"domainRouteNamespace",
"!==",
"NULL",
")",
"{",
"$",
"currentRouteCtrl",
"=",
"$",
"this",
"->",
"currentRoute",
"->",
"GetController",
"(",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"currentRouteCtrl",
",",
"0",
",",
"2",
")",
"!=",
"'//'",
"&&",
"substr",
"(",
"$",
"currentRouteCtrl",
",",
"0",
",",
"1",
")",
"!=",
"'\\\\'",
")",
"{",
"$",
"currentRouteCtrl",
"=",
"rtrim",
"(",
"$",
"domainRouteNamespace",
",",
"'\\\\'",
")",
".",
"'\\\\'",
".",
"$",
"currentRouteCtrl",
";",
"$",
"this",
"->",
"RedefineRoutedTarget",
"(",
"$",
"currentRouteCtrl",
",",
"NULL",
",",
"TRUE",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | After routing is done, check if there is any current domain route and
remember it's possible namespace value. Then check if there is any current
route.
If there is no current route found by any strategy, there is possible to
create automatically new default route into current route property by
configured default controller/action values. Then it's necessary to check
if request is targeting homepage or if router is configured to route
request to default controller and action. If those two conditions are OK,
create new route with default controller and action but in module router,
create that new route with controller in namespace by domain route if
there is any) and set this new route as current route to process default
controller and action even if there is no route for it.
If there is current route defined and domain route namespace is not
`NULL`, there is necessary to prepend domain route namespace into routed
controller name and redefine routed target. But prepend domain route
namespace into routed controller only if routed controller definition is
defined relatively and if it not start with two slashes (`//`) or with
single backslash (`\`).
@return \MvcCore\Ext\Routers\Module | [
"After",
"routing",
"is",
"done",
"check",
"if",
"there",
"is",
"any",
"current",
"domain",
"route",
"and",
"remember",
"it",
"s",
"possible",
"namespace",
"value",
".",
"Then",
"check",
"if",
"there",
"is",
"any",
"current",
"route",
".",
"If",
"there",
"is",
"no",
"current",
"route",
"found",
"by",
"any",
"strategy",
"there",
"is",
"possible",
"to",
"create",
"automatically",
"new",
"default",
"route",
"into",
"current",
"route",
"property",
"by",
"configured",
"default",
"controller",
"/",
"action",
"values",
".",
"Then",
"it",
"s",
"necessary",
"to",
"check",
"if",
"request",
"is",
"targeting",
"homepage",
"or",
"if",
"router",
"is",
"configured",
"to",
"route",
"request",
"to",
"default",
"controller",
"and",
"action",
".",
"If",
"those",
"two",
"conditions",
"are",
"OK",
"create",
"new",
"route",
"with",
"default",
"controller",
"and",
"action",
"but",
"in",
"module",
"router",
"create",
"that",
"new",
"route",
"with",
"controller",
"in",
"namespace",
"by",
"domain",
"route",
"if",
"there",
"is",
"any",
")",
"and",
"set",
"this",
"new",
"route",
"as",
"current",
"route",
"to",
"process",
"default",
"controller",
"and",
"action",
"even",
"if",
"there",
"is",
"no",
"route",
"for",
"it",
".",
"If",
"there",
"is",
"current",
"route",
"defined",
"and",
"domain",
"route",
"namespace",
"is",
"not",
"NULL",
"there",
"is",
"necessary",
"to",
"prepend",
"domain",
"route",
"namespace",
"into",
"routed",
"controller",
"name",
"and",
"redefine",
"routed",
"target",
".",
"But",
"prepend",
"domain",
"route",
"namespace",
"into",
"routed",
"controller",
"only",
"if",
"routed",
"controller",
"definition",
"is",
"defined",
"relatively",
"and",
"if",
"it",
"not",
"start",
"with",
"two",
"slashes",
"(",
"//",
")",
"or",
"with",
"single",
"backslash",
"(",
"\\",
")",
"."
] | train | https://github.com/mvccore/ext-router-module/blob/7695784a451db86cca6a43c98d076803cd0a50a7/src/MvcCore/Ext/Routers/Module/PreAndPostRouting.php#L53-L87 |
superjimpupcake/Pupcake | src/Pupcake/Router.php | Router.routeMatched | public function routeMatched($request_type, $route_pattern, $query_path)
{
$matched = $this->app->trigger(
'system.request.route.matching',
array($this, 'processRouteMatching'),
array(
'request_type'=> $request_type,
'query_path' => $query_path,
'route_pattern' => $route_pattern
)
);
return $matched;
} | php | public function routeMatched($request_type, $route_pattern, $query_path)
{
$matched = $this->app->trigger(
'system.request.route.matching',
array($this, 'processRouteMatching'),
array(
'request_type'=> $request_type,
'query_path' => $query_path,
'route_pattern' => $route_pattern
)
);
return $matched;
} | [
"public",
"function",
"routeMatched",
"(",
"$",
"request_type",
",",
"$",
"route_pattern",
",",
"$",
"query_path",
")",
"{",
"$",
"matched",
"=",
"$",
"this",
"->",
"app",
"->",
"trigger",
"(",
"'system.request.route.matching'",
",",
"array",
"(",
"$",
"this",
",",
"'processRouteMatching'",
")",
",",
"array",
"(",
"'request_type'",
"=>",
"$",
"request_type",
",",
"'query_path'",
"=>",
"$",
"query_path",
",",
"'route_pattern'",
"=>",
"$",
"route_pattern",
")",
")",
";",
"return",
"$",
"matched",
";",
"}"
] | check if a route is matched given a query path | [
"check",
"if",
"a",
"route",
"is",
"matched",
"given",
"a",
"query",
"path"
] | train | https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Router.php#L86-L99 |
superjimpupcake/Pupcake | src/Pupcake/Router.php | Router.findMatchedRoute | public function findMatchedRoute($request_method = "", $query_path = "", $route_map)
{
$query_path = $this->normalize($query_path);
$request_matched = false;
$output = "";
if (count($route_map) > 0) {
$request_types = array_keys($route_map);
$request_types_to_lookup = array();
foreach ($request_types as $request_type) {
if ($request_type == $request_method || $request_type == "*") {
$request_types_to_lookup[] = $request_type;
}
}
foreach ($request_types_to_lookup as $request_type) {
if (isset($route_map[$request_type]) && count($route_map[$request_type]) > 0) {
foreach ($route_map[$request_type] as $route_pattern => $route) {
//once we found there is a matched route, stop
$matched = $this->routeMatched($request_type, $route_pattern, $query_path);
if ($matched) {
$request_matched = true;
break 2;
}
}
}
}
}
return $request_matched;
} | php | public function findMatchedRoute($request_method = "", $query_path = "", $route_map)
{
$query_path = $this->normalize($query_path);
$request_matched = false;
$output = "";
if (count($route_map) > 0) {
$request_types = array_keys($route_map);
$request_types_to_lookup = array();
foreach ($request_types as $request_type) {
if ($request_type == $request_method || $request_type == "*") {
$request_types_to_lookup[] = $request_type;
}
}
foreach ($request_types_to_lookup as $request_type) {
if (isset($route_map[$request_type]) && count($route_map[$request_type]) > 0) {
foreach ($route_map[$request_type] as $route_pattern => $route) {
//once we found there is a matched route, stop
$matched = $this->routeMatched($request_type, $route_pattern, $query_path);
if ($matched) {
$request_matched = true;
break 2;
}
}
}
}
}
return $request_matched;
} | [
"public",
"function",
"findMatchedRoute",
"(",
"$",
"request_method",
"=",
"\"\"",
",",
"$",
"query_path",
"=",
"\"\"",
",",
"$",
"route_map",
")",
"{",
"$",
"query_path",
"=",
"$",
"this",
"->",
"normalize",
"(",
"$",
"query_path",
")",
";",
"$",
"request_matched",
"=",
"false",
";",
"$",
"output",
"=",
"\"\"",
";",
"if",
"(",
"count",
"(",
"$",
"route_map",
")",
">",
"0",
")",
"{",
"$",
"request_types",
"=",
"array_keys",
"(",
"$",
"route_map",
")",
";",
"$",
"request_types_to_lookup",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"request_types",
"as",
"$",
"request_type",
")",
"{",
"if",
"(",
"$",
"request_type",
"==",
"$",
"request_method",
"||",
"$",
"request_type",
"==",
"\"*\"",
")",
"{",
"$",
"request_types_to_lookup",
"[",
"]",
"=",
"$",
"request_type",
";",
"}",
"}",
"foreach",
"(",
"$",
"request_types_to_lookup",
"as",
"$",
"request_type",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"route_map",
"[",
"$",
"request_type",
"]",
")",
"&&",
"count",
"(",
"$",
"route_map",
"[",
"$",
"request_type",
"]",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"route_map",
"[",
"$",
"request_type",
"]",
"as",
"$",
"route_pattern",
"=>",
"$",
"route",
")",
"{",
"//once we found there is a matched route, stop",
"$",
"matched",
"=",
"$",
"this",
"->",
"routeMatched",
"(",
"$",
"request_type",
",",
"$",
"route_pattern",
",",
"$",
"query_path",
")",
";",
"if",
"(",
"$",
"matched",
")",
"{",
"$",
"request_matched",
"=",
"true",
";",
"break",
"2",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"request_matched",
";",
"}"
] | find a route | [
"find",
"a",
"route"
] | train | https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Router.php#L104-L133 |
superjimpupcake/Pupcake | src/Pupcake/Router.php | Router.processRouteMatchingNative | public function processRouteMatchingNative($event)
{
$request_type = $event->props('request_type');
$uri = $event->props('query_path');
$route_pattern= $event->props('route_pattern');
$result = false;
$params = array();
$route_pattern_length = strlen($route_pattern);
$path_pos = strpos($route_pattern, "*path"); //see if there is *path exists
if ($path_pos !== FALSE) {
$first_part_of_path = substr($route_pattern, 0, $path_pos);
if (substr($uri, 0, $path_pos) == $first_part_of_path) {
$uri_length = strlen($uri);
$params[":path"] = substr($uri, $path_pos, $uri_length - $path_pos);
$route = $this->getRoute($request_type, $route_pattern);
$route->setParams($params);
$this->setMatchedRoute($route);
$result = true;
return $result;
}
}
$uri_comps = explode("/", $uri);
$uri_comps_count = count($uri_comps);
$route_pattern_comps = explode("/", $route_pattern);
$route_pattern_comps_count = count($route_pattern_comps);
if ($uri_comps_count == $route_pattern_comps_count) {
for ($k=1;$k<$route_pattern_comps_count;$k++ ) { //we should start from index 1 since index 0 is the /
if ($route_pattern_comps[$k][0] == ":") {
$token = $route_pattern_comps[$k];
$params[$token] = $uri_comps[$k];
$route_pattern_comps[$k] = "";
$uri_comps[$k] = "";
}
}
$uri_reformed = implode("/",$uri_comps);
$route_pattern_reformed = implode("/",$route_pattern_comps);
$route = $this->getRoute($request_type, $route_pattern);
$route->setParams($params);
if ($uri_reformed == $route_pattern_reformed) {
$results = $this->app->trigger("system.routing.route.matched", "", array('route' => $route));
//the result can be either a boolean or an array
$result = true;
if ( is_array($results) && count($results) > 0 ) { //the result is an array
foreach ($results as $matched) {
if (!$matched) {
$result = false;
break;
}
}
}
else if ($results === FALSE) {
$result = false;
}
if ($result) {
$this->setMatchedRoute($route);
}
}
}
return $result;
} | php | public function processRouteMatchingNative($event)
{
$request_type = $event->props('request_type');
$uri = $event->props('query_path');
$route_pattern= $event->props('route_pattern');
$result = false;
$params = array();
$route_pattern_length = strlen($route_pattern);
$path_pos = strpos($route_pattern, "*path"); //see if there is *path exists
if ($path_pos !== FALSE) {
$first_part_of_path = substr($route_pattern, 0, $path_pos);
if (substr($uri, 0, $path_pos) == $first_part_of_path) {
$uri_length = strlen($uri);
$params[":path"] = substr($uri, $path_pos, $uri_length - $path_pos);
$route = $this->getRoute($request_type, $route_pattern);
$route->setParams($params);
$this->setMatchedRoute($route);
$result = true;
return $result;
}
}
$uri_comps = explode("/", $uri);
$uri_comps_count = count($uri_comps);
$route_pattern_comps = explode("/", $route_pattern);
$route_pattern_comps_count = count($route_pattern_comps);
if ($uri_comps_count == $route_pattern_comps_count) {
for ($k=1;$k<$route_pattern_comps_count;$k++ ) { //we should start from index 1 since index 0 is the /
if ($route_pattern_comps[$k][0] == ":") {
$token = $route_pattern_comps[$k];
$params[$token] = $uri_comps[$k];
$route_pattern_comps[$k] = "";
$uri_comps[$k] = "";
}
}
$uri_reformed = implode("/",$uri_comps);
$route_pattern_reformed = implode("/",$route_pattern_comps);
$route = $this->getRoute($request_type, $route_pattern);
$route->setParams($params);
if ($uri_reformed == $route_pattern_reformed) {
$results = $this->app->trigger("system.routing.route.matched", "", array('route' => $route));
//the result can be either a boolean or an array
$result = true;
if ( is_array($results) && count($results) > 0 ) { //the result is an array
foreach ($results as $matched) {
if (!$matched) {
$result = false;
break;
}
}
}
else if ($results === FALSE) {
$result = false;
}
if ($result) {
$this->setMatchedRoute($route);
}
}
}
return $result;
} | [
"public",
"function",
"processRouteMatchingNative",
"(",
"$",
"event",
")",
"{",
"$",
"request_type",
"=",
"$",
"event",
"->",
"props",
"(",
"'request_type'",
")",
";",
"$",
"uri",
"=",
"$",
"event",
"->",
"props",
"(",
"'query_path'",
")",
";",
"$",
"route_pattern",
"=",
"$",
"event",
"->",
"props",
"(",
"'route_pattern'",
")",
";",
"$",
"result",
"=",
"false",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"route_pattern_length",
"=",
"strlen",
"(",
"$",
"route_pattern",
")",
";",
"$",
"path_pos",
"=",
"strpos",
"(",
"$",
"route_pattern",
",",
"\"*path\"",
")",
";",
"//see if there is *path exists",
"if",
"(",
"$",
"path_pos",
"!==",
"FALSE",
")",
"{",
"$",
"first_part_of_path",
"=",
"substr",
"(",
"$",
"route_pattern",
",",
"0",
",",
"$",
"path_pos",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"$",
"path_pos",
")",
"==",
"$",
"first_part_of_path",
")",
"{",
"$",
"uri_length",
"=",
"strlen",
"(",
"$",
"uri",
")",
";",
"$",
"params",
"[",
"\":path\"",
"]",
"=",
"substr",
"(",
"$",
"uri",
",",
"$",
"path_pos",
",",
"$",
"uri_length",
"-",
"$",
"path_pos",
")",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"getRoute",
"(",
"$",
"request_type",
",",
"$",
"route_pattern",
")",
";",
"$",
"route",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setMatchedRoute",
"(",
"$",
"route",
")",
";",
"$",
"result",
"=",
"true",
";",
"return",
"$",
"result",
";",
"}",
"}",
"$",
"uri_comps",
"=",
"explode",
"(",
"\"/\"",
",",
"$",
"uri",
")",
";",
"$",
"uri_comps_count",
"=",
"count",
"(",
"$",
"uri_comps",
")",
";",
"$",
"route_pattern_comps",
"=",
"explode",
"(",
"\"/\"",
",",
"$",
"route_pattern",
")",
";",
"$",
"route_pattern_comps_count",
"=",
"count",
"(",
"$",
"route_pattern_comps",
")",
";",
"if",
"(",
"$",
"uri_comps_count",
"==",
"$",
"route_pattern_comps_count",
")",
"{",
"for",
"(",
"$",
"k",
"=",
"1",
";",
"$",
"k",
"<",
"$",
"route_pattern_comps_count",
";",
"$",
"k",
"++",
")",
"{",
"//we should start from index 1 since index 0 is the /",
"if",
"(",
"$",
"route_pattern_comps",
"[",
"$",
"k",
"]",
"[",
"0",
"]",
"==",
"\":\"",
")",
"{",
"$",
"token",
"=",
"$",
"route_pattern_comps",
"[",
"$",
"k",
"]",
";",
"$",
"params",
"[",
"$",
"token",
"]",
"=",
"$",
"uri_comps",
"[",
"$",
"k",
"]",
";",
"$",
"route_pattern_comps",
"[",
"$",
"k",
"]",
"=",
"\"\"",
";",
"$",
"uri_comps",
"[",
"$",
"k",
"]",
"=",
"\"\"",
";",
"}",
"}",
"$",
"uri_reformed",
"=",
"implode",
"(",
"\"/\"",
",",
"$",
"uri_comps",
")",
";",
"$",
"route_pattern_reformed",
"=",
"implode",
"(",
"\"/\"",
",",
"$",
"route_pattern_comps",
")",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"getRoute",
"(",
"$",
"request_type",
",",
"$",
"route_pattern",
")",
";",
"$",
"route",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"uri_reformed",
"==",
"$",
"route_pattern_reformed",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"app",
"->",
"trigger",
"(",
"\"system.routing.route.matched\"",
",",
"\"\"",
",",
"array",
"(",
"'route'",
"=>",
"$",
"route",
")",
")",
";",
"//the result can be either a boolean or an array ",
"$",
"result",
"=",
"true",
";",
"if",
"(",
"is_array",
"(",
"$",
"results",
")",
"&&",
"count",
"(",
"$",
"results",
")",
">",
"0",
")",
"{",
"//the result is an array",
"foreach",
"(",
"$",
"results",
"as",
"$",
"matched",
")",
"{",
"if",
"(",
"!",
"$",
"matched",
")",
"{",
"$",
"result",
"=",
"false",
";",
"break",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"$",
"results",
"===",
"FALSE",
")",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"setMatchedRoute",
"(",
"$",
"route",
")",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | process route matching
@param Event the event object
@return boolean whether the route matched the uri or not | [
"process",
"route",
"matching"
] | train | https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Router.php#L140-L207 |
Innmind/neo4j-dbal | src/Clause/SetClause.php | SetClause.withParameter | public function withParameter(string $key, $value): Clause
{
if (Str::of($key)->empty()) {
throw new DomainException;
}
$set = new self($this->cypher);
$set->parameters = $this->parameters->put(
$key,
new Parameter($key, $value)
);
return $set;
} | php | public function withParameter(string $key, $value): Clause
{
if (Str::of($key)->empty()) {
throw new DomainException;
}
$set = new self($this->cypher);
$set->parameters = $this->parameters->put(
$key,
new Parameter($key, $value)
);
return $set;
} | [
"public",
"function",
"withParameter",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"Clause",
"{",
"if",
"(",
"Str",
"::",
"of",
"(",
"$",
"key",
")",
"->",
"empty",
"(",
")",
")",
"{",
"throw",
"new",
"DomainException",
";",
"}",
"$",
"set",
"=",
"new",
"self",
"(",
"$",
"this",
"->",
"cypher",
")",
";",
"$",
"set",
"->",
"parameters",
"=",
"$",
"this",
"->",
"parameters",
"->",
"put",
"(",
"$",
"key",
",",
"new",
"Parameter",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
";",
"return",
"$",
"set",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Clause/SetClause.php#L53-L66 |
Eresus/EresusCMS | src/core/settings.php | TSettings.mkstr | private function mkstr($name, $type = 'string', $options = array())
{
$result = " define('$name', ";
$quot = "'";
$value = isset($_POST[$name]) ? $_POST[$name] : null;
if (isset($options['nobr']) && $options['nobr'])
{
$value = str_replace(array("\n", "\r"), ' ', $value);
}
if (isset($options['savebr']) && $options['savebr'])
{
$value = addcslashes($value, "\n\r\"");
$quot = '"';
}
switch ($type)
{
case 'string':
$value = str_replace(
array('\\', $quot),
array('\\\\', '\\' . $quot),
$value
);
$value = $quot . $value . $quot;
break;
case 'bool':
$value = $value ? 'true' : 'false';
break;
case 'int':
$value = intval($value);
break;
}
$result .= $value . ");\n";
return $result;
} | php | private function mkstr($name, $type = 'string', $options = array())
{
$result = " define('$name', ";
$quot = "'";
$value = isset($_POST[$name]) ? $_POST[$name] : null;
if (isset($options['nobr']) && $options['nobr'])
{
$value = str_replace(array("\n", "\r"), ' ', $value);
}
if (isset($options['savebr']) && $options['savebr'])
{
$value = addcslashes($value, "\n\r\"");
$quot = '"';
}
switch ($type)
{
case 'string':
$value = str_replace(
array('\\', $quot),
array('\\\\', '\\' . $quot),
$value
);
$value = $quot . $value . $quot;
break;
case 'bool':
$value = $value ? 'true' : 'false';
break;
case 'int':
$value = intval($value);
break;
}
$result .= $value . ");\n";
return $result;
} | [
"private",
"function",
"mkstr",
"(",
"$",
"name",
",",
"$",
"type",
"=",
"'string'",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"result",
"=",
"\" define('$name', \"",
";",
"$",
"quot",
"=",
"\"'\"",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"_POST",
"[",
"$",
"name",
"]",
":",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'nobr'",
"]",
")",
"&&",
"$",
"options",
"[",
"'nobr'",
"]",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"array",
"(",
"\"\\n\"",
",",
"\"\\r\"",
")",
",",
"' '",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'savebr'",
"]",
")",
"&&",
"$",
"options",
"[",
"'savebr'",
"]",
")",
"{",
"$",
"value",
"=",
"addcslashes",
"(",
"$",
"value",
",",
"\"\\n\\r\\\"\"",
")",
";",
"$",
"quot",
"=",
"'\"'",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'string'",
":",
"$",
"value",
"=",
"str_replace",
"(",
"array",
"(",
"'\\\\'",
",",
"$",
"quot",
")",
",",
"array",
"(",
"'\\\\\\\\'",
",",
"'\\\\'",
".",
"$",
"quot",
")",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"quot",
".",
"$",
"value",
".",
"$",
"quot",
";",
"break",
";",
"case",
"'bool'",
":",
"$",
"value",
"=",
"$",
"value",
"?",
"'true'",
":",
"'false'",
";",
"break",
";",
"case",
"'int'",
":",
"$",
"value",
"=",
"intval",
"(",
"$",
"value",
")",
";",
"break",
";",
"}",
"$",
"result",
".=",
"$",
"value",
".",
"\");\\n\"",
";",
"return",
"$",
"result",
";",
"}"
] | Создаёт строку параметра для записи в файл
@param string $name имя параметра
@param string $type тип: string, bool или int
@param array $options опции: nobr (true/false), savebr (true/false)
@return string | [
"Создаёт",
"строку",
"параметра",
"для",
"записи",
"в",
"файл"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/settings.php#L50-L86 |
Eresus/EresusCMS | src/core/settings.php | TSettings.update | private function update()
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '()');
$settings = "<?php\n";
$settings .= $this->mkstr('siteName', 'string');
$settings .= $this->mkstr('siteTitle', 'string');
$settings .= $this->mkstr('siteTitleReverse', 'bool');
$settings .= $this->mkstr('siteTitleDivider', 'string');
$settings .= $this->mkstr('siteKeywords', 'string', array('nobr'=>true));
$settings .= $this->mkstr('siteDescription', 'string', array('nobr'=>true));
$settings .= $this->mkstr('mailFromAddr', 'string');
$settings .= $this->mkstr('mailFromName', 'string');
$settings .= $this->mkstr('mailFromOrg', 'string');
$settings .= $this->mkstr('mailReplyTo', 'string');
$settings .= $this->mkstr('mailFromSign', 'string', array('savebr'=>true));
$settings .= $this->mkstr('filesModeSetOnUpload', 'bool');
$settings .= $this->mkstr('filesModeDefault', 'string');
$settings .= $this->mkstr('filesTranslitNames', 'bool');
$settings .= $this->mkstr('contentTypeDefault', 'string');
$settings .= $this->mkstr('pageTemplateDefault', 'string');
$legacyKernel = Eresus_Kernel::app()->getLegacyKernel();
file_put_contents($legacyKernel->froot . 'cfg/settings.php', $settings);
HTTP::goback();
} | php | private function update()
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '()');
$settings = "<?php\n";
$settings .= $this->mkstr('siteName', 'string');
$settings .= $this->mkstr('siteTitle', 'string');
$settings .= $this->mkstr('siteTitleReverse', 'bool');
$settings .= $this->mkstr('siteTitleDivider', 'string');
$settings .= $this->mkstr('siteKeywords', 'string', array('nobr'=>true));
$settings .= $this->mkstr('siteDescription', 'string', array('nobr'=>true));
$settings .= $this->mkstr('mailFromAddr', 'string');
$settings .= $this->mkstr('mailFromName', 'string');
$settings .= $this->mkstr('mailFromOrg', 'string');
$settings .= $this->mkstr('mailReplyTo', 'string');
$settings .= $this->mkstr('mailFromSign', 'string', array('savebr'=>true));
$settings .= $this->mkstr('filesModeSetOnUpload', 'bool');
$settings .= $this->mkstr('filesModeDefault', 'string');
$settings .= $this->mkstr('filesTranslitNames', 'bool');
$settings .= $this->mkstr('contentTypeDefault', 'string');
$settings .= $this->mkstr('pageTemplateDefault', 'string');
$legacyKernel = Eresus_Kernel::app()->getLegacyKernel();
file_put_contents($legacyKernel->froot . 'cfg/settings.php', $settings);
HTTP::goback();
} | [
"private",
"function",
"update",
"(",
")",
"{",
"Eresus_Kernel",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'()'",
")",
";",
"$",
"settings",
"=",
"\"<?php\\n\"",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'siteName'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'siteTitle'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'siteTitleReverse'",
",",
"'bool'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'siteTitleDivider'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'siteKeywords'",
",",
"'string'",
",",
"array",
"(",
"'nobr'",
"=>",
"true",
")",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'siteDescription'",
",",
"'string'",
",",
"array",
"(",
"'nobr'",
"=>",
"true",
")",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'mailFromAddr'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'mailFromName'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'mailFromOrg'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'mailReplyTo'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'mailFromSign'",
",",
"'string'",
",",
"array",
"(",
"'savebr'",
"=>",
"true",
")",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'filesModeSetOnUpload'",
",",
"'bool'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'filesModeDefault'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'filesTranslitNames'",
",",
"'bool'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'contentTypeDefault'",
",",
"'string'",
")",
";",
"$",
"settings",
".=",
"$",
"this",
"->",
"mkstr",
"(",
"'pageTemplateDefault'",
",",
"'string'",
")",
";",
"$",
"legacyKernel",
"=",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getLegacyKernel",
"(",
")",
";",
"file_put_contents",
"(",
"$",
"legacyKernel",
"->",
"froot",
".",
"'cfg/settings.php'",
",",
"$",
"settings",
")",
";",
"HTTP",
"::",
"goback",
"(",
")",
";",
"}"
] | Записывает настройки
@return void
@uses HTTP::goback | [
"Записывает",
"настройки"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/settings.php#L93-L119 |
Eresus/EresusCMS | src/core/settings.php | TSettings.renderForm | private function renderForm()
{
/** @var TAdminUI $page */
$page = Eresus_Kernel::app()->getPage();
$template = $page->getUITheme()->getResource('SiteSettings/form.html');
$form = new EresusForm($template, LOCALE_CHARSET);
/* Основные */
$form->setValue('siteName', option('siteName'));
$form->setValue('siteTitle', option('siteTitle'));
$form->setValue('siteTitleReverse', option('siteTitleReverse'));
$form->setValue('siteTitleDivider', option('siteTitleDivider'));
$form->setValue('siteKeywords', option('siteKeywords'));
$form->setValue('siteDescription', option('siteDescription'));
/* Почта */
$form->setValue('mailFromAddr', option('mailFromAddr'));
$form->setValue('mailFromName', option('mailFromName'));
$form->setValue('mailFromOrg', option('mailFromOrg'));
$form->setValue('mailReplyTo', option('mailReplyTo'));
$form->setValue('mailFromSign', option('mailFromSign'));
/* Файлы */
$form->setValue('filesModeSetOnUpload', option('filesModeSetOnUpload'));
$form->setValue('filesModeDefault', option('filesModeDefault'));
$form->setValue('filesTranslitNames', option('filesTranslitNames'));
/* Создаем список типов контента */
$contentTypes = array(
array('name' => 'default','caption' => admPagesContentDefault),
array('name' => 'list','caption' => admPagesContentList),
array('name' => 'url','caption' => admPagesContentURL)
);
foreach (Eresus_Plugin_Registry::getInstance()->getEnabled() as $plugin)
{
if ($plugin instanceof ContentPlugin || $plugin instanceof TContentPlugin)
{
$contentTypes []= array('name' => $plugin->name, 'caption' => $plugin->title);
}
}
$form->setValue('contentTypes', $contentTypes);
$form->setValue('contentTypeDefault', option('contentTypeDefault'));
/* Загружаем список шаблонов */
$templates = Templates::getInstance();
$list = $templates->enum();
$templates = array();
foreach ($list as $key => $value)
{
$templates []= array('name' => $key, 'caption' => $value);
}
$form->setValue('templates', $templates);
$form->setValue('pageTemplateDefault', option('pageTemplateDefault'));
$html = $form->compile();
return $html;
} | php | private function renderForm()
{
/** @var TAdminUI $page */
$page = Eresus_Kernel::app()->getPage();
$template = $page->getUITheme()->getResource('SiteSettings/form.html');
$form = new EresusForm($template, LOCALE_CHARSET);
/* Основные */
$form->setValue('siteName', option('siteName'));
$form->setValue('siteTitle', option('siteTitle'));
$form->setValue('siteTitleReverse', option('siteTitleReverse'));
$form->setValue('siteTitleDivider', option('siteTitleDivider'));
$form->setValue('siteKeywords', option('siteKeywords'));
$form->setValue('siteDescription', option('siteDescription'));
/* Почта */
$form->setValue('mailFromAddr', option('mailFromAddr'));
$form->setValue('mailFromName', option('mailFromName'));
$form->setValue('mailFromOrg', option('mailFromOrg'));
$form->setValue('mailReplyTo', option('mailReplyTo'));
$form->setValue('mailFromSign', option('mailFromSign'));
/* Файлы */
$form->setValue('filesModeSetOnUpload', option('filesModeSetOnUpload'));
$form->setValue('filesModeDefault', option('filesModeDefault'));
$form->setValue('filesTranslitNames', option('filesTranslitNames'));
/* Создаем список типов контента */
$contentTypes = array(
array('name' => 'default','caption' => admPagesContentDefault),
array('name' => 'list','caption' => admPagesContentList),
array('name' => 'url','caption' => admPagesContentURL)
);
foreach (Eresus_Plugin_Registry::getInstance()->getEnabled() as $plugin)
{
if ($plugin instanceof ContentPlugin || $plugin instanceof TContentPlugin)
{
$contentTypes []= array('name' => $plugin->name, 'caption' => $plugin->title);
}
}
$form->setValue('contentTypes', $contentTypes);
$form->setValue('contentTypeDefault', option('contentTypeDefault'));
/* Загружаем список шаблонов */
$templates = Templates::getInstance();
$list = $templates->enum();
$templates = array();
foreach ($list as $key => $value)
{
$templates []= array('name' => $key, 'caption' => $value);
}
$form->setValue('templates', $templates);
$form->setValue('pageTemplateDefault', option('pageTemplateDefault'));
$html = $form->compile();
return $html;
} | [
"private",
"function",
"renderForm",
"(",
")",
"{",
"/** @var TAdminUI $page */",
"$",
"page",
"=",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
";",
"$",
"template",
"=",
"$",
"page",
"->",
"getUITheme",
"(",
")",
"->",
"getResource",
"(",
"'SiteSettings/form.html'",
")",
";",
"$",
"form",
"=",
"new",
"EresusForm",
"(",
"$",
"template",
",",
"LOCALE_CHARSET",
")",
";",
"/* Основные */",
"$",
"form",
"->",
"setValue",
"(",
"'siteName'",
",",
"option",
"(",
"'siteName'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'siteTitle'",
",",
"option",
"(",
"'siteTitle'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'siteTitleReverse'",
",",
"option",
"(",
"'siteTitleReverse'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'siteTitleDivider'",
",",
"option",
"(",
"'siteTitleDivider'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'siteKeywords'",
",",
"option",
"(",
"'siteKeywords'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'siteDescription'",
",",
"option",
"(",
"'siteDescription'",
")",
")",
";",
"/* Почта */",
"$",
"form",
"->",
"setValue",
"(",
"'mailFromAddr'",
",",
"option",
"(",
"'mailFromAddr'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'mailFromName'",
",",
"option",
"(",
"'mailFromName'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'mailFromOrg'",
",",
"option",
"(",
"'mailFromOrg'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'mailReplyTo'",
",",
"option",
"(",
"'mailReplyTo'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'mailFromSign'",
",",
"option",
"(",
"'mailFromSign'",
")",
")",
";",
"/* Файлы */",
"$",
"form",
"->",
"setValue",
"(",
"'filesModeSetOnUpload'",
",",
"option",
"(",
"'filesModeSetOnUpload'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'filesModeDefault'",
",",
"option",
"(",
"'filesModeDefault'",
")",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'filesTranslitNames'",
",",
"option",
"(",
"'filesTranslitNames'",
")",
")",
";",
"/* Создаем список типов контента */",
"$",
"contentTypes",
"=",
"array",
"(",
"array",
"(",
"'name'",
"=>",
"'default'",
",",
"'caption'",
"=>",
"admPagesContentDefault",
")",
",",
"array",
"(",
"'name'",
"=>",
"'list'",
",",
"'caption'",
"=>",
"admPagesContentList",
")",
",",
"array",
"(",
"'name'",
"=>",
"'url'",
",",
"'caption'",
"=>",
"admPagesContentURL",
")",
")",
";",
"foreach",
"(",
"Eresus_Plugin_Registry",
"::",
"getInstance",
"(",
")",
"->",
"getEnabled",
"(",
")",
"as",
"$",
"plugin",
")",
"{",
"if",
"(",
"$",
"plugin",
"instanceof",
"ContentPlugin",
"||",
"$",
"plugin",
"instanceof",
"TContentPlugin",
")",
"{",
"$",
"contentTypes",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"plugin",
"->",
"name",
",",
"'caption'",
"=>",
"$",
"plugin",
"->",
"title",
")",
";",
"}",
"}",
"$",
"form",
"->",
"setValue",
"(",
"'contentTypes'",
",",
"$",
"contentTypes",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'contentTypeDefault'",
",",
"option",
"(",
"'contentTypeDefault'",
")",
")",
";",
"/* Загружаем список шаблонов */",
"$",
"templates",
"=",
"Templates",
"::",
"getInstance",
"(",
")",
";",
"$",
"list",
"=",
"$",
"templates",
"->",
"enum",
"(",
")",
";",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"key",
",",
"'caption'",
"=>",
"$",
"value",
")",
";",
"}",
"$",
"form",
"->",
"setValue",
"(",
"'templates'",
",",
"$",
"templates",
")",
";",
"$",
"form",
"->",
"setValue",
"(",
"'pageTemplateDefault'",
",",
"option",
"(",
"'pageTemplateDefault'",
")",
")",
";",
"$",
"html",
"=",
"$",
"form",
"->",
"compile",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] | Возвращает HTML-код раздела
@return string HTML
@uses EresusForm
@uses Templates | [
"Возвращает",
"HTML",
"-",
"код",
"раздела"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/settings.php#L127-L183 |
Eresus/EresusCMS | src/core/settings.php | TSettings.adminRender | function adminRender()
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '()');
if (!UserRights($this->access))
{
return '';
}
if (HTTP::request()->getMethod() == 'POST')
{
$this->update();
}
$html = $this->renderForm();
return $html;
} | php | function adminRender()
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '()');
if (!UserRights($this->access))
{
return '';
}
if (HTTP::request()->getMethod() == 'POST')
{
$this->update();
}
$html = $this->renderForm();
return $html;
} | [
"function",
"adminRender",
"(",
")",
"{",
"Eresus_Kernel",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'()'",
")",
";",
"if",
"(",
"!",
"UserRights",
"(",
"$",
"this",
"->",
"access",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"HTTP",
"::",
"request",
"(",
")",
"->",
"getMethod",
"(",
")",
"==",
"'POST'",
")",
"{",
"$",
"this",
"->",
"update",
"(",
")",
";",
"}",
"$",
"html",
"=",
"$",
"this",
"->",
"renderForm",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] | Отрисовка контента
@return string
@uses HTTP::request | [
"Отрисовка",
"контента"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/settings.php#L190-L205 |
nabab/bbn | src/bbn/html/element.php | element._init | private static function _init(){
if ( !self::$validator ){
self::$validator = new \JsonSchema\Validator();
if ( \is_string(self::$schema) ){
self::$schema = json_decode(self::$schema);
}
}
if ( !empty(static::$schema) ){
static::$schema = bbn\x::merge_objects(self::$schema, bbn\x::to_object(static::$schema));
}
else{
static::$schema = self::$schema;
}
} | php | private static function _init(){
if ( !self::$validator ){
self::$validator = new \JsonSchema\Validator();
if ( \is_string(self::$schema) ){
self::$schema = json_decode(self::$schema);
}
}
if ( !empty(static::$schema) ){
static::$schema = bbn\x::merge_objects(self::$schema, bbn\x::to_object(static::$schema));
}
else{
static::$schema = self::$schema;
}
} | [
"private",
"static",
"function",
"_init",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"validator",
")",
"{",
"self",
"::",
"$",
"validator",
"=",
"new",
"\\",
"JsonSchema",
"\\",
"Validator",
"(",
")",
";",
"if",
"(",
"\\",
"is_string",
"(",
"self",
"::",
"$",
"schema",
")",
")",
"{",
"self",
"::",
"$",
"schema",
"=",
"json_decode",
"(",
"self",
"::",
"$",
"schema",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"schema",
")",
")",
"{",
"static",
"::",
"$",
"schema",
"=",
"bbn",
"\\",
"x",
"::",
"merge_objects",
"(",
"self",
"::",
"$",
"schema",
",",
"bbn",
"\\",
"x",
"::",
"to_object",
"(",
"static",
"::",
"$",
"schema",
")",
")",
";",
"}",
"else",
"{",
"static",
"::",
"$",
"schema",
"=",
"self",
"::",
"$",
"schema",
";",
"}",
"}"
] | This creates a unique JSON schema validator object
And for each type of class generates the according JSON schema
By combining this root classs element schema
And the child class' schema
The schema has then to be called static::$schema and not self::$schema
@return void | [
"This",
"creates",
"a",
"unique",
"JSON",
"schema",
"validator",
"object",
"And",
"for",
"each",
"type",
"of",
"class",
"generates",
"the",
"according",
"JSON",
"schema",
"By",
"combining",
"this",
"root",
"classs",
"element",
"schema",
"And",
"the",
"child",
"class",
"schema",
"The",
"schema",
"has",
"then",
"to",
"be",
"called",
"static",
"::",
"$schema",
"and",
"not",
"self",
"::",
"$schema"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L169-L182 |
nabab/bbn | src/bbn/html/element.php | element.cast | private static function cast(array $cfg, $schema=null){
if ( \is_null($schema) && \is_object(static::$schema) ){
$schema = static::$schema;
}
if ( \is_object($schema) && \is_array($cfg) && isset($schema->properties) ){
foreach ( $schema->properties as $k => $p ){
if ( empty($cfg[$k]) ){
unset($cfg[$k]);
}
else if ( \is_object($p) ){
if ( \is_string($cfg[$k]) && $p->type === 'integer' ){
$cfg[$k] = (int)$cfg[$k];
}
else if ( \is_int($cfg[$k]) && $p->type === 'boolean' ){
$cfg[$k] = (bool)$cfg[$k];
}
else if ( \is_array($cfg[$k]) ){
$cfg[$k] = self::cast($cfg[$k], $p);
}
}
}
}
return $cfg;
} | php | private static function cast(array $cfg, $schema=null){
if ( \is_null($schema) && \is_object(static::$schema) ){
$schema = static::$schema;
}
if ( \is_object($schema) && \is_array($cfg) && isset($schema->properties) ){
foreach ( $schema->properties as $k => $p ){
if ( empty($cfg[$k]) ){
unset($cfg[$k]);
}
else if ( \is_object($p) ){
if ( \is_string($cfg[$k]) && $p->type === 'integer' ){
$cfg[$k] = (int)$cfg[$k];
}
else if ( \is_int($cfg[$k]) && $p->type === 'boolean' ){
$cfg[$k] = (bool)$cfg[$k];
}
else if ( \is_array($cfg[$k]) ){
$cfg[$k] = self::cast($cfg[$k], $p);
}
}
}
}
return $cfg;
} | [
"private",
"static",
"function",
"cast",
"(",
"array",
"$",
"cfg",
",",
"$",
"schema",
"=",
"null",
")",
"{",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"schema",
")",
"&&",
"\\",
"is_object",
"(",
"static",
"::",
"$",
"schema",
")",
")",
"{",
"$",
"schema",
"=",
"static",
"::",
"$",
"schema",
";",
"}",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"schema",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"cfg",
")",
"&&",
"isset",
"(",
"$",
"schema",
"->",
"properties",
")",
")",
"{",
"foreach",
"(",
"$",
"schema",
"->",
"properties",
"as",
"$",
"k",
"=>",
"$",
"p",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"cfg",
"[",
"$",
"k",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"cfg",
"[",
"$",
"k",
"]",
")",
";",
"}",
"else",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"p",
")",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"cfg",
"[",
"$",
"k",
"]",
")",
"&&",
"$",
"p",
"->",
"type",
"===",
"'integer'",
")",
"{",
"$",
"cfg",
"[",
"$",
"k",
"]",
"=",
"(",
"int",
")",
"$",
"cfg",
"[",
"$",
"k",
"]",
";",
"}",
"else",
"if",
"(",
"\\",
"is_int",
"(",
"$",
"cfg",
"[",
"$",
"k",
"]",
")",
"&&",
"$",
"p",
"->",
"type",
"===",
"'boolean'",
")",
"{",
"$",
"cfg",
"[",
"$",
"k",
"]",
"=",
"(",
"bool",
")",
"$",
"cfg",
"[",
"$",
"k",
"]",
";",
"}",
"else",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"cfg",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"cfg",
"[",
"$",
"k",
"]",
"=",
"self",
"::",
"cast",
"(",
"$",
"cfg",
"[",
"$",
"k",
"]",
",",
"$",
"p",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"cfg",
";",
"}"
] | Returns a config more adequate for the schema:
converts the types according to the schema
@param array $cfg Configuration
@param object $schema JSON Schema
@return array | [
"Returns",
"a",
"config",
"more",
"adequate",
"for",
"the",
"schema",
":",
"converts",
"the",
"types",
"according",
"to",
"the",
"schema"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L192-L215 |
nabab/bbn | src/bbn/html/element.php | element.check_config | public static function check_config($cfg){
if ( !\is_array($cfg) ){
self::$error = "The configuration is not a valid array";
return false;
}
self::$validator->check(bbn\x::to_object($cfg), static::$schema);
self::$error = '';
if ( self::$validator->isValid() ){
return 1;
}
foreach ( self::$validator->getErrors() as $error ){
self::$error .= sprintf("[%s] %s",$error['property'], $error['message']);
var_dump($cfg);
}
return false;
} | php | public static function check_config($cfg){
if ( !\is_array($cfg) ){
self::$error = "The configuration is not a valid array";
return false;
}
self::$validator->check(bbn\x::to_object($cfg), static::$schema);
self::$error = '';
if ( self::$validator->isValid() ){
return 1;
}
foreach ( self::$validator->getErrors() as $error ){
self::$error .= sprintf("[%s] %s",$error['property'], $error['message']);
var_dump($cfg);
}
return false;
} | [
"public",
"static",
"function",
"check_config",
"(",
"$",
"cfg",
")",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"cfg",
")",
")",
"{",
"self",
"::",
"$",
"error",
"=",
"\"The configuration is not a valid array\"",
";",
"return",
"false",
";",
"}",
"self",
"::",
"$",
"validator",
"->",
"check",
"(",
"bbn",
"\\",
"x",
"::",
"to_object",
"(",
"$",
"cfg",
")",
",",
"static",
"::",
"$",
"schema",
")",
";",
"self",
"::",
"$",
"error",
"=",
"''",
";",
"if",
"(",
"self",
"::",
"$",
"validator",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"1",
";",
"}",
"foreach",
"(",
"self",
"::",
"$",
"validator",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"self",
"::",
"$",
"error",
".=",
"sprintf",
"(",
"\"[%s] %s\"",
",",
"$",
"error",
"[",
"'property'",
"]",
",",
"$",
"error",
"[",
"'message'",
"]",
")",
";",
"var_dump",
"(",
"$",
"cfg",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Confront the JSON schema object with the current configuration
@param array $cfg Configuration
@return bool | [
"Confront",
"the",
"JSON",
"schema",
"object",
"with",
"the",
"current",
"configuration"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L232-L247 |
nabab/bbn | src/bbn/html/element.php | element.css_to_string | public static function css_to_string($css){
if ( \is_string($css) ){
return ' style="'.bbn\str::escape_dquotes($css).'"';
}
else if ( \is_array($css) && \count($css) > 0 ){
$st = '';
foreach ( $css as $prop => $val ){
$st .= $prop.':'.$val.';';
}
return ' style="'.bbn\str::escape_dquotes($st).'"';
}
} | php | public static function css_to_string($css){
if ( \is_string($css) ){
return ' style="'.bbn\str::escape_dquotes($css).'"';
}
else if ( \is_array($css) && \count($css) > 0 ){
$st = '';
foreach ( $css as $prop => $val ){
$st .= $prop.':'.$val.';';
}
return ' style="'.bbn\str::escape_dquotes($st).'"';
}
} | [
"public",
"static",
"function",
"css_to_string",
"(",
"$",
"css",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"css",
")",
")",
"{",
"return",
"' style=\"'",
".",
"bbn",
"\\",
"str",
"::",
"escape_dquotes",
"(",
"$",
"css",
")",
".",
"'\"'",
";",
"}",
"else",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"css",
")",
"&&",
"\\",
"count",
"(",
"$",
"css",
")",
">",
"0",
")",
"{",
"$",
"st",
"=",
"''",
";",
"foreach",
"(",
"$",
"css",
"as",
"$",
"prop",
"=>",
"$",
"val",
")",
"{",
"$",
"st",
".=",
"$",
"prop",
".",
"':'",
".",
"$",
"val",
".",
"';'",
";",
"}",
"return",
"' style=\"'",
".",
"bbn",
"\\",
"str",
"::",
"escape_dquotes",
"(",
"$",
"st",
")",
".",
"'\"'",
";",
"}",
"}"
] | Generates style string for a HTML tag
@param array|string $css CSS properties/values array
@return string | [
"Generates",
"style",
"string",
"for",
"a",
"HTML",
"tag"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L266-L277 |
nabab/bbn | src/bbn/html/element.php | element.update | protected function update()
{
$this->cfg = [];
foreach ( $this as $key => $var ){
if ( $key !== 'cfg' && !\is_null($var) ){
if ( \is_array($var) ){
foreach ( $var as $k => $v ){
if ( !isset($this->cfg[$key]) ){
$this->cfg[$key] = [];
}
if ( !\is_null($v) ){
$this->cfg[$key][$k] = $v;
}
}
}
else{
$this->cfg[$key] = $var;
}
}
}
return $this;
} | php | protected function update()
{
$this->cfg = [];
foreach ( $this as $key => $var ){
if ( $key !== 'cfg' && !\is_null($var) ){
if ( \is_array($var) ){
foreach ( $var as $k => $v ){
if ( !isset($this->cfg[$key]) ){
$this->cfg[$key] = [];
}
if ( !\is_null($v) ){
$this->cfg[$key][$k] = $v;
}
}
}
else{
$this->cfg[$key] = $var;
}
}
}
return $this;
} | [
"protected",
"function",
"update",
"(",
")",
"{",
"$",
"this",
"->",
"cfg",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"key",
"=>",
"$",
"var",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'cfg'",
"&&",
"!",
"\\",
"is_null",
"(",
"$",
"var",
")",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"var",
")",
")",
"{",
"foreach",
"(",
"$",
"var",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"cfg",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"\\",
"is_null",
"(",
"$",
"v",
")",
")",
"{",
"$",
"this",
"->",
"cfg",
"[",
"$",
"key",
"]",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"cfg",
"[",
"$",
"key",
"]",
"=",
"$",
"var",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the configuration property according to the current configuration
@return bbn\html\element | [
"Sets",
"the",
"configuration",
"property",
"according",
"to",
"the",
"current",
"configuration"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L375-L396 |
nabab/bbn | src/bbn/html/element.php | element.append | public function append($ele)
{
$args = \func_get_args();
foreach ( $args as $ele ){
if ( !isset($this->content) ){
if ( \is_array($ele) && isset($ele[0]) ){
$this->content = $ele;
}
else{
$this->content = \is_object($ele) ? [$ele] : $ele;
}
}
else if ( \is_array($this->content) ){
if ( \is_array($ele) ){
array_merge($this->content, $ele);
}
else{
array_push($this->content, $ele);
}
}
else if ( \is_string($this->content) ){
if ( \is_array($ele) ){
foreach ( $ele as $e ){
$this->content .= $e->html();
}
}
else{
$this->content .= \is_object($ele) ? $ele->html() : $ele;
}
}
}
return $this;
} | php | public function append($ele)
{
$args = \func_get_args();
foreach ( $args as $ele ){
if ( !isset($this->content) ){
if ( \is_array($ele) && isset($ele[0]) ){
$this->content = $ele;
}
else{
$this->content = \is_object($ele) ? [$ele] : $ele;
}
}
else if ( \is_array($this->content) ){
if ( \is_array($ele) ){
array_merge($this->content, $ele);
}
else{
array_push($this->content, $ele);
}
}
else if ( \is_string($this->content) ){
if ( \is_array($ele) ){
foreach ( $ele as $e ){
$this->content .= $e->html();
}
}
else{
$this->content .= \is_object($ele) ? $ele->html() : $ele;
}
}
}
return $this;
} | [
"public",
"function",
"append",
"(",
"$",
"ele",
")",
"{",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"ele",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"ele",
")",
"&&",
"isset",
"(",
"$",
"ele",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"ele",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"content",
"=",
"\\",
"is_object",
"(",
"$",
"ele",
")",
"?",
"[",
"$",
"ele",
"]",
":",
"$",
"ele",
";",
"}",
"}",
"else",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"ele",
")",
")",
"{",
"array_merge",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"ele",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"ele",
")",
";",
"}",
"}",
"else",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"ele",
")",
")",
"{",
"foreach",
"(",
"$",
"ele",
"as",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"content",
".=",
"$",
"e",
"->",
"html",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"content",
".=",
"\\",
"is_object",
"(",
"$",
"ele",
")",
"?",
"$",
"ele",
"->",
"html",
"(",
")",
":",
"$",
"ele",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add an element to the content, or a string if it's one
@param string|bbn\html\element $ele | [
"Add",
"an",
"element",
"to",
"the",
"content",
"or",
"a",
"string",
"if",
"it",
"s",
"one"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L403-L435 |
nabab/bbn | src/bbn/html/element.php | element.get_config | public function get_config()
{
$this->update();
$tmp = bbn\x::remove_empty($this->cfg);
if ( isset($tmp['content']) && \is_array($tmp['content']) ){
foreach ( $tmp['content'] as $i => $c ){
if ( \is_object($c) ){
if (method_exists($c, 'get_config') ){
$tmp['content'][$i] = $c->get_config();
}
}
}
}
return $tmp;
} | php | public function get_config()
{
$this->update();
$tmp = bbn\x::remove_empty($this->cfg);
if ( isset($tmp['content']) && \is_array($tmp['content']) ){
foreach ( $tmp['content'] as $i => $c ){
if ( \is_object($c) ){
if (method_exists($c, 'get_config') ){
$tmp['content'][$i] = $c->get_config();
}
}
}
}
return $tmp;
} | [
"public",
"function",
"get_config",
"(",
")",
"{",
"$",
"this",
"->",
"update",
"(",
")",
";",
"$",
"tmp",
"=",
"bbn",
"\\",
"x",
"::",
"remove_empty",
"(",
"$",
"this",
"->",
"cfg",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"tmp",
"[",
"'content'",
"]",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"tmp",
"[",
"'content'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"tmp",
"[",
"'content'",
"]",
"as",
"$",
"i",
"=>",
"$",
"c",
")",
"{",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"c",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"c",
",",
"'get_config'",
")",
")",
"{",
"$",
"tmp",
"[",
"'content'",
"]",
"[",
"$",
"i",
"]",
"=",
"$",
"c",
"->",
"get_config",
"(",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"tmp",
";",
"}"
] | Returns the current configuration.
@return array Current configuration | [
"Returns",
"the",
"current",
"configuration",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L441-L455 |
nabab/bbn | src/bbn/html/element.php | element.script | public function script($with_ele=1)
{
$this->update();
$r = '';
if ( isset($this->attr['id']) ){
if ( isset($this->cfg['events']) ){
foreach ( $this->cfg['events'] as $event => $fn ){
$r .= '.'.$event.'('.
( strpos($fn, 'function') === 0 ? $fn : 'function(e){'.$fn.'}' ).
')';
}
}
if ( isset($this->cfg['widget'], $this->cfg['widget']['name']) ){
$r .= '.'.$this->cfg['widget']['name'].'(';
if ( isset($this->cfg['widget']['options']) ){
$r .= '{';
foreach ( $this->cfg['widget']['options'] as $n => $o ){
$r .= '"'.$n.'":';
if ( \is_string($o) ){
$o = trim($o);
if ( (strpos($o, 'function(') === 0) ){
$r .= $o;
}
else{
$r .= '"'.bbn\str::escape_dquotes($o).'"';
}
}
else if ( \is_bool($o) ){
$r .= $o ? 'true' : 'false';
}
else{
$r .= json_encode($o);
}
$r .= ',';
}
$r .= '}';
}
$r .= ')';
}
if ( !empty($this->help) ){
// tooltip
}
if ( !empty($r) ){
if ( $with_ele ){
$r = '$("#'.$this->attr['id'].'")'.$r.';'.PHP_EOL;
}
else{
$r = $r.';'.PHP_EOL;
}
}
}
if ( !empty($this->script) ){
$r .= $this->script.PHP_EOL;
}
if ( \is_array($this->content) ){
foreach ( $this->content as $c ){
if ( \is_array($c) ){
$c = new bbn\html\element($c);
}
if (\is_object($c) && method_exists($c, 'script') ){
$r .= $c->script();
}
}
}
return $r;
} | php | public function script($with_ele=1)
{
$this->update();
$r = '';
if ( isset($this->attr['id']) ){
if ( isset($this->cfg['events']) ){
foreach ( $this->cfg['events'] as $event => $fn ){
$r .= '.'.$event.'('.
( strpos($fn, 'function') === 0 ? $fn : 'function(e){'.$fn.'}' ).
')';
}
}
if ( isset($this->cfg['widget'], $this->cfg['widget']['name']) ){
$r .= '.'.$this->cfg['widget']['name'].'(';
if ( isset($this->cfg['widget']['options']) ){
$r .= '{';
foreach ( $this->cfg['widget']['options'] as $n => $o ){
$r .= '"'.$n.'":';
if ( \is_string($o) ){
$o = trim($o);
if ( (strpos($o, 'function(') === 0) ){
$r .= $o;
}
else{
$r .= '"'.bbn\str::escape_dquotes($o).'"';
}
}
else if ( \is_bool($o) ){
$r .= $o ? 'true' : 'false';
}
else{
$r .= json_encode($o);
}
$r .= ',';
}
$r .= '}';
}
$r .= ')';
}
if ( !empty($this->help) ){
// tooltip
}
if ( !empty($r) ){
if ( $with_ele ){
$r = '$("#'.$this->attr['id'].'")'.$r.';'.PHP_EOL;
}
else{
$r = $r.';'.PHP_EOL;
}
}
}
if ( !empty($this->script) ){
$r .= $this->script.PHP_EOL;
}
if ( \is_array($this->content) ){
foreach ( $this->content as $c ){
if ( \is_array($c) ){
$c = new bbn\html\element($c);
}
if (\is_object($c) && method_exists($c, 'script') ){
$r .= $c->script();
}
}
}
return $r;
} | [
"public",
"function",
"script",
"(",
"$",
"with_ele",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"update",
"(",
")",
";",
"$",
"r",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attr",
"[",
"'id'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"'events'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"cfg",
"[",
"'events'",
"]",
"as",
"$",
"event",
"=>",
"$",
"fn",
")",
"{",
"$",
"r",
".=",
"'.'",
".",
"$",
"event",
".",
"'('",
".",
"(",
"strpos",
"(",
"$",
"fn",
",",
"'function'",
")",
"===",
"0",
"?",
"$",
"fn",
":",
"'function(e){'",
".",
"$",
"fn",
".",
"'}'",
")",
".",
"')'",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"'widget'",
"]",
",",
"$",
"this",
"->",
"cfg",
"[",
"'widget'",
"]",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"r",
".=",
"'.'",
".",
"$",
"this",
"->",
"cfg",
"[",
"'widget'",
"]",
"[",
"'name'",
"]",
".",
"'('",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"'widget'",
"]",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"r",
".=",
"'{'",
";",
"foreach",
"(",
"$",
"this",
"->",
"cfg",
"[",
"'widget'",
"]",
"[",
"'options'",
"]",
"as",
"$",
"n",
"=>",
"$",
"o",
")",
"{",
"$",
"r",
".=",
"'\"'",
".",
"$",
"n",
".",
"'\":'",
";",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"o",
")",
")",
"{",
"$",
"o",
"=",
"trim",
"(",
"$",
"o",
")",
";",
"if",
"(",
"(",
"strpos",
"(",
"$",
"o",
",",
"'function('",
")",
"===",
"0",
")",
")",
"{",
"$",
"r",
".=",
"$",
"o",
";",
"}",
"else",
"{",
"$",
"r",
".=",
"'\"'",
".",
"bbn",
"\\",
"str",
"::",
"escape_dquotes",
"(",
"$",
"o",
")",
".",
"'\"'",
";",
"}",
"}",
"else",
"if",
"(",
"\\",
"is_bool",
"(",
"$",
"o",
")",
")",
"{",
"$",
"r",
".=",
"$",
"o",
"?",
"'true'",
":",
"'false'",
";",
"}",
"else",
"{",
"$",
"r",
".=",
"json_encode",
"(",
"$",
"o",
")",
";",
"}",
"$",
"r",
".=",
"','",
";",
"}",
"$",
"r",
".=",
"'}'",
";",
"}",
"$",
"r",
".=",
"')'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"help",
")",
")",
"{",
"// tooltip",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"r",
")",
")",
"{",
"if",
"(",
"$",
"with_ele",
")",
"{",
"$",
"r",
"=",
"'$(\"#'",
".",
"$",
"this",
"->",
"attr",
"[",
"'id'",
"]",
".",
"'\")'",
".",
"$",
"r",
".",
"';'",
".",
"PHP_EOL",
";",
"}",
"else",
"{",
"$",
"r",
"=",
"$",
"r",
".",
"';'",
".",
"PHP_EOL",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"script",
")",
")",
"{",
"$",
"r",
".=",
"$",
"this",
"->",
"script",
".",
"PHP_EOL",
";",
"}",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"content",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"c",
")",
")",
"{",
"$",
"c",
"=",
"new",
"bbn",
"\\",
"html",
"\\",
"element",
"(",
"$",
"c",
")",
";",
"}",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"c",
")",
"&&",
"method_exists",
"(",
"$",
"c",
",",
"'script'",
")",
")",
"{",
"$",
"r",
".=",
"$",
"c",
"->",
"script",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"r",
";",
"}"
] | Returns the javascript coming with the object
@return string javascript string | [
"Returns",
"the",
"javascript",
"coming",
"with",
"the",
"object"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L482-L547 |
nabab/bbn | src/bbn/html/element.php | element.html | public function html($with_js = 1)
{
$html = '';
if ( $this->tag ){
$this->update();
// TAG
$html .= '<'.$this->tag;
foreach ( $this->attr as $key => $val ){
if ( \is_string($key) ){
$html .= ' '.htmlspecialchars($key).'="';
if ( is_numeric($val) ){
$html .= $val;
}
else if (\is_string($val) ){
$html .= htmlspecialchars($val);
}
$html .= '"';
}
}
if ( \count($this->css) > 0 ){
$html .= self::css_to_string($this->css);
}
if ( $this->xhtml ){
$html .= ' /';
}
$html .= '>';
if ( !\in_array($this->tag, self::$self_closing_tags) ){
if ( isset($this->text) ){
$html .= $this->text;
}
if ( isset($this->content) ){
// @todo: Add the ability to imbricate elements
if ( \is_string($this->content) ){
$html .= $this->content;
}
else if ( \is_array($this->content) ){
foreach ( $this->content as $c ){
if ( \is_array($c) ){
$c = new bbn\html\element($c);
}
$html .= $c->html($with_js);
}
}
}
$html .= '</'.$this->tag.'>';
}
if ( isset($this->placeholder) && strpos($this->placeholder,'%s') !== false ){
$html = sprintf($this->placeholder, $html);
}
}
return $html;
} | php | public function html($with_js = 1)
{
$html = '';
if ( $this->tag ){
$this->update();
// TAG
$html .= '<'.$this->tag;
foreach ( $this->attr as $key => $val ){
if ( \is_string($key) ){
$html .= ' '.htmlspecialchars($key).'="';
if ( is_numeric($val) ){
$html .= $val;
}
else if (\is_string($val) ){
$html .= htmlspecialchars($val);
}
$html .= '"';
}
}
if ( \count($this->css) > 0 ){
$html .= self::css_to_string($this->css);
}
if ( $this->xhtml ){
$html .= ' /';
}
$html .= '>';
if ( !\in_array($this->tag, self::$self_closing_tags) ){
if ( isset($this->text) ){
$html .= $this->text;
}
if ( isset($this->content) ){
// @todo: Add the ability to imbricate elements
if ( \is_string($this->content) ){
$html .= $this->content;
}
else if ( \is_array($this->content) ){
foreach ( $this->content as $c ){
if ( \is_array($c) ){
$c = new bbn\html\element($c);
}
$html .= $c->html($with_js);
}
}
}
$html .= '</'.$this->tag.'>';
}
if ( isset($this->placeholder) && strpos($this->placeholder,'%s') !== false ){
$html = sprintf($this->placeholder, $html);
}
}
return $html;
} | [
"public",
"function",
"html",
"(",
"$",
"with_js",
"=",
"1",
")",
"{",
"$",
"html",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"tag",
")",
"{",
"$",
"this",
"->",
"update",
"(",
")",
";",
"// TAG",
"$",
"html",
".=",
"'<'",
".",
"$",
"this",
"->",
"tag",
";",
"foreach",
"(",
"$",
"this",
"->",
"attr",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"html",
".=",
"' '",
".",
"htmlspecialchars",
"(",
"$",
"key",
")",
".",
"'=\"'",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"$",
"html",
".=",
"$",
"val",
";",
"}",
"else",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"val",
")",
")",
"{",
"$",
"html",
".=",
"htmlspecialchars",
"(",
"$",
"val",
")",
";",
"}",
"$",
"html",
".=",
"'\"'",
";",
"}",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"css",
")",
">",
"0",
")",
"{",
"$",
"html",
".=",
"self",
"::",
"css_to_string",
"(",
"$",
"this",
"->",
"css",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"xhtml",
")",
"{",
"$",
"html",
".=",
"' /'",
";",
"}",
"$",
"html",
".=",
"'>'",
";",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"this",
"->",
"tag",
",",
"self",
"::",
"$",
"self_closing_tags",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"text",
")",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"text",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"// @todo: Add the ability to imbricate elements",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"content",
";",
"}",
"else",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"content",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"c",
")",
")",
"{",
"$",
"c",
"=",
"new",
"bbn",
"\\",
"html",
"\\",
"element",
"(",
"$",
"c",
")",
";",
"}",
"$",
"html",
".=",
"$",
"c",
"->",
"html",
"(",
"$",
"with_js",
")",
";",
"}",
"}",
"}",
"$",
"html",
".=",
"'</'",
".",
"$",
"this",
"->",
"tag",
".",
"'>'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"placeholder",
")",
"&&",
"strpos",
"(",
"$",
"this",
"->",
"placeholder",
",",
"'%s'",
")",
"!==",
"false",
")",
"{",
"$",
"html",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"placeholder",
",",
"$",
"html",
")",
";",
"}",
"}",
"return",
"$",
"html",
";",
"}"
] | Returns the corresponding HTML string
@param bool $with_js Includes the javascript
@return string HTML string | [
"Returns",
"the",
"corresponding",
"HTML",
"string"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/element.php#L601-L660 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_set.php | ezcMailMboxSet.getNextLine | public function getNextLine()
{
if ( $this->currentMessagePosition === 0 )
{
$this->nextMail();
}
if ( $this->hasMoreMailData )
{
$data = fgets( $this->fh );
if ( feof( $this->fh ) || substr( $data, 0, 5 ) === "From " )
{
$this->hasMoreMailData = false;
return null;
}
return $data;
}
return null;
} | php | public function getNextLine()
{
if ( $this->currentMessagePosition === 0 )
{
$this->nextMail();
}
if ( $this->hasMoreMailData )
{
$data = fgets( $this->fh );
if ( feof( $this->fh ) || substr( $data, 0, 5 ) === "From " )
{
$this->hasMoreMailData = false;
return null;
}
return $data;
}
return null;
} | [
"public",
"function",
"getNextLine",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currentMessagePosition",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"nextMail",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasMoreMailData",
")",
"{",
"$",
"data",
"=",
"fgets",
"(",
"$",
"this",
"->",
"fh",
")",
";",
"if",
"(",
"feof",
"(",
"$",
"this",
"->",
"fh",
")",
"||",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"5",
")",
"===",
"\"From \"",
")",
"{",
"$",
"this",
"->",
"hasMoreMailData",
"=",
"false",
";",
"return",
"null",
";",
"}",
"return",
"$",
"data",
";",
"}",
"return",
"null",
";",
"}"
] | Returns one line of data from the current mail in the set
including the ending linebreak.
Null is returned if there is no current mail in the set or
the end of the mail is reached.
@return string | [
"Returns",
"one",
"line",
"of",
"data",
"from",
"the",
"current",
"mail",
"in",
"the",
"set",
"including",
"the",
"ending",
"linebreak",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_set.php#L101-L119 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_set.php | ezcMailMboxSet.nextMail | public function nextMail()
{
// seek to next message if available
if ( $this->currentMessagePosition > count( $this->messagePositions ) - 1 )
{
$this->hasMoreMailData = false;
return false;
}
fseek( $this->fh, $this->messagePositions[$this->currentMessagePosition] );
$this->currentMessagePosition++;
$this->hasMoreMailData = true;
return true;
} | php | public function nextMail()
{
// seek to next message if available
if ( $this->currentMessagePosition > count( $this->messagePositions ) - 1 )
{
$this->hasMoreMailData = false;
return false;
}
fseek( $this->fh, $this->messagePositions[$this->currentMessagePosition] );
$this->currentMessagePosition++;
$this->hasMoreMailData = true;
return true;
} | [
"public",
"function",
"nextMail",
"(",
")",
"{",
"// seek to next message if available",
"if",
"(",
"$",
"this",
"->",
"currentMessagePosition",
">",
"count",
"(",
"$",
"this",
"->",
"messagePositions",
")",
"-",
"1",
")",
"{",
"$",
"this",
"->",
"hasMoreMailData",
"=",
"false",
";",
"return",
"false",
";",
"}",
"fseek",
"(",
"$",
"this",
"->",
"fh",
",",
"$",
"this",
"->",
"messagePositions",
"[",
"$",
"this",
"->",
"currentMessagePosition",
"]",
")",
";",
"$",
"this",
"->",
"currentMessagePosition",
"++",
";",
"$",
"this",
"->",
"hasMoreMailData",
"=",
"true",
";",
"return",
"true",
";",
"}"
] | Moves the set to the next mail and returns true upon success.
False is returned if there are no more mail in the set.
@return bool | [
"Moves",
"the",
"set",
"to",
"the",
"next",
"mail",
"and",
"returns",
"true",
"upon",
"success",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_set.php#L138-L151 |
artscorestudio/document-bundle | Controller/PostController.php | PostController.listAction | public function listAction()
{
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page !');
$postManager = $this->get('asf_document.post.manager');
// Define DataGrid Source
$source = new Entity($postManager->getClassName());
// Get datagrid
$grid = $this->get('grid');
$grid instanceof Grid;
$grid->setSource($source);
$tableAlias = $source->getTableAlias();
$postClassName = $postManager->getShortClassName();
$source->manipulateQuery(function($query) use ($tableAlias, $postClassName) {
$query instanceof QueryBuilder;
// Get all original version of each posts
$query2 = $query->getEntityManager()->createQueryBuilder();
$query2->select('post.id')
->from($postClassName, 'post')
->where('post.original IS NULL');
$result = $query2->getQuery()->getResult();
// Search versions for each original posts
if (count($result)) {
$ids = array();
foreach($result as $original) {
$qb = $query->getEntityManager()->createQueryBuilder();
$qb->select('p')->from($postClassName, 'p')
->where('p.original=:original_id')
->orderBy('p.createdAt', 'DESC')
->setParameter('original_id', $original['id']);
$r = $qb->getQuery()->setMaxResults(1)->getResult();
if ( count($r) ) {
$ids[] = $r[0]->getId();
} else {
$ids[] = $original['id'];
}
}
// Create query for datagird
$query->add('where', $query->expr()->in($tableAlias.'.id', $ids));
}
if ( count($query->getDQLPart('orderBy')) == 0) {
$query->orderBy($tableAlias.'.createdAt', 'DESC');
}
});
// Grid Columns configuration
$this->get('event_dispatcher')->dispatch(DocumentEvents::POST_GRID_CONFIG, new PostGridEvent($grid, $source));
$grid->getColumn('id')->setVisible(false);
$grid->getColumn('title')->setTitle($this->get('translator')->trans('Post title', array(), 'asf_document'));
$grid->getColumn('content')->setVisible(false);
$grid->getColumn('slug')->setTitle($this->get('translator')->trans('Slug', array(), 'asf_document'));
$grid->getColumn('state')->setTitle($this->get('translator')->trans('State', array(), 'asf_document'))
->setFilterType('select')->setSelectFrom('values')->setOperatorsVisible(false)
->setDefaultOperator('eq')->setValues(array(
DocumentModel::STATE_DRAFT => $this->get('translator')->trans('Draft', array(), 'asf_document'),
DocumentModel::STATE_WAITING => $this->get('translator')->trans('Waiting', array(), 'asf_document'),
DocumentModel::STATE_PUBLISHED => $this->get('translator')->trans('Published', array(), 'asf_document')
));
$grid->getColumn('createdAt')->setTitle($this->get('translator')->trans('Created at', array(), 'asf_document'));
$grid->getColumn('updatedAt')->setTitle($this->get('translator')->trans('Updated at', array(), 'asf_document'));
$edit_action = new RowAction('btn_edit', 'asf_document_post_edit');
$edit_action->setRouteParameters(array('id'));
$grid->addRowAction($edit_action);
$delete_action = new RowAction('btn_delete', 'asf_document_post_delete', true);
$delete_action->setRouteParameters(array('id'))
->setConfirmMessage($this->get('translator')->trans('Do you want to delete this post?', array(), 'asf_document'));
$grid->addRowAction($delete_action);
$grid->setNoDataMessage($this->get('translator')->trans('No post was found.', array(), 'asf_document'));
return $grid->getGridResponse('ASFDocumentBundle:Post:list.html.twig', array('grid' => $grid));
} | php | public function listAction()
{
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page !');
$postManager = $this->get('asf_document.post.manager');
// Define DataGrid Source
$source = new Entity($postManager->getClassName());
// Get datagrid
$grid = $this->get('grid');
$grid instanceof Grid;
$grid->setSource($source);
$tableAlias = $source->getTableAlias();
$postClassName = $postManager->getShortClassName();
$source->manipulateQuery(function($query) use ($tableAlias, $postClassName) {
$query instanceof QueryBuilder;
// Get all original version of each posts
$query2 = $query->getEntityManager()->createQueryBuilder();
$query2->select('post.id')
->from($postClassName, 'post')
->where('post.original IS NULL');
$result = $query2->getQuery()->getResult();
// Search versions for each original posts
if (count($result)) {
$ids = array();
foreach($result as $original) {
$qb = $query->getEntityManager()->createQueryBuilder();
$qb->select('p')->from($postClassName, 'p')
->where('p.original=:original_id')
->orderBy('p.createdAt', 'DESC')
->setParameter('original_id', $original['id']);
$r = $qb->getQuery()->setMaxResults(1)->getResult();
if ( count($r) ) {
$ids[] = $r[0]->getId();
} else {
$ids[] = $original['id'];
}
}
// Create query for datagird
$query->add('where', $query->expr()->in($tableAlias.'.id', $ids));
}
if ( count($query->getDQLPart('orderBy')) == 0) {
$query->orderBy($tableAlias.'.createdAt', 'DESC');
}
});
// Grid Columns configuration
$this->get('event_dispatcher')->dispatch(DocumentEvents::POST_GRID_CONFIG, new PostGridEvent($grid, $source));
$grid->getColumn('id')->setVisible(false);
$grid->getColumn('title')->setTitle($this->get('translator')->trans('Post title', array(), 'asf_document'));
$grid->getColumn('content')->setVisible(false);
$grid->getColumn('slug')->setTitle($this->get('translator')->trans('Slug', array(), 'asf_document'));
$grid->getColumn('state')->setTitle($this->get('translator')->trans('State', array(), 'asf_document'))
->setFilterType('select')->setSelectFrom('values')->setOperatorsVisible(false)
->setDefaultOperator('eq')->setValues(array(
DocumentModel::STATE_DRAFT => $this->get('translator')->trans('Draft', array(), 'asf_document'),
DocumentModel::STATE_WAITING => $this->get('translator')->trans('Waiting', array(), 'asf_document'),
DocumentModel::STATE_PUBLISHED => $this->get('translator')->trans('Published', array(), 'asf_document')
));
$grid->getColumn('createdAt')->setTitle($this->get('translator')->trans('Created at', array(), 'asf_document'));
$grid->getColumn('updatedAt')->setTitle($this->get('translator')->trans('Updated at', array(), 'asf_document'));
$edit_action = new RowAction('btn_edit', 'asf_document_post_edit');
$edit_action->setRouteParameters(array('id'));
$grid->addRowAction($edit_action);
$delete_action = new RowAction('btn_delete', 'asf_document_post_delete', true);
$delete_action->setRouteParameters(array('id'))
->setConfirmMessage($this->get('translator')->trans('Do you want to delete this post?', array(), 'asf_document'));
$grid->addRowAction($delete_action);
$grid->setNoDataMessage($this->get('translator')->trans('No post was found.', array(), 'asf_document'));
return $grid->getGridResponse('ASFDocumentBundle:Post:list.html.twig', array('grid' => $grid));
} | [
"public",
"function",
"listAction",
"(",
")",
"{",
"$",
"this",
"->",
"denyAccessUnlessGranted",
"(",
"'ROLE_ADMIN'",
",",
"null",
",",
"'Unable to access this page !'",
")",
";",
"$",
"postManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'asf_document.post.manager'",
")",
";",
"// Define DataGrid Source",
"$",
"source",
"=",
"new",
"Entity",
"(",
"$",
"postManager",
"->",
"getClassName",
"(",
")",
")",
";",
"// Get datagrid",
"$",
"grid",
"=",
"$",
"this",
"->",
"get",
"(",
"'grid'",
")",
";",
"$",
"grid",
"instanceof",
"Grid",
";",
"$",
"grid",
"->",
"setSource",
"(",
"$",
"source",
")",
";",
"$",
"tableAlias",
"=",
"$",
"source",
"->",
"getTableAlias",
"(",
")",
";",
"$",
"postClassName",
"=",
"$",
"postManager",
"->",
"getShortClassName",
"(",
")",
";",
"$",
"source",
"->",
"manipulateQuery",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"tableAlias",
",",
"$",
"postClassName",
")",
"{",
"$",
"query",
"instanceof",
"QueryBuilder",
";",
"// Get all original version of each posts",
"$",
"query2",
"=",
"$",
"query",
"->",
"getEntityManager",
"(",
")",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query2",
"->",
"select",
"(",
"'post.id'",
")",
"->",
"from",
"(",
"$",
"postClassName",
",",
"'post'",
")",
"->",
"where",
"(",
"'post.original IS NULL'",
")",
";",
"$",
"result",
"=",
"$",
"query2",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"// Search versions for each original posts",
"if",
"(",
"count",
"(",
"$",
"result",
")",
")",
"{",
"$",
"ids",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"original",
")",
"{",
"$",
"qb",
"=",
"$",
"query",
"->",
"getEntityManager",
"(",
")",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"select",
"(",
"'p'",
")",
"->",
"from",
"(",
"$",
"postClassName",
",",
"'p'",
")",
"->",
"where",
"(",
"'p.original=:original_id'",
")",
"->",
"orderBy",
"(",
"'p.createdAt'",
",",
"'DESC'",
")",
"->",
"setParameter",
"(",
"'original_id'",
",",
"$",
"original",
"[",
"'id'",
"]",
")",
";",
"$",
"r",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"setMaxResults",
"(",
"1",
")",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"r",
")",
")",
"{",
"$",
"ids",
"[",
"]",
"=",
"$",
"r",
"[",
"0",
"]",
"->",
"getId",
"(",
")",
";",
"}",
"else",
"{",
"$",
"ids",
"[",
"]",
"=",
"$",
"original",
"[",
"'id'",
"]",
";",
"}",
"}",
"// Create query for datagird",
"$",
"query",
"->",
"add",
"(",
"'where'",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"in",
"(",
"$",
"tableAlias",
".",
"'.id'",
",",
"$",
"ids",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"query",
"->",
"getDQLPart",
"(",
"'orderBy'",
")",
")",
"==",
"0",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"tableAlias",
".",
"'.createdAt'",
",",
"'DESC'",
")",
";",
"}",
"}",
")",
";",
"// Grid Columns configuration",
"$",
"this",
"->",
"get",
"(",
"'event_dispatcher'",
")",
"->",
"dispatch",
"(",
"DocumentEvents",
"::",
"POST_GRID_CONFIG",
",",
"new",
"PostGridEvent",
"(",
"$",
"grid",
",",
"$",
"source",
")",
")",
";",
"$",
"grid",
"->",
"getColumn",
"(",
"'id'",
")",
"->",
"setVisible",
"(",
"false",
")",
";",
"$",
"grid",
"->",
"getColumn",
"(",
"'title'",
")",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Post title'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"$",
"grid",
"->",
"getColumn",
"(",
"'content'",
")",
"->",
"setVisible",
"(",
"false",
")",
";",
"$",
"grid",
"->",
"getColumn",
"(",
"'slug'",
")",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Slug'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"$",
"grid",
"->",
"getColumn",
"(",
"'state'",
")",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'State'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
"->",
"setFilterType",
"(",
"'select'",
")",
"->",
"setSelectFrom",
"(",
"'values'",
")",
"->",
"setOperatorsVisible",
"(",
"false",
")",
"->",
"setDefaultOperator",
"(",
"'eq'",
")",
"->",
"setValues",
"(",
"array",
"(",
"DocumentModel",
"::",
"STATE_DRAFT",
"=>",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Draft'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
",",
"DocumentModel",
"::",
"STATE_WAITING",
"=>",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Waiting'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
",",
"DocumentModel",
"::",
"STATE_PUBLISHED",
"=>",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Published'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
")",
";",
"$",
"grid",
"->",
"getColumn",
"(",
"'createdAt'",
")",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Created at'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"$",
"grid",
"->",
"getColumn",
"(",
"'updatedAt'",
")",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Updated at'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"$",
"edit_action",
"=",
"new",
"RowAction",
"(",
"'btn_edit'",
",",
"'asf_document_post_edit'",
")",
";",
"$",
"edit_action",
"->",
"setRouteParameters",
"(",
"array",
"(",
"'id'",
")",
")",
";",
"$",
"grid",
"->",
"addRowAction",
"(",
"$",
"edit_action",
")",
";",
"$",
"delete_action",
"=",
"new",
"RowAction",
"(",
"'btn_delete'",
",",
"'asf_document_post_delete'",
",",
"true",
")",
";",
"$",
"delete_action",
"->",
"setRouteParameters",
"(",
"array",
"(",
"'id'",
")",
")",
"->",
"setConfirmMessage",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Do you want to delete this post?'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"$",
"grid",
"->",
"addRowAction",
"(",
"$",
"delete_action",
")",
";",
"$",
"grid",
"->",
"setNoDataMessage",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'No post was found.'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"return",
"$",
"grid",
"->",
"getGridResponse",
"(",
"'ASFDocumentBundle:Post:list.html.twig'",
",",
"array",
"(",
"'grid'",
"=>",
"$",
"grid",
")",
")",
";",
"}"
] | List all blog posts
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response | [
"List",
"all",
"blog",
"posts"
] | train | https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Controller/PostController.php#L42-L124 |
artscorestudio/document-bundle | Controller/PostController.php | PostController.editAction | public function editAction(Request $request, $id = null)
{
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page !');
$postManager = $this->get('asf_document.post.manager');
if ( !is_null($id) ) {
$original = $postManager->getRepository()->findOneBy(array('id' => $id));
if ( $this->getParameter('asf_document.post.versionable') === true ) {
$post = clone $original;
$postManager->getEntityManager()->detach($post);
if ( is_null($original->getOriginal()) )
$post->setOriginal($original);
else
$post->setOriginal($original->getOriginal());
} else {
$post = $original;
}
$success_message = $this->get('translator')->trans('Updated successfully', array(), 'asf_document');
} else {
$post = $postManager->createInstance();
$post->setTitle($this->get('translator')->trans('New post', array(), 'asf_document'))->setSlug($this->get('translator')->trans('new-post', array(), 'asf_document'));
$success_message = $this->get('translator')->trans('Created successfully', array(), 'asf_document');
}
if ( is_null($post) )
throw new \Exception($this->get('translator')->trans('An error occurs when generating or getting the post', array(), 'asf_document'));
$formFactory = $this->get('asf_document.form.factory.post');
$form = $formFactory->createForm();
$form->setData($post);
$form->handleRequest($request);
if ( $form->isSubmitted() && $form->isValid() ) {
try {
$this->get('event_dispatcher')->dispatch(DocumentEvents::POST_EDIT_SUCCESS, new PostEvent($post));
if ( is_null($post->getId()) ) {
$postManager->getEntityManager()->persist($post);
}
$postManager->getEntityManager()->flush();
if ( $this->has('asf_layout.flash_message') ) {
$this->get('asf_layout.flash_message')->success($success_message);
}
return $this->redirect($this->get('router')->generate('asf_document_post_edit', array('id' => $post->getId())));
} catch (\Exception $e) {
if ( $this->has('asf_layout.flash_message') ) {
$this->get('asf_layout.flash_message')->danger($e->getMessage());
}
}
}
return $this->render('ASFDocumentBundle:Post:edit.html.twig', array(
'post' => $post,
'form' => $form->createView()
));
} | php | public function editAction(Request $request, $id = null)
{
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page !');
$postManager = $this->get('asf_document.post.manager');
if ( !is_null($id) ) {
$original = $postManager->getRepository()->findOneBy(array('id' => $id));
if ( $this->getParameter('asf_document.post.versionable') === true ) {
$post = clone $original;
$postManager->getEntityManager()->detach($post);
if ( is_null($original->getOriginal()) )
$post->setOriginal($original);
else
$post->setOriginal($original->getOriginal());
} else {
$post = $original;
}
$success_message = $this->get('translator')->trans('Updated successfully', array(), 'asf_document');
} else {
$post = $postManager->createInstance();
$post->setTitle($this->get('translator')->trans('New post', array(), 'asf_document'))->setSlug($this->get('translator')->trans('new-post', array(), 'asf_document'));
$success_message = $this->get('translator')->trans('Created successfully', array(), 'asf_document');
}
if ( is_null($post) )
throw new \Exception($this->get('translator')->trans('An error occurs when generating or getting the post', array(), 'asf_document'));
$formFactory = $this->get('asf_document.form.factory.post');
$form = $formFactory->createForm();
$form->setData($post);
$form->handleRequest($request);
if ( $form->isSubmitted() && $form->isValid() ) {
try {
$this->get('event_dispatcher')->dispatch(DocumentEvents::POST_EDIT_SUCCESS, new PostEvent($post));
if ( is_null($post->getId()) ) {
$postManager->getEntityManager()->persist($post);
}
$postManager->getEntityManager()->flush();
if ( $this->has('asf_layout.flash_message') ) {
$this->get('asf_layout.flash_message')->success($success_message);
}
return $this->redirect($this->get('router')->generate('asf_document_post_edit', array('id' => $post->getId())));
} catch (\Exception $e) {
if ( $this->has('asf_layout.flash_message') ) {
$this->get('asf_layout.flash_message')->danger($e->getMessage());
}
}
}
return $this->render('ASFDocumentBundle:Post:edit.html.twig', array(
'post' => $post,
'form' => $form->createView()
));
} | [
"public",
"function",
"editAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"denyAccessUnlessGranted",
"(",
"'ROLE_ADMIN'",
",",
"null",
",",
"'Unable to access this page !'",
")",
";",
"$",
"postManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'asf_document.post.manager'",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"id",
")",
")",
"{",
"$",
"original",
"=",
"$",
"postManager",
"->",
"getRepository",
"(",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'asf_document.post.versionable'",
")",
"===",
"true",
")",
"{",
"$",
"post",
"=",
"clone",
"$",
"original",
";",
"$",
"postManager",
"->",
"getEntityManager",
"(",
")",
"->",
"detach",
"(",
"$",
"post",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"original",
"->",
"getOriginal",
"(",
")",
")",
")",
"$",
"post",
"->",
"setOriginal",
"(",
"$",
"original",
")",
";",
"else",
"$",
"post",
"->",
"setOriginal",
"(",
"$",
"original",
"->",
"getOriginal",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"post",
"=",
"$",
"original",
";",
"}",
"$",
"success_message",
"=",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Updated successfully'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
";",
"}",
"else",
"{",
"$",
"post",
"=",
"$",
"postManager",
"->",
"createInstance",
"(",
")",
";",
"$",
"post",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'New post'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
"->",
"setSlug",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'new-post'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"$",
"success_message",
"=",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'Created successfully'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"post",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'An error occurs when generating or getting the post'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"$",
"formFactory",
"=",
"$",
"this",
"->",
"get",
"(",
"'asf_document.form.factory.post'",
")",
";",
"$",
"form",
"=",
"$",
"formFactory",
"->",
"createForm",
"(",
")",
";",
"$",
"form",
"->",
"setData",
"(",
"$",
"post",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isSubmitted",
"(",
")",
"&&",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"get",
"(",
"'event_dispatcher'",
")",
"->",
"dispatch",
"(",
"DocumentEvents",
"::",
"POST_EDIT_SUCCESS",
",",
"new",
"PostEvent",
"(",
"$",
"post",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"post",
"->",
"getId",
"(",
")",
")",
")",
"{",
"$",
"postManager",
"->",
"getEntityManager",
"(",
")",
"->",
"persist",
"(",
"$",
"post",
")",
";",
"}",
"$",
"postManager",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'asf_layout.flash_message'",
")",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'asf_layout.flash_message'",
")",
"->",
"success",
"(",
"$",
"success_message",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"get",
"(",
"'router'",
")",
"->",
"generate",
"(",
"'asf_document_post_edit'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"post",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'asf_layout.flash_message'",
")",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'asf_layout.flash_message'",
")",
"->",
"danger",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'ASFDocumentBundle:Post:edit.html.twig'",
",",
"array",
"(",
"'post'",
"=>",
"$",
"post",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
")",
")",
";",
"}"
] | Add or edit a post
@param integer $id ASFDocumentBundle:Post Entity ID
@throws AccessDeniedException If user does not have ACL's rights for edit the post
@throws \Exception Error on post's author not found or post not found
@return \Symfony\Component\HttpFoundation\Response | [
"Add",
"or",
"edit",
"a",
"post"
] | train | https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Controller/PostController.php#L134-L196 |
artscorestudio/document-bundle | Controller/PostController.php | PostController.deleteAction | public function deleteAction($id)
{
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page !');
$postManager = $this->get('asf_document.post.manager');
$post = $postManager->getRepository()->findOneBy(array('id' => $id));
try {
if ( is_null($post) )
throw new \Exception($this->get('translator')->trans('An error occurs when deleting the post', array(), 'asf_document'));
$postManager->getEntityManager()->remove($post);
$postManager->getEntityManager()->flush();
if ( $this->has('asf_layout.flash_message') ) {
$this->get('asf_layout.flash_message')->success($this->get('translator')->trans('The post "%name%" successfully deleted', array('%name%' => $post->getTitle()), 'asf_document'));
}
} catch (\Exception $e) {
if ( $this->has('asf_layout.flash_message') ) {
$this->get('asf_layout.flash_message')->danger($e->getMessage());
}
}
return $this->redirect($this->get('router')->generate('asf_document_post_list'));
} | php | public function deleteAction($id)
{
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page !');
$postManager = $this->get('asf_document.post.manager');
$post = $postManager->getRepository()->findOneBy(array('id' => $id));
try {
if ( is_null($post) )
throw new \Exception($this->get('translator')->trans('An error occurs when deleting the post', array(), 'asf_document'));
$postManager->getEntityManager()->remove($post);
$postManager->getEntityManager()->flush();
if ( $this->has('asf_layout.flash_message') ) {
$this->get('asf_layout.flash_message')->success($this->get('translator')->trans('The post "%name%" successfully deleted', array('%name%' => $post->getTitle()), 'asf_document'));
}
} catch (\Exception $e) {
if ( $this->has('asf_layout.flash_message') ) {
$this->get('asf_layout.flash_message')->danger($e->getMessage());
}
}
return $this->redirect($this->get('router')->generate('asf_document_post_list'));
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"denyAccessUnlessGranted",
"(",
"'ROLE_ADMIN'",
",",
"null",
",",
"'Unable to access this page !'",
")",
";",
"$",
"postManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'asf_document.post.manager'",
")",
";",
"$",
"post",
"=",
"$",
"postManager",
"->",
"getRepository",
"(",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
";",
"try",
"{",
"if",
"(",
"is_null",
"(",
"$",
"post",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'An error occurs when deleting the post'",
",",
"array",
"(",
")",
",",
"'asf_document'",
")",
")",
";",
"$",
"postManager",
"->",
"getEntityManager",
"(",
")",
"->",
"remove",
"(",
"$",
"post",
")",
";",
"$",
"postManager",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'asf_layout.flash_message'",
")",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'asf_layout.flash_message'",
")",
"->",
"success",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'The post \"%name%\" successfully deleted'",
",",
"array",
"(",
"'%name%'",
"=>",
"$",
"post",
"->",
"getTitle",
"(",
")",
")",
",",
"'asf_document'",
")",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'asf_layout.flash_message'",
")",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'asf_layout.flash_message'",
")",
"->",
"danger",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"get",
"(",
"'router'",
")",
"->",
"generate",
"(",
"'asf_document_post_list'",
")",
")",
";",
"}"
] | Delete a post
@param integer $id ASFDocumentBundle:Post Entity ID
@throws AccessDeniedException If user does not have ACL's rights for delete the post
@throws \Exception Error on post not found or on removing element from DB
@return \Symfony\Component\HttpFoundation\RedirectResponse | [
"Delete",
"a",
"post"
] | train | https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Controller/PostController.php#L206-L231 |
welderlourenco/laravel-seeder | src/WelderLourenco/LaravelSeeder/Providers/LaravelSeederServiceProvider.php | LaravelSeederServiceProvider.registerDbAll | public function registerDbAll()
{
$this->app->bind('welderlourenco::command.db.all', function($app) {
return new \WelderLourenco\LaravelSeeder\Commands\LaravelSeederAllCommand();
});
$this->commands(array(
'welderlourenco::command.db.all'
));
} | php | public function registerDbAll()
{
$this->app->bind('welderlourenco::command.db.all', function($app) {
return new \WelderLourenco\LaravelSeeder\Commands\LaravelSeederAllCommand();
});
$this->commands(array(
'welderlourenco::command.db.all'
));
} | [
"public",
"function",
"registerDbAll",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'welderlourenco::command.db.all'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"WelderLourenco",
"\\",
"LaravelSeeder",
"\\",
"Commands",
"\\",
"LaravelSeederAllCommand",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"commands",
"(",
"array",
"(",
"'welderlourenco::command.db.all'",
")",
")",
";",
"}"
] | Register the db:all command. | [
"Register",
"the",
"db",
":",
"all",
"command",
"."
] | train | https://github.com/welderlourenco/laravel-seeder/blob/165d1f3bd596e985d5ef6ddd5fe3ad21589f17ad/src/WelderLourenco/LaravelSeeder/Providers/LaravelSeederServiceProvider.php#L49-L57 |
welderlourenco/laravel-seeder | src/WelderLourenco/LaravelSeeder/Providers/LaravelSeederServiceProvider.php | LaravelSeederServiceProvider.registerDbOnly | public function registerDbOnly()
{
$this->app->bind('welderlourenco::command.db.only', function($app) {
return new \WelderLourenco\LaravelSeeder\Commands\LaravelSeederOnlyCommand();
});
$this->commands(array(
'welderlourenco::command.db.only'
));
} | php | public function registerDbOnly()
{
$this->app->bind('welderlourenco::command.db.only', function($app) {
return new \WelderLourenco\LaravelSeeder\Commands\LaravelSeederOnlyCommand();
});
$this->commands(array(
'welderlourenco::command.db.only'
));
} | [
"public",
"function",
"registerDbOnly",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'welderlourenco::command.db.only'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"WelderLourenco",
"\\",
"LaravelSeeder",
"\\",
"Commands",
"\\",
"LaravelSeederOnlyCommand",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"commands",
"(",
"array",
"(",
"'welderlourenco::command.db.only'",
")",
")",
";",
"}"
] | Register the db:only command. | [
"Register",
"the",
"db",
":",
"only",
"command",
"."
] | train | https://github.com/welderlourenco/laravel-seeder/blob/165d1f3bd596e985d5ef6ddd5fe3ad21589f17ad/src/WelderLourenco/LaravelSeeder/Providers/LaravelSeederServiceProvider.php#L63-L71 |
kenphp/ken | src/Helpers/View.php | View.render | public static function render(ResponseInterface $response, $view, array $params = [])
{
return Application::getInstance()->view->render($response, $view, $params);
} | php | public static function render(ResponseInterface $response, $view, array $params = [])
{
return Application::getInstance()->view->render($response, $view, $params);
} | [
"public",
"static",
"function",
"render",
"(",
"ResponseInterface",
"$",
"response",
",",
"$",
"view",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"return",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"view",
"->",
"render",
"(",
"$",
"response",
",",
"$",
"view",
",",
"$",
"params",
")",
";",
"}"
] | Render a view file.
@param ResponseInterface $response
@param string $view Path of view file started from 'views' directory
@param array $params Assosiative array containing parameters to be passed to view
@return ResponseInterface | [
"Render",
"a",
"view",
"file",
"."
] | train | https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Helpers/View.php#L22-L25 |
KunstmaanLegacy/KunstmaanSentryBundle | KunstmaanSentryBundle.php | KunstmaanSentryBundle.boot | public function boot()
{
if (!$this->container->getParameter('kunstmaan_sentry.enabled')) {
return;
}
$errorHandler = new ErrorHandler($this->container->get('sentry.client'));
$errorHandler->registerErrorHandler(true);
$errorHandler->registerShutdownFunction(500);
} | php | public function boot()
{
if (!$this->container->getParameter('kunstmaan_sentry.enabled')) {
return;
}
$errorHandler = new ErrorHandler($this->container->get('sentry.client'));
$errorHandler->registerErrorHandler(true);
$errorHandler->registerShutdownFunction(500);
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'kunstmaan_sentry.enabled'",
")",
")",
"{",
"return",
";",
"}",
"$",
"errorHandler",
"=",
"new",
"ErrorHandler",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sentry.client'",
")",
")",
";",
"$",
"errorHandler",
"->",
"registerErrorHandler",
"(",
"true",
")",
";",
"$",
"errorHandler",
"->",
"registerShutdownFunction",
"(",
"500",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/KunstmaanLegacy/KunstmaanSentryBundle/blob/db2bcf2ac5c6864b24715bc596c5feb41c8951cf/KunstmaanSentryBundle.php#L16-L25 |
mustardandrew/muan-laravel-acl | src/Traits/HasPermissionsTrait.php | HasPermissionsTrait.hasPermissionThroughRole | public function hasPermissionThroughRole($permission)
{
if (! $this->isMethodRolesExists()) {
return false;
}
if (! $permission = $this->preparePermission($permission)) {
return false;
}
foreach ($permission->roles as $role) {
if ($this->roles->contains($role)) {
return true;
}
}
return false;
} | php | public function hasPermissionThroughRole($permission)
{
if (! $this->isMethodRolesExists()) {
return false;
}
if (! $permission = $this->preparePermission($permission)) {
return false;
}
foreach ($permission->roles as $role) {
if ($this->roles->contains($role)) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasPermissionThroughRole",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isMethodRolesExists",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"permission",
"=",
"$",
"this",
"->",
"preparePermission",
"(",
"$",
"permission",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"permission",
"->",
"roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"roles",
"->",
"contains",
"(",
"$",
"role",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Has permission through role
@param Permission|string $permission
@return boolean | [
"Has",
"permission",
"through",
"role"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasPermissionsTrait.php#L32-L49 |
mustardandrew/muan-laravel-acl | src/Traits/HasPermissionsTrait.php | HasPermissionsTrait.hasDirectPermission | public function hasDirectPermission($permission)
{
$name = $permission instanceof Permission ? $permission->name : $permission;
return (bool) $this->permissions->where('name', $name)->count();
} | php | public function hasDirectPermission($permission)
{
$name = $permission instanceof Permission ? $permission->name : $permission;
return (bool) $this->permissions->where('name', $name)->count();
} | [
"public",
"function",
"hasDirectPermission",
"(",
"$",
"permission",
")",
"{",
"$",
"name",
"=",
"$",
"permission",
"instanceof",
"Permission",
"?",
"$",
"permission",
"->",
"name",
":",
"$",
"permission",
";",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"permissions",
"->",
"where",
"(",
"'name'",
",",
"$",
"name",
")",
"->",
"count",
"(",
")",
";",
"}"
] | Has direct permission
@param Permission|string $permission
@return boolean | [
"Has",
"direct",
"permission"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasPermissionsTrait.php#L57-L61 |
mustardandrew/muan-laravel-acl | src/Traits/HasPermissionsTrait.php | HasPermissionsTrait.attachPermission | public function attachPermission(...$permissions)
{
$this->eachPermission($permissions, function($permission) {
if (! $this->hasDirectPermission($permission)) {
$this->permissions()->attach($permission->id);
}
});
return $this;
} | php | public function attachPermission(...$permissions)
{
$this->eachPermission($permissions, function($permission) {
if (! $this->hasDirectPermission($permission)) {
$this->permissions()->attach($permission->id);
}
});
return $this;
} | [
"public",
"function",
"attachPermission",
"(",
"...",
"$",
"permissions",
")",
"{",
"$",
"this",
"->",
"eachPermission",
"(",
"$",
"permissions",
",",
"function",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasDirectPermission",
"(",
"$",
"permission",
")",
")",
"{",
"$",
"this",
"->",
"permissions",
"(",
")",
"->",
"attach",
"(",
"$",
"permission",
"->",
"id",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Attach permission
@param mixed ...$permissions
@return $this | [
"Attach",
"permission"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasPermissionsTrait.php#L69-L78 |
mustardandrew/muan-laravel-acl | src/Traits/HasPermissionsTrait.php | HasPermissionsTrait.detachPermission | public function detachPermission(...$permissions)
{
$this->eachPermission($permissions, function($permission) {
if ($this->hasDirectPermission($permission)) {
$this->permissions()->detach($permission->id);
}
});
return $this;
} | php | public function detachPermission(...$permissions)
{
$this->eachPermission($permissions, function($permission) {
if ($this->hasDirectPermission($permission)) {
$this->permissions()->detach($permission->id);
}
});
return $this;
} | [
"public",
"function",
"detachPermission",
"(",
"...",
"$",
"permissions",
")",
"{",
"$",
"this",
"->",
"eachPermission",
"(",
"$",
"permissions",
",",
"function",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasDirectPermission",
"(",
"$",
"permission",
")",
")",
"{",
"$",
"this",
"->",
"permissions",
"(",
")",
"->",
"detach",
"(",
"$",
"permission",
"->",
"id",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Detach permission
@param mixed ...$permissions
@return $this | [
"Detach",
"permission"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasPermissionsTrait.php#L86-L95 |
mustardandrew/muan-laravel-acl | src/Traits/HasPermissionsTrait.php | HasPermissionsTrait.preparePermission | public function preparePermission($permission)
{
if ($permission instanceof Permission) {
return $permission;
}
if (is_numeric($permission)) {
return Permission::whereId($permission)->first();
}
return Permission::whereName($permission)->first();
} | php | public function preparePermission($permission)
{
if ($permission instanceof Permission) {
return $permission;
}
if (is_numeric($permission)) {
return Permission::whereId($permission)->first();
}
return Permission::whereName($permission)->first();
} | [
"public",
"function",
"preparePermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"permission",
"instanceof",
"Permission",
")",
"{",
"return",
"$",
"permission",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"permission",
")",
")",
"{",
"return",
"Permission",
"::",
"whereId",
"(",
"$",
"permission",
")",
"->",
"first",
"(",
")",
";",
"}",
"return",
"Permission",
"::",
"whereName",
"(",
"$",
"permission",
")",
"->",
"first",
"(",
")",
";",
"}"
] | Prepare permission
@param Permission|string $permission
@return Permission | [
"Prepare",
"permission"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasPermissionsTrait.php#L125-L136 |
mustardandrew/muan-laravel-acl | src/Traits/HasPermissionsTrait.php | HasPermissionsTrait.eachPermission | public function eachPermission(array $permissions, callable $callback)
{
$permissions = array_flatten($permissions);
foreach ($permissions as $permission) {
if ($permission = $this->preparePermission($permission)) {
$callback($permission);
}
}
} | php | public function eachPermission(array $permissions, callable $callback)
{
$permissions = array_flatten($permissions);
foreach ($permissions as $permission) {
if ($permission = $this->preparePermission($permission)) {
$callback($permission);
}
}
} | [
"public",
"function",
"eachPermission",
"(",
"array",
"$",
"permissions",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"permissions",
"=",
"array_flatten",
"(",
"$",
"permissions",
")",
";",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"permission",
"=",
"$",
"this",
"->",
"preparePermission",
"(",
"$",
"permission",
")",
")",
"{",
"$",
"callback",
"(",
"$",
"permission",
")",
";",
"}",
"}",
"}"
] | Calc each permission
@param array $permissions
@param callable $callback | [
"Calc",
"each",
"permission"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasPermissionsTrait.php#L144-L153 |
vaibhavpandeyvpz/sandesh | src/UriFactory.php | UriFactory.createUri | public function createUri($uri = '')
{
$obj = new Uri();
if (empty($uri)) {
return $obj;
}
$url = parse_url($uri);
if (!$url) {
throw new \InvalidArgumentException('URL passed is not a well-formed URI');
}
if (isset($url['fragment'])) {
$obj = $obj->withFragment($url['fragment']);
}
if (isset($url['host'])) {
$obj = $obj->withHost($url['host']);
}
if (isset($url['path'])) {
$obj = $obj->withPath($url['path']);
}
if (isset($url['port'])) {
$obj = $obj->withPort($url['port']);
}
if (isset($url['query'])) {
$obj = $obj->withQuery($url['query']);
}
if (isset($url['scheme'])) {
$obj = $obj->withScheme($url['scheme']);
}
if (isset($url['user'])) {
$password = isset($url['pass']) ? $url['pass'] : null;
$obj = $obj->withUserInfo($url['user'], $password);
}
return $obj;
} | php | public function createUri($uri = '')
{
$obj = new Uri();
if (empty($uri)) {
return $obj;
}
$url = parse_url($uri);
if (!$url) {
throw new \InvalidArgumentException('URL passed is not a well-formed URI');
}
if (isset($url['fragment'])) {
$obj = $obj->withFragment($url['fragment']);
}
if (isset($url['host'])) {
$obj = $obj->withHost($url['host']);
}
if (isset($url['path'])) {
$obj = $obj->withPath($url['path']);
}
if (isset($url['port'])) {
$obj = $obj->withPort($url['port']);
}
if (isset($url['query'])) {
$obj = $obj->withQuery($url['query']);
}
if (isset($url['scheme'])) {
$obj = $obj->withScheme($url['scheme']);
}
if (isset($url['user'])) {
$password = isset($url['pass']) ? $url['pass'] : null;
$obj = $obj->withUserInfo($url['user'], $password);
}
return $obj;
} | [
"public",
"function",
"createUri",
"(",
"$",
"uri",
"=",
"''",
")",
"{",
"$",
"obj",
"=",
"new",
"Uri",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"uri",
")",
")",
"{",
"return",
"$",
"obj",
";",
"}",
"$",
"url",
"=",
"parse_url",
"(",
"$",
"uri",
")",
";",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'URL passed is not a well-formed URI'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'fragment'",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"obj",
"->",
"withFragment",
"(",
"$",
"url",
"[",
"'fragment'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'host'",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"obj",
"->",
"withHost",
"(",
"$",
"url",
"[",
"'host'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"obj",
"->",
"withPath",
"(",
"$",
"url",
"[",
"'path'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"obj",
"->",
"withPort",
"(",
"$",
"url",
"[",
"'port'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"obj",
"->",
"withQuery",
"(",
"$",
"url",
"[",
"'query'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'scheme'",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"obj",
"->",
"withScheme",
"(",
"$",
"url",
"[",
"'scheme'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"password",
"=",
"isset",
"(",
"$",
"url",
"[",
"'pass'",
"]",
")",
"?",
"$",
"url",
"[",
"'pass'",
"]",
":",
"null",
";",
"$",
"obj",
"=",
"$",
"obj",
"->",
"withUserInfo",
"(",
"$",
"url",
"[",
"'user'",
"]",
",",
"$",
"password",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/UriFactory.php#L25-L58 |
bit3archive/php-remote-objects | src/RemoteObjects/Server.php | Server.handle | public function handle()
{
try {
$request = $this->transport->receive();
list($method, $params) = $this->encoder->decodeMethod($request);
if (!$method) {
$result = null;
}
else {
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Receive remote method invocation',
array(
'method' => $method,
'params' => $params
)
);
}
$result = $this->invoke(
$this->target,
$method,
$params
);
}
$response = $this->encoder->encodeResult($result);
$this->transport->respond($response);
}
catch (\Exception $e) {
$response = $this->encoder->encodeException($e);
$this->transport->respond($response);
}
} | php | public function handle()
{
try {
$request = $this->transport->receive();
list($method, $params) = $this->encoder->decodeMethod($request);
if (!$method) {
$result = null;
}
else {
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Receive remote method invocation',
array(
'method' => $method,
'params' => $params
)
);
}
$result = $this->invoke(
$this->target,
$method,
$params
);
}
$response = $this->encoder->encodeResult($result);
$this->transport->respond($response);
}
catch (\Exception $e) {
$response = $this->encoder->encodeException($e);
$this->transport->respond($response);
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"try",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"transport",
"->",
"receive",
"(",
")",
";",
"list",
"(",
"$",
"method",
",",
"$",
"params",
")",
"=",
"$",
"this",
"->",
"encoder",
"->",
"decodeMethod",
"(",
"$",
"request",
")",
";",
"if",
"(",
"!",
"$",
"method",
")",
"{",
"$",
"result",
"=",
"null",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
"!==",
"null",
"&&",
"$",
"this",
"->",
"logger",
"->",
"isHandling",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"DEBUG",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"addDebug",
"(",
"'Receive remote method invocation'",
",",
"array",
"(",
"'method'",
"=>",
"$",
"method",
",",
"'params'",
"=>",
"$",
"params",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"invoke",
"(",
"$",
"this",
"->",
"target",
",",
"$",
"method",
",",
"$",
"params",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"encoder",
"->",
"encodeResult",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"transport",
"->",
"respond",
"(",
"$",
"response",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"encoder",
"->",
"encodeException",
"(",
"$",
"e",
")",
";",
"$",
"this",
"->",
"transport",
"->",
"respond",
"(",
"$",
"response",
")",
";",
"}",
"}"
] | Handle a remote invokation request.
@return mixed | [
"Handle",
"a",
"remote",
"invokation",
"request",
"."
] | train | https://github.com/bit3archive/php-remote-objects/blob/0a917cdb261d83b1e89bdbdce3627584823bff5f/src/RemoteObjects/Server.php#L138-L178 |
bit3archive/php-remote-objects | src/RemoteObjects/Server.php | Server.invoke | protected function invoke($targetObject, $methodName, array $methodParams)
{
if (strpos($methodName, '.') !== false) {
list($propertyName, $methodName) = explode('.', $methodName, 2);
// access native array item
if (is_array($targetObject)) {
if (array_key_exists($propertyName, $targetObject)) {
return $this->invoke(
$targetObject[$propertyName],
$methodName,
$methodParams
);
}
}
// access array object
else if ($targetObject instanceof \ArrayAccess) {
if ($targetObject->offsetExists($propertyName)) {
return $this->invoke(
$targetObject->offsetGet($propertyName),
$methodName,
$methodParams
);
}
}
// access object property
else if (is_object($targetObject)) {
if (get_class($targetObject) == 'stdClass') {
if (isset($targetObject->$propertyName)) {
return $this->invoke(
$targetObject->$propertyName,
$methodName,
$methodParams
);
}
}
else {
$class = new \ReflectionClass($targetObject);
if ($class->hasProperty($propertyName)) {
$property = $class->getProperty($propertyName);
if ($property->isPublic()) {
return $this->invoke(
$property->getValue($targetObject),
$methodName,
$methodParams
);
}
}
$getterName = 'get';
$getterName .= implode('', array_map('ucfirst', explode('_', $propertyName)));
if ($class->hasMethod($getterName)) {
$getter = $class->getMethod($getterName);
if ($getter->isPublic()) {
return $this->invoke(
$getter->invoke($targetObject),
$methodName,
$methodParams
);
}
}
}
}
}
else if (is_object($targetObject)) {
$class = new \ReflectionClass($targetObject);
if ($class->hasMethod($methodName)) {
$method = $class->getMethod($methodName);
if ($method->isPublic()) {
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Invoke method from remote',
array(
'class' => get_class($targetObject),
'method' => $methodName,
'params' => $methodParams
)
);
}
return $method->invokeArgs($targetObject, $methodParams);
}
}
}
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addError(
'Could not invoke method, because method not exists or not accessible',
array(
'class' => get_class($targetObject),
'method' => $methodName,
'params' => $methodParams
)
);
}
throw new \Exception('Method not found', -32601);
} | php | protected function invoke($targetObject, $methodName, array $methodParams)
{
if (strpos($methodName, '.') !== false) {
list($propertyName, $methodName) = explode('.', $methodName, 2);
// access native array item
if (is_array($targetObject)) {
if (array_key_exists($propertyName, $targetObject)) {
return $this->invoke(
$targetObject[$propertyName],
$methodName,
$methodParams
);
}
}
// access array object
else if ($targetObject instanceof \ArrayAccess) {
if ($targetObject->offsetExists($propertyName)) {
return $this->invoke(
$targetObject->offsetGet($propertyName),
$methodName,
$methodParams
);
}
}
// access object property
else if (is_object($targetObject)) {
if (get_class($targetObject) == 'stdClass') {
if (isset($targetObject->$propertyName)) {
return $this->invoke(
$targetObject->$propertyName,
$methodName,
$methodParams
);
}
}
else {
$class = new \ReflectionClass($targetObject);
if ($class->hasProperty($propertyName)) {
$property = $class->getProperty($propertyName);
if ($property->isPublic()) {
return $this->invoke(
$property->getValue($targetObject),
$methodName,
$methodParams
);
}
}
$getterName = 'get';
$getterName .= implode('', array_map('ucfirst', explode('_', $propertyName)));
if ($class->hasMethod($getterName)) {
$getter = $class->getMethod($getterName);
if ($getter->isPublic()) {
return $this->invoke(
$getter->invoke($targetObject),
$methodName,
$methodParams
);
}
}
}
}
}
else if (is_object($targetObject)) {
$class = new \ReflectionClass($targetObject);
if ($class->hasMethod($methodName)) {
$method = $class->getMethod($methodName);
if ($method->isPublic()) {
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Invoke method from remote',
array(
'class' => get_class($targetObject),
'method' => $methodName,
'params' => $methodParams
)
);
}
return $method->invokeArgs($targetObject, $methodParams);
}
}
}
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addError(
'Could not invoke method, because method not exists or not accessible',
array(
'class' => get_class($targetObject),
'method' => $methodName,
'params' => $methodParams
)
);
}
throw new \Exception('Method not found', -32601);
} | [
"protected",
"function",
"invoke",
"(",
"$",
"targetObject",
",",
"$",
"methodName",
",",
"array",
"$",
"methodParams",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"methodName",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"propertyName",
",",
"$",
"methodName",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"methodName",
",",
"2",
")",
";",
"// access native array item",
"if",
"(",
"is_array",
"(",
"$",
"targetObject",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"propertyName",
",",
"$",
"targetObject",
")",
")",
"{",
"return",
"$",
"this",
"->",
"invoke",
"(",
"$",
"targetObject",
"[",
"$",
"propertyName",
"]",
",",
"$",
"methodName",
",",
"$",
"methodParams",
")",
";",
"}",
"}",
"// access array object",
"else",
"if",
"(",
"$",
"targetObject",
"instanceof",
"\\",
"ArrayAccess",
")",
"{",
"if",
"(",
"$",
"targetObject",
"->",
"offsetExists",
"(",
"$",
"propertyName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"invoke",
"(",
"$",
"targetObject",
"->",
"offsetGet",
"(",
"$",
"propertyName",
")",
",",
"$",
"methodName",
",",
"$",
"methodParams",
")",
";",
"}",
"}",
"// access object property",
"else",
"if",
"(",
"is_object",
"(",
"$",
"targetObject",
")",
")",
"{",
"if",
"(",
"get_class",
"(",
"$",
"targetObject",
")",
"==",
"'stdClass'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"targetObject",
"->",
"$",
"propertyName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"invoke",
"(",
"$",
"targetObject",
"->",
"$",
"propertyName",
",",
"$",
"methodName",
",",
"$",
"methodParams",
")",
";",
"}",
"}",
"else",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"targetObject",
")",
";",
"if",
"(",
"$",
"class",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
")",
"{",
"$",
"property",
"=",
"$",
"class",
"->",
"getProperty",
"(",
"$",
"propertyName",
")",
";",
"if",
"(",
"$",
"property",
"->",
"isPublic",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"invoke",
"(",
"$",
"property",
"->",
"getValue",
"(",
"$",
"targetObject",
")",
",",
"$",
"methodName",
",",
"$",
"methodParams",
")",
";",
"}",
"}",
"$",
"getterName",
"=",
"'get'",
";",
"$",
"getterName",
".=",
"implode",
"(",
"''",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"'_'",
",",
"$",
"propertyName",
")",
")",
")",
";",
"if",
"(",
"$",
"class",
"->",
"hasMethod",
"(",
"$",
"getterName",
")",
")",
"{",
"$",
"getter",
"=",
"$",
"class",
"->",
"getMethod",
"(",
"$",
"getterName",
")",
";",
"if",
"(",
"$",
"getter",
"->",
"isPublic",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"invoke",
"(",
"$",
"getter",
"->",
"invoke",
"(",
"$",
"targetObject",
")",
",",
"$",
"methodName",
",",
"$",
"methodParams",
")",
";",
"}",
"}",
"}",
"}",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"targetObject",
")",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"targetObject",
")",
";",
"if",
"(",
"$",
"class",
"->",
"hasMethod",
"(",
"$",
"methodName",
")",
")",
"{",
"$",
"method",
"=",
"$",
"class",
"->",
"getMethod",
"(",
"$",
"methodName",
")",
";",
"if",
"(",
"$",
"method",
"->",
"isPublic",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
"!==",
"null",
"&&",
"$",
"this",
"->",
"logger",
"->",
"isHandling",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"DEBUG",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"addDebug",
"(",
"'Invoke method from remote'",
",",
"array",
"(",
"'class'",
"=>",
"get_class",
"(",
"$",
"targetObject",
")",
",",
"'method'",
"=>",
"$",
"methodName",
",",
"'params'",
"=>",
"$",
"methodParams",
")",
")",
";",
"}",
"return",
"$",
"method",
"->",
"invokeArgs",
"(",
"$",
"targetObject",
",",
"$",
"methodParams",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"logger",
"!==",
"null",
"&&",
"$",
"this",
"->",
"logger",
"->",
"isHandling",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"DEBUG",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"addError",
"(",
"'Could not invoke method, because method not exists or not accessible'",
",",
"array",
"(",
"'class'",
"=>",
"get_class",
"(",
"$",
"targetObject",
")",
",",
"'method'",
"=>",
"$",
"methodName",
",",
"'params'",
"=>",
"$",
"methodParams",
")",
")",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'Method not found'",
",",
"-",
"32601",
")",
";",
"}"
] | @param mixed $targetObject
@param string $methodName
@param array $methodParams
@return mixed
@throws \Exception | [
"@param",
"mixed",
"$targetObject",
"@param",
"string",
"$methodName",
"@param",
"array",
"$methodParams"
] | train | https://github.com/bit3archive/php-remote-objects/blob/0a917cdb261d83b1e89bdbdce3627584823bff5f/src/RemoteObjects/Server.php#L188-L295 |
zhouyl/mellivora | Mellivora/View/Compilers/Compiler.php | Compiler.isExpired | public function isExpired($path)
{
$compiled = $this->getCompiledPath($path);
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if (!is_file($compiled)) {
return true;
}
return filemtime($path) >= filemtime($compiled);
} | php | public function isExpired($path)
{
$compiled = $this->getCompiledPath($path);
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if (!is_file($compiled)) {
return true;
}
return filemtime($path) >= filemtime($compiled);
} | [
"public",
"function",
"isExpired",
"(",
"$",
"path",
")",
"{",
"$",
"compiled",
"=",
"$",
"this",
"->",
"getCompiledPath",
"(",
"$",
"path",
")",
";",
"// If the compiled file doesn't exist we will indicate that the view is expired",
"// so that it can be re-compiled. Else, we will verify the last modification",
"// of the views is less than the modification times of the compiled views.",
"if",
"(",
"!",
"is_file",
"(",
"$",
"compiled",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"filemtime",
"(",
"$",
"path",
")",
">=",
"filemtime",
"(",
"$",
"compiled",
")",
";",
"}"
] | Determine if the view at the given path is expired.
@param string $path
@return bool | [
"Determine",
"if",
"the",
"view",
"at",
"the",
"given",
"path",
"is",
"expired",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/View/Compilers/Compiler.php#L62-L74 |
shabbyrobe/amiss | doc/demo/ar.php | ArtistRecord.getType | public function getType()
{
if ($this->type === null) {
$this->type = $this->getRelated('type');
}
return $this->type;
} | php | public function getType()
{
if ($this->type === null) {
$this->type = $this->getRelated('type');
}
return $this->type;
} | [
"public",
"function",
"getType",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"$",
"this",
"->",
"getRelated",
"(",
"'type'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"type",
";",
"}"
] | :amiss = {"has": {"type": "one", "of": "Amiss\\Demo\\Active\\ArtistType", "from": "artistTypeId"}}; | [
":",
"amiss",
"=",
"{",
"has",
":",
"{",
"type",
":",
"one",
"of",
":",
"Amiss",
"\\\\",
"Demo",
"\\\\",
"Active",
"\\\\",
"ArtistType",
"from",
":",
"artistTypeId",
"}}",
";"
] | train | https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/doc/demo/ar.php#L33-L39 |
shabbyrobe/amiss | doc/demo/ar.php | ArtistType.getArtists | public function getArtists()
{
if ($this->artists === null) {
$this->artists = $this->getRelated('artists');
}
return $this->artists;
} | php | public function getArtists()
{
if ($this->artists === null) {
$this->artists = $this->getRelated('artists');
}
return $this->artists;
} | [
"public",
"function",
"getArtists",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"artists",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"artists",
"=",
"$",
"this",
"->",
"getRelated",
"(",
"'artists'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"artists",
";",
"}"
] | :amiss = {"has": {
"type": "many",
"of" : "Amiss\\Demo\\Active\\ArtistRecord",
"to" : "artistTypeId"
}}; | [
":",
"amiss",
"=",
"{",
"has",
":",
"{",
"type",
":",
"many",
"of",
":",
"Amiss",
"\\\\",
"Demo",
"\\\\",
"Active",
"\\\\",
"ArtistRecord",
"to",
":",
"artistTypeId",
"}}",
";"
] | train | https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/doc/demo/ar.php#L66-L72 |
shabbyrobe/amiss | doc/demo/ar.php | EventRecord.getVenue | public function getVenue()
{
if (!$this->venue && $this->venueId) {
$this->venue = $this->getRelated('venue');
}
return $this->venue;
} | php | public function getVenue()
{
if (!$this->venue && $this->venueId) {
$this->venue = $this->getRelated('venue');
}
return $this->venue;
} | [
"public",
"function",
"getVenue",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"venue",
"&&",
"$",
"this",
"->",
"venueId",
")",
"{",
"$",
"this",
"->",
"venue",
"=",
"$",
"this",
"->",
"getRelated",
"(",
"'venue'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"venue",
";",
"}"
] | :amiss = {"has": {"type": "one", "of": "Amiss\\Demo\\Active\\VenueRecord", "from": "venueId"}}; | [
":",
"amiss",
"=",
"{",
"has",
":",
"{",
"type",
":",
"one",
"of",
":",
"Amiss",
"\\\\",
"Demo",
"\\\\",
"Active",
"\\\\",
"VenueRecord",
"from",
":",
"venueId",
"}}",
";"
] | train | https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/doc/demo/ar.php#L111-L117 |
wenbinye/PhalconX | src/Php/AutoUseFixer.php | AutoUseFixer.enterUse | public function enterUse(Node\Stmt\Use_ $node)
{
$this->stmts[] = $node;
foreach ($node->uses as $use) {
if (isset($this->uses[$use->alias])) {
if ($this->logger) {
$this->logger->warning("use {0} conflicts", [$use->name]);
}
} elseif ($node->type === Node\Stmt\Use_::TYPE_NORMAL) {
$this->uses[$use->alias] = $use;
}
}
} | php | public function enterUse(Node\Stmt\Use_ $node)
{
$this->stmts[] = $node;
foreach ($node->uses as $use) {
if (isset($this->uses[$use->alias])) {
if ($this->logger) {
$this->logger->warning("use {0} conflicts", [$use->name]);
}
} elseif ($node->type === Node\Stmt\Use_::TYPE_NORMAL) {
$this->uses[$use->alias] = $use;
}
}
} | [
"public",
"function",
"enterUse",
"(",
"Node",
"\\",
"Stmt",
"\\",
"Use_",
"$",
"node",
")",
"{",
"$",
"this",
"->",
"stmts",
"[",
"]",
"=",
"$",
"node",
";",
"foreach",
"(",
"$",
"node",
"->",
"uses",
"as",
"$",
"use",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"uses",
"[",
"$",
"use",
"->",
"alias",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"use {0} conflicts\"",
",",
"[",
"$",
"use",
"->",
"name",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"node",
"->",
"type",
"===",
"Node",
"\\",
"Stmt",
"\\",
"Use_",
"::",
"TYPE_NORMAL",
")",
"{",
"$",
"this",
"->",
"uses",
"[",
"$",
"use",
"->",
"alias",
"]",
"=",
"$",
"use",
";",
"}",
"}",
"}"
] | collect use | [
"collect",
"use"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Php/AutoUseFixer.php#L70-L82 |
rhosocial/yii2-user | rbac/DbManager.php | DbManager.getRolesByUser | public function getRolesByUser($userGuid)
{
if (!isset($userGuid) || $userGuid === '') {
return [];
}
if ($userGuid instanceof User) {
$userGuid = $userGuid->getGUID();
}
$query = (new Query)->select('b.*')
->from(['a' => $this->assignmentTable, 'b' => $this->itemTable])
->where('{{a}}.[[item_name]]={{b}}.[[name]]')
->andWhere(['a.user_guid' => (string) $userGuid])
->andWhere(['b.type' => Item::TYPE_ROLE]);
$roles = [];
foreach ($query->all($this->db) as $row) {
$roles[$row['name']] = $this->populateItem($row);
}
return $roles;
} | php | public function getRolesByUser($userGuid)
{
if (!isset($userGuid) || $userGuid === '') {
return [];
}
if ($userGuid instanceof User) {
$userGuid = $userGuid->getGUID();
}
$query = (new Query)->select('b.*')
->from(['a' => $this->assignmentTable, 'b' => $this->itemTable])
->where('{{a}}.[[item_name]]={{b}}.[[name]]')
->andWhere(['a.user_guid' => (string) $userGuid])
->andWhere(['b.type' => Item::TYPE_ROLE]);
$roles = [];
foreach ($query->all($this->db) as $row) {
$roles[$row['name']] = $this->populateItem($row);
}
return $roles;
} | [
"public",
"function",
"getRolesByUser",
"(",
"$",
"userGuid",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"userGuid",
")",
"||",
"$",
"userGuid",
"===",
"''",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"userGuid",
"instanceof",
"User",
")",
"{",
"$",
"userGuid",
"=",
"$",
"userGuid",
"->",
"getGUID",
"(",
")",
";",
"}",
"$",
"query",
"=",
"(",
"new",
"Query",
")",
"->",
"select",
"(",
"'b.*'",
")",
"->",
"from",
"(",
"[",
"'a'",
"=>",
"$",
"this",
"->",
"assignmentTable",
",",
"'b'",
"=>",
"$",
"this",
"->",
"itemTable",
"]",
")",
"->",
"where",
"(",
"'{{a}}.[[item_name]]={{b}}.[[name]]'",
")",
"->",
"andWhere",
"(",
"[",
"'a.user_guid'",
"=>",
"(",
"string",
")",
"$",
"userGuid",
"]",
")",
"->",
"andWhere",
"(",
"[",
"'b.type'",
"=>",
"Item",
"::",
"TYPE_ROLE",
"]",
")",
";",
"$",
"roles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"all",
"(",
"$",
"this",
"->",
"db",
")",
"as",
"$",
"row",
")",
"{",
"$",
"roles",
"[",
"$",
"row",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"populateItem",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"roles",
";",
"}"
] | Get roles by user.
@param string|User $userGuid
@return array | [
"Get",
"roles",
"by",
"user",
"."
] | train | https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/rbac/DbManager.php#L148-L169 |
rhosocial/yii2-user | rbac/DbManager.php | DbManager.getDirectPermissionsByUser | protected function getDirectPermissionsByUser($userGuid)
{
$query = (new Query)->select('b.*')
->from(['a' => $this->assignmentTable, 'b' => $this->itemTable])
->where('{{a}}.[[item_name]]={{b}}.[[name]]')
->andWhere(['a.user_guid' => (string) $userGuid])
->andWhere(['b.type' => Item::TYPE_PERMISSION]);
$permissions = [];
foreach ($query->all($this->db) as $row) {
$permissions[$row['name']] = $this->populateItem($row);
}
return $permissions;
} | php | protected function getDirectPermissionsByUser($userGuid)
{
$query = (new Query)->select('b.*')
->from(['a' => $this->assignmentTable, 'b' => $this->itemTable])
->where('{{a}}.[[item_name]]={{b}}.[[name]]')
->andWhere(['a.user_guid' => (string) $userGuid])
->andWhere(['b.type' => Item::TYPE_PERMISSION]);
$permissions = [];
foreach ($query->all($this->db) as $row) {
$permissions[$row['name']] = $this->populateItem($row);
}
return $permissions;
} | [
"protected",
"function",
"getDirectPermissionsByUser",
"(",
"$",
"userGuid",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"Query",
")",
"->",
"select",
"(",
"'b.*'",
")",
"->",
"from",
"(",
"[",
"'a'",
"=>",
"$",
"this",
"->",
"assignmentTable",
",",
"'b'",
"=>",
"$",
"this",
"->",
"itemTable",
"]",
")",
"->",
"where",
"(",
"'{{a}}.[[item_name]]={{b}}.[[name]]'",
")",
"->",
"andWhere",
"(",
"[",
"'a.user_guid'",
"=>",
"(",
"string",
")",
"$",
"userGuid",
"]",
")",
"->",
"andWhere",
"(",
"[",
"'b.type'",
"=>",
"Item",
"::",
"TYPE_PERMISSION",
"]",
")",
";",
"$",
"permissions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"all",
"(",
"$",
"this",
"->",
"db",
")",
"as",
"$",
"row",
")",
"{",
"$",
"permissions",
"[",
"$",
"row",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"populateItem",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"permissions",
";",
"}"
] | Returns all permissions that are directly assigned to user.
@param string|User $userGuid the user GUID (see [[\rhosocial\user\User::guid]])
@return Permission[] all direct permissions that the user has. The array is indexed by the permission names. | [
"Returns",
"all",
"permissions",
"that",
"are",
"directly",
"assigned",
"to",
"user",
"."
] | train | https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/rbac/DbManager.php#L176-L189 |
rhosocial/yii2-user | rbac/DbManager.php | DbManager.getInheritedPermissionsByUser | protected function getInheritedPermissionsByUser($userGuid)
{
$query = (new Query)->select('item_name')
->from($this->assignmentTable)
->where(['user_guid' => (string) $userGuid]);
$childrenList = $this->getChildrenList();
$result = [];
foreach ($query->column($this->db) as $roleName) {
$this->getChildrenRecursive($roleName, $childrenList, $result);
}
if (empty($result)) {
return [];
}
$query = (new Query)->from($this->itemTable)->where([
'type' => Item::TYPE_PERMISSION,
'name' => array_keys($result),
]);
$permissions = [];
foreach ($query->all($this->db) as $row) {
$permissions[$row['name']] = $this->populateItem($row);
}
return $permissions;
} | php | protected function getInheritedPermissionsByUser($userGuid)
{
$query = (new Query)->select('item_name')
->from($this->assignmentTable)
->where(['user_guid' => (string) $userGuid]);
$childrenList = $this->getChildrenList();
$result = [];
foreach ($query->column($this->db) as $roleName) {
$this->getChildrenRecursive($roleName, $childrenList, $result);
}
if (empty($result)) {
return [];
}
$query = (new Query)->from($this->itemTable)->where([
'type' => Item::TYPE_PERMISSION,
'name' => array_keys($result),
]);
$permissions = [];
foreach ($query->all($this->db) as $row) {
$permissions[$row['name']] = $this->populateItem($row);
}
return $permissions;
} | [
"protected",
"function",
"getInheritedPermissionsByUser",
"(",
"$",
"userGuid",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"Query",
")",
"->",
"select",
"(",
"'item_name'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"assignmentTable",
")",
"->",
"where",
"(",
"[",
"'user_guid'",
"=>",
"(",
"string",
")",
"$",
"userGuid",
"]",
")",
";",
"$",
"childrenList",
"=",
"$",
"this",
"->",
"getChildrenList",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"column",
"(",
"$",
"this",
"->",
"db",
")",
"as",
"$",
"roleName",
")",
"{",
"$",
"this",
"->",
"getChildrenRecursive",
"(",
"$",
"roleName",
",",
"$",
"childrenList",
",",
"$",
"result",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"query",
"=",
"(",
"new",
"Query",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"itemTable",
")",
"->",
"where",
"(",
"[",
"'type'",
"=>",
"Item",
"::",
"TYPE_PERMISSION",
",",
"'name'",
"=>",
"array_keys",
"(",
"$",
"result",
")",
",",
"]",
")",
";",
"$",
"permissions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"all",
"(",
"$",
"this",
"->",
"db",
")",
"as",
"$",
"row",
")",
"{",
"$",
"permissions",
"[",
"$",
"row",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"populateItem",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"permissions",
";",
"}"
] | Returns all permissions that the user inherits from the roles assigned to him.
@param string|User $userGuid the user GUID (see [[\rhosocial\user\User::guid]])
@return Permission[] all inherited permissions that the user has. The array is indexed by the permission names. | [
"Returns",
"all",
"permissions",
"that",
"the",
"user",
"inherits",
"from",
"the",
"roles",
"assigned",
"to",
"him",
"."
] | train | https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/rbac/DbManager.php#L196-L221 |
rhosocial/yii2-user | rbac/DbManager.php | DbManager.revokeFailedAssignment | protected function revokeFailedAssignment(Assignment $assignment)
{
if ($assignment->failedAt === null) {
return false;
}
if (strtotime($assignment->failedAt) < strtotime(gmdate('Y-m-d H:i:s'))) {
$role = $this->getRole($assignment->roleName);
if (!$role) {
return true;
}
$this->revoke($role->name, $assignment->userGuid);
return true;
}
return false;
} | php | protected function revokeFailedAssignment(Assignment $assignment)
{
if ($assignment->failedAt === null) {
return false;
}
if (strtotime($assignment->failedAt) < strtotime(gmdate('Y-m-d H:i:s'))) {
$role = $this->getRole($assignment->roleName);
if (!$role) {
return true;
}
$this->revoke($role->name, $assignment->userGuid);
return true;
}
return false;
} | [
"protected",
"function",
"revokeFailedAssignment",
"(",
"Assignment",
"$",
"assignment",
")",
"{",
"if",
"(",
"$",
"assignment",
"->",
"failedAt",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strtotime",
"(",
"$",
"assignment",
"->",
"failedAt",
")",
"<",
"strtotime",
"(",
"gmdate",
"(",
"'Y-m-d H:i:s'",
")",
")",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"getRole",
"(",
"$",
"assignment",
"->",
"roleName",
")",
";",
"if",
"(",
"!",
"$",
"role",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"revoke",
"(",
"$",
"role",
"->",
"name",
",",
"$",
"assignment",
"->",
"userGuid",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Revoke failed assignment.
If assignment's `failedAt` attribute is `null`, false will be given directly.
@param Assignment $assignment
@return boolean | [
"Revoke",
"failed",
"assignment",
".",
"If",
"assignment",
"s",
"failedAt",
"attribute",
"is",
"null",
"false",
"will",
"be",
"given",
"directly",
"."
] | train | https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/rbac/DbManager.php#L264-L278 |
rhosocial/yii2-user | rbac/DbManager.php | DbManager.getUserGuidsByRole | public function getUserGuidsByRole($roleName)
{
if (empty($roleName)) {
return [];
}
return (new Query)->select('[[user_guid]]')
->from($this->assignmentTable)
->where(['item_name' => $roleName])->column($this->db);
} | php | public function getUserGuidsByRole($roleName)
{
if (empty($roleName)) {
return [];
}
return (new Query)->select('[[user_guid]]')
->from($this->assignmentTable)
->where(['item_name' => $roleName])->column($this->db);
} | [
"public",
"function",
"getUserGuidsByRole",
"(",
"$",
"roleName",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"roleName",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"(",
"new",
"Query",
")",
"->",
"select",
"(",
"'[[user_guid]]'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"assignmentTable",
")",
"->",
"where",
"(",
"[",
"'item_name'",
"=>",
"$",
"roleName",
"]",
")",
"->",
"column",
"(",
"$",
"this",
"->",
"db",
")",
";",
"}"
] | Returns all role assignment information for the specified role.
@param string $roleName
@return Assignment[] the assignments. An empty array will be
returned if role is not assigned to any user.
@since 2.0.7 | [
"Returns",
"all",
"role",
"assignment",
"information",
"for",
"the",
"specified",
"role",
"."
] | train | https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/rbac/DbManager.php#L387-L396 |
PhrozenByte/pico-parse-pages-content | PicoParsePagesContent.php | PicoParsePagesContent.onSinglePageLoaded | public function onSinglePageLoaded(array &$pageData)
{
if (!isset($pageData['content'])) {
$pageData['content'] = $this->prepareFileContent($pageData['raw_content'], $pageData['meta']);
$pageData['content'] = $this->parseFileContent($pageData['content']);
}
} | php | public function onSinglePageLoaded(array &$pageData)
{
if (!isset($pageData['content'])) {
$pageData['content'] = $this->prepareFileContent($pageData['raw_content'], $pageData['meta']);
$pageData['content'] = $this->parseFileContent($pageData['content']);
}
} | [
"public",
"function",
"onSinglePageLoaded",
"(",
"array",
"&",
"$",
"pageData",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"pageData",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"pageData",
"[",
"'content'",
"]",
"=",
"$",
"this",
"->",
"prepareFileContent",
"(",
"$",
"pageData",
"[",
"'raw_content'",
"]",
",",
"$",
"pageData",
"[",
"'meta'",
"]",
")",
";",
"$",
"pageData",
"[",
"'content'",
"]",
"=",
"$",
"this",
"->",
"parseFileContent",
"(",
"$",
"pageData",
"[",
"'content'",
"]",
")",
";",
"}",
"}"
] | Parses the contents of all pages
@see DummyPlugin::onSinglePageLoaded() | [
"Parses",
"the",
"contents",
"of",
"all",
"pages"
] | train | https://github.com/PhrozenByte/pico-parse-pages-content/blob/fda8266f04d5bf523de1a07665a8d4c268099130/PicoParsePagesContent.php#L48-L54 |
php-lug/lug | src/Component/Grid/Column/Type/TextType.php | TextType.render | public function render($data, array $options)
{
$text = $this->getValue($data, $options);
if ($text === null) {
return;
}
if (!is_scalar($text)) {
throw new InvalidTypeException(sprintf(
'The "%s" %s column type expects a scalar value, got "%s".',
$options['column']->getName(),
$this->getName(),
is_object($text) ? get_class($text) : gettype($text)
));
}
return $text;
} | php | public function render($data, array $options)
{
$text = $this->getValue($data, $options);
if ($text === null) {
return;
}
if (!is_scalar($text)) {
throw new InvalidTypeException(sprintf(
'The "%s" %s column type expects a scalar value, got "%s".',
$options['column']->getName(),
$this->getName(),
is_object($text) ? get_class($text) : gettype($text)
));
}
return $text;
} | [
"public",
"function",
"render",
"(",
"$",
"data",
",",
"array",
"$",
"options",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"getValue",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"text",
"===",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"text",
")",
")",
"{",
"throw",
"new",
"InvalidTypeException",
"(",
"sprintf",
"(",
"'The \"%s\" %s column type expects a scalar value, got \"%s\".'",
",",
"$",
"options",
"[",
"'column'",
"]",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"is_object",
"(",
"$",
"text",
")",
"?",
"get_class",
"(",
"$",
"text",
")",
":",
"gettype",
"(",
"$",
"text",
")",
")",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/TextType.php#L24-L42 |
CodeSleeve/fixture-l4 | src/Codesleeve/FixtureL4/FixtureL4ServiceProvider.php | FixtureL4ServiceProvider.register | public function register()
{
$this->app->singleton('driver', function()
{
$db = $this->app['db']->connection()->getPdo();
return new EloquentDriver($db, $this->app['Str']);
});
$this->app->bind('fixture', function()
{
$fixture = Fixture::getInstance();
$fixture->setDriver($this->app['driver']);
$fixture->setConfig($this->app['config']->get('fixture-l4::config'));
return $fixture;
});
} | php | public function register()
{
$this->app->singleton('driver', function()
{
$db = $this->app['db']->connection()->getPdo();
return new EloquentDriver($db, $this->app['Str']);
});
$this->app->bind('fixture', function()
{
$fixture = Fixture::getInstance();
$fixture->setDriver($this->app['driver']);
$fixture->setConfig($this->app['config']->get('fixture-l4::config'));
return $fixture;
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'driver'",
",",
"function",
"(",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"app",
"[",
"'db'",
"]",
"->",
"connection",
"(",
")",
"->",
"getPdo",
"(",
")",
";",
"return",
"new",
"EloquentDriver",
"(",
"$",
"db",
",",
"$",
"this",
"->",
"app",
"[",
"'Str'",
"]",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'fixture'",
",",
"function",
"(",
")",
"{",
"$",
"fixture",
"=",
"Fixture",
"::",
"getInstance",
"(",
")",
";",
"$",
"fixture",
"->",
"setDriver",
"(",
"$",
"this",
"->",
"app",
"[",
"'driver'",
"]",
")",
";",
"$",
"fixture",
"->",
"setConfig",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'fixture-l4::config'",
")",
")",
";",
"return",
"$",
"fixture",
";",
"}",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/CodeSleeve/fixture-l4/blob/23db25bce6756221119f21ce58d1a675d1db5c23/src/Codesleeve/FixtureL4/FixtureL4ServiceProvider.php#L31-L48 |
oroinc/OroLayoutComponent | LayoutItem.php | LayoutItem.initialize | public function initialize($id, $alias = null)
{
$this->id = $id;
$this->alias = $alias;
} | php | public function initialize($id, $alias = null)
{
$this->id = $id;
$this->alias = $alias;
} | [
"public",
"function",
"initialize",
"(",
"$",
"id",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"id",
"=",
"$",
"id",
";",
"$",
"this",
"->",
"alias",
"=",
"$",
"alias",
";",
"}"
] | Initializes the state of this object
@param string $id The layout item id
@param string|null $alias The layout item alias | [
"Initializes",
"the",
"state",
"of",
"this",
"object"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutItem.php#L37-L41 |
trunda/SmfMenu | src/Smf/Menu/MenuExtension.php | MenuExtension.buildOptions | public function buildOptions(array $options)
{
$options = array_merge(
array(
'link' => null,
'icon' => null,
),
$options
);
if (isset($options['link']) && $options['link'] !== null) {
$options['extras']['link'] = (array) $options['link'];
}
$options['extras']['icon'] = $options['icon'];
return $options;
} | php | public function buildOptions(array $options)
{
$options = array_merge(
array(
'link' => null,
'icon' => null,
),
$options
);
if (isset($options['link']) && $options['link'] !== null) {
$options['extras']['link'] = (array) $options['link'];
}
$options['extras']['icon'] = $options['icon'];
return $options;
} | [
"public",
"function",
"buildOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"array",
"(",
"'link'",
"=>",
"null",
",",
"'icon'",
"=>",
"null",
",",
")",
",",
"$",
"options",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'link'",
"]",
")",
"&&",
"$",
"options",
"[",
"'link'",
"]",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'extras'",
"]",
"[",
"'link'",
"]",
"=",
"(",
"array",
")",
"$",
"options",
"[",
"'link'",
"]",
";",
"}",
"$",
"options",
"[",
"'extras'",
"]",
"[",
"'icon'",
"]",
"=",
"$",
"options",
"[",
"'icon'",
"]",
";",
"return",
"$",
"options",
";",
"}"
] | Builds the full option array used to configure the item.
@param array $options The options processed by the previous extensions
@return array | [
"Builds",
"the",
"full",
"option",
"array",
"used",
"to",
"configure",
"the",
"item",
"."
] | train | https://github.com/trunda/SmfMenu/blob/739e74fb664c1f018b4a74142bd28d20c004bac6/src/Smf/Menu/MenuExtension.php#L18-L33 |
novaway/open-graph | src/View/OpenGraphRenderer.php | OpenGraphRenderer.renderNamespaceAttributes | public function renderNamespaceAttributes(OpenGraphInterface $graph, $withTag = true)
{
$namespaces = $graph->getNamespaces();
if (empty($namespaces)) {
return '';
}
$attributes = '';
foreach ($namespaces as $prefix => $uri) {
if (!empty($attributes)) {
$attributes .= ' ';
}
$attributes .= sprintf('%s: %s', $prefix, $uri);
}
if ($withTag) {
$attributes = sprintf('prefix="%s"', $attributes);
}
return $attributes;
} | php | public function renderNamespaceAttributes(OpenGraphInterface $graph, $withTag = true)
{
$namespaces = $graph->getNamespaces();
if (empty($namespaces)) {
return '';
}
$attributes = '';
foreach ($namespaces as $prefix => $uri) {
if (!empty($attributes)) {
$attributes .= ' ';
}
$attributes .= sprintf('%s: %s', $prefix, $uri);
}
if ($withTag) {
$attributes = sprintf('prefix="%s"', $attributes);
}
return $attributes;
} | [
"public",
"function",
"renderNamespaceAttributes",
"(",
"OpenGraphInterface",
"$",
"graph",
",",
"$",
"withTag",
"=",
"true",
")",
"{",
"$",
"namespaces",
"=",
"$",
"graph",
"->",
"getNamespaces",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"namespaces",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"attributes",
"=",
"''",
";",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"prefix",
"=>",
"$",
"uri",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"attributes",
".=",
"' '",
";",
"}",
"$",
"attributes",
".=",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"prefix",
",",
"$",
"uri",
")",
";",
"}",
"if",
"(",
"$",
"withTag",
")",
"{",
"$",
"attributes",
"=",
"sprintf",
"(",
"'prefix=\"%s\"'",
",",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/novaway/open-graph/blob/19817bee4b91cf26ca3fe44883ad58b32328e464/src/View/OpenGraphRenderer.php#L28-L49 |
novaway/open-graph | src/View/OpenGraphRenderer.php | OpenGraphRenderer.render | public function render(OpenGraphInterface $graph, $tagSeparator = '')
{
$html = '';
foreach ($graph->getTags() as $tag) {
if (!empty($html)) {
$html .= $tagSeparator;
}
$html .= $this->renderTag($tag);
}
return $html;
} | php | public function render(OpenGraphInterface $graph, $tagSeparator = '')
{
$html = '';
foreach ($graph->getTags() as $tag) {
if (!empty($html)) {
$html .= $tagSeparator;
}
$html .= $this->renderTag($tag);
}
return $html;
} | [
"public",
"function",
"render",
"(",
"OpenGraphInterface",
"$",
"graph",
",",
"$",
"tagSeparator",
"=",
"''",
")",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"graph",
"->",
"getTags",
"(",
")",
"as",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"html",
")",
")",
"{",
"$",
"html",
".=",
"$",
"tagSeparator",
";",
"}",
"$",
"html",
".=",
"$",
"this",
"->",
"renderTag",
"(",
"$",
"tag",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/novaway/open-graph/blob/19817bee4b91cf26ca3fe44883ad58b32328e464/src/View/OpenGraphRenderer.php#L54-L67 |
novaway/open-graph | src/View/OpenGraphRenderer.php | OpenGraphRenderer.renderTag | public function renderTag(OpenGraphTagInterface $tag)
{
return str_replace(
['#property#', '#content#'],
[sprintf('%s:%s', $tag->getPrefix(), $tag->getProperty()), $tag->getContent()],
self::$tagTemplate
);
} | php | public function renderTag(OpenGraphTagInterface $tag)
{
return str_replace(
['#property#', '#content#'],
[sprintf('%s:%s', $tag->getPrefix(), $tag->getProperty()), $tag->getContent()],
self::$tagTemplate
);
} | [
"public",
"function",
"renderTag",
"(",
"OpenGraphTagInterface",
"$",
"tag",
")",
"{",
"return",
"str_replace",
"(",
"[",
"'#property#'",
",",
"'#content#'",
"]",
",",
"[",
"sprintf",
"(",
"'%s:%s'",
",",
"$",
"tag",
"->",
"getPrefix",
"(",
")",
",",
"$",
"tag",
"->",
"getProperty",
"(",
")",
")",
",",
"$",
"tag",
"->",
"getContent",
"(",
")",
"]",
",",
"self",
"::",
"$",
"tagTemplate",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/novaway/open-graph/blob/19817bee4b91cf26ca3fe44883ad58b32328e464/src/View/OpenGraphRenderer.php#L72-L79 |
oroinc/OroLayoutComponent | Loader/LayoutUpdateLoader.php | LayoutUpdateLoader.load | public function load($file)
{
$fileExt = pathinfo($file, PATHINFO_EXTENSION);
if (!isset($this->drivers[$fileExt])) {
return null;
}
$driver = $this->drivers[$fileExt];
return $driver->load($file);
} | php | public function load($file)
{
$fileExt = pathinfo($file, PATHINFO_EXTENSION);
if (!isset($this->drivers[$fileExt])) {
return null;
}
$driver = $this->drivers[$fileExt];
return $driver->load($file);
} | [
"public",
"function",
"load",
"(",
"$",
"file",
")",
"{",
"$",
"fileExt",
"=",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"drivers",
"[",
"$",
"fileExt",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"driver",
"=",
"$",
"this",
"->",
"drivers",
"[",
"$",
"fileExt",
"]",
";",
"return",
"$",
"driver",
"->",
"load",
"(",
"$",
"file",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Loader/LayoutUpdateLoader.php#L28-L38 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/CharacterReference.php | HTML5_Parser_CharacterReference.lookupName | public static function lookupName($name) {
// Do we really want to return NULL here? or FFFD
return isset(HTML5_Entities::$byName[$name]) ? HTML5_Entities::$byName[$name] : null;
} | php | public static function lookupName($name) {
// Do we really want to return NULL here? or FFFD
return isset(HTML5_Entities::$byName[$name]) ? HTML5_Entities::$byName[$name] : null;
} | [
"public",
"static",
"function",
"lookupName",
"(",
"$",
"name",
")",
"{",
"// Do we really want to return NULL here? or FFFD",
"return",
"isset",
"(",
"HTML5_Entities",
"::",
"$",
"byName",
"[",
"$",
"name",
"]",
")",
"?",
"HTML5_Entities",
"::",
"$",
"byName",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | Given a name (e.g.
'amp'), lookup the UTF-8 character ('&')
@param string $name
The name to look up.
@return string The character sequence. In UTF-8 this may be more than one byte. | [
"Given",
"a",
"name",
"(",
"e",
".",
"g",
".",
"amp",
")",
"lookup",
"the",
"UTF",
"-",
"8",
"character",
"(",
"&",
")"
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/CharacterReference.php#L111-L114 |
phPoirot/psr7 | Uri.php | Uri.getPort | public function getPort()
{
return $this->_isNonStandardPort($this->scheme, $this->host, $this->port)
? $this->port
: null;
} | php | public function getPort()
{
return $this->_isNonStandardPort($this->scheme, $this->host, $this->port)
? $this->port
: null;
} | [
"public",
"function",
"getPort",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"_isNonStandardPort",
"(",
"$",
"this",
"->",
"scheme",
",",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
")",
"?",
"$",
"this",
"->",
"port",
":",
"null",
";",
"}"
] | Retrieve the port component of the URI.
If a port is present, and it is non-standard for the current scheme,
this method MUST return it as an integer. If the port is the standard port
used with the current scheme, this method SHOULD return null.
If no port is present, and no scheme is present, this method MUST return
a null value.
If no port is present, but a scheme is present, this method MAY return
the standard port for that scheme, but SHOULD return null.
@return null|int The URI port. | [
"Retrieve",
"the",
"port",
"component",
"of",
"the",
"URI",
"."
] | train | https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Uri.php#L145-L150 |
phPoirot/psr7 | Uri.php | Uri.withScheme | public function withScheme($scheme)
{
$scheme = (string) $scheme;
if ($scheme === $this->scheme)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->scheme = $scheme;
return $new;
} | php | public function withScheme($scheme)
{
$scheme = (string) $scheme;
if ($scheme === $this->scheme)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->scheme = $scheme;
return $new;
} | [
"public",
"function",
"withScheme",
"(",
"$",
"scheme",
")",
"{",
"$",
"scheme",
"=",
"(",
"string",
")",
"$",
"scheme",
";",
"if",
"(",
"$",
"scheme",
"===",
"$",
"this",
"->",
"scheme",
")",
"// Do nothing if no change was made.",
"return",
"$",
"this",
";",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"$",
"new",
"->",
"scheme",
"=",
"$",
"scheme",
";",
"return",
"$",
"new",
";",
"}"
] | Return an instance with the specified scheme.
This method MUST retain the state of the current instance, and return
an instance that contains the specified scheme.
Implementations MUST support the schemes "http" and "https" case
insensitively, and MAY accommodate other schemes if required.
An empty scheme is equivalent to removing the scheme.
@param string $scheme The scheme to use with the new instance.
@return self A new instance with the specified scheme.
@throws \InvalidArgumentException for invalid or unsupported schemes. | [
"Return",
"an",
"instance",
"with",
"the",
"specified",
"scheme",
"."
] | train | https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Uri.php#L243-L254 |
phPoirot/psr7 | Uri.php | Uri.withHost | public function withHost($host)
{
$host = $this->_filterHost((string) $host);
if ($host === $this->host)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->host = $host;
return $new;
} | php | public function withHost($host)
{
$host = $this->_filterHost((string) $host);
if ($host === $this->host)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->host = $host;
return $new;
} | [
"public",
"function",
"withHost",
"(",
"$",
"host",
")",
"{",
"$",
"host",
"=",
"$",
"this",
"->",
"_filterHost",
"(",
"(",
"string",
")",
"$",
"host",
")",
";",
"if",
"(",
"$",
"host",
"===",
"$",
"this",
"->",
"host",
")",
"// Do nothing if no change was made.",
"return",
"$",
"this",
";",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"$",
"new",
"->",
"host",
"=",
"$",
"host",
";",
"return",
"$",
"new",
";",
"}"
] | Return an instance with the specified host.
This method MUST retain the state of the current instance, and return
an instance that contains the specified host.
An empty host value is equivalent to removing the host.
@param string $host The hostname to use with the new instance.
@return self A new instance with the specified host.
@throws \InvalidArgumentException for invalid hostnames. | [
"Return",
"an",
"instance",
"with",
"the",
"specified",
"host",
"."
] | train | https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Uri.php#L297-L308 |
phPoirot/psr7 | Uri.php | Uri.withPath | public function withPath($path)
{
$path = (string) $path;
if (strpos($path, '?') !== false || strpos($path, '#') !== false)
throw new \InvalidArgumentException(
'Invalid path provided; must not contain a query or fragment.'
);
if ($path === $this->path)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->path = $path;
return $new;
} | php | public function withPath($path)
{
$path = (string) $path;
if (strpos($path, '?') !== false || strpos($path, '#') !== false)
throw new \InvalidArgumentException(
'Invalid path provided; must not contain a query or fragment.'
);
if ($path === $this->path)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->path = $path;
return $new;
} | [
"public",
"function",
"withPath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"(",
"string",
")",
"$",
"path",
";",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'?'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"path",
",",
"'#'",
")",
"!==",
"false",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid path provided; must not contain a query or fragment.'",
")",
";",
"if",
"(",
"$",
"path",
"===",
"$",
"this",
"->",
"path",
")",
"// Do nothing if no change was made.",
"return",
"$",
"this",
";",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"$",
"new",
"->",
"path",
"=",
"$",
"path",
";",
"return",
"$",
"new",
";",
"}"
] | Return an instance with the specified path.
This method MUST retain the state of the current instance, and return
an instance that contains the specified path.
The path can either be empty or absolute (starting with a slash) or
rootless (not starting with a slash). Implementations MUST support all
three syntaxes.
If the path is intended to be domain-relative rather than path relative then
it must begin with a slash ("/"). Paths not starting with a slash ("/")
are assumed to be relative to some base path known to the application or
consumer.
Users can provide both encoded and decoded path characters.
Implementations ensure the correct encoding as outlined in getPath().
@param string $path The path to use with the new instance.
@return self A new instance with the specified path.
@throws \InvalidArgumentException for invalid paths. | [
"Return",
"an",
"instance",
"with",
"the",
"specified",
"path",
"."
] | train | https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Uri.php#L363-L380 |
phPoirot/psr7 | Uri.php | Uri.withQuery | public function withQuery($query)
{
$query = (string) $query;
if (strpos($query, '#') !== false)
throw new \InvalidArgumentException(
'Query string must not include a URI fragment'
);
if ($query === $this->query)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->query = $query;
return $new;
} | php | public function withQuery($query)
{
$query = (string) $query;
if (strpos($query, '#') !== false)
throw new \InvalidArgumentException(
'Query string must not include a URI fragment'
);
if ($query === $this->query)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->query = $query;
return $new;
} | [
"public",
"function",
"withQuery",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"=",
"(",
"string",
")",
"$",
"query",
";",
"if",
"(",
"strpos",
"(",
"$",
"query",
",",
"'#'",
")",
"!==",
"false",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Query string must not include a URI fragment'",
")",
";",
"if",
"(",
"$",
"query",
"===",
"$",
"this",
"->",
"query",
")",
"// Do nothing if no change was made.",
"return",
"$",
"this",
";",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"$",
"new",
"->",
"query",
"=",
"$",
"query",
";",
"return",
"$",
"new",
";",
"}"
] | Return an instance with the specified query string.
This method MUST retain the state of the current instance, and return
an instance that contains the specified query string.
Users can provide both encoded and decoded query characters.
Implementations ensure the correct encoding as outlined in getQuery().
An empty query string value is equivalent to removing the query string.
@param string $query The query string to use with the new instance.
@return self A new instance with the specified query string.
@throws \InvalidArgumentException for invalid query strings. | [
"Return",
"an",
"instance",
"with",
"the",
"specified",
"query",
"string",
"."
] | train | https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Uri.php#L397-L414 |
phPoirot/psr7 | Uri.php | Uri.withFragment | public function withFragment($fragment)
{
$fragment = (string) $fragment;
if (strlen($fragment) && $fragment[0] == '#')
$fragment = substr($fragment, 1);
if ($fragment === $this->fragment)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->fragment = $fragment;
return $new;
} | php | public function withFragment($fragment)
{
$fragment = (string) $fragment;
if (strlen($fragment) && $fragment[0] == '#')
$fragment = substr($fragment, 1);
if ($fragment === $this->fragment)
// Do nothing if no change was made.
return $this;
$new = clone $this;
$new->fragment = $fragment;
return $new;
} | [
"public",
"function",
"withFragment",
"(",
"$",
"fragment",
")",
"{",
"$",
"fragment",
"=",
"(",
"string",
")",
"$",
"fragment",
";",
"if",
"(",
"strlen",
"(",
"$",
"fragment",
")",
"&&",
"$",
"fragment",
"[",
"0",
"]",
"==",
"'#'",
")",
"$",
"fragment",
"=",
"substr",
"(",
"$",
"fragment",
",",
"1",
")",
";",
"if",
"(",
"$",
"fragment",
"===",
"$",
"this",
"->",
"fragment",
")",
"// Do nothing if no change was made.",
"return",
"$",
"this",
";",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"$",
"new",
"->",
"fragment",
"=",
"$",
"fragment",
";",
"return",
"$",
"new",
";",
"}"
] | Return an instance with the specified URI fragment.
This method MUST retain the state of the current instance, and return
an instance that contains the specified URI fragment.
Users can provide both encoded and decoded fragment characters.
Implementations ensure the correct encoding as outlined in getFragment().
An empty fragment value is equivalent to removing the fragment.
@param string $fragment The fragment to use with the new instance.
@return self A new instance with the specified fragment. | [
"Return",
"an",
"instance",
"with",
"the",
"specified",
"URI",
"fragment",
"."
] | train | https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Uri.php#L430-L444 |
phPoirot/psr7 | Uri.php | Uri._parseFromString | protected function _parseFromString($uri)
{
if (false === $parts = parse_url($uri))
throw new \InvalidArgumentException(sprintf(
'Malformed uri (%s).'
, $uri
));
$this->scheme = isset($parts['scheme']) ? $parts['scheme'] : '';
$this->userInfo = isset($parts['user']) ? $parts['user'] : '';
$this->host = isset($parts['host']) ? $this->_filterHost($parts['host']) : '';
$this->port = isset($parts['port']) ? $parts['port'] : null;
$this->path = isset($parts['path']) ? $parts['path'] : '';
$this->query = isset($parts['query']) ? $parts['query'] : '';
$this->fragment = isset($parts['fragment']) ? $parts['fragment'] : '';
if (isset($parts['pass']))
$this->userInfo .= ':' . $parts['pass'];
} | php | protected function _parseFromString($uri)
{
if (false === $parts = parse_url($uri))
throw new \InvalidArgumentException(sprintf(
'Malformed uri (%s).'
, $uri
));
$this->scheme = isset($parts['scheme']) ? $parts['scheme'] : '';
$this->userInfo = isset($parts['user']) ? $parts['user'] : '';
$this->host = isset($parts['host']) ? $this->_filterHost($parts['host']) : '';
$this->port = isset($parts['port']) ? $parts['port'] : null;
$this->path = isset($parts['path']) ? $parts['path'] : '';
$this->query = isset($parts['query']) ? $parts['query'] : '';
$this->fragment = isset($parts['fragment']) ? $parts['fragment'] : '';
if (isset($parts['pass']))
$this->userInfo .= ':' . $parts['pass'];
} | [
"protected",
"function",
"_parseFromString",
"(",
"$",
"uri",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"uri",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Malformed uri (%s).'",
",",
"$",
"uri",
")",
")",
";",
"$",
"this",
"->",
"scheme",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'scheme'",
"]",
")",
"?",
"$",
"parts",
"[",
"'scheme'",
"]",
":",
"''",
";",
"$",
"this",
"->",
"userInfo",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'user'",
"]",
")",
"?",
"$",
"parts",
"[",
"'user'",
"]",
":",
"''",
";",
"$",
"this",
"->",
"host",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'host'",
"]",
")",
"?",
"$",
"this",
"->",
"_filterHost",
"(",
"$",
"parts",
"[",
"'host'",
"]",
")",
":",
"''",
";",
"$",
"this",
"->",
"port",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'port'",
"]",
")",
"?",
"$",
"parts",
"[",
"'port'",
"]",
":",
"null",
";",
"$",
"this",
"->",
"path",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'path'",
"]",
")",
"?",
"$",
"parts",
"[",
"'path'",
"]",
":",
"''",
";",
"$",
"this",
"->",
"query",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
"?",
"$",
"parts",
"[",
"'query'",
"]",
":",
"''",
";",
"$",
"this",
"->",
"fragment",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'fragment'",
"]",
")",
"?",
"$",
"parts",
"[",
"'fragment'",
"]",
":",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'pass'",
"]",
")",
")",
"$",
"this",
"->",
"userInfo",
".=",
"':'",
".",
"$",
"parts",
"[",
"'pass'",
"]",
";",
"}"
] | Parse a URI into its parts, and set the properties
@param string $uri | [
"Parse",
"a",
"URI",
"into",
"its",
"parts",
"and",
"set",
"the",
"properties"
] | train | https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Uri.php#L503-L521 |
phPoirot/psr7 | Uri.php | Uri._filterHost | function _filterHost($host)
{
if (strstr($host, ':') !== false)
throw new \InvalidArgumentException('Host name can`t contains port number.');
$host = strtolower($host);
return $host;
} | php | function _filterHost($host)
{
if (strstr($host, ':') !== false)
throw new \InvalidArgumentException('Host name can`t contains port number.');
$host = strtolower($host);
return $host;
} | [
"function",
"_filterHost",
"(",
"$",
"host",
")",
"{",
"if",
"(",
"strstr",
"(",
"$",
"host",
",",
"':'",
")",
"!==",
"false",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Host name can`t contains port number.'",
")",
";",
"$",
"host",
"=",
"strtolower",
"(",
"$",
"host",
")",
";",
"return",
"$",
"host",
";",
"}"
] | Validate and Filter host value
@param string $host
@return string normalized value | [
"Validate",
"and",
"Filter",
"host",
"value"
] | train | https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Uri.php#L550-L557 |
j-d/draggy | src/Draggy/Utils/Indenter/CPP/CPPLineIndenter.php | CPPLineIndenter.identifyLines | protected function identifyLines()
{
foreach ($this->indenterMachine->getLines() as $lineNumber => $line) {
$this->lineTypes['commentBlock'][$lineNumber] = $this->isStartCommentBlock($lineNumber);
$this->lineTypes['startBraces'][$lineNumber] = $this->isStartBracesBlock($lineNumber);
$this->lineTypes['endBraces'][$lineNumber] = $this->isEndBracesBlock($lineNumber);
$this->lineTypes['startBrackets'][$lineNumber] = $this->isStartBracketsBlock($lineNumber);
$this->lineTypes['endBrackets'][$lineNumber] = $this->isEndBracketsBlock($lineNumber);
$this->lineTypes['startSquaredBrackets'][$lineNumber] = $this->isStartSquaredBracketsBlock($lineNumber);
$this->lineTypes['endSquaredBrackets'][$lineNumber] = $this->isEndSquaredBracketsBlock($lineNumber);
$this->lineTypes['startCase'][$lineNumber] = $this->isStartCaseBlock($lineNumber);
$this->lineTypes['endCase'][$lineNumber] = $this->isEndCaseBlock($lineNumber);
$this->lineTypes['startEcho'][$lineNumber] = $this->isStartEchoBlock($lineNumber);
$this->lineTypes['endEcho'][$lineNumber] = $this->isEndEchoBlock($lineNumber);
$this->lineTypes['arrow'][$lineNumber] = $this->isArrowsRow($lineNumber);
$this->lineTypes['assignment'][$lineNumber] = $this->isAssignmentLine($lineNumber);
$this->lineTypes['atParam'][$lineNumber] = $this->isAtParamLine($lineNumber);
$this->lineTypes['special'][$lineNumber] = $this->isSpecialIndentationBlock($lineNumber);
}
} | php | protected function identifyLines()
{
foreach ($this->indenterMachine->getLines() as $lineNumber => $line) {
$this->lineTypes['commentBlock'][$lineNumber] = $this->isStartCommentBlock($lineNumber);
$this->lineTypes['startBraces'][$lineNumber] = $this->isStartBracesBlock($lineNumber);
$this->lineTypes['endBraces'][$lineNumber] = $this->isEndBracesBlock($lineNumber);
$this->lineTypes['startBrackets'][$lineNumber] = $this->isStartBracketsBlock($lineNumber);
$this->lineTypes['endBrackets'][$lineNumber] = $this->isEndBracketsBlock($lineNumber);
$this->lineTypes['startSquaredBrackets'][$lineNumber] = $this->isStartSquaredBracketsBlock($lineNumber);
$this->lineTypes['endSquaredBrackets'][$lineNumber] = $this->isEndSquaredBracketsBlock($lineNumber);
$this->lineTypes['startCase'][$lineNumber] = $this->isStartCaseBlock($lineNumber);
$this->lineTypes['endCase'][$lineNumber] = $this->isEndCaseBlock($lineNumber);
$this->lineTypes['startEcho'][$lineNumber] = $this->isStartEchoBlock($lineNumber);
$this->lineTypes['endEcho'][$lineNumber] = $this->isEndEchoBlock($lineNumber);
$this->lineTypes['arrow'][$lineNumber] = $this->isArrowsRow($lineNumber);
$this->lineTypes['assignment'][$lineNumber] = $this->isAssignmentLine($lineNumber);
$this->lineTypes['atParam'][$lineNumber] = $this->isAtParamLine($lineNumber);
$this->lineTypes['special'][$lineNumber] = $this->isSpecialIndentationBlock($lineNumber);
}
} | [
"protected",
"function",
"identifyLines",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"indenterMachine",
"->",
"getLines",
"(",
")",
"as",
"$",
"lineNumber",
"=>",
"$",
"line",
")",
"{",
"$",
"this",
"->",
"lineTypes",
"[",
"'commentBlock'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isStartCommentBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'startBraces'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isStartBracesBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'endBraces'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isEndBracesBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'startBrackets'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isStartBracketsBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'endBrackets'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isEndBracketsBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'startSquaredBrackets'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isStartSquaredBracketsBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'endSquaredBrackets'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isEndSquaredBracketsBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'startCase'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isStartCaseBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'endCase'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isEndCaseBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'startEcho'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isStartEchoBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'endEcho'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isEndEchoBlock",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'arrow'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isArrowsRow",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'assignment'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isAssignmentLine",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'atParam'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isAtParamLine",
"(",
"$",
"lineNumber",
")",
";",
"$",
"this",
"->",
"lineTypes",
"[",
"'special'",
"]",
"[",
"$",
"lineNumber",
"]",
"=",
"$",
"this",
"->",
"isSpecialIndentationBlock",
"(",
"$",
"lineNumber",
")",
";",
"}",
"}"
] | {inheritdoc} | [
"{",
"inheritdoc",
"}"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Indenter/CPP/CPPLineIndenter.php#L24-L49 |
bavix/laravel-worker-command | src/Commands/WorkerCommand.php | WorkerCommand.fnUpdate | public function fnUpdate(\GearmanJob $job)
{
$this->config->cleanup();
/**
* @var array $workload
*/
$workload = JSON::decode($job->workload());
foreach ($workload as $config)
{
$this->info('update config: ' . $config);
\config([
$config => $this->config
->get($config)
->asArray()
]);
}
} | php | public function fnUpdate(\GearmanJob $job)
{
$this->config->cleanup();
/**
* @var array $workload
*/
$workload = JSON::decode($job->workload());
foreach ($workload as $config)
{
$this->info('update config: ' . $config);
\config([
$config => $this->config
->get($config)
->asArray()
]);
}
} | [
"public",
"function",
"fnUpdate",
"(",
"\\",
"GearmanJob",
"$",
"job",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"cleanup",
"(",
")",
";",
"/**\n * @var array $workload\n */",
"$",
"workload",
"=",
"JSON",
"::",
"decode",
"(",
"$",
"job",
"->",
"workload",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"workload",
"as",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"info",
"(",
"'update config: '",
".",
"$",
"config",
")",
";",
"\\",
"config",
"(",
"[",
"$",
"config",
"=>",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"config",
")",
"->",
"asArray",
"(",
")",
"]",
")",
";",
"}",
"}"
] | @param \GearmanJob $job
@throws PermissionDenied
@throws Invalid
@throws Path | [
"@param",
"\\",
"GearmanJob",
"$job"
] | train | https://github.com/bavix/laravel-worker-command/blob/005d7f9d8fe13e4d992c5fbaf6ff2014753c46e6/src/Commands/WorkerCommand.php#L74-L93 |
bavix/laravel-worker-command | src/Commands/WorkerCommand.php | WorkerCommand.handle | public function handle()
{
if ($this->fnUpdate)
{
$this->worker->addFunction(
$this->fnReload(),
[$this, 'fnUpdate']
);
}
foreach ($this->map as $name => $callable)
{
$this->worker->addFunction($name, $callable);
}
while ($this->worker->work())
{
continue;
}
return null;
} | php | public function handle()
{
if ($this->fnUpdate)
{
$this->worker->addFunction(
$this->fnReload(),
[$this, 'fnUpdate']
);
}
foreach ($this->map as $name => $callable)
{
$this->worker->addFunction($name, $callable);
}
while ($this->worker->work())
{
continue;
}
return null;
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fnUpdate",
")",
"{",
"$",
"this",
"->",
"worker",
"->",
"addFunction",
"(",
"$",
"this",
"->",
"fnReload",
"(",
")",
",",
"[",
"$",
"this",
",",
"'fnUpdate'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"map",
"as",
"$",
"name",
"=>",
"$",
"callable",
")",
"{",
"$",
"this",
"->",
"worker",
"->",
"addFunction",
"(",
"$",
"name",
",",
"$",
"callable",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"worker",
"->",
"work",
"(",
")",
")",
"{",
"continue",
";",
"}",
"return",
"null",
";",
"}"
] | Execute the console command.
@return null | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/bavix/laravel-worker-command/blob/005d7f9d8fe13e4d992c5fbaf6ff2014753c46e6/src/Commands/WorkerCommand.php#L100-L121 |
gregorybesson/PlaygroundCms | src/Mapper/BlockHydrator.php | BlockHydrator.extract | public function extract($object)
{
if (!$object instanceof BlockEntityInterface) {
throw new Exception\InvalidArgumentException(
'$object must be an instance of PlaygroundCms\Entity\BlockInterface'
);
}
/* @var $object BlockInterface*/
$data = parent::extract($object);
//$data = $this->mapField('id', 'block_id', $data);
return $data;
} | php | public function extract($object)
{
if (!$object instanceof BlockEntityInterface) {
throw new Exception\InvalidArgumentException(
'$object must be an instance of PlaygroundCms\Entity\BlockInterface'
);
}
/* @var $object BlockInterface*/
$data = parent::extract($object);
//$data = $this->mapField('id', 'block_id', $data);
return $data;
} | [
"public",
"function",
"extract",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"BlockEntityInterface",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'$object must be an instance of PlaygroundCms\\Entity\\BlockInterface'",
")",
";",
"}",
"/* @var $object BlockInterface*/",
"$",
"data",
"=",
"parent",
"::",
"extract",
"(",
"$",
"object",
")",
";",
"//$data = $this->mapField('id', 'block_id', $data);",
"return",
"$",
"data",
";",
"}"
] | Extract values from an object
@param object $object
@return array
@throws Exception\InvalidArgumentException | [
"Extract",
"values",
"from",
"an",
"object"
] | train | https://github.com/gregorybesson/PlaygroundCms/blob/e929a283f2a6e82d4f248c930f7aa454ce20cbc3/src/Mapper/BlockHydrator.php#L17-L29 |
gregorybesson/PlaygroundCms | src/Mapper/BlockHydrator.php | BlockHydrator.hydrate | public function hydrate(array $data, $object)
{
if (!$object instanceof BlockEntityInterface) {
throw new Exception\InvalidArgumentException(
'$object must be an instance of PlaygroundCms\Entity\BlockInterface'
);
}
//$data = $this->mapField('block_id', 'id', $data);
return parent::hydrate($data, $object);
} | php | public function hydrate(array $data, $object)
{
if (!$object instanceof BlockEntityInterface) {
throw new Exception\InvalidArgumentException(
'$object must be an instance of PlaygroundCms\Entity\BlockInterface'
);
}
//$data = $this->mapField('block_id', 'id', $data);
return parent::hydrate($data, $object);
} | [
"public",
"function",
"hydrate",
"(",
"array",
"$",
"data",
",",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"BlockEntityInterface",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'$object must be an instance of PlaygroundCms\\Entity\\BlockInterface'",
")",
";",
"}",
"//$data = $this->mapField('block_id', 'id', $data);",
"return",
"parent",
"::",
"hydrate",
"(",
"$",
"data",
",",
"$",
"object",
")",
";",
"}"
] | Hydrate $object with the provided $data.
@param array $data
@param object $object
@return BlockInterface
@throws Exception\InvalidArgumentException | [
"Hydrate",
"$object",
"with",
"the",
"provided",
"$data",
"."
] | train | https://github.com/gregorybesson/PlaygroundCms/blob/e929a283f2a6e82d4f248c930f7aa454ce20cbc3/src/Mapper/BlockHydrator.php#L39-L48 |
WScore/Validation | src/Verify.php | Verify.is | public function is($value, $rules)
{
$valTO = $this->apply($value, $rules);
if ($valTO->fails()) {
return false;
}
return $valTO->getValue();
} | php | public function is($value, $rules)
{
$valTO = $this->apply($value, $rules);
if ($valTO->fails()) {
return false;
}
return $valTO->getValue();
} | [
"public",
"function",
"is",
"(",
"$",
"value",
",",
"$",
"rules",
")",
"{",
"$",
"valTO",
"=",
"$",
"this",
"->",
"apply",
"(",
"$",
"value",
",",
"$",
"rules",
")",
";",
"if",
"(",
"$",
"valTO",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"valTO",
"->",
"getValue",
"(",
")",
";",
"}"
] | validates a text value, or an array of text values.
returns the filtered value, or false if validation fails.
@param string|array $value
@param array|Rules $rules
@return bool|string | [
"validates",
"a",
"text",
"value",
"or",
"an",
"array",
"of",
"text",
"values",
".",
"returns",
"the",
"filtered",
"value",
"or",
"false",
"if",
"validation",
"fails",
"."
] | train | https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Verify.php#L54-L62 |
WScore/Validation | src/Verify.php | Verify.applyFilters | public function applyFilters($value, $rules = array())
{
$valueTO = $this->valueTO->forge($value);
// loop through all the rules to validate $value.
foreach ($rules as $rule => $parameter) {
// skip rules with option as FALSE.
if ($parameter === false) {
continue;
}
$this->filter->apply($rule, $valueTO, $parameter);
// loop break.
if ($valueTO->getBreak()) {
break;
}
}
return $valueTO;
} | php | public function applyFilters($value, $rules = array())
{
$valueTO = $this->valueTO->forge($value);
// loop through all the rules to validate $value.
foreach ($rules as $rule => $parameter) {
// skip rules with option as FALSE.
if ($parameter === false) {
continue;
}
$this->filter->apply($rule, $valueTO, $parameter);
// loop break.
if ($valueTO->getBreak()) {
break;
}
}
return $valueTO;
} | [
"public",
"function",
"applyFilters",
"(",
"$",
"value",
",",
"$",
"rules",
"=",
"array",
"(",
")",
")",
"{",
"$",
"valueTO",
"=",
"$",
"this",
"->",
"valueTO",
"->",
"forge",
"(",
"$",
"value",
")",
";",
"// loop through all the rules to validate $value.",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
"=>",
"$",
"parameter",
")",
"{",
"// skip rules with option as FALSE.",
"if",
"(",
"$",
"parameter",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"filter",
"->",
"apply",
"(",
"$",
"rule",
",",
"$",
"valueTO",
",",
"$",
"parameter",
")",
";",
"// loop break.",
"if",
"(",
"$",
"valueTO",
"->",
"getBreak",
"(",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"valueTO",
";",
"}"
] | apply filters on a single value.
@param string $value
@param array|Rules $rules
@return ValueTO | [
"apply",
"filters",
"on",
"a",
"single",
"value",
"."
] | train | https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Verify.php#L94-L112 |
php-lug/lug | src/Component/Behat/Extension/Api/Context/ApiContext.php | ApiContext.setBaseUrl | public function setBaseUrl($baseUrl)
{
if (strrpos($baseUrl, '/') === strlen($baseUrl) - 1) {
$baseUrl = substr($baseUrl, 0, -1);
}
$this->baseUrl = $baseUrl;
} | php | public function setBaseUrl($baseUrl)
{
if (strrpos($baseUrl, '/') === strlen($baseUrl) - 1) {
$baseUrl = substr($baseUrl, 0, -1);
}
$this->baseUrl = $baseUrl;
} | [
"public",
"function",
"setBaseUrl",
"(",
"$",
"baseUrl",
")",
"{",
"if",
"(",
"strrpos",
"(",
"$",
"baseUrl",
",",
"'/'",
")",
"===",
"strlen",
"(",
"$",
"baseUrl",
")",
"-",
"1",
")",
"{",
"$",
"baseUrl",
"=",
"substr",
"(",
"$",
"baseUrl",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"$",
"this",
"->",
"baseUrl",
"=",
"$",
"baseUrl",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Behat/Extension/Api/Context/ApiContext.php#L137-L144 |
php-lug/lug | src/Component/Behat/Extension/Api/Context/ApiContext.php | ApiContext.reset | public function reset()
{
$this->headers = [];
$this->request = null;
$this->response = null;
$this->multipartStreamBuilder = null;
foreach ($this->resources as $resource) {
if (is_resource($resource)) {
fclose($resource);
}
}
$this->resources = [];
} | php | public function reset()
{
$this->headers = [];
$this->request = null;
$this->response = null;
$this->multipartStreamBuilder = null;
foreach ($this->resources as $resource) {
if (is_resource($resource)) {
fclose($resource);
}
}
$this->resources = [];
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"headers",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"request",
"=",
"null",
";",
"$",
"this",
"->",
"response",
"=",
"null",
";",
"$",
"this",
"->",
"multipartStreamBuilder",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"resources",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"resource",
")",
")",
"{",
"fclose",
"(",
"$",
"resource",
")",
";",
"}",
"}",
"$",
"this",
"->",
"resources",
"=",
"[",
"]",
";",
"}"
] | @BeforeScenario
@Given I reset the API context | [
"@BeforeScenario"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Behat/Extension/Api/Context/ApiContext.php#L151-L165 |
php-lug/lug | src/Component/Behat/Extension/Api/Context/ApiContext.php | ApiContext.setFile | public function setFile($name, $file, $filename = null)
{
$path = $this->fileLocator->locate($file);
$this->resources[] = $resource = fopen($path, 'r');
$this->getMultipartStreamBuilder()->addResource($name, $resource, ['filename' => $filename]);
} | php | public function setFile($name, $file, $filename = null)
{
$path = $this->fileLocator->locate($file);
$this->resources[] = $resource = fopen($path, 'r');
$this->getMultipartStreamBuilder()->addResource($name, $resource, ['filename' => $filename]);
} | [
"public",
"function",
"setFile",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"filename",
"=",
"null",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"fileLocator",
"->",
"locate",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"resources",
"[",
"]",
"=",
"$",
"resource",
"=",
"fopen",
"(",
"$",
"path",
",",
"'r'",
")",
";",
"$",
"this",
"->",
"getMultipartStreamBuilder",
"(",
")",
"->",
"addResource",
"(",
"$",
"name",
",",
"$",
"resource",
",",
"[",
"'filename'",
"=>",
"$",
"filename",
"]",
")",
";",
"}"
] | @param string $name
@param string $file
@param string|null $filename
@Given I set the field ":name" with file ":file"
@Given I set the field ":name" with file ":file" and filename ":filename" | [
"@param",
"string",
"$name",
"@param",
"string",
"$file",
"@param",
"string|null",
"$filename"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Behat/Extension/Api/Context/ApiContext.php#L218-L223 |
php-lug/lug | src/Component/Behat/Extension/Api/Context/ApiContext.php | ApiContext.send | public function send($method, $url)
{
$this->request = $this->requestFactory->createRequest($method, $this->prepareUrl($url), $this->headers);
$this->sendRequest();
} | php | public function send($method, $url)
{
$this->request = $this->requestFactory->createRequest($method, $this->prepareUrl($url), $this->headers);
$this->sendRequest();
} | [
"public",
"function",
"send",
"(",
"$",
"method",
",",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"request",
"=",
"$",
"this",
"->",
"requestFactory",
"->",
"createRequest",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"prepareUrl",
"(",
"$",
"url",
")",
",",
"$",
"this",
"->",
"headers",
")",
";",
"$",
"this",
"->",
"sendRequest",
"(",
")",
";",
"}"
] | @param string $method
@param string $url
@When I send a ":method" request to ":url" | [
"@param",
"string",
"$method",
"@param",
"string",
"$url"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Behat/Extension/Api/Context/ApiContext.php#L231-L236 |
php-lug/lug | src/Component/Behat/Extension/Api/Context/ApiContext.php | ApiContext.sendWith | public function sendWith($method, $url, PyStringNode $string)
{
$this->request = $this->requestFactory->createRequest(
$method,
$this->prepareUrl($url),
$this->headers,
trim($string->getRaw())
);
$this->sendRequest();
} | php | public function sendWith($method, $url, PyStringNode $string)
{
$this->request = $this->requestFactory->createRequest(
$method,
$this->prepareUrl($url),
$this->headers,
trim($string->getRaw())
);
$this->sendRequest();
} | [
"public",
"function",
"sendWith",
"(",
"$",
"method",
",",
"$",
"url",
",",
"PyStringNode",
"$",
"string",
")",
"{",
"$",
"this",
"->",
"request",
"=",
"$",
"this",
"->",
"requestFactory",
"->",
"createRequest",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"prepareUrl",
"(",
"$",
"url",
")",
",",
"$",
"this",
"->",
"headers",
",",
"trim",
"(",
"$",
"string",
"->",
"getRaw",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"sendRequest",
"(",
")",
";",
"}"
] | @param string $method
@param string $url
@param PyStringNode $string
@When I send a ":method" request to ":url" with body: | [
"@param",
"string",
"$method",
"@param",
"string",
"$url",
"@param",
"PyStringNode",
"$string"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Behat/Extension/Api/Context/ApiContext.php#L245-L255 |
php-lug/lug | src/Component/Behat/Extension/Api/Context/ApiContext.php | ApiContext.assertResponseContains | public function assertResponseContains(PyStringNode $json)
{
$this->matcher->match((string) $this->response->getBody(), $json->getRaw());
\PHPUnit_Framework_Assert::assertNull($this->matcher->getError());
} | php | public function assertResponseContains(PyStringNode $json)
{
$this->matcher->match((string) $this->response->getBody(), $json->getRaw());
\PHPUnit_Framework_Assert::assertNull($this->matcher->getError());
} | [
"public",
"function",
"assertResponseContains",
"(",
"PyStringNode",
"$",
"json",
")",
"{",
"$",
"this",
"->",
"matcher",
"->",
"match",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"response",
"->",
"getBody",
"(",
")",
",",
"$",
"json",
"->",
"getRaw",
"(",
")",
")",
";",
"\\",
"PHPUnit_Framework_Assert",
"::",
"assertNull",
"(",
"$",
"this",
"->",
"matcher",
"->",
"getError",
"(",
")",
")",
";",
"}"
] | @param PyStringNode $json
@Then the response should contain: | [
"@param",
"PyStringNode",
"$json"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Behat/Extension/Api/Context/ApiContext.php#L272-L277 |
JBZoo/Assets | src/Asset/LessFile.php | LessFile.load | public function load(array $filters = [])
{
$result = parent::load($filters);
$compiled = null;
if ($result[1]) {
$options = $this->_manager->getParams();
$root = $this->_manager->getPath()->getRoot();
$less = new Less($options->get('less'));
$compiled = $less->compile($result[1], $root);
}
return [Asset::TYPE_CSS_FILE, $compiled];
} | php | public function load(array $filters = [])
{
$result = parent::load($filters);
$compiled = null;
if ($result[1]) {
$options = $this->_manager->getParams();
$root = $this->_manager->getPath()->getRoot();
$less = new Less($options->get('less'));
$compiled = $less->compile($result[1], $root);
}
return [Asset::TYPE_CSS_FILE, $compiled];
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"filters",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"load",
"(",
"$",
"filters",
")",
";",
"$",
"compiled",
"=",
"null",
";",
"if",
"(",
"$",
"result",
"[",
"1",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_manager",
"->",
"getParams",
"(",
")",
";",
"$",
"root",
"=",
"$",
"this",
"->",
"_manager",
"->",
"getPath",
"(",
")",
"->",
"getRoot",
"(",
")",
";",
"$",
"less",
"=",
"new",
"Less",
"(",
"$",
"options",
"->",
"get",
"(",
"'less'",
")",
")",
";",
"$",
"compiled",
"=",
"$",
"less",
"->",
"compile",
"(",
"$",
"result",
"[",
"1",
"]",
",",
"$",
"root",
")",
";",
"}",
"return",
"[",
"Asset",
"::",
"TYPE_CSS_FILE",
",",
"$",
"compiled",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/JBZoo/Assets/blob/134a109378f5b5e955dfb15e6ed2821581564991/src/Asset/LessFile.php#L31-L44 |
php-lug/lug | src/Component/Resource/Domain/DomainManager.php | DomainManager.doFind | protected function doFind($action, $repositoryMethod, array $criteria, array $sorting)
{
return $this->repository->$repositoryMethod($criteria, $sorting);
} | php | protected function doFind($action, $repositoryMethod, array $criteria, array $sorting)
{
return $this->repository->$repositoryMethod($criteria, $sorting);
} | [
"protected",
"function",
"doFind",
"(",
"$",
"action",
",",
"$",
"repositoryMethod",
",",
"array",
"$",
"criteria",
",",
"array",
"$",
"sorting",
")",
"{",
"return",
"$",
"this",
"->",
"repository",
"->",
"$",
"repositoryMethod",
"(",
"$",
"criteria",
",",
"$",
"sorting",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Domain/DomainManager.php#L55-L58 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.