repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Wedeto/HTTP | src/Response/RedirectRequest.php | RedirectRequest.getHeaders | public function getHeaders()
{
$h = array();
if (!empty($this->timeout))
$h['Refresh'] = $this->timeout . '; url=' . $this->url;
else
$h['Location'] = (string)$this->url;
return $h;
} | php | public function getHeaders()
{
$h = array();
if (!empty($this->timeout))
$h['Refresh'] = $this->timeout . '; url=' . $this->url;
else
$h['Location'] = (string)$this->url;
return $h;
} | [
"public",
"function",
"getHeaders",
"(",
")",
"{",
"$",
"h",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"timeout",
")",
")",
"$",
"h",
"[",
"'Refresh'",
"]",
"=",
"$",
"this",
"->",
"timeout",
".",
"'; url='",
".",
"$",
"this",
"->",
"url",
";",
"else",
"$",
"h",
"[",
"'Location'",
"]",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"url",
";",
"return",
"$",
"h",
";",
"}"
]
| Return the redirection headers | [
"Return",
"the",
"redirection",
"headers"
]
| 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Response/RedirectRequest.php#L87-L95 | train |
Erebot/Module_Wordlists | src/Wordlists.php | Wordlists.getHelp | public function getHelp(
\Erebot\Interfaces\Event\Base\TextMessage $event,
\Erebot\Interfaces\TextWrapper $words
) {
if ($event instanceof \Erebot\Interfaces\Event\Base\PrivateMessage) {
$target = $event->getSource();
$chan = null;
} else {
$target = $chan = $event->getChan();
}
if (count($words) == 1 && $words[0] === get_called_class()) {
$msg = $this->getFormatter($chan)->_(
"This module does not provide any command, but ".
"provides lists of words that other modules may use."
);
$this->sendMessage($target, $msg);
return true;
}
} | php | public function getHelp(
\Erebot\Interfaces\Event\Base\TextMessage $event,
\Erebot\Interfaces\TextWrapper $words
) {
if ($event instanceof \Erebot\Interfaces\Event\Base\PrivateMessage) {
$target = $event->getSource();
$chan = null;
} else {
$target = $chan = $event->getChan();
}
if (count($words) == 1 && $words[0] === get_called_class()) {
$msg = $this->getFormatter($chan)->_(
"This module does not provide any command, but ".
"provides lists of words that other modules may use."
);
$this->sendMessage($target, $msg);
return true;
}
} | [
"public",
"function",
"getHelp",
"(",
"\\",
"Erebot",
"\\",
"Interfaces",
"\\",
"Event",
"\\",
"Base",
"\\",
"TextMessage",
"$",
"event",
",",
"\\",
"Erebot",
"\\",
"Interfaces",
"\\",
"TextWrapper",
"$",
"words",
")",
"{",
"if",
"(",
"$",
"event",
"instanceof",
"\\",
"Erebot",
"\\",
"Interfaces",
"\\",
"Event",
"\\",
"Base",
"\\",
"PrivateMessage",
")",
"{",
"$",
"target",
"=",
"$",
"event",
"->",
"getSource",
"(",
")",
";",
"$",
"chan",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"target",
"=",
"$",
"chan",
"=",
"$",
"event",
"->",
"getChan",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"words",
")",
"==",
"1",
"&&",
"$",
"words",
"[",
"0",
"]",
"===",
"get_called_class",
"(",
")",
")",
"{",
"$",
"msg",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
"$",
"chan",
")",
"->",
"_",
"(",
"\"This module does not provide any command, but \"",
".",
"\"provides lists of words that other modules may use.\"",
")",
";",
"$",
"this",
"->",
"sendMessage",
"(",
"$",
"target",
",",
"$",
"msg",
")",
";",
"return",
"true",
";",
"}",
"}"
]
| Provides help about this module.
\param Erebot::Interfaces::Event::Base::TextMessage $event
Some help request.
\param Erebot::Interfaces::TextWrapper $words
Parameters passed with the request. This is the same
as this module's name when help is requested on the
module itself (in opposition with help on a specific
command provided by the module). | [
"Provides",
"help",
"about",
"this",
"module",
"."
]
| 121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7 | https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists.php#L77-L96 | train |
Erebot/Module_Wordlists | src/Wordlists.php | Wordlists.getAvailableLists | public function getAvailableLists()
{
if (self::$cache !== null) {
return array_keys(self::$cache);
}
$lists = array();
foreach (self::$paths as $path) {
$files = scandir($path);
foreach ($files as $file) {
if (substr($file, -7) == '.sqlite') {
$name = strtolower(substr($file, 0, -7));
if (isset($lists[$name])) {
; /// @TODO: log a warning
} else {
$lists[$name] = $path . DIRECTORY_SEPARATOR . $file;
}
}
}
}
// Create a regexp pattern for the policy
// and filter the lists according to that policy.
$policy = self::compilePolicy(
explode(' ', $this->parseString('policy', ''))
);
$lists = self::filterLists($lists, $policy);
self::$cache = $lists;
return array_keys($lists);
} | php | public function getAvailableLists()
{
if (self::$cache !== null) {
return array_keys(self::$cache);
}
$lists = array();
foreach (self::$paths as $path) {
$files = scandir($path);
foreach ($files as $file) {
if (substr($file, -7) == '.sqlite') {
$name = strtolower(substr($file, 0, -7));
if (isset($lists[$name])) {
; /// @TODO: log a warning
} else {
$lists[$name] = $path . DIRECTORY_SEPARATOR . $file;
}
}
}
}
// Create a regexp pattern for the policy
// and filter the lists according to that policy.
$policy = self::compilePolicy(
explode(' ', $this->parseString('policy', ''))
);
$lists = self::filterLists($lists, $policy);
self::$cache = $lists;
return array_keys($lists);
} | [
"public",
"function",
"getAvailableLists",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"cache",
"!==",
"null",
")",
"{",
"return",
"array_keys",
"(",
"self",
"::",
"$",
"cache",
")",
";",
"}",
"$",
"lists",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"$",
"files",
"=",
"scandir",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"-",
"7",
")",
"==",
"'.sqlite'",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"-",
"7",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"lists",
"[",
"$",
"name",
"]",
")",
")",
"{",
";",
"/// @TODO: log a warning",
"}",
"else",
"{",
"$",
"lists",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"}",
"}",
"}",
"}",
"// Create a regexp pattern for the policy",
"// and filter the lists according to that policy.",
"$",
"policy",
"=",
"self",
"::",
"compilePolicy",
"(",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"parseString",
"(",
"'policy'",
",",
"''",
")",
")",
")",
";",
"$",
"lists",
"=",
"self",
"::",
"filterLists",
"(",
"$",
"lists",
",",
"$",
"policy",
")",
";",
"self",
"::",
"$",
"cache",
"=",
"$",
"lists",
";",
"return",
"array_keys",
"(",
"$",
"lists",
")",
";",
"}"
]
| Returns the names of available lists.
\retval list
The names of all available lists. | [
"Returns",
"the",
"names",
"of",
"available",
"lists",
"."
]
| 121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7 | https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists.php#L104-L134 | train |
Erebot/Module_Wordlists | src/Wordlists.php | Wordlists.filterLists | protected static function filterLists($lists, $policy)
{
$res = array();
foreach ($lists as $name => $path) {
if ((bool) preg_match($policy, $name)) {
$res[$name] = $path;
}
}
return $res;
} | php | protected static function filterLists($lists, $policy)
{
$res = array();
foreach ($lists as $name => $path) {
if ((bool) preg_match($policy, $name)) {
$res[$name] = $path;
}
}
return $res;
} | [
"protected",
"static",
"function",
"filterLists",
"(",
"$",
"lists",
",",
"$",
"policy",
")",
"{",
"$",
"res",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"lists",
"as",
"$",
"name",
"=>",
"$",
"path",
")",
"{",
"if",
"(",
"(",
"bool",
")",
"preg_match",
"(",
"$",
"policy",
",",
"$",
"name",
")",
")",
"{",
"$",
"res",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
";",
"}",
"}",
"return",
"$",
"res",
";",
"}"
]
| Given a mapping of wordlists' names with their path
and a policy, returns the same mapping with only
those entries whose name matches the policy.
\param array $lists
A mapping of wordlists (indexed by their names)
to their path.
\param string $policy
A policy (as a regular expression pattern).
\retval array
A mapping of wordlists (indexed by their names)
to their path, contaning only those wordlists
that were allowed by the given policy. | [
"Given",
"a",
"mapping",
"of",
"wordlists",
"names",
"with",
"their",
"path",
"and",
"a",
"policy",
"returns",
"the",
"same",
"mapping",
"with",
"only",
"those",
"entries",
"whose",
"name",
"matches",
"the",
"policy",
"."
]
| 121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7 | https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists.php#L228-L237 | train |
Erebot/Module_Wordlists | src/Wordlists.php | Wordlists.registerPath | public static function registerPath($path)
{
$path = realpath($path);
if (!in_array($path, self::$paths)) {
self::$paths[] = $path;
self::$cache = null;
}
} | php | public static function registerPath($path)
{
$path = realpath($path);
if (!in_array($path, self::$paths)) {
self::$paths[] = $path;
self::$cache = null;
}
} | [
"public",
"static",
"function",
"registerPath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"realpath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"path",
",",
"self",
"::",
"$",
"paths",
")",
")",
"{",
"self",
"::",
"$",
"paths",
"[",
"]",
"=",
"$",
"path",
";",
"self",
"::",
"$",
"cache",
"=",
"null",
";",
"}",
"}"
]
| Registers a new path containing wordlists.
\param string $path
New path to register.
\return
This method does not return anything. | [
"Registers",
"a",
"new",
"path",
"containing",
"wordlists",
"."
]
| 121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7 | https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists.php#L248-L255 | train |
Erebot/Module_Wordlists | src/Wordlists.php | Wordlists.getList | public function getList($list)
{
if (isset(self::$refs[$list])) {
self::$refs[$list]['counter']++;
return \Erebot\Module\Wordlists\Proxy(
self::$refs[$list]['instance']
);
}
$lists = $this->getAvailableLists();
if (!in_array($list, $lists)) {
throw new \Erebot\Module\Wordlists\BadListNameException($list);
}
$listObject = new \Erebot\Module\Wordlists\Wordlist(
$this,
$list,
self::$cache[$list]
);
self::$refs[$list] = array(
'counter' => 1,
'instance' => $listObject,
);
return new \Erebot\Module\Wordlists\Proxy($listObject);
} | php | public function getList($list)
{
if (isset(self::$refs[$list])) {
self::$refs[$list]['counter']++;
return \Erebot\Module\Wordlists\Proxy(
self::$refs[$list]['instance']
);
}
$lists = $this->getAvailableLists();
if (!in_array($list, $lists)) {
throw new \Erebot\Module\Wordlists\BadListNameException($list);
}
$listObject = new \Erebot\Module\Wordlists\Wordlist(
$this,
$list,
self::$cache[$list]
);
self::$refs[$list] = array(
'counter' => 1,
'instance' => $listObject,
);
return new \Erebot\Module\Wordlists\Proxy($listObject);
} | [
"public",
"function",
"getList",
"(",
"$",
"list",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"refs",
"[",
"$",
"list",
"]",
")",
")",
"{",
"self",
"::",
"$",
"refs",
"[",
"$",
"list",
"]",
"[",
"'counter'",
"]",
"++",
";",
"return",
"\\",
"Erebot",
"\\",
"Module",
"\\",
"Wordlists",
"\\",
"Proxy",
"(",
"self",
"::",
"$",
"refs",
"[",
"$",
"list",
"]",
"[",
"'instance'",
"]",
")",
";",
"}",
"$",
"lists",
"=",
"$",
"this",
"->",
"getAvailableLists",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"list",
",",
"$",
"lists",
")",
")",
"{",
"throw",
"new",
"\\",
"Erebot",
"\\",
"Module",
"\\",
"Wordlists",
"\\",
"BadListNameException",
"(",
"$",
"list",
")",
";",
"}",
"$",
"listObject",
"=",
"new",
"\\",
"Erebot",
"\\",
"Module",
"\\",
"Wordlists",
"\\",
"Wordlist",
"(",
"$",
"this",
",",
"$",
"list",
",",
"self",
"::",
"$",
"cache",
"[",
"$",
"list",
"]",
")",
";",
"self",
"::",
"$",
"refs",
"[",
"$",
"list",
"]",
"=",
"array",
"(",
"'counter'",
"=>",
"1",
",",
"'instance'",
"=>",
"$",
"listObject",
",",
")",
";",
"return",
"new",
"\\",
"Erebot",
"\\",
"Module",
"\\",
"Wordlists",
"\\",
"Proxy",
"(",
"$",
"listObject",
")",
";",
"}"
]
| Returns a list of words.
\param string $list
Name of the list to return.
\throw Erebot::Module::Wordlists::BadListNameException
The given $list is not a valid list name. | [
"Returns",
"a",
"list",
"of",
"words",
"."
]
| 121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7 | https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists.php#L289-L314 | train |
Erebot/Module_Wordlists | src/Wordlists.php | Wordlists.releaseList | public function releaseList(\Erebot\Module\Wordlists\Wordlist $list)
{
$nameType = \Erebot\Module\Wordlists\Wordlist::METADATA_NAME;
$name = $list->getMetadata($nameType);
if (!isset(self::$refs[$name])) {
throw new \Erebot\NotFoundException('No such list');
}
if (--self::$refs[$name]['counter'] <= 0) {
unset(self::$refs[$name]);
}
} | php | public function releaseList(\Erebot\Module\Wordlists\Wordlist $list)
{
$nameType = \Erebot\Module\Wordlists\Wordlist::METADATA_NAME;
$name = $list->getMetadata($nameType);
if (!isset(self::$refs[$name])) {
throw new \Erebot\NotFoundException('No such list');
}
if (--self::$refs[$name]['counter'] <= 0) {
unset(self::$refs[$name]);
}
} | [
"public",
"function",
"releaseList",
"(",
"\\",
"Erebot",
"\\",
"Module",
"\\",
"Wordlists",
"\\",
"Wordlist",
"$",
"list",
")",
"{",
"$",
"nameType",
"=",
"\\",
"Erebot",
"\\",
"Module",
"\\",
"Wordlists",
"\\",
"Wordlist",
"::",
"METADATA_NAME",
";",
"$",
"name",
"=",
"$",
"list",
"->",
"getMetadata",
"(",
"$",
"nameType",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"refs",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Erebot",
"\\",
"NotFoundException",
"(",
"'No such list'",
")",
";",
"}",
"if",
"(",
"--",
"self",
"::",
"$",
"refs",
"[",
"$",
"name",
"]",
"[",
"'counter'",
"]",
"<=",
"0",
")",
"{",
"unset",
"(",
"self",
"::",
"$",
"refs",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}"
]
| Releases a wordlist.
This decreases the reference counter associated
with the list and removes it from the cache
entirely when the counter reaches zero.
\param Erebot::Module::Wordlists::Wordlist $list
Wordlist to release. | [
"Releases",
"a",
"wordlist",
"."
]
| 121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7 | https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists.php#L326-L337 | train |
TuumPHP/FileMap | src/Handler/Emitter.php | Emitter.handle | public function handle($file)
{
if (!$mime = $this->getMimeForEmit($file->getExtension())) {
return $file;
}
if (!$file_loc = $file->getLocation()) {
return $file;
}
$file->setMime($mime);
$file->setFound();
$fp = fopen($file_loc, 'r');
$file->setResource($fp);
return $file;
} | php | public function handle($file)
{
if (!$mime = $this->getMimeForEmit($file->getExtension())) {
return $file;
}
if (!$file_loc = $file->getLocation()) {
return $file;
}
$file->setMime($mime);
$file->setFound();
$fp = fopen($file_loc, 'r');
$file->setResource($fp);
return $file;
} | [
"public",
"function",
"handle",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"$",
"mime",
"=",
"$",
"this",
"->",
"getMimeForEmit",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"if",
"(",
"!",
"$",
"file_loc",
"=",
"$",
"file",
"->",
"getLocation",
"(",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"$",
"file",
"->",
"setMime",
"(",
"$",
"mime",
")",
";",
"$",
"file",
"->",
"setFound",
"(",
")",
";",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"file_loc",
",",
"'r'",
")",
";",
"$",
"file",
"->",
"setResource",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"file",
";",
"}"
]
| handles a file with proper extension such as gif, js, etc.
@param FileInfo $file
@return FileInfo | [
"handles",
"a",
"file",
"with",
"proper",
"extension",
"such",
"as",
"gif",
"js",
"etc",
"."
]
| 4371d4db6cd48bb8fe38f83ef6bd186b346e6427 | https://github.com/TuumPHP/FileMap/blob/4371d4db6cd48bb8fe38f83ef6bd186b346e6427/src/Handler/Emitter.php#L77-L91 | train |
joegreen88/zf1-component-validate | src/Zend/Validate/File/MimeType.php | Zend_Validate_File_MimeType.addMimeType | public function addMimeType($mimetype)
{
$mimetypes = $this->getMimeType(true);
if (is_string($mimetype)) {
$mimetype = explode(',', $mimetype);
} elseif (!is_array($mimetype)) {
throw new Zend_Validate_Exception("Invalid options to validator provided");
}
if (isset($mimetype['magicfile'])) {
unset($mimetype['magicfile']);
}
foreach ($mimetype as $content) {
if (empty($content) || !is_string($content)) {
continue;
}
$mimetypes[] = trim($content);
}
$mimetypes = array_unique($mimetypes);
// Sanity check to ensure no empty values
foreach ($mimetypes as $key => $mt) {
if (empty($mt)) {
unset($mimetypes[$key]);
}
}
$this->_mimetype = implode(',', $mimetypes);
return $this;
} | php | public function addMimeType($mimetype)
{
$mimetypes = $this->getMimeType(true);
if (is_string($mimetype)) {
$mimetype = explode(',', $mimetype);
} elseif (!is_array($mimetype)) {
throw new Zend_Validate_Exception("Invalid options to validator provided");
}
if (isset($mimetype['magicfile'])) {
unset($mimetype['magicfile']);
}
foreach ($mimetype as $content) {
if (empty($content) || !is_string($content)) {
continue;
}
$mimetypes[] = trim($content);
}
$mimetypes = array_unique($mimetypes);
// Sanity check to ensure no empty values
foreach ($mimetypes as $key => $mt) {
if (empty($mt)) {
unset($mimetypes[$key]);
}
}
$this->_mimetype = implode(',', $mimetypes);
return $this;
} | [
"public",
"function",
"addMimeType",
"(",
"$",
"mimetype",
")",
"{",
"$",
"mimetypes",
"=",
"$",
"this",
"->",
"getMimeType",
"(",
"true",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"mimetype",
")",
")",
"{",
"$",
"mimetype",
"=",
"explode",
"(",
"','",
",",
"$",
"mimetype",
")",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"mimetype",
")",
")",
"{",
"throw",
"new",
"Zend_Validate_Exception",
"(",
"\"Invalid options to validator provided\"",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mimetype",
"[",
"'magicfile'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"mimetype",
"[",
"'magicfile'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"mimetype",
"as",
"$",
"content",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"content",
")",
"||",
"!",
"is_string",
"(",
"$",
"content",
")",
")",
"{",
"continue",
";",
"}",
"$",
"mimetypes",
"[",
"]",
"=",
"trim",
"(",
"$",
"content",
")",
";",
"}",
"$",
"mimetypes",
"=",
"array_unique",
"(",
"$",
"mimetypes",
")",
";",
"// Sanity check to ensure no empty values",
"foreach",
"(",
"$",
"mimetypes",
"as",
"$",
"key",
"=>",
"$",
"mt",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"mt",
")",
")",
"{",
"unset",
"(",
"$",
"mimetypes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_mimetype",
"=",
"implode",
"(",
"','",
",",
"$",
"mimetypes",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Adds the mimetypes
@param string|array $mimetype The mimetypes to add for validation
@return Zend_Validate_File_Extension Provides a fluent interface | [
"Adds",
"the",
"mimetypes"
]
| 88d9ea016f73d48ff0ba7d06ecbbf28951fd279e | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/File/MimeType.php#L311-L344 | train |
ManifestWebDesign/dabl-stringformat | src/StringFormat.php | StringFormat.titleCase | static function titleCase($string, $delimiter = '') {
return implode($delimiter, array_map('ucfirst', self::getWords($string, true)));
} | php | static function titleCase($string, $delimiter = '') {
return implode($delimiter, array_map('ucfirst', self::getWords($string, true)));
} | [
"static",
"function",
"titleCase",
"(",
"$",
"string",
",",
"$",
"delimiter",
"=",
"''",
")",
"{",
"return",
"implode",
"(",
"$",
"delimiter",
",",
"array_map",
"(",
"'ucfirst'",
",",
"self",
"::",
"getWords",
"(",
"$",
"string",
",",
"true",
")",
")",
")",
";",
"}"
]
| Converts a given string to title case
@param string $string
@return string | [
"Converts",
"a",
"given",
"string",
"to",
"title",
"case"
]
| e24535a4732abe888324b65c8b2726b211fb9bf8 | https://github.com/ManifestWebDesign/dabl-stringformat/blob/e24535a4732abe888324b65c8b2726b211fb9bf8/src/StringFormat.php#L115-L117 | train |
ManifestWebDesign/dabl-stringformat | src/StringFormat.php | StringFormat.getWords | static function getWords($string, $lowercase = false) {
$string = self::clean($string, ' ');
// before an upper and a lower. FBar -> F Bar
$string = preg_replace('/(.)([A-Z])([a-z])/', '$1 $2$3', $string);
// between a lower and an upper. fooB -> foo B
$string = preg_replace('/([a-z])([A-Z])/', '$1 $2', $string);
// after any sequence of numbers. 45times -> 45 times
$string = preg_replace('/([0-9])([^0-9])/', '$1 $2', $string);
if ($lowercase) {
$string = strtolower($string);
}
do {
$string = str_replace(' ', ' ', $string, $count);
} while ($count > 0);
return explode(' ', $string);
} | php | static function getWords($string, $lowercase = false) {
$string = self::clean($string, ' ');
// before an upper and a lower. FBar -> F Bar
$string = preg_replace('/(.)([A-Z])([a-z])/', '$1 $2$3', $string);
// between a lower and an upper. fooB -> foo B
$string = preg_replace('/([a-z])([A-Z])/', '$1 $2', $string);
// after any sequence of numbers. 45times -> 45 times
$string = preg_replace('/([0-9])([^0-9])/', '$1 $2', $string);
if ($lowercase) {
$string = strtolower($string);
}
do {
$string = str_replace(' ', ' ', $string, $count);
} while ($count > 0);
return explode(' ', $string);
} | [
"static",
"function",
"getWords",
"(",
"$",
"string",
",",
"$",
"lowercase",
"=",
"false",
")",
"{",
"$",
"string",
"=",
"self",
"::",
"clean",
"(",
"$",
"string",
",",
"' '",
")",
";",
"// before an upper and a lower. FBar -> F Bar",
"$",
"string",
"=",
"preg_replace",
"(",
"'/(.)([A-Z])([a-z])/'",
",",
"'$1 $2$3'",
",",
"$",
"string",
")",
";",
"// between a lower and an upper. fooB -> foo B",
"$",
"string",
"=",
"preg_replace",
"(",
"'/([a-z])([A-Z])/'",
",",
"'$1 $2'",
",",
"$",
"string",
")",
";",
"// after any sequence of numbers. 45times -> 45 times",
"$",
"string",
"=",
"preg_replace",
"(",
"'/([0-9])([^0-9])/'",
",",
"'$1 $2'",
",",
"$",
"string",
")",
";",
"if",
"(",
"$",
"lowercase",
")",
"{",
"$",
"string",
"=",
"strtolower",
"(",
"$",
"string",
")",
";",
"}",
"do",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"' '",
",",
"' '",
",",
"$",
"string",
",",
"$",
"count",
")",
";",
"}",
"while",
"(",
"$",
"count",
">",
"0",
")",
";",
"return",
"explode",
"(",
"' '",
",",
"$",
"string",
")",
";",
"}"
]
| Returns array of the words in a string
@param string $string
@return array | [
"Returns",
"array",
"of",
"the",
"words",
"in",
"a",
"string"
]
| e24535a4732abe888324b65c8b2726b211fb9bf8 | https://github.com/ManifestWebDesign/dabl-stringformat/blob/e24535a4732abe888324b65c8b2726b211fb9bf8/src/StringFormat.php#L124-L146 | train |
ManifestWebDesign/dabl-stringformat | src/StringFormat.php | StringFormat.plural | static function plural($string) {
$plural = array(
array('/(quiz)$/i', "$1zes"),
array('/^(ox)$/i', "$1en"),
array('/([m|l])ouse$/i', "$1ice"),
array('/(matr|vert|ind)ix|ex$/i', "$1ices"),
array('/(x|ch|ss|sh)$/i', "$1es"),
array('/([^aeiouy]|qu)y$/i', "$1ies"),
array('/([^aeiouy]|qu)ies$/i', "$1y"),
array('/(hive|move)$/i', "$1s"),
array('/(?:([^f])fe|([lr])f)$/i', "$1$2ves"),
array('/sis$/i', "ses"),
array('/([ti])um$/i', "$1a"),
array('/(buffal|tomat)o$/i', "$1oes"),
array('/(bu)s$/i', "$1ses"),
array('/(alias|status|campus)$/i', "$1es"),
array('/(octop|cact|vir)us$/i', "$1i"),
array('/(ax|test)is$/i', "$1es"),
array('/^(m|wom)an$/i', "$1en"),
array('/(child)$/i', "$1ren"),
array('/(p)erson$/i', "$1eople"),
array('/s$/i', "s"),
array('/$/', "s")
);
$words = self::getWords($string);
$word = array_pop($words);
// check for matches using regular expressions
foreach ($plural as &$pattern) {
if (preg_match($pattern[0], $word)) {
$prefix = substr($string, 0, strrpos($string, $word));
return $prefix . preg_replace($pattern[0], $pattern[1], $word);
}
}
return $string . 's';
} | php | static function plural($string) {
$plural = array(
array('/(quiz)$/i', "$1zes"),
array('/^(ox)$/i', "$1en"),
array('/([m|l])ouse$/i', "$1ice"),
array('/(matr|vert|ind)ix|ex$/i', "$1ices"),
array('/(x|ch|ss|sh)$/i', "$1es"),
array('/([^aeiouy]|qu)y$/i', "$1ies"),
array('/([^aeiouy]|qu)ies$/i', "$1y"),
array('/(hive|move)$/i', "$1s"),
array('/(?:([^f])fe|([lr])f)$/i', "$1$2ves"),
array('/sis$/i', "ses"),
array('/([ti])um$/i', "$1a"),
array('/(buffal|tomat)o$/i', "$1oes"),
array('/(bu)s$/i', "$1ses"),
array('/(alias|status|campus)$/i', "$1es"),
array('/(octop|cact|vir)us$/i', "$1i"),
array('/(ax|test)is$/i', "$1es"),
array('/^(m|wom)an$/i', "$1en"),
array('/(child)$/i', "$1ren"),
array('/(p)erson$/i', "$1eople"),
array('/s$/i', "s"),
array('/$/', "s")
);
$words = self::getWords($string);
$word = array_pop($words);
// check for matches using regular expressions
foreach ($plural as &$pattern) {
if (preg_match($pattern[0], $word)) {
$prefix = substr($string, 0, strrpos($string, $word));
return $prefix . preg_replace($pattern[0], $pattern[1], $word);
}
}
return $string . 's';
} | [
"static",
"function",
"plural",
"(",
"$",
"string",
")",
"{",
"$",
"plural",
"=",
"array",
"(",
"array",
"(",
"'/(quiz)$/i'",
",",
"\"$1zes\"",
")",
",",
"array",
"(",
"'/^(ox)$/i'",
",",
"\"$1en\"",
")",
",",
"array",
"(",
"'/([m|l])ouse$/i'",
",",
"\"$1ice\"",
")",
",",
"array",
"(",
"'/(matr|vert|ind)ix|ex$/i'",
",",
"\"$1ices\"",
")",
",",
"array",
"(",
"'/(x|ch|ss|sh)$/i'",
",",
"\"$1es\"",
")",
",",
"array",
"(",
"'/([^aeiouy]|qu)y$/i'",
",",
"\"$1ies\"",
")",
",",
"array",
"(",
"'/([^aeiouy]|qu)ies$/i'",
",",
"\"$1y\"",
")",
",",
"array",
"(",
"'/(hive|move)$/i'",
",",
"\"$1s\"",
")",
",",
"array",
"(",
"'/(?:([^f])fe|([lr])f)$/i'",
",",
"\"$1$2ves\"",
")",
",",
"array",
"(",
"'/sis$/i'",
",",
"\"ses\"",
")",
",",
"array",
"(",
"'/([ti])um$/i'",
",",
"\"$1a\"",
")",
",",
"array",
"(",
"'/(buffal|tomat)o$/i'",
",",
"\"$1oes\"",
")",
",",
"array",
"(",
"'/(bu)s$/i'",
",",
"\"$1ses\"",
")",
",",
"array",
"(",
"'/(alias|status|campus)$/i'",
",",
"\"$1es\"",
")",
",",
"array",
"(",
"'/(octop|cact|vir)us$/i'",
",",
"\"$1i\"",
")",
",",
"array",
"(",
"'/(ax|test)is$/i'",
",",
"\"$1es\"",
")",
",",
"array",
"(",
"'/^(m|wom)an$/i'",
",",
"\"$1en\"",
")",
",",
"array",
"(",
"'/(child)$/i'",
",",
"\"$1ren\"",
")",
",",
"array",
"(",
"'/(p)erson$/i'",
",",
"\"$1eople\"",
")",
",",
"array",
"(",
"'/s$/i'",
",",
"\"s\"",
")",
",",
"array",
"(",
"'/$/'",
",",
"\"s\"",
")",
")",
";",
"$",
"words",
"=",
"self",
"::",
"getWords",
"(",
"$",
"string",
")",
";",
"$",
"word",
"=",
"array_pop",
"(",
"$",
"words",
")",
";",
"// check for matches using regular expressions",
"foreach",
"(",
"$",
"plural",
"as",
"&",
"$",
"pattern",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
"[",
"0",
"]",
",",
"$",
"word",
")",
")",
"{",
"$",
"prefix",
"=",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"strrpos",
"(",
"$",
"string",
",",
"$",
"word",
")",
")",
";",
"return",
"$",
"prefix",
".",
"preg_replace",
"(",
"$",
"pattern",
"[",
"0",
"]",
",",
"$",
"pattern",
"[",
"1",
"]",
",",
"$",
"word",
")",
";",
"}",
"}",
"return",
"$",
"string",
".",
"'s'",
";",
"}"
]
| Returns the plural version of the given word. If the plural version is
the same, then this method will simply add an 's' to the end of
the word.
@param string $string
@return string | [
"Returns",
"the",
"plural",
"version",
"of",
"the",
"given",
"word",
".",
"If",
"the",
"plural",
"version",
"is",
"the",
"same",
"then",
"this",
"method",
"will",
"simply",
"add",
"an",
"s",
"to",
"the",
"end",
"of",
"the",
"word",
"."
]
| e24535a4732abe888324b65c8b2726b211fb9bf8 | https://github.com/ManifestWebDesign/dabl-stringformat/blob/e24535a4732abe888324b65c8b2726b211fb9bf8/src/StringFormat.php#L155-L191 | train |
TuumPHP/FileMap | src/Handler/Renderer.php | Renderer.handle | public function handle($file)
{
foreach ($this->view_extensions as $ext => $handler) {
if ($file->exists($ext)) {
$file = $file->withExtension($ext);
$file->setMime($handler[1]);
$file->setFound();
$handle = $handler[0];
if (!is_callable($handle)) {
$handle = [$this, $handle];
}
return call_user_func($handle, $file);
}
}
return $file;
} | php | public function handle($file)
{
foreach ($this->view_extensions as $ext => $handler) {
if ($file->exists($ext)) {
$file = $file->withExtension($ext);
$file->setMime($handler[1]);
$file->setFound();
$handle = $handler[0];
if (!is_callable($handle)) {
$handle = [$this, $handle];
}
return call_user_func($handle, $file);
}
}
return $file;
} | [
"public",
"function",
"handle",
"(",
"$",
"file",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"view_extensions",
"as",
"$",
"ext",
"=>",
"$",
"handler",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"exists",
"(",
"$",
"ext",
")",
")",
"{",
"$",
"file",
"=",
"$",
"file",
"->",
"withExtension",
"(",
"$",
"ext",
")",
";",
"$",
"file",
"->",
"setMime",
"(",
"$",
"handler",
"[",
"1",
"]",
")",
";",
"$",
"file",
"->",
"setFound",
"(",
")",
";",
"$",
"handle",
"=",
"$",
"handler",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"handle",
")",
")",
"{",
"$",
"handle",
"=",
"[",
"$",
"this",
",",
"$",
"handle",
"]",
";",
"}",
"return",
"call_user_func",
"(",
"$",
"handle",
",",
"$",
"file",
")",
";",
"}",
"}",
"return",
"$",
"file",
";",
"}"
]
| handles text type file, such as html, php, text, and md.
@param FileInfo $file
@return FileInfo | [
"handles",
"text",
"type",
"file",
"such",
"as",
"html",
"php",
"text",
"and",
"md",
"."
]
| 4371d4db6cd48bb8fe38f83ef6bd186b346e6427 | https://github.com/TuumPHP/FileMap/blob/4371d4db6cd48bb8fe38f83ef6bd186b346e6427/src/Handler/Renderer.php#L64-L80 | train |
TuumPHP/FileMap | src/Handler/Renderer.php | Renderer.dummy | protected function dummy()
{
$this->evaluatePhp(null);
$this->markToHtml(null);
$this->textToPre(null);
} | php | protected function dummy()
{
$this->evaluatePhp(null);
$this->markToHtml(null);
$this->textToPre(null);
} | [
"protected",
"function",
"dummy",
"(",
")",
"{",
"$",
"this",
"->",
"evaluatePhp",
"(",
"null",
")",
";",
"$",
"this",
"->",
"markToHtml",
"(",
"null",
")",
";",
"$",
"this",
"->",
"textToPre",
"(",
"null",
")",
";",
"}"
]
| dummy method to call private methods which are judged as unused methods.
@codeCoverageIgnore | [
"dummy",
"method",
"to",
"call",
"private",
"methods",
"which",
"are",
"judged",
"as",
"unused",
"methods",
"."
]
| 4371d4db6cd48bb8fe38f83ef6bd186b346e6427 | https://github.com/TuumPHP/FileMap/blob/4371d4db6cd48bb8fe38f83ef6bd186b346e6427/src/Handler/Renderer.php#L128-L133 | train |
nathan818fr/phpuc-io-streams | src/ByteArrayOutputStream.php | ByteArrayOutputStream.size | public function size() : int
{
if ($this->bufSize == null) {
$this->bufSize = strlen($this->buf);
}
return $this->bufSize;
} | php | public function size() : int
{
if ($this->bufSize == null) {
$this->bufSize = strlen($this->buf);
}
return $this->bufSize;
} | [
"public",
"function",
"size",
"(",
")",
":",
"int",
"{",
"if",
"(",
"$",
"this",
"->",
"bufSize",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"bufSize",
"=",
"strlen",
"(",
"$",
"this",
"->",
"buf",
")",
";",
"}",
"return",
"$",
"this",
"->",
"bufSize",
";",
"}"
]
| Returns the current size of the buffer.
@return int the current size of the buffer | [
"Returns",
"the",
"current",
"size",
"of",
"the",
"buffer",
"."
]
| 8f748c1b3338b50e7c6e25a2f2ee73699cadb0ba | https://github.com/nathan818fr/phpuc-io-streams/blob/8f748c1b3338b50e7c6e25a2f2ee73699cadb0ba/src/ByteArrayOutputStream.php#L49-L55 | train |
field-interactive/cito-bundle | Twig/InlineSvgExtension.php | InlineSvgExtension.getInlineSvg | public function getInlineSvg($filename, $params = [])
{
$fullPath = $this->assetDir.$filename;
if (!file_exists($fullPath)) {
throw new \Exception(sprintf('Cannot find svg file: "%s"', $fullPath));
}
$svgString = file_get_contents($fullPath);
$hasAttr = array_key_exists('attr', $params);
$hasClasses = array_key_exists('classes', $params);
if ($hasAttr || $hasClasses) {
$svg = simplexml_load_string($svgString);
$attrs = $svg->attributes();
}
if ($hasAttr) {
foreach ($params['attr'] as $key => $value) {
if ($attrs[$key]) {
$attrs[$key] = $value;
} else {
$svg->addAttribute($key, $value);
}
}
$svgString = $svg->asXML();
}
if ($hasClasses) {
if ($attrs['class']) {
$attrs['class'] .= ' '.$params['classes'];
} else {
$svg->addAttribute('class', $params['classes']);
}
$svgString = $svg->asXML();
}
// remove annoying xml version added by as XML method
$svgString = preg_replace("#<\?xml version.*?>#", '', $svgString);
// remove comments
$svgString = preg_replace('#<!--.*-->#', '', $svgString);
return $svgString;
} | php | public function getInlineSvg($filename, $params = [])
{
$fullPath = $this->assetDir.$filename;
if (!file_exists($fullPath)) {
throw new \Exception(sprintf('Cannot find svg file: "%s"', $fullPath));
}
$svgString = file_get_contents($fullPath);
$hasAttr = array_key_exists('attr', $params);
$hasClasses = array_key_exists('classes', $params);
if ($hasAttr || $hasClasses) {
$svg = simplexml_load_string($svgString);
$attrs = $svg->attributes();
}
if ($hasAttr) {
foreach ($params['attr'] as $key => $value) {
if ($attrs[$key]) {
$attrs[$key] = $value;
} else {
$svg->addAttribute($key, $value);
}
}
$svgString = $svg->asXML();
}
if ($hasClasses) {
if ($attrs['class']) {
$attrs['class'] .= ' '.$params['classes'];
} else {
$svg->addAttribute('class', $params['classes']);
}
$svgString = $svg->asXML();
}
// remove annoying xml version added by as XML method
$svgString = preg_replace("#<\?xml version.*?>#", '', $svgString);
// remove comments
$svgString = preg_replace('#<!--.*-->#', '', $svgString);
return $svgString;
} | [
"public",
"function",
"getInlineSvg",
"(",
"$",
"filename",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"fullPath",
"=",
"$",
"this",
"->",
"assetDir",
".",
"$",
"filename",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fullPath",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Cannot find svg file: \"%s\"'",
",",
"$",
"fullPath",
")",
")",
";",
"}",
"$",
"svgString",
"=",
"file_get_contents",
"(",
"$",
"fullPath",
")",
";",
"$",
"hasAttr",
"=",
"array_key_exists",
"(",
"'attr'",
",",
"$",
"params",
")",
";",
"$",
"hasClasses",
"=",
"array_key_exists",
"(",
"'classes'",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"hasAttr",
"||",
"$",
"hasClasses",
")",
"{",
"$",
"svg",
"=",
"simplexml_load_string",
"(",
"$",
"svgString",
")",
";",
"$",
"attrs",
"=",
"$",
"svg",
"->",
"attributes",
"(",
")",
";",
"}",
"if",
"(",
"$",
"hasAttr",
")",
"{",
"foreach",
"(",
"$",
"params",
"[",
"'attr'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"attrs",
"[",
"$",
"key",
"]",
")",
"{",
"$",
"attrs",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"svg",
"->",
"addAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"svgString",
"=",
"$",
"svg",
"->",
"asXML",
"(",
")",
";",
"}",
"if",
"(",
"$",
"hasClasses",
")",
"{",
"if",
"(",
"$",
"attrs",
"[",
"'class'",
"]",
")",
"{",
"$",
"attrs",
"[",
"'class'",
"]",
".=",
"' '",
".",
"$",
"params",
"[",
"'classes'",
"]",
";",
"}",
"else",
"{",
"$",
"svg",
"->",
"addAttribute",
"(",
"'class'",
",",
"$",
"params",
"[",
"'classes'",
"]",
")",
";",
"}",
"$",
"svgString",
"=",
"$",
"svg",
"->",
"asXML",
"(",
")",
";",
"}",
"// remove annoying xml version added by as XML method",
"$",
"svgString",
"=",
"preg_replace",
"(",
"\"#<\\?xml version.*?>#\"",
",",
"''",
",",
"$",
"svgString",
")",
";",
"// remove comments",
"$",
"svgString",
"=",
"preg_replace",
"(",
"'#<!--.*-->#'",
",",
"''",
",",
"$",
"svgString",
")",
";",
"return",
"$",
"svgString",
";",
"}"
]
| Get an inline svg.
@param string $filename Path to the svg file
@param array $params Optional parameters
@return string
@throws \Exception | [
"Get",
"an",
"inline",
"svg",
"."
]
| 41cab570f960d964916e278c616720b17de258c1 | https://github.com/field-interactive/cito-bundle/blob/41cab570f960d964916e278c616720b17de258c1/Twig/InlineSvgExtension.php#L63-L105 | train |
SlabPHP/router | src/Router.php | Router.routeRequest | public function routeRequest(\Slab\Components\SystemInterface $system)
{
$this->determineSelectedRoute();
if (!empty($this->selectedRoute))
{
return $this->selectedRoute;
}
if (!empty($this->routeNameMap['404']))
{
return $this->routeNameMap['404'];
}
return null;
} | php | public function routeRequest(\Slab\Components\SystemInterface $system)
{
$this->determineSelectedRoute();
if (!empty($this->selectedRoute))
{
return $this->selectedRoute;
}
if (!empty($this->routeNameMap['404']))
{
return $this->routeNameMap['404'];
}
return null;
} | [
"public",
"function",
"routeRequest",
"(",
"\\",
"Slab",
"\\",
"Components",
"\\",
"SystemInterface",
"$",
"system",
")",
"{",
"$",
"this",
"->",
"determineSelectedRoute",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"selectedRoute",
")",
")",
"{",
"return",
"$",
"this",
"->",
"selectedRoute",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"routeNameMap",
"[",
"'404'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"routeNameMap",
"[",
"'404'",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Route the request
@param \Slab\Components\SystemInterface $system
@return \Slab\Components\Router\RouteInterface | [
"Route",
"the",
"request"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L143-L158 | train |
SlabPHP/router | src/Router.php | Router.validateRequestURI | private function validateRequestURI(&$requestURI)
{
if ($requestURI != '/' && substr($requestURI, -1) == '/') {
$url = rtrim($requestURI, '/');
if (php_sapi_name() === 'cli') {
exit("Please ensure the URL you typed in does not have a trailing backslash.\n");
}
header("Location: " . $url);
exit();
}
} | php | private function validateRequestURI(&$requestURI)
{
if ($requestURI != '/' && substr($requestURI, -1) == '/') {
$url = rtrim($requestURI, '/');
if (php_sapi_name() === 'cli') {
exit("Please ensure the URL you typed in does not have a trailing backslash.\n");
}
header("Location: " . $url);
exit();
}
} | [
"private",
"function",
"validateRequestURI",
"(",
"&",
"$",
"requestURI",
")",
"{",
"if",
"(",
"$",
"requestURI",
"!=",
"'/'",
"&&",
"substr",
"(",
"$",
"requestURI",
",",
"-",
"1",
")",
"==",
"'/'",
")",
"{",
"$",
"url",
"=",
"rtrim",
"(",
"$",
"requestURI",
",",
"'/'",
")",
";",
"if",
"(",
"php_sapi_name",
"(",
")",
"===",
"'cli'",
")",
"{",
"exit",
"(",
"\"Please ensure the URL you typed in does not have a trailing backslash.\\n\"",
")",
";",
"}",
"header",
"(",
"\"Location: \"",
".",
"$",
"url",
")",
";",
"exit",
"(",
")",
";",
"}",
"}"
]
| Make sure the request URI fits how we want it to
@param string $requestURI | [
"Make",
"sure",
"the",
"request",
"URI",
"fits",
"how",
"we",
"want",
"it",
"to"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L232-L244 | train |
SlabPHP/router | src/Router.php | Router.getPathInfo | private function getPathInfo()
{
$requestURI = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$this->validateRequestURI($requestURI);
if (empty($requestURI)) {
return;
}
$request = $requestURI;
$this->fullRequest = $this->currentRequest = $request;
$this->addDebugMessage("Full request " . $this->fullRequest);
$secure = !empty($_SERVER['HTTPS']);
$this->addDebugMessage($secure ? "Secure routing." : "Non-secure routing.");
$this->baseHREF = "http" . ($secure ? 's' : '') . '://' . $_SERVER['SERVER_NAME'];
$this->currentHREF = $this->baseHREF . $request;
$queryStringIndex = strpos($request, '?');
$startsWithSlash = ($request[0] == '/' ? 1 : 0);
if ($queryStringIndex !== false) {
$this->currentRequest = substr($request, 0, $queryStringIndex);
$request = substr($request, $startsWithSlash, $queryStringIndex - 1);
} else {
$request = substr($request, $startsWithSlash);
}
if (!empty($request)) {
$this->segments = explode('/', $request);
}
$this->isHomepage = (empty($request) || $request == '/');
$this->checkForTrailingSlashRedirect();
} | php | private function getPathInfo()
{
$requestURI = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$this->validateRequestURI($requestURI);
if (empty($requestURI)) {
return;
}
$request = $requestURI;
$this->fullRequest = $this->currentRequest = $request;
$this->addDebugMessage("Full request " . $this->fullRequest);
$secure = !empty($_SERVER['HTTPS']);
$this->addDebugMessage($secure ? "Secure routing." : "Non-secure routing.");
$this->baseHREF = "http" . ($secure ? 's' : '') . '://' . $_SERVER['SERVER_NAME'];
$this->currentHREF = $this->baseHREF . $request;
$queryStringIndex = strpos($request, '?');
$startsWithSlash = ($request[0] == '/' ? 1 : 0);
if ($queryStringIndex !== false) {
$this->currentRequest = substr($request, 0, $queryStringIndex);
$request = substr($request, $startsWithSlash, $queryStringIndex - 1);
} else {
$request = substr($request, $startsWithSlash);
}
if (!empty($request)) {
$this->segments = explode('/', $request);
}
$this->isHomepage = (empty($request) || $request == '/');
$this->checkForTrailingSlashRedirect();
} | [
"private",
"function",
"getPathInfo",
"(",
")",
"{",
"$",
"requestURI",
"=",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
":",
"''",
";",
"$",
"this",
"->",
"validateRequestURI",
"(",
"$",
"requestURI",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"requestURI",
")",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"requestURI",
";",
"$",
"this",
"->",
"fullRequest",
"=",
"$",
"this",
"->",
"currentRequest",
"=",
"$",
"request",
";",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Full request \"",
".",
"$",
"this",
"->",
"fullRequest",
")",
";",
"$",
"secure",
"=",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
";",
"$",
"this",
"->",
"addDebugMessage",
"(",
"$",
"secure",
"?",
"\"Secure routing.\"",
":",
"\"Non-secure routing.\"",
")",
";",
"$",
"this",
"->",
"baseHREF",
"=",
"\"http\"",
".",
"(",
"$",
"secure",
"?",
"'s'",
":",
"''",
")",
".",
"'://'",
".",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
";",
"$",
"this",
"->",
"currentHREF",
"=",
"$",
"this",
"->",
"baseHREF",
".",
"$",
"request",
";",
"$",
"queryStringIndex",
"=",
"strpos",
"(",
"$",
"request",
",",
"'?'",
")",
";",
"$",
"startsWithSlash",
"=",
"(",
"$",
"request",
"[",
"0",
"]",
"==",
"'/'",
"?",
"1",
":",
"0",
")",
";",
"if",
"(",
"$",
"queryStringIndex",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"currentRequest",
"=",
"substr",
"(",
"$",
"request",
",",
"0",
",",
"$",
"queryStringIndex",
")",
";",
"$",
"request",
"=",
"substr",
"(",
"$",
"request",
",",
"$",
"startsWithSlash",
",",
"$",
"queryStringIndex",
"-",
"1",
")",
";",
"}",
"else",
"{",
"$",
"request",
"=",
"substr",
"(",
"$",
"request",
",",
"$",
"startsWithSlash",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
")",
")",
"{",
"$",
"this",
"->",
"segments",
"=",
"explode",
"(",
"'/'",
",",
"$",
"request",
")",
";",
"}",
"$",
"this",
"->",
"isHomepage",
"=",
"(",
"empty",
"(",
"$",
"request",
")",
"||",
"$",
"request",
"==",
"'/'",
")",
";",
"$",
"this",
"->",
"checkForTrailingSlashRedirect",
"(",
")",
";",
"}"
]
| Gets the path info and parses out the segment structure | [
"Gets",
"the",
"path",
"info",
"and",
"parses",
"out",
"the",
"segment",
"structure"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L249-L290 | train |
SlabPHP/router | src/Router.php | Router.checkForTrailingSlashRedirect | private function checkForTrailingSlashRedirect()
{
if (!empty($this->segments) && empty($this->segments[count($this->segments) - 1])) {
//Trim off the empty segment
array_pop($this->segments);
$newUrl = $this->baseHREF . '/' . implode('/', $this->segments);
header("Location: " . $newUrl);
exit();
}
} | php | private function checkForTrailingSlashRedirect()
{
if (!empty($this->segments) && empty($this->segments[count($this->segments) - 1])) {
//Trim off the empty segment
array_pop($this->segments);
$newUrl = $this->baseHREF . '/' . implode('/', $this->segments);
header("Location: " . $newUrl);
exit();
}
} | [
"private",
"function",
"checkForTrailingSlashRedirect",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"segments",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"segments",
"[",
"count",
"(",
"$",
"this",
"->",
"segments",
")",
"-",
"1",
"]",
")",
")",
"{",
"//Trim off the empty segment",
"array_pop",
"(",
"$",
"this",
"->",
"segments",
")",
";",
"$",
"newUrl",
"=",
"$",
"this",
"->",
"baseHREF",
".",
"'/'",
".",
"implode",
"(",
"'/'",
",",
"$",
"this",
"->",
"segments",
")",
";",
"header",
"(",
"\"Location: \"",
".",
"$",
"newUrl",
")",
";",
"exit",
"(",
")",
";",
"}",
"}"
]
| Checks for a trailing slash or something in the url | [
"Checks",
"for",
"a",
"trailing",
"slash",
"or",
"something",
"in",
"the",
"url"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L295-L306 | train |
SlabPHP/router | src/Router.php | Router.getRoutingTable | public function getRoutingTable()
{
if ($this->enableCache && !empty($this->cacheInterface))
{
return $this->fetchRoutingTableFromCache();
}
return $this->fetchRoutingTable();
} | php | public function getRoutingTable()
{
if ($this->enableCache && !empty($this->cacheInterface))
{
return $this->fetchRoutingTableFromCache();
}
return $this->fetchRoutingTable();
} | [
"public",
"function",
"getRoutingTable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enableCache",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"cacheInterface",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fetchRoutingTableFromCache",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"fetchRoutingTable",
"(",
")",
";",
"}"
]
| Get the routing table from cache or otherwise | [
"Get",
"the",
"routing",
"table",
"from",
"cache",
"or",
"otherwise"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L311-L319 | train |
SlabPHP/router | src/Router.php | Router.fetchRoutingTable | private function fetchRoutingTable()
{
$this->routes = $this->loadRoutingTable();
if (!empty($this->routes)) {
$this->traverseRouteListAndBuildMap();
}
return $this->routes;
} | php | private function fetchRoutingTable()
{
$this->routes = $this->loadRoutingTable();
if (!empty($this->routes)) {
$this->traverseRouteListAndBuildMap();
}
return $this->routes;
} | [
"private",
"function",
"fetchRoutingTable",
"(",
")",
"{",
"$",
"this",
"->",
"routes",
"=",
"$",
"this",
"->",
"loadRoutingTable",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"$",
"this",
"->",
"traverseRouteListAndBuildMap",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"routes",
";",
"}"
]
| Fetch the routing table without caching
@return \Slab\Router\Route | [
"Fetch",
"the",
"routing",
"table",
"without",
"caching"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L326-L335 | train |
SlabPHP/router | src/Router.php | Router.fetchRoutingTableFromCache | private function fetchRoutingTableFromCache()
{
$this->routes = $this->cacheInterface->get('Routing_Table');
if (empty($this->routes))
{
$this->routes = $this->loadRoutingTable();
}
if (!empty($this->routes)) {
$this->traverseRouteListAndBuildMap();
}
return $this->routes;
} | php | private function fetchRoutingTableFromCache()
{
$this->routes = $this->cacheInterface->get('Routing_Table');
if (empty($this->routes))
{
$this->routes = $this->loadRoutingTable();
}
if (!empty($this->routes)) {
$this->traverseRouteListAndBuildMap();
}
return $this->routes;
} | [
"private",
"function",
"fetchRoutingTableFromCache",
"(",
")",
"{",
"$",
"this",
"->",
"routes",
"=",
"$",
"this",
"->",
"cacheInterface",
"->",
"get",
"(",
"'Routing_Table'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"$",
"this",
"->",
"routes",
"=",
"$",
"this",
"->",
"loadRoutingTable",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"$",
"this",
"->",
"traverseRouteListAndBuildMap",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"routes",
";",
"}"
]
| Fetch the routing table using the default cache provider
@return \Slab\Router\Route | [
"Fetch",
"the",
"routing",
"table",
"using",
"the",
"default",
"cache",
"provider"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L342-L356 | train |
SlabPHP/router | src/Router.php | Router.traverseRouteListAndBuildMap | private function traverseRouteListAndBuildMap($currentNode = null)
{
if (empty($currentNode)) {
$this->traverseRouteListAndBuildMap($this->routes);
return;
}
if (is_array($currentNode)) {
foreach ($currentNode as $node) {
$this->traverseRouteListAndBuildMap($node);
}
return;
}
if (!($currentNode instanceof Route)) {
return;
}
$currentNodeName = $currentNode->getName();
if (!empty($this->routeNameMap[$currentNodeName])) {
$this->addDebugMessage("Duplicate route name " . $currentNodeName . " detected.");
}
$this->routeNameMap[$currentNodeName] =& $currentNode;
if ($currentNode->getChildren()) {
foreach ($currentNode->getChildren() as $child) {
$this->traverseRouteListAndBuildMap($child);
}
}
} | php | private function traverseRouteListAndBuildMap($currentNode = null)
{
if (empty($currentNode)) {
$this->traverseRouteListAndBuildMap($this->routes);
return;
}
if (is_array($currentNode)) {
foreach ($currentNode as $node) {
$this->traverseRouteListAndBuildMap($node);
}
return;
}
if (!($currentNode instanceof Route)) {
return;
}
$currentNodeName = $currentNode->getName();
if (!empty($this->routeNameMap[$currentNodeName])) {
$this->addDebugMessage("Duplicate route name " . $currentNodeName . " detected.");
}
$this->routeNameMap[$currentNodeName] =& $currentNode;
if ($currentNode->getChildren()) {
foreach ($currentNode->getChildren() as $child) {
$this->traverseRouteListAndBuildMap($child);
}
}
} | [
"private",
"function",
"traverseRouteListAndBuildMap",
"(",
"$",
"currentNode",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"currentNode",
")",
")",
"{",
"$",
"this",
"->",
"traverseRouteListAndBuildMap",
"(",
"$",
"this",
"->",
"routes",
")",
";",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"currentNode",
")",
")",
"{",
"foreach",
"(",
"$",
"currentNode",
"as",
"$",
"node",
")",
"{",
"$",
"this",
"->",
"traverseRouteListAndBuildMap",
"(",
"$",
"node",
")",
";",
"}",
"return",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"currentNode",
"instanceof",
"Route",
")",
")",
"{",
"return",
";",
"}",
"$",
"currentNodeName",
"=",
"$",
"currentNode",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"routeNameMap",
"[",
"$",
"currentNodeName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Duplicate route name \"",
".",
"$",
"currentNodeName",
".",
"\" detected.\"",
")",
";",
"}",
"$",
"this",
"->",
"routeNameMap",
"[",
"$",
"currentNodeName",
"]",
"=",
"&",
"$",
"currentNode",
";",
"if",
"(",
"$",
"currentNode",
"->",
"getChildren",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"currentNode",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"traverseRouteListAndBuildMap",
"(",
"$",
"child",
")",
";",
"}",
"}",
"}"
]
| Traverses the list of routes and builds a name -> route map reference list
@param Route $currentNode | [
"Traverses",
"the",
"list",
"of",
"routes",
"and",
"builds",
"a",
"name",
"-",
">",
"route",
"map",
"reference",
"list"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L363-L395 | train |
SlabPHP/router | src/Router.php | Router.loadRoutingTable | public function loadRoutingTable()
{
if (empty($this->routeFiles) || !is_array($this->routeFiles)) {
if (!empty($this->log))
{
$this->log->error("Missing configuration option routeFiles, or route file list in improper format.");
}
return false;
}
$routeTable = array();
foreach ($this->routeFiles as $route) {
foreach ($this->configurationPaths as $dir) {
$fileName = $dir . '/' . $route;
if (file_exists($fileName)) {
$this->loadRouteFile($routeTable, $fileName);
$this->addDebugMessage("Loaded route file: " . $fileName);
} else {
$this->addDebugMessage("Failed to load route file: " . $fileName);
}
}
}
return $routeTable;
} | php | public function loadRoutingTable()
{
if (empty($this->routeFiles) || !is_array($this->routeFiles)) {
if (!empty($this->log))
{
$this->log->error("Missing configuration option routeFiles, or route file list in improper format.");
}
return false;
}
$routeTable = array();
foreach ($this->routeFiles as $route) {
foreach ($this->configurationPaths as $dir) {
$fileName = $dir . '/' . $route;
if (file_exists($fileName)) {
$this->loadRouteFile($routeTable, $fileName);
$this->addDebugMessage("Loaded route file: " . $fileName);
} else {
$this->addDebugMessage("Failed to load route file: " . $fileName);
}
}
}
return $routeTable;
} | [
"public",
"function",
"loadRoutingTable",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"routeFiles",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"routeFiles",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"log",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"\"Missing configuration option routeFiles, or route file list in improper format.\"",
")",
";",
"}",
"return",
"false",
";",
"}",
"$",
"routeTable",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"routeFiles",
"as",
"$",
"route",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"configurationPaths",
"as",
"$",
"dir",
")",
"{",
"$",
"fileName",
"=",
"$",
"dir",
".",
"'/'",
".",
"$",
"route",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"this",
"->",
"loadRouteFile",
"(",
"$",
"routeTable",
",",
"$",
"fileName",
")",
";",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Loaded route file: \"",
".",
"$",
"fileName",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Failed to load route file: \"",
".",
"$",
"fileName",
")",
";",
"}",
"}",
"}",
"return",
"$",
"routeTable",
";",
"}"
]
| Load routing table from files | [
"Load",
"routing",
"table",
"from",
"files"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L401-L426 | train |
SlabPHP/router | src/Router.php | Router.loadRouteFile | private function loadRouteFile(&$routeTable, $fileName)
{
libxml_use_internal_errors(true);
$xml = simplexml_load_file($fileName);
if (empty($xml)) {
$errorMessage = "Failed to parse XML route file: " . $fileName . "";
foreach (libxml_get_errors() as $error) {
$errorMessage .= "\n" . $error->message;
}
if (!empty($this->log))
{
$this->log->error($errorMessage);
}
return;
}
$routeClass = 'Slab\Router\Route';
if (empty($routeClass)) {
if (!empty($this->log))
{
$this->log->error("Failed to find suitable Route object.");
}
return;
}
foreach ($xml->xpath('route') as $routeObject) {
/**
* @var \Slab\Router\Route $route
*/
try
{
$route = new $routeClass($routeObject);
}
catch (\Exception $exception)
{
if (!empty($this->log))
{
$this->log->error("Failed to add route to table: " . $exception->getMessage());
}
continue;
}
if (!$route->isValid()) {
$this->addDebugMessage('Skipping invalid route!');
continue;
}
$path = $route->getRoutingPath();
//Here we'll iterate through the current routing tree on $currentLevel checking static routes
if ($path) {
$currentLevel =& $routeTable;
//$pathDepth = count($path);
//Loop through each path level and add that level of hierarchy to our routing table
foreach ($path as $pathFolder) {
if (empty($currentLevel[$pathFolder])) {
$currentLevel[$pathFolder] = array();
}
$currentLevel =& $currentLevel[$pathFolder];
}
if (!empty($currentLevel)) {
//Check each item in this list's pattern string against the one we currently have.
//If a pattern string matches (empty or not) that means we have an overridden path
$overridden = false;
foreach ($currentLevel as $index => $subRoute) {
if (($subRoute instanceof \Slab\Router\Route) &&
($subRoute->getPatternString() == $route->getPatternString())
) {
$currentLevel[$index] = $route;
$overridden = true;
}
}
if (!$overridden) {
$currentLevel[] = $route;
}
} else {
$currentLevel[] = $route;
}
} else {
$routeTable['/'][] = $route;
}
}
} | php | private function loadRouteFile(&$routeTable, $fileName)
{
libxml_use_internal_errors(true);
$xml = simplexml_load_file($fileName);
if (empty($xml)) {
$errorMessage = "Failed to parse XML route file: " . $fileName . "";
foreach (libxml_get_errors() as $error) {
$errorMessage .= "\n" . $error->message;
}
if (!empty($this->log))
{
$this->log->error($errorMessage);
}
return;
}
$routeClass = 'Slab\Router\Route';
if (empty($routeClass)) {
if (!empty($this->log))
{
$this->log->error("Failed to find suitable Route object.");
}
return;
}
foreach ($xml->xpath('route') as $routeObject) {
/**
* @var \Slab\Router\Route $route
*/
try
{
$route = new $routeClass($routeObject);
}
catch (\Exception $exception)
{
if (!empty($this->log))
{
$this->log->error("Failed to add route to table: " . $exception->getMessage());
}
continue;
}
if (!$route->isValid()) {
$this->addDebugMessage('Skipping invalid route!');
continue;
}
$path = $route->getRoutingPath();
//Here we'll iterate through the current routing tree on $currentLevel checking static routes
if ($path) {
$currentLevel =& $routeTable;
//$pathDepth = count($path);
//Loop through each path level and add that level of hierarchy to our routing table
foreach ($path as $pathFolder) {
if (empty($currentLevel[$pathFolder])) {
$currentLevel[$pathFolder] = array();
}
$currentLevel =& $currentLevel[$pathFolder];
}
if (!empty($currentLevel)) {
//Check each item in this list's pattern string against the one we currently have.
//If a pattern string matches (empty or not) that means we have an overridden path
$overridden = false;
foreach ($currentLevel as $index => $subRoute) {
if (($subRoute instanceof \Slab\Router\Route) &&
($subRoute->getPatternString() == $route->getPatternString())
) {
$currentLevel[$index] = $route;
$overridden = true;
}
}
if (!$overridden) {
$currentLevel[] = $route;
}
} else {
$currentLevel[] = $route;
}
} else {
$routeTable['/'][] = $route;
}
}
} | [
"private",
"function",
"loadRouteFile",
"(",
"&",
"$",
"routeTable",
",",
"$",
"fileName",
")",
"{",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"xml",
"=",
"simplexml_load_file",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"xml",
")",
")",
"{",
"$",
"errorMessage",
"=",
"\"Failed to parse XML route file: \"",
".",
"$",
"fileName",
".",
"\"\"",
";",
"foreach",
"(",
"libxml_get_errors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"errorMessage",
".=",
"\"\\n\"",
".",
"$",
"error",
"->",
"message",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"log",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"$",
"errorMessage",
")",
";",
"}",
"return",
";",
"}",
"$",
"routeClass",
"=",
"'Slab\\Router\\Route'",
";",
"if",
"(",
"empty",
"(",
"$",
"routeClass",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"log",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"\"Failed to find suitable Route object.\"",
")",
";",
"}",
"return",
";",
"}",
"foreach",
"(",
"$",
"xml",
"->",
"xpath",
"(",
"'route'",
")",
"as",
"$",
"routeObject",
")",
"{",
"/**\n * @var \\Slab\\Router\\Route $route\n */",
"try",
"{",
"$",
"route",
"=",
"new",
"$",
"routeClass",
"(",
"$",
"routeObject",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"log",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"\"Failed to add route to table: \"",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"route",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addDebugMessage",
"(",
"'Skipping invalid route!'",
")",
";",
"continue",
";",
"}",
"$",
"path",
"=",
"$",
"route",
"->",
"getRoutingPath",
"(",
")",
";",
"//Here we'll iterate through the current routing tree on $currentLevel checking static routes",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"currentLevel",
"=",
"&",
"$",
"routeTable",
";",
"//$pathDepth = count($path);",
"//Loop through each path level and add that level of hierarchy to our routing table",
"foreach",
"(",
"$",
"path",
"as",
"$",
"pathFolder",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"currentLevel",
"[",
"$",
"pathFolder",
"]",
")",
")",
"{",
"$",
"currentLevel",
"[",
"$",
"pathFolder",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"currentLevel",
"=",
"&",
"$",
"currentLevel",
"[",
"$",
"pathFolder",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"currentLevel",
")",
")",
"{",
"//Check each item in this list's pattern string against the one we currently have.",
"//If a pattern string matches (empty or not) that means we have an overridden path",
"$",
"overridden",
"=",
"false",
";",
"foreach",
"(",
"$",
"currentLevel",
"as",
"$",
"index",
"=>",
"$",
"subRoute",
")",
"{",
"if",
"(",
"(",
"$",
"subRoute",
"instanceof",
"\\",
"Slab",
"\\",
"Router",
"\\",
"Route",
")",
"&&",
"(",
"$",
"subRoute",
"->",
"getPatternString",
"(",
")",
"==",
"$",
"route",
"->",
"getPatternString",
"(",
")",
")",
")",
"{",
"$",
"currentLevel",
"[",
"$",
"index",
"]",
"=",
"$",
"route",
";",
"$",
"overridden",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"overridden",
")",
"{",
"$",
"currentLevel",
"[",
"]",
"=",
"$",
"route",
";",
"}",
"}",
"else",
"{",
"$",
"currentLevel",
"[",
"]",
"=",
"$",
"route",
";",
"}",
"}",
"else",
"{",
"$",
"routeTable",
"[",
"'/'",
"]",
"[",
"]",
"=",
"$",
"route",
";",
"}",
"}",
"}"
]
| Load an XML route file from a fully qualified path name
@param array $routeTable
@param string $fileName | [
"Load",
"an",
"XML",
"route",
"file",
"from",
"a",
"fully",
"qualified",
"path",
"name"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L434-L527 | train |
SlabPHP/router | src/Router.php | Router.determineSelectedRoute | public function determineSelectedRoute()
{
if (empty($this->routes))
{
$this->getRoutingTable();
}
if (empty($this->segments)) {
$this->segments = array('/');
}
$currentLevel = &$this->routes;
//$parentSegment = '/';
$index = 0;
$isRoot = true;
foreach ($this->segments as $segment) {
$segmentIsInteger = is_numeric($segment);
//Static route test, numeric segments are not allowed to be traversed
if (!$segmentIsInteger && !empty($currentLevel[$segment])) {
$this->addDebugMessage("Traversing " . $segment);
$currentLevel = &$currentLevel[$segment];
$index = 0;
$isRoot = false;
continue;
}
if ($isRoot && !empty($this->routes['/'])) {
$currentLevel = &$this->routes['/'];
}
//We've hit a dead end here. The current tree branch does not have a static segment to match $segment
if (!empty($currentLevel))
{
foreach ($currentLevel as $route) {
if ($route instanceof \Slab\Router\Route) {
$this->addDebugMessage("Checking route " . $route->getName());
$validationDebug = [];
if ($route->validateDynamicPattern($this->currentRequest, $validationDebug)) {
$this->addDebugMessage("Dynamic pattern match for route " . $route->getName());
$this->selectedRoute = &$route;
return true;
}
}
++$index;
}
}
$this->addDebugMessage("All hope is lost!");
return false;
}
if (!empty($currentLevel))
{
foreach ($currentLevel as &$route)
{
if (!($route instanceof \Slab\Router\Route)) continue;
/**
* @var \Slab\Router\Route $route
*/
if (!$route->isDynamic())
{
$this->selectedRoute = &$route;
$this->addDebugMessage("Found matching static route: " . $this->selectedRoute->getName());
return true;
}
else
{
$validationDebug = [];
if ($route->validateDynamicPattern($this->currentRequest, $validationDebug))
{
$this->selectedRoute = &$route;
$this->addDebugMessage("Found matching dynamic route: " . $this->selectedRoute->getName());
return true;
}
}
}
}
$this->addDebugMessage("Unable to find a matching route.");
return false;
} | php | public function determineSelectedRoute()
{
if (empty($this->routes))
{
$this->getRoutingTable();
}
if (empty($this->segments)) {
$this->segments = array('/');
}
$currentLevel = &$this->routes;
//$parentSegment = '/';
$index = 0;
$isRoot = true;
foreach ($this->segments as $segment) {
$segmentIsInteger = is_numeric($segment);
//Static route test, numeric segments are not allowed to be traversed
if (!$segmentIsInteger && !empty($currentLevel[$segment])) {
$this->addDebugMessage("Traversing " . $segment);
$currentLevel = &$currentLevel[$segment];
$index = 0;
$isRoot = false;
continue;
}
if ($isRoot && !empty($this->routes['/'])) {
$currentLevel = &$this->routes['/'];
}
//We've hit a dead end here. The current tree branch does not have a static segment to match $segment
if (!empty($currentLevel))
{
foreach ($currentLevel as $route) {
if ($route instanceof \Slab\Router\Route) {
$this->addDebugMessage("Checking route " . $route->getName());
$validationDebug = [];
if ($route->validateDynamicPattern($this->currentRequest, $validationDebug)) {
$this->addDebugMessage("Dynamic pattern match for route " . $route->getName());
$this->selectedRoute = &$route;
return true;
}
}
++$index;
}
}
$this->addDebugMessage("All hope is lost!");
return false;
}
if (!empty($currentLevel))
{
foreach ($currentLevel as &$route)
{
if (!($route instanceof \Slab\Router\Route)) continue;
/**
* @var \Slab\Router\Route $route
*/
if (!$route->isDynamic())
{
$this->selectedRoute = &$route;
$this->addDebugMessage("Found matching static route: " . $this->selectedRoute->getName());
return true;
}
else
{
$validationDebug = [];
if ($route->validateDynamicPattern($this->currentRequest, $validationDebug))
{
$this->selectedRoute = &$route;
$this->addDebugMessage("Found matching dynamic route: " . $this->selectedRoute->getName());
return true;
}
}
}
}
$this->addDebugMessage("Unable to find a matching route.");
return false;
} | [
"public",
"function",
"determineSelectedRoute",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"$",
"this",
"->",
"getRoutingTable",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"segments",
")",
")",
"{",
"$",
"this",
"->",
"segments",
"=",
"array",
"(",
"'/'",
")",
";",
"}",
"$",
"currentLevel",
"=",
"&",
"$",
"this",
"->",
"routes",
";",
"//$parentSegment = '/';",
"$",
"index",
"=",
"0",
";",
"$",
"isRoot",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"segments",
"as",
"$",
"segment",
")",
"{",
"$",
"segmentIsInteger",
"=",
"is_numeric",
"(",
"$",
"segment",
")",
";",
"//Static route test, numeric segments are not allowed to be traversed",
"if",
"(",
"!",
"$",
"segmentIsInteger",
"&&",
"!",
"empty",
"(",
"$",
"currentLevel",
"[",
"$",
"segment",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Traversing \"",
".",
"$",
"segment",
")",
";",
"$",
"currentLevel",
"=",
"&",
"$",
"currentLevel",
"[",
"$",
"segment",
"]",
";",
"$",
"index",
"=",
"0",
";",
"$",
"isRoot",
"=",
"false",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"isRoot",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"routes",
"[",
"'/'",
"]",
")",
")",
"{",
"$",
"currentLevel",
"=",
"&",
"$",
"this",
"->",
"routes",
"[",
"'/'",
"]",
";",
"}",
"//We've hit a dead end here. The current tree branch does not have a static segment to match $segment",
"if",
"(",
"!",
"empty",
"(",
"$",
"currentLevel",
")",
")",
"{",
"foreach",
"(",
"$",
"currentLevel",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"instanceof",
"\\",
"Slab",
"\\",
"Router",
"\\",
"Route",
")",
"{",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Checking route \"",
".",
"$",
"route",
"->",
"getName",
"(",
")",
")",
";",
"$",
"validationDebug",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"route",
"->",
"validateDynamicPattern",
"(",
"$",
"this",
"->",
"currentRequest",
",",
"$",
"validationDebug",
")",
")",
"{",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Dynamic pattern match for route \"",
".",
"$",
"route",
"->",
"getName",
"(",
")",
")",
";",
"$",
"this",
"->",
"selectedRoute",
"=",
"&",
"$",
"route",
";",
"return",
"true",
";",
"}",
"}",
"++",
"$",
"index",
";",
"}",
"}",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"All hope is lost!\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"currentLevel",
")",
")",
"{",
"foreach",
"(",
"$",
"currentLevel",
"as",
"&",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"route",
"instanceof",
"\\",
"Slab",
"\\",
"Router",
"\\",
"Route",
")",
")",
"continue",
";",
"/**\n * @var \\Slab\\Router\\Route $route\n */",
"if",
"(",
"!",
"$",
"route",
"->",
"isDynamic",
"(",
")",
")",
"{",
"$",
"this",
"->",
"selectedRoute",
"=",
"&",
"$",
"route",
";",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Found matching static route: \"",
".",
"$",
"this",
"->",
"selectedRoute",
"->",
"getName",
"(",
")",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"validationDebug",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"route",
"->",
"validateDynamicPattern",
"(",
"$",
"this",
"->",
"currentRequest",
",",
"$",
"validationDebug",
")",
")",
"{",
"$",
"this",
"->",
"selectedRoute",
"=",
"&",
"$",
"route",
";",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Found matching dynamic route: \"",
".",
"$",
"this",
"->",
"selectedRoute",
"->",
"getName",
"(",
")",
")",
";",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"addDebugMessage",
"(",
"\"Unable to find a matching route.\"",
")",
";",
"return",
"false",
";",
"}"
]
| Determine the actually selected route from URL params | [
"Determine",
"the",
"actually",
"selected",
"route",
"from",
"URL",
"params"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L532-L624 | train |
SlabPHP/router | src/Router.php | Router.getRouteByName | public function getRouteByName($routeName)
{
if (!empty($this->routeNameMap[$routeName])) {
return $this->routeNameMap[$routeName];
}
return null;
} | php | public function getRouteByName($routeName)
{
if (!empty($this->routeNameMap[$routeName])) {
return $this->routeNameMap[$routeName];
}
return null;
} | [
"public",
"function",
"getRouteByName",
"(",
"$",
"routeName",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"routeNameMap",
"[",
"$",
"routeName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"routeNameMap",
"[",
"$",
"routeName",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Gets a route by name
@param string $routeName
@return null|\Slab\Router\Route | [
"Gets",
"a",
"route",
"by",
"name"
]
| 3e95fa07f694c0e2288a9e9a0ca106117f501a6e | https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Router.php#L642-L649 | train |
the-eater/odango.php | src/NyaaMeta.php | NyaaMeta.createFromArray | public static function createFromArray($array, $unparsed = [])
{
$nyaaMeta = new NyaaMeta();
foreach ($array as $key => $value) {
$nyaaMeta->set($key, $value);
}
$nyaaMeta->setUnparsed($unparsed);
return $nyaaMeta;
} | php | public static function createFromArray($array, $unparsed = [])
{
$nyaaMeta = new NyaaMeta();
foreach ($array as $key => $value) {
$nyaaMeta->set($key, $value);
}
$nyaaMeta->setUnparsed($unparsed);
return $nyaaMeta;
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"$",
"array",
",",
"$",
"unparsed",
"=",
"[",
"]",
")",
"{",
"$",
"nyaaMeta",
"=",
"new",
"NyaaMeta",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"nyaaMeta",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"nyaaMeta",
"->",
"setUnparsed",
"(",
"$",
"unparsed",
")",
";",
"return",
"$",
"nyaaMeta",
";",
"}"
]
| Creates a new NyaaMeta instance from array
@param array $array array of tags that could be parsed
@param array $unparsed The tags that couldn't be parsed
@return NyaaMeta | [
"Creates",
"a",
"new",
"NyaaMeta",
"instance",
"from",
"array"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaMeta.php#L37-L47 | train |
the-eater/odango.php | src/NyaaMeta.php | NyaaMeta.solveIndicator | public static function solveIndicator($data) {
$normData = strtolower(trim($data));
foreach (self::$indicators as $key => $tests) {
foreach ($tests as $test) {
if ($test[0] == '/' && preg_match($test, $normData)) {
return [$key, $normData];
} elseif ($normData === $test) {
return [$key, $normData];
}
}
}
return false;
} | php | public static function solveIndicator($data) {
$normData = strtolower(trim($data));
foreach (self::$indicators as $key => $tests) {
foreach ($tests as $test) {
if ($test[0] == '/' && preg_match($test, $normData)) {
return [$key, $normData];
} elseif ($normData === $test) {
return [$key, $normData];
}
}
}
return false;
} | [
"public",
"static",
"function",
"solveIndicator",
"(",
"$",
"data",
")",
"{",
"$",
"normData",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"data",
")",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"indicators",
"as",
"$",
"key",
"=>",
"$",
"tests",
")",
"{",
"foreach",
"(",
"$",
"tests",
"as",
"$",
"test",
")",
"{",
"if",
"(",
"$",
"test",
"[",
"0",
"]",
"==",
"'/'",
"&&",
"preg_match",
"(",
"$",
"test",
",",
"$",
"normData",
")",
")",
"{",
"return",
"[",
"$",
"key",
",",
"$",
"normData",
"]",
";",
"}",
"elseif",
"(",
"$",
"normData",
"===",
"$",
"test",
")",
"{",
"return",
"[",
"$",
"key",
",",
"$",
"normData",
"]",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Solves what type of data an indicator is
@param string $data The indicator
@return array An array with the first item containing what it represents, and second item containing the normalized version of the data, false is returned when failing to find what is indicated | [
"Solves",
"what",
"type",
"of",
"data",
"an",
"indicator",
"is"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaMeta.php#L184-L197 | train |
the-eater/odango.php | src/NyaaMeta.php | NyaaMeta.get | public function get($meta)
{
return isset($this->parsed[$meta]) ? $this->parsed[$meta] : null;
} | php | public function get($meta)
{
return isset($this->parsed[$meta]) ? $this->parsed[$meta] : null;
} | [
"public",
"function",
"get",
"(",
"$",
"meta",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"parsed",
"[",
"$",
"meta",
"]",
")",
"?",
"$",
"this",
"->",
"parsed",
"[",
"$",
"meta",
"]",
":",
"null",
";",
"}"
]
| Gets the meta value by name, null returned if not found
@param string $meta
@return mixed | [
"Gets",
"the",
"meta",
"value",
"by",
"name",
"null",
"returned",
"if",
"not",
"found"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaMeta.php#L205-L208 | train |
Wedeto/HTML | src/BBCode.php | BBCode.addRule | public function addRule($pattern, $replacement = null)
{
if (is_object($pattern) && method_exists($pattern, 'toArray'))
$pattern = $pattern->toArray();
if (is_object($replacement) && method_exists($replacement, 'toArray'))
$replacement = $replacement->toArray();
if (!(is_array($pattern) || is_string($pattern)))
throw new \RuntimeException("Arguments must be string or array, or implement toArray method");
if (is_array($pattern))
{
if ($replacement !== null)
{
if (!is_array($replacement) || count($replacement) !== count($pattern))
throw new \RuntimeException("When providing arrays as arguments, the should have the same number of elements");
$pattern = array_combine($pattern, $replacement);
}
foreach ($pattern as $pat => $repl)
$this->addRule($pat, $repl);
return $this;
}
// Create a pattern from strings that aren't patterns already
if (substr($pattern, 0, 1) !== "/")
$pattern = "/" . preg_quote($pattern, "/") . "/";
$cb = is_callable($replacement);
if ($cb)
{
$interceptor = new ErrorInterceptor('preg_replace_callback');
$interceptor->registerError(E_WARNING, 'preg_replace');
$interceptor->execute($pattern, $replacement, '');
$errors = $interceptor->getInterceptedErrors();
}
else
{
$interceptor = new ErrorInterceptor('preg_replace');
$interceptor->registerError(E_WARNING, 'preg_replace');
$interceptor->execute($pattern, $replacement, "");
$errors = $interceptor->getInterceptedErrors();
}
if (!empty($errors))
{
$e = reset($errors);
self::$logger->error("Invalid pattern / replacement: {0} / {1}", [$pattern, $replacement]);
throw new \RuntimeException("Invalid pattern or replacement: {$pattern} / {$replacement}", 0, $e);
}
$this->rules[$pattern] = $replacement;
return $this;
} | php | public function addRule($pattern, $replacement = null)
{
if (is_object($pattern) && method_exists($pattern, 'toArray'))
$pattern = $pattern->toArray();
if (is_object($replacement) && method_exists($replacement, 'toArray'))
$replacement = $replacement->toArray();
if (!(is_array($pattern) || is_string($pattern)))
throw new \RuntimeException("Arguments must be string or array, or implement toArray method");
if (is_array($pattern))
{
if ($replacement !== null)
{
if (!is_array($replacement) || count($replacement) !== count($pattern))
throw new \RuntimeException("When providing arrays as arguments, the should have the same number of elements");
$pattern = array_combine($pattern, $replacement);
}
foreach ($pattern as $pat => $repl)
$this->addRule($pat, $repl);
return $this;
}
// Create a pattern from strings that aren't patterns already
if (substr($pattern, 0, 1) !== "/")
$pattern = "/" . preg_quote($pattern, "/") . "/";
$cb = is_callable($replacement);
if ($cb)
{
$interceptor = new ErrorInterceptor('preg_replace_callback');
$interceptor->registerError(E_WARNING, 'preg_replace');
$interceptor->execute($pattern, $replacement, '');
$errors = $interceptor->getInterceptedErrors();
}
else
{
$interceptor = new ErrorInterceptor('preg_replace');
$interceptor->registerError(E_WARNING, 'preg_replace');
$interceptor->execute($pattern, $replacement, "");
$errors = $interceptor->getInterceptedErrors();
}
if (!empty($errors))
{
$e = reset($errors);
self::$logger->error("Invalid pattern / replacement: {0} / {1}", [$pattern, $replacement]);
throw new \RuntimeException("Invalid pattern or replacement: {$pattern} / {$replacement}", 0, $e);
}
$this->rules[$pattern] = $replacement;
return $this;
} | [
"public",
"function",
"addRule",
"(",
"$",
"pattern",
",",
"$",
"replacement",
"=",
"null",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"pattern",
")",
"&&",
"method_exists",
"(",
"$",
"pattern",
",",
"'toArray'",
")",
")",
"$",
"pattern",
"=",
"$",
"pattern",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"replacement",
")",
"&&",
"method_exists",
"(",
"$",
"replacement",
",",
"'toArray'",
")",
")",
"$",
"replacement",
"=",
"$",
"replacement",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"!",
"(",
"is_array",
"(",
"$",
"pattern",
")",
"||",
"is_string",
"(",
"$",
"pattern",
")",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Arguments must be string or array, or implement toArray method\"",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"pattern",
")",
")",
"{",
"if",
"(",
"$",
"replacement",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"replacement",
")",
"||",
"count",
"(",
"$",
"replacement",
")",
"!==",
"count",
"(",
"$",
"pattern",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"When providing arrays as arguments, the should have the same number of elements\"",
")",
";",
"$",
"pattern",
"=",
"array_combine",
"(",
"$",
"pattern",
",",
"$",
"replacement",
")",
";",
"}",
"foreach",
"(",
"$",
"pattern",
"as",
"$",
"pat",
"=>",
"$",
"repl",
")",
"$",
"this",
"->",
"addRule",
"(",
"$",
"pat",
",",
"$",
"repl",
")",
";",
"return",
"$",
"this",
";",
"}",
"// Create a pattern from strings that aren't patterns already",
"if",
"(",
"substr",
"(",
"$",
"pattern",
",",
"0",
",",
"1",
")",
"!==",
"\"/\"",
")",
"$",
"pattern",
"=",
"\"/\"",
".",
"preg_quote",
"(",
"$",
"pattern",
",",
"\"/\"",
")",
".",
"\"/\"",
";",
"$",
"cb",
"=",
"is_callable",
"(",
"$",
"replacement",
")",
";",
"if",
"(",
"$",
"cb",
")",
"{",
"$",
"interceptor",
"=",
"new",
"ErrorInterceptor",
"(",
"'preg_replace_callback'",
")",
";",
"$",
"interceptor",
"->",
"registerError",
"(",
"E_WARNING",
",",
"'preg_replace'",
")",
";",
"$",
"interceptor",
"->",
"execute",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"''",
")",
";",
"$",
"errors",
"=",
"$",
"interceptor",
"->",
"getInterceptedErrors",
"(",
")",
";",
"}",
"else",
"{",
"$",
"interceptor",
"=",
"new",
"ErrorInterceptor",
"(",
"'preg_replace'",
")",
";",
"$",
"interceptor",
"->",
"registerError",
"(",
"E_WARNING",
",",
"'preg_replace'",
")",
";",
"$",
"interceptor",
"->",
"execute",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"\"\"",
")",
";",
"$",
"errors",
"=",
"$",
"interceptor",
"->",
"getInterceptedErrors",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"errors",
")",
")",
"{",
"$",
"e",
"=",
"reset",
"(",
"$",
"errors",
")",
";",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"\"Invalid pattern / replacement: {0} / {1}\"",
",",
"[",
"$",
"pattern",
",",
"$",
"replacement",
"]",
")",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Invalid pattern or replacement: {$pattern} / {$replacement}\"",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"$",
"this",
"->",
"rules",
"[",
"$",
"pattern",
"]",
"=",
"$",
"replacement",
";",
"return",
"$",
"this",
";",
"}"
]
| Add a rule to the set of rules in this BBCode instance
@param $pattern mixed A pattern, an array of patterns or an associative
array of pattern => replacement pairs. Patterns should start
with /. Strings starting with something else are considered
to be strings that should be replaced as-is, without any patterns.
@param $replacement mixed A replacement string, an array of replacements
belonging to the patterns or null, when $pattern specifies all.
Replacement can also be a callable method or function.
@return BBCode Provides fluent interface | [
"Add",
"a",
"rule",
"to",
"the",
"set",
"of",
"rules",
"in",
"this",
"BBCode",
"instance"
]
| 9e725288098c42d0d2953a929faebe628ff4e389 | https://github.com/Wedeto/HTML/blob/9e725288098c42d0d2953a929faebe628ff4e389/src/BBCode.php#L88-L143 | train |
Wedeto/HTML | src/BBCode.php | BBCode.apply | public function apply($txt)
{
if (!is_string($txt))
throw new \RuntimeException("Argument should be a string");
foreach ($this->rules as $pattern => $replacement)
{
if (is_callable($replacement))
$txt = preg_replace_callback($pattern, $replacement, $txt);
else
$txt = preg_replace($pattern, $replacement, $txt);
}
return $txt;
} | php | public function apply($txt)
{
if (!is_string($txt))
throw new \RuntimeException("Argument should be a string");
foreach ($this->rules as $pattern => $replacement)
{
if (is_callable($replacement))
$txt = preg_replace_callback($pattern, $replacement, $txt);
else
$txt = preg_replace($pattern, $replacement, $txt);
}
return $txt;
} | [
"public",
"function",
"apply",
"(",
"$",
"txt",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"txt",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Argument should be a string\"",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"pattern",
"=>",
"$",
"replacement",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"replacement",
")",
")",
"$",
"txt",
"=",
"preg_replace_callback",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"$",
"txt",
")",
";",
"else",
"$",
"txt",
"=",
"preg_replace",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"$",
"txt",
")",
";",
"}",
"return",
"$",
"txt",
";",
"}"
]
| Apply all the configured rules to the provided text and return the result
@param $txt string The text to work on
@return string The text with the patterns replaced by their replacements | [
"Apply",
"all",
"the",
"configured",
"rules",
"to",
"the",
"provided",
"text",
"and",
"return",
"the",
"result"
]
| 9e725288098c42d0d2953a929faebe628ff4e389 | https://github.com/Wedeto/HTML/blob/9e725288098c42d0d2953a929faebe628ff4e389/src/BBCode.php#L150-L164 | train |
mpf-soft/admin-widgets | datatable/Table.php | Table.renderPage | protected function renderPage($page, $options = array()) {
$this->render(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $page . '.php', $options);
} | php | protected function renderPage($page, $options = array()) {
$this->render(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $page . '.php', $options);
} | [
"protected",
"function",
"renderPage",
"(",
"$",
"page",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"render",
"(",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
".",
"'views'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"page",
".",
"'.php'",
",",
"$",
"options",
")",
";",
"}"
]
| Render a selected view.
@param string $page
@param mixed [string] $options | [
"Render",
"a",
"selected",
"view",
"."
]
| 92597f9a09d086664268d6b7e0111d5a5586d8c7 | https://github.com/mpf-soft/admin-widgets/blob/92597f9a09d086664268d6b7e0111d5a5586d8c7/datatable/Table.php#L225-L227 | train |
phossa/phossa-cache | src/Phossa/Cache/Utility/QuickCache.php | QuickCache.flatReference | protected function flatReference(array $reference)/*# : array */
{
reset($reference);
foreach ($reference as $key => $value) {
if (is_object($value)) {
$reference[$key] = get_class($value);
} elseif (is_array($value)) {
$reference[$key] = $this->flatReference($value);
}
}
ksort($reference);
return $reference;
} | php | protected function flatReference(array $reference)/*# : array */
{
reset($reference);
foreach ($reference as $key => $value) {
if (is_object($value)) {
$reference[$key] = get_class($value);
} elseif (is_array($value)) {
$reference[$key] = $this->flatReference($value);
}
}
ksort($reference);
return $reference;
} | [
"protected",
"function",
"flatReference",
"(",
"array",
"$",
"reference",
")",
"/*# : array */",
"{",
"reset",
"(",
"$",
"reference",
")",
";",
"foreach",
"(",
"$",
"reference",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"reference",
"[",
"$",
"key",
"]",
"=",
"get_class",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"reference",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"flatReference",
"(",
"$",
"value",
")",
";",
"}",
"}",
"ksort",
"(",
"$",
"reference",
")",
";",
"return",
"$",
"reference",
";",
"}"
]
| flat the reference array to make it easy for serialize
@param array $reference reference data
@return array flattered array
@access protected | [
"flat",
"the",
"reference",
"array",
"to",
"make",
"it",
"easy",
"for",
"serialize"
]
| ad86bee9c5c646fbae09f6f58a346b379d16276e | https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Utility/QuickCache.php#L121-L133 | train |
eureka-framework/component-response | src/Response/Header/Header.php | Header.setContent | protected function setContent($content)
{
$this->content = (string) $content;
if (empty($this->content)) {
throw new \Exception('Header content is empty !');
}
return $this;
} | php | protected function setContent($content)
{
$this->content = (string) $content;
if (empty($this->content)) {
throw new \Exception('Header content is empty !');
}
return $this;
} | [
"protected",
"function",
"setContent",
"(",
"$",
"content",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"(",
"string",
")",
"$",
"content",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Header content is empty !'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set header content
@param string $content
@return self
@throws \Exception | [
"Set",
"header",
"content"
]
| f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a | https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Header/Header.php#L70-L79 | train |
eureka-framework/component-response | src/Response/Header/Header.php | Header.setHttpCode | protected function setHttpCode($httpCode = null)
{
if ($httpCode !== null) {
$this->httpCode = (int) $httpCode;
if (!HttpCode::exists($this->httpCode)) {
throw new \DomainException('Http Code does not exist! (code: ' . $this->httpCode . ')');
}
}
return $this;
} | php | protected function setHttpCode($httpCode = null)
{
if ($httpCode !== null) {
$this->httpCode = (int) $httpCode;
if (!HttpCode::exists($this->httpCode)) {
throw new \DomainException('Http Code does not exist! (code: ' . $this->httpCode . ')');
}
}
return $this;
} | [
"protected",
"function",
"setHttpCode",
"(",
"$",
"httpCode",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"httpCode",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"httpCode",
"=",
"(",
"int",
")",
"$",
"httpCode",
";",
"if",
"(",
"!",
"HttpCode",
"::",
"exists",
"(",
"$",
"this",
"->",
"httpCode",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Http Code does not exist! (code: '",
".",
"$",
"this",
"->",
"httpCode",
".",
"')'",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set http code for the header
@param int $httpCode
@return self
@throws \DomainException | [
"Set",
"http",
"code",
"for",
"the",
"header"
]
| f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a | https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Header/Header.php#L101-L112 | train |
SlabPHP/controllers | src/Resources/Concatenator.php | Concatenator.determineInputFiles | protected function determineInputFiles()
{
if (empty($this->route->getParameters()->files))
{
$this->setNotReady("No input files found.", null, 404);
return;
}
if (is_array($this->route->getParameters()->files))
{
foreach ($this->route->getParameters()->files as $file)
{
$this->addFileObject((string) $file);
}
}
else
{
$this->addFileObject((string) $this->route->getParameters()->files);
}
} | php | protected function determineInputFiles()
{
if (empty($this->route->getParameters()->files))
{
$this->setNotReady("No input files found.", null, 404);
return;
}
if (is_array($this->route->getParameters()->files))
{
foreach ($this->route->getParameters()->files as $file)
{
$this->addFileObject((string) $file);
}
}
else
{
$this->addFileObject((string) $this->route->getParameters()->files);
}
} | [
"protected",
"function",
"determineInputFiles",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"route",
"->",
"getParameters",
"(",
")",
"->",
"files",
")",
")",
"{",
"$",
"this",
"->",
"setNotReady",
"(",
"\"No input files found.\"",
",",
"null",
",",
"404",
")",
";",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"route",
"->",
"getParameters",
"(",
")",
"->",
"files",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"route",
"->",
"getParameters",
"(",
")",
"->",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"addFileObject",
"(",
"(",
"string",
")",
"$",
"file",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"addFileObject",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"route",
"->",
"getParameters",
"(",
")",
"->",
"files",
")",
";",
"}",
"}"
]
| Determine input files from the route parameters
@throws \Exception | [
"Determine",
"input",
"files",
"from",
"the",
"route",
"parameters"
]
| a1c4fded0265100a85904dd664b972a7f8687652 | https://github.com/SlabPHP/controllers/blob/a1c4fded0265100a85904dd664b972a7f8687652/src/Resources/Concatenator.php#L50-L69 | train |
SlabPHP/controllers | src/Resources/Concatenator.php | Concatenator.addFileObject | private function addFileObject($file)
{
$file = $this->getActualFilename($file);
try
{
$this->concatenator->addObject($file, []);
}
catch (\Exception $e)
{
$this->system->log()->error("Failed to add concatenator object: " . $file);
}
} | php | private function addFileObject($file)
{
$file = $this->getActualFilename($file);
try
{
$this->concatenator->addObject($file, []);
}
catch (\Exception $e)
{
$this->system->log()->error("Failed to add concatenator object: " . $file);
}
} | [
"private",
"function",
"addFileObject",
"(",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getActualFilename",
"(",
"$",
"file",
")",
";",
"try",
"{",
"$",
"this",
"->",
"concatenator",
"->",
"addObject",
"(",
"$",
"file",
",",
"[",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"system",
"->",
"log",
"(",
")",
"->",
"error",
"(",
"\"Failed to add concatenator object: \"",
".",
"$",
"file",
")",
";",
"}",
"}"
]
| Add a file object
@param string $file | [
"Add",
"a",
"file",
"object"
]
| a1c4fded0265100a85904dd664b972a7f8687652 | https://github.com/SlabPHP/controllers/blob/a1c4fded0265100a85904dd664b972a7f8687652/src/Resources/Concatenator.php#L75-L87 | train |
gplcart/cli | controllers/commands/Address.php | Address.cmdGetAddress | public function cmdGetAddress()
{
$result = $this->getListAddress();
$this->outputFormat($result);
$this->outputFormatTableAddress($result);
$this->output();
} | php | public function cmdGetAddress()
{
$result = $this->getListAddress();
$this->outputFormat($result);
$this->outputFormatTableAddress($result);
$this->output();
} | [
"public",
"function",
"cmdGetAddress",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListAddress",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableAddress",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
]
| Callback for "address-get" command | [
"Callback",
"for",
"address",
"-",
"get",
"command"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Address.php#L40-L46 | train |
gplcart/cli | controllers/commands/Address.php | Address.cmdUpdateAddress | public function cmdUpdateAddress()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->setSubmittedJson('data');
$this->validateComponent('address');
$this->updateAddress($params[0]);
$this->output();
} | php | public function cmdUpdateAddress()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->setSubmittedJson('data');
$this->validateComponent('address');
$this->updateAddress($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateAddress",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"setSubmittedJson",
"(",
"'data'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'address'",
")",
";",
"$",
"this",
"->",
"updateAddress",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
]
| Callback for "address-update" command | [
"Callback",
"for",
"address",
"-",
"update",
"command"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Address.php#L102-L122 | train |
gplcart/cli | controllers/commands/Address.php | Address.addAddress | protected function addAddress()
{
if (!$this->isError()) {
$id = $this->address->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | php | protected function addAddress()
{
if (!$this->isError()) {
$id = $this->address->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | [
"protected",
"function",
"addAddress",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"address",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"}",
"}"
]
| Add a new address | [
"Add",
"a",
"new",
"address"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Address.php#L186-L198 | train |
gplcart/cli | controllers/commands/Address.php | Address.updateAddress | protected function updateAddress($address_id)
{
if (!$this->isError() && !$this->address->update($address_id, $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | php | protected function updateAddress($address_id)
{
if (!$this->isError() && !$this->address->update($address_id, $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | [
"protected",
"function",
"updateAddress",
"(",
"$",
"address_id",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"address",
"->",
"update",
"(",
"$",
"address_id",
",",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"}"
]
| Updates an address
@param string $address_id | [
"Updates",
"an",
"address"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Address.php#L204-L209 | train |
gplcart/cli | controllers/commands/Address.php | Address.submitAddAddress | protected function submitAddAddress()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmittedJson('data');
$this->validateComponent('address');
$this->addAddress();
} | php | protected function submitAddAddress()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmittedJson('data');
$this->validateComponent('address');
$this->addAddress();
} | [
"protected",
"function",
"submitAddAddress",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"setSubmittedJson",
"(",
"'data'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'address'",
")",
";",
"$",
"this",
"->",
"addAddress",
"(",
")",
";",
"}"
]
| Add a new address at once | [
"Add",
"a",
"new",
"address",
"at",
"once"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Address.php#L214-L220 | train |
gplcart/cli | controllers/commands/Address.php | Address.wizardAddAddress | protected function wizardAddAddress()
{
$types = $this->address->getTypes();
$this->validateMenu('type', $this->text('Address type'), 'address', array_combine($types, $types), 'shipping');
$this->validatePrompt('user_id', $this->text('User ID'), 'address');
$this->validatePrompt('country', $this->text('Country code'), 'address');
$this->validatePrompt('state_id', $this->text('Country state ID'), 'address');
$this->validatePrompt('city_id', $this->text('City ID'), 'address');
$this->validatePrompt('address_1', $this->text('Address'), 'address');
$this->validatePrompt('address_2', $this->text('Additional address'), 'address');
$this->validatePrompt('phone', $this->text('Phone'), 'address');
$this->validatePrompt('postcode', $this->text('Post code/ZIP'), 'address');
$this->validatePrompt('company', $this->text('Company'), 'address');
$this->validatePrompt('fax', $this->text('Fax'), 'address');
$this->validatePrompt('first_name', $this->text('First name'), 'address');
$this->validatePrompt('middle_name', $this->text('Middle name'), 'address');
$this->validatePrompt('last_name', $this->text('Last name'), 'address');
$this->validatePrompt('data', $this->text('Data'), 'address');
$this->setSubmittedJson('data');
$this->validateComponent('address');
$this->addAddress();
} | php | protected function wizardAddAddress()
{
$types = $this->address->getTypes();
$this->validateMenu('type', $this->text('Address type'), 'address', array_combine($types, $types), 'shipping');
$this->validatePrompt('user_id', $this->text('User ID'), 'address');
$this->validatePrompt('country', $this->text('Country code'), 'address');
$this->validatePrompt('state_id', $this->text('Country state ID'), 'address');
$this->validatePrompt('city_id', $this->text('City ID'), 'address');
$this->validatePrompt('address_1', $this->text('Address'), 'address');
$this->validatePrompt('address_2', $this->text('Additional address'), 'address');
$this->validatePrompt('phone', $this->text('Phone'), 'address');
$this->validatePrompt('postcode', $this->text('Post code/ZIP'), 'address');
$this->validatePrompt('company', $this->text('Company'), 'address');
$this->validatePrompt('fax', $this->text('Fax'), 'address');
$this->validatePrompt('first_name', $this->text('First name'), 'address');
$this->validatePrompt('middle_name', $this->text('Middle name'), 'address');
$this->validatePrompt('last_name', $this->text('Last name'), 'address');
$this->validatePrompt('data', $this->text('Data'), 'address');
$this->setSubmittedJson('data');
$this->validateComponent('address');
$this->addAddress();
} | [
"protected",
"function",
"wizardAddAddress",
"(",
")",
"{",
"$",
"types",
"=",
"$",
"this",
"->",
"address",
"->",
"getTypes",
"(",
")",
";",
"$",
"this",
"->",
"validateMenu",
"(",
"'type'",
",",
"$",
"this",
"->",
"text",
"(",
"'Address type'",
")",
",",
"'address'",
",",
"array_combine",
"(",
"$",
"types",
",",
"$",
"types",
")",
",",
"'shipping'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'user_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'User ID'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'country'",
",",
"$",
"this",
"->",
"text",
"(",
"'Country code'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'state_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Country state ID'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'city_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'City ID'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'address_1'",
",",
"$",
"this",
"->",
"text",
"(",
"'Address'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'address_2'",
",",
"$",
"this",
"->",
"text",
"(",
"'Additional address'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'phone'",
",",
"$",
"this",
"->",
"text",
"(",
"'Phone'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'postcode'",
",",
"$",
"this",
"->",
"text",
"(",
"'Post code/ZIP'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'company'",
",",
"$",
"this",
"->",
"text",
"(",
"'Company'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'fax'",
",",
"$",
"this",
"->",
"text",
"(",
"'Fax'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'first_name'",
",",
"$",
"this",
"->",
"text",
"(",
"'First name'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'middle_name'",
",",
"$",
"this",
"->",
"text",
"(",
"'Middle name'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'last_name'",
",",
"$",
"this",
"->",
"text",
"(",
"'Last name'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'data'",
",",
"$",
"this",
"->",
"text",
"(",
"'Data'",
")",
",",
"'address'",
")",
";",
"$",
"this",
"->",
"setSubmittedJson",
"(",
"'data'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'address'",
")",
";",
"$",
"this",
"->",
"addAddress",
"(",
")",
";",
"}"
]
| Add a new address step by step | [
"Add",
"a",
"new",
"address",
"step",
"by",
"step"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Address.php#L225-L248 | train |
gap-db/OrmCache | GapOrmCache/Drivers/MemcacheDriver.php | MemcacheDriver.remove | public function remove($key){
return ($this->memcache) ? $this->memcache->remove($this->prefix . '_' . $key) : false;
} | php | public function remove($key){
return ($this->memcache) ? $this->memcache->remove($this->prefix . '_' . $key) : false;
} | [
"public",
"function",
"remove",
"(",
"$",
"key",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"memcache",
")",
"?",
"$",
"this",
"->",
"memcache",
"->",
"remove",
"(",
"$",
"this",
"->",
"prefix",
".",
"'_'",
".",
"$",
"key",
")",
":",
"false",
";",
"}"
]
| Remove Memcache key
@param $key
@return bool | [
"Remove",
"Memcache",
"key"
]
| 52c50c643b9bb5d4d7bca5edcc78897b60833e59 | https://github.com/gap-db/OrmCache/blob/52c50c643b9bb5d4d7bca5edcc78897b60833e59/GapOrmCache/Drivers/MemcacheDriver.php#L60-L62 | train |
itcreator/custom-cmf | Module/Category/src/Cmf/Category/Controller/CategoryController.php | CategoryController.checkRootNode | protected function checkRootNode()
{
$id = (int)Application::getRequest()->get('id');
$repository = $this->getEntityManager()->getRepository($this->entityName);
/** @var $node Category */
if ($node = $repository->find($id)) {
return $node->getLevel() > 1;
}
return false;
} | php | protected function checkRootNode()
{
$id = (int)Application::getRequest()->get('id');
$repository = $this->getEntityManager()->getRepository($this->entityName);
/** @var $node Category */
if ($node = $repository->find($id)) {
return $node->getLevel() > 1;
}
return false;
} | [
"protected",
"function",
"checkRootNode",
"(",
")",
"{",
"$",
"id",
"=",
"(",
"int",
")",
"Application",
"::",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"repository",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"entityName",
")",
";",
"/** @var $node Category */",
"if",
"(",
"$",
"node",
"=",
"$",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"node",
"->",
"getLevel",
"(",
")",
">",
"1",
";",
"}",
"return",
"false",
";",
"}"
]
| If node not root then method return true
@return bool | [
"If",
"node",
"not",
"root",
"then",
"method",
"return",
"true"
]
| 42fc0535dfa0f641856f06673f6ab596b2020c40 | https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/Category/src/Cmf/Category/Controller/CategoryController.php#L45-L56 | train |
net-tools/core | src/Helpers/DataHelper.php | DataHelper.array2Parameters | static function array2Parameters($params, $stringdelim)
{
$s = "";
foreach ( $params as $p )
{
if ( is_int($p) )
$s .= "$p, ";
else
$s .= $stringdelim . $p . $stringdelim . ", ";
}
if ( $s )
// remove last ', ' (comma and space)
$s = substr($s, 0, -2);
return $s;
} | php | static function array2Parameters($params, $stringdelim)
{
$s = "";
foreach ( $params as $p )
{
if ( is_int($p) )
$s .= "$p, ";
else
$s .= $stringdelim . $p . $stringdelim . ", ";
}
if ( $s )
// remove last ', ' (comma and space)
$s = substr($s, 0, -2);
return $s;
} | [
"static",
"function",
"array2Parameters",
"(",
"$",
"params",
",",
"$",
"stringdelim",
")",
"{",
"$",
"s",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"p",
")",
")",
"$",
"s",
".=",
"\"$p, \"",
";",
"else",
"$",
"s",
".=",
"$",
"stringdelim",
".",
"$",
"p",
".",
"$",
"stringdelim",
".",
"\", \"",
";",
"}",
"if",
"(",
"$",
"s",
")",
"// remove last ', ' (comma and space)",
"$",
"s",
"=",
"substr",
"(",
"$",
"s",
",",
"0",
",",
"-",
"2",
")",
";",
"return",
"$",
"s",
";",
"}"
]
| Convert an array to a commas separated string of parameters
Srings in array are enclosed with a given delimiter, number are outputed directly
@param string[] $params An associative array to convert to a string
@param string $stringdelim Delimiters for strings (usually ' or ")
@return string Return a string with the array imploded (values separated by ", ") | [
"Convert",
"an",
"array",
"to",
"a",
"commas",
"separated",
"string",
"of",
"parameters"
]
| 51446641cee22c0cf53d2b409c76cc8bd1a187e7 | https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/DataHelper.php#L76-L93 | train |
net-tools/core | src/Helpers/DataHelper.php | DataHelper.is_associative_array | static function is_associative_array($a, $ifEmptyAssociativeArray = false)
{
if( !is_array($a) )
return false;
if ( count($a) == 0 )
return $ifEmptyAssociativeArray;
// firstly, verify that all keys are ints ; if not, the array is associative
$keys = array_keys($a);
foreach ( $keys as $k )
if ( !is_int($k) )
return true;
// if all keys are numeric, they must follow themselves : e.g. 0, 1, 2, 3 is OK, but 0, 3, 4 is NOT OK.
return max($keys)+1 != count($a);
} | php | static function is_associative_array($a, $ifEmptyAssociativeArray = false)
{
if( !is_array($a) )
return false;
if ( count($a) == 0 )
return $ifEmptyAssociativeArray;
// firstly, verify that all keys are ints ; if not, the array is associative
$keys = array_keys($a);
foreach ( $keys as $k )
if ( !is_int($k) )
return true;
// if all keys are numeric, they must follow themselves : e.g. 0, 1, 2, 3 is OK, but 0, 3, 4 is NOT OK.
return max($keys)+1 != count($a);
} | [
"static",
"function",
"is_associative_array",
"(",
"$",
"a",
",",
"$",
"ifEmptyAssociativeArray",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"a",
")",
")",
"return",
"false",
";",
"if",
"(",
"count",
"(",
"$",
"a",
")",
"==",
"0",
")",
"return",
"$",
"ifEmptyAssociativeArray",
";",
"// firstly, verify that all keys are ints ; if not, the array is associative",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"a",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"k",
")",
"if",
"(",
"!",
"is_int",
"(",
"$",
"k",
")",
")",
"return",
"true",
";",
"// if all keys are numeric, they must follow themselves : e.g. 0, 1, 2, 3 is OK, but 0, 3, 4 is NOT OK.",
"return",
"max",
"(",
"$",
"keys",
")",
"+",
"1",
"!=",
"count",
"(",
"$",
"a",
")",
";",
"}"
]
| Test if a given array is associative or has only numeric keys
@param mixed[] $a Array to test
@param bool $ifEmptyAssociativeArray If $a is an empty array, we can return true or false, depending on this optionnal parameter
@return bool True if array $a is associative, false otherwise | [
"Test",
"if",
"a",
"given",
"array",
"is",
"associative",
"or",
"has",
"only",
"numeric",
"keys"
]
| 51446641cee22c0cf53d2b409c76cc8bd1a187e7 | https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/DataHelper.php#L140-L155 | train |
net-tools/core | src/Helpers/DataHelper.php | DataHelper.matchAll | static function matchAll($pattern, $buffer, $vars, &$matches)
{
$tmp = array();
if ( preg_match_all($pattern, $buffer, $tmp, PREG_SET_ORDER) === FALSE )
return false;
else
{
// for all matching substrings
for ( $m = 0 ; $m < count($tmp) ; $m++ )
{
$res = array();
// for all named capturing parenthesis
for ( $v = 0 ; $v < count($vars) ; $v++ )
// if this capture group must be returned (name not empty)
if ( $vars[$v] != '' )
$res[$vars[$v]] = $tmp[$m][1+$v]; //$matches[0] = full matching string, first matching parenthesis is at column 1
// new matching substring to return
$matches[] = $res;
}
return true;
}
} | php | static function matchAll($pattern, $buffer, $vars, &$matches)
{
$tmp = array();
if ( preg_match_all($pattern, $buffer, $tmp, PREG_SET_ORDER) === FALSE )
return false;
else
{
// for all matching substrings
for ( $m = 0 ; $m < count($tmp) ; $m++ )
{
$res = array();
// for all named capturing parenthesis
for ( $v = 0 ; $v < count($vars) ; $v++ )
// if this capture group must be returned (name not empty)
if ( $vars[$v] != '' )
$res[$vars[$v]] = $tmp[$m][1+$v]; //$matches[0] = full matching string, first matching parenthesis is at column 1
// new matching substring to return
$matches[] = $res;
}
return true;
}
} | [
"static",
"function",
"matchAll",
"(",
"$",
"pattern",
",",
"$",
"buffer",
",",
"$",
"vars",
",",
"&",
"$",
"matches",
")",
"{",
"$",
"tmp",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"buffer",
",",
"$",
"tmp",
",",
"PREG_SET_ORDER",
")",
"===",
"FALSE",
")",
"return",
"false",
";",
"else",
"{",
"// for all matching substrings",
"for",
"(",
"$",
"m",
"=",
"0",
";",
"$",
"m",
"<",
"count",
"(",
"$",
"tmp",
")",
";",
"$",
"m",
"++",
")",
"{",
"$",
"res",
"=",
"array",
"(",
")",
";",
"// for all named capturing parenthesis ",
"for",
"(",
"$",
"v",
"=",
"0",
";",
"$",
"v",
"<",
"count",
"(",
"$",
"vars",
")",
";",
"$",
"v",
"++",
")",
"// if this capture group must be returned (name not empty)",
"if",
"(",
"$",
"vars",
"[",
"$",
"v",
"]",
"!=",
"''",
")",
"$",
"res",
"[",
"$",
"vars",
"[",
"$",
"v",
"]",
"]",
"=",
"$",
"tmp",
"[",
"$",
"m",
"]",
"[",
"1",
"+",
"$",
"v",
"]",
";",
"//$matches[0] = full matching string, first matching parenthesis is at column 1",
"// new matching substring to return",
"$",
"matches",
"[",
"]",
"=",
"$",
"res",
";",
"}",
"return",
"true",
";",
"}",
"}"
]
| Convenient function to extract data from a string through a regular expression.
We get data in an associative array (instead of numeric indexes for capturing parenthesis).
The function set all matching substrings (preg_match_all) in the matches paremeters (passed by reference), so the
returned array is in fact an array of array : first index is the n-substring matching, second index is the named parenthesis data.
@param string $pattern PCRE regular expression
@param string $buffer String to be searched
@param string[] $vars Array of strings, naming capturing parenthesis in their order of appearance in the pattern
@param string[] $matches Array of matches (passed by reference)
@return bool Return true of false (no match) | [
"Convenient",
"function",
"to",
"extract",
"data",
"from",
"a",
"string",
"through",
"a",
"regular",
"expression",
"."
]
| 51446641cee22c0cf53d2b409c76cc8bd1a187e7 | https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/DataHelper.php#L198-L223 | train |
net-tools/core | src/Helpers/DataHelper.php | DataHelper.string2associativeArray | static function string2associativeArray($str, $sep, $sepval, $valIfEmpty = NULL)
{
$str = explode($sep, $str);
$ret = array();
// for each items
foreach ( $str as $s )
{
// get key and value
$s = explode($sepval, $s);
if ( count($s) == 2 ) // we should always have 2 items here : the key and the value
$ret[$s[0]] = ($s[1]!='') ? $s[1] : $valIfEmpty;
}
return $ret;
} | php | static function string2associativeArray($str, $sep, $sepval, $valIfEmpty = NULL)
{
$str = explode($sep, $str);
$ret = array();
// for each items
foreach ( $str as $s )
{
// get key and value
$s = explode($sepval, $s);
if ( count($s) == 2 ) // we should always have 2 items here : the key and the value
$ret[$s[0]] = ($s[1]!='') ? $s[1] : $valIfEmpty;
}
return $ret;
} | [
"static",
"function",
"string2associativeArray",
"(",
"$",
"str",
",",
"$",
"sep",
",",
"$",
"sepval",
",",
"$",
"valIfEmpty",
"=",
"NULL",
")",
"{",
"$",
"str",
"=",
"explode",
"(",
"$",
"sep",
",",
"$",
"str",
")",
";",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"// for each items",
"foreach",
"(",
"$",
"str",
"as",
"$",
"s",
")",
"{",
"// get key and value",
"$",
"s",
"=",
"explode",
"(",
"$",
"sepval",
",",
"$",
"s",
")",
";",
"if",
"(",
"count",
"(",
"$",
"s",
")",
"==",
"2",
")",
"// we should always have 2 items here : the key and the value",
"$",
"ret",
"[",
"$",
"s",
"[",
"0",
"]",
"]",
"=",
"(",
"$",
"s",
"[",
"1",
"]",
"!=",
"''",
")",
"?",
"$",
"s",
"[",
"1",
"]",
":",
"$",
"valIfEmpty",
";",
"}",
"return",
"$",
"ret",
";",
"}"
]
| Decode a string to an associative array
Useful to decode url parameters to array : e.g. file=my.txt&user=me becomes the array ['file'=>'my.txt','user'=>'me']
@param string $str String to process
@param string $sep Separator of values (e.g. '&' in a querystring)
@param string $sepval Separator between key and value (e.g. '=' in a querystring)
@param string $valIfEmpty Default value if value is empty
@return string[] String converted to an associative array | [
"Decode",
"a",
"string",
"to",
"an",
"associative",
"array"
]
| 51446641cee22c0cf53d2b409c76cc8bd1a187e7 | https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/DataHelper.php#L237-L252 | train |
net-tools/core | src/Helpers/DataHelper.php | DataHelper.explodeAssociativeArray | static function explodeAssociativeArray($str, $sep = ';', $sepval = '=', $valIfEmpty = NULL)
{
return self::string2associativeArray($str, $sep, $sepval, $valIfEmpty);
} | php | static function explodeAssociativeArray($str, $sep = ';', $sepval = '=', $valIfEmpty = NULL)
{
return self::string2associativeArray($str, $sep, $sepval, $valIfEmpty);
} | [
"static",
"function",
"explodeAssociativeArray",
"(",
"$",
"str",
",",
"$",
"sep",
"=",
"';'",
",",
"$",
"sepval",
"=",
"'='",
",",
"$",
"valIfEmpty",
"=",
"NULL",
")",
"{",
"return",
"self",
"::",
"string2associativeArray",
"(",
"$",
"str",
",",
"$",
"sep",
",",
"$",
"sepval",
",",
"$",
"valIfEmpty",
")",
";",
"}"
]
| Synonymous for string2associativeArray, with default values for separators
@param string $str String to process
@param string $sep Separator of values (e.g. '&' in a querystring)
@param string $sepval Separator between key and value (e.g. '=' in a querystring)
@param string $valIfEmpty Default value if value is empty
@return string[] String converted to an associative array | [
"Synonymous",
"for",
"string2associativeArray",
"with",
"default",
"values",
"for",
"separators"
]
| 51446641cee22c0cf53d2b409c76cc8bd1a187e7 | https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/DataHelper.php#L263-L266 | train |
ekyna/SettingBundle | DependencyInjection/Configuration.php | Configuration.getPoolsSection | private function getPoolsSection()
{
$builder = new TreeBuilder();
$node = $builder->root('pools');
$node
->addDefaultsIfNotSet()
->children()
->arrayNode('helper')
->isRequired()
->addDefaultsIfNotSet()
->children()
->variableNode('templates')->defaultValue([
'_form.html' => 'EkynaSettingBundle:Admin/Helper:_form.html',
'show.html' => 'EkynaSettingBundle:Admin/Helper:show.html',
])->end()
->scalarNode('parent')->end()
->scalarNode('entity')->defaultValue('Ekyna\Bundle\SettingBundle\Entity\Helper')->end()
->scalarNode('controller')->defaultValue('Ekyna\Bundle\SettingBundle\Controller\Admin\HelperController')->end()
->scalarNode('operator')->end()
->scalarNode('repository')->defaultValue('Ekyna\Bundle\SettingBundle\Entity\HelperRepository')->end()
->scalarNode('form')->defaultValue('Ekyna\Bundle\SettingBundle\Form\Type\HelperType')->end()
->scalarNode('table')->defaultValue('Ekyna\Bundle\SettingBundle\Table\Type\HelperType')->end()
->end()
->end()
->arrayNode('redirection')
->isRequired()
->addDefaultsIfNotSet()
->children()
->variableNode('templates')->defaultValue([
'_form.html' => 'EkynaSettingBundle:Admin/Redirection:_form.html',
'show.html' => 'EkynaSettingBundle:Admin/Redirection:show.html',
])->end()
->scalarNode('parent')->end()
->scalarNode('entity')->defaultValue('Ekyna\Bundle\SettingBundle\Entity\Redirection')->end()
->scalarNode('controller')->defaultValue('Ekyna\Bundle\SettingBundle\Controller\Admin\RedirectionController')->end()
->scalarNode('operator')->end()
->scalarNode('repository')->defaultValue('Ekyna\Bundle\SettingBundle\Entity\RedirectionRepository')->end()
->scalarNode('form')->defaultValue('Ekyna\Bundle\SettingBundle\Form\Type\RedirectionType')->end()
->scalarNode('table')->defaultValue('Ekyna\Bundle\SettingBundle\Table\Type\RedirectionType')->end()
->end()
->end()
->end()
;
return $node;
} | php | private function getPoolsSection()
{
$builder = new TreeBuilder();
$node = $builder->root('pools');
$node
->addDefaultsIfNotSet()
->children()
->arrayNode('helper')
->isRequired()
->addDefaultsIfNotSet()
->children()
->variableNode('templates')->defaultValue([
'_form.html' => 'EkynaSettingBundle:Admin/Helper:_form.html',
'show.html' => 'EkynaSettingBundle:Admin/Helper:show.html',
])->end()
->scalarNode('parent')->end()
->scalarNode('entity')->defaultValue('Ekyna\Bundle\SettingBundle\Entity\Helper')->end()
->scalarNode('controller')->defaultValue('Ekyna\Bundle\SettingBundle\Controller\Admin\HelperController')->end()
->scalarNode('operator')->end()
->scalarNode('repository')->defaultValue('Ekyna\Bundle\SettingBundle\Entity\HelperRepository')->end()
->scalarNode('form')->defaultValue('Ekyna\Bundle\SettingBundle\Form\Type\HelperType')->end()
->scalarNode('table')->defaultValue('Ekyna\Bundle\SettingBundle\Table\Type\HelperType')->end()
->end()
->end()
->arrayNode('redirection')
->isRequired()
->addDefaultsIfNotSet()
->children()
->variableNode('templates')->defaultValue([
'_form.html' => 'EkynaSettingBundle:Admin/Redirection:_form.html',
'show.html' => 'EkynaSettingBundle:Admin/Redirection:show.html',
])->end()
->scalarNode('parent')->end()
->scalarNode('entity')->defaultValue('Ekyna\Bundle\SettingBundle\Entity\Redirection')->end()
->scalarNode('controller')->defaultValue('Ekyna\Bundle\SettingBundle\Controller\Admin\RedirectionController')->end()
->scalarNode('operator')->end()
->scalarNode('repository')->defaultValue('Ekyna\Bundle\SettingBundle\Entity\RedirectionRepository')->end()
->scalarNode('form')->defaultValue('Ekyna\Bundle\SettingBundle\Form\Type\RedirectionType')->end()
->scalarNode('table')->defaultValue('Ekyna\Bundle\SettingBundle\Table\Type\RedirectionType')->end()
->end()
->end()
->end()
;
return $node;
} | [
"private",
"function",
"getPoolsSection",
"(",
")",
"{",
"$",
"builder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"node",
"=",
"$",
"builder",
"->",
"root",
"(",
"'pools'",
")",
";",
"$",
"node",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"arrayNode",
"(",
"'helper'",
")",
"->",
"isRequired",
"(",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"variableNode",
"(",
"'templates'",
")",
"->",
"defaultValue",
"(",
"[",
"'_form.html'",
"=>",
"'EkynaSettingBundle:Admin/Helper:_form.html'",
",",
"'show.html'",
"=>",
"'EkynaSettingBundle:Admin/Helper:show.html'",
",",
"]",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'parent'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'entity'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Entity\\Helper'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'controller'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Controller\\Admin\\HelperController'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'operator'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'repository'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Entity\\HelperRepository'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'form'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Form\\Type\\HelperType'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'table'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Table\\Type\\HelperType'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'redirection'",
")",
"->",
"isRequired",
"(",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"variableNode",
"(",
"'templates'",
")",
"->",
"defaultValue",
"(",
"[",
"'_form.html'",
"=>",
"'EkynaSettingBundle:Admin/Redirection:_form.html'",
",",
"'show.html'",
"=>",
"'EkynaSettingBundle:Admin/Redirection:show.html'",
",",
"]",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'parent'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'entity'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Entity\\Redirection'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'controller'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Controller\\Admin\\RedirectionController'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'operator'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'repository'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Entity\\RedirectionRepository'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'form'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Form\\Type\\RedirectionType'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'table'",
")",
"->",
"defaultValue",
"(",
"'Ekyna\\Bundle\\SettingBundle\\Table\\Type\\RedirectionType'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"node",
";",
"}"
]
| Returns the pools configuration definition.
@return \Symfony\Component\Config\Definition\Builder\NodeDefinition | [
"Returns",
"the",
"pools",
"configuration",
"definition",
"."
]
| df58f83eb3a01ef56cd76ea73639322c581e75c1 | https://github.com/ekyna/SettingBundle/blob/df58f83eb3a01ef56cd76ea73639322c581e75c1/DependencyInjection/Configuration.php#L43-L89 | train |
wakerscz/cms-base-module | src/Util/NestedSet.php | NestedSet.getTree | public function getTree(ObjectCollection $objectCollection, int $left = 0, int $right = NULL) : array
{
$items = [];
foreach ($objectCollection as $item)
{
$items[] = $item;
}
$tree = $this->generateTree($items, $left, $right);
return $tree;
} | php | public function getTree(ObjectCollection $objectCollection, int $left = 0, int $right = NULL) : array
{
$items = [];
foreach ($objectCollection as $item)
{
$items[] = $item;
}
$tree = $this->generateTree($items, $left, $right);
return $tree;
} | [
"public",
"function",
"getTree",
"(",
"ObjectCollection",
"$",
"objectCollection",
",",
"int",
"$",
"left",
"=",
"0",
",",
"int",
"$",
"right",
"=",
"NULL",
")",
":",
"array",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"objectCollection",
"as",
"$",
"item",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"$",
"tree",
"=",
"$",
"this",
"->",
"generateTree",
"(",
"$",
"items",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"return",
"$",
"tree",
";",
"}"
]
| Metoda pro transformaci nested tree do multilevel pole
@param ObjectCollection $objectCollection
@param int $left
@param int|NULL $right
@return array | [
"Metoda",
"pro",
"transformaci",
"nested",
"tree",
"do",
"multilevel",
"pole"
]
| 3a14ea5d6a41999eb5b92fb956b55363806ff872 | https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/NestedSet.php#L72-L84 | train |
wakerscz/cms-base-module | src/Util/NestedSet.php | NestedSet.getFlatCollection | public function getFlatCollection(array $tree) : ObjectCollection
{
$data = [];
array_walk_recursive($tree, function ($item) use (&$data)
{
if ($item !== NULL)
{
$data[] = $item;
}
});
return new ObjectCollection($data);
} | php | public function getFlatCollection(array $tree) : ObjectCollection
{
$data = [];
array_walk_recursive($tree, function ($item) use (&$data)
{
if ($item !== NULL)
{
$data[] = $item;
}
});
return new ObjectCollection($data);
} | [
"public",
"function",
"getFlatCollection",
"(",
"array",
"$",
"tree",
")",
":",
"ObjectCollection",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"array_walk_recursive",
"(",
"$",
"tree",
",",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"&",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"item",
"!==",
"NULL",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
")",
";",
"return",
"new",
"ObjectCollection",
"(",
"$",
"data",
")",
";",
"}"
]
| Metoda pro transformaci multilevel pole do flat ObjectCollection
@param array $tree
@return ObjectCollection | [
"Metoda",
"pro",
"transformaci",
"multilevel",
"pole",
"do",
"flat",
"ObjectCollection"
]
| 3a14ea5d6a41999eb5b92fb956b55363806ff872 | https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/NestedSet.php#L92-L105 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.date | public function date(string $format = Date::DISPLAY_FORMAT) : DateFieldBuilder
{
return new DateFieldBuilder($this->field->type(new DateType($format)));
} | php | public function date(string $format = Date::DISPLAY_FORMAT) : DateFieldBuilder
{
return new DateFieldBuilder($this->field->type(new DateType($format)));
} | [
"public",
"function",
"date",
"(",
"string",
"$",
"format",
"=",
"Date",
"::",
"DISPLAY_FORMAT",
")",
":",
"DateFieldBuilder",
"{",
"return",
"new",
"DateFieldBuilder",
"(",
"$",
"this",
"->",
"field",
"->",
"type",
"(",
"new",
"DateType",
"(",
"$",
"format",
")",
")",
")",
";",
"}"
]
| Validates the input with the supplied format and
converts the input to a Date instance.
@see \Dms\Common\Structure\DateTime\Date
@param string $format
@return DateFieldBuilder | [
"Validates",
"the",
"input",
"with",
"the",
"supplied",
"format",
"and",
"converts",
"the",
"input",
"to",
"a",
"Date",
"instance",
"."
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L193-L196 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.dateTime | public function dateTime(string $format = DateTime::DISPLAY_FORMAT) : DateTimeFieldBuilder
{
return new DateTimeFieldBuilder($this->field->type(new DateTimeType($format)));
} | php | public function dateTime(string $format = DateTime::DISPLAY_FORMAT) : DateTimeFieldBuilder
{
return new DateTimeFieldBuilder($this->field->type(new DateTimeType($format)));
} | [
"public",
"function",
"dateTime",
"(",
"string",
"$",
"format",
"=",
"DateTime",
"::",
"DISPLAY_FORMAT",
")",
":",
"DateTimeFieldBuilder",
"{",
"return",
"new",
"DateTimeFieldBuilder",
"(",
"$",
"this",
"->",
"field",
"->",
"type",
"(",
"new",
"DateTimeType",
"(",
"$",
"format",
")",
")",
")",
";",
"}"
]
| Validates the input with the supplied format and
converts the input to a DateTime instance.
@see Dms\Common\Structure\DateTime\DateTime
@param string $format
@return DateTimeFieldBuilder | [
"Validates",
"the",
"input",
"with",
"the",
"supplied",
"format",
"and",
"converts",
"the",
"input",
"to",
"a",
"DateTime",
"instance",
"."
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L208-L211 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.time | public function time(string $format = TimeOfDay::DEFAULT_FORMAT) : TimeOfDayFieldBuilder
{
return new TimeOfDayFieldBuilder($this->field->type(new TimeOfDayType($format)));
} | php | public function time(string $format = TimeOfDay::DEFAULT_FORMAT) : TimeOfDayFieldBuilder
{
return new TimeOfDayFieldBuilder($this->field->type(new TimeOfDayType($format)));
} | [
"public",
"function",
"time",
"(",
"string",
"$",
"format",
"=",
"TimeOfDay",
"::",
"DEFAULT_FORMAT",
")",
":",
"TimeOfDayFieldBuilder",
"{",
"return",
"new",
"TimeOfDayFieldBuilder",
"(",
"$",
"this",
"->",
"field",
"->",
"type",
"(",
"new",
"TimeOfDayType",
"(",
"$",
"format",
")",
")",
")",
";",
"}"
]
| Validates the input with the supplied format and
converts the input to a TimeOfDay instance.
@see Dms\Common\Structure\DateTime\TimeOfDay
@param string $format
@return TimeOfDayFieldBuilder | [
"Validates",
"the",
"input",
"with",
"the",
"supplied",
"format",
"and",
"converts",
"the",
"input",
"to",
"a",
"TimeOfDay",
"instance",
"."
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L223-L226 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.dateTimeWithTimezone | public function dateTimeWithTimezone(string $format = TimezonedDateTime::DISPLAY_FORMAT) : TimezonedDateTimeFieldBuilder
{
return new TimezonedDateTimeFieldBuilder($this->field->type(new TimezonedDateTimeType($format)));
} | php | public function dateTimeWithTimezone(string $format = TimezonedDateTime::DISPLAY_FORMAT) : TimezonedDateTimeFieldBuilder
{
return new TimezonedDateTimeFieldBuilder($this->field->type(new TimezonedDateTimeType($format)));
} | [
"public",
"function",
"dateTimeWithTimezone",
"(",
"string",
"$",
"format",
"=",
"TimezonedDateTime",
"::",
"DISPLAY_FORMAT",
")",
":",
"TimezonedDateTimeFieldBuilder",
"{",
"return",
"new",
"TimezonedDateTimeFieldBuilder",
"(",
"$",
"this",
"->",
"field",
"->",
"type",
"(",
"new",
"TimezonedDateTimeType",
"(",
"$",
"format",
")",
")",
")",
";",
"}"
]
| Validates the input with the supplied format and
converts the input to a TimezonedDateTime instance.
@see Dms\Common\Structure\DateTime\TimezonedDateTime
@param string $format
@return TimezonedDateTimeFieldBuilder | [
"Validates",
"the",
"input",
"with",
"the",
"supplied",
"format",
"and",
"converts",
"the",
"input",
"to",
"a",
"TimezonedDateTime",
"instance",
"."
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L238-L241 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.dateRange | public function dateRange(string $format = Date::DISPLAY_FORMAT) : FieldBuilderBase
{
return $this->field->type(new DateRangeType($format));
} | php | public function dateRange(string $format = Date::DISPLAY_FORMAT) : FieldBuilderBase
{
return $this->field->type(new DateRangeType($format));
} | [
"public",
"function",
"dateRange",
"(",
"string",
"$",
"format",
"=",
"Date",
"::",
"DISPLAY_FORMAT",
")",
":",
"FieldBuilderBase",
"{",
"return",
"$",
"this",
"->",
"field",
"->",
"type",
"(",
"new",
"DateRangeType",
"(",
"$",
"format",
")",
")",
";",
"}"
]
| Validates the input as a date range and converts
it to an instance of DateRange.
@see \Dms\Common\Structure\DateTime\DateRange
@param string $format
@return FieldBuilderBase | [
"Validates",
"the",
"input",
"as",
"a",
"date",
"range",
"and",
"converts",
"it",
"to",
"an",
"instance",
"of",
"DateRange",
"."
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L253-L256 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.dateTimeRange | public function dateTimeRange(string $format = DateTime::DISPLAY_FORMAT) : FieldBuilderBase
{
return $this->field->type(new DateTimeRangeType($format));
} | php | public function dateTimeRange(string $format = DateTime::DISPLAY_FORMAT) : FieldBuilderBase
{
return $this->field->type(new DateTimeRangeType($format));
} | [
"public",
"function",
"dateTimeRange",
"(",
"string",
"$",
"format",
"=",
"DateTime",
"::",
"DISPLAY_FORMAT",
")",
":",
"FieldBuilderBase",
"{",
"return",
"$",
"this",
"->",
"field",
"->",
"type",
"(",
"new",
"DateTimeRangeType",
"(",
"$",
"format",
")",
")",
";",
"}"
]
| Validates the input with the supplied format and
converts the input to a DateTimeRange instance.
@see Dms\Common\Structure\DateTime\DateTimeRange
@param string $format
@return FieldBuilderBase | [
"Validates",
"the",
"input",
"with",
"the",
"supplied",
"format",
"and",
"converts",
"the",
"input",
"to",
"a",
"DateTimeRange",
"instance",
"."
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L268-L271 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.timeRange | public function timeRange(string $format = TimeOfDay::DEFAULT_FORMAT) : FieldBuilderBase
{
return $this->field->type(new TimeRangeType($format));
} | php | public function timeRange(string $format = TimeOfDay::DEFAULT_FORMAT) : FieldBuilderBase
{
return $this->field->type(new TimeRangeType($format));
} | [
"public",
"function",
"timeRange",
"(",
"string",
"$",
"format",
"=",
"TimeOfDay",
"::",
"DEFAULT_FORMAT",
")",
":",
"FieldBuilderBase",
"{",
"return",
"$",
"this",
"->",
"field",
"->",
"type",
"(",
"new",
"TimeRangeType",
"(",
"$",
"format",
")",
")",
";",
"}"
]
| Validates the input with the supplied format and
converts the input to a TimeRange instance.
@see Dms\Common\Structure\DateTime\TimeRange
@param string $format
@return FieldBuilderBase | [
"Validates",
"the",
"input",
"with",
"the",
"supplied",
"format",
"and",
"converts",
"the",
"input",
"to",
"a",
"TimeRange",
"instance",
"."
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L283-L286 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.dateTimeWithTimezoneRange | public function dateTimeWithTimezoneRange(string $format = TimezonedDateTime::DISPLAY_FORMAT) : FieldBuilderBase
{
return $this->field->type(new TimezonedDateTimeRangeType($format));
} | php | public function dateTimeWithTimezoneRange(string $format = TimezonedDateTime::DISPLAY_FORMAT) : FieldBuilderBase
{
return $this->field->type(new TimezonedDateTimeRangeType($format));
} | [
"public",
"function",
"dateTimeWithTimezoneRange",
"(",
"string",
"$",
"format",
"=",
"TimezonedDateTime",
"::",
"DISPLAY_FORMAT",
")",
":",
"FieldBuilderBase",
"{",
"return",
"$",
"this",
"->",
"field",
"->",
"type",
"(",
"new",
"TimezonedDateTimeRangeType",
"(",
"$",
"format",
")",
")",
";",
"}"
]
| Validates the input with the supplied format and
converts the input to a TimezonedDateTimeRange instance.
@see Dms\Common\Structure\DateTime\TimezonedDateTimeRange
@param string $format
@return FieldBuilderBase | [
"Validates",
"the",
"input",
"with",
"the",
"supplied",
"format",
"and",
"converts",
"the",
"input",
"to",
"a",
"TimezonedDateTimeRange",
"instance",
"."
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L298-L301 | train |
dms-org/common.structure | src/FieldBuilder.php | FieldBuilder.multipleFrom | public function multipleFrom(array $valueLabelMap) : ArrayOfFieldBuilder
{
return $this->arrayOf(
Field::element()->string()->oneOf($valueLabelMap)->required()
)->containsNoDuplicates();
} | php | public function multipleFrom(array $valueLabelMap) : ArrayOfFieldBuilder
{
return $this->arrayOf(
Field::element()->string()->oneOf($valueLabelMap)->required()
)->containsNoDuplicates();
} | [
"public",
"function",
"multipleFrom",
"(",
"array",
"$",
"valueLabelMap",
")",
":",
"ArrayOfFieldBuilder",
"{",
"return",
"$",
"this",
"->",
"arrayOf",
"(",
"Field",
"::",
"element",
"(",
")",
"->",
"string",
"(",
")",
"->",
"oneOf",
"(",
"$",
"valueLabelMap",
")",
"->",
"required",
"(",
")",
")",
"->",
"containsNoDuplicates",
"(",
")",
";",
"}"
]
| Validates the input as an an array only containing elements which
are in the supplied value map
Example
<code>
->multipleFrom([
'value' => 'Label',
'another-value' => 'Another Label',
])
</code>
@param array $valueLabelMap
@return ArrayOfFieldBuilder | [
"Validates",
"the",
"input",
"as",
"an",
"an",
"array",
"only",
"containing",
"elements",
"which",
"are",
"in",
"the",
"supplied",
"value",
"map"
]
| 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FieldBuilder.php#L569-L574 | train |
covex-nn/JooS | src/JooS/VarSpace.php | VarSpace.nsPush | public function nsPush()
{
$nsName = self::DELIMITER . (self::$_pushID++);
$this->_data[$nsName] = array();
$this->_current = &$this->_data[$nsName];
$this->_names[] = &$this->_current;
$this->_pushedData[] = $nsName;
} | php | public function nsPush()
{
$nsName = self::DELIMITER . (self::$_pushID++);
$this->_data[$nsName] = array();
$this->_current = &$this->_data[$nsName];
$this->_names[] = &$this->_current;
$this->_pushedData[] = $nsName;
} | [
"public",
"function",
"nsPush",
"(",
")",
"{",
"$",
"nsName",
"=",
"self",
"::",
"DELIMITER",
".",
"(",
"self",
"::",
"$",
"_pushID",
"++",
")",
";",
"$",
"this",
"->",
"_data",
"[",
"$",
"nsName",
"]",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"_current",
"=",
"&",
"$",
"this",
"->",
"_data",
"[",
"$",
"nsName",
"]",
";",
"$",
"this",
"->",
"_names",
"[",
"]",
"=",
"&",
"$",
"this",
"->",
"_current",
";",
"$",
"this",
"->",
"_pushedData",
"[",
"]",
"=",
"$",
"nsName",
";",
"}"
]
| Pushes namespace.
@return null | [
"Pushes",
"namespace",
"."
]
| 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/VarSpace.php#L121-L129 | train |
covex-nn/JooS | src/JooS/VarSpace.php | VarSpace.nsPop | public function nsPop()
{
array_pop($this->_names);
$this->_current = &$this->_names[sizeof($this->_names) - 1];
unset($this->_data[array_pop($this->_pushedData)]);
} | php | public function nsPop()
{
array_pop($this->_names);
$this->_current = &$this->_names[sizeof($this->_names) - 1];
unset($this->_data[array_pop($this->_pushedData)]);
} | [
"public",
"function",
"nsPop",
"(",
")",
"{",
"array_pop",
"(",
"$",
"this",
"->",
"_names",
")",
";",
"$",
"this",
"->",
"_current",
"=",
"&",
"$",
"this",
"->",
"_names",
"[",
"sizeof",
"(",
"$",
"this",
"->",
"_names",
")",
"-",
"1",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"_data",
"[",
"array_pop",
"(",
"$",
"this",
"->",
"_pushedData",
")",
"]",
")",
";",
"}"
]
| Pops namespace.
@return null | [
"Pops",
"namespace",
"."
]
| 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/VarSpace.php#L136-L141 | train |
covex-nn/JooS | src/JooS/VarSpace.php | VarSpace._shiftTmp | private function _shiftTmp($path)
{
if ($path) {
$names = explode(self::DELIMITER, $path);
foreach ($names as $name) {
if (!is_array($this->_tmp)) {
$this->_tmp = array();
}
if (!isset($this->_tmp[$name])) {
$this->_tmp[$name] = null;
}
$this->_tmp = &$this->_tmp[$name];
}
}
} | php | private function _shiftTmp($path)
{
if ($path) {
$names = explode(self::DELIMITER, $path);
foreach ($names as $name) {
if (!is_array($this->_tmp)) {
$this->_tmp = array();
}
if (!isset($this->_tmp[$name])) {
$this->_tmp[$name] = null;
}
$this->_tmp = &$this->_tmp[$name];
}
}
} | [
"private",
"function",
"_shiftTmp",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"names",
"=",
"explode",
"(",
"self",
"::",
"DELIMITER",
",",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"_tmp",
")",
")",
"{",
"$",
"this",
"->",
"_tmp",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_tmp",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_tmp",
"[",
"$",
"name",
"]",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"_tmp",
"=",
"&",
"$",
"this",
"->",
"_tmp",
"[",
"$",
"name",
"]",
";",
"}",
"}",
"}"
]
| It shifts.
@param string $path Path
@return null | [
"It",
"shifts",
"."
]
| 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/VarSpace.php#L150-L165 | train |
enebe-nb/phergie-irc-plugin-react-autorejoin | src/Plugin.php | Plugin.joinOnMatch | public function joinOnMatch($nickname, UserEventInterface $event, EventQueueInterface $queue)
{
if ($nickname == $event->getConnection()->getNickname()
&& ($index = array_search($event->getSource(), $this->channels)) !== false) {
$queue->ircJoin($this->channels[$index],
$this->keys ? $this->keys[$index] : null);
}
} | php | public function joinOnMatch($nickname, UserEventInterface $event, EventQueueInterface $queue)
{
if ($nickname == $event->getConnection()->getNickname()
&& ($index = array_search($event->getSource(), $this->channels)) !== false) {
$queue->ircJoin($this->channels[$index],
$this->keys ? $this->keys[$index] : null);
}
} | [
"public",
"function",
"joinOnMatch",
"(",
"$",
"nickname",
",",
"UserEventInterface",
"$",
"event",
",",
"EventQueueInterface",
"$",
"queue",
")",
"{",
"if",
"(",
"$",
"nickname",
"==",
"$",
"event",
"->",
"getConnection",
"(",
")",
"->",
"getNickname",
"(",
")",
"&&",
"(",
"$",
"index",
"=",
"array_search",
"(",
"$",
"event",
"->",
"getSource",
"(",
")",
",",
"$",
"this",
"->",
"channels",
")",
")",
"!==",
"false",
")",
"{",
"$",
"queue",
"->",
"ircJoin",
"(",
"$",
"this",
"->",
"channels",
"[",
"$",
"index",
"]",
",",
"$",
"this",
"->",
"keys",
"?",
"$",
"this",
"->",
"keys",
"[",
"$",
"index",
"]",
":",
"null",
")",
";",
"}",
"}"
]
| Joins a channel if nickname and channel matches the own nickname
and a channel in 'channels' configuration respectively.
@param string $nickname
@param \Phergie\Irc\Event\UserEventInterface $event
@param \Phergie\Irc\Bot\React\EventQueueInterface $queue | [
"Joins",
"a",
"channel",
"if",
"nickname",
"and",
"channel",
"matches",
"the",
"own",
"nickname",
"and",
"a",
"channel",
"in",
"channels",
"configuration",
"respectively",
"."
]
| 75b540ef8bf12b18efb653de538c76f0b40508dd | https://github.com/enebe-nb/phergie-irc-plugin-react-autorejoin/blob/75b540ef8bf12b18efb653de538c76f0b40508dd/src/Plugin.php#L87-L94 | train |
enebe-nb/phergie-irc-plugin-react-autorejoin | src/Plugin.php | Plugin.onPartChannels | public function onPartChannels(UserEventInterface $event, EventQueueInterface $queue)
{
$this->joinOnMatch($event->getNick(), $event, $queue);
} | php | public function onPartChannels(UserEventInterface $event, EventQueueInterface $queue)
{
$this->joinOnMatch($event->getNick(), $event, $queue);
} | [
"public",
"function",
"onPartChannels",
"(",
"UserEventInterface",
"$",
"event",
",",
"EventQueueInterface",
"$",
"queue",
")",
"{",
"$",
"this",
"->",
"joinOnMatch",
"(",
"$",
"event",
"->",
"getNick",
"(",
")",
",",
"$",
"event",
",",
"$",
"queue",
")",
";",
"}"
]
| Listen for part channel events.
@param \Phergie\Irc\Event\UserEventInterface $event
@param \Phergie\Irc\Bot\React\EventQueueInterface $queue | [
"Listen",
"for",
"part",
"channel",
"events",
"."
]
| 75b540ef8bf12b18efb653de538c76f0b40508dd | https://github.com/enebe-nb/phergie-irc-plugin-react-autorejoin/blob/75b540ef8bf12b18efb653de538c76f0b40508dd/src/Plugin.php#L102-L105 | train |
enebe-nb/phergie-irc-plugin-react-autorejoin | src/Plugin.php | Plugin.onKickChannels | public function onKickChannels(UserEventInterface $event, EventQueueInterface $queue)
{
$this->joinOnMatch($event->getParams()['user'], $event, $queue);
} | php | public function onKickChannels(UserEventInterface $event, EventQueueInterface $queue)
{
$this->joinOnMatch($event->getParams()['user'], $event, $queue);
} | [
"public",
"function",
"onKickChannels",
"(",
"UserEventInterface",
"$",
"event",
",",
"EventQueueInterface",
"$",
"queue",
")",
"{",
"$",
"this",
"->",
"joinOnMatch",
"(",
"$",
"event",
"->",
"getParams",
"(",
")",
"[",
"'user'",
"]",
",",
"$",
"event",
",",
"$",
"queue",
")",
";",
"}"
]
| Listen for kick channel events.
@param \Phergie\Irc\Event\UserEventInterface $event
@param \Phergie\Irc\Bot\React\EventQueueInterface $queue | [
"Listen",
"for",
"kick",
"channel",
"events",
"."
]
| 75b540ef8bf12b18efb653de538c76f0b40508dd | https://github.com/enebe-nb/phergie-irc-plugin-react-autorejoin/blob/75b540ef8bf12b18efb653de538c76f0b40508dd/src/Plugin.php#L113-L116 | train |
SlabPHP/database | src/Providers/MySQL/Provider.php | Provider.query | public function query($queryString, $suggestedClass = NULL)
{
if (!empty($this->log)) {
$this->log->debug("Performing SQL: " . $queryString . '...', 'DATABASE');
}
$result = $this->mysqli->query($queryString);
if (!empty($this->mysqli->error)) {
throw new \Slab\Database\Exceptions\Query("Query error: " . $queryString . " with error " . $this->mysqli->error);
}
if (empty($result)) {
throw new \Slab\Database\Exceptions\Query("Query Failed: " . $queryString . " with no error.");
}
$affectedRows = 0;
$error = '';
try
{
$affectedRows = $this->mysqli->affected_rows;
$error = $this->mysqli->error;
}
catch (\Throwable $exception)
{
//This means we're in a test environment
}
$response = new Response();
$response->initializeFromQueryResults(
$result,
$affectedRows,
$error,
$suggestedClass
);
return $response;
} | php | public function query($queryString, $suggestedClass = NULL)
{
if (!empty($this->log)) {
$this->log->debug("Performing SQL: " . $queryString . '...', 'DATABASE');
}
$result = $this->mysqli->query($queryString);
if (!empty($this->mysqli->error)) {
throw new \Slab\Database\Exceptions\Query("Query error: " . $queryString . " with error " . $this->mysqli->error);
}
if (empty($result)) {
throw new \Slab\Database\Exceptions\Query("Query Failed: " . $queryString . " with no error.");
}
$affectedRows = 0;
$error = '';
try
{
$affectedRows = $this->mysqli->affected_rows;
$error = $this->mysqli->error;
}
catch (\Throwable $exception)
{
//This means we're in a test environment
}
$response = new Response();
$response->initializeFromQueryResults(
$result,
$affectedRows,
$error,
$suggestedClass
);
return $response;
} | [
"public",
"function",
"query",
"(",
"$",
"queryString",
",",
"$",
"suggestedClass",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"log",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"\"Performing SQL: \"",
".",
"$",
"queryString",
".",
"'...'",
",",
"'DATABASE'",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"queryString",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"mysqli",
"->",
"error",
")",
")",
"{",
"throw",
"new",
"\\",
"Slab",
"\\",
"Database",
"\\",
"Exceptions",
"\\",
"Query",
"(",
"\"Query error: \"",
".",
"$",
"queryString",
".",
"\" with error \"",
".",
"$",
"this",
"->",
"mysqli",
"->",
"error",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"\\",
"Slab",
"\\",
"Database",
"\\",
"Exceptions",
"\\",
"Query",
"(",
"\"Query Failed: \"",
".",
"$",
"queryString",
".",
"\" with no error.\"",
")",
";",
"}",
"$",
"affectedRows",
"=",
"0",
";",
"$",
"error",
"=",
"''",
";",
"try",
"{",
"$",
"affectedRows",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"affected_rows",
";",
"$",
"error",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"error",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"exception",
")",
"{",
"//This means we're in a test environment",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"initializeFromQueryResults",
"(",
"$",
"result",
",",
"$",
"affectedRows",
",",
"$",
"error",
",",
"$",
"suggestedClass",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Perform a standard query
@param string $queryString
@param string $suggestedClass
@throws \Slab\Database\Exceptions\Query
@return \Slab\Database\Providers\BaseResponse | [
"Perform",
"a",
"standard",
"query"
]
| d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Providers/MySQL/Provider.php#L56-L94 | train |
SlabPHP/database | src/Providers/MySQL/Provider.php | Provider.buildInsertQuery | public function buildInsertQuery($table, $data)
{
$sql = "INSERT INTO " . $this->quoteSpecialName($table) . " ";
if (!empty($data['ON DUPLICATE'])) {
$onDuplicate = $data['ON DUPLICATE'];
unset($data['ON DUPLICATE']);
}
$keys = $values = '';
foreach ($data as $key => $value) {
if (!empty($keys)) $keys .= ', ';
if (!empty($values)) $values .= ', ';
$keys .= '`' . $key . '`';
$values .= $this->escapeItem($value);
}
$keys = '(' . $keys . ')';
$values = '(' . $values . ')';
$sql .= $keys . ' VALUES ' . $values;
if (!empty($onDuplicate)) {
$sql .= " ON DUPLICATE KEY UPDATE " . $onDuplicate;
}
$sql .= ';';
return $sql;
} | php | public function buildInsertQuery($table, $data)
{
$sql = "INSERT INTO " . $this->quoteSpecialName($table) . " ";
if (!empty($data['ON DUPLICATE'])) {
$onDuplicate = $data['ON DUPLICATE'];
unset($data['ON DUPLICATE']);
}
$keys = $values = '';
foreach ($data as $key => $value) {
if (!empty($keys)) $keys .= ', ';
if (!empty($values)) $values .= ', ';
$keys .= '`' . $key . '`';
$values .= $this->escapeItem($value);
}
$keys = '(' . $keys . ')';
$values = '(' . $values . ')';
$sql .= $keys . ' VALUES ' . $values;
if (!empty($onDuplicate)) {
$sql .= " ON DUPLICATE KEY UPDATE " . $onDuplicate;
}
$sql .= ';';
return $sql;
} | [
"public",
"function",
"buildInsertQuery",
"(",
"$",
"table",
",",
"$",
"data",
")",
"{",
"$",
"sql",
"=",
"\"INSERT INTO \"",
".",
"$",
"this",
"->",
"quoteSpecialName",
"(",
"$",
"table",
")",
".",
"\" \"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'ON DUPLICATE'",
"]",
")",
")",
"{",
"$",
"onDuplicate",
"=",
"$",
"data",
"[",
"'ON DUPLICATE'",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"'ON DUPLICATE'",
"]",
")",
";",
"}",
"$",
"keys",
"=",
"$",
"values",
"=",
"''",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"keys",
")",
")",
"$",
"keys",
".=",
"', '",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"values",
")",
")",
"$",
"values",
".=",
"', '",
";",
"$",
"keys",
".=",
"'`'",
".",
"$",
"key",
".",
"'`'",
";",
"$",
"values",
".=",
"$",
"this",
"->",
"escapeItem",
"(",
"$",
"value",
")",
";",
"}",
"$",
"keys",
"=",
"'('",
".",
"$",
"keys",
".",
"')'",
";",
"$",
"values",
"=",
"'('",
".",
"$",
"values",
".",
"')'",
";",
"$",
"sql",
".=",
"$",
"keys",
".",
"' VALUES '",
".",
"$",
"values",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"onDuplicate",
")",
")",
"{",
"$",
"sql",
".=",
"\" ON DUPLICATE KEY UPDATE \"",
".",
"$",
"onDuplicate",
";",
"}",
"$",
"sql",
".=",
"';'",
";",
"return",
"$",
"sql",
";",
"}"
]
| Perform an insert query
@param string $table
@param string[] $data
@return integer|boolean | [
"Perform",
"an",
"insert",
"query"
]
| d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Providers/MySQL/Provider.php#L126-L157 | train |
SlabPHP/database | src/Providers/MySQL/Provider.php | Provider.quoteSpecialName | protected function quoteSpecialName($name)
{
//If user already back ticked, return the original string
if ($name[0] == '`' && $name[mb_strlen($name) - 1] == '`') return $name;
//Back tick string
$name = '`' . $name . '`';
//Check if its a qualified table name, if so escape around the dot as well
$name = str_replace('.', '`.`', $name);
return $name;
} | php | protected function quoteSpecialName($name)
{
//If user already back ticked, return the original string
if ($name[0] == '`' && $name[mb_strlen($name) - 1] == '`') return $name;
//Back tick string
$name = '`' . $name . '`';
//Check if its a qualified table name, if so escape around the dot as well
$name = str_replace('.', '`.`', $name);
return $name;
} | [
"protected",
"function",
"quoteSpecialName",
"(",
"$",
"name",
")",
"{",
"//If user already back ticked, return the original string",
"if",
"(",
"$",
"name",
"[",
"0",
"]",
"==",
"'`'",
"&&",
"$",
"name",
"[",
"mb_strlen",
"(",
"$",
"name",
")",
"-",
"1",
"]",
"==",
"'`'",
")",
"return",
"$",
"name",
";",
"//Back tick string",
"$",
"name",
"=",
"'`'",
".",
"$",
"name",
".",
"'`'",
";",
"//Check if its a qualified table name, if so escape around the dot as well",
"$",
"name",
"=",
"str_replace",
"(",
"'.'",
",",
"'`.`'",
",",
"$",
"name",
")",
";",
"return",
"$",
"name",
";",
"}"
]
| MySQL style special naming backticks quotes
@param string $name
@return string | [
"MySQL",
"style",
"special",
"naming",
"backticks",
"quotes"
]
| d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Providers/MySQL/Provider.php#L181-L193 | train |
SlabPHP/database | src/Providers/MySQL/Provider.php | Provider.buildUpdateQuery | public function buildUpdateQuery($table, $data, $where, $limit)
{
$sql = "UPDATE " . $this->quoteSpecialName($table) . " SET ";
$values = '';
foreach ($data as $key => $value) {
if (!empty($values)) $values .= ', ';
$values .= $this->quoteSpecialName($key) . ' = ' . $this->escapeItem($value);
}
$sql .= $values . ' WHERE ' . $where;
if (!empty($limit)) {
$sql .= ' LIMIT ' . $limit;
}
$sql .= ';';
return $sql;
} | php | public function buildUpdateQuery($table, $data, $where, $limit)
{
$sql = "UPDATE " . $this->quoteSpecialName($table) . " SET ";
$values = '';
foreach ($data as $key => $value) {
if (!empty($values)) $values .= ', ';
$values .= $this->quoteSpecialName($key) . ' = ' . $this->escapeItem($value);
}
$sql .= $values . ' WHERE ' . $where;
if (!empty($limit)) {
$sql .= ' LIMIT ' . $limit;
}
$sql .= ';';
return $sql;
} | [
"public",
"function",
"buildUpdateQuery",
"(",
"$",
"table",
",",
"$",
"data",
",",
"$",
"where",
",",
"$",
"limit",
")",
"{",
"$",
"sql",
"=",
"\"UPDATE \"",
".",
"$",
"this",
"->",
"quoteSpecialName",
"(",
"$",
"table",
")",
".",
"\" SET \"",
";",
"$",
"values",
"=",
"''",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"values",
")",
")",
"$",
"values",
".=",
"', '",
";",
"$",
"values",
".=",
"$",
"this",
"->",
"quoteSpecialName",
"(",
"$",
"key",
")",
".",
"' = '",
".",
"$",
"this",
"->",
"escapeItem",
"(",
"$",
"value",
")",
";",
"}",
"$",
"sql",
".=",
"$",
"values",
".",
"' WHERE '",
".",
"$",
"where",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"sql",
".=",
"' LIMIT '",
".",
"$",
"limit",
";",
"}",
"$",
"sql",
".=",
"';'",
";",
"return",
"$",
"sql",
";",
"}"
]
| Update a table
@param string $table
@param array $data
@param string $whereValue
@param integer $limit
@return string | [
"Update",
"a",
"table"
]
| d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Providers/MySQL/Provider.php#L205-L225 | train |
SlabPHP/database | src/Providers/MySQL/Provider.php | Provider.wheel | public function wheel($table, $column, $value, $separator = '_', $maxTries = 10)
{
$tempValue = $value;
for ($i = 2; $i <= $maxTries; ++$i) {
$result = $this->query("select count(*) as cnt from " . $this->quoteSpecialName($table) . " where " . $this->quoteSpecialName($column) . " = '" . $this->real_escape($tempValue) . "' limit 1;", null);
$row = $result->row();
if ($row->cnt == 0) {
return $tempValue;
}
$tempValue = $value . $separator . $i;
}
throw new \Slab\Database\Exceptions\Query("Failed to wheel value " . $value . " over " . $maxTries . " tries on " . $table . "." . $column);
} | php | public function wheel($table, $column, $value, $separator = '_', $maxTries = 10)
{
$tempValue = $value;
for ($i = 2; $i <= $maxTries; ++$i) {
$result = $this->query("select count(*) as cnt from " . $this->quoteSpecialName($table) . " where " . $this->quoteSpecialName($column) . " = '" . $this->real_escape($tempValue) . "' limit 1;", null);
$row = $result->row();
if ($row->cnt == 0) {
return $tempValue;
}
$tempValue = $value . $separator . $i;
}
throw new \Slab\Database\Exceptions\Query("Failed to wheel value " . $value . " over " . $maxTries . " tries on " . $table . "." . $column);
} | [
"public",
"function",
"wheel",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"value",
",",
"$",
"separator",
"=",
"'_'",
",",
"$",
"maxTries",
"=",
"10",
")",
"{",
"$",
"tempValue",
"=",
"$",
"value",
";",
"for",
"(",
"$",
"i",
"=",
"2",
";",
"$",
"i",
"<=",
"$",
"maxTries",
";",
"++",
"$",
"i",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"query",
"(",
"\"select count(*) as cnt from \"",
".",
"$",
"this",
"->",
"quoteSpecialName",
"(",
"$",
"table",
")",
".",
"\" where \"",
".",
"$",
"this",
"->",
"quoteSpecialName",
"(",
"$",
"column",
")",
".",
"\" = '\"",
".",
"$",
"this",
"->",
"real_escape",
"(",
"$",
"tempValue",
")",
".",
"\"' limit 1;\"",
",",
"null",
")",
";",
"$",
"row",
"=",
"$",
"result",
"->",
"row",
"(",
")",
";",
"if",
"(",
"$",
"row",
"->",
"cnt",
"==",
"0",
")",
"{",
"return",
"$",
"tempValue",
";",
"}",
"$",
"tempValue",
"=",
"$",
"value",
".",
"$",
"separator",
".",
"$",
"i",
";",
"}",
"throw",
"new",
"\\",
"Slab",
"\\",
"Database",
"\\",
"Exceptions",
"\\",
"Query",
"(",
"\"Failed to wheel value \"",
".",
"$",
"value",
".",
"\" over \"",
".",
"$",
"maxTries",
".",
"\" tries on \"",
".",
"$",
"table",
".",
"\".\"",
".",
"$",
"column",
")",
";",
"}"
]
| "Wheel" a string value in the database
@param $table
@param $column
@param $value
@param string $separator
@param int $maxTries
@return string
@throws \Slab\Database\Exceptions\Query | [
"Wheel",
"a",
"string",
"value",
"in",
"the",
"database"
]
| d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Providers/MySQL/Provider.php#L291-L307 | train |
agentmedia/phine-core | src/Core/Logic/Config/SettingsProxy.php | SettingsProxy.CreateSettings | private function CreateSettings()
{
$this->settings = new Settings();
$this->settings->SetLogLifetime(90);
$this->settings->SetChangeRequestLifetime(30);
$this->settings->SetSmtpSecurity((string)Enums\SmtpSecurity::None());
$admin = $this->FirstAdmin();
if ($admin)
{
$this->settings->SetMailFromEMail($admin->GetEMail());
if ($admin->GetFirstName() && $admin->GetLastName())
{
$this->settings->SetMailFromName($admin->GetFirstName() . ' ' . $admin->GetLastName());
}
}
$this->settings->Save();
} | php | private function CreateSettings()
{
$this->settings = new Settings();
$this->settings->SetLogLifetime(90);
$this->settings->SetChangeRequestLifetime(30);
$this->settings->SetSmtpSecurity((string)Enums\SmtpSecurity::None());
$admin = $this->FirstAdmin();
if ($admin)
{
$this->settings->SetMailFromEMail($admin->GetEMail());
if ($admin->GetFirstName() && $admin->GetLastName())
{
$this->settings->SetMailFromName($admin->GetFirstName() . ' ' . $admin->GetLastName());
}
}
$this->settings->Save();
} | [
"private",
"function",
"CreateSettings",
"(",
")",
"{",
"$",
"this",
"->",
"settings",
"=",
"new",
"Settings",
"(",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetLogLifetime",
"(",
"90",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetChangeRequestLifetime",
"(",
"30",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetSmtpSecurity",
"(",
"(",
"string",
")",
"Enums",
"\\",
"SmtpSecurity",
"::",
"None",
"(",
")",
")",
";",
"$",
"admin",
"=",
"$",
"this",
"->",
"FirstAdmin",
"(",
")",
";",
"if",
"(",
"$",
"admin",
")",
"{",
"$",
"this",
"->",
"settings",
"->",
"SetMailFromEMail",
"(",
"$",
"admin",
"->",
"GetEMail",
"(",
")",
")",
";",
"if",
"(",
"$",
"admin",
"->",
"GetFirstName",
"(",
")",
"&&",
"$",
"admin",
"->",
"GetLastName",
"(",
")",
")",
"{",
"$",
"this",
"->",
"settings",
"->",
"SetMailFromName",
"(",
"$",
"admin",
"->",
"GetFirstName",
"(",
")",
".",
"' '",
".",
"$",
"admin",
"->",
"GetLastName",
"(",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"settings",
"->",
"Save",
"(",
")",
";",
"}"
]
| Creates the settings initally | [
"Creates",
"the",
"settings",
"initally"
]
| 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Config/SettingsProxy.php#L60-L76 | train |
agentmedia/phine-core | src/Core/Logic/Config/SettingsProxy.php | SettingsProxy.FirstAdmin | private function FirstAdmin()
{
$sql = Access::SqlBuilder();
$tblUser = User::Schema()->Table();
$where = $sql->Equals($tblUser->Field('IsAdmin'), $sql->Value(true));
$orderBy = $sql->OrderList($sql->OrderAsc($tblUser->Field('ID')));
return User::Schema()->First($where, $orderBy);
} | php | private function FirstAdmin()
{
$sql = Access::SqlBuilder();
$tblUser = User::Schema()->Table();
$where = $sql->Equals($tblUser->Field('IsAdmin'), $sql->Value(true));
$orderBy = $sql->OrderList($sql->OrderAsc($tblUser->Field('ID')));
return User::Schema()->First($where, $orderBy);
} | [
"private",
"function",
"FirstAdmin",
"(",
")",
"{",
"$",
"sql",
"=",
"Access",
"::",
"SqlBuilder",
"(",
")",
";",
"$",
"tblUser",
"=",
"User",
"::",
"Schema",
"(",
")",
"->",
"Table",
"(",
")",
";",
"$",
"where",
"=",
"$",
"sql",
"->",
"Equals",
"(",
"$",
"tblUser",
"->",
"Field",
"(",
"'IsAdmin'",
")",
",",
"$",
"sql",
"->",
"Value",
"(",
"true",
")",
")",
";",
"$",
"orderBy",
"=",
"$",
"sql",
"->",
"OrderList",
"(",
"$",
"sql",
"->",
"OrderAsc",
"(",
"$",
"tblUser",
"->",
"Field",
"(",
"'ID'",
")",
")",
")",
";",
"return",
"User",
"::",
"Schema",
"(",
")",
"->",
"First",
"(",
"$",
"where",
",",
"$",
"orderBy",
")",
";",
"}"
]
| Gets the first user that is an admin
@return User The admin user, if present | [
"Gets",
"the",
"first",
"user",
"that",
"is",
"an",
"admin"
]
| 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Config/SettingsProxy.php#L82-L89 | train |
Innmind/Compose | src/ContainerBuilder/Cache.php | Cache.onChange | public static function onChange(PathInterface $cache, Loader $load = null): self
{
$self = new self($cache, $load);
$self->debug = true;
return $self;
} | php | public static function onChange(PathInterface $cache, Loader $load = null): self
{
$self = new self($cache, $load);
$self->debug = true;
return $self;
} | [
"public",
"static",
"function",
"onChange",
"(",
"PathInterface",
"$",
"cache",
",",
"Loader",
"$",
"load",
"=",
"null",
")",
":",
"self",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
"$",
"cache",
",",
"$",
"load",
")",
";",
"$",
"self",
"->",
"debug",
"=",
"true",
";",
"return",
"$",
"self",
";",
"}"
]
| The cached container will be recompiled if the definition file has changed
since the last compilation | [
"The",
"cached",
"container",
"will",
"be",
"recompiled",
"if",
"the",
"definition",
"file",
"has",
"changed",
"since",
"the",
"last",
"compilation"
]
| 1a833d7ba2f6248e9c472c00cd7aca041c1a2ba9 | https://github.com/Innmind/Compose/blob/1a833d7ba2f6248e9c472c00cd7aca041c1a2ba9/src/ContainerBuilder/Cache.php#L39-L45 | train |
Sectorr/Core | Sectorr/Core/App.php | App.boot | public function boot()
{
session_start();
$this->registerWhoops();
$route = (empty($_REQUEST['_']) ? '/' : htmlspecialchars($_REQUEST['_']));
require_once(PATH . '/app/routes.php');
return Route::execute($route);
} | php | public function boot()
{
session_start();
$this->registerWhoops();
$route = (empty($_REQUEST['_']) ? '/' : htmlspecialchars($_REQUEST['_']));
require_once(PATH . '/app/routes.php');
return Route::execute($route);
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"session_start",
"(",
")",
";",
"$",
"this",
"->",
"registerWhoops",
"(",
")",
";",
"$",
"route",
"=",
"(",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'_'",
"]",
")",
"?",
"'/'",
":",
"htmlspecialchars",
"(",
"$",
"_REQUEST",
"[",
"'_'",
"]",
")",
")",
";",
"require_once",
"(",
"PATH",
".",
"'/app/routes.php'",
")",
";",
"return",
"Route",
"::",
"execute",
"(",
"$",
"route",
")",
";",
"}"
]
| Boot Sectorr application. | [
"Boot",
"Sectorr",
"application",
"."
]
| 31df852dc6cc61642b0b87d9f0ae56c8e7da5a27 | https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/App.php#L20-L30 | train |
Sectorr/Core | Sectorr/Core/App.php | App.registerWhoops | protected function registerWhoops()
{
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
} | php | protected function registerWhoops()
{
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
} | [
"protected",
"function",
"registerWhoops",
"(",
")",
"{",
"$",
"whoops",
"=",
"new",
"\\",
"Whoops",
"\\",
"Run",
";",
"$",
"whoops",
"->",
"pushHandler",
"(",
"new",
"\\",
"Whoops",
"\\",
"Handler",
"\\",
"PrettyPageHandler",
")",
";",
"$",
"whoops",
"->",
"register",
"(",
")",
";",
"}"
]
| Register Whoops error handler. | [
"Register",
"Whoops",
"error",
"handler",
"."
]
| 31df852dc6cc61642b0b87d9f0ae56c8e7da5a27 | https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/App.php#L35-L40 | train |
staticka/staticka | src/Filter/HtmlMinifier.php | HtmlMinifier.childbearing | protected function childbearing(\DOMNode $node)
{
if ($node->hasChildNodes())
{
foreach ($node->childNodes as $child)
{
if ($child->nodeType === XML_ELEMENT_NODE)
{
return true;
}
}
}
return false;
} | php | protected function childbearing(\DOMNode $node)
{
if ($node->hasChildNodes())
{
foreach ($node->childNodes as $child)
{
if ($child->nodeType === XML_ELEMENT_NODE)
{
return true;
}
}
}
return false;
} | [
"protected",
"function",
"childbearing",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"hasChildNodes",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"node",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"nodeType",
"===",
"XML_ELEMENT_NODE",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Checks if a specified node has children.
@param \DOMNode $node
@return boolean | [
"Checks",
"if",
"a",
"specified",
"node",
"has",
"children",
"."
]
| 6e3b814c391ed03b0bd409803e11579bae677ce4 | https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Filter/HtmlMinifier.php#L52-L66 | train |
staticka/staticka | src/Filter/HtmlMinifier.php | HtmlMinifier.minify | protected function minify($html)
{
$html = str_replace('<?xml encoding="UTF-8">', '', $html);
$html = trim(preg_replace('/\s+/', ' ', $html));
$html = str_replace('> <', '><', $html);
return str_replace(array(' />', '/>'), '>', $html);
} | php | protected function minify($html)
{
$html = str_replace('<?xml encoding="UTF-8">', '', $html);
$html = trim(preg_replace('/\s+/', ' ', $html));
$html = str_replace('> <', '><', $html);
return str_replace(array(' />', '/>'), '>', $html);
} | [
"protected",
"function",
"minify",
"(",
"$",
"html",
")",
"{",
"$",
"html",
"=",
"str_replace",
"(",
"'<?xml encoding=\"UTF-8\">'",
",",
"''",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"trim",
"(",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"$",
"html",
")",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'> <'",
",",
"'><'",
",",
"$",
"html",
")",
";",
"return",
"str_replace",
"(",
"array",
"(",
"' />'",
",",
"'/>'",
")",
",",
"'>'",
",",
"$",
"html",
")",
";",
"}"
]
| Minifies the specified HTML.
@param string $html
@return string | [
"Minifies",
"the",
"specified",
"HTML",
"."
]
| 6e3b814c391ed03b0bd409803e11579bae677ce4 | https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Filter/HtmlMinifier.php#L74-L83 | train |
staticka/staticka | src/Filter/HtmlMinifier.php | HtmlMinifier.remove | protected function remove(\DOMNodeList $elements)
{
$encoded = array('textarea', 'code');
foreach ($elements as $element)
{
if ($this->childbearing($element))
{
continue;
}
$output = (string) $element->nodeValue;
if (in_array($element->nodeName, $encoded))
{
$output = htmlentities($element->nodeValue);
}
array_push($this->data, (string) $output);
$current = count($this->data) - 1;
$element->nodeValue = '$' . $current . '$';
}
} | php | protected function remove(\DOMNodeList $elements)
{
$encoded = array('textarea', 'code');
foreach ($elements as $element)
{
if ($this->childbearing($element))
{
continue;
}
$output = (string) $element->nodeValue;
if (in_array($element->nodeName, $encoded))
{
$output = htmlentities($element->nodeValue);
}
array_push($this->data, (string) $output);
$current = count($this->data) - 1;
$element->nodeValue = '$' . $current . '$';
}
} | [
"protected",
"function",
"remove",
"(",
"\\",
"DOMNodeList",
"$",
"elements",
")",
"{",
"$",
"encoded",
"=",
"array",
"(",
"'textarea'",
",",
"'code'",
")",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"childbearing",
"(",
"$",
"element",
")",
")",
"{",
"continue",
";",
"}",
"$",
"output",
"=",
"(",
"string",
")",
"$",
"element",
"->",
"nodeValue",
";",
"if",
"(",
"in_array",
"(",
"$",
"element",
"->",
"nodeName",
",",
"$",
"encoded",
")",
")",
"{",
"$",
"output",
"=",
"htmlentities",
"(",
"$",
"element",
"->",
"nodeValue",
")",
";",
"}",
"array_push",
"(",
"$",
"this",
"->",
"data",
",",
"(",
"string",
")",
"$",
"output",
")",
";",
"$",
"current",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
")",
"-",
"1",
";",
"$",
"element",
"->",
"nodeValue",
"=",
"'$'",
".",
"$",
"current",
".",
"'$'",
";",
"}",
"}"
]
| Removes the content of single elements.
@param \DOMNodeList $elements
@return void | [
"Removes",
"the",
"content",
"of",
"single",
"elements",
"."
]
| 6e3b814c391ed03b0bd409803e11579bae677ce4 | https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Filter/HtmlMinifier.php#L91-L115 | train |
staticka/staticka | src/Filter/HtmlMinifier.php | HtmlMinifier.restore | protected function restore($html)
{
foreach ($this->data as $index => $item)
{
$key = (string) '$' . $index . '$';
$html = str_replace($key, $item, $html);
}
return (string) $html;
} | php | protected function restore($html)
{
foreach ($this->data as $index => $item)
{
$key = (string) '$' . $index . '$';
$html = str_replace($key, $item, $html);
}
return (string) $html;
} | [
"protected",
"function",
"restore",
"(",
"$",
"html",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"index",
"=>",
"$",
"item",
")",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"'$'",
".",
"$",
"index",
".",
"'$'",
";",
"$",
"html",
"=",
"str_replace",
"(",
"$",
"key",
",",
"$",
"item",
",",
"$",
"html",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"html",
";",
"}"
]
| Restores the data into the minified HTML.
@param string $html
@return string | [
"Restores",
"the",
"data",
"into",
"the",
"minified",
"HTML",
"."
]
| 6e3b814c391ed03b0bd409803e11579bae677ce4 | https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Filter/HtmlMinifier.php#L123-L133 | train |
chalasr/RCHCapistranoBundle | Command/Deploy/RunCommand.php | RunCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$rootDir = $this->getRootDir();
$stagingName = $input->getOption('staging-name');
$stagingPath = $this->getCapistranoDir().'/deploy/';
$staging = sprintf('%s%s.rb', $stagingPath, $stagingName);
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
$this->sayWelcome($output);
if (false === file_exists($staging)) {
$yamlStaging = sprintf('%s/config/rch/staging/%s.yml', $rootDir, $stagingName);
if (false === file_exists($yamlStaging)) {
throw new InvalidArgumentException(sprintf('Unable to find staging with name %s', $stagingName));
}
$params = $this->parseYamlStaging($yamlStaging);
$generator = new StagingGenerator($params, $stagingPath, $stagingName);
$this->generate($generator);
}
$builder = new ProcessBuilder(['bundle', 'exec', 'cap', $stagingName, 'deploy']);
$builder->setTimeout(null);
$process = $builder->getProcess();
$process->run(function ($type, $buffer) use ($output) {
$output->write(sprintf('<info>%s</info>', $buffer));
});
if (!$process->isSuccessful()) {
$output->writeln(PHP_EOL);
$output->writeln('<error>Deployment failed</error>');
$output->writeln(
sprintf('<error>Execute <comment>cap %s deploy --trace</comment> for more details</error>', $stagingName)
);
return $process->getExitCode();
}
return $output->writeln(
'<info>Project successfully deployed !</info>'
);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$rootDir = $this->getRootDir();
$stagingName = $input->getOption('staging-name');
$stagingPath = $this->getCapistranoDir().'/deploy/';
$staging = sprintf('%s%s.rb', $stagingPath, $stagingName);
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
$this->sayWelcome($output);
if (false === file_exists($staging)) {
$yamlStaging = sprintf('%s/config/rch/staging/%s.yml', $rootDir, $stagingName);
if (false === file_exists($yamlStaging)) {
throw new InvalidArgumentException(sprintf('Unable to find staging with name %s', $stagingName));
}
$params = $this->parseYamlStaging($yamlStaging);
$generator = new StagingGenerator($params, $stagingPath, $stagingName);
$this->generate($generator);
}
$builder = new ProcessBuilder(['bundle', 'exec', 'cap', $stagingName, 'deploy']);
$builder->setTimeout(null);
$process = $builder->getProcess();
$process->run(function ($type, $buffer) use ($output) {
$output->write(sprintf('<info>%s</info>', $buffer));
});
if (!$process->isSuccessful()) {
$output->writeln(PHP_EOL);
$output->writeln('<error>Deployment failed</error>');
$output->writeln(
sprintf('<error>Execute <comment>cap %s deploy --trace</comment> for more details</error>', $stagingName)
);
return $process->getExitCode();
}
return $output->writeln(
'<info>Project successfully deployed !</info>'
);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"rootDir",
"=",
"$",
"this",
"->",
"getRootDir",
"(",
")",
";",
"$",
"stagingName",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'staging-name'",
")",
";",
"$",
"stagingPath",
"=",
"$",
"this",
"->",
"getCapistranoDir",
"(",
")",
".",
"'/deploy/'",
";",
"$",
"staging",
"=",
"sprintf",
"(",
"'%s%s.rb'",
",",
"$",
"stagingPath",
",",
"$",
"stagingName",
")",
";",
"$",
"output",
"->",
"setVerbosity",
"(",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"$",
"this",
"->",
"sayWelcome",
"(",
"$",
"output",
")",
";",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"staging",
")",
")",
"{",
"$",
"yamlStaging",
"=",
"sprintf",
"(",
"'%s/config/rch/staging/%s.yml'",
",",
"$",
"rootDir",
",",
"$",
"stagingName",
")",
";",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"yamlStaging",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unable to find staging with name %s'",
",",
"$",
"stagingName",
")",
")",
";",
"}",
"$",
"params",
"=",
"$",
"this",
"->",
"parseYamlStaging",
"(",
"$",
"yamlStaging",
")",
";",
"$",
"generator",
"=",
"new",
"StagingGenerator",
"(",
"$",
"params",
",",
"$",
"stagingPath",
",",
"$",
"stagingName",
")",
";",
"$",
"this",
"->",
"generate",
"(",
"$",
"generator",
")",
";",
"}",
"$",
"builder",
"=",
"new",
"ProcessBuilder",
"(",
"[",
"'bundle'",
",",
"'exec'",
",",
"'cap'",
",",
"$",
"stagingName",
",",
"'deploy'",
"]",
")",
";",
"$",
"builder",
"->",
"setTimeout",
"(",
"null",
")",
";",
"$",
"process",
"=",
"$",
"builder",
"->",
"getProcess",
"(",
")",
";",
"$",
"process",
"->",
"run",
"(",
"function",
"(",
"$",
"type",
",",
"$",
"buffer",
")",
"use",
"(",
"$",
"output",
")",
"{",
"$",
"output",
"->",
"write",
"(",
"sprintf",
"(",
"'<info>%s</info>'",
",",
"$",
"buffer",
")",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"PHP_EOL",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'<error>Deployment failed</error>'",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<error>Execute <comment>cap %s deploy --trace</comment> for more details</error>'",
",",
"$",
"stagingName",
")",
")",
";",
"return",
"$",
"process",
"->",
"getExitCode",
"(",
")",
";",
"}",
"return",
"$",
"output",
"->",
"writeln",
"(",
"'<info>Project successfully deployed !</info>'",
")",
";",
"}"
]
| Deploys application.
@param InputInterface $input
@param OutputInterface $output | [
"Deploys",
"application",
"."
]
| c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Command/Deploy/RunCommand.php#L52-L96 | train |
ciims/ciims-modules-api | controllers/CardController.php | CardController.actionIndex | public function actionIndex()
{
// Fetch all the dashboard cards for the current user
$cards = $this->loadDashboardCards();
$cardData = array();
// Find all the metadata for those cards and load them
foreach ($cards->value as $id=>$url)
{
$metadata = $this->loadCardDetailsModel($id);
$cardData[$id] = $metadata->value;
}
return array(
'cards' => $cards->value,
'cardData' => $cardData
);
} | php | public function actionIndex()
{
// Fetch all the dashboard cards for the current user
$cards = $this->loadDashboardCards();
$cardData = array();
// Find all the metadata for those cards and load them
foreach ($cards->value as $id=>$url)
{
$metadata = $this->loadCardDetailsModel($id);
$cardData[$id] = $metadata->value;
}
return array(
'cards' => $cards->value,
'cardData' => $cardData
);
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"// Fetch all the dashboard cards for the current user\r",
"$",
"cards",
"=",
"$",
"this",
"->",
"loadDashboardCards",
"(",
")",
";",
"$",
"cardData",
"=",
"array",
"(",
")",
";",
"// Find all the metadata for those cards and load them\r",
"foreach",
"(",
"$",
"cards",
"->",
"value",
"as",
"$",
"id",
"=>",
"$",
"url",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"loadCardDetailsModel",
"(",
"$",
"id",
")",
";",
"$",
"cardData",
"[",
"$",
"id",
"]",
"=",
"$",
"metadata",
"->",
"value",
";",
"}",
"return",
"array",
"(",
"'cards'",
"=>",
"$",
"cards",
"->",
"value",
",",
"'cardData'",
"=>",
"$",
"cardData",
")",
";",
"}"
]
| Retrieves all the dashboard cards for the current user | [
"Retrieves",
"all",
"the",
"dashboard",
"cards",
"for",
"the",
"current",
"user"
]
| 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/CardController.php#L22-L39 | train |
ciims/ciims-modules-api | controllers/CardController.php | CardController.actionIndexPost | public function actionIndexPost()
{
$cards = $this->loadDashboardCards();
$id = Cii::get($_POST, 'id', false);
$url = Cii::get($_POST, 'url', false);
$data = Cii::get($_POST, 'details', false);
if ($id === false || $url === false || $data == false)
throw new CHttpException(400, Yii::t('Api.card', 'Invalid card data'));
$values = $cards->value;
$values[$id] = $url;
$cards->value = CJSON::encode($values);
$newCard = $this->loadCardDetailsModel($id);
$newCard->value = CJSON::encode($data);
// If we saved the card metadata
if ($newCard->save())
{
// Try to save the card to the dashboard
if ($cards->save())
return true;
// If that fails, delete the new card data, and throw the 400 error below
$newCard->delete();
}
throw new CHttpException(500, Yii::t('Api.card', 'Card could not be saved.'));
} | php | public function actionIndexPost()
{
$cards = $this->loadDashboardCards();
$id = Cii::get($_POST, 'id', false);
$url = Cii::get($_POST, 'url', false);
$data = Cii::get($_POST, 'details', false);
if ($id === false || $url === false || $data == false)
throw new CHttpException(400, Yii::t('Api.card', 'Invalid card data'));
$values = $cards->value;
$values[$id] = $url;
$cards->value = CJSON::encode($values);
$newCard = $this->loadCardDetailsModel($id);
$newCard->value = CJSON::encode($data);
// If we saved the card metadata
if ($newCard->save())
{
// Try to save the card to the dashboard
if ($cards->save())
return true;
// If that fails, delete the new card data, and throw the 400 error below
$newCard->delete();
}
throw new CHttpException(500, Yii::t('Api.card', 'Card could not be saved.'));
} | [
"public",
"function",
"actionIndexPost",
"(",
")",
"{",
"$",
"cards",
"=",
"$",
"this",
"->",
"loadDashboardCards",
"(",
")",
";",
"$",
"id",
"=",
"Cii",
"::",
"get",
"(",
"$",
"_POST",
",",
"'id'",
",",
"false",
")",
";",
"$",
"url",
"=",
"Cii",
"::",
"get",
"(",
"$",
"_POST",
",",
"'url'",
",",
"false",
")",
";",
"$",
"data",
"=",
"Cii",
"::",
"get",
"(",
"$",
"_POST",
",",
"'details'",
",",
"false",
")",
";",
"if",
"(",
"$",
"id",
"===",
"false",
"||",
"$",
"url",
"===",
"false",
"||",
"$",
"data",
"==",
"false",
")",
"throw",
"new",
"CHttpException",
"(",
"400",
",",
"Yii",
"::",
"t",
"(",
"'Api.card'",
",",
"'Invalid card data'",
")",
")",
";",
"$",
"values",
"=",
"$",
"cards",
"->",
"value",
";",
"$",
"values",
"[",
"$",
"id",
"]",
"=",
"$",
"url",
";",
"$",
"cards",
"->",
"value",
"=",
"CJSON",
"::",
"encode",
"(",
"$",
"values",
")",
";",
"$",
"newCard",
"=",
"$",
"this",
"->",
"loadCardDetailsModel",
"(",
"$",
"id",
")",
";",
"$",
"newCard",
"->",
"value",
"=",
"CJSON",
"::",
"encode",
"(",
"$",
"data",
")",
";",
"// If we saved the card metadata\r",
"if",
"(",
"$",
"newCard",
"->",
"save",
"(",
")",
")",
"{",
"// Try to save the card to the dashboard\r",
"if",
"(",
"$",
"cards",
"->",
"save",
"(",
")",
")",
"return",
"true",
";",
"// If that fails, delete the new card data, and throw the 400 error below\r",
"$",
"newCard",
"->",
"delete",
"(",
")",
";",
"}",
"throw",
"new",
"CHttpException",
"(",
"500",
",",
"Yii",
"::",
"t",
"(",
"'Api.card'",
",",
"'Card could not be saved.'",
")",
")",
";",
"}"
]
| Installs a new card to the dashboard cards, and adds the appropriate settings to the database
@return boolean | [
"Installs",
"a",
"new",
"card",
"to",
"the",
"dashboard",
"cards",
"and",
"adds",
"the",
"appropriate",
"settings",
"to",
"the",
"database"
]
| 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/CardController.php#L45-L74 | train |
ciims/ciims-modules-api | controllers/CardController.php | CardController.actionIndexDelete | public function actionIndexDelete($id=NULL)
{
$cards = $this->loadDashboardCards();
$value = $cards->value;
if (array_key_exists($id, $value))
unset($value[$id]);
$cards->value = CJSON::encode($value);
if ($cards->save())
{
$newCard = $this->loadCardDetailsModel($id);
if ($newCard->delete())
return true;
}
throw new CHttpException(500, Yii::t('Api.card', 'Card could not be saved.'));
} | php | public function actionIndexDelete($id=NULL)
{
$cards = $this->loadDashboardCards();
$value = $cards->value;
if (array_key_exists($id, $value))
unset($value[$id]);
$cards->value = CJSON::encode($value);
if ($cards->save())
{
$newCard = $this->loadCardDetailsModel($id);
if ($newCard->delete())
return true;
}
throw new CHttpException(500, Yii::t('Api.card', 'Card could not be saved.'));
} | [
"public",
"function",
"actionIndexDelete",
"(",
"$",
"id",
"=",
"NULL",
")",
"{",
"$",
"cards",
"=",
"$",
"this",
"->",
"loadDashboardCards",
"(",
")",
";",
"$",
"value",
"=",
"$",
"cards",
"->",
"value",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"value",
")",
")",
"unset",
"(",
"$",
"value",
"[",
"$",
"id",
"]",
")",
";",
"$",
"cards",
"->",
"value",
"=",
"CJSON",
"::",
"encode",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"cards",
"->",
"save",
"(",
")",
")",
"{",
"$",
"newCard",
"=",
"$",
"this",
"->",
"loadCardDetailsModel",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"newCard",
"->",
"delete",
"(",
")",
")",
"return",
"true",
";",
"}",
"throw",
"new",
"CHttpException",
"(",
"500",
",",
"Yii",
"::",
"t",
"(",
"'Api.card'",
",",
"'Card could not be saved.'",
")",
")",
";",
"}"
]
| Deletes a card from the dashboard
@param string $id The card ID
@return boolean | [
"Deletes",
"a",
"card",
"from",
"the",
"dashboard"
]
| 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/CardController.php#L81-L98 | train |
ciims/ciims-modules-api | controllers/CardController.php | CardController.loadDashboardCards | private function loadDashboardCards()
{
// Fetch all the dashboard cards for the current user
$model = UserMetadata::model()->getPrototype('UserMetadata', array(
'user_id' => $this->user->id,
'key' => 'dashboard_cards'
), array('value' => '{}'));
$model->value = CJSON::decode($model->value);
return $model;
} | php | private function loadDashboardCards()
{
// Fetch all the dashboard cards for the current user
$model = UserMetadata::model()->getPrototype('UserMetadata', array(
'user_id' => $this->user->id,
'key' => 'dashboard_cards'
), array('value' => '{}'));
$model->value = CJSON::decode($model->value);
return $model;
} | [
"private",
"function",
"loadDashboardCards",
"(",
")",
"{",
"// Fetch all the dashboard cards for the current user\r",
"$",
"model",
"=",
"UserMetadata",
"::",
"model",
"(",
")",
"->",
"getPrototype",
"(",
"'UserMetadata'",
",",
"array",
"(",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"id",
",",
"'key'",
"=>",
"'dashboard_cards'",
")",
",",
"array",
"(",
"'value'",
"=>",
"'{}'",
")",
")",
";",
"$",
"model",
"->",
"value",
"=",
"CJSON",
"::",
"decode",
"(",
"$",
"model",
"->",
"value",
")",
";",
"return",
"$",
"model",
";",
"}"
]
| Loads all the dashboard cards, in order for this particular user
@return UserMetadata | [
"Loads",
"all",
"the",
"dashboard",
"cards",
"in",
"order",
"for",
"this",
"particular",
"user"
]
| 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/CardController.php#L156-L167 | train |
ciims/ciims-modules-api | controllers/CardController.php | CardController.loadCardDetailsModel | private function loadCardDetailsModel($id=NULL)
{
if ($id == NULL)
throw new CHttpException(400, Yii::t('Api.card', 'Missing card ID'));
$model = UserMetadata::model()->getPrototype('UserMetadata', array(
'user_id' => $this->user->id,
'key' => $id.'_card_settings'
), array('value' => '{}'));
$model->value = CJSON::decode($model->value);
return $model;
} | php | private function loadCardDetailsModel($id=NULL)
{
if ($id == NULL)
throw new CHttpException(400, Yii::t('Api.card', 'Missing card ID'));
$model = UserMetadata::model()->getPrototype('UserMetadata', array(
'user_id' => $this->user->id,
'key' => $id.'_card_settings'
), array('value' => '{}'));
$model->value = CJSON::decode($model->value);
return $model;
} | [
"private",
"function",
"loadCardDetailsModel",
"(",
"$",
"id",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"id",
"==",
"NULL",
")",
"throw",
"new",
"CHttpException",
"(",
"400",
",",
"Yii",
"::",
"t",
"(",
"'Api.card'",
",",
"'Missing card ID'",
")",
")",
";",
"$",
"model",
"=",
"UserMetadata",
"::",
"model",
"(",
")",
"->",
"getPrototype",
"(",
"'UserMetadata'",
",",
"array",
"(",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"id",
",",
"'key'",
"=>",
"$",
"id",
".",
"'_card_settings'",
")",
",",
"array",
"(",
"'value'",
"=>",
"'{}'",
")",
")",
";",
"$",
"model",
"->",
"value",
"=",
"CJSON",
"::",
"decode",
"(",
"$",
"model",
"->",
"value",
")",
";",
"return",
"$",
"model",
";",
"}"
]
| Returns a UserMetadata Object for a given card, containing the properties and settings for that card.
@param string $id The card ID
@return UserMetadata | [
"Returns",
"a",
"UserMetadata",
"Object",
"for",
"a",
"given",
"card",
"containing",
"the",
"properties",
"and",
"settings",
"for",
"that",
"card",
"."
]
| 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/CardController.php#L174-L187 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.setView | final public function setView(View $view) {
$this->view = $view;
$this->publicAssetsPath = ROOT . 'public' . DIRECTORY_SEPARATOR . '.assets' . DIRECTORY_SEPARATOR;
return $this;
} | php | final public function setView(View $view) {
$this->view = $view;
$this->publicAssetsPath = ROOT . 'public' . DIRECTORY_SEPARATOR . '.assets' . DIRECTORY_SEPARATOR;
return $this;
} | [
"final",
"public",
"function",
"setView",
"(",
"View",
"$",
"view",
")",
"{",
"$",
"this",
"->",
"view",
"=",
"$",
"view",
";",
"$",
"this",
"->",
"publicAssetsPath",
"=",
"ROOT",
".",
"'public'",
".",
"DIRECTORY_SEPARATOR",
".",
"'.assets'",
".",
"DIRECTORY_SEPARATOR",
";",
"return",
"$",
"this",
";",
"}"
]
| Sets the view to render
@param View $view
@return Renderer | [
"Sets",
"the",
"view",
"to",
"render"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L42-L46 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.module | protected function module($check = null) {
$module = Util::camelToHyphen($this->view->getModule());
return $check ? ($check == $module) : $module;
} | php | protected function module($check = null) {
$module = Util::camelToHyphen($this->view->getModule());
return $check ? ($check == $module) : $module;
} | [
"protected",
"function",
"module",
"(",
"$",
"check",
"=",
"null",
")",
"{",
"$",
"module",
"=",
"Util",
"::",
"camelToHyphen",
"(",
"$",
"this",
"->",
"view",
"->",
"getModule",
"(",
")",
")",
";",
"return",
"$",
"check",
"?",
"(",
"$",
"check",
"==",
"$",
"module",
")",
":",
"$",
"module",
";",
"}"
]
| Fetches the current module
@param mixed $check Compare the module with this and return boolean if
they are the same
@return mixed | [
"Fetches",
"the",
"current",
"module"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L62-L65 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.controller | protected function controller($check = null) {
$controller = Util::camelToHyphen($this->view->getController()->getClassName());
return $check ? ($check == $controller) : $controller;
} | php | protected function controller($check = null) {
$controller = Util::camelToHyphen($this->view->getController()->getClassName());
return $check ? ($check == $controller) : $controller;
} | [
"protected",
"function",
"controller",
"(",
"$",
"check",
"=",
"null",
")",
"{",
"$",
"controller",
"=",
"Util",
"::",
"camelToHyphen",
"(",
"$",
"this",
"->",
"view",
"->",
"getController",
"(",
")",
"->",
"getClassName",
"(",
")",
")",
";",
"return",
"$",
"check",
"?",
"(",
"$",
"check",
"==",
"$",
"controller",
")",
":",
"$",
"controller",
";",
"}"
]
| Fetches the current controller
@param mixed $check Compare the controller with this and return boolean if
they are the same
@return mixed | [
"Fetches",
"the",
"current",
"controller"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L73-L76 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.params | protected function params($check = null) {
$params = $this->view->getParams();
if ($check) {
if (is_array($check)) {
$inter = array_intersect($check, $params);
return (count($inter) === count($check));
}
else {
return in_array($check, $params);
}
}
return $params;
} | php | protected function params($check = null) {
$params = $this->view->getParams();
if ($check) {
if (is_array($check)) {
$inter = array_intersect($check, $params);
return (count($inter) === count($check));
}
else {
return in_array($check, $params);
}
}
return $params;
} | [
"protected",
"function",
"params",
"(",
"$",
"check",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"view",
"->",
"getParams",
"(",
")",
";",
"if",
"(",
"$",
"check",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"check",
")",
")",
"{",
"$",
"inter",
"=",
"array_intersect",
"(",
"$",
"check",
",",
"$",
"params",
")",
";",
"return",
"(",
"count",
"(",
"$",
"inter",
")",
"===",
"count",
"(",
"$",
"check",
")",
")",
";",
"}",
"else",
"{",
"return",
"in_array",
"(",
"$",
"check",
",",
"$",
"params",
")",
";",
"}",
"}",
"return",
"$",
"params",
";",
"}"
]
| Fetches the parameters set to the current action
@param mixed $check Compare the parameters with this and return boolean.
If array, return TRUE if all values are in parameters. If not array,
return TRUE if exists in parameters
@return mixed | [
"Fetches",
"the",
"parameters",
"set",
"to",
"the",
"current",
"action"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L96-L108 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.loadLayout | final public function loadLayout($layoutName, array $variables = array(), $fromTheme = false) {
$dsLayout = $this->getLayoutPath($layoutName, $fromTheme);
if (!$dsLayout)
return '';
foreach ($variables as $var => $value) {
$$var = $value;
}
include $dsLayout;
} | php | final public function loadLayout($layoutName, array $variables = array(), $fromTheme = false) {
$dsLayout = $this->getLayoutPath($layoutName, $fromTheme);
if (!$dsLayout)
return '';
foreach ($variables as $var => $value) {
$$var = $value;
}
include $dsLayout;
} | [
"final",
"public",
"function",
"loadLayout",
"(",
"$",
"layoutName",
",",
"array",
"$",
"variables",
"=",
"array",
"(",
")",
",",
"$",
"fromTheme",
"=",
"false",
")",
"{",
"$",
"dsLayout",
"=",
"$",
"this",
"->",
"getLayoutPath",
"(",
"$",
"layoutName",
",",
"$",
"fromTheme",
")",
";",
"if",
"(",
"!",
"$",
"dsLayout",
")",
"return",
"''",
";",
"foreach",
"(",
"$",
"variables",
"as",
"$",
"var",
"=>",
"$",
"value",
")",
"{",
"$",
"$",
"var",
"=",
"$",
"value",
";",
"}",
"include",
"$",
"dsLayout",
";",
"}"
]
| Loads a layout
@param string $layoutName Without the extension
@param array $variables Array of variables to pass into the layout
[name => value] with "dsLayout" as an exemption of name
@param boolean $fromTheme Indicates whether to get theme layouts or
search through modules
@return string | [
"Loads",
"a",
"layout"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L148-L157 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.getLayoutPath | private function getLayoutPath($layout = null, $fromTheme = false) {
$layout = ($layout === null) ? $this->view->getController()->getLayout() : $layout;
if (!$layout)
return false;
if (!$fromTheme && is_readable(MODULES . $this->view->getModule() . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . $layout .
'.phtml'))
return MODULES . $this->view->getModule() . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . $layout .
'.phtml';
elseif (is_readable(THEMES . engineGet('config', 'defaults', 'theme') .
DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . $layout . '.phtml'))
return THEMES . engineGet('config', 'defaults', 'theme') . DIRECTORY_SEPARATOR .
'layouts' . DIRECTORY_SEPARATOR . $layout . '.phtml';
else {
throw new Exception('Layout "' . $layout . '" not found both at the module and theme levels');
}
} | php | private function getLayoutPath($layout = null, $fromTheme = false) {
$layout = ($layout === null) ? $this->view->getController()->getLayout() : $layout;
if (!$layout)
return false;
if (!$fromTheme && is_readable(MODULES . $this->view->getModule() . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . $layout .
'.phtml'))
return MODULES . $this->view->getModule() . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . $layout .
'.phtml';
elseif (is_readable(THEMES . engineGet('config', 'defaults', 'theme') .
DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . $layout . '.phtml'))
return THEMES . engineGet('config', 'defaults', 'theme') . DIRECTORY_SEPARATOR .
'layouts' . DIRECTORY_SEPARATOR . $layout . '.phtml';
else {
throw new Exception('Layout "' . $layout . '" not found both at the module and theme levels');
}
} | [
"private",
"function",
"getLayoutPath",
"(",
"$",
"layout",
"=",
"null",
",",
"$",
"fromTheme",
"=",
"false",
")",
"{",
"$",
"layout",
"=",
"(",
"$",
"layout",
"===",
"null",
")",
"?",
"$",
"this",
"->",
"view",
"->",
"getController",
"(",
")",
"->",
"getLayout",
"(",
")",
":",
"$",
"layout",
";",
"if",
"(",
"!",
"$",
"layout",
")",
"return",
"false",
";",
"if",
"(",
"!",
"$",
"fromTheme",
"&&",
"is_readable",
"(",
"MODULES",
".",
"$",
"this",
"->",
"view",
"->",
"getModule",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'View'",
".",
"DIRECTORY_SEPARATOR",
".",
"'layouts'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"layout",
".",
"'.phtml'",
")",
")",
"return",
"MODULES",
".",
"$",
"this",
"->",
"view",
"->",
"getModule",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'View'",
".",
"DIRECTORY_SEPARATOR",
".",
"'layouts'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"layout",
".",
"'.phtml'",
";",
"elseif",
"(",
"is_readable",
"(",
"THEMES",
".",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'theme'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'layouts'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"layout",
".",
"'.phtml'",
")",
")",
"return",
"THEMES",
".",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'theme'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'layouts'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"layout",
".",
"'.phtml'",
";",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Layout \"'",
".",
"$",
"layout",
".",
"'\" not found both at the module and theme levels'",
")",
";",
"}",
"}"
]
| Fetches the layout path
@param string|null $layout
@return boolean
@throws Exception | [
"Fetches",
"the",
"layout",
"path"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L165-L183 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.render | final public function render($content = null) {
if ($content === null) {
foreach ($this->view->getVariables() as $var => $val) {
$$var = $val;
}
$viewFile = $this->view->getViewFile();
if (!is_readable(MODULES . $viewFile[0] . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR .
$viewFile[1] . DIRECTORY_SEPARATOR . $viewFile[2] . '.phtml'))
throw new Exception('View layout "' . join(DIRECTORY_SEPARATOR, $viewFile) . '" not found');
// include action view
ob_start();
include_once MODULES . $viewFile[0] . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR .
$viewFile[1] . DIRECTORY_SEPARATOR . $viewFile[2] . '.phtml';
$content = ob_get_clean();
if (!$this->view->isPartial()) {
// include controller layout
$controllerLayout = self::getLayoutPath();
if ($controllerLayout) {
ob_start();
include_once $controllerLayout;
$content = ob_get_clean();
}
else if (engineGet('config', 'defaults', 'defaultLayout', false)) {
ob_start();
$this->loadLayout(engineGet('config', 'defaults', 'defaultLayout'), array('content' => $content));
$content = ob_get_clean();
}
else {
throw new Exception('No layout found.');
}
}
}
else {
if (!$errorLayout = engineGet('config', 'modules', $this->view->getModule(), 'defaults', 'errorLayout', false)) {
if (!$errorLayout = engineGet('config', 'defaults', 'errorLayout', false)) {
throw new Exception('Error layout not found', true);
}
}
if (is_array($errorLayout)) {
if (!array_key_exists('guest', $errorLayout))
throw new Exception('Error layout not found for "guest"', true);
if (array_key_exists($this->userIdentity()->getUser()->getRole(), $errorLayout))
$errorLayout = $errorLayout[$this->userIdentity()->getUser()->getRole()];
else
$errorLayout = $errorLayout['guest'];
}
ob_start();
$this->loadLayout($errorLayout, array_merge(array('content' => $content), $this->view->getVariables()));
$content = ob_get_clean();
}
echo($content);
} | php | final public function render($content = null) {
if ($content === null) {
foreach ($this->view->getVariables() as $var => $val) {
$$var = $val;
}
$viewFile = $this->view->getViewFile();
if (!is_readable(MODULES . $viewFile[0] . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR .
$viewFile[1] . DIRECTORY_SEPARATOR . $viewFile[2] . '.phtml'))
throw new Exception('View layout "' . join(DIRECTORY_SEPARATOR, $viewFile) . '" not found');
// include action view
ob_start();
include_once MODULES . $viewFile[0] . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR .
$viewFile[1] . DIRECTORY_SEPARATOR . $viewFile[2] . '.phtml';
$content = ob_get_clean();
if (!$this->view->isPartial()) {
// include controller layout
$controllerLayout = self::getLayoutPath();
if ($controllerLayout) {
ob_start();
include_once $controllerLayout;
$content = ob_get_clean();
}
else if (engineGet('config', 'defaults', 'defaultLayout', false)) {
ob_start();
$this->loadLayout(engineGet('config', 'defaults', 'defaultLayout'), array('content' => $content));
$content = ob_get_clean();
}
else {
throw new Exception('No layout found.');
}
}
}
else {
if (!$errorLayout = engineGet('config', 'modules', $this->view->getModule(), 'defaults', 'errorLayout', false)) {
if (!$errorLayout = engineGet('config', 'defaults', 'errorLayout', false)) {
throw new Exception('Error layout not found', true);
}
}
if (is_array($errorLayout)) {
if (!array_key_exists('guest', $errorLayout))
throw new Exception('Error layout not found for "guest"', true);
if (array_key_exists($this->userIdentity()->getUser()->getRole(), $errorLayout))
$errorLayout = $errorLayout[$this->userIdentity()->getUser()->getRole()];
else
$errorLayout = $errorLayout['guest'];
}
ob_start();
$this->loadLayout($errorLayout, array_merge(array('content' => $content), $this->view->getVariables()));
$content = ob_get_clean();
}
echo($content);
} | [
"final",
"public",
"function",
"render",
"(",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"content",
"===",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"view",
"->",
"getVariables",
"(",
")",
"as",
"$",
"var",
"=>",
"$",
"val",
")",
"{",
"$",
"$",
"var",
"=",
"$",
"val",
";",
"}",
"$",
"viewFile",
"=",
"$",
"this",
"->",
"view",
"->",
"getViewFile",
"(",
")",
";",
"if",
"(",
"!",
"is_readable",
"(",
"MODULES",
".",
"$",
"viewFile",
"[",
"0",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"'View'",
".",
"DIRECTORY_SEPARATOR",
".",
"'views'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"viewFile",
"[",
"1",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"viewFile",
"[",
"2",
"]",
".",
"'.phtml'",
")",
")",
"throw",
"new",
"Exception",
"(",
"'View layout \"'",
".",
"join",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"viewFile",
")",
".",
"'\" not found'",
")",
";",
"// include action view",
"ob_start",
"(",
")",
";",
"include_once",
"MODULES",
".",
"$",
"viewFile",
"[",
"0",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"'View'",
".",
"DIRECTORY_SEPARATOR",
".",
"'views'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"viewFile",
"[",
"1",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"viewFile",
"[",
"2",
"]",
".",
"'.phtml'",
";",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"view",
"->",
"isPartial",
"(",
")",
")",
"{",
"// include controller layout",
"$",
"controllerLayout",
"=",
"self",
"::",
"getLayoutPath",
"(",
")",
";",
"if",
"(",
"$",
"controllerLayout",
")",
"{",
"ob_start",
"(",
")",
";",
"include_once",
"$",
"controllerLayout",
";",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"}",
"else",
"if",
"(",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'defaultLayout'",
",",
"false",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"this",
"->",
"loadLayout",
"(",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'defaultLayout'",
")",
",",
"array",
"(",
"'content'",
"=>",
"$",
"content",
")",
")",
";",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'No layout found.'",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"errorLayout",
"=",
"engineGet",
"(",
"'config'",
",",
"'modules'",
",",
"$",
"this",
"->",
"view",
"->",
"getModule",
"(",
")",
",",
"'defaults'",
",",
"'errorLayout'",
",",
"false",
")",
")",
"{",
"if",
"(",
"!",
"$",
"errorLayout",
"=",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'errorLayout'",
",",
"false",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Error layout not found'",
",",
"true",
")",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"errorLayout",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'guest'",
",",
"$",
"errorLayout",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Error layout not found for \"guest\"'",
",",
"true",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"userIdentity",
"(",
")",
"->",
"getUser",
"(",
")",
"->",
"getRole",
"(",
")",
",",
"$",
"errorLayout",
")",
")",
"$",
"errorLayout",
"=",
"$",
"errorLayout",
"[",
"$",
"this",
"->",
"userIdentity",
"(",
")",
"->",
"getUser",
"(",
")",
"->",
"getRole",
"(",
")",
"]",
";",
"else",
"$",
"errorLayout",
"=",
"$",
"errorLayout",
"[",
"'guest'",
"]",
";",
"}",
"ob_start",
"(",
")",
";",
"$",
"this",
"->",
"loadLayout",
"(",
"$",
"errorLayout",
",",
"array_merge",
"(",
"array",
"(",
"'content'",
"=>",
"$",
"content",
")",
",",
"$",
"this",
"->",
"view",
"->",
"getVariables",
"(",
")",
")",
")",
";",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"}",
"echo",
"(",
"$",
"content",
")",
";",
"}"
]
| Renders the action content to the browser
@param string $content The error message if any
@throws Exception | [
"Renders",
"the",
"action",
"content",
"to",
"the",
"browser"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L198-L259 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.updateAssets | private function updateAssets($file) {
$modulesAssets = MODULES . $this->view->getModule() . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
$themeAssets = THEMES . engineGet('config', 'defaults', 'theme') .
DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
if (is_dir($modulesAssets) && is_readable($modulesAssets . $file)) {
$publicFile = $this->publicAssetsPath . $this->view->getModule() . DIRECTORY_SEPARATOR . $file;
if (!is_dir($modulesAssets . $file) && (!is_readable($publicFile) || $this->checkOutOfDate($publicFile, $modulesAssets . $file))) {
if (!is_dir(dirname($publicFile))) {
mkdir(dirname($publicFile), 0777, true);
}
copy($modulesAssets . $file, $publicFile);
}
else if (is_dir($modulesAssets . $file)) {
Util::copyDir($modulesAssets . $file, $publicFile);
}
}
else if (is_dir($themeAssets) && is_readable($themeAssets . $file)) {
$publicFile = $this->publicAssetsPath . engineGet('config', 'defaults', 'theme') . DIRECTORY_SEPARATOR . $file;
if (!is_dir($themeAssets . $file) && (!is_readable($publicFile) || $this->checkOutOfDate($publicFile, $themeAssets . $file))) {
if (!is_dir(dirname($publicFile))) {
mkdir(dirname($publicFile), 0777, true);
}
copy($themeAssets . $file, $publicFile);
}
else if (is_dir($themeAssets . $file)) {
Util::copyDir($themeAssets . $file, $publicFile);
}
}
else {
return false;
}
return true;
} | php | private function updateAssets($file) {
$modulesAssets = MODULES . $this->view->getModule() . DIRECTORY_SEPARATOR . 'View' .
DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
$themeAssets = THEMES . engineGet('config', 'defaults', 'theme') .
DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
if (is_dir($modulesAssets) && is_readable($modulesAssets . $file)) {
$publicFile = $this->publicAssetsPath . $this->view->getModule() . DIRECTORY_SEPARATOR . $file;
if (!is_dir($modulesAssets . $file) && (!is_readable($publicFile) || $this->checkOutOfDate($publicFile, $modulesAssets . $file))) {
if (!is_dir(dirname($publicFile))) {
mkdir(dirname($publicFile), 0777, true);
}
copy($modulesAssets . $file, $publicFile);
}
else if (is_dir($modulesAssets . $file)) {
Util::copyDir($modulesAssets . $file, $publicFile);
}
}
else if (is_dir($themeAssets) && is_readable($themeAssets . $file)) {
$publicFile = $this->publicAssetsPath . engineGet('config', 'defaults', 'theme') . DIRECTORY_SEPARATOR . $file;
if (!is_dir($themeAssets . $file) && (!is_readable($publicFile) || $this->checkOutOfDate($publicFile, $themeAssets . $file))) {
if (!is_dir(dirname($publicFile))) {
mkdir(dirname($publicFile), 0777, true);
}
copy($themeAssets . $file, $publicFile);
}
else if (is_dir($themeAssets . $file)) {
Util::copyDir($themeAssets . $file, $publicFile);
}
}
else {
return false;
}
return true;
} | [
"private",
"function",
"updateAssets",
"(",
"$",
"file",
")",
"{",
"$",
"modulesAssets",
"=",
"MODULES",
".",
"$",
"this",
"->",
"view",
"->",
"getModule",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'View'",
".",
"DIRECTORY_SEPARATOR",
".",
"'assets'",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"themeAssets",
"=",
"THEMES",
".",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'theme'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'assets'",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"is_dir",
"(",
"$",
"modulesAssets",
")",
"&&",
"is_readable",
"(",
"$",
"modulesAssets",
".",
"$",
"file",
")",
")",
"{",
"$",
"publicFile",
"=",
"$",
"this",
"->",
"publicAssetsPath",
".",
"$",
"this",
"->",
"view",
"->",
"getModule",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"modulesAssets",
".",
"$",
"file",
")",
"&&",
"(",
"!",
"is_readable",
"(",
"$",
"publicFile",
")",
"||",
"$",
"this",
"->",
"checkOutOfDate",
"(",
"$",
"publicFile",
",",
"$",
"modulesAssets",
".",
"$",
"file",
")",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"dirname",
"(",
"$",
"publicFile",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"publicFile",
")",
",",
"0777",
",",
"true",
")",
";",
"}",
"copy",
"(",
"$",
"modulesAssets",
".",
"$",
"file",
",",
"$",
"publicFile",
")",
";",
"}",
"else",
"if",
"(",
"is_dir",
"(",
"$",
"modulesAssets",
".",
"$",
"file",
")",
")",
"{",
"Util",
"::",
"copyDir",
"(",
"$",
"modulesAssets",
".",
"$",
"file",
",",
"$",
"publicFile",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_dir",
"(",
"$",
"themeAssets",
")",
"&&",
"is_readable",
"(",
"$",
"themeAssets",
".",
"$",
"file",
")",
")",
"{",
"$",
"publicFile",
"=",
"$",
"this",
"->",
"publicAssetsPath",
".",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'theme'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"themeAssets",
".",
"$",
"file",
")",
"&&",
"(",
"!",
"is_readable",
"(",
"$",
"publicFile",
")",
"||",
"$",
"this",
"->",
"checkOutOfDate",
"(",
"$",
"publicFile",
",",
"$",
"themeAssets",
".",
"$",
"file",
")",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"dirname",
"(",
"$",
"publicFile",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"publicFile",
")",
",",
"0777",
",",
"true",
")",
";",
"}",
"copy",
"(",
"$",
"themeAssets",
".",
"$",
"file",
",",
"$",
"publicFile",
")",
";",
"}",
"else",
"if",
"(",
"is_dir",
"(",
"$",
"themeAssets",
".",
"$",
"file",
")",
")",
"{",
"Util",
"::",
"copyDir",
"(",
"$",
"themeAssets",
".",
"$",
"file",
",",
"$",
"publicFile",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| updates the cached asset files
@todo don't overwrite existing assets unless they are changed (both original && copied) | [
"updates",
"the",
"cached",
"asset",
"files"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L265-L300 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.getFile | private function getFile($file, $fromTheme) {
$this->updateAssets($file);
if (!$fromTheme && is_readable($this->publicAssetsPath . $this->view->getModule() . DIRECTORY_SEPARATOR . $file)) {
return $this->parseFile($this->view->getModule() . DIRECTORY_SEPARATOR . $file);
}
elseif (is_readable($this->publicAssetsPath . engineGet('config', 'defaults', 'theme') . DIRECTORY_SEPARATOR . $file)) {
return $this->parseFile(engineGet('config', 'defaults', 'theme') . DIRECTORY_SEPARATOR . $file);
}
else {
return 'not-found/' . $file;
}
} | php | private function getFile($file, $fromTheme) {
$this->updateAssets($file);
if (!$fromTheme && is_readable($this->publicAssetsPath . $this->view->getModule() . DIRECTORY_SEPARATOR . $file)) {
return $this->parseFile($this->view->getModule() . DIRECTORY_SEPARATOR . $file);
}
elseif (is_readable($this->publicAssetsPath . engineGet('config', 'defaults', 'theme') . DIRECTORY_SEPARATOR . $file)) {
return $this->parseFile(engineGet('config', 'defaults', 'theme') . DIRECTORY_SEPARATOR . $file);
}
else {
return 'not-found/' . $file;
}
} | [
"private",
"function",
"getFile",
"(",
"$",
"file",
",",
"$",
"fromTheme",
")",
"{",
"$",
"this",
"->",
"updateAssets",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"$",
"fromTheme",
"&&",
"is_readable",
"(",
"$",
"this",
"->",
"publicAssetsPath",
".",
"$",
"this",
"->",
"view",
"->",
"getModule",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"parseFile",
"(",
"$",
"this",
"->",
"view",
"->",
"getModule",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"elseif",
"(",
"is_readable",
"(",
"$",
"this",
"->",
"publicAssetsPath",
".",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'theme'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"parseFile",
"(",
"engineGet",
"(",
"'config'",
",",
"'defaults'",
",",
"'theme'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"else",
"{",
"return",
"'not-found/'",
".",
"$",
"file",
";",
"}",
"}"
]
| Fetches the path to file
@param string $file
@param boolean $fromTheme Indicates whether to get file from theme assets and not modules' assets
@todo Look for a way to use files directly without copying them to the public folder to guide
against script injections and what-have-yous
@return string | [
"Fetches",
"the",
"path",
"to",
"file"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L319-L331 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.loadCss | final protected function loadCss($css, $fromTheme = false, $once = false) {
if ($once && !$this->canLoadAsset($css, 'css'))
return null;
return '<link rel="stylesheet" type="text/css" href="' . $this->getFile($css . '.css', $fromTheme) . '" />' . "\n";
} | php | final protected function loadCss($css, $fromTheme = false, $once = false) {
if ($once && !$this->canLoadAsset($css, 'css'))
return null;
return '<link rel="stylesheet" type="text/css" href="' . $this->getFile($css . '.css', $fromTheme) . '" />' . "\n";
} | [
"final",
"protected",
"function",
"loadCss",
"(",
"$",
"css",
",",
"$",
"fromTheme",
"=",
"false",
",",
"$",
"once",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"once",
"&&",
"!",
"$",
"this",
"->",
"canLoadAsset",
"(",
"$",
"css",
",",
"'css'",
")",
")",
"return",
"null",
";",
"return",
"'<link rel=\"stylesheet\" type=\"text/css\" href=\"'",
".",
"$",
"this",
"->",
"getFile",
"(",
"$",
"css",
".",
"'.css'",
",",
"$",
"fromTheme",
")",
".",
"'\" />'",
".",
"\"\\n\"",
";",
"}"
]
| Loads a style sheet file
@param string $css Filename without the extension with base as ./assets
@param boolean $fromTheme Indicates whether to load the stylesheet from the theme or current module
@param boolean $once Indicates whether to load the stylesheet only once
@return string | [
"Loads",
"a",
"style",
"sheet",
"file"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L350-L354 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.