id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
6,100 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/upload.php | Upload.get_errors | public static function get_errors($index = null)
{
// convert element name formats
is_string($index) and $index = str_replace(':', '.', $index);
$files = static::$upload->getInvalidFiles($index);
// convert the file object to 1.x compatible data
$result = array();
foreach ($files as $file)
{
$data = array();
foreach ($file as $item => $value)
{
// swap item names for BC
$item == 'element' and $item = 'field';
$item == 'tmp_name' and $item = 'file';
$item == 'filename' and $item = 'saved_as';
$item == 'path' and $item = 'saved_to';
$data[$item] = $value;
}
$data['field'] = str_replace('.', ':', $data['field']);
$data['error'] = ! $file->isValid();
$data['errors'] = array();
foreach ($file->getErrors() as $error)
{
$data['errors'][] = array('error' => $error->getError(), 'message' => $error->getMessage());
}
$result[] = $data;
}
// compatibility with < 1.5, return the single entry if only one was found
if (func_num_args() and count($result) == 1)
{
return reset($result);
}
else
{
return $result;
}
} | php | public static function get_errors($index = null)
{
// convert element name formats
is_string($index) and $index = str_replace(':', '.', $index);
$files = static::$upload->getInvalidFiles($index);
// convert the file object to 1.x compatible data
$result = array();
foreach ($files as $file)
{
$data = array();
foreach ($file as $item => $value)
{
// swap item names for BC
$item == 'element' and $item = 'field';
$item == 'tmp_name' and $item = 'file';
$item == 'filename' and $item = 'saved_as';
$item == 'path' and $item = 'saved_to';
$data[$item] = $value;
}
$data['field'] = str_replace('.', ':', $data['field']);
$data['error'] = ! $file->isValid();
$data['errors'] = array();
foreach ($file->getErrors() as $error)
{
$data['errors'][] = array('error' => $error->getError(), 'message' => $error->getMessage());
}
$result[] = $data;
}
// compatibility with < 1.5, return the single entry if only one was found
if (func_num_args() and count($result) == 1)
{
return reset($result);
}
else
{
return $result;
}
} | [
"public",
"static",
"function",
"get_errors",
"(",
"$",
"index",
"=",
"null",
")",
"{",
"// convert element name formats",
"is_string",
"(",
"$",
"index",
")",
"and",
"$",
"index",
"=",
"str_replace",
"(",
"':'",
",",
"'.'",
",",
"$",
"index",
")",
";",
"$",
"files",
"=",
"static",
"::",
"$",
"upload",
"->",
"getInvalidFiles",
"(",
"$",
"index",
")",
";",
"// convert the file object to 1.x compatible data",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"file",
"as",
"$",
"item",
"=>",
"$",
"value",
")",
"{",
"// swap item names for BC",
"$",
"item",
"==",
"'element'",
"and",
"$",
"item",
"=",
"'field'",
";",
"$",
"item",
"==",
"'tmp_name'",
"and",
"$",
"item",
"=",
"'file'",
";",
"$",
"item",
"==",
"'filename'",
"and",
"$",
"item",
"=",
"'saved_as'",
";",
"$",
"item",
"==",
"'path'",
"and",
"$",
"item",
"=",
"'saved_to'",
";",
"$",
"data",
"[",
"$",
"item",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"data",
"[",
"'field'",
"]",
"=",
"str_replace",
"(",
"'.'",
",",
"':'",
",",
"$",
"data",
"[",
"'field'",
"]",
")",
";",
"$",
"data",
"[",
"'error'",
"]",
"=",
"!",
"$",
"file",
"->",
"isValid",
"(",
")",
";",
"$",
"data",
"[",
"'errors'",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"file",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"data",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"array",
"(",
"'error'",
"=>",
"$",
"error",
"->",
"getError",
"(",
")",
",",
"'message'",
"=>",
"$",
"error",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"result",
"[",
"]",
"=",
"$",
"data",
";",
"}",
"// compatibility with < 1.5, return the single entry if only one was found",
"if",
"(",
"func_num_args",
"(",
")",
"and",
"count",
"(",
"$",
"result",
")",
"==",
"1",
")",
"{",
"return",
"reset",
"(",
"$",
"result",
")",
";",
"}",
"else",
"{",
"return",
"$",
"result",
";",
"}",
"}"
] | Get the list of non-validated files
@return array list of uploaded files that failed to validate | [
"Get",
"the",
"list",
"of",
"non",
"-",
"validated",
"files"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/upload.php#L224-L265 |
6,101 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/upload.php | Upload.process | public static function process($config = array())
{
foreach (static::$upload->getAllFiles() as $file)
{
$file->setConfig($config);
$file->validate();
}
} | php | public static function process($config = array())
{
foreach (static::$upload->getAllFiles() as $file)
{
$file->setConfig($config);
$file->validate();
}
} | [
"public",
"static",
"function",
"process",
"(",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"upload",
"->",
"getAllFiles",
"(",
")",
"as",
"$",
"file",
")",
"{",
"$",
"file",
"->",
"setConfig",
"(",
"$",
"config",
")",
";",
"$",
"file",
"->",
"validate",
"(",
")",
";",
"}",
"}"
] | Process the uploaded files, and run the validation
@return void | [
"Process",
"the",
"uploaded",
"files",
"and",
"run",
"the",
"validation"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/upload.php#L294-L301 |
6,102 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/upload.php | Upload.with_ftp | public static function with_ftp($config = 'default', $connect = true)
{
if (static::$with_ftp = \Ftp::forge($config, $connect))
{
// if we have an ftp object, activate the move callback
static::$upload->setConfig('moveCallback', '\\Upload\\move_callback');
}
else
{
// creating the ftp object failed, disable the callback
static::$upload->setConfig('moveCallback', null);
}
} | php | public static function with_ftp($config = 'default', $connect = true)
{
if (static::$with_ftp = \Ftp::forge($config, $connect))
{
// if we have an ftp object, activate the move callback
static::$upload->setConfig('moveCallback', '\\Upload\\move_callback');
}
else
{
// creating the ftp object failed, disable the callback
static::$upload->setConfig('moveCallback', null);
}
} | [
"public",
"static",
"function",
"with_ftp",
"(",
"$",
"config",
"=",
"'default'",
",",
"$",
"connect",
"=",
"true",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"with_ftp",
"=",
"\\",
"Ftp",
"::",
"forge",
"(",
"$",
"config",
",",
"$",
"connect",
")",
")",
"{",
"// if we have an ftp object, activate the move callback",
"static",
"::",
"$",
"upload",
"->",
"setConfig",
"(",
"'moveCallback'",
",",
"'\\\\Upload\\\\move_callback'",
")",
";",
"}",
"else",
"{",
"// creating the ftp object failed, disable the callback",
"static",
"::",
"$",
"upload",
"->",
"setConfig",
"(",
"'moveCallback'",
",",
"null",
")",
";",
"}",
"}"
] | Upload files with FTP
@param string|array The name of the config group to use, or a configuration array.
@param bool Automatically connect to this server. | [
"Upload",
"files",
"with",
"FTP"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/upload.php#L311-L323 |
6,103 | simplecomplex/inspect | src/Inspect.php | Inspect.loadDependencies | protected function loadDependencies() /*: void*/
{
if (!$this->validate) {
$this->validate = Validate::getInstance();
if (!$this->config) {
// Use enviroment variable wrapper config class if exists;
// fall back on empty sectioned map.
try {
if (class_exists('\\SimpleComplex\\Config\\EnvSectionedConfig')) {
$this->config = call_user_func('\\SimpleComplex\\Config\\EnvSectionedConfig::getInstance');
} else {
$this->config = new SectionedMap();
}
} catch (\Throwable $ignore) {
$this->config = new SectionedMap();
}
}
if (!$this->unicode) {
$this->unicode = Unicode::getInstance();
}
if (!$this->sanitize) {
$this->sanitize = Sanitize::getInstance();
}
}
} | php | protected function loadDependencies() /*: void*/
{
if (!$this->validate) {
$this->validate = Validate::getInstance();
if (!$this->config) {
// Use enviroment variable wrapper config class if exists;
// fall back on empty sectioned map.
try {
if (class_exists('\\SimpleComplex\\Config\\EnvSectionedConfig')) {
$this->config = call_user_func('\\SimpleComplex\\Config\\EnvSectionedConfig::getInstance');
} else {
$this->config = new SectionedMap();
}
} catch (\Throwable $ignore) {
$this->config = new SectionedMap();
}
}
if (!$this->unicode) {
$this->unicode = Unicode::getInstance();
}
if (!$this->sanitize) {
$this->sanitize = Sanitize::getInstance();
}
}
} | [
"protected",
"function",
"loadDependencies",
"(",
")",
"/*: void*/",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validate",
")",
"{",
"$",
"this",
"->",
"validate",
"=",
"Validate",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
")",
"{",
"// Use enviroment variable wrapper config class if exists;",
"// fall back on empty sectioned map.",
"try",
"{",
"if",
"(",
"class_exists",
"(",
"'\\\\SimpleComplex\\\\Config\\\\EnvSectionedConfig'",
")",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"call_user_func",
"(",
"'\\\\SimpleComplex\\\\Config\\\\EnvSectionedConfig::getInstance'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"config",
"=",
"new",
"SectionedMap",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"ignore",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"new",
"SectionedMap",
"(",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"unicode",
")",
"{",
"$",
"this",
"->",
"unicode",
"=",
"Unicode",
"::",
"getInstance",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"sanitize",
")",
"{",
"$",
"this",
"->",
"sanitize",
"=",
"Sanitize",
"::",
"getInstance",
"(",
")",
";",
"}",
"}",
"}"
] | Load dependencies on demand.
@see \SimpleComplex\Config\EnvSectionedConfig
@return void | [
"Load",
"dependencies",
"on",
"demand",
"."
] | ced7655460d1ae006d5c282be3d93311c75e67a4 | https://github.com/simplecomplex/inspect/blob/ced7655460d1ae006d5c282be3d93311c75e67a4/src/Inspect.php#L195-L220 |
6,104 | simplecomplex/inspect | src/Inspect.php | Inspect.variable | public function variable($subject, $options = []) : Inspector
{
// Init.----------------------------------------------------------------
$this->loadDependencies();
// Business.------------------------------------------------------------
$options['kind'] = 'variable';
$class_inspector = static::CLASS_INSPECTOR;
/** @var Inspector */
return new $class_inspector(
$this,
$subject,
$options
);
} | php | public function variable($subject, $options = []) : Inspector
{
// Init.----------------------------------------------------------------
$this->loadDependencies();
// Business.------------------------------------------------------------
$options['kind'] = 'variable';
$class_inspector = static::CLASS_INSPECTOR;
/** @var Inspector */
return new $class_inspector(
$this,
$subject,
$options
);
} | [
"public",
"function",
"variable",
"(",
"$",
"subject",
",",
"$",
"options",
"=",
"[",
"]",
")",
":",
"Inspector",
"{",
"// Init.----------------------------------------------------------------",
"$",
"this",
"->",
"loadDependencies",
"(",
")",
";",
"// Business.------------------------------------------------------------",
"$",
"options",
"[",
"'kind'",
"]",
"=",
"'variable'",
";",
"$",
"class_inspector",
"=",
"static",
"::",
"CLASS_INSPECTOR",
";",
"/** @var Inspector */",
"return",
"new",
"$",
"class_inspector",
"(",
"$",
"this",
",",
"$",
"subject",
",",
"$",
"options",
")",
";",
"}"
] | Force variable inspection, even if subject is a throwable.
@see Inspector::$options
@param mixed $subject
@param array|int|string $options
@return Inspector
Stringable. | [
"Force",
"variable",
"inspection",
"even",
"if",
"subject",
"is",
"a",
"throwable",
"."
] | ced7655460d1ae006d5c282be3d93311c75e67a4 | https://github.com/simplecomplex/inspect/blob/ced7655460d1ae006d5c282be3d93311c75e67a4/src/Inspect.php#L268-L283 |
6,105 | dashifen/response | src/AbstractResponse.php | AbstractResponse.setContent | public function setContent(string $content): void {
// there's two options here: that the concatenation of $this->root_path
// and $content is a file and we pass that to our view or that it isn't
// and we pass the $content argument to the view directly assuming that
// it's a string of content.
$temp = $this->root_path . DIRECTORY_SEPARATOR . $content;
$this->view->setContent(is_file($temp) ? $temp : $content);
} | php | public function setContent(string $content): void {
// there's two options here: that the concatenation of $this->root_path
// and $content is a file and we pass that to our view or that it isn't
// and we pass the $content argument to the view directly assuming that
// it's a string of content.
$temp = $this->root_path . DIRECTORY_SEPARATOR . $content;
$this->view->setContent(is_file($temp) ? $temp : $content);
} | [
"public",
"function",
"setContent",
"(",
"string",
"$",
"content",
")",
":",
"void",
"{",
"// there's two options here: that the concatenation of $this->root_path",
"// and $content is a file and we pass that to our view or that it isn't",
"// and we pass the $content argument to the view directly assuming that",
"// it's a string of content.",
"$",
"temp",
"=",
"$",
"this",
"->",
"root_path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"content",
";",
"$",
"this",
"->",
"view",
"->",
"setContent",
"(",
"is_file",
"(",
"$",
"temp",
")",
"?",
"$",
"temp",
":",
"$",
"content",
")",
";",
"}"
] | passes content to our view
@param string $content
@return void | [
"passes",
"content",
"to",
"our",
"view"
] | 1ddf55cda480fd22130e4a8ff7000b445b21ee11 | https://github.com/dashifen/response/blob/1ddf55cda480fd22130e4a8ff7000b445b21ee11/src/AbstractResponse.php#L322-L331 |
6,106 | dashifen/response | src/AbstractResponse.php | AbstractResponse.redirect | public function redirect(string $url): void {
if (!filter_var($url, FILTER_VALIDATE_URL)) {
throw new ResponseException("Invalid URL: $url", ResponseException::INVALID_URL);
}
$this->setType("redirect");
$this->data["url"] = $url;
} | php | public function redirect(string $url): void {
if (!filter_var($url, FILTER_VALIDATE_URL)) {
throw new ResponseException("Invalid URL: $url", ResponseException::INVALID_URL);
}
$this->setType("redirect");
$this->data["url"] = $url;
} | [
"public",
"function",
"redirect",
"(",
"string",
"$",
"url",
")",
":",
"void",
"{",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"url",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"throw",
"new",
"ResponseException",
"(",
"\"Invalid URL: $url\"",
",",
"ResponseException",
"::",
"INVALID_URL",
")",
";",
"}",
"$",
"this",
"->",
"setType",
"(",
"\"redirect\"",
")",
";",
"$",
"this",
"->",
"data",
"[",
"\"url\"",
"]",
"=",
"$",
"url",
";",
"}"
] | sets the appropriate type and data for a redirection
@param string $url
@throws ResponseException | [
"sets",
"the",
"appropriate",
"type",
"and",
"data",
"for",
"a",
"redirection"
] | 1ddf55cda480fd22130e4a8ff7000b445b21ee11 | https://github.com/dashifen/response/blob/1ddf55cda480fd22130e4a8ff7000b445b21ee11/src/AbstractResponse.php#L340-L347 |
6,107 | oal/babble | src/Path.php | Path.bindRoute | public function bindRoute(string $templateDir)
{
$this->routeBindings = [];
if (strlen($templateDir) === 0) return;
// $dirsOrVars contains directories or variables like this: ['blog', '$year', '$month', '$day'].
$dirsOrVars = explode('/', trim($templateDir, '/'));
// $varValues contains values to be bound like ['blog', '2017', '12', '02', 'some-id']
// it may be longer than $dirsOrVars as the last value in $varValues may be the resource ID or "index".
$varValues = explode('/', trim($this->path, '/'));
for ($i = 0; $i < count($dirsOrVars); $i++) {
$dirOrVar = $dirsOrVars[$i];
if ($dirOrVar[0] !== '$') continue; // Only bind variables like "$year", and ignore literals like "blog".
$boundVar = substr($dirOrVar, 1); // Drop the dollar sign.
// If this is matched with a file, it might look like "$page.twig", so we need to drop the extension.
$extStart = strpos($boundVar, '.');
if ($extStart !== false) {
$boundVar = substr($boundVar, 0, $extStart);
}
$this->routeBindings[$boundVar] = $varValues[$i];
}
} | php | public function bindRoute(string $templateDir)
{
$this->routeBindings = [];
if (strlen($templateDir) === 0) return;
// $dirsOrVars contains directories or variables like this: ['blog', '$year', '$month', '$day'].
$dirsOrVars = explode('/', trim($templateDir, '/'));
// $varValues contains values to be bound like ['blog', '2017', '12', '02', 'some-id']
// it may be longer than $dirsOrVars as the last value in $varValues may be the resource ID or "index".
$varValues = explode('/', trim($this->path, '/'));
for ($i = 0; $i < count($dirsOrVars); $i++) {
$dirOrVar = $dirsOrVars[$i];
if ($dirOrVar[0] !== '$') continue; // Only bind variables like "$year", and ignore literals like "blog".
$boundVar = substr($dirOrVar, 1); // Drop the dollar sign.
// If this is matched with a file, it might look like "$page.twig", so we need to drop the extension.
$extStart = strpos($boundVar, '.');
if ($extStart !== false) {
$boundVar = substr($boundVar, 0, $extStart);
}
$this->routeBindings[$boundVar] = $varValues[$i];
}
} | [
"public",
"function",
"bindRoute",
"(",
"string",
"$",
"templateDir",
")",
"{",
"$",
"this",
"->",
"routeBindings",
"=",
"[",
"]",
";",
"if",
"(",
"strlen",
"(",
"$",
"templateDir",
")",
"===",
"0",
")",
"return",
";",
"// $dirsOrVars contains directories or variables like this: ['blog', '$year', '$month', '$day'].",
"$",
"dirsOrVars",
"=",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"templateDir",
",",
"'/'",
")",
")",
";",
"// $varValues contains values to be bound like ['blog', '2017', '12', '02', 'some-id']",
"// it may be longer than $dirsOrVars as the last value in $varValues may be the resource ID or \"index\".",
"$",
"varValues",
"=",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"this",
"->",
"path",
",",
"'/'",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"dirsOrVars",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"dirOrVar",
"=",
"$",
"dirsOrVars",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"dirOrVar",
"[",
"0",
"]",
"!==",
"'$'",
")",
"continue",
";",
"// Only bind variables like \"$year\", and ignore literals like \"blog\".",
"$",
"boundVar",
"=",
"substr",
"(",
"$",
"dirOrVar",
",",
"1",
")",
";",
"// Drop the dollar sign.",
"// If this is matched with a file, it might look like \"$page.twig\", so we need to drop the extension.",
"$",
"extStart",
"=",
"strpos",
"(",
"$",
"boundVar",
",",
"'.'",
")",
";",
"if",
"(",
"$",
"extStart",
"!==",
"false",
")",
"{",
"$",
"boundVar",
"=",
"substr",
"(",
"$",
"boundVar",
",",
"0",
",",
"$",
"extStart",
")",
";",
"}",
"$",
"this",
"->",
"routeBindings",
"[",
"$",
"boundVar",
"]",
"=",
"$",
"varValues",
"[",
"$",
"i",
"]",
";",
"}",
"}"
] | Takes in a template directory and matches variables with values in the path.
Should not be called outside Babble core!
@param string $templateDir | [
"Takes",
"in",
"a",
"template",
"directory",
"and",
"matches",
"variables",
"with",
"values",
"in",
"the",
"path",
".",
"Should",
"not",
"be",
"called",
"outside",
"Babble",
"core!"
] | 5a352d12ead6341294747831b0dfce097a0215e7 | https://github.com/oal/babble/blob/5a352d12ead6341294747831b0dfce097a0215e7/src/Path.php#L83-L109 |
6,108 | dpeuscher/DpZFExtensions | src/DpZFExtensions/ServiceManager/ServiceLocatorDecorator.php | ServiceLocatorDecorator.get | public function get($name, $usePeeringServiceManagers = true) {
try {
return parent::get($name,$usePeeringServiceManagers);
} catch (ServiceNotFoundException $e) {
if (isset($this->_decoree))
return $this->getDecoree()->get($name,$usePeeringServiceManagers);
else
throw $e;
}
} | php | public function get($name, $usePeeringServiceManagers = true) {
try {
return parent::get($name,$usePeeringServiceManagers);
} catch (ServiceNotFoundException $e) {
if (isset($this->_decoree))
return $this->getDecoree()->get($name,$usePeeringServiceManagers);
else
throw $e;
}
} | [
"public",
"function",
"get",
"(",
"$",
"name",
",",
"$",
"usePeeringServiceManagers",
"=",
"true",
")",
"{",
"try",
"{",
"return",
"parent",
"::",
"get",
"(",
"$",
"name",
",",
"$",
"usePeeringServiceManagers",
")",
";",
"}",
"catch",
"(",
"ServiceNotFoundException",
"$",
"e",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_decoree",
")",
")",
"return",
"$",
"this",
"->",
"getDecoree",
"(",
")",
"->",
"get",
"(",
"$",
"name",
",",
"$",
"usePeeringServiceManagers",
")",
";",
"else",
"throw",
"$",
"e",
";",
"}",
"}"
] | Retrieve a registered instance
@param string $name
@param bool $usePeeringServiceManagers
@throws \Exception|\Zend\ServiceManager\Exception\ServiceNotFoundException
@return object|array | [
"Retrieve",
"a",
"registered",
"instance"
] | e0194daca449601a58f5b2fc019dbdbd1a1b1b89 | https://github.com/dpeuscher/DpZFExtensions/blob/e0194daca449601a58f5b2fc019dbdbd1a1b1b89/src/DpZFExtensions/ServiceManager/ServiceLocatorDecorator.php#L38-L47 |
6,109 | webriq/core | module/Core/src/Grid/Core/Controller/RpcController.php | RpcController.rawData | protected static function rawData( $object )
{
if ( is_object( $object ) )
{
$hash = spl_object_hash( $object );
if ( isset( self::$rawCheck[$hash] ) )
{
return array( '#recursion#' => $hash );
}
self::$rawCheck[$hash] = true;
}
$object = (array) $object;
foreach ( $object as $key => $value )
{
if ( is_array( $value ) || is_object( $value ) )
{
$object[$key] = self::rawData( $value );
}
}
return (object) $object;
} | php | protected static function rawData( $object )
{
if ( is_object( $object ) )
{
$hash = spl_object_hash( $object );
if ( isset( self::$rawCheck[$hash] ) )
{
return array( '#recursion#' => $hash );
}
self::$rawCheck[$hash] = true;
}
$object = (array) $object;
foreach ( $object as $key => $value )
{
if ( is_array( $value ) || is_object( $value ) )
{
$object[$key] = self::rawData( $value );
}
}
return (object) $object;
} | [
"protected",
"static",
"function",
"rawData",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"$",
"hash",
"=",
"spl_object_hash",
"(",
"$",
"object",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"rawCheck",
"[",
"$",
"hash",
"]",
")",
")",
"{",
"return",
"array",
"(",
"'#recursion#'",
"=>",
"$",
"hash",
")",
";",
"}",
"self",
"::",
"$",
"rawCheck",
"[",
"$",
"hash",
"]",
"=",
"true",
";",
"}",
"$",
"object",
"=",
"(",
"array",
")",
"$",
"object",
";",
"foreach",
"(",
"$",
"object",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"object",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"rawData",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"(",
"object",
")",
"$",
"object",
";",
"}"
] | Convert data to raw object
@param array|object $object
@return object | [
"Convert",
"data",
"to",
"raw",
"object"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Controller/RpcController.php#L37-L62 |
6,110 | webriq/core | module/Core/src/Grid/Core/Controller/RpcController.php | RpcController.logException | public function logException( Exception $exception,
$priority = Logger::CRIT )
{
/* @var $logger \Zork\Log\LoggerManager */
$logger = $this->getServiceLocator()
->get( 'Zork\Log\LoggerManager' );
if ( $logger->hasLogger( 'exception' ) )
{
$logger->getLogger( 'exception' )
->log( $priority,
'<pre>' . $exception . PHP_EOL . '</pre>' . PHP_EOL );
}
} | php | public function logException( Exception $exception,
$priority = Logger::CRIT )
{
/* @var $logger \Zork\Log\LoggerManager */
$logger = $this->getServiceLocator()
->get( 'Zork\Log\LoggerManager' );
if ( $logger->hasLogger( 'exception' ) )
{
$logger->getLogger( 'exception' )
->log( $priority,
'<pre>' . $exception . PHP_EOL . '</pre>' . PHP_EOL );
}
} | [
"public",
"function",
"logException",
"(",
"Exception",
"$",
"exception",
",",
"$",
"priority",
"=",
"Logger",
"::",
"CRIT",
")",
"{",
"/* @var $logger \\Zork\\Log\\LoggerManager */",
"$",
"logger",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'Zork\\Log\\LoggerManager'",
")",
";",
"if",
"(",
"$",
"logger",
"->",
"hasLogger",
"(",
"'exception'",
")",
")",
"{",
"$",
"logger",
"->",
"getLogger",
"(",
"'exception'",
")",
"->",
"log",
"(",
"$",
"priority",
",",
"'<pre>'",
".",
"$",
"exception",
".",
"PHP_EOL",
".",
"'</pre>'",
".",
"PHP_EOL",
")",
";",
"}",
"}"
] | Log a single exception
@param \Exception $exception
@param int $priority | [
"Log",
"a",
"single",
"exception"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Controller/RpcController.php#L86-L99 |
6,111 | dcsg/MailchimpApiConnector | lib/MailchimpApiConnector/MailchimpApi.php | MailchimpApi.getUrlToOldApi | private function getUrlToOldApi($method, array $params, $format)
{
$queryString = sprintf(
'?apikey=%s&format=%s&method=%s%s',
$this->getApiKey(),
$format,
$method,
$this->paramsQueryStringBuilder($params)
);
return sprintf(
$this::API_URL,
$this->getDc(),
$this->getApiVersion(),
$queryString
);
} | php | private function getUrlToOldApi($method, array $params, $format)
{
$queryString = sprintf(
'?apikey=%s&format=%s&method=%s%s',
$this->getApiKey(),
$format,
$method,
$this->paramsQueryStringBuilder($params)
);
return sprintf(
$this::API_URL,
$this->getDc(),
$this->getApiVersion(),
$queryString
);
} | [
"private",
"function",
"getUrlToOldApi",
"(",
"$",
"method",
",",
"array",
"$",
"params",
",",
"$",
"format",
")",
"{",
"$",
"queryString",
"=",
"sprintf",
"(",
"'?apikey=%s&format=%s&method=%s%s'",
",",
"$",
"this",
"->",
"getApiKey",
"(",
")",
",",
"$",
"format",
",",
"$",
"method",
",",
"$",
"this",
"->",
"paramsQueryStringBuilder",
"(",
"$",
"params",
")",
")",
";",
"return",
"sprintf",
"(",
"$",
"this",
"::",
"API_URL",
",",
"$",
"this",
"->",
"getDc",
"(",
")",
",",
"$",
"this",
"->",
"getApiVersion",
"(",
")",
",",
"$",
"queryString",
")",
";",
"}"
] | Gets the url for Mailchimp API version < 2.0
@param string $method
@param array $params
@param string $format
@return string | [
"Gets",
"the",
"url",
"for",
"Mailchimp",
"API",
"version",
"<",
"2",
".",
"0"
] | 417fe30899ae71d5cedbb401c34ede6012c13979 | https://github.com/dcsg/MailchimpApiConnector/blob/417fe30899ae71d5cedbb401c34ede6012c13979/lib/MailchimpApiConnector/MailchimpApi.php#L64-L80 |
6,112 | dcsg/MailchimpApiConnector | lib/MailchimpApiConnector/MailchimpApi.php | MailchimpApi.getUrl | private function getUrl($method)
{
return sprintf(
$this::API_URL,
$this->getDc(),
$this->getApiVersion(),
$method
);
} | php | private function getUrl($method)
{
return sprintf(
$this::API_URL,
$this->getDc(),
$this->getApiVersion(),
$method
);
} | [
"private",
"function",
"getUrl",
"(",
"$",
"method",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"::",
"API_URL",
",",
"$",
"this",
"->",
"getDc",
"(",
")",
",",
"$",
"this",
"->",
"getApiVersion",
"(",
")",
",",
"$",
"method",
")",
";",
"}"
] | Gets the url for Mailchimp API version >= 2.0
@param string $method
@return string | [
"Gets",
"the",
"url",
"for",
"Mailchimp",
"API",
"version",
">",
"=",
"2",
".",
"0"
] | 417fe30899ae71d5cedbb401c34ede6012c13979 | https://github.com/dcsg/MailchimpApiConnector/blob/417fe30899ae71d5cedbb401c34ede6012c13979/lib/MailchimpApiConnector/MailchimpApi.php#L97-L105 |
6,113 | setrun/setrun-component-user | src/commands/UserAbstractController.php | UserAbstractController.readValue | protected function readValue(User $user, string $attribute) : void
{
$user->$attribute = $this->prompt(mb_convert_case($attribute, MB_CASE_TITLE, 'utf-8') . ':', [
'validator' => function ($input, &$error) use ($user, $attribute) {
$user->$attribute = $input;
if ($user->validate([$attribute])) {
return true;
} else {
$error = implode(',', $user->getErrors($attribute));
return false;
}
},
]);
} | php | protected function readValue(User $user, string $attribute) : void
{
$user->$attribute = $this->prompt(mb_convert_case($attribute, MB_CASE_TITLE, 'utf-8') . ':', [
'validator' => function ($input, &$error) use ($user, $attribute) {
$user->$attribute = $input;
if ($user->validate([$attribute])) {
return true;
} else {
$error = implode(',', $user->getErrors($attribute));
return false;
}
},
]);
} | [
"protected",
"function",
"readValue",
"(",
"User",
"$",
"user",
",",
"string",
"$",
"attribute",
")",
":",
"void",
"{",
"$",
"user",
"->",
"$",
"attribute",
"=",
"$",
"this",
"->",
"prompt",
"(",
"mb_convert_case",
"(",
"$",
"attribute",
",",
"MB_CASE_TITLE",
",",
"'utf-8'",
")",
".",
"':'",
",",
"[",
"'validator'",
"=>",
"function",
"(",
"$",
"input",
",",
"&",
"$",
"error",
")",
"use",
"(",
"$",
"user",
",",
"$",
"attribute",
")",
"{",
"$",
"user",
"->",
"$",
"attribute",
"=",
"$",
"input",
";",
"if",
"(",
"$",
"user",
"->",
"validate",
"(",
"[",
"$",
"attribute",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"error",
"=",
"implode",
"(",
"','",
",",
"$",
"user",
"->",
"getErrors",
"(",
"$",
"attribute",
")",
")",
";",
"return",
"false",
";",
"}",
"}",
",",
"]",
")",
";",
"}"
] | Get the value of the console.
@param User $user
@param string $attribute
@return void | [
"Get",
"the",
"value",
"of",
"the",
"console",
"."
] | 6aca4c62f099918032b66da1f94d7565694a0735 | https://github.com/setrun/setrun-component-user/blob/6aca4c62f099918032b66da1f94d7565694a0735/src/commands/UserAbstractController.php#L56-L69 |
6,114 | setrun/setrun-component-user | src/commands/UserAbstractController.php | UserAbstractController.log | protected function log(bool $success) : void
{
if ($success) {
$this->stdout('Success!', Console::FG_GREEN, Console::BOLD);
} else {
$this->stderr('Error!', Console::FG_RED, Console::BOLD);
}
$this->stdout(PHP_EOL);
} | php | protected function log(bool $success) : void
{
if ($success) {
$this->stdout('Success!', Console::FG_GREEN, Console::BOLD);
} else {
$this->stderr('Error!', Console::FG_RED, Console::BOLD);
}
$this->stdout(PHP_EOL);
} | [
"protected",
"function",
"log",
"(",
"bool",
"$",
"success",
")",
":",
"void",
"{",
"if",
"(",
"$",
"success",
")",
"{",
"$",
"this",
"->",
"stdout",
"(",
"'Success!'",
",",
"Console",
"::",
"FG_GREEN",
",",
"Console",
"::",
"BOLD",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"stderr",
"(",
"'Error!'",
",",
"Console",
"::",
"FG_RED",
",",
"Console",
"::",
"BOLD",
")",
";",
"}",
"$",
"this",
"->",
"stdout",
"(",
"PHP_EOL",
")",
";",
"}"
] | Console log.
@param bool $success
@return void | [
"Console",
"log",
"."
] | 6aca4c62f099918032b66da1f94d7565694a0735 | https://github.com/setrun/setrun-component-user/blob/6aca4c62f099918032b66da1f94d7565694a0735/src/commands/UserAbstractController.php#L76-L84 |
6,115 | yujin1st/yii2-user | controllers/RecoveryController.php | RecoveryController.actionRequest | public function actionRequest() {
if (!$this->module->enablePasswordRecovery) {
throw new NotFoundHttpException();
}
/** @var RecoveryForm $model */
$model = Yii::createObject([
'class' => RecoveryForm::className(),
'scenario' => 'request',
]);
$event = $this->getFormEvent($model);
$this->performAjaxValidation($model);
$this->trigger(self::EVENT_BEFORE_REQUEST, $event);
if ($model->load(Yii::$app->request->post()) && $model->sendRecoveryMessage()) {
$this->trigger(self::EVENT_AFTER_REQUEST, $event);
return $this->render('/message', [
'title' => Yii::t('users', 'Recovery message sent'),
'module' => $this->module,
]);
}
return $this->render('request', [
'model' => $model,
]);
} | php | public function actionRequest() {
if (!$this->module->enablePasswordRecovery) {
throw new NotFoundHttpException();
}
/** @var RecoveryForm $model */
$model = Yii::createObject([
'class' => RecoveryForm::className(),
'scenario' => 'request',
]);
$event = $this->getFormEvent($model);
$this->performAjaxValidation($model);
$this->trigger(self::EVENT_BEFORE_REQUEST, $event);
if ($model->load(Yii::$app->request->post()) && $model->sendRecoveryMessage()) {
$this->trigger(self::EVENT_AFTER_REQUEST, $event);
return $this->render('/message', [
'title' => Yii::t('users', 'Recovery message sent'),
'module' => $this->module,
]);
}
return $this->render('request', [
'model' => $model,
]);
} | [
"public",
"function",
"actionRequest",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"module",
"->",
"enablePasswordRecovery",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"/** @var RecoveryForm $model */",
"$",
"model",
"=",
"Yii",
"::",
"createObject",
"(",
"[",
"'class'",
"=>",
"RecoveryForm",
"::",
"className",
"(",
")",
",",
"'scenario'",
"=>",
"'request'",
",",
"]",
")",
";",
"$",
"event",
"=",
"$",
"this",
"->",
"getFormEvent",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"performAjaxValidation",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_BEFORE_REQUEST",
",",
"$",
"event",
")",
";",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"sendRecoveryMessage",
"(",
")",
")",
"{",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_REQUEST",
",",
"$",
"event",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'/message'",
",",
"[",
"'title'",
"=>",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'Recovery message sent'",
")",
",",
"'module'",
"=>",
"$",
"this",
"->",
"module",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'request'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}"
] | Shows page where user can request password recovery.
@return string
@throws \yii\web\NotFoundHttpException | [
"Shows",
"page",
"where",
"user",
"can",
"request",
"password",
"recovery",
"."
] | b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f | https://github.com/yujin1st/yii2-user/blob/b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f/controllers/RecoveryController.php#L90-L116 |
6,116 | yujin1st/yii2-user | controllers/RecoveryController.php | RecoveryController.actionReset | public function actionReset($id, $code) {
if (!$this->module->enablePasswordRecovery) {
throw new NotFoundHttpException();
}
/** @var Token $token */
$token = Token::find()->where(['userId' => $id, 'code' => $code, 'type' => Token::TYPE_RECOVERY])->one();
$event = $this->getResetPasswordEvent($token);
$this->trigger(self::EVENT_BEFORE_TOKEN_VALIDATE, $event);
if ($token === null || $token->isExpired || $token->user === null) {
$this->trigger(self::EVENT_AFTER_TOKEN_VALIDATE, $event);
Yii::$app->session->setFlash('danger', Yii::t('users', 'Recovery link is invalid or expired. Please try requesting a new one.'));
return $this->render('/message', [
'title' => Yii::t('users', 'Invalid or expired link'),
'module' => $this->module,
]);
}
/** @var RecoveryForm $model */
$model = Yii::createObject([
'class' => RecoveryForm::className(),
'scenario' => 'reset',
]);
$event->setForm($model);
$this->performAjaxValidation($model);
$this->trigger(self::EVENT_BEFORE_RESET, $event);
if ($model->load(Yii::$app->getRequest()->post()) && $model->resetPassword($token)) {
$this->trigger(self::EVENT_AFTER_RESET, $event);
return $this->render('/message', [
'title' => Yii::t('users', 'Password has been changed'),
'module' => $this->module,
]);
}
return $this->render('reset', [
'model' => $model,
]);
} | php | public function actionReset($id, $code) {
if (!$this->module->enablePasswordRecovery) {
throw new NotFoundHttpException();
}
/** @var Token $token */
$token = Token::find()->where(['userId' => $id, 'code' => $code, 'type' => Token::TYPE_RECOVERY])->one();
$event = $this->getResetPasswordEvent($token);
$this->trigger(self::EVENT_BEFORE_TOKEN_VALIDATE, $event);
if ($token === null || $token->isExpired || $token->user === null) {
$this->trigger(self::EVENT_AFTER_TOKEN_VALIDATE, $event);
Yii::$app->session->setFlash('danger', Yii::t('users', 'Recovery link is invalid or expired. Please try requesting a new one.'));
return $this->render('/message', [
'title' => Yii::t('users', 'Invalid or expired link'),
'module' => $this->module,
]);
}
/** @var RecoveryForm $model */
$model = Yii::createObject([
'class' => RecoveryForm::className(),
'scenario' => 'reset',
]);
$event->setForm($model);
$this->performAjaxValidation($model);
$this->trigger(self::EVENT_BEFORE_RESET, $event);
if ($model->load(Yii::$app->getRequest()->post()) && $model->resetPassword($token)) {
$this->trigger(self::EVENT_AFTER_RESET, $event);
return $this->render('/message', [
'title' => Yii::t('users', 'Password has been changed'),
'module' => $this->module,
]);
}
return $this->render('reset', [
'model' => $model,
]);
} | [
"public",
"function",
"actionReset",
"(",
"$",
"id",
",",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"module",
"->",
"enablePasswordRecovery",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"/** @var Token $token */",
"$",
"token",
"=",
"Token",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'userId'",
"=>",
"$",
"id",
",",
"'code'",
"=>",
"$",
"code",
",",
"'type'",
"=>",
"Token",
"::",
"TYPE_RECOVERY",
"]",
")",
"->",
"one",
"(",
")",
";",
"$",
"event",
"=",
"$",
"this",
"->",
"getResetPasswordEvent",
"(",
"$",
"token",
")",
";",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_BEFORE_TOKEN_VALIDATE",
",",
"$",
"event",
")",
";",
"if",
"(",
"$",
"token",
"===",
"null",
"||",
"$",
"token",
"->",
"isExpired",
"||",
"$",
"token",
"->",
"user",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_TOKEN_VALIDATE",
",",
"$",
"event",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'danger'",
",",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'Recovery link is invalid or expired. Please try requesting a new one.'",
")",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'/message'",
",",
"[",
"'title'",
"=>",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'Invalid or expired link'",
")",
",",
"'module'",
"=>",
"$",
"this",
"->",
"module",
",",
"]",
")",
";",
"}",
"/** @var RecoveryForm $model */",
"$",
"model",
"=",
"Yii",
"::",
"createObject",
"(",
"[",
"'class'",
"=>",
"RecoveryForm",
"::",
"className",
"(",
")",
",",
"'scenario'",
"=>",
"'reset'",
",",
"]",
")",
";",
"$",
"event",
"->",
"setForm",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"performAjaxValidation",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_BEFORE_RESET",
",",
"$",
"event",
")",
";",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"resetPassword",
"(",
"$",
"token",
")",
")",
"{",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_RESET",
",",
"$",
"event",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'/message'",
",",
"[",
"'title'",
"=>",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'Password has been changed'",
")",
",",
"'module'",
"=>",
"$",
"this",
"->",
"module",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'reset'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}"
] | Displays page where user can reset password.
@param int $id
@param string $code
@return string
@throws \yii\web\NotFoundHttpException | [
"Displays",
"page",
"where",
"user",
"can",
"reset",
"password",
"."
] | b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f | https://github.com/yujin1st/yii2-user/blob/b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f/controllers/RecoveryController.php#L127-L168 |
6,117 | ongr-archive/ContentBundle | Document/AbstractCategoryDocument.php | AbstractCategoryDocument.hasVisibleChildren | public function hasVisibleChildren()
{
if (is_array($this->children) && count($this->children)) {
foreach ($this->children as $child) {
if (!$child->isHidden()) {
return true;
}
}
}
return false;
} | php | public function hasVisibleChildren()
{
if (is_array($this->children) && count($this->children)) {
foreach ($this->children as $child) {
if (!$child->isHidden()) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"hasVisibleChildren",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"children",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"children",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"!",
"$",
"child",
"->",
"isHidden",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Tests if category has any visible children.
@return bool | [
"Tests",
"if",
"category",
"has",
"any",
"visible",
"children",
"."
] | 453a02c0c89c16f66dc9caed000243534dbeffa5 | https://github.com/ongr-archive/ContentBundle/blob/453a02c0c89c16f66dc9caed000243534dbeffa5/Document/AbstractCategoryDocument.php#L118-L129 |
6,118 | Eresus/EForms | src/eforms/classes/Form.php | EForms_Form.processActions | public function processActions()
{
$Eresus = Eresus_CMS::getLegacyKernel();
$this->parse();
$actionsElement = $this->xml->getElementsByTagNameNS(self::NS, 'actions');
if ($actionsElement)
{
$actions = $actionsElement->item(0)->childNodes;
for ($i = 0; $i < $actions->length; $i++)
{
$action = $actions->item($i);
if ($action->nodeType == XML_ELEMENT_NODE)
{
$this->processAction($action);
}
}
}
if ($this->redirect)
{
$url = $this->redirect;
if (!is_null($this->marker))
{
$url .= '#' . $this->marker;
}
HTTP::redirect($url);
}
elseif (!$this->html)
{
HTTP::redirect($Eresus->request['referer']);
}
return $this->html;
} | php | public function processActions()
{
$Eresus = Eresus_CMS::getLegacyKernel();
$this->parse();
$actionsElement = $this->xml->getElementsByTagNameNS(self::NS, 'actions');
if ($actionsElement)
{
$actions = $actionsElement->item(0)->childNodes;
for ($i = 0; $i < $actions->length; $i++)
{
$action = $actions->item($i);
if ($action->nodeType == XML_ELEMENT_NODE)
{
$this->processAction($action);
}
}
}
if ($this->redirect)
{
$url = $this->redirect;
if (!is_null($this->marker))
{
$url .= '#' . $this->marker;
}
HTTP::redirect($url);
}
elseif (!$this->html)
{
HTTP::redirect($Eresus->request['referer']);
}
return $this->html;
} | [
"public",
"function",
"processActions",
"(",
")",
"{",
"$",
"Eresus",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
";",
"$",
"this",
"->",
"parse",
"(",
")",
";",
"$",
"actionsElement",
"=",
"$",
"this",
"->",
"xml",
"->",
"getElementsByTagNameNS",
"(",
"self",
"::",
"NS",
",",
"'actions'",
")",
";",
"if",
"(",
"$",
"actionsElement",
")",
"{",
"$",
"actions",
"=",
"$",
"actionsElement",
"->",
"item",
"(",
"0",
")",
"->",
"childNodes",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"actions",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"action",
"=",
"$",
"actions",
"->",
"item",
"(",
"$",
"i",
")",
";",
"if",
"(",
"$",
"action",
"->",
"nodeType",
"==",
"XML_ELEMENT_NODE",
")",
"{",
"$",
"this",
"->",
"processAction",
"(",
"$",
"action",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"redirect",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"redirect",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"marker",
")",
")",
"{",
"$",
"url",
".=",
"'#'",
".",
"$",
"this",
"->",
"marker",
";",
"}",
"HTTP",
"::",
"redirect",
"(",
"$",
"url",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"html",
")",
"{",
"HTTP",
"::",
"redirect",
"(",
"$",
"Eresus",
"->",
"request",
"[",
"'referer'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"html",
";",
"}"
] | Process form actions | [
"Process",
"form",
"actions"
] | cdbea1c4215864b739ff8c988b5de1672079389b | https://github.com/Eresus/EForms/blob/cdbea1c4215864b739ff8c988b5de1672079389b/src/eforms/classes/Form.php#L194-L228 |
6,119 | Eresus/EForms | src/eforms/classes/Form.php | EForms_Form.setActionAttribute | protected function setActionAttribute()
{
$Eresus = Eresus_CMS::getLegacyKernel();
/** @var DOMElement $form */
$form = $this->xml->getElementsByTagName('form')->item(0);
$url = $Eresus->request['path'];
/*
* Если есть тег marker и нет тега redirect, то маркер надо добавить к адресу в атрибуте
* action.
*/
$markers = $this->xml->getElementsByTagNameNS(self::NS, 'marker');
$redirects = $this->xml->getElementsByTagNameNS(self::NS, 'redirect');
if ($markers->length > 0 && 0 == $redirects->length)
{
// На случай если указано несколько маркеров, берём только последний
/** @var DOMElement $marker */
$marker = $markers->item($markers->length - 1);
$url .= '#' . $marker->getAttribute('value');
}
$form->setAttribute('action', $url);
} | php | protected function setActionAttribute()
{
$Eresus = Eresus_CMS::getLegacyKernel();
/** @var DOMElement $form */
$form = $this->xml->getElementsByTagName('form')->item(0);
$url = $Eresus->request['path'];
/*
* Если есть тег marker и нет тега redirect, то маркер надо добавить к адресу в атрибуте
* action.
*/
$markers = $this->xml->getElementsByTagNameNS(self::NS, 'marker');
$redirects = $this->xml->getElementsByTagNameNS(self::NS, 'redirect');
if ($markers->length > 0 && 0 == $redirects->length)
{
// На случай если указано несколько маркеров, берём только последний
/** @var DOMElement $marker */
$marker = $markers->item($markers->length - 1);
$url .= '#' . $marker->getAttribute('value');
}
$form->setAttribute('action', $url);
} | [
"protected",
"function",
"setActionAttribute",
"(",
")",
"{",
"$",
"Eresus",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
";",
"/** @var DOMElement $form */",
"$",
"form",
"=",
"$",
"this",
"->",
"xml",
"->",
"getElementsByTagName",
"(",
"'form'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"url",
"=",
"$",
"Eresus",
"->",
"request",
"[",
"'path'",
"]",
";",
"/*\n * Если есть тег marker и нет тега redirect, то маркер надо добавить к адресу в атрибуте\n * action.\n */",
"$",
"markers",
"=",
"$",
"this",
"->",
"xml",
"->",
"getElementsByTagNameNS",
"(",
"self",
"::",
"NS",
",",
"'marker'",
")",
";",
"$",
"redirects",
"=",
"$",
"this",
"->",
"xml",
"->",
"getElementsByTagNameNS",
"(",
"self",
"::",
"NS",
",",
"'redirect'",
")",
";",
"if",
"(",
"$",
"markers",
"->",
"length",
">",
"0",
"&&",
"0",
"==",
"$",
"redirects",
"->",
"length",
")",
"{",
"// На случай если указано несколько маркеров, берём только последний",
"/** @var DOMElement $marker */",
"$",
"marker",
"=",
"$",
"markers",
"->",
"item",
"(",
"$",
"markers",
"->",
"length",
"-",
"1",
")",
";",
"$",
"url",
".=",
"'#'",
".",
"$",
"marker",
"->",
"getAttribute",
"(",
"'value'",
")",
";",
"}",
"$",
"form",
"->",
"setAttribute",
"(",
"'action'",
",",
"$",
"url",
")",
";",
"}"
] | Set form's action attribute | [
"Set",
"form",
"s",
"action",
"attribute"
] | cdbea1c4215864b739ff8c988b5de1672079389b | https://github.com/Eresus/EForms/blob/cdbea1c4215864b739ff8c988b5de1672079389b/src/eforms/classes/Form.php#L266-L289 |
6,120 | Eresus/EForms | src/eforms/classes/Form.php | EForms_Form.setActionTags | protected function setActionTags()
{
$form = $this->xml->getElementsByTagName('form')->item(0);
$div = $this->xml->createElement('div');
$input = $this->xml->createElement('input');
$input->setAttribute('type', 'hidden');
$input->setAttribute('name', 'ext');
$input->setAttribute('value', $this->owner->name);
$div->appendChild($input);
$input = $this->xml->createElement('input');
$input->setAttribute('type', 'hidden');
$input->setAttribute('name', 'form');
$input->setAttribute('value', $this->name);
$div->appendChild($input);
$form->appendChild($div);
} | php | protected function setActionTags()
{
$form = $this->xml->getElementsByTagName('form')->item(0);
$div = $this->xml->createElement('div');
$input = $this->xml->createElement('input');
$input->setAttribute('type', 'hidden');
$input->setAttribute('name', 'ext');
$input->setAttribute('value', $this->owner->name);
$div->appendChild($input);
$input = $this->xml->createElement('input');
$input->setAttribute('type', 'hidden');
$input->setAttribute('name', 'form');
$input->setAttribute('value', $this->name);
$div->appendChild($input);
$form->appendChild($div);
} | [
"protected",
"function",
"setActionTags",
"(",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"xml",
"->",
"getElementsByTagName",
"(",
"'form'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"div",
"=",
"$",
"this",
"->",
"xml",
"->",
"createElement",
"(",
"'div'",
")",
";",
"$",
"input",
"=",
"$",
"this",
"->",
"xml",
"->",
"createElement",
"(",
"'input'",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'type'",
",",
"'hidden'",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'name'",
",",
"'ext'",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'value'",
",",
"$",
"this",
"->",
"owner",
"->",
"name",
")",
";",
"$",
"div",
"->",
"appendChild",
"(",
"$",
"input",
")",
";",
"$",
"input",
"=",
"$",
"this",
"->",
"xml",
"->",
"createElement",
"(",
"'input'",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'type'",
",",
"'hidden'",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'name'",
",",
"'form'",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'value'",
",",
"$",
"this",
"->",
"name",
")",
";",
"$",
"div",
"->",
"appendChild",
"(",
"$",
"input",
")",
";",
"$",
"form",
"->",
"appendChild",
"(",
"$",
"div",
")",
";",
"}"
] | Adds hidden inputs to form | [
"Adds",
"hidden",
"inputs",
"to",
"form"
] | cdbea1c4215864b739ff8c988b5de1672079389b | https://github.com/Eresus/EForms/blob/cdbea1c4215864b739ff8c988b5de1672079389b/src/eforms/classes/Form.php#L295-L313 |
6,121 | Eresus/EForms | src/eforms/classes/Form.php | EForms_Form.getFormData | protected function getFormData()
{
$data = array();
$inputTagNames = array('input', 'textarea', 'select');
$skipNames = array('ext', 'form');
/** @var DOMElement $element */
$element = $this->xml->getElementsByTagName('form')->item(0);
$elements = $element->getElementsByTagName('*');
for ($i = 0; $i < $elements->length; $i++)
{
$element = $elements->item($i);
$isElement = $element->nodeType == XML_ELEMENT_NODE;
$isInputTag = $isElement && in_array($element->nodeName, $inputTagNames);
if ($isInputTag)
{
$name = $element->getAttribute('name');
if (in_array($name, $skipNames))
{
continue;
}
if ($name)
{
if ($element->getAttribute('type') == 'file')
{
$data[$name]['file'] = $_FILES[$name];
}
else
{
$data[$name]['data'] = arg($name);
}
$data[$name]['label'] = $this->getLabelAttr($element);
if (!$data[$name]['label'])
{
$data[$name]['label'] = $name;
}
switch ($element->nodeName)
{
case 'input':
switch ($element->getAttribute('type'))
{
case 'checkbox':
$data[$name]['data'] = $data[$name]['data'] ? strYes : strNo;
break;
}
break;
}
}
}
}
return $data;
} | php | protected function getFormData()
{
$data = array();
$inputTagNames = array('input', 'textarea', 'select');
$skipNames = array('ext', 'form');
/** @var DOMElement $element */
$element = $this->xml->getElementsByTagName('form')->item(0);
$elements = $element->getElementsByTagName('*');
for ($i = 0; $i < $elements->length; $i++)
{
$element = $elements->item($i);
$isElement = $element->nodeType == XML_ELEMENT_NODE;
$isInputTag = $isElement && in_array($element->nodeName, $inputTagNames);
if ($isInputTag)
{
$name = $element->getAttribute('name');
if (in_array($name, $skipNames))
{
continue;
}
if ($name)
{
if ($element->getAttribute('type') == 'file')
{
$data[$name]['file'] = $_FILES[$name];
}
else
{
$data[$name]['data'] = arg($name);
}
$data[$name]['label'] = $this->getLabelAttr($element);
if (!$data[$name]['label'])
{
$data[$name]['label'] = $name;
}
switch ($element->nodeName)
{
case 'input':
switch ($element->getAttribute('type'))
{
case 'checkbox':
$data[$name]['data'] = $data[$name]['data'] ? strYes : strNo;
break;
}
break;
}
}
}
}
return $data;
} | [
"protected",
"function",
"getFormData",
"(",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"inputTagNames",
"=",
"array",
"(",
"'input'",
",",
"'textarea'",
",",
"'select'",
")",
";",
"$",
"skipNames",
"=",
"array",
"(",
"'ext'",
",",
"'form'",
")",
";",
"/** @var DOMElement $element */",
"$",
"element",
"=",
"$",
"this",
"->",
"xml",
"->",
"getElementsByTagName",
"(",
"'form'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"elements",
"=",
"$",
"element",
"->",
"getElementsByTagName",
"(",
"'*'",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"elements",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"element",
"=",
"$",
"elements",
"->",
"item",
"(",
"$",
"i",
")",
";",
"$",
"isElement",
"=",
"$",
"element",
"->",
"nodeType",
"==",
"XML_ELEMENT_NODE",
";",
"$",
"isInputTag",
"=",
"$",
"isElement",
"&&",
"in_array",
"(",
"$",
"element",
"->",
"nodeName",
",",
"$",
"inputTagNames",
")",
";",
"if",
"(",
"$",
"isInputTag",
")",
"{",
"$",
"name",
"=",
"$",
"element",
"->",
"getAttribute",
"(",
"'name'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"skipNames",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getAttribute",
"(",
"'type'",
")",
"==",
"'file'",
")",
"{",
"$",
"data",
"[",
"$",
"name",
"]",
"[",
"'file'",
"]",
"=",
"$",
"_FILES",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"name",
"]",
"[",
"'data'",
"]",
"=",
"arg",
"(",
"$",
"name",
")",
";",
"}",
"$",
"data",
"[",
"$",
"name",
"]",
"[",
"'label'",
"]",
"=",
"$",
"this",
"->",
"getLabelAttr",
"(",
"$",
"element",
")",
";",
"if",
"(",
"!",
"$",
"data",
"[",
"$",
"name",
"]",
"[",
"'label'",
"]",
")",
"{",
"$",
"data",
"[",
"$",
"name",
"]",
"[",
"'label'",
"]",
"=",
"$",
"name",
";",
"}",
"switch",
"(",
"$",
"element",
"->",
"nodeName",
")",
"{",
"case",
"'input'",
":",
"switch",
"(",
"$",
"element",
"->",
"getAttribute",
"(",
"'type'",
")",
")",
"{",
"case",
"'checkbox'",
":",
"$",
"data",
"[",
"$",
"name",
"]",
"[",
"'data'",
"]",
"=",
"$",
"data",
"[",
"$",
"name",
"]",
"[",
"'data'",
"]",
"?",
"strYes",
":",
"strNo",
";",
"break",
";",
"}",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Return posted form data
@return array | [
"Return",
"posted",
"form",
"data"
] | cdbea1c4215864b739ff8c988b5de1672079389b | https://github.com/Eresus/EForms/blob/cdbea1c4215864b739ff8c988b5de1672079389b/src/eforms/classes/Form.php#L332-L388 |
6,122 | Eresus/EForms | src/eforms/classes/Form.php | EForms_Form.processAction | protected function processAction(DOMNode $action)
{
$actionName = substr($action->nodeName, strlen($action->lookupPrefix(self::NS)) + 1);
$methodName = 'action' . $actionName;
if (method_exists($this, $methodName))
{
$this->$methodName($action);
}
} | php | protected function processAction(DOMNode $action)
{
$actionName = substr($action->nodeName, strlen($action->lookupPrefix(self::NS)) + 1);
$methodName = 'action' . $actionName;
if (method_exists($this, $methodName))
{
$this->$methodName($action);
}
} | [
"protected",
"function",
"processAction",
"(",
"DOMNode",
"$",
"action",
")",
"{",
"$",
"actionName",
"=",
"substr",
"(",
"$",
"action",
"->",
"nodeName",
",",
"strlen",
"(",
"$",
"action",
"->",
"lookupPrefix",
"(",
"self",
"::",
"NS",
")",
")",
"+",
"1",
")",
";",
"$",
"methodName",
"=",
"'action'",
".",
"$",
"actionName",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"methodName",
")",
")",
"{",
"$",
"this",
"->",
"$",
"methodName",
"(",
"$",
"action",
")",
";",
"}",
"}"
] | Process action directive
@param DOMNode $action | [
"Process",
"action",
"directive"
] | cdbea1c4215864b739ff8c988b5de1672079389b | https://github.com/Eresus/EForms/blob/cdbea1c4215864b739ff8c988b5de1672079389b/src/eforms/classes/Form.php#L395-L403 |
6,123 | Eresus/EForms | src/eforms/classes/Form.php | EForms_Form.actionRedirect | protected function actionRedirect($action)
{
if ($this->redirect)
{
return;
}
$this->redirect = $action->getAttribute('uri');
/** @var TAdminUI $page */
$page = Eresus_Kernel::app()->getPage();
$this->redirect = $page->replaceMacros($this->redirect);
} | php | protected function actionRedirect($action)
{
if ($this->redirect)
{
return;
}
$this->redirect = $action->getAttribute('uri');
/** @var TAdminUI $page */
$page = Eresus_Kernel::app()->getPage();
$this->redirect = $page->replaceMacros($this->redirect);
} | [
"protected",
"function",
"actionRedirect",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"redirect",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"redirect",
"=",
"$",
"action",
"->",
"getAttribute",
"(",
"'uri'",
")",
";",
"/** @var TAdminUI $page */",
"$",
"page",
"=",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
";",
"$",
"this",
"->",
"redirect",
"=",
"$",
"page",
"->",
"replaceMacros",
"(",
"$",
"this",
"->",
"redirect",
")",
";",
"}"
] | Process 'redirect' action
@param DOMElement $action | [
"Process",
"redirect",
"action"
] | cdbea1c4215864b739ff8c988b5de1672079389b | https://github.com/Eresus/EForms/blob/cdbea1c4215864b739ff8c988b5de1672079389b/src/eforms/classes/Form.php#L463-L474 |
6,124 | Eresus/EForms | src/eforms/classes/Form.php | EForms_Form.actionHtml | protected function actionHtml($action)
{
$elements = $action->childNodes;
if ($elements->length)
{
$html = '';
for ($i = 0; $i < $elements->length; $i++)
{
$html .= $this->xml->saveXML($elements->item($i));
}
$this->html .= $html;
}
} | php | protected function actionHtml($action)
{
$elements = $action->childNodes;
if ($elements->length)
{
$html = '';
for ($i = 0; $i < $elements->length; $i++)
{
$html .= $this->xml->saveXML($elements->item($i));
}
$this->html .= $html;
}
} | [
"protected",
"function",
"actionHtml",
"(",
"$",
"action",
")",
"{",
"$",
"elements",
"=",
"$",
"action",
"->",
"childNodes",
";",
"if",
"(",
"$",
"elements",
"->",
"length",
")",
"{",
"$",
"html",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"elements",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"xml",
"->",
"saveXML",
"(",
"$",
"elements",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"}",
"$",
"this",
"->",
"html",
".=",
"$",
"html",
";",
"}",
"}"
] | Process 'html' action
@param DOMElement $action | [
"Process",
"html",
"action"
] | cdbea1c4215864b739ff8c988b5de1672079389b | https://github.com/Eresus/EForms/blob/cdbea1c4215864b739ff8c988b5de1672079389b/src/eforms/classes/Form.php#L481-L494 |
6,125 | wisquimas/valleysofsorcery | admin/mf_posttype.php | mf_posttype.edit_post_type | public function edit_post_type() {
if(!isset($_GET['post_type']) ){
$this->mf_flash( 'Oops! something was wrong, you will be redirected a safe place in a few seconds' );
}
$post_type = $this->get_post_type($_GET['post_type']);
if( !$post_type ){
$this->mf_flash('error');
}else{
$data = $this->fields_form();
$post_type_support = array();
if( isset($post_type['support']) ){
foreach($post_type['support'] as $k => $v){
array_push($post_type_support,$k);
}
$data['posttype_support'] = $post_type_support;
}
$post_type_taxonomy = array();
if( isset($post_type['taxonomy']) ){
foreach($post_type['taxonomy'] as $k => $v){
array_push($post_type_taxonomy,$k);
}
$data['posttype_taxonomy'] = $post_type_taxonomy;
}
// update fields
$perm = array('core','option','label');
foreach($post_type as $key => $value){
if( in_array($key,$perm) ){
foreach($value as $id => $val){
$data[$key][$id]['value'] = $val;
}
}
}
$this->form_post_type($data);
}
} | php | public function edit_post_type() {
if(!isset($_GET['post_type']) ){
$this->mf_flash( 'Oops! something was wrong, you will be redirected a safe place in a few seconds' );
}
$post_type = $this->get_post_type($_GET['post_type']);
if( !$post_type ){
$this->mf_flash('error');
}else{
$data = $this->fields_form();
$post_type_support = array();
if( isset($post_type['support']) ){
foreach($post_type['support'] as $k => $v){
array_push($post_type_support,$k);
}
$data['posttype_support'] = $post_type_support;
}
$post_type_taxonomy = array();
if( isset($post_type['taxonomy']) ){
foreach($post_type['taxonomy'] as $k => $v){
array_push($post_type_taxonomy,$k);
}
$data['posttype_taxonomy'] = $post_type_taxonomy;
}
// update fields
$perm = array('core','option','label');
foreach($post_type as $key => $value){
if( in_array($key,$perm) ){
foreach($value as $id => $val){
$data[$key][$id]['value'] = $val;
}
}
}
$this->form_post_type($data);
}
} | [
"public",
"function",
"edit_post_type",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_GET",
"[",
"'post_type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"mf_flash",
"(",
"'Oops! something was wrong, you will be redirected a safe place in a few seconds'",
")",
";",
"}",
"$",
"post_type",
"=",
"$",
"this",
"->",
"get_post_type",
"(",
"$",
"_GET",
"[",
"'post_type'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"post_type",
")",
"{",
"$",
"this",
"->",
"mf_flash",
"(",
"'error'",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"fields_form",
"(",
")",
";",
"$",
"post_type_support",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"post_type",
"[",
"'support'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"post_type",
"[",
"'support'",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"array_push",
"(",
"$",
"post_type_support",
",",
"$",
"k",
")",
";",
"}",
"$",
"data",
"[",
"'posttype_support'",
"]",
"=",
"$",
"post_type_support",
";",
"}",
"$",
"post_type_taxonomy",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"post_type",
"[",
"'taxonomy'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"post_type",
"[",
"'taxonomy'",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"array_push",
"(",
"$",
"post_type_taxonomy",
",",
"$",
"k",
")",
";",
"}",
"$",
"data",
"[",
"'posttype_taxonomy'",
"]",
"=",
"$",
"post_type_taxonomy",
";",
"}",
"// update fields",
"$",
"perm",
"=",
"array",
"(",
"'core'",
",",
"'option'",
",",
"'label'",
")",
";",
"foreach",
"(",
"$",
"post_type",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"perm",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"id",
"=>",
"$",
"val",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"[",
"$",
"id",
"]",
"[",
"'value'",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"form_post_type",
"(",
"$",
"data",
")",
";",
"}",
"}"
] | Edit post type | [
"Edit",
"post",
"type"
] | 78a8d8f1d1102c5043e2cf7c98762e63464d2d7a | https://github.com/wisquimas/valleysofsorcery/blob/78a8d8f1d1102c5043e2cf7c98762e63464d2d7a/admin/mf_posttype.php#L372-L413 |
6,126 | wisquimas/valleysofsorcery | admin/mf_posttype.php | mf_posttype.save_post_type | public function save_post_type () {
global $mf_domain;
//checking the nonce
check_admin_referer('form_post_type_posttype');
//saving the posttype
if(isset($_POST['mf_posttype'])){
//check posttype_id
$mf = $_POST['mf_posttype'];
if($mf['core']['id']){
$this->update_post_type($mf);
}else{
if($this->new_posttype($mf)){
//redirect to dashboard
}else{
//reload form and show warning
}
}
$name = trim($mf['option']['capability_type']);
if( !in_array($name,array('post','page')) && !empty($name) ){
//register capabilities for admin
$this->_add_cap($name);
}
}
$this->mf_redirect("mf_posttype","update_rewrite",array("noheader" => "true"));
} | php | public function save_post_type () {
global $mf_domain;
//checking the nonce
check_admin_referer('form_post_type_posttype');
//saving the posttype
if(isset($_POST['mf_posttype'])){
//check posttype_id
$mf = $_POST['mf_posttype'];
if($mf['core']['id']){
$this->update_post_type($mf);
}else{
if($this->new_posttype($mf)){
//redirect to dashboard
}else{
//reload form and show warning
}
}
$name = trim($mf['option']['capability_type']);
if( !in_array($name,array('post','page')) && !empty($name) ){
//register capabilities for admin
$this->_add_cap($name);
}
}
$this->mf_redirect("mf_posttype","update_rewrite",array("noheader" => "true"));
} | [
"public",
"function",
"save_post_type",
"(",
")",
"{",
"global",
"$",
"mf_domain",
";",
"//checking the nonce",
"check_admin_referer",
"(",
"'form_post_type_posttype'",
")",
";",
"//saving the posttype",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'mf_posttype'",
"]",
")",
")",
"{",
"//check posttype_id",
"$",
"mf",
"=",
"$",
"_POST",
"[",
"'mf_posttype'",
"]",
";",
"if",
"(",
"$",
"mf",
"[",
"'core'",
"]",
"[",
"'id'",
"]",
")",
"{",
"$",
"this",
"->",
"update_post_type",
"(",
"$",
"mf",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"new_posttype",
"(",
"$",
"mf",
")",
")",
"{",
"//redirect to dashboard",
"}",
"else",
"{",
"//reload form and show warning",
"}",
"}",
"$",
"name",
"=",
"trim",
"(",
"$",
"mf",
"[",
"'option'",
"]",
"[",
"'capability_type'",
"]",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"array",
"(",
"'post'",
",",
"'page'",
")",
")",
"&&",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"//register capabilities for admin",
"$",
"this",
"->",
"_add_cap",
"(",
"$",
"name",
")",
";",
"}",
"}",
"$",
"this",
"->",
"mf_redirect",
"(",
"\"mf_posttype\"",
",",
"\"update_rewrite\"",
",",
"array",
"(",
"\"noheader\"",
"=>",
"\"true\"",
")",
")",
";",
"}"
] | Save a Post Type | [
"Save",
"a",
"Post",
"Type"
] | 78a8d8f1d1102c5043e2cf7c98762e63464d2d7a | https://github.com/wisquimas/valleysofsorcery/blob/78a8d8f1d1102c5043e2cf7c98762e63464d2d7a/admin/mf_posttype.php#L647-L674 |
6,127 | wisquimas/valleysofsorcery | admin/mf_posttype.php | mf_posttype._add_cap | public function _add_cap($name){
$caps = array(
'publish_posts' => sprintf('publish_%ss',$name),
'edit_posts' => sprintf('edit_%ss',$name),
'edit_others_posts' => sprintf('edit_others_%ss',$name),
'read_private_posts' => sprintf('read_private_%ss',$name),
'edit_post' => sprintf('edit_%s',$name),
'delete_post' => sprintf('delete_%s',$name),
'read_post' => sprintf('read_%s',$name)
);
$role = get_role('administrator');
if( !in_array($caps['edit_post'],array_keys($role->capabilities)) ){
foreach($caps as $cap){
$role->add_cap($cap);
}
}
} | php | public function _add_cap($name){
$caps = array(
'publish_posts' => sprintf('publish_%ss',$name),
'edit_posts' => sprintf('edit_%ss',$name),
'edit_others_posts' => sprintf('edit_others_%ss',$name),
'read_private_posts' => sprintf('read_private_%ss',$name),
'edit_post' => sprintf('edit_%s',$name),
'delete_post' => sprintf('delete_%s',$name),
'read_post' => sprintf('read_%s',$name)
);
$role = get_role('administrator');
if( !in_array($caps['edit_post'],array_keys($role->capabilities)) ){
foreach($caps as $cap){
$role->add_cap($cap);
}
}
} | [
"public",
"function",
"_add_cap",
"(",
"$",
"name",
")",
"{",
"$",
"caps",
"=",
"array",
"(",
"'publish_posts'",
"=>",
"sprintf",
"(",
"'publish_%ss'",
",",
"$",
"name",
")",
",",
"'edit_posts'",
"=>",
"sprintf",
"(",
"'edit_%ss'",
",",
"$",
"name",
")",
",",
"'edit_others_posts'",
"=>",
"sprintf",
"(",
"'edit_others_%ss'",
",",
"$",
"name",
")",
",",
"'read_private_posts'",
"=>",
"sprintf",
"(",
"'read_private_%ss'",
",",
"$",
"name",
")",
",",
"'edit_post'",
"=>",
"sprintf",
"(",
"'edit_%s'",
",",
"$",
"name",
")",
",",
"'delete_post'",
"=>",
"sprintf",
"(",
"'delete_%s'",
",",
"$",
"name",
")",
",",
"'read_post'",
"=>",
"sprintf",
"(",
"'read_%s'",
",",
"$",
"name",
")",
")",
";",
"$",
"role",
"=",
"get_role",
"(",
"'administrator'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"caps",
"[",
"'edit_post'",
"]",
",",
"array_keys",
"(",
"$",
"role",
"->",
"capabilities",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"caps",
"as",
"$",
"cap",
")",
"{",
"$",
"role",
"->",
"add_cap",
"(",
"$",
"cap",
")",
";",
"}",
"}",
"}"
] | Add a news Capabilities for Administrator | [
"Add",
"a",
"news",
"Capabilities",
"for",
"Administrator"
] | 78a8d8f1d1102c5043e2cf7c98762e63464d2d7a | https://github.com/wisquimas/valleysofsorcery/blob/78a8d8f1d1102c5043e2cf7c98762e63464d2d7a/admin/mf_posttype.php#L687-L706 |
6,128 | wisquimas/valleysofsorcery | admin/mf_posttype.php | mf_posttype.get_post_type | public function get_post_type($post_type){
global $wpdb;
$query = $wpdb->prepare( "SELECT * FROM ".MF_TABLE_POSTTYPES." WHERE type = %s", array( $post_type ) );
$post_type = $wpdb->get_row( $query, ARRAY_A );
if($post_type){
$post_type_id = $post_type['id'];
$post_type = unserialize($post_type['arguments']);
$post_type['core']['id'] = $post_type_id;
return $post_type;
}
return false;
} | php | public function get_post_type($post_type){
global $wpdb;
$query = $wpdb->prepare( "SELECT * FROM ".MF_TABLE_POSTTYPES." WHERE type = %s", array( $post_type ) );
$post_type = $wpdb->get_row( $query, ARRAY_A );
if($post_type){
$post_type_id = $post_type['id'];
$post_type = unserialize($post_type['arguments']);
$post_type['core']['id'] = $post_type_id;
return $post_type;
}
return false;
} | [
"public",
"function",
"get_post_type",
"(",
"$",
"post_type",
")",
"{",
"global",
"$",
"wpdb",
";",
"$",
"query",
"=",
"$",
"wpdb",
"->",
"prepare",
"(",
"\"SELECT * FROM \"",
".",
"MF_TABLE_POSTTYPES",
".",
"\" WHERE type = %s\"",
",",
"array",
"(",
"$",
"post_type",
")",
")",
";",
"$",
"post_type",
"=",
"$",
"wpdb",
"->",
"get_row",
"(",
"$",
"query",
",",
"ARRAY_A",
")",
";",
"if",
"(",
"$",
"post_type",
")",
"{",
"$",
"post_type_id",
"=",
"$",
"post_type",
"[",
"'id'",
"]",
";",
"$",
"post_type",
"=",
"unserialize",
"(",
"$",
"post_type",
"[",
"'arguments'",
"]",
")",
";",
"$",
"post_type",
"[",
"'core'",
"]",
"[",
"'id'",
"]",
"=",
"$",
"post_type_id",
";",
"return",
"$",
"post_type",
";",
"}",
"return",
"false",
";",
"}"
] | get a specific post type using the post_type_id or the post_type_name
@param mixed post_type, can be a integer or a string
@return array | [
"get",
"a",
"specific",
"post",
"type",
"using",
"the",
"post_type_id",
"or",
"the",
"post_type_name"
] | 78a8d8f1d1102c5043e2cf7c98762e63464d2d7a | https://github.com/wisquimas/valleysofsorcery/blob/78a8d8f1d1102c5043e2cf7c98762e63464d2d7a/admin/mf_posttype.php#L714-L727 |
6,129 | wisquimas/valleysofsorcery | admin/mf_posttype.php | mf_posttype.delete_post_type | public function delete_post_type(){
global $wpdb;
//checking the nonce
check_admin_referer('delete_post_type_mf_posttype');
if( isset($_GET['post_type']) ){
$post_type = $_GET['post_type'];
if( $post_type ){
$sql = $wpdb->prepare( "DELETE FROM ".MF_TABLE_POSTTYPES." WHERE type = '%s'",$post_type );
$wpdb->query($sql);
//delete all groups of post_type
$sql_fields = $wpdb->prepare( "DELETE FROM ".MF_TABLE_CUSTOM_GROUPS." WHERE post_type = '%s'",$post_type );
$wpdb->query($sql_fields);
//delete field of post_type
$sql_fields = $wpdb->prepare( "DELETE FROM ".MF_TABLE_CUSTOM_FIELDS." WHERE post_type = '%s'",$post_type );
$wpdb->query($sql_fields);
$this->mf_redirect(null,null,array('message' => 'success'));
}
}
} | php | public function delete_post_type(){
global $wpdb;
//checking the nonce
check_admin_referer('delete_post_type_mf_posttype');
if( isset($_GET['post_type']) ){
$post_type = $_GET['post_type'];
if( $post_type ){
$sql = $wpdb->prepare( "DELETE FROM ".MF_TABLE_POSTTYPES." WHERE type = '%s'",$post_type );
$wpdb->query($sql);
//delete all groups of post_type
$sql_fields = $wpdb->prepare( "DELETE FROM ".MF_TABLE_CUSTOM_GROUPS." WHERE post_type = '%s'",$post_type );
$wpdb->query($sql_fields);
//delete field of post_type
$sql_fields = $wpdb->prepare( "DELETE FROM ".MF_TABLE_CUSTOM_FIELDS." WHERE post_type = '%s'",$post_type );
$wpdb->query($sql_fields);
$this->mf_redirect(null,null,array('message' => 'success'));
}
}
} | [
"public",
"function",
"delete_post_type",
"(",
")",
"{",
"global",
"$",
"wpdb",
";",
"//checking the nonce",
"check_admin_referer",
"(",
"'delete_post_type_mf_posttype'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'post_type'",
"]",
")",
")",
"{",
"$",
"post_type",
"=",
"$",
"_GET",
"[",
"'post_type'",
"]",
";",
"if",
"(",
"$",
"post_type",
")",
"{",
"$",
"sql",
"=",
"$",
"wpdb",
"->",
"prepare",
"(",
"\"DELETE FROM \"",
".",
"MF_TABLE_POSTTYPES",
".",
"\" WHERE type = '%s'\"",
",",
"$",
"post_type",
")",
";",
"$",
"wpdb",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"//delete all groups of post_type",
"$",
"sql_fields",
"=",
"$",
"wpdb",
"->",
"prepare",
"(",
"\"DELETE FROM \"",
".",
"MF_TABLE_CUSTOM_GROUPS",
".",
"\" WHERE post_type = '%s'\"",
",",
"$",
"post_type",
")",
";",
"$",
"wpdb",
"->",
"query",
"(",
"$",
"sql_fields",
")",
";",
"//delete field of post_type",
"$",
"sql_fields",
"=",
"$",
"wpdb",
"->",
"prepare",
"(",
"\"DELETE FROM \"",
".",
"MF_TABLE_CUSTOM_FIELDS",
".",
"\" WHERE post_type = '%s'\"",
",",
"$",
"post_type",
")",
";",
"$",
"wpdb",
"->",
"query",
"(",
"$",
"sql_fields",
")",
";",
"$",
"this",
"->",
"mf_redirect",
"(",
"null",
",",
"null",
",",
"array",
"(",
"'message'",
"=>",
"'success'",
")",
")",
";",
"}",
"}",
"}"
] | delete a post type | [
"delete",
"a",
"post",
"type"
] | 78a8d8f1d1102c5043e2cf7c98762e63464d2d7a | https://github.com/wisquimas/valleysofsorcery/blob/78a8d8f1d1102c5043e2cf7c98762e63464d2d7a/admin/mf_posttype.php#L732-L757 |
6,130 | encorephp/config | src/FileLoader.php | FileLoader.findInPaths | protected function findInPaths(array $paths, $group, $mode = null, $exists = false)
{
$items = [];
foreach ($paths as $path) {
if ($this->fs->exists($file = "{$path}/{$group}.php")) {
if ($exists) return true;
$items = array_merge_recursive($this->fs->getRequire($file), $items);
}
if ($mode and $this->fs->exists($file = "{$path}/{$mode}/{$group}.php")) {
if ($exists) return true;
$items = array_merge_recursive($this->fs->getRequire($file), $items);
}
}
return $items;
} | php | protected function findInPaths(array $paths, $group, $mode = null, $exists = false)
{
$items = [];
foreach ($paths as $path) {
if ($this->fs->exists($file = "{$path}/{$group}.php")) {
if ($exists) return true;
$items = array_merge_recursive($this->fs->getRequire($file), $items);
}
if ($mode and $this->fs->exists($file = "{$path}/{$mode}/{$group}.php")) {
if ($exists) return true;
$items = array_merge_recursive($this->fs->getRequire($file), $items);
}
}
return $items;
} | [
"protected",
"function",
"findInPaths",
"(",
"array",
"$",
"paths",
",",
"$",
"group",
",",
"$",
"mode",
"=",
"null",
",",
"$",
"exists",
"=",
"false",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"file",
"=",
"\"{$path}/{$group}.php\"",
")",
")",
"{",
"if",
"(",
"$",
"exists",
")",
"return",
"true",
";",
"$",
"items",
"=",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"fs",
"->",
"getRequire",
"(",
"$",
"file",
")",
",",
"$",
"items",
")",
";",
"}",
"if",
"(",
"$",
"mode",
"and",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"file",
"=",
"\"{$path}/{$mode}/{$group}.php\"",
")",
")",
"{",
"if",
"(",
"$",
"exists",
")",
"return",
"true",
";",
"$",
"items",
"=",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"fs",
"->",
"getRequire",
"(",
"$",
"file",
")",
",",
"$",
"items",
")",
";",
"}",
"}",
"return",
"$",
"items",
";",
"}"
] | Get the path for the specified namespace
@param array $paths
@param string $group
@param string $mode
@param bool $exists
@return string | [
"Get",
"the",
"path",
"for",
"the",
"specified",
"namespace"
] | aa13e8f21068a1df5c21cec52b203c194d9fba59 | https://github.com/encorephp/config/blob/aa13e8f21068a1df5c21cec52b203c194d9fba59/src/FileLoader.php#L152-L171 |
6,131 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.FindFirstSets | function FindFirstSets()
{
for ($i = 0; $i < $this->nsymbol; $i++) {
$this->symbols[$i]->lambda = false;
}
for($i = $this->nterminal; $i < $this->nsymbol; $i++) {
$this->symbols[$i]->firstset = array();
}
/* First compute all lambdas */
do{
$progress = 0;
for ($rp = $this->rule; $rp; $rp = $rp->next) {
if ($rp->lhs->lambda) {
continue;
}
for ($i = 0; $i < $rp->nrhs; $i++) {
$sp = $rp->rhs[$i];
if ($sp->type != PHP_ParserGenerator_Symbol::TERMINAL || $sp->lambda === false) {
break;
}
}
if ($i === $rp->nrhs) {
$rp->lhs->lambda = true;
$progress = 1;
}
}
} while ($progress);
/* Now compute all first sets */
do {
$progress = 0;
for ($rp = $this->rule; $rp; $rp = $rp->next) {
$s1 = $rp->lhs;
for ($i = 0; $i < $rp->nrhs; $i++) {
$s2 = $rp->rhs[$i];
if ($s2->type == PHP_ParserGenerator_Symbol::TERMINAL) {
//progress += SetAdd(s1->firstset,s2->index);
$progress += isset($s1->firstset[$s2->index]) ? 0 : 1;
$s1->firstset[$s2->index] = 1;
break;
} elseif ($s2->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) {
for ($j = 0; $j < $s2->nsubsym; $j++) {
//progress += SetAdd(s1->firstset,s2->subsym[j]->index);
$progress += isset($s1->firstset[$s2->subsym[$j]->index]) ? 0 : 1;
$s1->firstset[$s2->subsym[$j]->index] = 1;
}
break;
} elseif ($s1 === $s2) {
if ($s1->lambda === false) {
break;
}
} else {
//progress += SetUnion(s1->firstset,s2->firstset);
$test = array_diff_key($s2->firstset, $s1->firstset);
if (count($test)) {
$progress++;
$s1->firstset += $test;
}
if ($s2->lambda === false) {
break;
}
}
}
}
} while ($progress);
} | php | function FindFirstSets()
{
for ($i = 0; $i < $this->nsymbol; $i++) {
$this->symbols[$i]->lambda = false;
}
for($i = $this->nterminal; $i < $this->nsymbol; $i++) {
$this->symbols[$i]->firstset = array();
}
/* First compute all lambdas */
do{
$progress = 0;
for ($rp = $this->rule; $rp; $rp = $rp->next) {
if ($rp->lhs->lambda) {
continue;
}
for ($i = 0; $i < $rp->nrhs; $i++) {
$sp = $rp->rhs[$i];
if ($sp->type != PHP_ParserGenerator_Symbol::TERMINAL || $sp->lambda === false) {
break;
}
}
if ($i === $rp->nrhs) {
$rp->lhs->lambda = true;
$progress = 1;
}
}
} while ($progress);
/* Now compute all first sets */
do {
$progress = 0;
for ($rp = $this->rule; $rp; $rp = $rp->next) {
$s1 = $rp->lhs;
for ($i = 0; $i < $rp->nrhs; $i++) {
$s2 = $rp->rhs[$i];
if ($s2->type == PHP_ParserGenerator_Symbol::TERMINAL) {
//progress += SetAdd(s1->firstset,s2->index);
$progress += isset($s1->firstset[$s2->index]) ? 0 : 1;
$s1->firstset[$s2->index] = 1;
break;
} elseif ($s2->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) {
for ($j = 0; $j < $s2->nsubsym; $j++) {
//progress += SetAdd(s1->firstset,s2->subsym[j]->index);
$progress += isset($s1->firstset[$s2->subsym[$j]->index]) ? 0 : 1;
$s1->firstset[$s2->subsym[$j]->index] = 1;
}
break;
} elseif ($s1 === $s2) {
if ($s1->lambda === false) {
break;
}
} else {
//progress += SetUnion(s1->firstset,s2->firstset);
$test = array_diff_key($s2->firstset, $s1->firstset);
if (count($test)) {
$progress++;
$s1->firstset += $test;
}
if ($s2->lambda === false) {
break;
}
}
}
}
} while ($progress);
} | [
"function",
"FindFirstSets",
"(",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nsymbol",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"symbols",
"[",
"$",
"i",
"]",
"->",
"lambda",
"=",
"false",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"$",
"this",
"->",
"nterminal",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nsymbol",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"symbols",
"[",
"$",
"i",
"]",
"->",
"firstset",
"=",
"array",
"(",
")",
";",
"}",
"/* First compute all lambdas */",
"do",
"{",
"$",
"progress",
"=",
"0",
";",
"for",
"(",
"$",
"rp",
"=",
"$",
"this",
"->",
"rule",
";",
"$",
"rp",
";",
"$",
"rp",
"=",
"$",
"rp",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"rp",
"->",
"lhs",
"->",
"lambda",
")",
"{",
"continue",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"rp",
"->",
"nrhs",
";",
"$",
"i",
"++",
")",
"{",
"$",
"sp",
"=",
"$",
"rp",
"->",
"rhs",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"sp",
"->",
"type",
"!=",
"PHP_ParserGenerator_Symbol",
"::",
"TERMINAL",
"||",
"$",
"sp",
"->",
"lambda",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"i",
"===",
"$",
"rp",
"->",
"nrhs",
")",
"{",
"$",
"rp",
"->",
"lhs",
"->",
"lambda",
"=",
"true",
";",
"$",
"progress",
"=",
"1",
";",
"}",
"}",
"}",
"while",
"(",
"$",
"progress",
")",
";",
"/* Now compute all first sets */",
"do",
"{",
"$",
"progress",
"=",
"0",
";",
"for",
"(",
"$",
"rp",
"=",
"$",
"this",
"->",
"rule",
";",
"$",
"rp",
";",
"$",
"rp",
"=",
"$",
"rp",
"->",
"next",
")",
"{",
"$",
"s1",
"=",
"$",
"rp",
"->",
"lhs",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"rp",
"->",
"nrhs",
";",
"$",
"i",
"++",
")",
"{",
"$",
"s2",
"=",
"$",
"rp",
"->",
"rhs",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"s2",
"->",
"type",
"==",
"PHP_ParserGenerator_Symbol",
"::",
"TERMINAL",
")",
"{",
"//progress += SetAdd(s1->firstset,s2->index);",
"$",
"progress",
"+=",
"isset",
"(",
"$",
"s1",
"->",
"firstset",
"[",
"$",
"s2",
"->",
"index",
"]",
")",
"?",
"0",
":",
"1",
";",
"$",
"s1",
"->",
"firstset",
"[",
"$",
"s2",
"->",
"index",
"]",
"=",
"1",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"s2",
"->",
"type",
"==",
"PHP_ParserGenerator_Symbol",
"::",
"MULTITERMINAL",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"s2",
"->",
"nsubsym",
";",
"$",
"j",
"++",
")",
"{",
"//progress += SetAdd(s1->firstset,s2->subsym[j]->index);",
"$",
"progress",
"+=",
"isset",
"(",
"$",
"s1",
"->",
"firstset",
"[",
"$",
"s2",
"->",
"subsym",
"[",
"$",
"j",
"]",
"->",
"index",
"]",
")",
"?",
"0",
":",
"1",
";",
"$",
"s1",
"->",
"firstset",
"[",
"$",
"s2",
"->",
"subsym",
"[",
"$",
"j",
"]",
"->",
"index",
"]",
"=",
"1",
";",
"}",
"break",
";",
"}",
"elseif",
"(",
"$",
"s1",
"===",
"$",
"s2",
")",
"{",
"if",
"(",
"$",
"s1",
"->",
"lambda",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"else",
"{",
"//progress += SetUnion(s1->firstset,s2->firstset);",
"$",
"test",
"=",
"array_diff_key",
"(",
"$",
"s2",
"->",
"firstset",
",",
"$",
"s1",
"->",
"firstset",
")",
";",
"if",
"(",
"count",
"(",
"$",
"test",
")",
")",
"{",
"$",
"progress",
"++",
";",
"$",
"s1",
"->",
"firstset",
"+=",
"$",
"test",
";",
"}",
"if",
"(",
"$",
"s2",
"->",
"lambda",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"while",
"(",
"$",
"progress",
")",
";",
"}"
] | Find all nonterminals which will generate the empty string.
Then go back and compute the first sets of every nonterminal.
The first set is the set of all terminal symbols which can begin
a string generated by that nonterminal. | [
"Find",
"all",
"nonterminals",
"which",
"will",
"generate",
"the",
"empty",
"string",
".",
"Then",
"go",
"back",
"and",
"compute",
"the",
"first",
"sets",
"of",
"every",
"nonterminal",
".",
"The",
"first",
"set",
"is",
"the",
"set",
"of",
"all",
"terminal",
"symbols",
"which",
"can",
"begin",
"a",
"string",
"generated",
"by",
"that",
"nonterminal",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L354-L420 |
6,132 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.buildshifts | private function buildshifts(PHP_ParserGenerator_State $stp)
{
// struct config *cfp; /* For looping thru the config closure of "stp" */
// struct config *bcfp; /* For the inner loop on config closure of "stp" */
// struct config *new; /* */
// struct symbol *sp; /* Symbol following the dot in configuration "cfp" */
// struct symbol *bsp; /* Symbol following the dot in configuration "bcfp" */
// struct state *newstp; /* A pointer to a successor state */
/* Each configuration becomes complete after it contibutes to a successor
** state. Initially, all configurations are incomplete */
$cfp = $stp->cfp;
for ($cfp = $stp->cfp; $cfp; $cfp = $cfp->next) {
$cfp->status = PHP_ParserGenerator_Config::INCOMPLETE;
}
/* Loop through all configurations of the state "stp" */
for ($cfp = $stp->cfp; $cfp; $cfp = $cfp->next) {
if ($cfp->status == PHP_ParserGenerator_Config::COMPLETE) {
continue; /* Already used by inner loop */
}
if ($cfp->dot >= $cfp->rp->nrhs) {
continue; /* Can't shift this config */
}
PHP_ParserGenerator_Config::Configlist_reset(); /* Reset the new config set */
$sp = $cfp->rp->rhs[$cfp->dot]; /* Symbol after the dot */
/* For every configuration in the state "stp" which has the symbol "sp"
** following its dot, add the same configuration to the basis set under
** construction but with the dot shifted one symbol to the right. */
$bcfp = $cfp;
for ($bcfp = $cfp; $bcfp; $bcfp = $bcfp->next) {
if ($bcfp->status == PHP_ParserGenerator_Config::COMPLETE) {
continue; /* Already used */
}
if ($bcfp->dot >= $bcfp->rp->nrhs) {
continue; /* Can't shift this one */
}
$bsp = $bcfp->rp->rhs[$bcfp->dot]; /* Get symbol after dot */
if (!PHP_ParserGenerator_Symbol::same_symbol($bsp, $sp)) {
continue; /* Must be same as for "cfp" */
}
$bcfp->status = PHP_ParserGenerator_Config::COMPLETE; /* Mark this config as used */
$new = PHP_ParserGenerator_Config::Configlist_addbasis($bcfp->rp, $bcfp->dot + 1);
PHP_ParserGenerator_PropagationLink::Plink_add($new->bplp, $bcfp);
}
/* Get a pointer to the state described by the basis configuration set
** constructed in the preceding loop */
$newstp = $this->getstate();
if (is_array($newstp)) {
$this->buildshifts($newstp[0]); /* Recursively compute successor states */
$newstp = $newstp[0];
}
/* The state "newstp" is reached from the state "stp" by a shift action
** on the symbol "sp" */
if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) {
for($i = 0; $i < $sp->nsubsym; $i++) {
PHP_ParserGenerator_Action::Action_add($stp->ap, PHP_ParserGenerator_Action::SHIFT, $sp->subsym[$i],
$newstp);
}
} else {
PHP_ParserGenerator_Action::Action_add($stp->ap, PHP_ParserGenerator_Action::SHIFT, $sp, $newstp);
}
}
} | php | private function buildshifts(PHP_ParserGenerator_State $stp)
{
// struct config *cfp; /* For looping thru the config closure of "stp" */
// struct config *bcfp; /* For the inner loop on config closure of "stp" */
// struct config *new; /* */
// struct symbol *sp; /* Symbol following the dot in configuration "cfp" */
// struct symbol *bsp; /* Symbol following the dot in configuration "bcfp" */
// struct state *newstp; /* A pointer to a successor state */
/* Each configuration becomes complete after it contibutes to a successor
** state. Initially, all configurations are incomplete */
$cfp = $stp->cfp;
for ($cfp = $stp->cfp; $cfp; $cfp = $cfp->next) {
$cfp->status = PHP_ParserGenerator_Config::INCOMPLETE;
}
/* Loop through all configurations of the state "stp" */
for ($cfp = $stp->cfp; $cfp; $cfp = $cfp->next) {
if ($cfp->status == PHP_ParserGenerator_Config::COMPLETE) {
continue; /* Already used by inner loop */
}
if ($cfp->dot >= $cfp->rp->nrhs) {
continue; /* Can't shift this config */
}
PHP_ParserGenerator_Config::Configlist_reset(); /* Reset the new config set */
$sp = $cfp->rp->rhs[$cfp->dot]; /* Symbol after the dot */
/* For every configuration in the state "stp" which has the symbol "sp"
** following its dot, add the same configuration to the basis set under
** construction but with the dot shifted one symbol to the right. */
$bcfp = $cfp;
for ($bcfp = $cfp; $bcfp; $bcfp = $bcfp->next) {
if ($bcfp->status == PHP_ParserGenerator_Config::COMPLETE) {
continue; /* Already used */
}
if ($bcfp->dot >= $bcfp->rp->nrhs) {
continue; /* Can't shift this one */
}
$bsp = $bcfp->rp->rhs[$bcfp->dot]; /* Get symbol after dot */
if (!PHP_ParserGenerator_Symbol::same_symbol($bsp, $sp)) {
continue; /* Must be same as for "cfp" */
}
$bcfp->status = PHP_ParserGenerator_Config::COMPLETE; /* Mark this config as used */
$new = PHP_ParserGenerator_Config::Configlist_addbasis($bcfp->rp, $bcfp->dot + 1);
PHP_ParserGenerator_PropagationLink::Plink_add($new->bplp, $bcfp);
}
/* Get a pointer to the state described by the basis configuration set
** constructed in the preceding loop */
$newstp = $this->getstate();
if (is_array($newstp)) {
$this->buildshifts($newstp[0]); /* Recursively compute successor states */
$newstp = $newstp[0];
}
/* The state "newstp" is reached from the state "stp" by a shift action
** on the symbol "sp" */
if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) {
for($i = 0; $i < $sp->nsubsym; $i++) {
PHP_ParserGenerator_Action::Action_add($stp->ap, PHP_ParserGenerator_Action::SHIFT, $sp->subsym[$i],
$newstp);
}
} else {
PHP_ParserGenerator_Action::Action_add($stp->ap, PHP_ParserGenerator_Action::SHIFT, $sp, $newstp);
}
}
} | [
"private",
"function",
"buildshifts",
"(",
"PHP_ParserGenerator_State",
"$",
"stp",
")",
"{",
"// struct config *cfp; /* For looping thru the config closure of \"stp\" */",
"// struct config *bcfp; /* For the inner loop on config closure of \"stp\" */",
"// struct config *new; /* */",
"// struct symbol *sp; /* Symbol following the dot in configuration \"cfp\" */",
"// struct symbol *bsp; /* Symbol following the dot in configuration \"bcfp\" */",
"// struct state *newstp; /* A pointer to a successor state */",
"/* Each configuration becomes complete after it contibutes to a successor\n ** state. Initially, all configurations are incomplete */",
"$",
"cfp",
"=",
"$",
"stp",
"->",
"cfp",
";",
"for",
"(",
"$",
"cfp",
"=",
"$",
"stp",
"->",
"cfp",
";",
"$",
"cfp",
";",
"$",
"cfp",
"=",
"$",
"cfp",
"->",
"next",
")",
"{",
"$",
"cfp",
"->",
"status",
"=",
"PHP_ParserGenerator_Config",
"::",
"INCOMPLETE",
";",
"}",
"/* Loop through all configurations of the state \"stp\" */",
"for",
"(",
"$",
"cfp",
"=",
"$",
"stp",
"->",
"cfp",
";",
"$",
"cfp",
";",
"$",
"cfp",
"=",
"$",
"cfp",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"cfp",
"->",
"status",
"==",
"PHP_ParserGenerator_Config",
"::",
"COMPLETE",
")",
"{",
"continue",
";",
"/* Already used by inner loop */",
"}",
"if",
"(",
"$",
"cfp",
"->",
"dot",
">=",
"$",
"cfp",
"->",
"rp",
"->",
"nrhs",
")",
"{",
"continue",
";",
"/* Can't shift this config */",
"}",
"PHP_ParserGenerator_Config",
"::",
"Configlist_reset",
"(",
")",
";",
"/* Reset the new config set */",
"$",
"sp",
"=",
"$",
"cfp",
"->",
"rp",
"->",
"rhs",
"[",
"$",
"cfp",
"->",
"dot",
"]",
";",
"/* Symbol after the dot */",
"/* For every configuration in the state \"stp\" which has the symbol \"sp\"\n ** following its dot, add the same configuration to the basis set under\n ** construction but with the dot shifted one symbol to the right. */",
"$",
"bcfp",
"=",
"$",
"cfp",
";",
"for",
"(",
"$",
"bcfp",
"=",
"$",
"cfp",
";",
"$",
"bcfp",
";",
"$",
"bcfp",
"=",
"$",
"bcfp",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"bcfp",
"->",
"status",
"==",
"PHP_ParserGenerator_Config",
"::",
"COMPLETE",
")",
"{",
"continue",
";",
"/* Already used */",
"}",
"if",
"(",
"$",
"bcfp",
"->",
"dot",
">=",
"$",
"bcfp",
"->",
"rp",
"->",
"nrhs",
")",
"{",
"continue",
";",
"/* Can't shift this one */",
"}",
"$",
"bsp",
"=",
"$",
"bcfp",
"->",
"rp",
"->",
"rhs",
"[",
"$",
"bcfp",
"->",
"dot",
"]",
";",
"/* Get symbol after dot */",
"if",
"(",
"!",
"PHP_ParserGenerator_Symbol",
"::",
"same_symbol",
"(",
"$",
"bsp",
",",
"$",
"sp",
")",
")",
"{",
"continue",
";",
"/* Must be same as for \"cfp\" */",
"}",
"$",
"bcfp",
"->",
"status",
"=",
"PHP_ParserGenerator_Config",
"::",
"COMPLETE",
";",
"/* Mark this config as used */",
"$",
"new",
"=",
"PHP_ParserGenerator_Config",
"::",
"Configlist_addbasis",
"(",
"$",
"bcfp",
"->",
"rp",
",",
"$",
"bcfp",
"->",
"dot",
"+",
"1",
")",
";",
"PHP_ParserGenerator_PropagationLink",
"::",
"Plink_add",
"(",
"$",
"new",
"->",
"bplp",
",",
"$",
"bcfp",
")",
";",
"}",
"/* Get a pointer to the state described by the basis configuration set\n ** constructed in the preceding loop */",
"$",
"newstp",
"=",
"$",
"this",
"->",
"getstate",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"newstp",
")",
")",
"{",
"$",
"this",
"->",
"buildshifts",
"(",
"$",
"newstp",
"[",
"0",
"]",
")",
";",
"/* Recursively compute successor states */",
"$",
"newstp",
"=",
"$",
"newstp",
"[",
"0",
"]",
";",
"}",
"/* The state \"newstp\" is reached from the state \"stp\" by a shift action\n ** on the symbol \"sp\" */",
"if",
"(",
"$",
"sp",
"->",
"type",
"==",
"PHP_ParserGenerator_Symbol",
"::",
"MULTITERMINAL",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"sp",
"->",
"nsubsym",
";",
"$",
"i",
"++",
")",
"{",
"PHP_ParserGenerator_Action",
"::",
"Action_add",
"(",
"$",
"stp",
"->",
"ap",
",",
"PHP_ParserGenerator_Action",
"::",
"SHIFT",
",",
"$",
"sp",
"->",
"subsym",
"[",
"$",
"i",
"]",
",",
"$",
"newstp",
")",
";",
"}",
"}",
"else",
"{",
"PHP_ParserGenerator_Action",
"::",
"Action_add",
"(",
"$",
"stp",
"->",
"ap",
",",
"PHP_ParserGenerator_Action",
"::",
"SHIFT",
",",
"$",
"sp",
",",
"$",
"newstp",
")",
";",
"}",
"}",
"}"
] | Construct all successor states to the given state. A "successor"
state is any state which can be reached by a shift action.
@param PHP_ParserGenerator_Data
@param PHP_ParserGenerator_State The state from which successors are computed | [
"Construct",
"all",
"successor",
"states",
"to",
"the",
"given",
"state",
".",
"A",
"successor",
"state",
"is",
"any",
"state",
"which",
"can",
"be",
"reached",
"by",
"a",
"shift",
"action",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L536-L602 |
6,133 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.FindLinks | function FindLinks()
{
/* Housekeeping detail:
** Add to every propagate link a pointer back to the state to
** which the link is attached. */
foreach ($this->sorted as $info) {
$info->key->stp = $info->data;
}
/* Convert all backlinks into forward links. Only the forward
** links are used in the follow-set computation. */
for ($i = 0; $i < $this->nstate; $i++) {
$stp = $this->sorted[$i];
for ($cfp = $stp->data->cfp; $cfp; $cfp = $cfp->next) {
for ($plp = $cfp->bplp; $plp; $plp = $plp->next) {
$other = $plp->cfp;
PHP_ParserGenerator_PropagationLink::Plink_add($other->fplp, $cfp);
}
}
}
} | php | function FindLinks()
{
/* Housekeeping detail:
** Add to every propagate link a pointer back to the state to
** which the link is attached. */
foreach ($this->sorted as $info) {
$info->key->stp = $info->data;
}
/* Convert all backlinks into forward links. Only the forward
** links are used in the follow-set computation. */
for ($i = 0; $i < $this->nstate; $i++) {
$stp = $this->sorted[$i];
for ($cfp = $stp->data->cfp; $cfp; $cfp = $cfp->next) {
for ($plp = $cfp->bplp; $plp; $plp = $plp->next) {
$other = $plp->cfp;
PHP_ParserGenerator_PropagationLink::Plink_add($other->fplp, $cfp);
}
}
}
} | [
"function",
"FindLinks",
"(",
")",
"{",
"/* Housekeeping detail:\n ** Add to every propagate link a pointer back to the state to\n ** which the link is attached. */",
"foreach",
"(",
"$",
"this",
"->",
"sorted",
"as",
"$",
"info",
")",
"{",
"$",
"info",
"->",
"key",
"->",
"stp",
"=",
"$",
"info",
"->",
"data",
";",
"}",
"/* Convert all backlinks into forward links. Only the forward\n ** links are used in the follow-set computation. */",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nstate",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stp",
"=",
"$",
"this",
"->",
"sorted",
"[",
"$",
"i",
"]",
";",
"for",
"(",
"$",
"cfp",
"=",
"$",
"stp",
"->",
"data",
"->",
"cfp",
";",
"$",
"cfp",
";",
"$",
"cfp",
"=",
"$",
"cfp",
"->",
"next",
")",
"{",
"for",
"(",
"$",
"plp",
"=",
"$",
"cfp",
"->",
"bplp",
";",
"$",
"plp",
";",
"$",
"plp",
"=",
"$",
"plp",
"->",
"next",
")",
"{",
"$",
"other",
"=",
"$",
"plp",
"->",
"cfp",
";",
"PHP_ParserGenerator_PropagationLink",
"::",
"Plink_add",
"(",
"$",
"other",
"->",
"fplp",
",",
"$",
"cfp",
")",
";",
"}",
"}",
"}",
"}"
] | Construct the propagation links | [
"Construct",
"the",
"propagation",
"links"
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L607-L627 |
6,134 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.resolve_conflict | function resolve_conflict($apx, $apy, $errsym)
{
$errcnt = 0;
if ($apx->sp !== $apy->sp) {
throw new Exception('no conflict but resolve_conflict called');
}
if ($apx->type == PHP_ParserGenerator_Action::SHIFT && $apy->type == PHP_ParserGenerator_Action::REDUCE) {
$spx = $apx->sp;
$spy = $apy->x->precsym;
if ($spy === 0 || $spx->prec < 0 || $spy->prec < 0) {
/* Not enough precedence information. */
$apy->type = PHP_ParserGenerator_Action::CONFLICT;
$errcnt++;
} elseif ($spx->prec > $spy->prec) { /* Lower precedence wins */
$apy->type = PHP_ParserGenerator_Action::RD_RESOLVED;
} elseif ($spx->prec < $spy->prec) {
$apx->type = PHP_ParserGenerator_Action::SH_RESOLVED;
} elseif ($spx->prec === $spy->prec && $spx->assoc == PHP_ParserGenerator_Symbol::RIGHT) {
/* Use operator */
$apy->type = PHP_ParserGenerator_Action::RD_RESOLVED; /* associativity */
} elseif ($spx->prec === $spy->prec && $spx->assoc == PHP_ParserGenerator_Symbol::LEFT) {
/* to break tie */
$apx->type = PHP_ParserGenerator_Action::SH_RESOLVED;
} else {
if ($spx->prec !== $spy->prec || $spx->assoc !== PHP_ParserGenerator_Symbol::NONE) {
throw new Exception('$spx->prec !== $spy->prec || $spx->assoc !== PHP_ParserGenerator_Symbol::NONE');
}
$apy->type = PHP_ParserGenerator_Action::CONFLICT;
$errcnt++;
}
} elseif ($apx->type == PHP_ParserGenerator_Action::REDUCE && $apy->type == PHP_ParserGenerator_Action::REDUCE) {
$spx = $apx->x->precsym;
$spy = $apy->x->precsym;
if ($spx === 0 || $spy === 0 || $spx->prec < 0 ||
$spy->prec < 0 || $spx->prec === $spy->prec) {
$apy->type = PHP_ParserGenerator_Action::CONFLICT;
$errcnt++;
} elseif ($spx->prec > $spy->prec) {
$apy->type = PHP_ParserGenerator_Action::RD_RESOLVED;
} elseif ($spx->prec < $spy->prec) {
$apx->type = PHP_ParserGenerator_Action::RD_RESOLVED;
}
} else {
if ($apx->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&
$apx->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&
$apx->type!== PHP_ParserGenerator_Action::CONFLICT &&
$apy->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&
$apy->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&
$apy->type!== PHP_ParserGenerator_Action::CONFLICT) {
throw new Exception('$apx->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&
$apx->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&
$apx->type!== PHP_ParserGenerator_Action::CONFLICT &&
$apy->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&
$apy->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&
$apy->type!== PHP_ParserGenerator_Action::CONFLICT');
}
/* The REDUCE/SHIFT case cannot happen because SHIFTs come before
** REDUCEs on the list. If we reach this point it must be because
** the parser conflict had already been resolved. */
}
return $errcnt;
} | php | function resolve_conflict($apx, $apy, $errsym)
{
$errcnt = 0;
if ($apx->sp !== $apy->sp) {
throw new Exception('no conflict but resolve_conflict called');
}
if ($apx->type == PHP_ParserGenerator_Action::SHIFT && $apy->type == PHP_ParserGenerator_Action::REDUCE) {
$spx = $apx->sp;
$spy = $apy->x->precsym;
if ($spy === 0 || $spx->prec < 0 || $spy->prec < 0) {
/* Not enough precedence information. */
$apy->type = PHP_ParserGenerator_Action::CONFLICT;
$errcnt++;
} elseif ($spx->prec > $spy->prec) { /* Lower precedence wins */
$apy->type = PHP_ParserGenerator_Action::RD_RESOLVED;
} elseif ($spx->prec < $spy->prec) {
$apx->type = PHP_ParserGenerator_Action::SH_RESOLVED;
} elseif ($spx->prec === $spy->prec && $spx->assoc == PHP_ParserGenerator_Symbol::RIGHT) {
/* Use operator */
$apy->type = PHP_ParserGenerator_Action::RD_RESOLVED; /* associativity */
} elseif ($spx->prec === $spy->prec && $spx->assoc == PHP_ParserGenerator_Symbol::LEFT) {
/* to break tie */
$apx->type = PHP_ParserGenerator_Action::SH_RESOLVED;
} else {
if ($spx->prec !== $spy->prec || $spx->assoc !== PHP_ParserGenerator_Symbol::NONE) {
throw new Exception('$spx->prec !== $spy->prec || $spx->assoc !== PHP_ParserGenerator_Symbol::NONE');
}
$apy->type = PHP_ParserGenerator_Action::CONFLICT;
$errcnt++;
}
} elseif ($apx->type == PHP_ParserGenerator_Action::REDUCE && $apy->type == PHP_ParserGenerator_Action::REDUCE) {
$spx = $apx->x->precsym;
$spy = $apy->x->precsym;
if ($spx === 0 || $spy === 0 || $spx->prec < 0 ||
$spy->prec < 0 || $spx->prec === $spy->prec) {
$apy->type = PHP_ParserGenerator_Action::CONFLICT;
$errcnt++;
} elseif ($spx->prec > $spy->prec) {
$apy->type = PHP_ParserGenerator_Action::RD_RESOLVED;
} elseif ($spx->prec < $spy->prec) {
$apx->type = PHP_ParserGenerator_Action::RD_RESOLVED;
}
} else {
if ($apx->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&
$apx->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&
$apx->type!== PHP_ParserGenerator_Action::CONFLICT &&
$apy->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&
$apy->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&
$apy->type!== PHP_ParserGenerator_Action::CONFLICT) {
throw new Exception('$apx->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&
$apx->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&
$apx->type!== PHP_ParserGenerator_Action::CONFLICT &&
$apy->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&
$apy->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&
$apy->type!== PHP_ParserGenerator_Action::CONFLICT');
}
/* The REDUCE/SHIFT case cannot happen because SHIFTs come before
** REDUCEs on the list. If we reach this point it must be because
** the parser conflict had already been resolved. */
}
return $errcnt;
} | [
"function",
"resolve_conflict",
"(",
"$",
"apx",
",",
"$",
"apy",
",",
"$",
"errsym",
")",
"{",
"$",
"errcnt",
"=",
"0",
";",
"if",
"(",
"$",
"apx",
"->",
"sp",
"!==",
"$",
"apy",
"->",
"sp",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'no conflict but resolve_conflict called'",
")",
";",
"}",
"if",
"(",
"$",
"apx",
"->",
"type",
"==",
"PHP_ParserGenerator_Action",
"::",
"SHIFT",
"&&",
"$",
"apy",
"->",
"type",
"==",
"PHP_ParserGenerator_Action",
"::",
"REDUCE",
")",
"{",
"$",
"spx",
"=",
"$",
"apx",
"->",
"sp",
";",
"$",
"spy",
"=",
"$",
"apy",
"->",
"x",
"->",
"precsym",
";",
"if",
"(",
"$",
"spy",
"===",
"0",
"||",
"$",
"spx",
"->",
"prec",
"<",
"0",
"||",
"$",
"spy",
"->",
"prec",
"<",
"0",
")",
"{",
"/* Not enough precedence information. */",
"$",
"apy",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"CONFLICT",
";",
"$",
"errcnt",
"++",
";",
"}",
"elseif",
"(",
"$",
"spx",
"->",
"prec",
">",
"$",
"spy",
"->",
"prec",
")",
"{",
"/* Lower precedence wins */",
"$",
"apy",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"RD_RESOLVED",
";",
"}",
"elseif",
"(",
"$",
"spx",
"->",
"prec",
"<",
"$",
"spy",
"->",
"prec",
")",
"{",
"$",
"apx",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"SH_RESOLVED",
";",
"}",
"elseif",
"(",
"$",
"spx",
"->",
"prec",
"===",
"$",
"spy",
"->",
"prec",
"&&",
"$",
"spx",
"->",
"assoc",
"==",
"PHP_ParserGenerator_Symbol",
"::",
"RIGHT",
")",
"{",
"/* Use operator */",
"$",
"apy",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"RD_RESOLVED",
";",
"/* associativity */",
"}",
"elseif",
"(",
"$",
"spx",
"->",
"prec",
"===",
"$",
"spy",
"->",
"prec",
"&&",
"$",
"spx",
"->",
"assoc",
"==",
"PHP_ParserGenerator_Symbol",
"::",
"LEFT",
")",
"{",
"/* to break tie */",
"$",
"apx",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"SH_RESOLVED",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"spx",
"->",
"prec",
"!==",
"$",
"spy",
"->",
"prec",
"||",
"$",
"spx",
"->",
"assoc",
"!==",
"PHP_ParserGenerator_Symbol",
"::",
"NONE",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'$spx->prec !== $spy->prec || $spx->assoc !== PHP_ParserGenerator_Symbol::NONE'",
")",
";",
"}",
"$",
"apy",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"CONFLICT",
";",
"$",
"errcnt",
"++",
";",
"}",
"}",
"elseif",
"(",
"$",
"apx",
"->",
"type",
"==",
"PHP_ParserGenerator_Action",
"::",
"REDUCE",
"&&",
"$",
"apy",
"->",
"type",
"==",
"PHP_ParserGenerator_Action",
"::",
"REDUCE",
")",
"{",
"$",
"spx",
"=",
"$",
"apx",
"->",
"x",
"->",
"precsym",
";",
"$",
"spy",
"=",
"$",
"apy",
"->",
"x",
"->",
"precsym",
";",
"if",
"(",
"$",
"spx",
"===",
"0",
"||",
"$",
"spy",
"===",
"0",
"||",
"$",
"spx",
"->",
"prec",
"<",
"0",
"||",
"$",
"spy",
"->",
"prec",
"<",
"0",
"||",
"$",
"spx",
"->",
"prec",
"===",
"$",
"spy",
"->",
"prec",
")",
"{",
"$",
"apy",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"CONFLICT",
";",
"$",
"errcnt",
"++",
";",
"}",
"elseif",
"(",
"$",
"spx",
"->",
"prec",
">",
"$",
"spy",
"->",
"prec",
")",
"{",
"$",
"apy",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"RD_RESOLVED",
";",
"}",
"elseif",
"(",
"$",
"spx",
"->",
"prec",
"<",
"$",
"spy",
"->",
"prec",
")",
"{",
"$",
"apx",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"RD_RESOLVED",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"apx",
"->",
"type",
"!==",
"PHP_ParserGenerator_Action",
"::",
"SH_RESOLVED",
"&&",
"$",
"apx",
"->",
"type",
"!==",
"PHP_ParserGenerator_Action",
"::",
"RD_RESOLVED",
"&&",
"$",
"apx",
"->",
"type",
"!==",
"PHP_ParserGenerator_Action",
"::",
"CONFLICT",
"&&",
"$",
"apy",
"->",
"type",
"!==",
"PHP_ParserGenerator_Action",
"::",
"SH_RESOLVED",
"&&",
"$",
"apy",
"->",
"type",
"!==",
"PHP_ParserGenerator_Action",
"::",
"RD_RESOLVED",
"&&",
"$",
"apy",
"->",
"type",
"!==",
"PHP_ParserGenerator_Action",
"::",
"CONFLICT",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'$apx->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&\n $apx->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&\n $apx->type!== PHP_ParserGenerator_Action::CONFLICT &&\n $apy->type!== PHP_ParserGenerator_Action::SH_RESOLVED &&\n $apy->type!== PHP_ParserGenerator_Action::RD_RESOLVED &&\n $apy->type!== PHP_ParserGenerator_Action::CONFLICT'",
")",
";",
"}",
"/* The REDUCE/SHIFT case cannot happen because SHIFTs come before\n ** REDUCEs on the list. If we reach this point it must be because\n ** the parser conflict had already been resolved. */",
"}",
"return",
"$",
"errcnt",
";",
"}"
] | Resolve a conflict between the two given actions. If the
conflict can't be resolve, return non-zero.
NO LONGER TRUE:
To resolve a conflict, first look to see if either action
is on an error rule. In that case, take the action which
is not associated with the error rule. If neither or both
actions are associated with an error rule, then try to
use precedence to resolve the conflict.
If either action is a SHIFT, then it must be apx. This
function won't work if apx->type==REDUCE and apy->type==SHIFT.
@param PHP_ParserGenerator_Action
@param PHP_ParserGenerator_Action
@param PHP_ParserGenerator_Symbol|null The error symbol (if defined. NULL otherwise) | [
"Resolve",
"a",
"conflict",
"between",
"the",
"two",
"given",
"actions",
".",
"If",
"the",
"conflict",
"can",
"t",
"be",
"resolve",
"return",
"non",
"-",
"zero",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L728-L789 |
6,135 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.CompressTables | function CompressTables()
{
for ($i = 0; $i < $this->nstate; $i++) {
$stp = $this->sorted[$i]->data;
$nbest = 0;
$rbest = 0;
for ($ap = $stp->ap; $ap; $ap = $ap->next) {
if ($ap->type != PHP_ParserGenerator_Action::REDUCE) {
continue;
}
$rp = $ap->x;
if ($rp === $rbest) {
continue;
}
$n = 1;
for ($ap2 = $ap->next; $ap2; $ap2 = $ap2->next) {
if ($ap2->type != PHP_ParserGenerator_Action::REDUCE) {
continue;
}
$rp2 = $ap2->x;
if ($rp2 === $rbest) {
continue;
}
if ($rp2 === $rp) {
$n++;
}
}
if ($n > $nbest) {
$nbest = $n;
$rbest = $rp;
}
}
/* Do not make a default if the number of rules to default
** is not at least 1 */
if ($nbest < 1) {
continue;
}
/* Combine matching REDUCE actions into a single default */
for ($ap = $stp->ap; $ap; $ap = $ap->next) {
if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) {
break;
}
}
if ($ap === 0) {
throw new Exception('$ap is not an object');
}
$ap->sp = PHP_ParserGenerator_Symbol::Symbol_new("{default}");
for ($ap = $ap->next; $ap; $ap = $ap->next) {
if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) {
$ap->type = PHP_ParserGenerator_Action::NOT_USED;
}
}
$stp->ap = PHP_ParserGenerator_Action::Action_sort($stp->ap);
}
} | php | function CompressTables()
{
for ($i = 0; $i < $this->nstate; $i++) {
$stp = $this->sorted[$i]->data;
$nbest = 0;
$rbest = 0;
for ($ap = $stp->ap; $ap; $ap = $ap->next) {
if ($ap->type != PHP_ParserGenerator_Action::REDUCE) {
continue;
}
$rp = $ap->x;
if ($rp === $rbest) {
continue;
}
$n = 1;
for ($ap2 = $ap->next; $ap2; $ap2 = $ap2->next) {
if ($ap2->type != PHP_ParserGenerator_Action::REDUCE) {
continue;
}
$rp2 = $ap2->x;
if ($rp2 === $rbest) {
continue;
}
if ($rp2 === $rp) {
$n++;
}
}
if ($n > $nbest) {
$nbest = $n;
$rbest = $rp;
}
}
/* Do not make a default if the number of rules to default
** is not at least 1 */
if ($nbest < 1) {
continue;
}
/* Combine matching REDUCE actions into a single default */
for ($ap = $stp->ap; $ap; $ap = $ap->next) {
if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) {
break;
}
}
if ($ap === 0) {
throw new Exception('$ap is not an object');
}
$ap->sp = PHP_ParserGenerator_Symbol::Symbol_new("{default}");
for ($ap = $ap->next; $ap; $ap = $ap->next) {
if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) {
$ap->type = PHP_ParserGenerator_Action::NOT_USED;
}
}
$stp->ap = PHP_ParserGenerator_Action::Action_sort($stp->ap);
}
} | [
"function",
"CompressTables",
"(",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nstate",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stp",
"=",
"$",
"this",
"->",
"sorted",
"[",
"$",
"i",
"]",
"->",
"data",
";",
"$",
"nbest",
"=",
"0",
";",
"$",
"rbest",
"=",
"0",
";",
"for",
"(",
"$",
"ap",
"=",
"$",
"stp",
"->",
"ap",
";",
"$",
"ap",
";",
"$",
"ap",
"=",
"$",
"ap",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"ap",
"->",
"type",
"!=",
"PHP_ParserGenerator_Action",
"::",
"REDUCE",
")",
"{",
"continue",
";",
"}",
"$",
"rp",
"=",
"$",
"ap",
"->",
"x",
";",
"if",
"(",
"$",
"rp",
"===",
"$",
"rbest",
")",
"{",
"continue",
";",
"}",
"$",
"n",
"=",
"1",
";",
"for",
"(",
"$",
"ap2",
"=",
"$",
"ap",
"->",
"next",
";",
"$",
"ap2",
";",
"$",
"ap2",
"=",
"$",
"ap2",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"ap2",
"->",
"type",
"!=",
"PHP_ParserGenerator_Action",
"::",
"REDUCE",
")",
"{",
"continue",
";",
"}",
"$",
"rp2",
"=",
"$",
"ap2",
"->",
"x",
";",
"if",
"(",
"$",
"rp2",
"===",
"$",
"rbest",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"rp2",
"===",
"$",
"rp",
")",
"{",
"$",
"n",
"++",
";",
"}",
"}",
"if",
"(",
"$",
"n",
">",
"$",
"nbest",
")",
"{",
"$",
"nbest",
"=",
"$",
"n",
";",
"$",
"rbest",
"=",
"$",
"rp",
";",
"}",
"}",
"/* Do not make a default if the number of rules to default\n ** is not at least 1 */",
"if",
"(",
"$",
"nbest",
"<",
"1",
")",
"{",
"continue",
";",
"}",
"/* Combine matching REDUCE actions into a single default */",
"for",
"(",
"$",
"ap",
"=",
"$",
"stp",
"->",
"ap",
";",
"$",
"ap",
";",
"$",
"ap",
"=",
"$",
"ap",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"ap",
"->",
"type",
"==",
"PHP_ParserGenerator_Action",
"::",
"REDUCE",
"&&",
"$",
"ap",
"->",
"x",
"===",
"$",
"rbest",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"ap",
"===",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'$ap is not an object'",
")",
";",
"}",
"$",
"ap",
"->",
"sp",
"=",
"PHP_ParserGenerator_Symbol",
"::",
"Symbol_new",
"(",
"\"{default}\"",
")",
";",
"for",
"(",
"$",
"ap",
"=",
"$",
"ap",
"->",
"next",
";",
"$",
"ap",
";",
"$",
"ap",
"=",
"$",
"ap",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"ap",
"->",
"type",
"==",
"PHP_ParserGenerator_Action",
"::",
"REDUCE",
"&&",
"$",
"ap",
"->",
"x",
"===",
"$",
"rbest",
")",
"{",
"$",
"ap",
"->",
"type",
"=",
"PHP_ParserGenerator_Action",
"::",
"NOT_USED",
";",
"}",
"}",
"$",
"stp",
"->",
"ap",
"=",
"PHP_ParserGenerator_Action",
"::",
"Action_sort",
"(",
"$",
"stp",
"->",
"ap",
")",
";",
"}",
"}"
] | Reduce the size of the action tables, if possible, by making use
of defaults.
In this version, we take the most frequent REDUCE action and make
it the default. | [
"Reduce",
"the",
"size",
"of",
"the",
"action",
"tables",
"if",
"possible",
"by",
"making",
"use",
"of",
"defaults",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L798-L856 |
6,136 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.ResortStates | function ResortStates()
{
for ($i = 0; $i < $this->nstate; $i++) {
$stp = $this->sorted[$i]->data;
$stp->nTknAct = $stp->nNtAct = 0;
$stp->iDflt = $this->nstate + $this->nrule;
$stp->iTknOfst = PHP_ParserGenerator_Data::NO_OFFSET;
$stp->iNtOfst = PHP_ParserGenerator_Data::NO_OFFSET;
for ($ap = $stp->ap; $ap; $ap = $ap->next) {
if ($this->compute_action($ap) >= 0) {
if ($ap->sp->index < $this->nterminal) {
$stp->nTknAct++;
} elseif ($ap->sp->index < $this->nsymbol) {
$stp->nNtAct++;
} else {
$stp->iDflt = $this->compute_action($ap);
}
}
}
$this->sorted[$i] = $stp;
}
$save = $this->sorted[0];
unset($this->sorted[0]);
usort($this->sorted, array('PHP_ParserGenerator_State', 'stateResortCompare'));
array_unshift($this->sorted, $save);
for($i = 0; $i < $this->nstate; $i++) {
$this->sorted[$i]->statenum = $i;
}
} | php | function ResortStates()
{
for ($i = 0; $i < $this->nstate; $i++) {
$stp = $this->sorted[$i]->data;
$stp->nTknAct = $stp->nNtAct = 0;
$stp->iDflt = $this->nstate + $this->nrule;
$stp->iTknOfst = PHP_ParserGenerator_Data::NO_OFFSET;
$stp->iNtOfst = PHP_ParserGenerator_Data::NO_OFFSET;
for ($ap = $stp->ap; $ap; $ap = $ap->next) {
if ($this->compute_action($ap) >= 0) {
if ($ap->sp->index < $this->nterminal) {
$stp->nTknAct++;
} elseif ($ap->sp->index < $this->nsymbol) {
$stp->nNtAct++;
} else {
$stp->iDflt = $this->compute_action($ap);
}
}
}
$this->sorted[$i] = $stp;
}
$save = $this->sorted[0];
unset($this->sorted[0]);
usort($this->sorted, array('PHP_ParserGenerator_State', 'stateResortCompare'));
array_unshift($this->sorted, $save);
for($i = 0; $i < $this->nstate; $i++) {
$this->sorted[$i]->statenum = $i;
}
} | [
"function",
"ResortStates",
"(",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nstate",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stp",
"=",
"$",
"this",
"->",
"sorted",
"[",
"$",
"i",
"]",
"->",
"data",
";",
"$",
"stp",
"->",
"nTknAct",
"=",
"$",
"stp",
"->",
"nNtAct",
"=",
"0",
";",
"$",
"stp",
"->",
"iDflt",
"=",
"$",
"this",
"->",
"nstate",
"+",
"$",
"this",
"->",
"nrule",
";",
"$",
"stp",
"->",
"iTknOfst",
"=",
"PHP_ParserGenerator_Data",
"::",
"NO_OFFSET",
";",
"$",
"stp",
"->",
"iNtOfst",
"=",
"PHP_ParserGenerator_Data",
"::",
"NO_OFFSET",
";",
"for",
"(",
"$",
"ap",
"=",
"$",
"stp",
"->",
"ap",
";",
"$",
"ap",
";",
"$",
"ap",
"=",
"$",
"ap",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"compute_action",
"(",
"$",
"ap",
")",
">=",
"0",
")",
"{",
"if",
"(",
"$",
"ap",
"->",
"sp",
"->",
"index",
"<",
"$",
"this",
"->",
"nterminal",
")",
"{",
"$",
"stp",
"->",
"nTknAct",
"++",
";",
"}",
"elseif",
"(",
"$",
"ap",
"->",
"sp",
"->",
"index",
"<",
"$",
"this",
"->",
"nsymbol",
")",
"{",
"$",
"stp",
"->",
"nNtAct",
"++",
";",
"}",
"else",
"{",
"$",
"stp",
"->",
"iDflt",
"=",
"$",
"this",
"->",
"compute_action",
"(",
"$",
"ap",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"sorted",
"[",
"$",
"i",
"]",
"=",
"$",
"stp",
";",
"}",
"$",
"save",
"=",
"$",
"this",
"->",
"sorted",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"sorted",
"[",
"0",
"]",
")",
";",
"usort",
"(",
"$",
"this",
"->",
"sorted",
",",
"array",
"(",
"'PHP_ParserGenerator_State'",
",",
"'stateResortCompare'",
")",
")",
";",
"array_unshift",
"(",
"$",
"this",
"->",
"sorted",
",",
"$",
"save",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nstate",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"sorted",
"[",
"$",
"i",
"]",
"->",
"statenum",
"=",
"$",
"i",
";",
"}",
"}"
] | Renumber and resort states so that states with fewer choices
occur at the end. Except, keep state 0 as the first state. | [
"Renumber",
"and",
"resort",
"states",
"so",
"that",
"states",
"with",
"fewer",
"choices",
"occur",
"at",
"the",
"end",
".",
"Except",
"keep",
"state",
"0",
"as",
"the",
"first",
"state",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L862-L890 |
6,137 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.compute_action | function compute_action($ap)
{
switch ($ap->type) {
case PHP_ParserGenerator_Action::SHIFT:
$act = $ap->x->statenum;
break;
case PHP_ParserGenerator_Action::REDUCE:
$act = $ap->x->index + $this->nstate;
break;
case PHP_ParserGenerator_Action::ERROR:
$act = $this->nstate + $this->nrule;
break;
case PHP_ParserGenerator_Action::ACCEPT:
$act = $this->nstate + $this->nrule + 1;
break;
default:
$act = -1;
break;
}
return $act;
} | php | function compute_action($ap)
{
switch ($ap->type) {
case PHP_ParserGenerator_Action::SHIFT:
$act = $ap->x->statenum;
break;
case PHP_ParserGenerator_Action::REDUCE:
$act = $ap->x->index + $this->nstate;
break;
case PHP_ParserGenerator_Action::ERROR:
$act = $this->nstate + $this->nrule;
break;
case PHP_ParserGenerator_Action::ACCEPT:
$act = $this->nstate + $this->nrule + 1;
break;
default:
$act = -1;
break;
}
return $act;
} | [
"function",
"compute_action",
"(",
"$",
"ap",
")",
"{",
"switch",
"(",
"$",
"ap",
"->",
"type",
")",
"{",
"case",
"PHP_ParserGenerator_Action",
"::",
"SHIFT",
":",
"$",
"act",
"=",
"$",
"ap",
"->",
"x",
"->",
"statenum",
";",
"break",
";",
"case",
"PHP_ParserGenerator_Action",
"::",
"REDUCE",
":",
"$",
"act",
"=",
"$",
"ap",
"->",
"x",
"->",
"index",
"+",
"$",
"this",
"->",
"nstate",
";",
"break",
";",
"case",
"PHP_ParserGenerator_Action",
"::",
"ERROR",
":",
"$",
"act",
"=",
"$",
"this",
"->",
"nstate",
"+",
"$",
"this",
"->",
"nrule",
";",
"break",
";",
"case",
"PHP_ParserGenerator_Action",
"::",
"ACCEPT",
":",
"$",
"act",
"=",
"$",
"this",
"->",
"nstate",
"+",
"$",
"this",
"->",
"nrule",
"+",
"1",
";",
"break",
";",
"default",
":",
"$",
"act",
"=",
"-",
"1",
";",
"break",
";",
"}",
"return",
"$",
"act",
";",
"}"
] | Given an action, compute the integer value for that action
which is to be put in the action table of the generated machine.
Return negative if no action should be generated.
@param PHP_ParserGenerator_Action | [
"Given",
"an",
"action",
"compute",
"the",
"integer",
"value",
"for",
"that",
"action",
"which",
"is",
"to",
"be",
"put",
"in",
"the",
"action",
"table",
"of",
"the",
"generated",
"machine",
".",
"Return",
"negative",
"if",
"no",
"action",
"should",
"be",
"generated",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L898-L918 |
6,138 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.ReportOutput | function ReportOutput()
{
$fp = fopen($this->filenosuffix . ".out", "wb");
if (!$fp) {
return;
}
for ($i = 0; $i < $this->nstate; $i++) {
$stp = $this->sorted[$i];
fprintf($fp, "State %d:\n", $stp->statenum);
if ($this->basisflag) {
$cfp = $stp->bp;
} else {
$cfp = $stp->cfp;
}
while ($cfp) {
if ($cfp->dot == $cfp->rp->nrhs) {
$buf = sprintf('(%d)', $cfp->rp->index);
fprintf($fp, ' %5s ', $buf);
} else {
fwrite($fp,' ');
}
$cfp->ConfigPrint($fp);
fwrite($fp, "\n");
if (0) {
//SetPrint(fp,cfp->fws,$this);
//PlinkPrint(fp,cfp->fplp,"To ");
//PlinkPrint(fp,cfp->bplp,"From");
}
if ($this->basisflag) {
$cfp = $cfp->bp;
} else {
$cfp = $cfp->next;
}
}
fwrite($fp, "\n");
for ($ap = $stp->ap; $ap; $ap = $ap->next) {
if ($ap->PrintAction($fp, 30)) {
fprintf($fp,"\n");
}
}
fwrite($fp,"\n");
}
fclose($fp);
} | php | function ReportOutput()
{
$fp = fopen($this->filenosuffix . ".out", "wb");
if (!$fp) {
return;
}
for ($i = 0; $i < $this->nstate; $i++) {
$stp = $this->sorted[$i];
fprintf($fp, "State %d:\n", $stp->statenum);
if ($this->basisflag) {
$cfp = $stp->bp;
} else {
$cfp = $stp->cfp;
}
while ($cfp) {
if ($cfp->dot == $cfp->rp->nrhs) {
$buf = sprintf('(%d)', $cfp->rp->index);
fprintf($fp, ' %5s ', $buf);
} else {
fwrite($fp,' ');
}
$cfp->ConfigPrint($fp);
fwrite($fp, "\n");
if (0) {
//SetPrint(fp,cfp->fws,$this);
//PlinkPrint(fp,cfp->fplp,"To ");
//PlinkPrint(fp,cfp->bplp,"From");
}
if ($this->basisflag) {
$cfp = $cfp->bp;
} else {
$cfp = $cfp->next;
}
}
fwrite($fp, "\n");
for ($ap = $stp->ap; $ap; $ap = $ap->next) {
if ($ap->PrintAction($fp, 30)) {
fprintf($fp,"\n");
}
}
fwrite($fp,"\n");
}
fclose($fp);
} | [
"function",
"ReportOutput",
"(",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"this",
"->",
"filenosuffix",
".",
"\".out\"",
",",
"\"wb\"",
")",
";",
"if",
"(",
"!",
"$",
"fp",
")",
"{",
"return",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nstate",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stp",
"=",
"$",
"this",
"->",
"sorted",
"[",
"$",
"i",
"]",
";",
"fprintf",
"(",
"$",
"fp",
",",
"\"State %d:\\n\"",
",",
"$",
"stp",
"->",
"statenum",
")",
";",
"if",
"(",
"$",
"this",
"->",
"basisflag",
")",
"{",
"$",
"cfp",
"=",
"$",
"stp",
"->",
"bp",
";",
"}",
"else",
"{",
"$",
"cfp",
"=",
"$",
"stp",
"->",
"cfp",
";",
"}",
"while",
"(",
"$",
"cfp",
")",
"{",
"if",
"(",
"$",
"cfp",
"->",
"dot",
"==",
"$",
"cfp",
"->",
"rp",
"->",
"nrhs",
")",
"{",
"$",
"buf",
"=",
"sprintf",
"(",
"'(%d)'",
",",
"$",
"cfp",
"->",
"rp",
"->",
"index",
")",
";",
"fprintf",
"(",
"$",
"fp",
",",
"' %5s '",
",",
"$",
"buf",
")",
";",
"}",
"else",
"{",
"fwrite",
"(",
"$",
"fp",
",",
"' '",
")",
";",
"}",
"$",
"cfp",
"->",
"ConfigPrint",
"(",
"$",
"fp",
")",
";",
"fwrite",
"(",
"$",
"fp",
",",
"\"\\n\"",
")",
";",
"if",
"(",
"0",
")",
"{",
"//SetPrint(fp,cfp->fws,$this);",
"//PlinkPrint(fp,cfp->fplp,\"To \");",
"//PlinkPrint(fp,cfp->bplp,\"From\");",
"}",
"if",
"(",
"$",
"this",
"->",
"basisflag",
")",
"{",
"$",
"cfp",
"=",
"$",
"cfp",
"->",
"bp",
";",
"}",
"else",
"{",
"$",
"cfp",
"=",
"$",
"cfp",
"->",
"next",
";",
"}",
"}",
"fwrite",
"(",
"$",
"fp",
",",
"\"\\n\"",
")",
";",
"for",
"(",
"$",
"ap",
"=",
"$",
"stp",
"->",
"ap",
";",
"$",
"ap",
";",
"$",
"ap",
"=",
"$",
"ap",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"ap",
"->",
"PrintAction",
"(",
"$",
"fp",
",",
"30",
")",
")",
"{",
"fprintf",
"(",
"$",
"fp",
",",
"\"\\n\"",
")",
";",
"}",
"}",
"fwrite",
"(",
"$",
"fp",
",",
"\"\\n\"",
")",
";",
"}",
"fclose",
"(",
"$",
"fp",
")",
";",
"}"
] | Generate the "Parse.out" log file | [
"Generate",
"the",
"Parse",
".",
"out",
"log",
"file"
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L923-L966 |
6,139 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.tplt_open | private function tplt_open()
{
$templatename = $this->parser_template ? $this->parser_template : dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "Lempar.php";
$buf = $this->filenosuffix . '.lt';
if (file_exists($buf) && is_readable($buf)) {
$tpltname = $buf;
} elseif (file_exists($templatename) && is_readable($templatename)) {
$tpltname = $templatename;
} elseif ($fp = @fopen($templatename, 'rb', true)) {
return $fp;
}
if (!isset($tpltname)) {
echo "Can't find the parser driver template file \"%s\".\n",
$templatename;
$this->errorcnt++;
return 0;
}
$in = @fopen($tpltname,"rb");
if (!$in) {
printf("Can't open the template file \"%s\".\n", $tpltname);
$this->errorcnt++;
return 0;
}
return $in;
} | php | private function tplt_open()
{
$templatename = $this->parser_template ? $this->parser_template : dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "Lempar.php";
$buf = $this->filenosuffix . '.lt';
if (file_exists($buf) && is_readable($buf)) {
$tpltname = $buf;
} elseif (file_exists($templatename) && is_readable($templatename)) {
$tpltname = $templatename;
} elseif ($fp = @fopen($templatename, 'rb', true)) {
return $fp;
}
if (!isset($tpltname)) {
echo "Can't find the parser driver template file \"%s\".\n",
$templatename;
$this->errorcnt++;
return 0;
}
$in = @fopen($tpltname,"rb");
if (!$in) {
printf("Can't open the template file \"%s\".\n", $tpltname);
$this->errorcnt++;
return 0;
}
return $in;
} | [
"private",
"function",
"tplt_open",
"(",
")",
"{",
"$",
"templatename",
"=",
"$",
"this",
"->",
"parser_template",
"?",
"$",
"this",
"->",
"parser_template",
":",
"dirname",
"(",
"dirname",
"(",
"__FILE__",
")",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"\"Lempar.php\"",
";",
"$",
"buf",
"=",
"$",
"this",
"->",
"filenosuffix",
".",
"'.lt'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"buf",
")",
"&&",
"is_readable",
"(",
"$",
"buf",
")",
")",
"{",
"$",
"tpltname",
"=",
"$",
"buf",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"templatename",
")",
"&&",
"is_readable",
"(",
"$",
"templatename",
")",
")",
"{",
"$",
"tpltname",
"=",
"$",
"templatename",
";",
"}",
"elseif",
"(",
"$",
"fp",
"=",
"@",
"fopen",
"(",
"$",
"templatename",
",",
"'rb'",
",",
"true",
")",
")",
"{",
"return",
"$",
"fp",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"tpltname",
")",
")",
"{",
"echo",
"\"Can't find the parser driver template file \\\"%s\\\".\\n\"",
",",
"$",
"templatename",
";",
"$",
"this",
"->",
"errorcnt",
"++",
";",
"return",
"0",
";",
"}",
"$",
"in",
"=",
"@",
"fopen",
"(",
"$",
"tpltname",
",",
"\"rb\"",
")",
";",
"if",
"(",
"!",
"$",
"in",
")",
"{",
"printf",
"(",
"\"Can't open the template file \\\"%s\\\".\\n\"",
",",
"$",
"tpltname",
")",
";",
"$",
"this",
"->",
"errorcnt",
"++",
";",
"return",
"0",
";",
"}",
"return",
"$",
"in",
";",
"}"
] | The next function finds the template file and opens it, returning
a pointer to the opened file.
@return resource | [
"The",
"next",
"function",
"finds",
"the",
"template",
"file",
"and",
"opens",
"it",
"returning",
"a",
"pointer",
"to",
"the",
"opened",
"file",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L973-L998 |
6,140 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.tplt_xfer | private function tplt_xfer($name, $in, $out, &$lineno)
{
while (($line = fgets($in, 1024)) && ($line[0] != '%' || $line[1] != '%')) {
$lineno++;
$iStart = 0;
if ($name) {
for ($i = 0; $i < strlen($line); $i++) {
if ($line[$i] == 'P' && substr($line, $i, 5) == "Parse"
&& ($i === 0 || preg_match('/[^a-zA-Z]/', $line[$i - 1]))) {
if ($i > $iStart) {
fwrite($out, substr($line, $iStart, $i - $iStart));
}
fwrite($out, $name);
$i += 4;
$iStart = $i + 1;
}
}
}
fwrite($out, substr($line, $iStart));
}
} | php | private function tplt_xfer($name, $in, $out, &$lineno)
{
while (($line = fgets($in, 1024)) && ($line[0] != '%' || $line[1] != '%')) {
$lineno++;
$iStart = 0;
if ($name) {
for ($i = 0; $i < strlen($line); $i++) {
if ($line[$i] == 'P' && substr($line, $i, 5) == "Parse"
&& ($i === 0 || preg_match('/[^a-zA-Z]/', $line[$i - 1]))) {
if ($i > $iStart) {
fwrite($out, substr($line, $iStart, $i - $iStart));
}
fwrite($out, $name);
$i += 4;
$iStart = $i + 1;
}
}
}
fwrite($out, substr($line, $iStart));
}
} | [
"private",
"function",
"tplt_xfer",
"(",
"$",
"name",
",",
"$",
"in",
",",
"$",
"out",
",",
"&",
"$",
"lineno",
")",
"{",
"while",
"(",
"(",
"$",
"line",
"=",
"fgets",
"(",
"$",
"in",
",",
"1024",
")",
")",
"&&",
"(",
"$",
"line",
"[",
"0",
"]",
"!=",
"'%'",
"||",
"$",
"line",
"[",
"1",
"]",
"!=",
"'%'",
")",
")",
"{",
"$",
"lineno",
"++",
";",
"$",
"iStart",
"=",
"0",
";",
"if",
"(",
"$",
"name",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"line",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"line",
"[",
"$",
"i",
"]",
"==",
"'P'",
"&&",
"substr",
"(",
"$",
"line",
",",
"$",
"i",
",",
"5",
")",
"==",
"\"Parse\"",
"&&",
"(",
"$",
"i",
"===",
"0",
"||",
"preg_match",
"(",
"'/[^a-zA-Z]/'",
",",
"$",
"line",
"[",
"$",
"i",
"-",
"1",
"]",
")",
")",
")",
"{",
"if",
"(",
"$",
"i",
">",
"$",
"iStart",
")",
"{",
"fwrite",
"(",
"$",
"out",
",",
"substr",
"(",
"$",
"line",
",",
"$",
"iStart",
",",
"$",
"i",
"-",
"$",
"iStart",
")",
")",
";",
"}",
"fwrite",
"(",
"$",
"out",
",",
"$",
"name",
")",
";",
"$",
"i",
"+=",
"4",
";",
"$",
"iStart",
"=",
"$",
"i",
"+",
"1",
";",
"}",
"}",
"}",
"fwrite",
"(",
"$",
"out",
",",
"substr",
"(",
"$",
"line",
",",
"$",
"iStart",
")",
")",
";",
"}",
"}"
] | The first function transfers data from "in" to "out" until
a line is seen which begins with "%%". The line number is
tracked.
if name!=0, then any word that begin with "Parse" is changed to
begin with *name instead. | [
"The",
"first",
"function",
"transfers",
"data",
"from",
"in",
"to",
"out",
"until",
"a",
"line",
"is",
"seen",
"which",
"begins",
"with",
"%%",
".",
"The",
"line",
"number",
"is",
"tracked",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L1013-L1033 |
6,141 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.tplt_print | private function tplt_print($out, $str, $strln, &$lineno)
{
if ($str == '') {
return;
}
$this->tplt_linedir($out, $strln, $this->filename);
$lineno++;
fwrite($out, $str);
$lineno += count(explode("\n", $str)) - 1;
$this->tplt_linedir($out, $lineno + 2, $this->outname);
$lineno += 2;
} | php | private function tplt_print($out, $str, $strln, &$lineno)
{
if ($str == '') {
return;
}
$this->tplt_linedir($out, $strln, $this->filename);
$lineno++;
fwrite($out, $str);
$lineno += count(explode("\n", $str)) - 1;
$this->tplt_linedir($out, $lineno + 2, $this->outname);
$lineno += 2;
} | [
"private",
"function",
"tplt_print",
"(",
"$",
"out",
",",
"$",
"str",
",",
"$",
"strln",
",",
"&",
"$",
"lineno",
")",
"{",
"if",
"(",
"$",
"str",
"==",
"''",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"tplt_linedir",
"(",
"$",
"out",
",",
"$",
"strln",
",",
"$",
"this",
"->",
"filename",
")",
";",
"$",
"lineno",
"++",
";",
"fwrite",
"(",
"$",
"out",
",",
"$",
"str",
")",
";",
"$",
"lineno",
"+=",
"count",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"str",
")",
")",
"-",
"1",
";",
"$",
"this",
"->",
"tplt_linedir",
"(",
"$",
"out",
",",
"$",
"lineno",
"+",
"2",
",",
"$",
"this",
"->",
"outname",
")",
";",
"$",
"lineno",
"+=",
"2",
";",
"}"
] | Print a string to the file and keep the linenumber up to date | [
"Print",
"a",
"string",
"to",
"the",
"file",
"and",
"keep",
"the",
"linenumber",
"up",
"to",
"date"
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L1046-L1057 |
6,142 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.FindFollowSets | function FindFollowSets()
{
for ($i = 0; $i < $this->nstate; $i++) {
for ($cfp = $this->sorted[$i]->data->cfp; $cfp; $cfp = $cfp->next) {
$cfp->status = PHP_ParserGenerator_Config::INCOMPLETE;
}
}
do {
$progress = 0;
for ($i = 0; $i < $this->nstate; $i++) {
for ($cfp = $this->sorted[$i]->data->cfp; $cfp; $cfp = $cfp->next) {
if ($cfp->status == PHP_ParserGenerator_Config::COMPLETE) {
continue;
}
for ($plp = $cfp->fplp; $plp; $plp = $plp->next) {
$a = array_diff_key($cfp->fws, $plp->cfp->fws);
if (count($a)) {
$plp->cfp->fws += $a;
$plp->cfp->status = PHP_ParserGenerator_Config::INCOMPLETE;
$progress = 1;
}
}
$cfp->status = PHP_ParserGenerator_Config::COMPLETE;
}
}
} while ($progress);
} | php | function FindFollowSets()
{
for ($i = 0; $i < $this->nstate; $i++) {
for ($cfp = $this->sorted[$i]->data->cfp; $cfp; $cfp = $cfp->next) {
$cfp->status = PHP_ParserGenerator_Config::INCOMPLETE;
}
}
do {
$progress = 0;
for ($i = 0; $i < $this->nstate; $i++) {
for ($cfp = $this->sorted[$i]->data->cfp; $cfp; $cfp = $cfp->next) {
if ($cfp->status == PHP_ParserGenerator_Config::COMPLETE) {
continue;
}
for ($plp = $cfp->fplp; $plp; $plp = $plp->next) {
$a = array_diff_key($cfp->fws, $plp->cfp->fws);
if (count($a)) {
$plp->cfp->fws += $a;
$plp->cfp->status = PHP_ParserGenerator_Config::INCOMPLETE;
$progress = 1;
}
}
$cfp->status = PHP_ParserGenerator_Config::COMPLETE;
}
}
} while ($progress);
} | [
"function",
"FindFollowSets",
"(",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nstate",
";",
"$",
"i",
"++",
")",
"{",
"for",
"(",
"$",
"cfp",
"=",
"$",
"this",
"->",
"sorted",
"[",
"$",
"i",
"]",
"->",
"data",
"->",
"cfp",
";",
"$",
"cfp",
";",
"$",
"cfp",
"=",
"$",
"cfp",
"->",
"next",
")",
"{",
"$",
"cfp",
"->",
"status",
"=",
"PHP_ParserGenerator_Config",
"::",
"INCOMPLETE",
";",
"}",
"}",
"do",
"{",
"$",
"progress",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nstate",
";",
"$",
"i",
"++",
")",
"{",
"for",
"(",
"$",
"cfp",
"=",
"$",
"this",
"->",
"sorted",
"[",
"$",
"i",
"]",
"->",
"data",
"->",
"cfp",
";",
"$",
"cfp",
";",
"$",
"cfp",
"=",
"$",
"cfp",
"->",
"next",
")",
"{",
"if",
"(",
"$",
"cfp",
"->",
"status",
"==",
"PHP_ParserGenerator_Config",
"::",
"COMPLETE",
")",
"{",
"continue",
";",
"}",
"for",
"(",
"$",
"plp",
"=",
"$",
"cfp",
"->",
"fplp",
";",
"$",
"plp",
";",
"$",
"plp",
"=",
"$",
"plp",
"->",
"next",
")",
"{",
"$",
"a",
"=",
"array_diff_key",
"(",
"$",
"cfp",
"->",
"fws",
",",
"$",
"plp",
"->",
"cfp",
"->",
"fws",
")",
";",
"if",
"(",
"count",
"(",
"$",
"a",
")",
")",
"{",
"$",
"plp",
"->",
"cfp",
"->",
"fws",
"+=",
"$",
"a",
";",
"$",
"plp",
"->",
"cfp",
"->",
"status",
"=",
"PHP_ParserGenerator_Config",
"::",
"INCOMPLETE",
";",
"$",
"progress",
"=",
"1",
";",
"}",
"}",
"$",
"cfp",
"->",
"status",
"=",
"PHP_ParserGenerator_Config",
"::",
"COMPLETE",
";",
"}",
"}",
"}",
"while",
"(",
"$",
"progress",
")",
";",
"}"
] | Compute all followsets.
A followset is the set of all symbols which can come immediately
after a configuration. | [
"Compute",
"all",
"followsets",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L1066-L1093 |
6,143 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.emit_code | function emit_code($out, PHP_ParserGenerator_Rule $rp, &$lineno)
{
$linecnt = 0;
/* Generate code to do the reduce action */
if ($rp->code) {
$this->tplt_linedir($out, $rp->line, $this->filename);
fwrite($out, " function yy_r$rp->index(){" . $rp->code);
$linecnt += count(explode("\n", $rp->code)) - 1;
$lineno += 3 + $linecnt;
fwrite($out, " }\n");
$this->tplt_linedir($out, $lineno, $this->outname);
} /* End if( rp->code ) */
} | php | function emit_code($out, PHP_ParserGenerator_Rule $rp, &$lineno)
{
$linecnt = 0;
/* Generate code to do the reduce action */
if ($rp->code) {
$this->tplt_linedir($out, $rp->line, $this->filename);
fwrite($out, " function yy_r$rp->index(){" . $rp->code);
$linecnt += count(explode("\n", $rp->code)) - 1;
$lineno += 3 + $linecnt;
fwrite($out, " }\n");
$this->tplt_linedir($out, $lineno, $this->outname);
} /* End if( rp->code ) */
} | [
"function",
"emit_code",
"(",
"$",
"out",
",",
"PHP_ParserGenerator_Rule",
"$",
"rp",
",",
"&",
"$",
"lineno",
")",
"{",
"$",
"linecnt",
"=",
"0",
";",
"/* Generate code to do the reduce action */",
"if",
"(",
"$",
"rp",
"->",
"code",
")",
"{",
"$",
"this",
"->",
"tplt_linedir",
"(",
"$",
"out",
",",
"$",
"rp",
"->",
"line",
",",
"$",
"this",
"->",
"filename",
")",
";",
"fwrite",
"(",
"$",
"out",
",",
"\" function yy_r$rp->index(){\"",
".",
"$",
"rp",
"->",
"code",
")",
";",
"$",
"linecnt",
"+=",
"count",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"rp",
"->",
"code",
")",
")",
"-",
"1",
";",
"$",
"lineno",
"+=",
"3",
"+",
"$",
"linecnt",
";",
"fwrite",
"(",
"$",
"out",
",",
"\" }\\n\"",
")",
";",
"$",
"this",
"->",
"tplt_linedir",
"(",
"$",
"out",
",",
"$",
"lineno",
",",
"$",
"this",
"->",
"outname",
")",
";",
"}",
"/* End if( rp->code ) */",
"}"
] | Generate code which executes when the rule "rp" is reduced. Write
the code to "out". Make sure lineno stays up-to-date. | [
"Generate",
"code",
"which",
"executes",
"when",
"the",
"rule",
"rp",
"is",
"reduced",
".",
"Write",
"the",
"code",
"to",
"out",
".",
"Make",
"sure",
"lineno",
"stays",
"up",
"-",
"to",
"-",
"date",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L1656-L1669 |
6,144 | rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Data.php | PHP_ParserGenerator_Data.emit_destructor_code | function emit_destructor_code($out, PHP_ParserGenerator_Symbol $sp, &$lineno)
// FILE *out;
// struct symbol *sp;
// struct lemon *lemp;
// int *lineno;
{
$cp = 0;
$linecnt = 0;
if ($sp->type == PHP_ParserGenerator_Symbol::TERMINAL) {
$cp = $this->tokendest;
if ($cp === 0) {
return;
}
$this->tplt_linedir($out, $this->tokendestln, $this->filename);
fwrite($out, "{");
} elseif ($sp->destructor) {
$cp = $sp->destructor;
$this->tplt_linedir($out, $sp->destructorln, $this->filename);
fwrite($out, "{");
} elseif ($this->vardest) {
$cp = $this->vardest;
if ($cp === 0) {
return;
}
$this->tplt_linedir($out, $this->vardestln, $this->filename);
fwrite($out, "{");
} else {
throw new Exception('emit_destructor'); /* Cannot happen */
}
for ($i = 0; $i < strlen($cp); $i++) {
if ($cp[$i]=='$' && $cp[$i + 1]=='$' ) {
fprintf($out, "(yypminor->yy%d)", $sp->dtnum);
$i++;
continue;
}
if ($cp[$i] == "\n") {
$linecnt++;
}
fwrite($out, $cp[$i]);
}
$lineno += 3 + $linecnt;
fwrite($out, "}\n");
$this->tplt_linedir($out, $lineno, $this->outname);
} | php | function emit_destructor_code($out, PHP_ParserGenerator_Symbol $sp, &$lineno)
// FILE *out;
// struct symbol *sp;
// struct lemon *lemp;
// int *lineno;
{
$cp = 0;
$linecnt = 0;
if ($sp->type == PHP_ParserGenerator_Symbol::TERMINAL) {
$cp = $this->tokendest;
if ($cp === 0) {
return;
}
$this->tplt_linedir($out, $this->tokendestln, $this->filename);
fwrite($out, "{");
} elseif ($sp->destructor) {
$cp = $sp->destructor;
$this->tplt_linedir($out, $sp->destructorln, $this->filename);
fwrite($out, "{");
} elseif ($this->vardest) {
$cp = $this->vardest;
if ($cp === 0) {
return;
}
$this->tplt_linedir($out, $this->vardestln, $this->filename);
fwrite($out, "{");
} else {
throw new Exception('emit_destructor'); /* Cannot happen */
}
for ($i = 0; $i < strlen($cp); $i++) {
if ($cp[$i]=='$' && $cp[$i + 1]=='$' ) {
fprintf($out, "(yypminor->yy%d)", $sp->dtnum);
$i++;
continue;
}
if ($cp[$i] == "\n") {
$linecnt++;
}
fwrite($out, $cp[$i]);
}
$lineno += 3 + $linecnt;
fwrite($out, "}\n");
$this->tplt_linedir($out, $lineno, $this->outname);
} | [
"function",
"emit_destructor_code",
"(",
"$",
"out",
",",
"PHP_ParserGenerator_Symbol",
"$",
"sp",
",",
"&",
"$",
"lineno",
")",
"// FILE *out;",
"// struct symbol *sp;",
"// struct lemon *lemp;",
"// int *lineno;",
"{",
"$",
"cp",
"=",
"0",
";",
"$",
"linecnt",
"=",
"0",
";",
"if",
"(",
"$",
"sp",
"->",
"type",
"==",
"PHP_ParserGenerator_Symbol",
"::",
"TERMINAL",
")",
"{",
"$",
"cp",
"=",
"$",
"this",
"->",
"tokendest",
";",
"if",
"(",
"$",
"cp",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"tplt_linedir",
"(",
"$",
"out",
",",
"$",
"this",
"->",
"tokendestln",
",",
"$",
"this",
"->",
"filename",
")",
";",
"fwrite",
"(",
"$",
"out",
",",
"\"{\"",
")",
";",
"}",
"elseif",
"(",
"$",
"sp",
"->",
"destructor",
")",
"{",
"$",
"cp",
"=",
"$",
"sp",
"->",
"destructor",
";",
"$",
"this",
"->",
"tplt_linedir",
"(",
"$",
"out",
",",
"$",
"sp",
"->",
"destructorln",
",",
"$",
"this",
"->",
"filename",
")",
";",
"fwrite",
"(",
"$",
"out",
",",
"\"{\"",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"vardest",
")",
"{",
"$",
"cp",
"=",
"$",
"this",
"->",
"vardest",
";",
"if",
"(",
"$",
"cp",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"tplt_linedir",
"(",
"$",
"out",
",",
"$",
"this",
"->",
"vardestln",
",",
"$",
"this",
"->",
"filename",
")",
";",
"fwrite",
"(",
"$",
"out",
",",
"\"{\"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'emit_destructor'",
")",
";",
"/* Cannot happen */",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"cp",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"cp",
"[",
"$",
"i",
"]",
"==",
"'$'",
"&&",
"$",
"cp",
"[",
"$",
"i",
"+",
"1",
"]",
"==",
"'$'",
")",
"{",
"fprintf",
"(",
"$",
"out",
",",
"\"(yypminor->yy%d)\"",
",",
"$",
"sp",
"->",
"dtnum",
")",
";",
"$",
"i",
"++",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"cp",
"[",
"$",
"i",
"]",
"==",
"\"\\n\"",
")",
"{",
"$",
"linecnt",
"++",
";",
"}",
"fwrite",
"(",
"$",
"out",
",",
"$",
"cp",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"lineno",
"+=",
"3",
"+",
"$",
"linecnt",
";",
"fwrite",
"(",
"$",
"out",
",",
"\"}\\n\"",
")",
";",
"$",
"this",
"->",
"tplt_linedir",
"(",
"$",
"out",
",",
"$",
"lineno",
",",
"$",
"this",
"->",
"outname",
")",
";",
"}"
] | The following routine emits code for the destructor for the
symbol sp | [
"The",
"following",
"routine",
"emits",
"code",
"for",
"the",
"destructor",
"for",
"the",
"symbol",
"sp"
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Data.php#L1804-L1848 |
6,145 | ekyna/Characteristics | Twig/CharacteristicsExtension.php | CharacteristicsExtension.renderCharacteristics | public function renderCharacteristics(CharacteristicsInterface $characteristics, array $options = array())
{
$options = array_merge(array(
'table_class' => 'table table-striped table-bordered table-condensed ekyna-characteristics',
'highlight_inherited' => false,
'display_group' => null,
), $options);
return $this->template->render(array(
'view' => $this->manager->createView($characteristics, $options['display_group']),
'options' => $options,
));
} | php | public function renderCharacteristics(CharacteristicsInterface $characteristics, array $options = array())
{
$options = array_merge(array(
'table_class' => 'table table-striped table-bordered table-condensed ekyna-characteristics',
'highlight_inherited' => false,
'display_group' => null,
), $options);
return $this->template->render(array(
'view' => $this->manager->createView($characteristics, $options['display_group']),
'options' => $options,
));
} | [
"public",
"function",
"renderCharacteristics",
"(",
"CharacteristicsInterface",
"$",
"characteristics",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"array",
"(",
"'table_class'",
"=>",
"'table table-striped table-bordered table-condensed ekyna-characteristics'",
",",
"'highlight_inherited'",
"=>",
"false",
",",
"'display_group'",
"=>",
"null",
",",
")",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
"array",
"(",
"'view'",
"=>",
"$",
"this",
"->",
"manager",
"->",
"createView",
"(",
"$",
"characteristics",
",",
"$",
"options",
"[",
"'display_group'",
"]",
")",
",",
"'options'",
"=>",
"$",
"options",
",",
")",
")",
";",
"}"
] | Renders a characteristics view table.
@param CharacteristicsInterface $characteristics
@param array $options
@return string | [
"Renders",
"a",
"characteristics",
"view",
"table",
"."
] | 118a349fd98a7c28721d3cbaba67ce79d1cffada | https://github.com/ekyna/Characteristics/blob/118a349fd98a7c28721d3cbaba67ce79d1cffada/Twig/CharacteristicsExtension.php#L70-L82 |
6,146 | Puzzlout/FrameworkMvcLegacy | src/GeneratorEngine/Core/ControllerNameConstantsEngine.php | ControllerNameConstantsEngine.Run | public function Run($data = null) {
$this->ProcessFrameworkData();
$ApplicationList = \Puzzlout\Framework\GeneratorEngine\Constants\ApplicationList::Init()->GetList();
foreach ($ApplicationList as $Appname) {
$this->ProcessApplicationData($Appname);
}
} | php | public function Run($data = null) {
$this->ProcessFrameworkData();
$ApplicationList = \Puzzlout\Framework\GeneratorEngine\Constants\ApplicationList::Init()->GetList();
foreach ($ApplicationList as $Appname) {
$this->ProcessApplicationData($Appname);
}
} | [
"public",
"function",
"Run",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"ProcessFrameworkData",
"(",
")",
";",
"$",
"ApplicationList",
"=",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"GeneratorEngine",
"\\",
"Constants",
"\\",
"ApplicationList",
"::",
"Init",
"(",
")",
"->",
"GetList",
"(",
")",
";",
"foreach",
"(",
"$",
"ApplicationList",
"as",
"$",
"Appname",
")",
"{",
"$",
"this",
"->",
"ProcessApplicationData",
"(",
"$",
"Appname",
")",
";",
"}",
"}"
] | Retrieve the lists of controller filenames.
Generate the Classes that list the Controller names available in the
solution.
@param assoc array $data depending on the situation, some data can be passed
on to generate the files desired. | [
"Retrieve",
"the",
"lists",
"of",
"controller",
"filenames",
".",
"Generate",
"the",
"Classes",
"that",
"list",
"the",
"Controller",
"names",
"available",
"in",
"the",
"solution",
"."
] | 14e0fc5b16978cbd209f552ee9c649f66a0dfc6e | https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/GeneratorEngine/Core/ControllerNameConstantsEngine.php#L29-L36 |
6,147 | Puzzlout/FrameworkMvcLegacy | src/GeneratorEngine/Core/ControllerNameConstantsEngine.php | ControllerNameConstantsEngine.ProcessApplicationData | function ProcessApplicationData($Appname) {
$ApplicationControllers = DirectoryManager::GetFileNames(
"APP_ROOT_DIR" .
\Puzzlout\Framework\Enums\ApplicationFolderName::AppsFolderName .
$Appname .
\Puzzlout\Framework\Enums\ApplicationFolderName::ControllersFolderName);
$this->params = array(
BaseClassGenerator::NameSpaceKey => "Applications\\" . $Appname . "\Generated",
BaseClassGenerator::ClassNameKey => $Appname . $this->GeneratedClassPrefix,
BaseClassGenerator::DestinationDirKey => \Puzzlout\Framework\Enums\ApplicationFolderName::AppsFolderName .
$Appname . \Puzzlout\Framework\Enums\ApplicationFolderName::Generated,
BaseClassGenerator::ClassDescriptionKey => "Lists the constants for application controller classes to autocompletion and easy coding.",
ConstantsClassGeneratorBase::DoGenerateConstantKeysKey => true,
ConstantsClassGeneratorBase::DoGenerateGetListMethodKey => true
);
$this->GenerateApplicationFile($ApplicationControllers);
} | php | function ProcessApplicationData($Appname) {
$ApplicationControllers = DirectoryManager::GetFileNames(
"APP_ROOT_DIR" .
\Puzzlout\Framework\Enums\ApplicationFolderName::AppsFolderName .
$Appname .
\Puzzlout\Framework\Enums\ApplicationFolderName::ControllersFolderName);
$this->params = array(
BaseClassGenerator::NameSpaceKey => "Applications\\" . $Appname . "\Generated",
BaseClassGenerator::ClassNameKey => $Appname . $this->GeneratedClassPrefix,
BaseClassGenerator::DestinationDirKey => \Puzzlout\Framework\Enums\ApplicationFolderName::AppsFolderName .
$Appname . \Puzzlout\Framework\Enums\ApplicationFolderName::Generated,
BaseClassGenerator::ClassDescriptionKey => "Lists the constants for application controller classes to autocompletion and easy coding.",
ConstantsClassGeneratorBase::DoGenerateConstantKeysKey => true,
ConstantsClassGeneratorBase::DoGenerateGetListMethodKey => true
);
$this->GenerateApplicationFile($ApplicationControllers);
} | [
"function",
"ProcessApplicationData",
"(",
"$",
"Appname",
")",
"{",
"$",
"ApplicationControllers",
"=",
"DirectoryManager",
"::",
"GetFileNames",
"(",
"\"APP_ROOT_DIR\"",
".",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"Enums",
"\\",
"ApplicationFolderName",
"::",
"AppsFolderName",
".",
"$",
"Appname",
".",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"Enums",
"\\",
"ApplicationFolderName",
"::",
"ControllersFolderName",
")",
";",
"$",
"this",
"->",
"params",
"=",
"array",
"(",
"BaseClassGenerator",
"::",
"NameSpaceKey",
"=>",
"\"Applications\\\\\"",
".",
"$",
"Appname",
".",
"\"\\Generated\"",
",",
"BaseClassGenerator",
"::",
"ClassNameKey",
"=>",
"$",
"Appname",
".",
"$",
"this",
"->",
"GeneratedClassPrefix",
",",
"BaseClassGenerator",
"::",
"DestinationDirKey",
"=>",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"Enums",
"\\",
"ApplicationFolderName",
"::",
"AppsFolderName",
".",
"$",
"Appname",
".",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"Enums",
"\\",
"ApplicationFolderName",
"::",
"Generated",
",",
"BaseClassGenerator",
"::",
"ClassDescriptionKey",
"=>",
"\"Lists the constants for application controller classes to autocompletion and easy coding.\"",
",",
"ConstantsClassGeneratorBase",
"::",
"DoGenerateConstantKeysKey",
"=>",
"true",
",",
"ConstantsClassGeneratorBase",
"::",
"DoGenerateGetListMethodKey",
"=>",
"true",
")",
";",
"$",
"this",
"->",
"GenerateApplicationFile",
"(",
"$",
"ApplicationControllers",
")",
";",
"}"
] | Generate the files for an app.
@param string $Appname | [
"Generate",
"the",
"files",
"for",
"an",
"app",
"."
] | 14e0fc5b16978cbd209f552ee9c649f66a0dfc6e | https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/GeneratorEngine/Core/ControllerNameConstantsEngine.php#L58-L75 |
6,148 | uthando-cms/uthando-common | src/UthandoCommon/Model/AbstractCollection.php | AbstractCollection.add | public function add($entity)
{
$class = $this->entityClass;
if (!$entity instanceof $class) {
throw new CollectionException('class must an instance of ' . $class);
}
$this->entities[] = $entity;
return $this;
} | php | public function add($entity)
{
$class = $this->entityClass;
if (!$entity instanceof $class) {
throw new CollectionException('class must an instance of ' . $class);
}
$this->entities[] = $entity;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"entity",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"entityClass",
";",
"if",
"(",
"!",
"$",
"entity",
"instanceof",
"$",
"class",
")",
"{",
"throw",
"new",
"CollectionException",
"(",
"'class must an instance of '",
".",
"$",
"class",
")",
";",
"}",
"$",
"this",
"->",
"entities",
"[",
"]",
"=",
"$",
"entity",
";",
"return",
"$",
"this",
";",
"}"
] | adds an entity to the collection
@param object $entity
@return $this
@throws CollectionException | [
"adds",
"an",
"entity",
"to",
"the",
"collection"
] | feb915da5d26b60f536282e1bc3ad5c22e53f485 | https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Model/AbstractCollection.php#L59-L70 |
6,149 | uthando-cms/uthando-common | src/UthandoCommon/Model/AbstractCollection.php | AbstractCollection.checkEntities | public function checkEntities($entities)
{
return array_filter($entities, function ($val) {
$entityClass = $this->entityClass;
return ($val instanceof $entityClass);
});
} | php | public function checkEntities($entities)
{
return array_filter($entities, function ($val) {
$entityClass = $this->entityClass;
return ($val instanceof $entityClass);
});
} | [
"public",
"function",
"checkEntities",
"(",
"$",
"entities",
")",
"{",
"return",
"array_filter",
"(",
"$",
"entities",
",",
"function",
"(",
"$",
"val",
")",
"{",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"entityClass",
";",
"return",
"(",
"$",
"val",
"instanceof",
"$",
"entityClass",
")",
";",
"}",
")",
";",
"}"
] | filter out all entities that don't belong to the entity class
@param $entities
@return array | [
"filter",
"out",
"all",
"entities",
"that",
"don",
"t",
"belong",
"to",
"the",
"entity",
"class"
] | feb915da5d26b60f536282e1bc3ad5c22e53f485 | https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Model/AbstractCollection.php#L78-L84 |
6,150 | uthando-cms/uthando-common | src/UthandoCommon/Model/AbstractCollection.php | AbstractCollection.offsetSet | public function offsetSet($key, $entity)
{
$class = $this->entityClass;
if ($entity instanceof $class) {
if (!isset($key)) {
$this->entities[] = $entity;
} else {
$this->entities[$key] = $entity;
}
return true;
}
throw new CollectionException(
'The specified entity is not allowed for this collection.'
);
} | php | public function offsetSet($key, $entity)
{
$class = $this->entityClass;
if ($entity instanceof $class) {
if (!isset($key)) {
$this->entities[] = $entity;
} else {
$this->entities[$key] = $entity;
}
return true;
}
throw new CollectionException(
'The specified entity is not allowed for this collection.'
);
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"key",
",",
"$",
"entity",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"entityClass",
";",
"if",
"(",
"$",
"entity",
"instanceof",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"entities",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"entities",
"[",
"$",
"key",
"]",
"=",
"$",
"entity",
";",
"}",
"return",
"true",
";",
"}",
"throw",
"new",
"CollectionException",
"(",
"'The specified entity is not allowed for this collection.'",
")",
";",
"}"
] | Add an entity to the collection
@param mixed $key
@param mixed $entity
@return bool|void
@throws CollectionException | [
"Add",
"an",
"entity",
"to",
"the",
"collection"
] | feb915da5d26b60f536282e1bc3ad5c22e53f485 | https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Model/AbstractCollection.php#L180-L196 |
6,151 | uthando-cms/uthando-common | src/UthandoCommon/Model/AbstractCollection.php | AbstractCollection.offsetUnset | public function offsetUnset($key)
{
$entityClass = $this->entityClass;
if ($key instanceof $entityClass) {
$this->entities = array_filter($this->entities, function ($v) use ($key) {
return $v !== $key;
});
return true;
}
if (isset($this->entities[$key])) {
unset($this->entities[$key]);
return true;
}
return false;
} | php | public function offsetUnset($key)
{
$entityClass = $this->entityClass;
if ($key instanceof $entityClass) {
$this->entities = array_filter($this->entities, function ($v) use ($key) {
return $v !== $key;
});
return true;
}
if (isset($this->entities[$key])) {
unset($this->entities[$key]);
return true;
}
return false;
} | [
"public",
"function",
"offsetUnset",
"(",
"$",
"key",
")",
"{",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"entityClass",
";",
"if",
"(",
"$",
"key",
"instanceof",
"$",
"entityClass",
")",
"{",
"$",
"this",
"->",
"entities",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"entities",
",",
"function",
"(",
"$",
"v",
")",
"use",
"(",
"$",
"key",
")",
"{",
"return",
"$",
"v",
"!==",
"$",
"key",
";",
"}",
")",
";",
"return",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entities",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"entities",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Remove an entity from the collection
@param mixed $key
@return bool|void | [
"Remove",
"an",
"entity",
"from",
"the",
"collection"
] | feb915da5d26b60f536282e1bc3ad5c22e53f485 | https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Model/AbstractCollection.php#L204-L221 |
6,152 | uthando-cms/uthando-common | src/UthandoCommon/Model/AbstractCollection.php | AbstractCollection.offsetGet | public function offsetGet($key)
{
return isset($this->entities[$key]) ?
$this->entities[$key] :
null;
} | php | public function offsetGet($key)
{
return isset($this->entities[$key]) ?
$this->entities[$key] :
null;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"entities",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"entities",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Get the specified entity in the collection
@param mixed $key
@return mixed|null | [
"Get",
"the",
"specified",
"entity",
"in",
"the",
"collection"
] | feb915da5d26b60f536282e1bc3ad5c22e53f485 | https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Model/AbstractCollection.php#L229-L234 |
6,153 | uthando-cms/uthando-common | src/UthandoCommon/Model/AbstractCollection.php | AbstractCollection.seek | public function seek($index)
{
$this->rewind();
$position = 0;
while ($position < $index && $this->valid()) {
$this->next();
$position++;
}
if (!$this->valid()) {
throw new CollectionException('Invalid seek position');
}
} | php | public function seek($index)
{
$this->rewind();
$position = 0;
while ($position < $index && $this->valid()) {
$this->next();
$position++;
}
if (!$this->valid()) {
throw new CollectionException('Invalid seek position');
}
} | [
"public",
"function",
"seek",
"(",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"$",
"position",
"=",
"0",
";",
"while",
"(",
"$",
"position",
"<",
"$",
"index",
"&&",
"$",
"this",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"next",
"(",
")",
";",
"$",
"position",
"++",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"valid",
"(",
")",
")",
"{",
"throw",
"new",
"CollectionException",
"(",
"'Invalid seek position'",
")",
";",
"}",
"}"
] | Seek to the given index.
@param int $index
@throws CollectionException | [
"Seek",
"to",
"the",
"given",
"index",
"."
] | feb915da5d26b60f536282e1bc3ad5c22e53f485 | https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Model/AbstractCollection.php#L253-L266 |
6,154 | bishopb/vanilla | applications/dashboard/controllers/class.utilitycontroller.php | UtilityController.Sort | public function Sort() {
$this->Permission('Garden.Settings.Manage');
$Session = Gdn::Session();
$TransientKey = GetPostValue('TransientKey', '');
$Target = GetPostValue('Target', '');
if ($Session->ValidateTransientKey($TransientKey)) {
$TableID = GetPostValue('TableID', FALSE);
if ($TableID) {
$Rows = GetPostValue($TableID, FALSE);
if (is_array($Rows)) {
try {
$Table = str_replace('Table', '', $TableID);
$TableModel = new Gdn_Model($Table);
foreach ($Rows as $Sort => $ID) {
$TableModel->Update(array('Sort' => $Sort), array($Table.'ID' => $ID));
}
} catch (Exception $ex) {
$this->Form->AddError($ex->getMessage());
}
}
}
}
if ($this->DeliveryType() != DELIVERY_TYPE_BOOL)
Redirect($Target);
$this->Render();
} | php | public function Sort() {
$this->Permission('Garden.Settings.Manage');
$Session = Gdn::Session();
$TransientKey = GetPostValue('TransientKey', '');
$Target = GetPostValue('Target', '');
if ($Session->ValidateTransientKey($TransientKey)) {
$TableID = GetPostValue('TableID', FALSE);
if ($TableID) {
$Rows = GetPostValue($TableID, FALSE);
if (is_array($Rows)) {
try {
$Table = str_replace('Table', '', $TableID);
$TableModel = new Gdn_Model($Table);
foreach ($Rows as $Sort => $ID) {
$TableModel->Update(array('Sort' => $Sort), array($Table.'ID' => $ID));
}
} catch (Exception $ex) {
$this->Form->AddError($ex->getMessage());
}
}
}
}
if ($this->DeliveryType() != DELIVERY_TYPE_BOOL)
Redirect($Target);
$this->Render();
} | [
"public",
"function",
"Sort",
"(",
")",
"{",
"$",
"this",
"->",
"Permission",
"(",
"'Garden.Settings.Manage'",
")",
";",
"$",
"Session",
"=",
"Gdn",
"::",
"Session",
"(",
")",
";",
"$",
"TransientKey",
"=",
"GetPostValue",
"(",
"'TransientKey'",
",",
"''",
")",
";",
"$",
"Target",
"=",
"GetPostValue",
"(",
"'Target'",
",",
"''",
")",
";",
"if",
"(",
"$",
"Session",
"->",
"ValidateTransientKey",
"(",
"$",
"TransientKey",
")",
")",
"{",
"$",
"TableID",
"=",
"GetPostValue",
"(",
"'TableID'",
",",
"FALSE",
")",
";",
"if",
"(",
"$",
"TableID",
")",
"{",
"$",
"Rows",
"=",
"GetPostValue",
"(",
"$",
"TableID",
",",
"FALSE",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"Rows",
")",
")",
"{",
"try",
"{",
"$",
"Table",
"=",
"str_replace",
"(",
"'Table'",
",",
"''",
",",
"$",
"TableID",
")",
";",
"$",
"TableModel",
"=",
"new",
"Gdn_Model",
"(",
"$",
"Table",
")",
";",
"foreach",
"(",
"$",
"Rows",
"as",
"$",
"Sort",
"=>",
"$",
"ID",
")",
"{",
"$",
"TableModel",
"->",
"Update",
"(",
"array",
"(",
"'Sort'",
"=>",
"$",
"Sort",
")",
",",
"array",
"(",
"$",
"Table",
".",
"'ID'",
"=>",
"$",
"ID",
")",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"DeliveryType",
"(",
")",
"!=",
"DELIVERY_TYPE_BOOL",
")",
"Redirect",
"(",
"$",
"Target",
")",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Set the sort order for data on an arbitrary database table.
Expect post values TransientKey, Target (redirect URL), Table (database table name),
and TableID (an array of sort order => unique ID).
@since 2.0.0
@access public | [
"Set",
"the",
"sort",
"order",
"for",
"data",
"on",
"an",
"arbitrary",
"database",
"table",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.utilitycontroller.php#L182-L209 |
6,155 | bishopb/vanilla | applications/dashboard/controllers/class.utilitycontroller.php | UtilityController.Update | public function Update() {
try {
// Check for permission or flood control.
// These settings are loaded/saved to the database because we don't want the config file storing non/config information.
$Now = time();
$LastTime = Gdn::Get('Garden.Update.LastTimestamp', 0);
if ($LastTime + (60 * 60 * 24) > $Now) {
// Check for flood control.
$Count = Gdn::Get('Garden.Update.Count', 0) + 1;
if ($Count > 5) {
if (!Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
// We are only allowing an update of 5 times every 24 hours.
throw PermissionException();
}
}
} else {
$Count = 1;
}
Gdn::Set('Garden.Update.LastTimestamp', $Now);
Gdn::Set('Garden.Update.Count', $Count);
} catch (PermissionException $Ex) {
return;
} catch (Exception $Ex) {}
try {
// Run the structure.
$UpdateModel = new UpdateModel();
$UpdateModel->RunStructure();
$this->SetData('Success', TRUE);
} catch (Exception $Ex) {
$this->SetData('Success', FALSE);
}
if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
SaveToConfig('Garden.Version', APPLICATION_VERSION);
}
if ($Target = $this->Request->Get('Target')) {
Redirect($Target);
}
$this->FireEvent('AfterUpdate');
$this->MasterView = 'empty';
$this->CssClass = 'Home';
$this->Render();
} | php | public function Update() {
try {
// Check for permission or flood control.
// These settings are loaded/saved to the database because we don't want the config file storing non/config information.
$Now = time();
$LastTime = Gdn::Get('Garden.Update.LastTimestamp', 0);
if ($LastTime + (60 * 60 * 24) > $Now) {
// Check for flood control.
$Count = Gdn::Get('Garden.Update.Count', 0) + 1;
if ($Count > 5) {
if (!Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
// We are only allowing an update of 5 times every 24 hours.
throw PermissionException();
}
}
} else {
$Count = 1;
}
Gdn::Set('Garden.Update.LastTimestamp', $Now);
Gdn::Set('Garden.Update.Count', $Count);
} catch (PermissionException $Ex) {
return;
} catch (Exception $Ex) {}
try {
// Run the structure.
$UpdateModel = new UpdateModel();
$UpdateModel->RunStructure();
$this->SetData('Success', TRUE);
} catch (Exception $Ex) {
$this->SetData('Success', FALSE);
}
if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
SaveToConfig('Garden.Version', APPLICATION_VERSION);
}
if ($Target = $this->Request->Get('Target')) {
Redirect($Target);
}
$this->FireEvent('AfterUpdate');
$this->MasterView = 'empty';
$this->CssClass = 'Home';
$this->Render();
} | [
"public",
"function",
"Update",
"(",
")",
"{",
"try",
"{",
"// Check for permission or flood control.",
"// These settings are loaded/saved to the database because we don't want the config file storing non/config information.",
"$",
"Now",
"=",
"time",
"(",
")",
";",
"$",
"LastTime",
"=",
"Gdn",
"::",
"Get",
"(",
"'Garden.Update.LastTimestamp'",
",",
"0",
")",
";",
"if",
"(",
"$",
"LastTime",
"+",
"(",
"60",
"*",
"60",
"*",
"24",
")",
">",
"$",
"Now",
")",
"{",
"// Check for flood control.",
"$",
"Count",
"=",
"Gdn",
"::",
"Get",
"(",
"'Garden.Update.Count'",
",",
"0",
")",
"+",
"1",
";",
"if",
"(",
"$",
"Count",
">",
"5",
")",
"{",
"if",
"(",
"!",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"CheckPermission",
"(",
"'Garden.Settings.Manage'",
")",
")",
"{",
"// We are only allowing an update of 5 times every 24 hours.",
"throw",
"PermissionException",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"Count",
"=",
"1",
";",
"}",
"Gdn",
"::",
"Set",
"(",
"'Garden.Update.LastTimestamp'",
",",
"$",
"Now",
")",
";",
"Gdn",
"::",
"Set",
"(",
"'Garden.Update.Count'",
",",
"$",
"Count",
")",
";",
"}",
"catch",
"(",
"PermissionException",
"$",
"Ex",
")",
"{",
"return",
";",
"}",
"catch",
"(",
"Exception",
"$",
"Ex",
")",
"{",
"}",
"try",
"{",
"// Run the structure.",
"$",
"UpdateModel",
"=",
"new",
"UpdateModel",
"(",
")",
";",
"$",
"UpdateModel",
"->",
"RunStructure",
"(",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'Success'",
",",
"TRUE",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"Ex",
")",
"{",
"$",
"this",
"->",
"SetData",
"(",
"'Success'",
",",
"FALSE",
")",
";",
"}",
"if",
"(",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"CheckPermission",
"(",
"'Garden.Settings.Manage'",
")",
")",
"{",
"SaveToConfig",
"(",
"'Garden.Version'",
",",
"APPLICATION_VERSION",
")",
";",
"}",
"if",
"(",
"$",
"Target",
"=",
"$",
"this",
"->",
"Request",
"->",
"Get",
"(",
"'Target'",
")",
")",
"{",
"Redirect",
"(",
"$",
"Target",
")",
";",
"}",
"$",
"this",
"->",
"FireEvent",
"(",
"'AfterUpdate'",
")",
";",
"$",
"this",
"->",
"MasterView",
"=",
"'empty'",
";",
"$",
"this",
"->",
"CssClass",
"=",
"'Home'",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Run a structure update on the database.
@since 2.0.?
@access public | [
"Run",
"a",
"structure",
"update",
"on",
"the",
"database",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.utilitycontroller.php#L346-L394 |
6,156 | bishopb/vanilla | applications/dashboard/controllers/class.utilitycontroller.php | UtilityController.Alive | public function Alive() {
$this->SetData('Success', TRUE);
$this->MasterView = 'empty';
$this->CssClass = 'Home';
$this->FireEvent('Alive');
$this->Render();
} | php | public function Alive() {
$this->SetData('Success', TRUE);
$this->MasterView = 'empty';
$this->CssClass = 'Home';
$this->FireEvent('Alive');
$this->Render();
} | [
"public",
"function",
"Alive",
"(",
")",
"{",
"$",
"this",
"->",
"SetData",
"(",
"'Success'",
",",
"TRUE",
")",
";",
"$",
"this",
"->",
"MasterView",
"=",
"'empty'",
";",
"$",
"this",
"->",
"CssClass",
"=",
"'Home'",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'Alive'",
")",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Signs of life.
@since 2.0.?
@access public | [
"Signs",
"of",
"life",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.utilitycontroller.php#L412-L420 |
6,157 | bishopb/vanilla | applications/dashboard/controllers/class.utilitycontroller.php | UtilityController.GetFeed | public function GetFeed($Type = 'news', $Length = 5, $FeedFormat = 'normal') {
echo file_get_contents('http://vanillaforums.org/vforg/home/getfeed/'.$Type.'/'.$Length.'/'.$FeedFormat.'/?DeliveryType=VIEW');
$this->DeliveryType(DELIVERY_TYPE_NONE);
$this->Render();
} | php | public function GetFeed($Type = 'news', $Length = 5, $FeedFormat = 'normal') {
echo file_get_contents('http://vanillaforums.org/vforg/home/getfeed/'.$Type.'/'.$Length.'/'.$FeedFormat.'/?DeliveryType=VIEW');
$this->DeliveryType(DELIVERY_TYPE_NONE);
$this->Render();
} | [
"public",
"function",
"GetFeed",
"(",
"$",
"Type",
"=",
"'news'",
",",
"$",
"Length",
"=",
"5",
",",
"$",
"FeedFormat",
"=",
"'normal'",
")",
"{",
"echo",
"file_get_contents",
"(",
"'http://vanillaforums.org/vforg/home/getfeed/'",
".",
"$",
"Type",
".",
"'/'",
".",
"$",
"Length",
".",
"'/'",
".",
"$",
"FeedFormat",
".",
"'/?DeliveryType=VIEW'",
")",
";",
"$",
"this",
"->",
"DeliveryType",
"(",
"DELIVERY_TYPE_NONE",
")",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Grab a feed from the mothership.
@since 2.0.?
@access public
@param string $Type Type of feed.
@param int $Length Number of items to get.
@param string $FeedFormat How we want it (valid formats are 'normal' or 'sexy'. OK, not really). | [
"Grab",
"a",
"feed",
"from",
"the",
"mothership",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.utilitycontroller.php#L479-L483 |
6,158 | bishopb/vanilla | applications/dashboard/controllers/class.utilitycontroller.php | UtilityController.FetchPageInfo | public function FetchPageInfo($Url = '') {
$PageInfo = FetchPageInfo($Url);
$this->SetData('PageInfo', $PageInfo);
$this->MasterView = 'default';
$this->RemoveCssFile('admin.css');
$this->AddCssFile('style.css');
$this->SetData('_NoPanel', TRUE);
$this->Render();
} | php | public function FetchPageInfo($Url = '') {
$PageInfo = FetchPageInfo($Url);
$this->SetData('PageInfo', $PageInfo);
$this->MasterView = 'default';
$this->RemoveCssFile('admin.css');
$this->AddCssFile('style.css');
$this->SetData('_NoPanel', TRUE);
$this->Render();
} | [
"public",
"function",
"FetchPageInfo",
"(",
"$",
"Url",
"=",
"''",
")",
"{",
"$",
"PageInfo",
"=",
"FetchPageInfo",
"(",
"$",
"Url",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'PageInfo'",
",",
"$",
"PageInfo",
")",
";",
"$",
"this",
"->",
"MasterView",
"=",
"'default'",
";",
"$",
"this",
"->",
"RemoveCssFile",
"(",
"'admin.css'",
")",
";",
"$",
"this",
"->",
"AddCssFile",
"(",
"'style.css'",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_NoPanel'",
",",
"TRUE",
")",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Return some meta information about any page on the internet in JSON format. | [
"Return",
"some",
"meta",
"information",
"about",
"any",
"page",
"on",
"the",
"internet",
"in",
"JSON",
"format",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.utilitycontroller.php#L488-L496 |
6,159 | ForceLabsDev/framework | src/Traits/Singleton.php | Singleton.getInstance | final public static function getInstance(...$params)
{
$called = static::class;
if (self::$instance instanceof $called) {
return self::$instance;
} else {
return self::$instance = new $called(...$params);
}
} | php | final public static function getInstance(...$params)
{
$called = static::class;
if (self::$instance instanceof $called) {
return self::$instance;
} else {
return self::$instance = new $called(...$params);
}
} | [
"final",
"public",
"static",
"function",
"getInstance",
"(",
"...",
"$",
"params",
")",
"{",
"$",
"called",
"=",
"static",
"::",
"class",
";",
"if",
"(",
"self",
"::",
"$",
"instance",
"instanceof",
"$",
"called",
")",
"{",
"return",
"self",
"::",
"$",
"instance",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"$",
"instance",
"=",
"new",
"$",
"called",
"(",
"...",
"$",
"params",
")",
";",
"}",
"}"
] | Dynamic singleton can call a class with parameters.
@param ...$params
@return $this
@throws \ForceLabs\Framework\Debug\BasicException | [
"Dynamic",
"singleton",
"can",
"call",
"a",
"class",
"with",
"parameters",
"."
] | e2288582432857771e85c9859acd6d32e5f2f9b7 | https://github.com/ForceLabsDev/framework/blob/e2288582432857771e85c9859acd6d32e5f2f9b7/src/Traits/Singleton.php#L34-L42 |
6,160 | Sparhandy/CodingStandard | src/phpcs/Production/Sniffs/Commenting/MethodDocBlockSpacingSniff.php | MethodDocBlockSpacingSniff.numberOfLineFeedsBetweenDocBlockAndDeclaration | protected function numberOfLineFeedsBetweenDocBlockAndDeclaration(File $sniffedFile, $indexOfFunctionToken)
{
$indexOfClosingDocBlock = $sniffedFile->findPrevious([T_DOC_COMMENT_CLOSE_TAG], $indexOfFunctionToken);
if ($indexOfClosingDocBlock === false)
{
return false;
}
$numberOfLineFeeds = 0;
for ($i = $indexOfClosingDocBlock; $i < $indexOfFunctionToken; $i++)
{
if ($this->isLinefeedToken($sniffedFile, $i))
{
$numberOfLineFeeds++;
}
}
return $numberOfLineFeeds;
} | php | protected function numberOfLineFeedsBetweenDocBlockAndDeclaration(File $sniffedFile, $indexOfFunctionToken)
{
$indexOfClosingDocBlock = $sniffedFile->findPrevious([T_DOC_COMMENT_CLOSE_TAG], $indexOfFunctionToken);
if ($indexOfClosingDocBlock === false)
{
return false;
}
$numberOfLineFeeds = 0;
for ($i = $indexOfClosingDocBlock; $i < $indexOfFunctionToken; $i++)
{
if ($this->isLinefeedToken($sniffedFile, $i))
{
$numberOfLineFeeds++;
}
}
return $numberOfLineFeeds;
} | [
"protected",
"function",
"numberOfLineFeedsBetweenDocBlockAndDeclaration",
"(",
"File",
"$",
"sniffedFile",
",",
"$",
"indexOfFunctionToken",
")",
"{",
"$",
"indexOfClosingDocBlock",
"=",
"$",
"sniffedFile",
"->",
"findPrevious",
"(",
"[",
"T_DOC_COMMENT_CLOSE_TAG",
"]",
",",
"$",
"indexOfFunctionToken",
")",
";",
"if",
"(",
"$",
"indexOfClosingDocBlock",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"numberOfLineFeeds",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"indexOfClosingDocBlock",
";",
"$",
"i",
"<",
"$",
"indexOfFunctionToken",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isLinefeedToken",
"(",
"$",
"sniffedFile",
",",
"$",
"i",
")",
")",
"{",
"$",
"numberOfLineFeeds",
"++",
";",
"}",
"}",
"return",
"$",
"numberOfLineFeeds",
";",
"}"
] | Counts the linefeeds between a method declaration and its docblock.
@param File $sniffedFile file to be checked
@param int $indexOfFunctionToken position of current token in token list
@return int | [
"Counts",
"the",
"linefeeds",
"between",
"a",
"method",
"declaration",
"and",
"its",
"docblock",
"."
] | 519a0b0a4dc172b118bac1f22a25badfbf993b87 | https://github.com/Sparhandy/CodingStandard/blob/519a0b0a4dc172b118bac1f22a25badfbf993b87/src/phpcs/Production/Sniffs/Commenting/MethodDocBlockSpacingSniff.php#L50-L68 |
6,161 | mintyphp/tools | conventionist.php | Conventionist.pluralize | private static function pluralize($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)$/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)$/i', "$1es"),
array('/(octop|vir)us$/i', "$1i"),
array('/(ax|test)is$/i', "$1es"),
array('/s$/i', "s"),
array('/$/', "s"),
);
$irregular = array(
array('move', 'moves'),
array('sex', 'sexes'),
array('child', 'children'),
array('man', 'men'),
array('person', 'people'),
);
$uncountable = array(
'sheep',
'fish',
'series',
'species',
'money',
'rice',
'information',
'equipment',
);
// save some time in the case that singular and plural are the same
if (in_array(strtolower($string), $uncountable)) {
return $string;
}
// check for irregular singular forms
foreach ($irregular as $noun) {if (strtolower($string) == $noun[0]) {
return $noun[1];
}
}
// check for matches using regular expressions
foreach ($plural as $pattern) {if (preg_match($pattern[0], $string)) {
return preg_replace($pattern[0], $pattern[1], $string);
}
}
return $string;
} | php | private static function pluralize($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)$/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)$/i', "$1es"),
array('/(octop|vir)us$/i', "$1i"),
array('/(ax|test)is$/i', "$1es"),
array('/s$/i', "s"),
array('/$/', "s"),
);
$irregular = array(
array('move', 'moves'),
array('sex', 'sexes'),
array('child', 'children'),
array('man', 'men'),
array('person', 'people'),
);
$uncountable = array(
'sheep',
'fish',
'series',
'species',
'money',
'rice',
'information',
'equipment',
);
// save some time in the case that singular and plural are the same
if (in_array(strtolower($string), $uncountable)) {
return $string;
}
// check for irregular singular forms
foreach ($irregular as $noun) {if (strtolower($string) == $noun[0]) {
return $noun[1];
}
}
// check for matches using regular expressions
foreach ($plural as $pattern) {if (preg_match($pattern[0], $string)) {
return preg_replace($pattern[0], $pattern[1], $string);
}
}
return $string;
} | [
"private",
"static",
"function",
"pluralize",
"(",
"$",
"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)$/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)$/i'",
",",
"\"$1es\"",
")",
",",
"array",
"(",
"'/(octop|vir)us$/i'",
",",
"\"$1i\"",
")",
",",
"array",
"(",
"'/(ax|test)is$/i'",
",",
"\"$1es\"",
")",
",",
"array",
"(",
"'/s$/i'",
",",
"\"s\"",
")",
",",
"array",
"(",
"'/$/'",
",",
"\"s\"",
")",
",",
")",
";",
"$",
"irregular",
"=",
"array",
"(",
"array",
"(",
"'move'",
",",
"'moves'",
")",
",",
"array",
"(",
"'sex'",
",",
"'sexes'",
")",
",",
"array",
"(",
"'child'",
",",
"'children'",
")",
",",
"array",
"(",
"'man'",
",",
"'men'",
")",
",",
"array",
"(",
"'person'",
",",
"'people'",
")",
",",
")",
";",
"$",
"uncountable",
"=",
"array",
"(",
"'sheep'",
",",
"'fish'",
",",
"'series'",
",",
"'species'",
",",
"'money'",
",",
"'rice'",
",",
"'information'",
",",
"'equipment'",
",",
")",
";",
"// save some time in the case that singular and plural are the same",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"string",
")",
",",
"$",
"uncountable",
")",
")",
"{",
"return",
"$",
"string",
";",
"}",
"// check for irregular singular forms",
"foreach",
"(",
"$",
"irregular",
"as",
"$",
"noun",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"string",
")",
"==",
"$",
"noun",
"[",
"0",
"]",
")",
"{",
"return",
"$",
"noun",
"[",
"1",
"]",
";",
"}",
"}",
"// check for matches using regular expressions",
"foreach",
"(",
"$",
"plural",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
"[",
"0",
"]",
",",
"$",
"string",
")",
")",
"{",
"return",
"preg_replace",
"(",
"$",
"pattern",
"[",
"0",
"]",
",",
"$",
"pattern",
"[",
"1",
"]",
",",
"$",
"string",
")",
";",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] | who translated it from Ruby from the Rails Inflector class | [
"who",
"translated",
"it",
"from",
"Ruby",
"from",
"the",
"Rails",
"Inflector",
"class"
] | e2ecbc9d5b7aaabf46b8d2473445535defc47696 | https://github.com/mintyphp/tools/blob/e2ecbc9d5b7aaabf46b8d2473445535defc47696/conventionist.php#L99-L155 |
6,162 | narrowspark/automatic-common | Generator/AbstractGenerator.php | AbstractGenerator.generate | public function generate(): void
{
$this->filesystem->mkdir($this->getDirectories());
foreach ($this->getFiles() as $filePath => $fileContent) {
$this->filesystem->dumpFile($filePath, $fileContent);
}
$this->filesystem->remove($this->clean());
} | php | public function generate(): void
{
$this->filesystem->mkdir($this->getDirectories());
foreach ($this->getFiles() as $filePath => $fileContent) {
$this->filesystem->dumpFile($filePath, $fileContent);
}
$this->filesystem->remove($this->clean());
} | [
"public",
"function",
"generate",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"mkdir",
"(",
"$",
"this",
"->",
"getDirectories",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFiles",
"(",
")",
"as",
"$",
"filePath",
"=>",
"$",
"fileContent",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"dumpFile",
"(",
"$",
"filePath",
",",
"$",
"fileContent",
")",
";",
"}",
"$",
"this",
"->",
"filesystem",
"->",
"remove",
"(",
"$",
"this",
"->",
"clean",
"(",
")",
")",
";",
"}"
] | Generate the project.
@return void | [
"Generate",
"the",
"project",
"."
] | 415f0d566932847c3ca799e06f27e588bd244881 | https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/Generator/AbstractGenerator.php#L56-L65 |
6,163 | lucifurious/kisma | src/Kisma/Core/Tools/DataReader.php | DataReader.nextRowset | public function nextRowset()
{
if ( false !== ( $result = $this->_statement->nextRowset() ) )
{
$this->_index = null;
}
return $result;
} | php | public function nextRowset()
{
if ( false !== ( $result = $this->_statement->nextRowset() ) )
{
$this->_index = null;
}
return $result;
} | [
"public",
"function",
"nextRowset",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"_statement",
"->",
"nextRowset",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"_index",
"=",
"null",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Advances the reader to the next rowset
Not supported by mssql
@return boolean | [
"Advances",
"the",
"reader",
"to",
"the",
"next",
"rowset",
"Not",
"supported",
"by",
"mssql"
] | 4cc9954249da4e535b52f154e728935f07e648ae | https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Tools/DataReader.php#L192-L200 |
6,164 | lucifurious/kisma | src/Kisma/Core/Tools/DataReader.php | DataReader.next | public function next()
{
$this->_row = $this->fetch();
if ( !empty( $this->_row ) )
{
$this->_index++;
}
} | php | public function next()
{
$this->_row = $this->fetch();
if ( !empty( $this->_row ) )
{
$this->_index++;
}
} | [
"public",
"function",
"next",
"(",
")",
"{",
"$",
"this",
"->",
"_row",
"=",
"$",
"this",
"->",
"fetch",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_row",
")",
")",
"{",
"$",
"this",
"->",
"_index",
"++",
";",
"}",
"}"
] | Moves the internal pointer to the next row. | [
"Moves",
"the",
"internal",
"pointer",
"to",
"the",
"next",
"row",
"."
] | 4cc9954249da4e535b52f154e728935f07e648ae | https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Tools/DataReader.php#L259-L267 |
6,165 | headzoo/core | src/Headzoo/Core/Objects.php | Objects.getFullName | public static function getFullName($obj)
{
$name = null;
if (is_object($obj)) {
$name = get_class($obj);
} else if (is_string($obj)) {
$name = trim($obj, '\\');
} else {
self::toss(
"InvalidArgument",
"Argument must be an object or string. Got {0} instead.",
$obj
);
}
return $name;
} | php | public static function getFullName($obj)
{
$name = null;
if (is_object($obj)) {
$name = get_class($obj);
} else if (is_string($obj)) {
$name = trim($obj, '\\');
} else {
self::toss(
"InvalidArgument",
"Argument must be an object or string. Got {0} instead.",
$obj
);
}
return $name;
} | [
"public",
"static",
"function",
"getFullName",
"(",
"$",
"obj",
")",
"{",
"$",
"name",
"=",
"null",
";",
"if",
"(",
"is_object",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"name",
"=",
"get_class",
"(",
"$",
"obj",
")",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"$",
"obj",
",",
"'\\\\'",
")",
";",
"}",
"else",
"{",
"self",
"::",
"toss",
"(",
"\"InvalidArgument\"",
",",
"\"Argument must be an object or string. Got {0} instead.\"",
",",
"$",
"obj",
")",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Returns a fully qualified class name
Returns a string containing the fully qualified name of the class. The name is normalized by
removing leading and trailing namespace separators.
The $obj argument may be either an object, or a string. When given a string the value *shout*
be the name of a class, but this method does not check if the class exists.
Examples:
```php
echo Objects::getFullName(new stdClass());
// Outputs: "stdClass"
echo Objects::getFullName('\Headzoo\Core\Objects');
// Outputs: "Headzoo\Core\Objects"
```
@param object|string $obj An object or class name
@return string | [
"Returns",
"a",
"fully",
"qualified",
"class",
"name"
] | 1e574813e197aa827b3e952f8caa81be31a8b5b5 | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Objects.php#L31-L47 |
6,166 | headzoo/core | src/Headzoo/Core/Objects.php | Objects.isObject | public static function isObject($obj)
{
if (is_object($obj)) {
$is_object = true;
} else if (is_array($obj)) {
$reduced = array_filter($obj, function($o) {
return is_object($o);
});
$is_object = count($reduced) == count($obj);
} else {
$is_object = false;
}
return $is_object;
} | php | public static function isObject($obj)
{
if (is_object($obj)) {
$is_object = true;
} else if (is_array($obj)) {
$reduced = array_filter($obj, function($o) {
return is_object($o);
});
$is_object = count($reduced) == count($obj);
} else {
$is_object = false;
}
return $is_object;
} | [
"public",
"static",
"function",
"isObject",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"is_object",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"reduced",
"=",
"array_filter",
"(",
"$",
"obj",
",",
"function",
"(",
"$",
"o",
")",
"{",
"return",
"is_object",
"(",
"$",
"o",
")",
";",
"}",
")",
";",
"$",
"is_object",
"=",
"count",
"(",
"$",
"reduced",
")",
"==",
"count",
"(",
"$",
"obj",
")",
";",
"}",
"else",
"{",
"$",
"is_object",
"=",
"false",
";",
"}",
"return",
"$",
"is_object",
";",
"}"
] | Returns whether a value is an object, or array of objects
Returns a boolean value indicating whether the $obj argument is an object, or an array of nothing
but objects. Returns false when $obj is neither an object nor array.
Examples:
```php
$obj = new stdClass();
$is = Objects::isObject($obj);
var_dump($is);
// Outputs: bool(true)
$objs = [
new stdClass(),
new Headzoo\Core\Strings()
];
$is = Objects::isObject($objs);
var_dump($is);
// Outputs: bool(true)
$is = Objects::isObject('stdClass');
var_dump($is);
// Outputs: bool(false)
$objs = [
new stdClass(),
'Headzoo\Core\Strings'
];
$is = Objects::isObject($objs);
var_dump($is);
// Outputs: bool(false)
```
@param object|array $obj The object or array of objects to test
@return bool | [
"Returns",
"whether",
"a",
"value",
"is",
"an",
"object",
"or",
"array",
"of",
"objects"
] | 1e574813e197aa827b3e952f8caa81be31a8b5b5 | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Objects.php#L90-L104 |
6,167 | headzoo/core | src/Headzoo/Core/Objects.php | Objects.isInstance | public static function isInstance($obj, $class)
{
if (is_array($obj)) {
$reduced = array_filter($obj, function($o) use($class) {
return self::isInstance($o, $class);
});
$is_instance = count($obj) == count($reduced);
} else {
if (!is_object($obj)) {
$is_instance = false;
} else {
$class = self::getFullName($class);
$is_instance = is_subclass_of($obj, $class) ||
self::getFullName($obj) === $class;
}
}
return $is_instance;
} | php | public static function isInstance($obj, $class)
{
if (is_array($obj)) {
$reduced = array_filter($obj, function($o) use($class) {
return self::isInstance($o, $class);
});
$is_instance = count($obj) == count($reduced);
} else {
if (!is_object($obj)) {
$is_instance = false;
} else {
$class = self::getFullName($class);
$is_instance = is_subclass_of($obj, $class) ||
self::getFullName($obj) === $class;
}
}
return $is_instance;
} | [
"public",
"static",
"function",
"isInstance",
"(",
"$",
"obj",
",",
"$",
"class",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"reduced",
"=",
"array_filter",
"(",
"$",
"obj",
",",
"function",
"(",
"$",
"o",
")",
"use",
"(",
"$",
"class",
")",
"{",
"return",
"self",
"::",
"isInstance",
"(",
"$",
"o",
",",
"$",
"class",
")",
";",
"}",
")",
";",
"$",
"is_instance",
"=",
"count",
"(",
"$",
"obj",
")",
"==",
"count",
"(",
"$",
"reduced",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"is_instance",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"class",
"=",
"self",
"::",
"getFullName",
"(",
"$",
"class",
")",
";",
"$",
"is_instance",
"=",
"is_subclass_of",
"(",
"$",
"obj",
",",
"$",
"class",
")",
"||",
"self",
"::",
"getFullName",
"(",
"$",
"obj",
")",
"===",
"$",
"class",
";",
"}",
"}",
"return",
"$",
"is_instance",
";",
"}"
] | Returns whether the object, or array of objects, is an instance of a class
Similar to PHP's own instanceof comparison operator, this method differs in two ways:
- The first argument may be an array of objects to test.
- The second argument may be a string with the name of a class.
Throws an exception when $obj is not an object or an array of objects.
Examples:
```php
$is = Objects::isInstance(new Strings(), new Strings());
var_dump($is);
// Outputs: bool(true)
$is = Objects::isInstance(new Strings(), Strings::class);
var_dump($is);
// Outputs: bool(true)
$is = Objects::isInstance(new Arrays(), new Strings());
var_dump($is);
// Outputs: bool(false)
$is = Objects::isInstance(new Arrays(), Arrays::class);
var_dump($is);
// Outputs: bool(false)
$objects = [
new Strings(),
new Strings()
];
$is = Objects::isInstance($objects, Strings::class);
var_dump($is);
// Outputs: bool(true)
$objects = [
new Strings(),
new stdClass()
];
$is = Objects::isInstance($objects, Strings::class);
var_dump($is);
// Outputs: bool(false)
$objects = [
[
new Strings(),
new Strings()
],
[
new Strings(),
new Strings()
]
];
$is = Objects::isInstance($objects, Strings::class);
var_dump($is);
// Outputs: bool(true)
```
@param object|object[] $obj The object or array of objects to test
@param object|string $class Object or string naming a class
@return bool
@throws Exceptions\LogicException When the $obj argument is not an object or array of objects | [
"Returns",
"whether",
"the",
"object",
"or",
"array",
"of",
"objects",
"is",
"an",
"instance",
"of",
"a",
"class"
] | 1e574813e197aa827b3e952f8caa81be31a8b5b5 | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Objects.php#L169-L187 |
6,168 | headzoo/core | src/Headzoo/Core/Objects.php | Objects.equals | public static function equals($obj_a, $obj_b, $deep = false)
{
$is_equal = false;
if ($obj_a instanceof $obj_b) {
if ($deep) {
$obj_a = ((array)$obj_a);
$obj_b = ((array)$obj_b);
} else {
$obj_a = get_object_vars($obj_a);
$obj_b = get_object_vars($obj_b);
}
$is_equal = $obj_a === $obj_b;
}
return $is_equal;
} | php | public static function equals($obj_a, $obj_b, $deep = false)
{
$is_equal = false;
if ($obj_a instanceof $obj_b) {
if ($deep) {
$obj_a = ((array)$obj_a);
$obj_b = ((array)$obj_b);
} else {
$obj_a = get_object_vars($obj_a);
$obj_b = get_object_vars($obj_b);
}
$is_equal = $obj_a === $obj_b;
}
return $is_equal;
} | [
"public",
"static",
"function",
"equals",
"(",
"$",
"obj_a",
",",
"$",
"obj_b",
",",
"$",
"deep",
"=",
"false",
")",
"{",
"$",
"is_equal",
"=",
"false",
";",
"if",
"(",
"$",
"obj_a",
"instanceof",
"$",
"obj_b",
")",
"{",
"if",
"(",
"$",
"deep",
")",
"{",
"$",
"obj_a",
"=",
"(",
"(",
"array",
")",
"$",
"obj_a",
")",
";",
"$",
"obj_b",
"=",
"(",
"(",
"array",
")",
"$",
"obj_b",
")",
";",
"}",
"else",
"{",
"$",
"obj_a",
"=",
"get_object_vars",
"(",
"$",
"obj_a",
")",
";",
"$",
"obj_b",
"=",
"get_object_vars",
"(",
"$",
"obj_b",
")",
";",
"}",
"$",
"is_equal",
"=",
"$",
"obj_a",
"===",
"$",
"obj_b",
";",
"}",
"return",
"$",
"is_equal",
";",
"}"
] | Returns whether two objects are equal to each other
For two objects to be equal they must be of the same class type, and public properties from each
must have the same value. When $deep is true, the protected and private property values must
also be equal. A strict === comparison is done between property values.
Examples:
```php
$obj_a = new Strings();
$obj_b = new Strings();
$obj_a->value = "monkey";
$obj_b->value = "moneky";
$is_equal = Objects::equals($obj_a, $obj_b);
var_dump($is_equal);
// Outputs: bool(true)
$obj_a = new Strings();
$obj_b = new Strings();
$obj_a->value = "monkey";
$obj_b->value = "donkey";
$is_equal = Objects::equals($obj_a, $obj_b);
var_dump($is_equal);
// Outputs: bool(false)
```
@param object $obj_a The first object to test
@param object $obj_b The second object to test
@param bool $deep True to check both public and private properties
@return bool | [
"Returns",
"whether",
"two",
"objects",
"are",
"equal",
"to",
"each",
"other"
] | 1e574813e197aa827b3e952f8caa81be31a8b5b5 | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Objects.php#L222-L237 |
6,169 | headzoo/core | src/Headzoo/Core/Objects.php | Objects.merge | public static function merge($obj, $obj2)
{
if (!is_object($obj) || !is_object($obj2)) {
self::toss(
"InvalidArgument",
"Merged values must be objects. Got type {0}.",
gettype($obj)
);
}
if (func_num_args() > 2) {
$args = func_get_args();
$obj = array_shift($args);
foreach($args as $arg) {
self::merge($obj, $arg);
}
} else {
foreach($obj2 as $name => $value) {
if (null !== $value) {
$obj->$name = $value;
}
}
}
return $obj;
} | php | public static function merge($obj, $obj2)
{
if (!is_object($obj) || !is_object($obj2)) {
self::toss(
"InvalidArgument",
"Merged values must be objects. Got type {0}.",
gettype($obj)
);
}
if (func_num_args() > 2) {
$args = func_get_args();
$obj = array_shift($args);
foreach($args as $arg) {
self::merge($obj, $arg);
}
} else {
foreach($obj2 as $name => $value) {
if (null !== $value) {
$obj->$name = $value;
}
}
}
return $obj;
} | [
"public",
"static",
"function",
"merge",
"(",
"$",
"obj",
",",
"$",
"obj2",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"obj",
")",
"||",
"!",
"is_object",
"(",
"$",
"obj2",
")",
")",
"{",
"self",
"::",
"toss",
"(",
"\"InvalidArgument\"",
",",
"\"Merged values must be objects. Got type {0}.\"",
",",
"gettype",
"(",
"$",
"obj",
")",
")",
";",
"}",
"if",
"(",
"func_num_args",
"(",
")",
">",
"2",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"obj",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"self",
"::",
"merge",
"(",
"$",
"obj",
",",
"$",
"arg",
")",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"obj2",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"value",
")",
"{",
"$",
"obj",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"obj",
";",
"}"
] | Merges two or more objects
Copies the public property values from $obj2 to $obj1, and returns $obj1. Properties from $obj2
are either added to $obj1, or overwrite existing properties with the same name. Null values
do not overwrite non-null values. More than two objects may be merged.
Protected and private properties are not merged.
Examples:
```php
$obj_a = new stdClass();
$obj_a->job = "Circus Freak";
$obj_b = new stdClass();
$obj_b->name = "Joe"
$obj_b->job = "Space Buccaneer";
$obj_c = new stdClass();
$obj_c->age = 23;
$merged = Objects::merge($obj_a, $obj_b, $obj_c);
var_dump($obj_a === $merged);
var_dump($merged);
// Outputs:
// bool(true);
// class stdClass {
// public $name => string(4) "Joe"
// public $job => string(15) "Space Buccaneer"
// public $age => int(23)
//
// }
// The objects do not have to be the same type.
$obj_a = new Strings();
$obj_a->value = "PhpStorm Rocks!";
$obj_b = new Strings();
$obj_b->value = "So does IntelliJ IDEA!";
$obj_c = new stdClass();
$obj_c->website = "http://www.jetbrains.com/";
$merged = Objects::merge($obj_a, $obj_b, $obj_c);
var_dump($merged === $obj_a);
var_dump($merged);
// Outputs:
// bool(true)
// class Strings {
// public $value => string(22) "So does IntelliJ IDEA!",
// public $website => string(25) "http://www.jetbrains.com/"
// }
// Easily merge objects into a new "blank" object.
$obj_a = new Strings();
$obj_a->value = "PhpStorm Rocks!";
$obj_b = new Arrays();
$obj_b->count = 23;
$merged = Objects::merge(new stdClass(), $obj_a, $obj_b);
var_dump($merged);
// Outputs:
// class stdClass {
// public $value => string(15) "PhpStorm Rocks!",
// public $count => 23
// }
```
@param object $obj The base object
@param object $obj2 Gets merged into the base object
@param object ... Additional objects to merge
@return mixed | [
"Merges",
"two",
"or",
"more",
"objects"
] | 1e574813e197aa827b3e952f8caa81be31a8b5b5 | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Objects.php#L316-L341 |
6,170 | gliverphp/helpers | src/ArrayHelper/ArrayHelperClass.php | ArrayHelperClass.getMethodArgs | public function getMethodArgs($argName){
//check if the argument is already set
if( array_key_exists($argName, $this->methodArgs)){
//return the value of this argument
return $this->methodArgs[$argName];
}
//this argument is not yet set, so return null
else{
//return a null
return null;
}
} | php | public function getMethodArgs($argName){
//check if the argument is already set
if( array_key_exists($argName, $this->methodArgs)){
//return the value of this argument
return $this->methodArgs[$argName];
}
//this argument is not yet set, so return null
else{
//return a null
return null;
}
} | [
"public",
"function",
"getMethodArgs",
"(",
"$",
"argName",
")",
"{",
"//check if the argument is already set",
"if",
"(",
"array_key_exists",
"(",
"$",
"argName",
",",
"$",
"this",
"->",
"methodArgs",
")",
")",
"{",
"//return the value of this argument",
"return",
"$",
"this",
"->",
"methodArgs",
"[",
"$",
"argName",
"]",
";",
"}",
"//this argument is not yet set, so return null",
"else",
"{",
"//return a null",
"return",
"null",
";",
"}",
"}"
] | This method gets and returns the value of the arguments requested
@param string $argName The name of the argument to look up
@return mixed The value of the argument or a Boolean False on failure | [
"This",
"method",
"gets",
"and",
"returns",
"the",
"value",
"of",
"the",
"arguments",
"requested"
] | c5204df8169fad55f5b273422e45f56164373ab8 | https://github.com/gliverphp/helpers/blob/c5204df8169fad55f5b273422e45f56164373ab8/src/ArrayHelper/ArrayHelperClass.php#L63-L81 |
6,171 | gliverphp/helpers | src/ArrayHelper/ArrayHelperClass.php | ArrayHelperClass.trim | public function trim($array)
{
//set the $inputElement
$this->inputElement = $array;
//loop the through the array elements removing the whitespaces
$this->outputElement = array_map(function($item){
return trim($item);
}, $array);
//return this self same class
return $this;
} | php | public function trim($array)
{
//set the $inputElement
$this->inputElement = $array;
//loop the through the array elements removing the whitespaces
$this->outputElement = array_map(function($item){
return trim($item);
}, $array);
//return this self same class
return $this;
} | [
"public",
"function",
"trim",
"(",
"$",
"array",
")",
"{",
"//set the $inputElement",
"$",
"this",
"->",
"inputElement",
"=",
"$",
"array",
";",
"//loop the through the array elements removing the whitespaces",
"$",
"this",
"->",
"outputElement",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"trim",
"(",
"$",
"item",
")",
";",
"}",
",",
"$",
"array",
")",
";",
"//return this self same class",
"return",
"$",
"this",
";",
"}"
] | This method loops through array elements removing whitespaces from begining and ending of string element values
@param array $array The input array to be trimmed of whitespace
@return Object \ArrayHelper | [
"This",
"method",
"loops",
"through",
"array",
"elements",
"removing",
"whitespaces",
"from",
"begining",
"and",
"ending",
"of",
"string",
"element",
"values"
] | c5204df8169fad55f5b273422e45f56164373ab8 | https://github.com/gliverphp/helpers/blob/c5204df8169fad55f5b273422e45f56164373ab8/src/ArrayHelper/ArrayHelperClass.php#L209-L224 |
6,172 | gliverphp/helpers | src/ArrayHelper/ArrayHelperClass.php | ArrayHelperClass.flatten | public function flatten($array, $return = array())
{
//loop through the multi-dimensional array flattening the array value
foreach ($array as $key => $value)
{
//flatten is array element is a value or element
if( is_array($value) || is_object($value))
{
//return
$return = self::flatten($value, $return);
}
else
{
$return[] = $value;
}
}
//set the value of the $outputElement
$this->outputElement = $return;
//return this self same class
return $this;
} | php | public function flatten($array, $return = array())
{
//loop through the multi-dimensional array flattening the array value
foreach ($array as $key => $value)
{
//flatten is array element is a value or element
if( is_array($value) || is_object($value))
{
//return
$return = self::flatten($value, $return);
}
else
{
$return[] = $value;
}
}
//set the value of the $outputElement
$this->outputElement = $return;
//return this self same class
return $this;
} | [
"public",
"function",
"flatten",
"(",
"$",
"array",
",",
"$",
"return",
"=",
"array",
"(",
")",
")",
"{",
"//loop through the multi-dimensional array flattening the array value",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"//flatten is array element is a value or element",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"//return ",
"$",
"return",
"=",
"self",
"::",
"flatten",
"(",
"$",
"value",
",",
"$",
"return",
")",
";",
"}",
"else",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"//set the value of the $outputElement",
"$",
"this",
"->",
"outputElement",
"=",
"$",
"return",
";",
"//return this self same class",
"return",
"$",
"this",
";",
"}"
] | This method converts a multi-dimensional array into a uni-dimensional array
@param array $array The array to flatten
@param array $return The return array
@return Object \ArrayHelper | [
"This",
"method",
"converts",
"a",
"multi",
"-",
"dimensional",
"array",
"into",
"a",
"uni",
"-",
"dimensional",
"array"
] | c5204df8169fad55f5b273422e45f56164373ab8 | https://github.com/gliverphp/helpers/blob/c5204df8169fad55f5b273422e45f56164373ab8/src/ArrayHelper/ArrayHelperClass.php#L233-L259 |
6,173 | noccy80/php-virtfs | lib/VirtFs.php | VirtFs.addAutoloader | public function addAutoloader($namespace, $path=null, $psr4=false)
{
$loader = new VirtFsLoader($this);
$loader->register($namespace, $path, $psr4);
$this->pushLoader($loader);
} | php | public function addAutoloader($namespace, $path=null, $psr4=false)
{
$loader = new VirtFsLoader($this);
$loader->register($namespace, $path, $psr4);
$this->pushLoader($loader);
} | [
"public",
"function",
"addAutoloader",
"(",
"$",
"namespace",
",",
"$",
"path",
"=",
"null",
",",
"$",
"psr4",
"=",
"false",
")",
"{",
"$",
"loader",
"=",
"new",
"VirtFsLoader",
"(",
"$",
"this",
")",
";",
"$",
"loader",
"->",
"register",
"(",
"$",
"namespace",
",",
"$",
"path",
",",
"$",
"psr4",
")",
";",
"$",
"this",
"->",
"pushLoader",
"(",
"$",
"loader",
")",
";",
"}"
] | Register an autoloader for the virtual filesystem
@param string The namespace to register
@param string The root of the autoloader
@param bool If true, use a psr-4 autoloader, otherwise a psr-0. | [
"Register",
"an",
"autoloader",
"for",
"the",
"virtual",
"filesystem"
] | 480a5e33421b1c81fddf9a4820d5742ebcbfbd7c | https://github.com/noccy80/php-virtfs/blob/480a5e33421b1c81fddf9a4820d5742ebcbfbd7c/lib/VirtFs.php#L71-L76 |
6,174 | noccy80/php-virtfs | lib/VirtFs.php | VirtFs.pushLoader | public function pushLoader(VirtFsLoader $loader)
{
if (!in_array($loader,$this->loaders)) {
$this->loaders[] = $loader;
}
return $this;
} | php | public function pushLoader(VirtFsLoader $loader)
{
if (!in_array($loader,$this->loaders)) {
$this->loaders[] = $loader;
}
return $this;
} | [
"public",
"function",
"pushLoader",
"(",
"VirtFsLoader",
"$",
"loader",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"loader",
",",
"$",
"this",
"->",
"loaders",
")",
")",
"{",
"$",
"this",
"->",
"loaders",
"[",
"]",
"=",
"$",
"loader",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Push a VirtFsLoader onto the stack of autoloaders for the virtual filesystem.
@param \NoccyLabs\VirtFs\VirtFsLoader The loader to register
@return \NoccyLabs\VirtFs\VirtFs | [
"Push",
"a",
"VirtFsLoader",
"onto",
"the",
"stack",
"of",
"autoloaders",
"for",
"the",
"virtual",
"filesystem",
"."
] | 480a5e33421b1c81fddf9a4820d5742ebcbfbd7c | https://github.com/noccy80/php-virtfs/blob/480a5e33421b1c81fddf9a4820d5742ebcbfbd7c/lib/VirtFs.php#L84-L90 |
6,175 | noccy80/php-virtfs | lib/VirtFs.php | VirtFs.registerStreamWrapper | public function registerStreamWrapper($protocol=null)
{
if ($this->registered_wrapper) {
throw new \RuntimeException("Unregister the wrapper before registering it again!");
}
if ($protocol && !$this->protocol) {
$this->protocol = $protocol;
}
$this->registered_wrapper = true;
self::$handlers[$this->protocol] = $this;
return stream_wrapper_register($this->protocol, __CLASS__, 0);
} | php | public function registerStreamWrapper($protocol=null)
{
if ($this->registered_wrapper) {
throw new \RuntimeException("Unregister the wrapper before registering it again!");
}
if ($protocol && !$this->protocol) {
$this->protocol = $protocol;
}
$this->registered_wrapper = true;
self::$handlers[$this->protocol] = $this;
return stream_wrapper_register($this->protocol, __CLASS__, 0);
} | [
"public",
"function",
"registerStreamWrapper",
"(",
"$",
"protocol",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"registered_wrapper",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Unregister the wrapper before registering it again!\"",
")",
";",
"}",
"if",
"(",
"$",
"protocol",
"&&",
"!",
"$",
"this",
"->",
"protocol",
")",
"{",
"$",
"this",
"->",
"protocol",
"=",
"$",
"protocol",
";",
"}",
"$",
"this",
"->",
"registered_wrapper",
"=",
"true",
";",
"self",
"::",
"$",
"handlers",
"[",
"$",
"this",
"->",
"protocol",
"]",
"=",
"$",
"this",
";",
"return",
"stream_wrapper_register",
"(",
"$",
"this",
"->",
"protocol",
",",
"__CLASS__",
",",
"0",
")",
";",
"}"
] | Register a protocol as a stream wrapper.
This makes access possible with the regular file i/o functions using
a path such as "protocol://file.txt".
@param string The protocol to register
@return bool
@throws \RuntimeException | [
"Register",
"a",
"protocol",
"as",
"a",
"stream",
"wrapper",
"."
] | 480a5e33421b1c81fddf9a4820d5742ebcbfbd7c | https://github.com/noccy80/php-virtfs/blob/480a5e33421b1c81fddf9a4820d5742ebcbfbd7c/lib/VirtFs.php#L102-L113 |
6,176 | noccy80/php-virtfs | lib/VirtFs.php | VirtFs.addDirectory | public function addDirectory($path, $mountpoint='/', $writable=false, $priority=0) {
$mounter = new Mounter\DirectoryMounter($path, $mountpoint);
$mounter->setPriority($priority);
$mounter->setIsWritable($writable);
$this->nodes[] = $mounter;
return $this;
} | php | public function addDirectory($path, $mountpoint='/', $writable=false, $priority=0) {
$mounter = new Mounter\DirectoryMounter($path, $mountpoint);
$mounter->setPriority($priority);
$mounter->setIsWritable($writable);
$this->nodes[] = $mounter;
return $this;
} | [
"public",
"function",
"addDirectory",
"(",
"$",
"path",
",",
"$",
"mountpoint",
"=",
"'/'",
",",
"$",
"writable",
"=",
"false",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"$",
"mounter",
"=",
"new",
"Mounter",
"\\",
"DirectoryMounter",
"(",
"$",
"path",
",",
"$",
"mountpoint",
")",
";",
"$",
"mounter",
"->",
"setPriority",
"(",
"$",
"priority",
")",
";",
"$",
"mounter",
"->",
"setIsWritable",
"(",
"$",
"writable",
")",
";",
"$",
"this",
"->",
"nodes",
"[",
"]",
"=",
"$",
"mounter",
";",
"return",
"$",
"this",
";",
"}"
] | Add a directory to the virtual filesystem.
@param string The directory to mount
@param string The mountpoint in the virtual filesystem
@param bool If true, the directory will be considered a candidate for writing operations.
@param int Priority of this location when matching paths
@return \NoccyLabs\VirtFs\VirtFs | [
"Add",
"a",
"directory",
"to",
"the",
"virtual",
"filesystem",
"."
] | 480a5e33421b1c81fddf9a4820d5742ebcbfbd7c | https://github.com/noccy80/php-virtfs/blob/480a5e33421b1c81fddf9a4820d5742ebcbfbd7c/lib/VirtFs.php#L137-L143 |
6,177 | noccy80/php-virtfs | lib/VirtFs.php | VirtFs.addArchive | public function addArchive($path, $mountpoint='/', $priority=0) {
$mounter = new Mounter\ArchiveMounter($path, $mountpoint);
$mounter->setPriority($priority);
$this->nodes[] = $mounter;
return $this;
} | php | public function addArchive($path, $mountpoint='/', $priority=0) {
$mounter = new Mounter\ArchiveMounter($path, $mountpoint);
$mounter->setPriority($priority);
$this->nodes[] = $mounter;
return $this;
} | [
"public",
"function",
"addArchive",
"(",
"$",
"path",
",",
"$",
"mountpoint",
"=",
"'/'",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"$",
"mounter",
"=",
"new",
"Mounter",
"\\",
"ArchiveMounter",
"(",
"$",
"path",
",",
"$",
"mountpoint",
")",
";",
"$",
"mounter",
"->",
"setPriority",
"(",
"$",
"priority",
")",
";",
"$",
"this",
"->",
"nodes",
"[",
"]",
"=",
"$",
"mounter",
";",
"return",
"$",
"this",
";",
"}"
] | Add an archive to the virtual filesystem
@param string The path to the archive to mount
@param string The mountpoint in the virtual filesystem
@param int Priority of this location when matching paths
@return \NoccyLabs\VirtFs\VirtFs | [
"Add",
"an",
"archive",
"to",
"the",
"virtual",
"filesystem"
] | 480a5e33421b1c81fddf9a4820d5742ebcbfbd7c | https://github.com/noccy80/php-virtfs/blob/480a5e33421b1c81fddf9a4820d5742ebcbfbd7c/lib/VirtFs.php#L153-L158 |
6,178 | noccy80/php-virtfs | lib/VirtFs.php | VirtFs.getDirectoryListing | public function getDirectoryListing($path='/')
{
// 1. find out what is mounted on this path
$listing = array();
foreach($this->nodes as $node) {
$mp = $node->getMountPoint();
if ((dirname($mp) == $path) && ($path != '/')) {
$listing[] = basename($mp)."/";
}
if (strncmp($path, $mp, strlen($mp)) === 0) {
$listing = array_merge($listing, $node->getDirectoryListing($path));
}
}
return $listing;
} | php | public function getDirectoryListing($path='/')
{
// 1. find out what is mounted on this path
$listing = array();
foreach($this->nodes as $node) {
$mp = $node->getMountPoint();
if ((dirname($mp) == $path) && ($path != '/')) {
$listing[] = basename($mp)."/";
}
if (strncmp($path, $mp, strlen($mp)) === 0) {
$listing = array_merge($listing, $node->getDirectoryListing($path));
}
}
return $listing;
} | [
"public",
"function",
"getDirectoryListing",
"(",
"$",
"path",
"=",
"'/'",
")",
"{",
"// 1. find out what is mounted on this path",
"$",
"listing",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"mp",
"=",
"$",
"node",
"->",
"getMountPoint",
"(",
")",
";",
"if",
"(",
"(",
"dirname",
"(",
"$",
"mp",
")",
"==",
"$",
"path",
")",
"&&",
"(",
"$",
"path",
"!=",
"'/'",
")",
")",
"{",
"$",
"listing",
"[",
"]",
"=",
"basename",
"(",
"$",
"mp",
")",
".",
"\"/\"",
";",
"}",
"if",
"(",
"strncmp",
"(",
"$",
"path",
",",
"$",
"mp",
",",
"strlen",
"(",
"$",
"mp",
")",
")",
"===",
"0",
")",
"{",
"$",
"listing",
"=",
"array_merge",
"(",
"$",
"listing",
",",
"$",
"node",
"->",
"getDirectoryListing",
"(",
"$",
"path",
")",
")",
";",
"}",
"}",
"return",
"$",
"listing",
";",
"}"
] | Get a directory listing from the virtual filesystem.
@param string The path to get the listing of
@return type | [
"Get",
"a",
"directory",
"listing",
"from",
"the",
"virtual",
"filesystem",
"."
] | 480a5e33421b1c81fddf9a4820d5742ebcbfbd7c | https://github.com/noccy80/php-virtfs/blob/480a5e33421b1c81fddf9a4820d5742ebcbfbd7c/lib/VirtFs.php#L166-L181 |
6,179 | noccy80/php-virtfs | lib/VirtFs.php | VirtFs.getPath | public function getPath($file)
{
$file = "/".ltrim($file,"/");
$best = null;
foreach($this->nodes as $node) {
$mount = $node->getMountPoint();
if (strncmp($mount, $file, strlen($mount)) === 0) {
$nodefile = substr($file, strlen($mount));
//printf("nodefile=%s mount=%s file=%s\n", $nodefile, $mount, $file);
if ($node->has($nodefile)) {
return $node->getPath($nodefile);
}
if (!$best) {
$best = $node->getPath($nodefile);
}
if ($node->getIsWritable($nodefile)) {
$best = $node->getPath($nodefile);
}
}
}
return $best;
} | php | public function getPath($file)
{
$file = "/".ltrim($file,"/");
$best = null;
foreach($this->nodes as $node) {
$mount = $node->getMountPoint();
if (strncmp($mount, $file, strlen($mount)) === 0) {
$nodefile = substr($file, strlen($mount));
//printf("nodefile=%s mount=%s file=%s\n", $nodefile, $mount, $file);
if ($node->has($nodefile)) {
return $node->getPath($nodefile);
}
if (!$best) {
$best = $node->getPath($nodefile);
}
if ($node->getIsWritable($nodefile)) {
$best = $node->getPath($nodefile);
}
}
}
return $best;
} | [
"public",
"function",
"getPath",
"(",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"\"/\"",
".",
"ltrim",
"(",
"$",
"file",
",",
"\"/\"",
")",
";",
"$",
"best",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"mount",
"=",
"$",
"node",
"->",
"getMountPoint",
"(",
")",
";",
"if",
"(",
"strncmp",
"(",
"$",
"mount",
",",
"$",
"file",
",",
"strlen",
"(",
"$",
"mount",
")",
")",
"===",
"0",
")",
"{",
"$",
"nodefile",
"=",
"substr",
"(",
"$",
"file",
",",
"strlen",
"(",
"$",
"mount",
")",
")",
";",
"//printf(\"nodefile=%s mount=%s file=%s\\n\", $nodefile, $mount, $file);",
"if",
"(",
"$",
"node",
"->",
"has",
"(",
"$",
"nodefile",
")",
")",
"{",
"return",
"$",
"node",
"->",
"getPath",
"(",
"$",
"nodefile",
")",
";",
"}",
"if",
"(",
"!",
"$",
"best",
")",
"{",
"$",
"best",
"=",
"$",
"node",
"->",
"getPath",
"(",
"$",
"nodefile",
")",
";",
"}",
"if",
"(",
"$",
"node",
"->",
"getIsWritable",
"(",
"$",
"nodefile",
")",
")",
"{",
"$",
"best",
"=",
"$",
"node",
"->",
"getPath",
"(",
"$",
"nodefile",
")",
";",
"}",
"}",
"}",
"return",
"$",
"best",
";",
"}"
] | Get the canonical path to a file in the virtual filesystem.
@param string The file to get the path of
@return string The full path or URI to the file | [
"Get",
"the",
"canonical",
"path",
"to",
"a",
"file",
"in",
"the",
"virtual",
"filesystem",
"."
] | 480a5e33421b1c81fddf9a4820d5742ebcbfbd7c | https://github.com/noccy80/php-virtfs/blob/480a5e33421b1c81fddf9a4820d5742ebcbfbd7c/lib/VirtFs.php#L211-L234 |
6,180 | cblanquera/cradle-captcha | src/Action/Captcha.php | Captcha.render | public function render(Request $request, Response $response) {
$key = $response->getResults('captcha');
$content = $response->getContent();
$content .= '<script src="https://www.google.com/recaptcha/api.js"></script>';
$content .= '<div class="form-group"><div class="g-recaptcha" '
. 'data-sitekey="'.$key.'"></div></div>';
$response->setContent($content);
return $this;
} | php | public function render(Request $request, Response $response) {
$key = $response->getResults('captcha');
$content = $response->getContent();
$content .= '<script src="https://www.google.com/recaptcha/api.js"></script>';
$content .= '<div class="form-group"><div class="g-recaptcha" '
. 'data-sitekey="'.$key.'"></div></div>';
$response->setContent($content);
return $this;
} | [
"public",
"function",
"render",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"key",
"=",
"$",
"response",
"->",
"getResults",
"(",
"'captcha'",
")",
";",
"$",
"content",
"=",
"$",
"response",
"->",
"getContent",
"(",
")",
";",
"$",
"content",
".=",
"'<script src=\"https://www.google.com/recaptcha/api.js\"></script>'",
";",
"$",
"content",
".=",
"'<div class=\"form-group\"><div class=\"g-recaptcha\" '",
".",
"'data-sitekey=\"'",
".",
"$",
"key",
".",
"'\"></div></div>'",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Renders a csrf field
@param *Request $request
@param *Response $response
@return Csrf | [
"Renders",
"a",
"csrf",
"field"
] | c0f2c25b0b1d3f55640278ae367bd80abd677219 | https://github.com/cblanquera/cradle-captcha/blob/c0f2c25b0b1d3f55640278ae367bd80abd677219/src/Action/Captcha.php#L143-L153 |
6,181 | vinala/kernel | src/Mailing/Mailable.php | Mailable.view | public function view($name)
{
$this->_view = View::make($name);
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (!in_array($key, ['_view', '_text', '_type', '_subject', '_sender_name', '_sender_mail'])) {
$this->_view->with($key, $value);
}
}
$this->_type = 'text/html';
return $this;
} | php | public function view($name)
{
$this->_view = View::make($name);
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (!in_array($key, ['_view', '_text', '_type', '_subject', '_sender_name', '_sender_mail'])) {
$this->_view->with($key, $value);
}
}
$this->_type = 'text/html';
return $this;
} | [
"public",
"function",
"view",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"_view",
"=",
"View",
"::",
"make",
"(",
"$",
"name",
")",
";",
"$",
"vars",
"=",
"get_object_vars",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"[",
"'_view'",
",",
"'_text'",
",",
"'_type'",
",",
"'_subject'",
",",
"'_sender_name'",
",",
"'_sender_mail'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_view",
"->",
"with",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_type",
"=",
"'text/html'",
";",
"return",
"$",
"this",
";",
"}"
] | Set the view.
@param string $name
@return $this | [
"Set",
"the",
"view",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Mailing/Mailable.php#L146-L161 |
6,182 | vinala/kernel | src/Mailing/Mailable.php | Mailable.from | public function from($mail, $name)
{
$this->_sender_name = $name;
$this->_sender_mail = $mail;
return $this;
} | php | public function from($mail, $name)
{
$this->_sender_name = $name;
$this->_sender_mail = $mail;
return $this;
} | [
"public",
"function",
"from",
"(",
"$",
"mail",
",",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"_sender_name",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"_sender_mail",
"=",
"$",
"mail",
";",
"return",
"$",
"this",
";",
"}"
] | Set the sender email and name.
@param string $mail
@param string $name
@return $this | [
"Set",
"the",
"sender",
"email",
"and",
"name",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Mailing/Mailable.php#L187-L193 |
6,183 | vinala/kernel | src/Mailing/Mailable.php | Mailable.attachments | public function attachments()
{
$files = func_get_args();
foreach ($files as $file) {
if (is_string($file)) {
$this->_attachments[] = ['file' => $file];
} elseif (is_array($file)) {
foreach ($file as $key => $value) {
$this->_attachments[] = ['name' => $key, 'file' => $value];
}
}
}
return $this;
} | php | public function attachments()
{
$files = func_get_args();
foreach ($files as $file) {
if (is_string($file)) {
$this->_attachments[] = ['file' => $file];
} elseif (is_array($file)) {
foreach ($file as $key => $value) {
$this->_attachments[] = ['name' => $key, 'file' => $value];
}
}
}
return $this;
} | [
"public",
"function",
"attachments",
"(",
")",
"{",
"$",
"files",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"_attachments",
"[",
"]",
"=",
"[",
"'file'",
"=>",
"$",
"file",
"]",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"file",
")",
")",
"{",
"foreach",
"(",
"$",
"file",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_attachments",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"key",
",",
"'file'",
"=>",
"$",
"value",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | add attachments to the mail.
@return $this | [
"add",
"attachments",
"to",
"the",
"mail",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Mailing/Mailable.php#L214-L229 |
6,184 | vinala/kernel | src/Mailing/Mailable.php | Mailable.attachment | public function attachment($file, $name = null)
{
if (!is_null($name)) {
$this->_attachments[] = ['name' => $key, 'file' => $value];
} else {
$this->_attachments[] = ['file' => $value];
}
return $this;
} | php | public function attachment($file, $name = null)
{
if (!is_null($name)) {
$this->_attachments[] = ['name' => $key, 'file' => $value];
} else {
$this->_attachments[] = ['file' => $value];
}
return $this;
} | [
"public",
"function",
"attachment",
"(",
"$",
"file",
",",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"_attachments",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"key",
",",
"'file'",
"=>",
"$",
"value",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_attachments",
"[",
"]",
"=",
"[",
"'file'",
"=>",
"$",
"value",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add attachment to the mail.
@param string $file
@param string $name
@return $this | [
"Add",
"attachment",
"to",
"the",
"mail",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Mailing/Mailable.php#L239-L248 |
6,185 | vinala/kernel | src/Mailing/Mailable.php | Mailable.cc | public function cc()
{
$mails = func_get_args();
foreach ($mails as $mail) {
if (is_string($mail)) {
$this->_cc[] = $mail;
} elseif (is_array($mail)) {
foreach ($mail as $submail) {
$this->_cc[] = $submail;
}
}
}
return $this;
} | php | public function cc()
{
$mails = func_get_args();
foreach ($mails as $mail) {
if (is_string($mail)) {
$this->_cc[] = $mail;
} elseif (is_array($mail)) {
foreach ($mail as $submail) {
$this->_cc[] = $submail;
}
}
}
return $this;
} | [
"public",
"function",
"cc",
"(",
")",
"{",
"$",
"mails",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"mails",
"as",
"$",
"mail",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"mail",
")",
")",
"{",
"$",
"this",
"->",
"_cc",
"[",
"]",
"=",
"$",
"mail",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"mail",
")",
")",
"{",
"foreach",
"(",
"$",
"mail",
"as",
"$",
"submail",
")",
"{",
"$",
"this",
"->",
"_cc",
"[",
"]",
"=",
"$",
"submail",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add Carbon Copy to mailable.
@return $this | [
"Add",
"Carbon",
"Copy",
"to",
"mailable",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Mailing/Mailable.php#L255-L270 |
6,186 | vinala/kernel | src/Mailing/Mailable.php | Mailable.cci | public function cci()
{
$mails = func_get_args();
foreach ($mails as $mail) {
if (is_string($mail)) {
$this->_cci[] = $mail;
} elseif (is_array($mail)) {
foreach ($mail as $submail) {
$this->_cci[] = $submail;
}
}
}
return $this;
} | php | public function cci()
{
$mails = func_get_args();
foreach ($mails as $mail) {
if (is_string($mail)) {
$this->_cci[] = $mail;
} elseif (is_array($mail)) {
foreach ($mail as $submail) {
$this->_cci[] = $submail;
}
}
}
return $this;
} | [
"public",
"function",
"cci",
"(",
")",
"{",
"$",
"mails",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"mails",
"as",
"$",
"mail",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"mail",
")",
")",
"{",
"$",
"this",
"->",
"_cci",
"[",
"]",
"=",
"$",
"mail",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"mail",
")",
")",
"{",
"foreach",
"(",
"$",
"mail",
"as",
"$",
"submail",
")",
"{",
"$",
"this",
"->",
"_cci",
"[",
"]",
"=",
"$",
"submail",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add Invisble Carbon Copy to mailable.
@return $this | [
"Add",
"Invisble",
"Carbon",
"Copy",
"to",
"mailable",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Mailing/Mailable.php#L277-L292 |
6,187 | samurai-fw/samurai | src/Samurai/Filter/ViewFilter.php | ViewFilter._renderTemplate | private function _renderTemplate($template = null)
{
// when no template, auto generate template path.
// View/Content/[controller]/[action].html.twig
$def = $this->actionChain->getCurrentAction();
if (! $template) {
$controller = join(DS, array_map('ucfirst', explode('_', $def['controller_name'])));
$action = $def['action'];
$template = sprintf('%s/%s.%s', $controller, substr($this->actionChain->actionNameStrategy($action), 0, -6), $this->renderer->getSuffix());
}
// rendering by renderer.
$def['controller']->beforeRenderer();
$result = $this->renderer->render($template);
$this->response->setBody($result);
if ($this->response->isHttp()) {
$this->response->setHeader('content-type', sprintf('text/html; charset=%s', $this->application->config('encoding.output')));
}
} | php | private function _renderTemplate($template = null)
{
// when no template, auto generate template path.
// View/Content/[controller]/[action].html.twig
$def = $this->actionChain->getCurrentAction();
if (! $template) {
$controller = join(DS, array_map('ucfirst', explode('_', $def['controller_name'])));
$action = $def['action'];
$template = sprintf('%s/%s.%s', $controller, substr($this->actionChain->actionNameStrategy($action), 0, -6), $this->renderer->getSuffix());
}
// rendering by renderer.
$def['controller']->beforeRenderer();
$result = $this->renderer->render($template);
$this->response->setBody($result);
if ($this->response->isHttp()) {
$this->response->setHeader('content-type', sprintf('text/html; charset=%s', $this->application->config('encoding.output')));
}
} | [
"private",
"function",
"_renderTemplate",
"(",
"$",
"template",
"=",
"null",
")",
"{",
"// when no template, auto generate template path.",
"// View/Content/[controller]/[action].html.twig",
"$",
"def",
"=",
"$",
"this",
"->",
"actionChain",
"->",
"getCurrentAction",
"(",
")",
";",
"if",
"(",
"!",
"$",
"template",
")",
"{",
"$",
"controller",
"=",
"join",
"(",
"DS",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"'_'",
",",
"$",
"def",
"[",
"'controller_name'",
"]",
")",
")",
")",
";",
"$",
"action",
"=",
"$",
"def",
"[",
"'action'",
"]",
";",
"$",
"template",
"=",
"sprintf",
"(",
"'%s/%s.%s'",
",",
"$",
"controller",
",",
"substr",
"(",
"$",
"this",
"->",
"actionChain",
"->",
"actionNameStrategy",
"(",
"$",
"action",
")",
",",
"0",
",",
"-",
"6",
")",
",",
"$",
"this",
"->",
"renderer",
"->",
"getSuffix",
"(",
")",
")",
";",
"}",
"// rendering by renderer.",
"$",
"def",
"[",
"'controller'",
"]",
"->",
"beforeRenderer",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"renderer",
"->",
"render",
"(",
"$",
"template",
")",
";",
"$",
"this",
"->",
"response",
"->",
"setBody",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"this",
"->",
"response",
"->",
"isHttp",
"(",
")",
")",
"{",
"$",
"this",
"->",
"response",
"->",
"setHeader",
"(",
"'content-type'",
",",
"sprintf",
"(",
"'text/html; charset=%s'",
",",
"$",
"this",
"->",
"application",
"->",
"config",
"(",
"'encoding.output'",
")",
")",
")",
";",
"}",
"}"
] | rendering template.
@param string $template | [
"rendering",
"template",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Filter/ViewFilter.php#L130-L148 |
6,188 | samurai-fw/samurai | src/Samurai/Filter/ViewFilter.php | ViewFilter._getResult | private function _getResult()
{
$def = $this->actionChain->getCurrentAction();
$result = $def['result'];
if (! $result) {
return null;
} elseif (is_string($result)) {
return $result;
} elseif (is_array($result)) {
return array_shift($result);
} else {
throw new Exception('invalid action result.');
}
} | php | private function _getResult()
{
$def = $this->actionChain->getCurrentAction();
$result = $def['result'];
if (! $result) {
return null;
} elseif (is_string($result)) {
return $result;
} elseif (is_array($result)) {
return array_shift($result);
} else {
throw new Exception('invalid action result.');
}
} | [
"private",
"function",
"_getResult",
"(",
")",
"{",
"$",
"def",
"=",
"$",
"this",
"->",
"actionChain",
"->",
"getCurrentAction",
"(",
")",
";",
"$",
"result",
"=",
"$",
"def",
"[",
"'result'",
"]",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"null",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"result",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"result",
")",
")",
"{",
"return",
"array_shift",
"(",
"$",
"result",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'invalid action result.'",
")",
";",
"}",
"}"
] | Get action result.
@return string
@throw Samurai\Samurai\Exception\Exception | [
"Get",
"action",
"result",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Filter/ViewFilter.php#L194-L207 |
6,189 | samurai-fw/samurai | src/Samurai/Filter/ViewFilter.php | ViewFilter._getResultData | private function _getResultData()
{
$def = $this->actionChain->getCurrentAction();
$result = $def['result'];
if (is_string($result)) {
return $this->getAttribute($result);
} elseif (is_array($result)) {
return array_pop($result);
} else {
return null;
}
} | php | private function _getResultData()
{
$def = $this->actionChain->getCurrentAction();
$result = $def['result'];
if (is_string($result)) {
return $this->getAttribute($result);
} elseif (is_array($result)) {
return array_pop($result);
} else {
return null;
}
} | [
"private",
"function",
"_getResultData",
"(",
")",
"{",
"$",
"def",
"=",
"$",
"this",
"->",
"actionChain",
"->",
"getCurrentAction",
"(",
")",
";",
"$",
"result",
"=",
"$",
"def",
"[",
"'result'",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"result",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getAttribute",
"(",
"$",
"result",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"result",
")",
")",
"{",
"return",
"array_pop",
"(",
"$",
"result",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Get action result data.
@access private
@return mixed | [
"Get",
"action",
"result",
"data",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Filter/ViewFilter.php#L215-L226 |
6,190 | BuildrPHP/Utils | src/Factories/StringFactory.php | StringFactory.create | public static function create($string) {
if(is_array($string)) {
throw new InvalidArgumentException('Arrays cannot be casted to string!');
}
if(is_object($string) &&
!(($string instanceof StringConvertibleInterface) || (method_exists($string, '__toString')))) {
throw new InvalidArgumentException('The given value is an object but cant converted to string!');
}
$value = (string) $string;
return new StringObject($value);
} | php | public static function create($string) {
if(is_array($string)) {
throw new InvalidArgumentException('Arrays cannot be casted to string!');
}
if(is_object($string) &&
!(($string instanceof StringConvertibleInterface) || (method_exists($string, '__toString')))) {
throw new InvalidArgumentException('The given value is an object but cant converted to string!');
}
$value = (string) $string;
return new StringObject($value);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Arrays cannot be casted to string!'",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"string",
")",
"&&",
"!",
"(",
"(",
"$",
"string",
"instanceof",
"StringConvertibleInterface",
")",
"||",
"(",
"method_exists",
"(",
"$",
"string",
",",
"'__toString'",
")",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The given value is an object but cant converted to string!'",
")",
";",
"}",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"string",
";",
"return",
"new",
"StringObject",
"(",
"$",
"value",
")",
";",
"}"
] | Creates a new stringObject class from the given value.
If the given value is an object and is string convertible the object
will be converted to string, before consumed.
@param string $string
@return \BuildR\Utils\StringObject
@throws \BuildR\Foundation\Exception\InvalidArgumentException | [
"Creates",
"a",
"new",
"stringObject",
"class",
"from",
"the",
"given",
"value",
".",
"If",
"the",
"given",
"value",
"is",
"an",
"object",
"and",
"is",
"string",
"convertible",
"the",
"object",
"will",
"be",
"converted",
"to",
"string",
"before",
"consumed",
"."
] | e3b1b9e58f3ebc644e1b9f3838c69936812fc53c | https://github.com/BuildrPHP/Utils/blob/e3b1b9e58f3ebc644e1b9f3838c69936812fc53c/src/Factories/StringFactory.php#L33-L45 |
6,191 | praxisnetau/silverware-google | src/Buttons/GoogleSharingButton.php | GoogleSharingButton.getButtonAnnotationOptions | public function getButtonAnnotationOptions()
{
return [
self::ANNOTATION_NONE => _t(__CLASS__ . '.NONE', 'None'),
self::ANNOTATION_BUBBLE => _t(__CLASS__ . '.BUBBLE', 'Bubble'),
self::ANNOTATION_INLINE => _t(__CLASS__ . '.INLINE', 'Inline'),
self::ANNOTATION_VERTICAL => _t(__CLASS__ . '.VERTICALBUBBLE', 'Vertical Bubble')
];
} | php | public function getButtonAnnotationOptions()
{
return [
self::ANNOTATION_NONE => _t(__CLASS__ . '.NONE', 'None'),
self::ANNOTATION_BUBBLE => _t(__CLASS__ . '.BUBBLE', 'Bubble'),
self::ANNOTATION_INLINE => _t(__CLASS__ . '.INLINE', 'Inline'),
self::ANNOTATION_VERTICAL => _t(__CLASS__ . '.VERTICALBUBBLE', 'Vertical Bubble')
];
} | [
"public",
"function",
"getButtonAnnotationOptions",
"(",
")",
"{",
"return",
"[",
"self",
"::",
"ANNOTATION_NONE",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.NONE'",
",",
"'None'",
")",
",",
"self",
"::",
"ANNOTATION_BUBBLE",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.BUBBLE'",
",",
"'Bubble'",
")",
",",
"self",
"::",
"ANNOTATION_INLINE",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.INLINE'",
",",
"'Inline'",
")",
",",
"self",
"::",
"ANNOTATION_VERTICAL",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.VERTICALBUBBLE'",
",",
"'Vertical Bubble'",
")",
"]",
";",
"}"
] | Answers an array of options for the button annotation field.
@return array | [
"Answers",
"an",
"array",
"of",
"options",
"for",
"the",
"button",
"annotation",
"field",
"."
] | 573632d33fe99c9d943fec8733fa5bbce57586f5 | https://github.com/praxisnetau/silverware-google/blob/573632d33fe99c9d943fec8733fa5bbce57586f5/src/Buttons/GoogleSharingButton.php#L266-L274 |
6,192 | ekyna/UserBundle | Model/Genders.php | Genders.getChoices | public static function getChoices($long = false)
{
$offset = $long ? 1 : 0;
$choices = [];
foreach (static::getConfig() as $constant => $config) {
$choices[$constant] = $config[$offset];
}
return $choices;
} | php | public static function getChoices($long = false)
{
$offset = $long ? 1 : 0;
$choices = [];
foreach (static::getConfig() as $constant => $config) {
$choices[$constant] = $config[$offset];
}
return $choices;
} | [
"public",
"static",
"function",
"getChoices",
"(",
"$",
"long",
"=",
"false",
")",
"{",
"$",
"offset",
"=",
"$",
"long",
"?",
"1",
":",
"0",
";",
"$",
"choices",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"getConfig",
"(",
")",
"as",
"$",
"constant",
"=>",
"$",
"config",
")",
"{",
"$",
"choices",
"[",
"$",
"constant",
"]",
"=",
"$",
"config",
"[",
"$",
"offset",
"]",
";",
"}",
"return",
"$",
"choices",
";",
"}"
] | Returns the constant choices.
@param bool $long
@return array | [
"Returns",
"the",
"constant",
"choices",
"."
] | e38d56aee978148a312a923b9e70bdaad1a381bf | https://github.com/ekyna/UserBundle/blob/e38d56aee978148a312a923b9e70bdaad1a381bf/Model/Genders.php#L39-L47 |
6,193 | ekyna/UserBundle | Model/Genders.php | Genders.getLabel | public static function getLabel($constant, $long = false)
{
static::isValid($constant, true);
return static::getConfig()[$constant][$long ? 1 : 0];
} | php | public static function getLabel($constant, $long = false)
{
static::isValid($constant, true);
return static::getConfig()[$constant][$long ? 1 : 0];
} | [
"public",
"static",
"function",
"getLabel",
"(",
"$",
"constant",
",",
"$",
"long",
"=",
"false",
")",
"{",
"static",
"::",
"isValid",
"(",
"$",
"constant",
",",
"true",
")",
";",
"return",
"static",
"::",
"getConfig",
"(",
")",
"[",
"$",
"constant",
"]",
"[",
"$",
"long",
"?",
"1",
":",
"0",
"]",
";",
"}"
] | Returns the label for the given constant.
@param mixed $constant
@param bool $long
@return string | [
"Returns",
"the",
"label",
"for",
"the",
"given",
"constant",
"."
] | e38d56aee978148a312a923b9e70bdaad1a381bf | https://github.com/ekyna/UserBundle/blob/e38d56aee978148a312a923b9e70bdaad1a381bf/Model/Genders.php#L56-L61 |
6,194 | newscoop/newscoop-api-php-sdk | src/Newscoop/API/Client.php | Client.makeRequest | public function makeRequest($path, $params)
{
$this->dispatcher->dispatch('api.createUri',
new GenericEvent($this, array(
'path' => $path,
'params' => $params
))
);
$this->response = $this->browser->get($this->getUri());
$parsedResponse = json_decode($this->response->getContent(), true);
if (array_key_exists('errors', $parsedResponse)) {
throw new NewscoopApiException($parsedResponse);
}
return $this;
} | php | public function makeRequest($path, $params)
{
$this->dispatcher->dispatch('api.createUri',
new GenericEvent($this, array(
'path' => $path,
'params' => $params
))
);
$this->response = $this->browser->get($this->getUri());
$parsedResponse = json_decode($this->response->getContent(), true);
if (array_key_exists('errors', $parsedResponse)) {
throw new NewscoopApiException($parsedResponse);
}
return $this;
} | [
"public",
"function",
"makeRequest",
"(",
"$",
"path",
",",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"'api.createUri'",
",",
"new",
"GenericEvent",
"(",
"$",
"this",
",",
"array",
"(",
"'path'",
"=>",
"$",
"path",
",",
"'params'",
"=>",
"$",
"params",
")",
")",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"this",
"->",
"browser",
"->",
"get",
"(",
"$",
"this",
"->",
"getUri",
"(",
")",
")",
";",
"$",
"parsedResponse",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"response",
"->",
"getContent",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'errors'",
",",
"$",
"parsedResponse",
")",
")",
"{",
"throw",
"new",
"NewscoopApiException",
"(",
"$",
"parsedResponse",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Make request to resource
@return object Client | [
"Make",
"request",
"to",
"resource"
] | 841c3d2bdcef32cf26b87bd5fdade2ec9243111a | https://github.com/newscoop/newscoop-api-php-sdk/blob/841c3d2bdcef32cf26b87bd5fdade2ec9243111a/src/Newscoop/API/Client.php#L143-L160 |
6,195 | Flowpack/Flowpack.SingleSignOn.Client | Classes/Flowpack/SingleSignOn/Client/Service/SimpleGlobalAccountMapper.php | SimpleGlobalAccountMapper.mapParty | protected function mapParty(array $source) {
if (!isset($source['__type'])) {
throw new Exception('Cannot map party without explicit type (server should return "__type" in party account data):' . json_encode($source), 1354111717);
}
$partyType = $source['__type'];
unset($source['__type']);
if (isset($this->typeMapping[$partyType])) {
$partyType = $this->typeMapping[$partyType];
}
$configuration = new TrustedPropertyMappingConfiguration();
// TODO Deal with mapping errors from property mapper
return $this->propertyMapper->convert($source, $partyType, $configuration);
} | php | protected function mapParty(array $source) {
if (!isset($source['__type'])) {
throw new Exception('Cannot map party without explicit type (server should return "__type" in party account data):' . json_encode($source), 1354111717);
}
$partyType = $source['__type'];
unset($source['__type']);
if (isset($this->typeMapping[$partyType])) {
$partyType = $this->typeMapping[$partyType];
}
$configuration = new TrustedPropertyMappingConfiguration();
// TODO Deal with mapping errors from property mapper
return $this->propertyMapper->convert($source, $partyType, $configuration);
} | [
"protected",
"function",
"mapParty",
"(",
"array",
"$",
"source",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"source",
"[",
"'__type'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Cannot map party without explicit type (server should return \"__type\" in party account data):'",
".",
"json_encode",
"(",
"$",
"source",
")",
",",
"1354111717",
")",
";",
"}",
"$",
"partyType",
"=",
"$",
"source",
"[",
"'__type'",
"]",
";",
"unset",
"(",
"$",
"source",
"[",
"'__type'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"typeMapping",
"[",
"$",
"partyType",
"]",
")",
")",
"{",
"$",
"partyType",
"=",
"$",
"this",
"->",
"typeMapping",
"[",
"$",
"partyType",
"]",
";",
"}",
"$",
"configuration",
"=",
"new",
"TrustedPropertyMappingConfiguration",
"(",
")",
";",
"// TODO Deal with mapping errors from property mapper",
"return",
"$",
"this",
"->",
"propertyMapper",
"->",
"convert",
"(",
"$",
"source",
",",
"$",
"partyType",
",",
"$",
"configuration",
")",
";",
"}"
] | Map the party from the given source data
@param array $source
@return \TYPO3\Party\Domain\Model\AbstractParty | [
"Map",
"the",
"party",
"from",
"the",
"given",
"source",
"data"
] | 0512b66bba7cf31fd03c9608a1e4c67a7c1c0e00 | https://github.com/Flowpack/Flowpack.SingleSignOn.Client/blob/0512b66bba7cf31fd03c9608a1e4c67a7c1c0e00/Classes/Flowpack/SingleSignOn/Client/Service/SimpleGlobalAccountMapper.php#L71-L85 |
6,196 | jakecleary/ultrapress-library | src/Ultra/Mutator/Mutator.php | Mutator.with | public function with(array $data)
{
foreach($data as $method)
{
if(method_exists($this, $method))
{
$this->$method();
}
elseif(taxonomy_exists($method))
{
$this->taxonomy($method);
}
elseif(function_exists('get_field'))
{
$this->field($method);
}
}
return $this;
} | php | public function with(array $data)
{
foreach($data as $method)
{
if(method_exists($this, $method))
{
$this->$method();
}
elseif(taxonomy_exists($method))
{
$this->taxonomy($method);
}
elseif(function_exists('get_field'))
{
$this->field($method);
}
}
return $this;
} | [
"public",
"function",
"with",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"$",
"this",
"->",
"$",
"method",
"(",
")",
";",
"}",
"elseif",
"(",
"taxonomy_exists",
"(",
"$",
"method",
")",
")",
"{",
"$",
"this",
"->",
"taxonomy",
"(",
"$",
"method",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'get_field'",
")",
")",
"{",
"$",
"this",
"->",
"field",
"(",
"$",
"method",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set which data to include in the data object, additionally
search for an available ACF field if a method can't be
found directly.
@param array $data An array of meta-data slugs
@return Ultra\Mutator\Mutator The mutated data object | [
"Set",
"which",
"data",
"to",
"include",
"in",
"the",
"data",
"object",
"additionally",
"search",
"for",
"an",
"available",
"ACF",
"field",
"if",
"a",
"method",
"can",
"t",
"be",
"found",
"directly",
"."
] | 84ca5d1dae8eb16de8c886787575ea41f9332ae2 | https://github.com/jakecleary/ultrapress-library/blob/84ca5d1dae8eb16de8c886787575ea41f9332ae2/src/Ultra/Mutator/Mutator.php#L38-L57 |
6,197 | jakecleary/ultrapress-library | src/Ultra/Mutator/Mutator.php | Mutator.trim | public function trim(array $namespaces)
{
foreach($this->data as $post)
{
$this->removeNamespace($post, $namespaces);
}
return $this;
} | php | public function trim(array $namespaces)
{
foreach($this->data as $post)
{
$this->removeNamespace($post, $namespaces);
}
return $this;
} | [
"public",
"function",
"trim",
"(",
"array",
"$",
"namespaces",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"post",
")",
"{",
"$",
"this",
"->",
"removeNamespace",
"(",
"$",
"post",
",",
"$",
"namespaces",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Trim surplus namespaces from array keys.
@param array $namespaces The namespaces to remove
@return Ultra\Mutator\Mutator | [
"Trim",
"surplus",
"namespaces",
"from",
"array",
"keys",
"."
] | 84ca5d1dae8eb16de8c886787575ea41f9332ae2 | https://github.com/jakecleary/ultrapress-library/blob/84ca5d1dae8eb16de8c886787575ea41f9332ae2/src/Ultra/Mutator/Mutator.php#L65-L73 |
6,198 | jakecleary/ultrapress-library | src/Ultra/Mutator/Mutator.php | Mutator.author | public function author()
{
foreach($this->data as $post)
{
$id = $post->author;
$author = get_userdata($id);
$avatar = get_field('author_avatar', 'user_' . $id);
$banner = get_field('author_banner', 'user_' . $id);
$author = (object) [
'name' => $author->display_name,
'permalink' => get_author_posts_url($id),
'images' => (object) [
'avatar' => $avatar ? $avatar['url'] : false,
'banner' => $banner ? $banner['url'] : false
]
];
$post->author = $author;
}
return $this;
} | php | public function author()
{
foreach($this->data as $post)
{
$id = $post->author;
$author = get_userdata($id);
$avatar = get_field('author_avatar', 'user_' . $id);
$banner = get_field('author_banner', 'user_' . $id);
$author = (object) [
'name' => $author->display_name,
'permalink' => get_author_posts_url($id),
'images' => (object) [
'avatar' => $avatar ? $avatar['url'] : false,
'banner' => $banner ? $banner['url'] : false
]
];
$post->author = $author;
}
return $this;
} | [
"public",
"function",
"author",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"post",
")",
"{",
"$",
"id",
"=",
"$",
"post",
"->",
"author",
";",
"$",
"author",
"=",
"get_userdata",
"(",
"$",
"id",
")",
";",
"$",
"avatar",
"=",
"get_field",
"(",
"'author_avatar'",
",",
"'user_'",
".",
"$",
"id",
")",
";",
"$",
"banner",
"=",
"get_field",
"(",
"'author_banner'",
",",
"'user_'",
".",
"$",
"id",
")",
";",
"$",
"author",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"author",
"->",
"display_name",
",",
"'permalink'",
"=>",
"get_author_posts_url",
"(",
"$",
"id",
")",
",",
"'images'",
"=>",
"(",
"object",
")",
"[",
"'avatar'",
"=>",
"$",
"avatar",
"?",
"$",
"avatar",
"[",
"'url'",
"]",
":",
"false",
",",
"'banner'",
"=>",
"$",
"banner",
"?",
"$",
"banner",
"[",
"'url'",
"]",
":",
"false",
"]",
"]",
";",
"$",
"post",
"->",
"author",
"=",
"$",
"author",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Include the author display name in the post object.
@return Ultra\Mutator\Mutator The mutated data object | [
"Include",
"the",
"author",
"display",
"name",
"in",
"the",
"post",
"object",
"."
] | 84ca5d1dae8eb16de8c886787575ea41f9332ae2 | https://github.com/jakecleary/ultrapress-library/blob/84ca5d1dae8eb16de8c886787575ea41f9332ae2/src/Ultra/Mutator/Mutator.php#L80-L103 |
6,199 | jakecleary/ultrapress-library | src/Ultra/Mutator/Mutator.php | Mutator.taxonomy | public function taxonomy($name)
{
foreach($this->data as $post)
{
$terms = get_the_terms($post->ID, $name);
if(!empty($terms))
{
$term = array_values($terms)[0];
$post->$name = (object) [
'name' => $term->name,
'permalink' => get_term_link($term->slug, $name)
];
}
}
return $this;
} | php | public function taxonomy($name)
{
foreach($this->data as $post)
{
$terms = get_the_terms($post->ID, $name);
if(!empty($terms))
{
$term = array_values($terms)[0];
$post->$name = (object) [
'name' => $term->name,
'permalink' => get_term_link($term->slug, $name)
];
}
}
return $this;
} | [
"public",
"function",
"taxonomy",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"post",
")",
"{",
"$",
"terms",
"=",
"get_the_terms",
"(",
"$",
"post",
"->",
"ID",
",",
"$",
"name",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"terms",
")",
")",
"{",
"$",
"term",
"=",
"array_values",
"(",
"$",
"terms",
")",
"[",
"0",
"]",
";",
"$",
"post",
"->",
"$",
"name",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"term",
"->",
"name",
",",
"'permalink'",
"=>",
"get_term_link",
"(",
"$",
"term",
"->",
"slug",
",",
"$",
"name",
")",
"]",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Include the first taxonomy term name in the post object.
@param string $name The taxonomy name
@return Ultra\Mutator\Mutator The mutated data object | [
"Include",
"the",
"first",
"taxonomy",
"term",
"name",
"in",
"the",
"post",
"object",
"."
] | 84ca5d1dae8eb16de8c886787575ea41f9332ae2 | https://github.com/jakecleary/ultrapress-library/blob/84ca5d1dae8eb16de8c886787575ea41f9332ae2/src/Ultra/Mutator/Mutator.php#L111-L129 |
Subsets and Splits