repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
m4grio/bangkok-insurance-php | src/Client/ParamsMapperTrait.php | ParamsMapperTrait.mergeParams | public function mergeParams($method, Array $params = [])
{
$result = parent::mergeParams($method, $params);
foreach ($this->map as $oldKey => $newKey)
{
if (array_key_exists($oldKey, $result[$method])) {
$result[$method][$newKey] = $result[$method][$oldKey];
$result[$method][$oldKey] = null;
unset($result[$method][$oldKey]);
}
}
return $result;
} | php | public function mergeParams($method, Array $params = [])
{
$result = parent::mergeParams($method, $params);
foreach ($this->map as $oldKey => $newKey)
{
if (array_key_exists($oldKey, $result[$method])) {
$result[$method][$newKey] = $result[$method][$oldKey];
$result[$method][$oldKey] = null;
unset($result[$method][$oldKey]);
}
}
return $result;
} | [
"public",
"function",
"mergeParams",
"(",
"$",
"method",
",",
"Array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"mergeParams",
"(",
"$",
"method",
",",
"$",
"params",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"map",
"as",
"$",
"oldKey",
"=>",
"$",
"newKey",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"oldKey",
",",
"$",
"result",
"[",
"$",
"method",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"method",
"]",
"[",
"$",
"newKey",
"]",
"=",
"$",
"result",
"[",
"$",
"method",
"]",
"[",
"$",
"oldKey",
"]",
";",
"$",
"result",
"[",
"$",
"method",
"]",
"[",
"$",
"oldKey",
"]",
"=",
"null",
";",
"unset",
"(",
"$",
"result",
"[",
"$",
"method",
"]",
"[",
"$",
"oldKey",
"]",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Merge and remap params
@param $method
@param array $params
@return mixed | [
"Merge",
"and",
"remap",
"params"
] | train | https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/Client/ParamsMapperTrait.php#L27-L41 |
MASNathan/Parser | src/Type/Ini.php | Ini.encode | public static function encode($data)
{
$data = (array) $data;
$resultString = self::loopEncode($data);
return trim($resultString, PHP_EOL);
} | php | public static function encode($data)
{
$data = (array) $data;
$resultString = self::loopEncode($data);
return trim($resultString, PHP_EOL);
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"data",
";",
"$",
"resultString",
"=",
"self",
"::",
"loopEncode",
"(",
"$",
"data",
")",
";",
"return",
"trim",
"(",
"$",
"resultString",
",",
"PHP_EOL",
")",
";",
"}"
] | Encodes an array to ini strutcture
@param array $data Data to encode
@return string | [
"Encodes",
"an",
"array",
"to",
"ini",
"strutcture"
] | train | https://github.com/MASNathan/Parser/blob/0f55402b99b1e071bdcd6277b9268f783ca25e34/src/Type/Ini.php#L12-L19 |
MASNathan/Parser | src/Type/Ini.php | Ini.loopEncode | public static function loopEncode($data, array $parent = array())
{
$resultString = '';
foreach ($data as $key => $value) {
if (is_array($value)) {
//subsection case
//merge all the sections into one array...
$sec = array_merge((array) $parent, (array) $key);
//add section information to the output
$resultString .= PHP_EOL . '[' . join('.', $sec) . ']' . PHP_EOL;
//recursively traverse deeper
$resultString .= self::loopEncode($value, $sec);
} else {
$resultString .= "$key = $value" . PHP_EOL;
}
}
return $resultString;
} | php | public static function loopEncode($data, array $parent = array())
{
$resultString = '';
foreach ($data as $key => $value) {
if (is_array($value)) {
//subsection case
//merge all the sections into one array...
$sec = array_merge((array) $parent, (array) $key);
//add section information to the output
$resultString .= PHP_EOL . '[' . join('.', $sec) . ']' . PHP_EOL;
//recursively traverse deeper
$resultString .= self::loopEncode($value, $sec);
} else {
$resultString .= "$key = $value" . PHP_EOL;
}
}
return $resultString;
} | [
"public",
"static",
"function",
"loopEncode",
"(",
"$",
"data",
",",
"array",
"$",
"parent",
"=",
"array",
"(",
")",
")",
"{",
"$",
"resultString",
"=",
"''",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"//subsection case",
"//merge all the sections into one array...",
"$",
"sec",
"=",
"array_merge",
"(",
"(",
"array",
")",
"$",
"parent",
",",
"(",
"array",
")",
"$",
"key",
")",
";",
"//add section information to the output",
"$",
"resultString",
".=",
"PHP_EOL",
".",
"'['",
".",
"join",
"(",
"'.'",
",",
"$",
"sec",
")",
".",
"']'",
".",
"PHP_EOL",
";",
"//recursively traverse deeper",
"$",
"resultString",
".=",
"self",
"::",
"loopEncode",
"(",
"$",
"value",
",",
"$",
"sec",
")",
";",
"}",
"else",
"{",
"$",
"resultString",
".=",
"\"$key = $value\"",
".",
"PHP_EOL",
";",
"}",
"}",
"return",
"$",
"resultString",
";",
"}"
] | Method to look the data and encode it to ini format
@param array $data Data to encode
@param array $parent Parent array, in case of recursive arrays
@return string | [
"Method",
"to",
"look",
"the",
"data",
"and",
"encode",
"it",
"to",
"ini",
"format"
] | train | https://github.com/MASNathan/Parser/blob/0f55402b99b1e071bdcd6277b9268f783ca25e34/src/Type/Ini.php#L27-L45 |
NuclearCMS/Hierarchy | src/Tags/Tag.php | Tag.scopeSortable | public function scopeSortable($query, $key = null, $direction = null)
{
list($key, $direction) = $this->validateSortableParameters($key, $direction);
if ($this->isTranslationAttribute($key))
{
return $this->orderByTranslationAttribute($query, $key, $direction);
}
return $query->orderBy($key, $direction);
} | php | public function scopeSortable($query, $key = null, $direction = null)
{
list($key, $direction) = $this->validateSortableParameters($key, $direction);
if ($this->isTranslationAttribute($key))
{
return $this->orderByTranslationAttribute($query, $key, $direction);
}
return $query->orderBy($key, $direction);
} | [
"public",
"function",
"scopeSortable",
"(",
"$",
"query",
",",
"$",
"key",
"=",
"null",
",",
"$",
"direction",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"direction",
")",
"=",
"$",
"this",
"->",
"validateSortableParameters",
"(",
"$",
"key",
",",
"$",
"direction",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isTranslationAttribute",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"orderByTranslationAttribute",
"(",
"$",
"query",
",",
"$",
"key",
",",
"$",
"direction",
")",
";",
"}",
"return",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"key",
",",
"$",
"direction",
")",
";",
"}"
] | Sortable by scope
@param $query
@param string|null $key
@param string|null $direction
@return Builder | [
"Sortable",
"by",
"scope"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Tags/Tag.php#L103-L113 |
NuclearCMS/Hierarchy | src/Tags/Tag.php | Tag.firstByTitleOrCreate | public static function firstByTitleOrCreate($title, $locale = null)
{
$tag = Tag::whereTranslation('title', $title, $locale)->first();
if (is_null($tag))
{
$attributes = compact('title');
if ($locale)
{
$attributes = [$locale => $attributes];
}
$tag = Tag::create($attributes);
}
return $tag;
} | php | public static function firstByTitleOrCreate($title, $locale = null)
{
$tag = Tag::whereTranslation('title', $title, $locale)->first();
if (is_null($tag))
{
$attributes = compact('title');
if ($locale)
{
$attributes = [$locale => $attributes];
}
$tag = Tag::create($attributes);
}
return $tag;
} | [
"public",
"static",
"function",
"firstByTitleOrCreate",
"(",
"$",
"title",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"tag",
"=",
"Tag",
"::",
"whereTranslation",
"(",
"'title'",
",",
"$",
"title",
",",
"$",
"locale",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"tag",
")",
")",
"{",
"$",
"attributes",
"=",
"compact",
"(",
"'title'",
")",
";",
"if",
"(",
"$",
"locale",
")",
"{",
"$",
"attributes",
"=",
"[",
"$",
"locale",
"=>",
"$",
"attributes",
"]",
";",
"}",
"$",
"tag",
"=",
"Tag",
"::",
"create",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"tag",
";",
"}"
] | Finds a tag by title or creates it
@param string $title
@param string $locale
@return Tag | [
"Finds",
"a",
"tag",
"by",
"title",
"or",
"creates",
"it"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Tags/Tag.php#L138-L155 |
NuclearCMS/Hierarchy | src/Tags/Tag.php | Tag.getLocaleForName | public function getLocaleForName($name)
{
foreach ($this->translations as $translation)
{
if ($translation->tag_name === $name)
{
return $translation->locale;
}
}
return null;
} | php | public function getLocaleForName($name)
{
foreach ($this->translations as $translation)
{
if ($translation->tag_name === $name)
{
return $translation->locale;
}
}
return null;
} | [
"public",
"function",
"getLocaleForName",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translation",
")",
"{",
"if",
"(",
"$",
"translation",
"->",
"tag_name",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"translation",
"->",
"locale",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns locale for name
@param string $name
@return string | [
"Returns",
"locale",
"for",
"name"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Tags/Tag.php#L163-L174 |
codezero-be/laravel-localizer | src/LocalizerServiceProvider.php | LocalizerServiceProvider.registerLocalizer | protected function registerLocalizer()
{
$this->app->bind(Localizer::class, function ($app) {
$locales = $app['config']->get("{$this->name}.supported-locales");
$detectors = $app['config']->get("{$this->name}.detectors");
$stores = $app['config']->get("{$this->name}.stores");
return new Localizer($locales, $detectors, $stores);
});
} | php | protected function registerLocalizer()
{
$this->app->bind(Localizer::class, function ($app) {
$locales = $app['config']->get("{$this->name}.supported-locales");
$detectors = $app['config']->get("{$this->name}.detectors");
$stores = $app['config']->get("{$this->name}.stores");
return new Localizer($locales, $detectors, $stores);
});
} | [
"protected",
"function",
"registerLocalizer",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"Localizer",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"locales",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"\"{$this->name}.supported-locales\"",
")",
";",
"$",
"detectors",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"\"{$this->name}.detectors\"",
")",
";",
"$",
"stores",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"\"{$this->name}.stores\"",
")",
";",
"return",
"new",
"Localizer",
"(",
"$",
"locales",
",",
"$",
"detectors",
",",
"$",
"stores",
")",
";",
"}",
")",
";",
"}"
] | Register Localizer.
@return void | [
"Register",
"Localizer",
"."
] | train | https://github.com/codezero-be/laravel-localizer/blob/812692796a73bd38fc205404d8ef90df5bfa0d83/src/LocalizerServiceProvider.php#L65-L74 |
InactiveProjects/limoncello-illuminate | app/Http/Requests/RolesRequest.php | RolesRequest.validateOnPost | protected function validateOnPost(ErrorCollection $errors)
{
$this->validateData([
Schema::KEYWORD_ID => $this->getId(),
], [
Schema::KEYWORD_ID => 'required|unique:' . Model::TABLE_NAME . ',' . Model::FIELD_ID,
], $errors);
$this->validateAttributes([
Schema::ATTR_NAME => 'required|max:' . Model::LENGTH_NAME,
], $errors);
} | php | protected function validateOnPost(ErrorCollection $errors)
{
$this->validateData([
Schema::KEYWORD_ID => $this->getId(),
], [
Schema::KEYWORD_ID => 'required|unique:' . Model::TABLE_NAME . ',' . Model::FIELD_ID,
], $errors);
$this->validateAttributes([
Schema::ATTR_NAME => 'required|max:' . Model::LENGTH_NAME,
], $errors);
} | [
"protected",
"function",
"validateOnPost",
"(",
"ErrorCollection",
"$",
"errors",
")",
"{",
"$",
"this",
"->",
"validateData",
"(",
"[",
"Schema",
"::",
"KEYWORD_ID",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"]",
",",
"[",
"Schema",
"::",
"KEYWORD_ID",
"=>",
"'required|unique:'",
".",
"Model",
"::",
"TABLE_NAME",
".",
"','",
".",
"Model",
"::",
"FIELD_ID",
",",
"]",
",",
"$",
"errors",
")",
";",
"$",
"this",
"->",
"validateAttributes",
"(",
"[",
"Schema",
"::",
"ATTR_NAME",
"=>",
"'required|max:'",
".",
"Model",
"::",
"LENGTH_NAME",
",",
"]",
",",
"$",
"errors",
")",
";",
"}"
] | Validate input for 'store' action.
@param ErrorCollection $errors
@return void | [
"Validate",
"input",
"for",
"store",
"action",
"."
] | train | https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Http/Requests/RolesRequest.php#L22-L33 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.get | public function get(string $name, ?array $parameters = null)
{
try {
return $this->resolve($name, $parameters);
} catch (Exception\ServiceNotFound $e) {
return $this->wrapService($name, $parameters);
}
} | php | public function get(string $name, ?array $parameters = null)
{
try {
return $this->resolve($name, $parameters);
} catch (Exception\ServiceNotFound $e) {
return $this->wrapService($name, $parameters);
}
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"name",
",",
"?",
"array",
"$",
"parameters",
"=",
"null",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"resolve",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"ServiceNotFound",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"wrapService",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
";",
"}",
"}"
] | Get service. | [
"Get",
"service",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L97-L104 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.resolve | public function resolve(string $name, ?array $parameters = null)
{
if (isset($this->service[$name])) {
return $this->service[$name];
}
if ($this->config->has($name)) {
return $this->wrapService($name, $parameters);
}
if (null !== $this->parent_service) {
$parents = array_merge([$name], class_implements($this->parent_service), class_parents($this->parent_service));
if (in_array($name, $parents, true) && $this->parent_service instanceof $name) {
return $this->parent_service;
}
}
if (null !== $this->parent) {
return $this->parent->resolve($name, $parameters);
}
throw new Exception\ServiceNotFound("service $name was not found in service tree");
} | php | public function resolve(string $name, ?array $parameters = null)
{
if (isset($this->service[$name])) {
return $this->service[$name];
}
if ($this->config->has($name)) {
return $this->wrapService($name, $parameters);
}
if (null !== $this->parent_service) {
$parents = array_merge([$name], class_implements($this->parent_service), class_parents($this->parent_service));
if (in_array($name, $parents, true) && $this->parent_service instanceof $name) {
return $this->parent_service;
}
}
if (null !== $this->parent) {
return $this->parent->resolve($name, $parameters);
}
throw new Exception\ServiceNotFound("service $name was not found in service tree");
} | [
"public",
"function",
"resolve",
"(",
"string",
"$",
"name",
",",
"?",
"array",
"$",
"parameters",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"service",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"service",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"wrapService",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"parent_service",
")",
"{",
"$",
"parents",
"=",
"array_merge",
"(",
"[",
"$",
"name",
"]",
",",
"class_implements",
"(",
"$",
"this",
"->",
"parent_service",
")",
",",
"class_parents",
"(",
"$",
"this",
"->",
"parent_service",
")",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"parents",
",",
"true",
")",
"&&",
"$",
"this",
"->",
"parent_service",
"instanceof",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"parent_service",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"parent",
")",
"{",
"return",
"$",
"this",
"->",
"parent",
"->",
"resolve",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"ServiceNotFound",
"(",
"\"service $name was not found in service tree\"",
")",
";",
"}"
] | Resolve service. | [
"Resolve",
"service",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L109-L132 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.storeService | protected function storeService(string $name, array $config, $service)
{
if (false === $config['singleton']) {
return $service;
}
$this->service[$name] = $service;
if (isset($this->children[$name])) {
$this->children[$name]->setParentService($service);
}
return $service;
} | php | protected function storeService(string $name, array $config, $service)
{
if (false === $config['singleton']) {
return $service;
}
$this->service[$name] = $service;
if (isset($this->children[$name])) {
$this->children[$name]->setParentService($service);
}
return $service;
} | [
"protected",
"function",
"storeService",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"config",
",",
"$",
"service",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"config",
"[",
"'singleton'",
"]",
")",
"{",
"return",
"$",
"service",
";",
"}",
"$",
"this",
"->",
"service",
"[",
"$",
"name",
"]",
"=",
"$",
"service",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"children",
"[",
"$",
"name",
"]",
"->",
"setParentService",
"(",
"$",
"service",
")",
";",
"}",
"return",
"$",
"service",
";",
"}"
] | Store service. | [
"Store",
"service",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L137-L149 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.wrapService | protected function wrapService(string $name, ?array $parameters = null)
{
$config = $this->config->get($name);
if (true === $config['wrap']) {
$that = $this;
return function () use ($that, $name, $parameters) {
return $that->autoWireClass($name, $parameters);
};
}
return $this->autoWireClass($name, $parameters);
} | php | protected function wrapService(string $name, ?array $parameters = null)
{
$config = $this->config->get($name);
if (true === $config['wrap']) {
$that = $this;
return function () use ($that, $name, $parameters) {
return $that->autoWireClass($name, $parameters);
};
}
return $this->autoWireClass($name, $parameters);
} | [
"protected",
"function",
"wrapService",
"(",
"string",
"$",
"name",
",",
"?",
"array",
"$",
"parameters",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"true",
"===",
"$",
"config",
"[",
"'wrap'",
"]",
")",
"{",
"$",
"that",
"=",
"$",
"this",
";",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"that",
",",
"$",
"name",
",",
"$",
"parameters",
")",
"{",
"return",
"$",
"that",
"->",
"autoWireClass",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
";",
"}",
";",
"}",
"return",
"$",
"this",
"->",
"autoWireClass",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
";",
"}"
] | Wrap resolved service in callable if enabled. | [
"Wrap",
"resolved",
"service",
"in",
"callable",
"if",
"enabled",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L154-L166 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.autoWireClass | protected function autoWireClass(string $name, ?array $parameters = null)
{
$config = $this->config->get($name);
$class = $config['use'];
if (null !== $parameters) {
$config['singleton'] = false;
}
if (preg_match('#^\{([^{}]+)\}$#', $class, $match)) {
return $this->wireReference($name, $match[1], $config);
}
$reflection = new ReflectionClass($class);
if (isset($config['factory'])) {
$factory = $reflection->getMethod($config['factory']);
$args = $this->autoWireMethod($name, $factory, $config, $parameters);
$instance = call_user_func_array([$class, $config['factory']], $args);
return $this->prepareService($name, $instance, $reflection, $config);
}
$constructor = $reflection->getConstructor();
if (null === $constructor) {
return $this->storeService($name, $config, new $class());
}
$args = $this->autoWireMethod($name, $constructor, $config, $parameters);
return $this->createInstance($name, $reflection, $args, $config);
} | php | protected function autoWireClass(string $name, ?array $parameters = null)
{
$config = $this->config->get($name);
$class = $config['use'];
if (null !== $parameters) {
$config['singleton'] = false;
}
if (preg_match('#^\{([^{}]+)\}$#', $class, $match)) {
return $this->wireReference($name, $match[1], $config);
}
$reflection = new ReflectionClass($class);
if (isset($config['factory'])) {
$factory = $reflection->getMethod($config['factory']);
$args = $this->autoWireMethod($name, $factory, $config, $parameters);
$instance = call_user_func_array([$class, $config['factory']], $args);
return $this->prepareService($name, $instance, $reflection, $config);
}
$constructor = $reflection->getConstructor();
if (null === $constructor) {
return $this->storeService($name, $config, new $class());
}
$args = $this->autoWireMethod($name, $constructor, $config, $parameters);
return $this->createInstance($name, $reflection, $args, $config);
} | [
"protected",
"function",
"autoWireClass",
"(",
"string",
"$",
"name",
",",
"?",
"array",
"$",
"parameters",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"name",
")",
";",
"$",
"class",
"=",
"$",
"config",
"[",
"'use'",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"parameters",
")",
"{",
"$",
"config",
"[",
"'singleton'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'#^\\{([^{}]+)\\}$#'",
",",
"$",
"class",
",",
"$",
"match",
")",
")",
"{",
"return",
"$",
"this",
"->",
"wireReference",
"(",
"$",
"name",
",",
"$",
"match",
"[",
"1",
"]",
",",
"$",
"config",
")",
";",
"}",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'factory'",
"]",
")",
")",
"{",
"$",
"factory",
"=",
"$",
"reflection",
"->",
"getMethod",
"(",
"$",
"config",
"[",
"'factory'",
"]",
")",
";",
"$",
"args",
"=",
"$",
"this",
"->",
"autoWireMethod",
"(",
"$",
"name",
",",
"$",
"factory",
",",
"$",
"config",
",",
"$",
"parameters",
")",
";",
"$",
"instance",
"=",
"call_user_func_array",
"(",
"[",
"$",
"class",
",",
"$",
"config",
"[",
"'factory'",
"]",
"]",
",",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"prepareService",
"(",
"$",
"name",
",",
"$",
"instance",
",",
"$",
"reflection",
",",
"$",
"config",
")",
";",
"}",
"$",
"constructor",
"=",
"$",
"reflection",
"->",
"getConstructor",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"constructor",
")",
"{",
"return",
"$",
"this",
"->",
"storeService",
"(",
"$",
"name",
",",
"$",
"config",
",",
"new",
"$",
"class",
"(",
")",
")",
";",
"}",
"$",
"args",
"=",
"$",
"this",
"->",
"autoWireMethod",
"(",
"$",
"name",
",",
"$",
"constructor",
",",
"$",
"config",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"this",
"->",
"createInstance",
"(",
"$",
"name",
",",
"$",
"reflection",
",",
"$",
"args",
",",
"$",
"config",
")",
";",
"}"
] | Auto wire. | [
"Auto",
"wire",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L171-L203 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.wireReference | protected function wireReference(string $name, string $reference, array $config)
{
$service = $this->get($reference);
$reflection = new ReflectionClass(get_class($service));
$config = $this->config->get($name);
$service = $this->prepareService($name, $service, $reflection, $config);
return $service;
} | php | protected function wireReference(string $name, string $reference, array $config)
{
$service = $this->get($reference);
$reflection = new ReflectionClass(get_class($service));
$config = $this->config->get($name);
$service = $this->prepareService($name, $service, $reflection, $config);
return $service;
} | [
"protected",
"function",
"wireReference",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"reference",
",",
"array",
"$",
"config",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"reference",
")",
";",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"service",
")",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"name",
")",
";",
"$",
"service",
"=",
"$",
"this",
"->",
"prepareService",
"(",
"$",
"name",
",",
"$",
"service",
",",
"$",
"reflection",
",",
"$",
"config",
")",
";",
"return",
"$",
"service",
";",
"}"
] | Wire named referenced service. | [
"Wire",
"named",
"referenced",
"service",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L208-L216 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.createInstance | protected function createInstance(string $name, ReflectionClass $class, array $arguments, array $config)
{
if (true === $config['lazy']) {
return $this->getProxyInstance($name, $class, $arguments, $config);
}
return $this->getRealInstance($name, $class, $arguments, $config);
} | php | protected function createInstance(string $name, ReflectionClass $class, array $arguments, array $config)
{
if (true === $config['lazy']) {
return $this->getProxyInstance($name, $class, $arguments, $config);
}
return $this->getRealInstance($name, $class, $arguments, $config);
} | [
"protected",
"function",
"createInstance",
"(",
"string",
"$",
"name",
",",
"ReflectionClass",
"$",
"class",
",",
"array",
"$",
"arguments",
",",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"config",
"[",
"'lazy'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"getProxyInstance",
"(",
"$",
"name",
",",
"$",
"class",
",",
"$",
"arguments",
",",
"$",
"config",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getRealInstance",
"(",
"$",
"name",
",",
"$",
"class",
",",
"$",
"arguments",
",",
"$",
"config",
")",
";",
"}"
] | Get instance (virtual or real instance). | [
"Get",
"instance",
"(",
"virtual",
"or",
"real",
"instance",
")",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L221-L228 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.getProxyInstance | protected function getProxyInstance(string $name, ReflectionClass $class, array $arguments, array $config)
{
$factory = new LazyLoadingValueHolderFactory();
$that = $this;
return $factory->createProxy(
$class->getName(),
function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) use ($that, $name,$class,$arguments,$config) {
$wrappedObject = $that->getRealInstance($name, $class, $arguments, $config);
$initializer = null;
}
);
} | php | protected function getProxyInstance(string $name, ReflectionClass $class, array $arguments, array $config)
{
$factory = new LazyLoadingValueHolderFactory();
$that = $this;
return $factory->createProxy(
$class->getName(),
function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) use ($that, $name,$class,$arguments,$config) {
$wrappedObject = $that->getRealInstance($name, $class, $arguments, $config);
$initializer = null;
}
);
} | [
"protected",
"function",
"getProxyInstance",
"(",
"string",
"$",
"name",
",",
"ReflectionClass",
"$",
"class",
",",
"array",
"$",
"arguments",
",",
"array",
"$",
"config",
")",
"{",
"$",
"factory",
"=",
"new",
"LazyLoadingValueHolderFactory",
"(",
")",
";",
"$",
"that",
"=",
"$",
"this",
";",
"return",
"$",
"factory",
"->",
"createProxy",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
",",
"function",
"(",
"&",
"$",
"wrappedObject",
",",
"$",
"proxy",
",",
"$",
"method",
",",
"$",
"parameters",
",",
"&",
"$",
"initializer",
")",
"use",
"(",
"$",
"that",
",",
"$",
"name",
",",
"$",
"class",
",",
"$",
"arguments",
",",
"$",
"config",
")",
"{",
"$",
"wrappedObject",
"=",
"$",
"that",
"->",
"getRealInstance",
"(",
"$",
"name",
",",
"$",
"class",
",",
"$",
"arguments",
",",
"$",
"config",
")",
";",
"$",
"initializer",
"=",
"null",
";",
"}",
")",
";",
"}"
] | Create proxy instance. | [
"Create",
"proxy",
"instance",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L233-L245 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.getRealInstance | protected function getRealInstance(string $name, ReflectionClass $class, array $arguments, array $config)
{
$instance = $class->newInstanceArgs($arguments);
$instance = $this->prepareService($name, $instance, $class, $config);
return $instance;
} | php | protected function getRealInstance(string $name, ReflectionClass $class, array $arguments, array $config)
{
$instance = $class->newInstanceArgs($arguments);
$instance = $this->prepareService($name, $instance, $class, $config);
return $instance;
} | [
"protected",
"function",
"getRealInstance",
"(",
"string",
"$",
"name",
",",
"ReflectionClass",
"$",
"class",
",",
"array",
"$",
"arguments",
",",
"array",
"$",
"config",
")",
"{",
"$",
"instance",
"=",
"$",
"class",
"->",
"newInstanceArgs",
"(",
"$",
"arguments",
")",
";",
"$",
"instance",
"=",
"$",
"this",
"->",
"prepareService",
"(",
"$",
"name",
",",
"$",
"instance",
",",
"$",
"class",
",",
"$",
"config",
")",
";",
"return",
"$",
"instance",
";",
"}"
] | Create real instance. | [
"Create",
"real",
"instance",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L250-L256 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.prepareService | protected function prepareService(string $name, $service, ReflectionClass $class, array $config)
{
$this->storeService($name, $config, $service);
foreach ($config['calls'] as $call) {
if (!is_array($call)) {
continue;
}
if (!isset($call['method'])) {
throw new Exception\InvalidConfiguration('method is required for setter injection in service '.$name);
}
$arguments = [];
try {
$method = $class->getMethod($call['method']);
} catch (\ReflectionException $e) {
throw new Exception\InvalidConfiguration('method '.$call['method'].' is not callable in class '.$class->getName().' for service '.$name);
}
$arguments = $this->autoWireMethod($name, $method, $call);
$result = call_user_func_array([&$service, $call['method']], $arguments);
if (isset($call['select']) && true === $call['select']) {
$service = $result;
}
}
$this->storeService($name, $config, $service);
return $service;
} | php | protected function prepareService(string $name, $service, ReflectionClass $class, array $config)
{
$this->storeService($name, $config, $service);
foreach ($config['calls'] as $call) {
if (!is_array($call)) {
continue;
}
if (!isset($call['method'])) {
throw new Exception\InvalidConfiguration('method is required for setter injection in service '.$name);
}
$arguments = [];
try {
$method = $class->getMethod($call['method']);
} catch (\ReflectionException $e) {
throw new Exception\InvalidConfiguration('method '.$call['method'].' is not callable in class '.$class->getName().' for service '.$name);
}
$arguments = $this->autoWireMethod($name, $method, $call);
$result = call_user_func_array([&$service, $call['method']], $arguments);
if (isset($call['select']) && true === $call['select']) {
$service = $result;
}
}
$this->storeService($name, $config, $service);
return $service;
} | [
"protected",
"function",
"prepareService",
"(",
"string",
"$",
"name",
",",
"$",
"service",
",",
"ReflectionClass",
"$",
"class",
",",
"array",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"storeService",
"(",
"$",
"name",
",",
"$",
"config",
",",
"$",
"service",
")",
";",
"foreach",
"(",
"$",
"config",
"[",
"'calls'",
"]",
"as",
"$",
"call",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"call",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"call",
"[",
"'method'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidConfiguration",
"(",
"'method is required for setter injection in service '",
".",
"$",
"name",
")",
";",
"}",
"$",
"arguments",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"method",
"=",
"$",
"class",
"->",
"getMethod",
"(",
"$",
"call",
"[",
"'method'",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidConfiguration",
"(",
"'method '",
".",
"$",
"call",
"[",
"'method'",
"]",
".",
"' is not callable in class '",
".",
"$",
"class",
"->",
"getName",
"(",
")",
".",
"' for service '",
".",
"$",
"name",
")",
";",
"}",
"$",
"arguments",
"=",
"$",
"this",
"->",
"autoWireMethod",
"(",
"$",
"name",
",",
"$",
"method",
",",
"$",
"call",
")",
";",
"$",
"result",
"=",
"call_user_func_array",
"(",
"[",
"&",
"$",
"service",
",",
"$",
"call",
"[",
"'method'",
"]",
"]",
",",
"$",
"arguments",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"call",
"[",
"'select'",
"]",
")",
"&&",
"true",
"===",
"$",
"call",
"[",
"'select'",
"]",
")",
"{",
"$",
"service",
"=",
"$",
"result",
";",
"}",
"}",
"$",
"this",
"->",
"storeService",
"(",
"$",
"name",
",",
"$",
"config",
",",
"$",
"service",
")",
";",
"return",
"$",
"service",
";",
"}"
] | Prepare service (execute sub selects and excute setter injections). | [
"Prepare",
"service",
"(",
"execute",
"sub",
"selects",
"and",
"excute",
"setter",
"injections",
")",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L261-L293 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.autoWireMethod | protected function autoWireMethod(string $name, ReflectionMethod $method, array $config, ?array $parameters = null): array
{
$params = $method->getParameters();
$args = [];
foreach ($params as $param) {
$type = $param->getClass();
$param_name = $param->getName();
if (isset($parameters[$param_name])) {
$args[$param_name] = $parameters[$param_name];
} elseif (isset($config['arguments'][$param_name])) {
$args[$param_name] = $this->parseParam($config['arguments'][$param_name], $name);
} elseif (null !== $type) {
$args[$param_name] = $this->resolveServiceArgument($name, $type, $param);
} elseif ($param->isDefaultValueAvailable()) {
$args[$param_name] = $param->getDefaultValue();
} elseif ($param->allowsNull()) {
$args[$param_name] = null;
} else {
throw new Exception\InvalidConfiguration('no value found for argument '.$param_name.' in method '.$method->getName().' for service '.$name);
}
if (!$param->canBePassedByValue()) {
$value = &$args[$param_name];
$args[$param_name] = &$value;
}
}
return $args;
} | php | protected function autoWireMethod(string $name, ReflectionMethod $method, array $config, ?array $parameters = null): array
{
$params = $method->getParameters();
$args = [];
foreach ($params as $param) {
$type = $param->getClass();
$param_name = $param->getName();
if (isset($parameters[$param_name])) {
$args[$param_name] = $parameters[$param_name];
} elseif (isset($config['arguments'][$param_name])) {
$args[$param_name] = $this->parseParam($config['arguments'][$param_name], $name);
} elseif (null !== $type) {
$args[$param_name] = $this->resolveServiceArgument($name, $type, $param);
} elseif ($param->isDefaultValueAvailable()) {
$args[$param_name] = $param->getDefaultValue();
} elseif ($param->allowsNull()) {
$args[$param_name] = null;
} else {
throw new Exception\InvalidConfiguration('no value found for argument '.$param_name.' in method '.$method->getName().' for service '.$name);
}
if (!$param->canBePassedByValue()) {
$value = &$args[$param_name];
$args[$param_name] = &$value;
}
}
return $args;
} | [
"protected",
"function",
"autoWireMethod",
"(",
"string",
"$",
"name",
",",
"ReflectionMethod",
"$",
"method",
",",
"array",
"$",
"config",
",",
"?",
"array",
"$",
"parameters",
"=",
"null",
")",
":",
"array",
"{",
"$",
"params",
"=",
"$",
"method",
"->",
"getParameters",
"(",
")",
";",
"$",
"args",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"type",
"=",
"$",
"param",
"->",
"getClass",
"(",
")",
";",
"$",
"param_name",
"=",
"$",
"param",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"$",
"param_name",
"]",
")",
")",
"{",
"$",
"args",
"[",
"$",
"param_name",
"]",
"=",
"$",
"parameters",
"[",
"$",
"param_name",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"config",
"[",
"'arguments'",
"]",
"[",
"$",
"param_name",
"]",
")",
")",
"{",
"$",
"args",
"[",
"$",
"param_name",
"]",
"=",
"$",
"this",
"->",
"parseParam",
"(",
"$",
"config",
"[",
"'arguments'",
"]",
"[",
"$",
"param_name",
"]",
",",
"$",
"name",
")",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"type",
")",
"{",
"$",
"args",
"[",
"$",
"param_name",
"]",
"=",
"$",
"this",
"->",
"resolveServiceArgument",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"param",
")",
";",
"}",
"elseif",
"(",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"$",
"args",
"[",
"$",
"param_name",
"]",
"=",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"param",
"->",
"allowsNull",
"(",
")",
")",
"{",
"$",
"args",
"[",
"$",
"param_name",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidConfiguration",
"(",
"'no value found for argument '",
".",
"$",
"param_name",
".",
"' in method '",
".",
"$",
"method",
"->",
"getName",
"(",
")",
".",
"' for service '",
".",
"$",
"name",
")",
";",
"}",
"if",
"(",
"!",
"$",
"param",
"->",
"canBePassedByValue",
"(",
")",
")",
"{",
"$",
"value",
"=",
"&",
"$",
"args",
"[",
"$",
"param_name",
"]",
";",
"$",
"args",
"[",
"$",
"param_name",
"]",
"=",
"&",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"args",
";",
"}"
] | Autowire method. | [
"Autowire",
"method",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L298-L328 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.resolveServiceArgument | protected function resolveServiceArgument(string $name, ReflectionClass $type, ReflectionParameter $param)
{
$type_class = $type->getName();
if ($type_class === $name) {
throw new RuntimeException('class '.$type_class.' can not depend on itself');
}
try {
return $this->traverseTree($name, $type_class);
} catch (\Exception $e) {
if ($param->isDefaultValueAvailable() && null === $param->getDefaultValue()) {
return null;
}
throw $e;
}
} | php | protected function resolveServiceArgument(string $name, ReflectionClass $type, ReflectionParameter $param)
{
$type_class = $type->getName();
if ($type_class === $name) {
throw new RuntimeException('class '.$type_class.' can not depend on itself');
}
try {
return $this->traverseTree($name, $type_class);
} catch (\Exception $e) {
if ($param->isDefaultValueAvailable() && null === $param->getDefaultValue()) {
return null;
}
throw $e;
}
} | [
"protected",
"function",
"resolveServiceArgument",
"(",
"string",
"$",
"name",
",",
"ReflectionClass",
"$",
"type",
",",
"ReflectionParameter",
"$",
"param",
")",
"{",
"$",
"type_class",
"=",
"$",
"type",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"type_class",
"===",
"$",
"name",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'class '",
".",
"$",
"type_class",
".",
"' can not depend on itself'",
")",
";",
"}",
"try",
"{",
"return",
"$",
"this",
"->",
"traverseTree",
"(",
"$",
"name",
",",
"$",
"type_class",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
"&&",
"null",
"===",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"}"
] | Resolve service argument. | [
"Resolve",
"service",
"argument",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L333-L350 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.parseParam | protected function parseParam($param, string $name)
{
if (is_iterable($param)) {
foreach ($param as $key => $value) {
$param[$key] = $this->parseParam($value, $name);
}
return $param;
}
if (is_string($param)) {
$param = $this->config->getEnv($param);
if (preg_match('#^\{\{([^{}]+)\}\}$#', $param, $matches)) {
return '{'.$matches[1].'}';
}
if (preg_match('#^\{([^{}]+)\}$#', $param, $matches)) {
return $this->traverseTree($name, $matches[1]);
}
return $param;
}
return $param;
} | php | protected function parseParam($param, string $name)
{
if (is_iterable($param)) {
foreach ($param as $key => $value) {
$param[$key] = $this->parseParam($value, $name);
}
return $param;
}
if (is_string($param)) {
$param = $this->config->getEnv($param);
if (preg_match('#^\{\{([^{}]+)\}\}$#', $param, $matches)) {
return '{'.$matches[1].'}';
}
if (preg_match('#^\{([^{}]+)\}$#', $param, $matches)) {
return $this->traverseTree($name, $matches[1]);
}
return $param;
}
return $param;
} | [
"protected",
"function",
"parseParam",
"(",
"$",
"param",
",",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"is_iterable",
"(",
"$",
"param",
")",
")",
"{",
"foreach",
"(",
"$",
"param",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"param",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"parseParam",
"(",
"$",
"value",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"param",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"param",
")",
")",
"{",
"$",
"param",
"=",
"$",
"this",
"->",
"config",
"->",
"getEnv",
"(",
"$",
"param",
")",
";",
"if",
"(",
"preg_match",
"(",
"'#^\\{\\{([^{}]+)\\}\\}$#'",
",",
"$",
"param",
",",
"$",
"matches",
")",
")",
"{",
"return",
"'{'",
".",
"$",
"matches",
"[",
"1",
"]",
".",
"'}'",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'#^\\{([^{}]+)\\}$#'",
",",
"$",
"param",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"this",
"->",
"traverseTree",
"(",
"$",
"name",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"return",
"$",
"param",
";",
"}",
"return",
"$",
"param",
";",
"}"
] | Parse param value. | [
"Parse",
"param",
"value",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L355-L379 |
gyselroth/micro-container | src/RuntimeContainer.php | RuntimeContainer.traverseTree | protected function traverseTree(string $current_service, string $service)
{
if (isset($this->children[$current_service])) {
return $this->children[$current_service]->get($service);
}
$config = $this->config->get($current_service);
if (isset($config['services'])) {
$this->children[$current_service] = new self($config['services'], $this, $this->service[ContainerInterface::class]);
return $this->children[$current_service]->get($service);
}
return $this->get($service);
} | php | protected function traverseTree(string $current_service, string $service)
{
if (isset($this->children[$current_service])) {
return $this->children[$current_service]->get($service);
}
$config = $this->config->get($current_service);
if (isset($config['services'])) {
$this->children[$current_service] = new self($config['services'], $this, $this->service[ContainerInterface::class]);
return $this->children[$current_service]->get($service);
}
return $this->get($service);
} | [
"protected",
"function",
"traverseTree",
"(",
"string",
"$",
"current_service",
",",
"string",
"$",
"service",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"current_service",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"children",
"[",
"$",
"current_service",
"]",
"->",
"get",
"(",
"$",
"service",
")",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"current_service",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'services'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"children",
"[",
"$",
"current_service",
"]",
"=",
"new",
"self",
"(",
"$",
"config",
"[",
"'services'",
"]",
",",
"$",
"this",
",",
"$",
"this",
"->",
"service",
"[",
"ContainerInterface",
"::",
"class",
"]",
")",
";",
"return",
"$",
"this",
"->",
"children",
"[",
"$",
"current_service",
"]",
"->",
"get",
"(",
"$",
"service",
")",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"service",
")",
";",
"}"
] | Locate service. | [
"Locate",
"service",
"."
] | train | https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L384-L398 |
zicht/z | src/Zicht/Tool/Packager/Packager.php | Packager.package | public function package($targetFile, $force)
{
if (is_file($targetFile)) {
if ($force) {
unlink($targetFile);
} else {
throw new \RuntimeException("File {$targetFile} already exists");
}
}
$curDir = getcwd();
$buildFile = 'build.phar';
$phar = new \Phar($buildFile);
if ($static = $this->options['static']) {
$stub = new Node\StaticStub(
$phar,
$this->options['app-name'],
$this->options['app-version'],
$this->options['static'],
$this->options['static-plugin-paths']
);
} else {
$stub = new Node\DynamicStub(
$phar,
$this->options['app-name'],
$this->options['app-version'],
$this->options['config-filename']
);
}
$buffer = new Buffer();
$buffer
->writeln('#!/usr/bin/env php')
->writeln('<?php')
->writeln(self::$HEADER)
;
$stub->compile($buffer);
chdir($this->srcRoot);
$finder = new Finder();
$files = $finder
->in(array('vendor', 'src'))
->ignoreVCS(true)
// Finder is only used by the packager, not by Z itself.
->exclude(array('vendor/symfony/finder'))
->files();
foreach ($files as $file) {
$phar[$file->getPathname()] = file_get_contents($file->getPathname());
}
$phar['LICENSE'] = file_get_contents('LICENSE');
chdir($curDir);
$phar->setStub($buffer->getResult());
rename($buildFile, $targetFile);
chmod($targetFile, 0755);
chdir($curDir);
return realpath($targetFile);
} | php | public function package($targetFile, $force)
{
if (is_file($targetFile)) {
if ($force) {
unlink($targetFile);
} else {
throw new \RuntimeException("File {$targetFile} already exists");
}
}
$curDir = getcwd();
$buildFile = 'build.phar';
$phar = new \Phar($buildFile);
if ($static = $this->options['static']) {
$stub = new Node\StaticStub(
$phar,
$this->options['app-name'],
$this->options['app-version'],
$this->options['static'],
$this->options['static-plugin-paths']
);
} else {
$stub = new Node\DynamicStub(
$phar,
$this->options['app-name'],
$this->options['app-version'],
$this->options['config-filename']
);
}
$buffer = new Buffer();
$buffer
->writeln('#!/usr/bin/env php')
->writeln('<?php')
->writeln(self::$HEADER)
;
$stub->compile($buffer);
chdir($this->srcRoot);
$finder = new Finder();
$files = $finder
->in(array('vendor', 'src'))
->ignoreVCS(true)
// Finder is only used by the packager, not by Z itself.
->exclude(array('vendor/symfony/finder'))
->files();
foreach ($files as $file) {
$phar[$file->getPathname()] = file_get_contents($file->getPathname());
}
$phar['LICENSE'] = file_get_contents('LICENSE');
chdir($curDir);
$phar->setStub($buffer->getResult());
rename($buildFile, $targetFile);
chmod($targetFile, 0755);
chdir($curDir);
return realpath($targetFile);
} | [
"public",
"function",
"package",
"(",
"$",
"targetFile",
",",
"$",
"force",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"targetFile",
")",
")",
"{",
"if",
"(",
"$",
"force",
")",
"{",
"unlink",
"(",
"$",
"targetFile",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"File {$targetFile} already exists\"",
")",
";",
"}",
"}",
"$",
"curDir",
"=",
"getcwd",
"(",
")",
";",
"$",
"buildFile",
"=",
"'build.phar'",
";",
"$",
"phar",
"=",
"new",
"\\",
"Phar",
"(",
"$",
"buildFile",
")",
";",
"if",
"(",
"$",
"static",
"=",
"$",
"this",
"->",
"options",
"[",
"'static'",
"]",
")",
"{",
"$",
"stub",
"=",
"new",
"Node",
"\\",
"StaticStub",
"(",
"$",
"phar",
",",
"$",
"this",
"->",
"options",
"[",
"'app-name'",
"]",
",",
"$",
"this",
"->",
"options",
"[",
"'app-version'",
"]",
",",
"$",
"this",
"->",
"options",
"[",
"'static'",
"]",
",",
"$",
"this",
"->",
"options",
"[",
"'static-plugin-paths'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"stub",
"=",
"new",
"Node",
"\\",
"DynamicStub",
"(",
"$",
"phar",
",",
"$",
"this",
"->",
"options",
"[",
"'app-name'",
"]",
",",
"$",
"this",
"->",
"options",
"[",
"'app-version'",
"]",
",",
"$",
"this",
"->",
"options",
"[",
"'config-filename'",
"]",
")",
";",
"}",
"$",
"buffer",
"=",
"new",
"Buffer",
"(",
")",
";",
"$",
"buffer",
"->",
"writeln",
"(",
"'#!/usr/bin/env php'",
")",
"->",
"writeln",
"(",
"'<?php'",
")",
"->",
"writeln",
"(",
"self",
"::",
"$",
"HEADER",
")",
";",
"$",
"stub",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"chdir",
"(",
"$",
"this",
"->",
"srcRoot",
")",
";",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"files",
"=",
"$",
"finder",
"->",
"in",
"(",
"array",
"(",
"'vendor'",
",",
"'src'",
")",
")",
"->",
"ignoreVCS",
"(",
"true",
")",
"// Finder is only used by the packager, not by Z itself.",
"->",
"exclude",
"(",
"array",
"(",
"'vendor/symfony/finder'",
")",
")",
"->",
"files",
"(",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"phar",
"[",
"$",
"file",
"->",
"getPathname",
"(",
")",
"]",
"=",
"file_get_contents",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"$",
"phar",
"[",
"'LICENSE'",
"]",
"=",
"file_get_contents",
"(",
"'LICENSE'",
")",
";",
"chdir",
"(",
"$",
"curDir",
")",
";",
"$",
"phar",
"->",
"setStub",
"(",
"$",
"buffer",
"->",
"getResult",
"(",
")",
")",
";",
"rename",
"(",
"$",
"buildFile",
",",
"$",
"targetFile",
")",
";",
"chmod",
"(",
"$",
"targetFile",
",",
"0755",
")",
";",
"chdir",
"(",
"$",
"curDir",
")",
";",
"return",
"realpath",
"(",
"$",
"targetFile",
")",
";",
"}"
] | Build the package file.
Throws an exception if the file already exists. Pass $force as true to override this.
@param string $targetFile
@param bool $force
@return string
@throws \RuntimeException | [
"Build",
"the",
"package",
"file",
".",
"Throws",
"an",
"exception",
"if",
"the",
"file",
"already",
"exists",
".",
"Pass",
"$force",
"as",
"true",
"to",
"override",
"this",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Packager/Packager.php#L48-L106 |
ZayconFoods/whatcounts | src/ZayconWhatCounts/Realm.php | Realm.setRealmId | public function setRealmId( $realm_id )
{
$this->realm_id = (is_numeric($realm_id)) ? abs(round($realm_id)) : NULL;
return $this;
} | php | public function setRealmId( $realm_id )
{
$this->realm_id = (is_numeric($realm_id)) ? abs(round($realm_id)) : NULL;
return $this;
} | [
"public",
"function",
"setRealmId",
"(",
"$",
"realm_id",
")",
"{",
"$",
"this",
"->",
"realm_id",
"=",
"(",
"is_numeric",
"(",
"$",
"realm_id",
")",
")",
"?",
"abs",
"(",
"round",
"(",
"$",
"realm_id",
")",
")",
":",
"NULL",
";",
"return",
"$",
"this",
";",
"}"
] | @param mixed $realm_id
@return Realm | [
"@param",
"mixed",
"$realm_id"
] | train | https://github.com/ZayconFoods/whatcounts/blob/ff18491fc152571a72e4b558f8102f4fbb9bb7fd/src/ZayconWhatCounts/Realm.php#L30-L35 |
ZayconFoods/whatcounts | src/ZayconWhatCounts/Realm.php | Realm.setUseCustomerKey | public function setUseCustomerKey( $use_customer_key )
{
$this->use_customer_key = ($use_customer_key == 1 || $use_customer_key == 'Y' || $use_customer_key === TRUE) ? TRUE : FALSE;
return $this;
} | php | public function setUseCustomerKey( $use_customer_key )
{
$this->use_customer_key = ($use_customer_key == 1 || $use_customer_key == 'Y' || $use_customer_key === TRUE) ? TRUE : FALSE;
return $this;
} | [
"public",
"function",
"setUseCustomerKey",
"(",
"$",
"use_customer_key",
")",
"{",
"$",
"this",
"->",
"use_customer_key",
"=",
"(",
"$",
"use_customer_key",
"==",
"1",
"||",
"$",
"use_customer_key",
"==",
"'Y'",
"||",
"$",
"use_customer_key",
"===",
"TRUE",
")",
"?",
"TRUE",
":",
"FALSE",
";",
"return",
"$",
"this",
";",
"}"
] | @param mixed $use_customer_key
@return Realm | [
"@param",
"mixed",
"$use_customer_key"
] | train | https://github.com/ZayconFoods/whatcounts/blob/ff18491fc152571a72e4b558f8102f4fbb9bb7fd/src/ZayconWhatCounts/Realm.php#L50-L55 |
ZayconFoods/whatcounts | src/ZayconWhatCounts/Realm.php | Realm.setEnableRelationalDatabase | public function setEnableRelationalDatabase( $enable_relational_database )
{
$this->enable_relational_database = ($enable_relational_database == 1 || $enable_relational_database == 'Y' || $enable_relational_database === TRUE) ? TRUE : FALSE;
return $this;
} | php | public function setEnableRelationalDatabase( $enable_relational_database )
{
$this->enable_relational_database = ($enable_relational_database == 1 || $enable_relational_database == 'Y' || $enable_relational_database === TRUE) ? TRUE : FALSE;
return $this;
} | [
"public",
"function",
"setEnableRelationalDatabase",
"(",
"$",
"enable_relational_database",
")",
"{",
"$",
"this",
"->",
"enable_relational_database",
"=",
"(",
"$",
"enable_relational_database",
"==",
"1",
"||",
"$",
"enable_relational_database",
"==",
"'Y'",
"||",
"$",
"enable_relational_database",
"===",
"TRUE",
")",
"?",
"TRUE",
":",
"FALSE",
";",
"return",
"$",
"this",
";",
"}"
] | @param mixed $enable_relational_database
@return Realm | [
"@param",
"mixed",
"$enable_relational_database"
] | train | https://github.com/ZayconFoods/whatcounts/blob/ff18491fc152571a72e4b558f8102f4fbb9bb7fd/src/ZayconWhatCounts/Realm.php#L70-L75 |
jarod2011/SimpleConcurrentRequestClient | src/SimpleConcurrent.php | SimpleRequest.setRequest | public function setRequest(RequestInterface $request, array $options = []): self
{
$this->requestOrign = $request;
$this->requestOption = $options;
return $this;
} | php | public function setRequest(RequestInterface $request, array $options = []): self
{
$this->requestOrign = $request;
$this->requestOption = $options;
return $this;
} | [
"public",
"function",
"setRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"this",
"->",
"requestOrign",
"=",
"$",
"request",
";",
"$",
"this",
"->",
"requestOption",
"=",
"$",
"options",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritDoc}
@see \SimpleConcurrent\SimpleRequestInterface::setRequest() | [
"{"
] | train | https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L220-L225 |
jarod2011/SimpleConcurrentRequestClient | src/SimpleConcurrent.php | SimpleRequest.getPromise | public function getPromise(): PromiseInterface
{
if (! $this->requestOrign && ! $this->promise) throw new RequestBuildExpection('please give a request.');
if (! $this->promise) {
$this->promise = $this->_getClient()->sendAsync($this->requestOrign, $this->requestOption);
}
if ($this->responseIsJson && ! $this->isJsonCallbackPassed) {
array_unshift($this->callbackOfSuccess, function ($res) {
return json_decode($res, true);
});
$this->isJsonCallbackPassed = true;
}
return $this->promise;
} | php | public function getPromise(): PromiseInterface
{
if (! $this->requestOrign && ! $this->promise) throw new RequestBuildExpection('please give a request.');
if (! $this->promise) {
$this->promise = $this->_getClient()->sendAsync($this->requestOrign, $this->requestOption);
}
if ($this->responseIsJson && ! $this->isJsonCallbackPassed) {
array_unshift($this->callbackOfSuccess, function ($res) {
return json_decode($res, true);
});
$this->isJsonCallbackPassed = true;
}
return $this->promise;
} | [
"public",
"function",
"getPromise",
"(",
")",
":",
"PromiseInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"requestOrign",
"&&",
"!",
"$",
"this",
"->",
"promise",
")",
"throw",
"new",
"RequestBuildExpection",
"(",
"'please give a request.'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"promise",
")",
"{",
"$",
"this",
"->",
"promise",
"=",
"$",
"this",
"->",
"_getClient",
"(",
")",
"->",
"sendAsync",
"(",
"$",
"this",
"->",
"requestOrign",
",",
"$",
"this",
"->",
"requestOption",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"responseIsJson",
"&&",
"!",
"$",
"this",
"->",
"isJsonCallbackPassed",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"callbackOfSuccess",
",",
"function",
"(",
"$",
"res",
")",
"{",
"return",
"json_decode",
"(",
"$",
"res",
",",
"true",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"isJsonCallbackPassed",
"=",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"promise",
";",
"}"
] | {@inheritDoc}
@see \SimpleConcurrent\SimpleRequestInterface::getPromise() | [
"{"
] | train | https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L262-L275 |
jarod2011/SimpleConcurrentRequestClient | src/SimpleConcurrent.php | RequestClient._getClient | private function _getClient(): ClientInterface
{
if (! $this->client instanceof ClientInterface) $this->client = new Client($this->clientConfig);
return $this->client;
} | php | private function _getClient(): ClientInterface
{
if (! $this->client instanceof ClientInterface) $this->client = new Client($this->clientConfig);
return $this->client;
} | [
"private",
"function",
"_getClient",
"(",
")",
":",
"ClientInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"client",
"instanceof",
"ClientInterface",
")",
"$",
"this",
"->",
"client",
"=",
"new",
"Client",
"(",
"$",
"this",
"->",
"clientConfig",
")",
";",
"return",
"$",
"this",
"->",
"client",
";",
"}"
] | get a client implements \GuzzleHttp\ClientInterface
@return ClientInterface | [
"get",
"a",
"client",
"implements",
"\\",
"GuzzleHttp",
"\\",
"ClientInterface"
] | train | https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L434-L438 |
jarod2011/SimpleConcurrentRequestClient | src/SimpleConcurrent.php | RequestClient.addClientHeader | public function addClientHeader(string $headerName, $headerValue): self
{
$this->clientConfig['headers'][$headerName] = $headerValue;
return $this;
} | php | public function addClientHeader(string $headerName, $headerValue): self
{
$this->clientConfig['headers'][$headerName] = $headerValue;
return $this;
} | [
"public",
"function",
"addClientHeader",
"(",
"string",
"$",
"headerName",
",",
"$",
"headerValue",
")",
":",
"self",
"{",
"$",
"this",
"->",
"clientConfig",
"[",
"'headers'",
"]",
"[",
"$",
"headerName",
"]",
"=",
"$",
"headerValue",
";",
"return",
"$",
"this",
";",
"}"
] | add a client request header
@param string $headerName
@param mixed $headerValue
@return self | [
"add",
"a",
"client",
"request",
"header"
] | train | https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L457-L461 |
jarod2011/SimpleConcurrentRequestClient | src/SimpleConcurrent.php | RequestClient._responseSuccessHandle | private function _responseSuccessHandle($response, $index)
{
try {
if (! $response instanceof ResponseInterface) throw new UnknowResponseExpection($response);
$result = $response->getBody()->getContents();
$cbk = $this->requestList[$index]->getSuccessCallbackList();
if (! empty($cbk)) {
$result = array_reduce($cbk, function ($prev, $cb) {
return $cb($prev);
}, $result);
}
$response = new SimpleResponse();
$response->setResult($result);
$this->requestList[$index]->setResponse($response);
} catch (\Exception $e) {
$this->_responseFailHandle($e, $index);
}
} | php | private function _responseSuccessHandle($response, $index)
{
try {
if (! $response instanceof ResponseInterface) throw new UnknowResponseExpection($response);
$result = $response->getBody()->getContents();
$cbk = $this->requestList[$index]->getSuccessCallbackList();
if (! empty($cbk)) {
$result = array_reduce($cbk, function ($prev, $cb) {
return $cb($prev);
}, $result);
}
$response = new SimpleResponse();
$response->setResult($result);
$this->requestList[$index]->setResponse($response);
} catch (\Exception $e) {
$this->_responseFailHandle($e, $index);
}
} | [
"private",
"function",
"_responseSuccessHandle",
"(",
"$",
"response",
",",
"$",
"index",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"response",
"instanceof",
"ResponseInterface",
")",
"throw",
"new",
"UnknowResponseExpection",
"(",
"$",
"response",
")",
";",
"$",
"result",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"$",
"cbk",
"=",
"$",
"this",
"->",
"requestList",
"[",
"$",
"index",
"]",
"->",
"getSuccessCallbackList",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cbk",
")",
")",
"{",
"$",
"result",
"=",
"array_reduce",
"(",
"$",
"cbk",
",",
"function",
"(",
"$",
"prev",
",",
"$",
"cb",
")",
"{",
"return",
"$",
"cb",
"(",
"$",
"prev",
")",
";",
"}",
",",
"$",
"result",
")",
";",
"}",
"$",
"response",
"=",
"new",
"SimpleResponse",
"(",
")",
";",
"$",
"response",
"->",
"setResult",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"requestList",
"[",
"$",
"index",
"]",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"_responseFailHandle",
"(",
"$",
"e",
",",
"$",
"index",
")",
";",
"}",
"}"
] | when request successed this method will be called
@param mixed $response
@param int $index
@throws \Exception | [
"when",
"request",
"successed",
"this",
"method",
"will",
"be",
"called"
] | train | https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L557-L574 |
jarod2011/SimpleConcurrentRequestClient | src/SimpleConcurrent.php | RequestClient._responseFailHandle | private function _responseFailHandle($error, $index)
{
$cbk = $this->requestList[$index]->getFailCallbackList();
if (! empty($cbk)) {
$error = array_reduce($cbk, function ($prev, $cb) {
return $cb($prev);
}, $error);
}
$response = new SimpleResponse();
$response->setFail($error);
$this->requestList[$index]->setResponse($response);
} | php | private function _responseFailHandle($error, $index)
{
$cbk = $this->requestList[$index]->getFailCallbackList();
if (! empty($cbk)) {
$error = array_reduce($cbk, function ($prev, $cb) {
return $cb($prev);
}, $error);
}
$response = new SimpleResponse();
$response->setFail($error);
$this->requestList[$index]->setResponse($response);
} | [
"private",
"function",
"_responseFailHandle",
"(",
"$",
"error",
",",
"$",
"index",
")",
"{",
"$",
"cbk",
"=",
"$",
"this",
"->",
"requestList",
"[",
"$",
"index",
"]",
"->",
"getFailCallbackList",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cbk",
")",
")",
"{",
"$",
"error",
"=",
"array_reduce",
"(",
"$",
"cbk",
",",
"function",
"(",
"$",
"prev",
",",
"$",
"cb",
")",
"{",
"return",
"$",
"cb",
"(",
"$",
"prev",
")",
";",
"}",
",",
"$",
"error",
")",
";",
"}",
"$",
"response",
"=",
"new",
"SimpleResponse",
"(",
")",
";",
"$",
"response",
"->",
"setFail",
"(",
"$",
"error",
")",
";",
"$",
"this",
"->",
"requestList",
"[",
"$",
"index",
"]",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"}"
] | when request failed this method will be called
@param mixed $error
@param int $index | [
"when",
"request",
"failed",
"this",
"method",
"will",
"be",
"called"
] | train | https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L581-L592 |
jarod2011/SimpleConcurrentRequestClient | src/SimpleConcurrent.php | RequestClient._getRequestPool | private function _getRequestPool(): Pool
{
return new Pool($this->_getClient(), $this->_getRequestPromise(), [
'concurrency' => max(1, $this->configOfConcurrency),
'fulfilled' => function () {
call_user_func_array([$this, '_responseSuccessHandle'], func_get_args());
},
'rejected' => function () {
call_user_func_array([$this, '_responseFailHandle'], func_get_args());
}
]);
} | php | private function _getRequestPool(): Pool
{
return new Pool($this->_getClient(), $this->_getRequestPromise(), [
'concurrency' => max(1, $this->configOfConcurrency),
'fulfilled' => function () {
call_user_func_array([$this, '_responseSuccessHandle'], func_get_args());
},
'rejected' => function () {
call_user_func_array([$this, '_responseFailHandle'], func_get_args());
}
]);
} | [
"private",
"function",
"_getRequestPool",
"(",
")",
":",
"Pool",
"{",
"return",
"new",
"Pool",
"(",
"$",
"this",
"->",
"_getClient",
"(",
")",
",",
"$",
"this",
"->",
"_getRequestPromise",
"(",
")",
",",
"[",
"'concurrency'",
"=>",
"max",
"(",
"1",
",",
"$",
"this",
"->",
"configOfConcurrency",
")",
",",
"'fulfilled'",
"=>",
"function",
"(",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'_responseSuccessHandle'",
"]",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
",",
"'rejected'",
"=>",
"function",
"(",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'_responseFailHandle'",
"]",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
"]",
")",
";",
"}"
] | build a request pool implements \GuzzleHttp\Pool
@return Pool | [
"build",
"a",
"request",
"pool",
"implements",
"\\",
"GuzzleHttp",
"\\",
"Pool"
] | train | https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L610-L621 |
jarod2011/SimpleConcurrentRequestClient | src/SimpleConcurrent.php | RequestClient.customSetting | public function customSetting(string $settingKey, $settingValue): self
{
$this->clientConfig[$settingKey] = $settingValue;
return $this;
} | php | public function customSetting(string $settingKey, $settingValue): self
{
$this->clientConfig[$settingKey] = $settingValue;
return $this;
} | [
"public",
"function",
"customSetting",
"(",
"string",
"$",
"settingKey",
",",
"$",
"settingValue",
")",
":",
"self",
"{",
"$",
"this",
"->",
"clientConfig",
"[",
"$",
"settingKey",
"]",
"=",
"$",
"settingValue",
";",
"return",
"$",
"this",
";",
"}"
] | add or modify client config by custom
@return self | [
"add",
"or",
"modify",
"client",
"config",
"by",
"custom"
] | train | https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L648-L652 |
alevilar/ristorantino-vendor | Risto/Controller/Component/Auth/PinAuthenticate.php | PinAuthenticate._checkFields | protected function _checkFields(CakeRequest $request, $model, $fields) {
if (empty($request->data[$model])) {
return false;
}
foreach (array($fields['pin']) as $field) {
$value = $request->data($model . '.' . $field);
if (empty($value) && $value !== '0' || !is_string($value)) {
return false;
}
}
return true;
} | php | protected function _checkFields(CakeRequest $request, $model, $fields) {
if (empty($request->data[$model])) {
return false;
}
foreach (array($fields['pin']) as $field) {
$value = $request->data($model . '.' . $field);
if (empty($value) && $value !== '0' || !is_string($value)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"_checkFields",
"(",
"CakeRequest",
"$",
"request",
",",
"$",
"model",
",",
"$",
"fields",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"request",
"->",
"data",
"[",
"$",
"model",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array",
"(",
"$",
"fields",
"[",
"'pin'",
"]",
")",
"as",
"$",
"field",
")",
"{",
"$",
"value",
"=",
"$",
"request",
"->",
"data",
"(",
"$",
"model",
".",
"'.'",
".",
"$",
"field",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"!==",
"'0'",
"||",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks the fields to ensure they are supplied.
@param CakeRequest $request The request that contains login information.
@param string $model The model used for login verification.
@param array $fields The fields to be checked.
@return bool False if the fields have not been supplied. True if they exist. | [
"Checks",
"the",
"fields",
"to",
"ensure",
"they",
"are",
"supplied",
"."
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/Component/Auth/PinAuthenticate.php#L59-L70 |
alevilar/ristorantino-vendor | Risto/Controller/Component/Auth/PinAuthenticate.php | PinAuthenticate.authenticate | public function authenticate(CakeRequest $request, CakeResponse $response) {
App::uses('MtSites', 'MtSites./Utility/MtSites');
// solo utilizar el logueo con PIN desde un Tenant
if ( !MtSites::isTenant() ) {
return false;
}
$userModel = $this->settings['userModel'];
list(, $model) = pluginSplit($userModel);
$fields = $this->settings['fields'];
if (!$this->_checkFields($request, $model, $fields)) {
return false;
}
return $this->_findUser($request->data[$model][$fields['pin']]);
} | php | public function authenticate(CakeRequest $request, CakeResponse $response) {
App::uses('MtSites', 'MtSites./Utility/MtSites');
// solo utilizar el logueo con PIN desde un Tenant
if ( !MtSites::isTenant() ) {
return false;
}
$userModel = $this->settings['userModel'];
list(, $model) = pluginSplit($userModel);
$fields = $this->settings['fields'];
if (!$this->_checkFields($request, $model, $fields)) {
return false;
}
return $this->_findUser($request->data[$model][$fields['pin']]);
} | [
"public",
"function",
"authenticate",
"(",
"CakeRequest",
"$",
"request",
",",
"CakeResponse",
"$",
"response",
")",
"{",
"App",
"::",
"uses",
"(",
"'MtSites'",
",",
"'MtSites./Utility/MtSites'",
")",
";",
"// solo utilizar el logueo con PIN desde un Tenant",
"if",
"(",
"!",
"MtSites",
"::",
"isTenant",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"userModel",
"=",
"$",
"this",
"->",
"settings",
"[",
"'userModel'",
"]",
";",
"list",
"(",
",",
"$",
"model",
")",
"=",
"pluginSplit",
"(",
"$",
"userModel",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"settings",
"[",
"'fields'",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_checkFields",
"(",
"$",
"request",
",",
"$",
"model",
",",
"$",
"fields",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"_findUser",
"(",
"$",
"request",
"->",
"data",
"[",
"$",
"model",
"]",
"[",
"$",
"fields",
"[",
"'pin'",
"]",
"]",
")",
";",
"}"
] | Authenticates the identity contained in a request. Will use the `settings.userModel`, and `settings.fields`
to find POST data that is used to find a matching record in the `settings.userModel`. Will return false if
there is no post data, either username or pin is missing, or if the scope conditions have not been met.
@param CakeRequest $request The request that contains login information.
@param CakeResponse $response Unused response object.
@return mixed False on login failure. An array of User data on success. | [
"Authenticates",
"the",
"identity",
"contained",
"in",
"a",
"request",
".",
"Will",
"use",
"the",
"settings",
".",
"userModel",
"and",
"settings",
".",
"fields",
"to",
"find",
"POST",
"data",
"that",
"is",
"used",
"to",
"find",
"a",
"matching",
"record",
"in",
"the",
"settings",
".",
"userModel",
".",
"Will",
"return",
"false",
"if",
"there",
"is",
"no",
"post",
"data",
"either",
"username",
"or",
"pin",
"is",
"missing",
"or",
"if",
"the",
"scope",
"conditions",
"have",
"not",
"been",
"met",
"."
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/Component/Auth/PinAuthenticate.php#L81-L96 |
alevilar/ristorantino-vendor | Risto/Controller/Component/Auth/PinAuthenticate.php | PinAuthenticate._findUser | protected function _findUser($pin, $password = null) {
App::uses("MtSites", "MtSites.Utility");
$userModel = $this->settings['userModel'];
list(, $model) = pluginSplit($userModel);
$fields = $this->settings['fields'];
$conditions = array(
$model . '.pin' => $pin
);
if (!empty($this->settings['scope'])) {
$conditions = array_merge($conditions, $this->settings['scope']);
}
$userFields = $this->settings['userFields'];
if ($pin !== null && $userFields !== null) {
$userFields[] = $model . '.' . $fields['pin'];
}
$result = ClassRegistry::init($userModel)->find('first', array(
'conditions' => $conditions,
'recursive' => $this->settings['recursive'],
'fields' => $userFields,
'contain' => $this->settings['contain'],
));
if (empty($result[$model])) {
return false;
}
debug($result);
$user = $result[$model];
$user['username'] = $result['Rol']['name'];
$user['Rol'] = array($result['Rol']);
$site = ClassRegistry::init('MtSites.Site')->find('first', array(
'conditions' => array(
'Site.alias' => MtSites::getSiteName()
)
));
$user['Site'] = array($site['Site']);
unset($result[$model]);
return $user;
} | php | protected function _findUser($pin, $password = null) {
App::uses("MtSites", "MtSites.Utility");
$userModel = $this->settings['userModel'];
list(, $model) = pluginSplit($userModel);
$fields = $this->settings['fields'];
$conditions = array(
$model . '.pin' => $pin
);
if (!empty($this->settings['scope'])) {
$conditions = array_merge($conditions, $this->settings['scope']);
}
$userFields = $this->settings['userFields'];
if ($pin !== null && $userFields !== null) {
$userFields[] = $model . '.' . $fields['pin'];
}
$result = ClassRegistry::init($userModel)->find('first', array(
'conditions' => $conditions,
'recursive' => $this->settings['recursive'],
'fields' => $userFields,
'contain' => $this->settings['contain'],
));
if (empty($result[$model])) {
return false;
}
debug($result);
$user = $result[$model];
$user['username'] = $result['Rol']['name'];
$user['Rol'] = array($result['Rol']);
$site = ClassRegistry::init('MtSites.Site')->find('first', array(
'conditions' => array(
'Site.alias' => MtSites::getSiteName()
)
));
$user['Site'] = array($site['Site']);
unset($result[$model]);
return $user;
} | [
"protected",
"function",
"_findUser",
"(",
"$",
"pin",
",",
"$",
"password",
"=",
"null",
")",
"{",
"App",
"::",
"uses",
"(",
"\"MtSites\"",
",",
"\"MtSites.Utility\"",
")",
";",
"$",
"userModel",
"=",
"$",
"this",
"->",
"settings",
"[",
"'userModel'",
"]",
";",
"list",
"(",
",",
"$",
"model",
")",
"=",
"pluginSplit",
"(",
"$",
"userModel",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"settings",
"[",
"'fields'",
"]",
";",
"$",
"conditions",
"=",
"array",
"(",
"$",
"model",
".",
"'.pin'",
"=>",
"$",
"pin",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'scope'",
"]",
")",
")",
"{",
"$",
"conditions",
"=",
"array_merge",
"(",
"$",
"conditions",
",",
"$",
"this",
"->",
"settings",
"[",
"'scope'",
"]",
")",
";",
"}",
"$",
"userFields",
"=",
"$",
"this",
"->",
"settings",
"[",
"'userFields'",
"]",
";",
"if",
"(",
"$",
"pin",
"!==",
"null",
"&&",
"$",
"userFields",
"!==",
"null",
")",
"{",
"$",
"userFields",
"[",
"]",
"=",
"$",
"model",
".",
"'.'",
".",
"$",
"fields",
"[",
"'pin'",
"]",
";",
"}",
"$",
"result",
"=",
"ClassRegistry",
"::",
"init",
"(",
"$",
"userModel",
")",
"->",
"find",
"(",
"'first'",
",",
"array",
"(",
"'conditions'",
"=>",
"$",
"conditions",
",",
"'recursive'",
"=>",
"$",
"this",
"->",
"settings",
"[",
"'recursive'",
"]",
",",
"'fields'",
"=>",
"$",
"userFields",
",",
"'contain'",
"=>",
"$",
"this",
"->",
"settings",
"[",
"'contain'",
"]",
",",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
"[",
"$",
"model",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"debug",
"(",
"$",
"result",
")",
";",
"$",
"user",
"=",
"$",
"result",
"[",
"$",
"model",
"]",
";",
"$",
"user",
"[",
"'username'",
"]",
"=",
"$",
"result",
"[",
"'Rol'",
"]",
"[",
"'name'",
"]",
";",
"$",
"user",
"[",
"'Rol'",
"]",
"=",
"array",
"(",
"$",
"result",
"[",
"'Rol'",
"]",
")",
";",
"$",
"site",
"=",
"ClassRegistry",
"::",
"init",
"(",
"'MtSites.Site'",
")",
"->",
"find",
"(",
"'first'",
",",
"array",
"(",
"'conditions'",
"=>",
"array",
"(",
"'Site.alias'",
"=>",
"MtSites",
"::",
"getSiteName",
"(",
")",
")",
")",
")",
";",
"$",
"user",
"[",
"'Site'",
"]",
"=",
"array",
"(",
"$",
"site",
"[",
"'Site'",
"]",
")",
";",
"unset",
"(",
"$",
"result",
"[",
"$",
"model",
"]",
")",
";",
"return",
"$",
"user",
";",
"}"
] | Find a user record using the standard options.
The $username parameter can be a (string)username or an array containing
conditions for Model::find('first'). If the $pin param is not provided
the pin field will be present in returned array.
Input passwords will be hashed even when a user doesn't exist. This
helps mitigate timing attacks that are attempting to find valid usernames.
@param string $pin The pin, only used if $username param is string.
@param string|array $username The username/identifier, or an array of find conditions.
@return bool|array Either false on failure, or an array of user data. | [
"Find",
"a",
"user",
"record",
"using",
"the",
"standard",
"options",
"."
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/Component/Auth/PinAuthenticate.php#L114-L159 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Scrybe/Converter/Metadata/Glossary.php | Glossary.addTerm | public function addTerm($term, $filename, $line_number)
{
if (!isset($this[$term])) {
$this[$term] = array();
}
if (!isset($this[$term][$filename])) {
$this[$term][$filename] = array();
}
$this[$term][$filename][] = $line_number;
} | php | public function addTerm($term, $filename, $line_number)
{
if (!isset($this[$term])) {
$this[$term] = array();
}
if (!isset($this[$term][$filename])) {
$this[$term][$filename] = array();
}
$this[$term][$filename][] = $line_number;
} | [
"public",
"function",
"addTerm",
"(",
"$",
"term",
",",
"$",
"filename",
",",
"$",
"line_number",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"[",
"$",
"term",
"]",
")",
")",
"{",
"$",
"this",
"[",
"$",
"term",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"[",
"$",
"term",
"]",
"[",
"$",
"filename",
"]",
")",
")",
"{",
"$",
"this",
"[",
"$",
"term",
"]",
"[",
"$",
"filename",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"[",
"$",
"term",
"]",
"[",
"$",
"filename",
"]",
"[",
"]",
"=",
"$",
"line_number",
";",
"}"
] | Adds a glossary term to the collection.
@param string $term
@param string $filename
@param int $line_number
@return void | [
"Adds",
"a",
"glossary",
"term",
"to",
"the",
"collection",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Converter/Metadata/Glossary.php#L48-L58 |
wenbinye/PhalconX | src/Db/Schema/Column.php | Column.fromColumn | public static function fromColumn(Db\Column $column)
{
$data = $column->toArray();
if (isset($data['type']) && is_integer($data['type'])) {
$data['type'] = self::getTypeName($data['type']);
}
if (isset($data['bindType']) && is_integer($data['bindType'])) {
$data['bindType'] = self::getBindName($data['bindType']);
}
return new self($data);
} | php | public static function fromColumn(Db\Column $column)
{
$data = $column->toArray();
if (isset($data['type']) && is_integer($data['type'])) {
$data['type'] = self::getTypeName($data['type']);
}
if (isset($data['bindType']) && is_integer($data['bindType'])) {
$data['bindType'] = self::getBindName($data['bindType']);
}
return new self($data);
} | [
"public",
"static",
"function",
"fromColumn",
"(",
"Db",
"\\",
"Column",
"$",
"column",
")",
"{",
"$",
"data",
"=",
"$",
"column",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
"&&",
"is_integer",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'type'",
"]",
"=",
"self",
"::",
"getTypeName",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'bindType'",
"]",
")",
"&&",
"is_integer",
"(",
"$",
"data",
"[",
"'bindType'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'bindType'",
"]",
"=",
"self",
"::",
"getBindName",
"(",
"$",
"data",
"[",
"'bindType'",
"]",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"data",
")",
";",
"}"
] | create column object | [
"create",
"column",
"object"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Db/Schema/Column.php#L42-L53 |
tyokinuhata/html-builder | lib/Core.php | Core.append | public function append($mode = 'min')
{
if ($mode === 'dev')
{
var_dump($this->buffer);
}
else if ($mode === 'prod')
{
// TODO: 実装
}
else if ($mode === 'min')
{
echo implode('', $this->buffer);
}
} | php | public function append($mode = 'min')
{
if ($mode === 'dev')
{
var_dump($this->buffer);
}
else if ($mode === 'prod')
{
// TODO: 実装
}
else if ($mode === 'min')
{
echo implode('', $this->buffer);
}
} | [
"public",
"function",
"append",
"(",
"$",
"mode",
"=",
"'min'",
")",
"{",
"if",
"(",
"$",
"mode",
"===",
"'dev'",
")",
"{",
"var_dump",
"(",
"$",
"this",
"->",
"buffer",
")",
";",
"}",
"else",
"if",
"(",
"$",
"mode",
"===",
"'prod'",
")",
"{",
"// TODO: 実装",
"}",
"else",
"if",
"(",
"$",
"mode",
"===",
"'min'",
")",
"{",
"echo",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"buffer",
")",
";",
"}",
"}"
] | dev: 開発者モード
prod: プロダクトモード
min: プロダクトモード(ミニファイ)
で出力します
@param $mode | [
"dev",
":",
"開発者モード",
"prod",
":",
"プロダクトモード",
"min",
":",
"プロダクトモード",
"(",
"ミニファイ",
")",
"で出力します"
] | train | https://github.com/tyokinuhata/html-builder/blob/e8deda5e275298694b35122ec0df3eeaef1f7804/lib/Core.php#L25-L39 |
tyokinuhata/html-builder | lib/Core.php | Core.build | public function build($path)
{
$fileName = $path . '.html';
if (!file_exists($fileName))
{
touch($fileName);
}
file_put_contents($fileName, $this->buffer);
} | php | public function build($path)
{
$fileName = $path . '.html';
if (!file_exists($fileName))
{
touch($fileName);
}
file_put_contents($fileName, $this->buffer);
} | [
"public",
"function",
"build",
"(",
"$",
"path",
")",
"{",
"$",
"fileName",
"=",
"$",
"path",
".",
"'.html'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"touch",
"(",
"$",
"fileName",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"fileName",
",",
"$",
"this",
"->",
"buffer",
")",
";",
"}"
] | 任意のパスに任意の名前のhtmlファイルを生成します
@param $path | [
"任意のパスに任意の名前のhtmlファイルを生成します"
] | train | https://github.com/tyokinuhata/html-builder/blob/e8deda5e275298694b35122ec0df3eeaef1f7804/lib/Core.php#L45-L53 |
surebert/surebert-framework | src/sb/JSON/RPC2/Client.php | Client.useEncryption | public function useEncryption($key)
{
$this->encryptor = new \sb\Encryption\ForTransmission($key);
$this->encryption_key = $key;
} | php | public function useEncryption($key)
{
$this->encryptor = new \sb\Encryption\ForTransmission($key);
$this->encryption_key = $key;
} | [
"public",
"function",
"useEncryption",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"encryptor",
"=",
"new",
"\\",
"sb",
"\\",
"Encryption",
"\\",
"ForTransmission",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"encryption_key",
"=",
"$",
"key",
";",
"}"
] | Sets the key that data is encrypted with and turns on encryption, the server must use the same key
@param $key String | [
"Sets",
"the",
"key",
"that",
"data",
"is",
"encrypted",
"with",
"and",
"turns",
"on",
"encryption",
"the",
"server",
"must",
"use",
"the",
"same",
"key"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/JSON/RPC2/Client.php#L114-L118 |
surebert/surebert-framework | src/sb/JSON/RPC2/Client.php | Client.addCookie | public function addCookie($cookie = Array())
{
foreach ($cookie as $key => $val) {
if (isset($this->encryption_key)) {
$val = $this->encryptor->encrypt($val);
}
$this->cookies[$key] = $val;
}
} | php | public function addCookie($cookie = Array())
{
foreach ($cookie as $key => $val) {
if (isset($this->encryption_key)) {
$val = $this->encryptor->encrypt($val);
}
$this->cookies[$key] = $val;
}
} | [
"public",
"function",
"addCookie",
"(",
"$",
"cookie",
"=",
"Array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"cookie",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"encryption_key",
")",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"encryptor",
"->",
"encrypt",
"(",
"$",
"val",
")",
";",
"}",
"$",
"this",
"->",
"cookies",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}"
] | Adds a cookie to send to the server
@param $cookie Array('key' => 'val'); | [
"Adds",
"a",
"cookie",
"to",
"send",
"to",
"the",
"server"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/JSON/RPC2/Client.php#L124-L133 |
surebert/surebert-framework | src/sb/JSON/RPC2/Client.php | Client.dispatch | public function dispatch(\sb\JSON\RPC2\Request $request)
{
if (!(is_array($request->params) || is_object($request->params))) {
$response = new \sb\JSON\RPC2\Response();
$response->error = new \sb\JSON\RPC2\Error('-32602');
$response->message = 'Invalid params';
$response->error->data = 'Invalid method parameters: ' . json_encode($request->params);
return $response;
}
$host = $this->host;
$port = $this->port;
$timeout = $this->timeout;
$request_timeout = $this->request_timeout;
$uri = $this->uri;
$json = json_encode($request);
$this->logRequest($json);
if ($this->debug == true) {
echo "--> " . $json;
}
$headers = [];
if ($this->php_serialize_response) {
$headers[] = "php-serialize-response:".($this->php_serialize_response ? 1 : 0);
}
//if there are cookies add them
if (!empty($this->cookies)) {
$cookies = '';
foreach ($this->cookies as $key => $val) {
$cookies .= $key . '=' . urlencode($val) . ';';
}
$headers[] = "Cookie: " . $cookies;
}
$response_str = '';
$ch = curl_init();
if($headers){
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->verify_ssl ? 2 : false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl ? 2 : false);
curl_setopt($ch, CURLOPT_USERAGENT, $this->agent ? $this->agent : \sb\Gateway::$http_host.' '.'\sb\JSON\RPC2\Client ');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $request_timeout);
curl_setopt($ch, CURLOPT_PORT, $port);
$url = 'http'.($this->port == 443 ? 's' : '').'://'.$this->host.$uri;
if($this->method == 'post'){
if (isset($this->encryption_key)) {
$json = $this->encryptor->encrypt($json);
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
} else {
$params = base64_encode(json_encode($request->params));
$params = urlencode($params);
$url .= (strstr($this->uri, '?') ? '&' : '?')
. 'method=' . $request->method . '¶ms='
. $params . '&id=' . $request->id;
}
curl_setopt ($ch, CURLOPT_URL, $url);
$response_str = curl_exec($ch);
$error = curl_errno($ch);
if($error){
$response = new \sb\JSON\RPC2\Response();
$response->error = new \sb\JSON\RPC2\Error('-32099');
$response->error->message = 'Server error';
$response->error->data = 'Could not reach: ' . $this->host . ": #$error - ". curl_error($ch);
return $response;
}
return $this->processResponse($response_str);
} | php | public function dispatch(\sb\JSON\RPC2\Request $request)
{
if (!(is_array($request->params) || is_object($request->params))) {
$response = new \sb\JSON\RPC2\Response();
$response->error = new \sb\JSON\RPC2\Error('-32602');
$response->message = 'Invalid params';
$response->error->data = 'Invalid method parameters: ' . json_encode($request->params);
return $response;
}
$host = $this->host;
$port = $this->port;
$timeout = $this->timeout;
$request_timeout = $this->request_timeout;
$uri = $this->uri;
$json = json_encode($request);
$this->logRequest($json);
if ($this->debug == true) {
echo "--> " . $json;
}
$headers = [];
if ($this->php_serialize_response) {
$headers[] = "php-serialize-response:".($this->php_serialize_response ? 1 : 0);
}
//if there are cookies add them
if (!empty($this->cookies)) {
$cookies = '';
foreach ($this->cookies as $key => $val) {
$cookies .= $key . '=' . urlencode($val) . ';';
}
$headers[] = "Cookie: " . $cookies;
}
$response_str = '';
$ch = curl_init();
if($headers){
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->verify_ssl ? 2 : false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl ? 2 : false);
curl_setopt($ch, CURLOPT_USERAGENT, $this->agent ? $this->agent : \sb\Gateway::$http_host.' '.'\sb\JSON\RPC2\Client ');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $request_timeout);
curl_setopt($ch, CURLOPT_PORT, $port);
$url = 'http'.($this->port == 443 ? 's' : '').'://'.$this->host.$uri;
if($this->method == 'post'){
if (isset($this->encryption_key)) {
$json = $this->encryptor->encrypt($json);
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
} else {
$params = base64_encode(json_encode($request->params));
$params = urlencode($params);
$url .= (strstr($this->uri, '?') ? '&' : '?')
. 'method=' . $request->method . '¶ms='
. $params . '&id=' . $request->id;
}
curl_setopt ($ch, CURLOPT_URL, $url);
$response_str = curl_exec($ch);
$error = curl_errno($ch);
if($error){
$response = new \sb\JSON\RPC2\Response();
$response->error = new \sb\JSON\RPC2\Error('-32099');
$response->error->message = 'Server error';
$response->error->data = 'Could not reach: ' . $this->host . ": #$error - ". curl_error($ch);
return $response;
}
return $this->processResponse($response_str);
} | [
"public",
"function",
"dispatch",
"(",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"(",
"is_array",
"(",
"$",
"request",
"->",
"params",
")",
"||",
"is_object",
"(",
"$",
"request",
"->",
"params",
")",
")",
")",
"{",
"$",
"response",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"error",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
"(",
"'-32602'",
")",
";",
"$",
"response",
"->",
"message",
"=",
"'Invalid params'",
";",
"$",
"response",
"->",
"error",
"->",
"data",
"=",
"'Invalid method parameters: '",
".",
"json_encode",
"(",
"$",
"request",
"->",
"params",
")",
";",
"return",
"$",
"response",
";",
"}",
"$",
"host",
"=",
"$",
"this",
"->",
"host",
";",
"$",
"port",
"=",
"$",
"this",
"->",
"port",
";",
"$",
"timeout",
"=",
"$",
"this",
"->",
"timeout",
";",
"$",
"request_timeout",
"=",
"$",
"this",
"->",
"request_timeout",
";",
"$",
"uri",
"=",
"$",
"this",
"->",
"uri",
";",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"logRequest",
"(",
"$",
"json",
")",
";",
"if",
"(",
"$",
"this",
"->",
"debug",
"==",
"true",
")",
"{",
"echo",
"\"--> \"",
".",
"$",
"json",
";",
"}",
"$",
"headers",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"php_serialize_response",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"\"php-serialize-response:\"",
".",
"(",
"$",
"this",
"->",
"php_serialize_response",
"?",
"1",
":",
"0",
")",
";",
"}",
"//if there are cookies add them",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"cookies",
")",
")",
"{",
"$",
"cookies",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"cookies",
".=",
"$",
"key",
".",
"'='",
".",
"urlencode",
"(",
"$",
"val",
")",
".",
"';'",
";",
"}",
"$",
"headers",
"[",
"]",
"=",
"\"Cookie: \"",
".",
"$",
"cookies",
";",
"}",
"$",
"response_str",
"=",
"''",
";",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"if",
"(",
"$",
"headers",
")",
"{",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"$",
"this",
"->",
"verify_ssl",
"?",
"2",
":",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"$",
"this",
"->",
"verify_ssl",
"?",
"2",
":",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_USERAGENT",
",",
"$",
"this",
"->",
"agent",
"?",
"$",
"this",
"->",
"agent",
":",
"\\",
"sb",
"\\",
"Gateway",
"::",
"$",
"http_host",
".",
"' '",
".",
"'\\sb\\JSON\\RPC2\\Client '",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_FOLLOWLOCATION",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CONNECTTIMEOUT",
",",
"$",
"timeout",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_TIMEOUT",
",",
"$",
"request_timeout",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_PORT",
",",
"$",
"port",
")",
";",
"$",
"url",
"=",
"'http'",
".",
"(",
"$",
"this",
"->",
"port",
"==",
"443",
"?",
"'s'",
":",
"''",
")",
".",
"'://'",
".",
"$",
"this",
"->",
"host",
".",
"$",
"uri",
";",
"if",
"(",
"$",
"this",
"->",
"method",
"==",
"'post'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"encryption_key",
")",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"encryptor",
"->",
"encrypt",
"(",
"$",
"json",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POST",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"json",
")",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"base64_encode",
"(",
"json_encode",
"(",
"$",
"request",
"->",
"params",
")",
")",
";",
"$",
"params",
"=",
"urlencode",
"(",
"$",
"params",
")",
";",
"$",
"url",
".=",
"(",
"strstr",
"(",
"$",
"this",
"->",
"uri",
",",
"'?'",
")",
"?",
"'&'",
":",
"'?'",
")",
".",
"'method='",
".",
"$",
"request",
"->",
"method",
".",
"'¶ms='",
".",
"$",
"params",
".",
"'&id='",
".",
"$",
"request",
"->",
"id",
";",
"}",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"$",
"response_str",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"error",
"=",
"curl_errno",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"$",
"error",
")",
"{",
"$",
"response",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"error",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
"(",
"'-32099'",
")",
";",
"$",
"response",
"->",
"error",
"->",
"message",
"=",
"'Server error'",
";",
"$",
"response",
"->",
"error",
"->",
"data",
"=",
"'Could not reach: '",
".",
"$",
"this",
"->",
"host",
".",
"\": #$error - \"",
".",
"curl_error",
"(",
"$",
"ch",
")",
";",
"return",
"$",
"response",
";",
"}",
"return",
"$",
"this",
"->",
"processResponse",
"(",
"$",
"response_str",
")",
";",
"}"
] | Dispatches a \sb\JSON\RPC2\Request
@param $request \sb\JSON\RPC2\Request An object instance that models that request
@return \sb\JSON\RPC2\Response | [
"Dispatches",
"a",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Request"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/JSON/RPC2/Client.php#L140-L227 |
surebert/surebert-framework | src/sb/JSON/RPC2/Client.php | Client.processResponse | protected function processResponse($str)
{
if (!empty($this->encryption_key)) {
$str = $this->encryptor->decrypt($str);
}
$this->logResponse($str);
//check if response body is serialized json_response object and just unserialize and return if it is
if ($this->php_serialize_response && !empty($str)) {
try {
$serialized = \unserialize($str);
if ($serialized !== false) {
$response = $serialized;
}
} catch (\Exception $e) {
if ($this->debug) {
echo $body;
}
}
}
//Not sure about this?
$str = \utf8_encode($str);
if (!isset($response)) {
$response = new \sb\JSON\RPC2\Response($str);
}
return $response;
} | php | protected function processResponse($str)
{
if (!empty($this->encryption_key)) {
$str = $this->encryptor->decrypt($str);
}
$this->logResponse($str);
//check if response body is serialized json_response object and just unserialize and return if it is
if ($this->php_serialize_response && !empty($str)) {
try {
$serialized = \unserialize($str);
if ($serialized !== false) {
$response = $serialized;
}
} catch (\Exception $e) {
if ($this->debug) {
echo $body;
}
}
}
//Not sure about this?
$str = \utf8_encode($str);
if (!isset($response)) {
$response = new \sb\JSON\RPC2\Response($str);
}
return $response;
} | [
"protected",
"function",
"processResponse",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"encryption_key",
")",
")",
"{",
"$",
"str",
"=",
"$",
"this",
"->",
"encryptor",
"->",
"decrypt",
"(",
"$",
"str",
")",
";",
"}",
"$",
"this",
"->",
"logResponse",
"(",
"$",
"str",
")",
";",
"//check if response body is serialized json_response object and just unserialize and return if it is",
"if",
"(",
"$",
"this",
"->",
"php_serialize_response",
"&&",
"!",
"empty",
"(",
"$",
"str",
")",
")",
"{",
"try",
"{",
"$",
"serialized",
"=",
"\\",
"unserialize",
"(",
"$",
"str",
")",
";",
"if",
"(",
"$",
"serialized",
"!==",
"false",
")",
"{",
"$",
"response",
"=",
"$",
"serialized",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"echo",
"$",
"body",
";",
"}",
"}",
"}",
"//Not sure about this?",
"$",
"str",
"=",
"\\",
"utf8_encode",
"(",
"$",
"str",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"response",
")",
")",
"{",
"$",
"response",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Response",
"(",
"$",
"str",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Break down the received data into headers and response and then handle gz encoding, encryption, utf, etc
@param $str The data returned from the socket connection
@return string The body of the message | [
"Break",
"down",
"the",
"received",
"data",
"into",
"headers",
"and",
"response",
"and",
"then",
"handle",
"gz",
"encoding",
"encryption",
"utf",
"etc"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/JSON/RPC2/Client.php#L234-L267 |
MASNathan/Parser | src/Parser.php | Parser.files | public static function files(array $listOfFiles)
{
$listOfContents = array();
foreach ($listOfFiles as $key => $filepath) {
$listOfContents[$key] = self::file($filepath);
}
return $listOfContents;
} | php | public static function files(array $listOfFiles)
{
$listOfContents = array();
foreach ($listOfFiles as $key => $filepath) {
$listOfContents[$key] = self::file($filepath);
}
return $listOfContents;
} | [
"public",
"static",
"function",
"files",
"(",
"array",
"$",
"listOfFiles",
")",
"{",
"$",
"listOfContents",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"listOfFiles",
"as",
"$",
"key",
"=>",
"$",
"filepath",
")",
"{",
"$",
"listOfContents",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"file",
"(",
"$",
"filepath",
")",
";",
"}",
"return",
"$",
"listOfContents",
";",
"}"
] | Creates an array of objects from multiple files
@param array $listOfFiles List of file paths
@return array | [
"Creates",
"an",
"array",
"of",
"objects",
"from",
"multiple",
"files"
] | train | https://github.com/MASNathan/Parser/blob/0f55402b99b1e071bdcd6277b9268f783ca25e34/src/Parser.php#L36-L43 |
DesignPond/newsletter | src/Http/Controllers/Backend/ContentController.php | ContentController.store | public function store(ContentRequest $request){
$data = $request->all();
$upload = new Helper();
// image resize
if(isset($data['image']) && !empty($data['image']))
{
$upload->resizeImage($data['image'],$data['type_id']);
}
$this->content->create($data);
alert()->success('Bloc ajouté');
return redirect('build/campagne/'.$data['campagne'].'#componant');
} | php | public function store(ContentRequest $request){
$data = $request->all();
$upload = new Helper();
// image resize
if(isset($data['image']) && !empty($data['image']))
{
$upload->resizeImage($data['image'],$data['type_id']);
}
$this->content->create($data);
alert()->success('Bloc ajouté');
return redirect('build/campagne/'.$data['campagne'].'#componant');
} | [
"public",
"function",
"store",
"(",
"ContentRequest",
"$",
"request",
")",
"{",
"$",
"data",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"upload",
"=",
"new",
"Helper",
"(",
")",
";",
"// image resize",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'image'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"data",
"[",
"'image'",
"]",
")",
")",
"{",
"$",
"upload",
"->",
"resizeImage",
"(",
"$",
"data",
"[",
"'image'",
"]",
",",
"$",
"data",
"[",
"'type_id'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"content",
"->",
"create",
"(",
"$",
"data",
")",
";",
"alert",
"(",
")",
"->",
"success",
"(",
"'Bloc ajouté')",
";",
"",
"return",
"redirect",
"(",
"'build/campagne/'",
".",
"$",
"data",
"[",
"'campagne'",
"]",
".",
"'#componant'",
")",
";",
"}"
] | Add bloc to newsletter
POST data
@return Response | [
"Add",
"bloc",
"to",
"newsletter",
"POST",
"data"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/ContentController.php#L42-L60 |
DesignPond/newsletter | src/Http/Controllers/Backend/ContentController.php | ContentController.update | public function update(Request $request){
$contents = $this->content->update($request->all());
alert()->success('Bloc édité');
return redirect('build/campagne/'.$contents->newsletter_campagne_id.'#componant');
} | php | public function update(Request $request){
$contents = $this->content->update($request->all());
alert()->success('Bloc édité');
return redirect('build/campagne/'.$contents->newsletter_campagne_id.'#componant');
} | [
"public",
"function",
"update",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"content",
"->",
"update",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"alert",
"(",
")",
"->",
"success",
"(",
"'Bloc édité');",
"",
"",
"return",
"redirect",
"(",
"'build/campagne/'",
".",
"$",
"contents",
"->",
"newsletter_campagne_id",
".",
"'#componant'",
")",
";",
"}"
] | Edit bloc from newsletter
POST data
@return Response | [
"Edit",
"bloc",
"from",
"newsletter",
"POST",
"data"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/ContentController.php#L67-L74 |
DesignPond/newsletter | src/Http/Controllers/Backend/ContentController.php | ContentController.sorting | public function sorting(Request $request){
$data = $request->all();
$contents = $this->content->updateSorting($data['bloc_rang']);
return 'ok';
} | php | public function sorting(Request $request){
$data = $request->all();
$contents = $this->content->updateSorting($data['bloc_rang']);
return 'ok';
} | [
"public",
"function",
"sorting",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"data",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"contents",
"=",
"$",
"this",
"->",
"content",
"->",
"updateSorting",
"(",
"$",
"data",
"[",
"'bloc_rang'",
"]",
")",
";",
"return",
"'ok'",
";",
"}"
] | Sorting bloc newsletter
POST remove
AJAX
@return Response | [
"Sorting",
"bloc",
"newsletter",
"POST",
"remove",
"AJAX"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/ContentController.php#L95-L102 |
DesignPond/newsletter | src/Http/Controllers/Backend/ContentController.php | ContentController.sortingGroup | public function sortingGroup(Request $request){
$model = new \App\Droit\Arret\Entities\Groupe();
$helper = new Helper();
$data = $request->all();
$groupe_rang = $data['groupe_rang'];
$groupe_id = $data['groupe_id'];
$arrets = $helper->prepareCategories($groupe_rang);
$groupe = $model->find($groupe_id);
$groupe->arrets()->sync($arrets);
print_r($groupe);
} | php | public function sortingGroup(Request $request){
$model = new \App\Droit\Arret\Entities\Groupe();
$helper = new Helper();
$data = $request->all();
$groupe_rang = $data['groupe_rang'];
$groupe_id = $data['groupe_id'];
$arrets = $helper->prepareCategories($groupe_rang);
$groupe = $model->find($groupe_id);
$groupe->arrets()->sync($arrets);
print_r($groupe);
} | [
"public",
"function",
"sortingGroup",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"model",
"=",
"new",
"\\",
"App",
"\\",
"Droit",
"\\",
"Arret",
"\\",
"Entities",
"\\",
"Groupe",
"(",
")",
";",
"$",
"helper",
"=",
"new",
"Helper",
"(",
")",
";",
"$",
"data",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"groupe_rang",
"=",
"$",
"data",
"[",
"'groupe_rang'",
"]",
";",
"$",
"groupe_id",
"=",
"$",
"data",
"[",
"'groupe_id'",
"]",
";",
"$",
"arrets",
"=",
"$",
"helper",
"->",
"prepareCategories",
"(",
"$",
"groupe_rang",
")",
";",
"$",
"groupe",
"=",
"$",
"model",
"->",
"find",
"(",
"$",
"groupe_id",
")",
";",
"$",
"groupe",
"->",
"arrets",
"(",
")",
"->",
"sync",
"(",
"$",
"arrets",
")",
";",
"print_r",
"(",
"$",
"groupe",
")",
";",
"}"
] | Sorting bloc newsletter
POST remove
AJAX
@return Response | [
"Sorting",
"bloc",
"newsletter",
"POST",
"remove",
"AJAX"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/ContentController.php#L110-L126 |
surebert/surebert-framework | src/sb/PDO/Mysql/Utf8.php | Utf8.convert | public function convert(\PDO $db) {
$this->setMaxExecutionTime(86400);
$this->setMemoryLimit(2000);
//find all the tables in the db
$tables = [];
$sql = "SHOW TABLES";
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$tables = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
}
//loop through the tables and grab the create statements
foreach ($tables as $table) {
$this->log($table, "CONVERTING TABLE");
$sql = "SHOW CREATE TABLE " . $table;
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$create = $stmt->fetchAll(\PDO::FETCH_COLUMN, 1)[0];
$this->log($create . "\n", "ORIGINAL CREATE SQL");
//convert the create statements into utf8 charset
$utf_create = preg_replace("~CHARSET=(.*)~", "CHARSET=utf8", $create);
$this->log($utf_create . "\n", "UTF8 CREATE SQL");
$backup_table = $table . "_backup";
//create table backup
$sql = "CREATE TABLE `" . $backup_table . "` SELECT * FROM `" . $table . "`";
$this->log($sql, "MAKING BACKUP");
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$this->log($backup_table, "BACKUP COMPLETE");
//drop original table
$sql = "DROP TABLE `" . $table . "`";
$this->log($sql, "DROPPING ORIGINAL");
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$this->log($table, "DROPPED ORIGINAL");
//create the UTF8 version of the table
$this->log($table, "CREATING UTF TABLE");
$result = false;
try{
$stmt = $db->prepare($utf_create);
$result = $stmt->execute();
}catch(\PDOException $e){
$this->log($table.': '.print_r($e->getMessage()), "ERROR!!!!!");
}
if ($result) {
$this->log($table, "UTF TABLE CREATED");
//restore the data from the backup table
$sql = "INSERT INTO `" . $table . "` SELECT * FROM `" . $backup_table . "`";
$this->log($backup_table . ' -> ' . $table, "RESTORING");
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$this->log($backup_table . ' -> ' . $table, "RESTORED");
//dropping the backup table
$this->log($backup_table, "DROPPING");
$sql = "DROP TABLE " . $backup_table;
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$this->log($backup_table, "BACKUP DROPPED");
}
}
}
}
}
}
}
} | php | public function convert(\PDO $db) {
$this->setMaxExecutionTime(86400);
$this->setMemoryLimit(2000);
//find all the tables in the db
$tables = [];
$sql = "SHOW TABLES";
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$tables = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
}
//loop through the tables and grab the create statements
foreach ($tables as $table) {
$this->log($table, "CONVERTING TABLE");
$sql = "SHOW CREATE TABLE " . $table;
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$create = $stmt->fetchAll(\PDO::FETCH_COLUMN, 1)[0];
$this->log($create . "\n", "ORIGINAL CREATE SQL");
//convert the create statements into utf8 charset
$utf_create = preg_replace("~CHARSET=(.*)~", "CHARSET=utf8", $create);
$this->log($utf_create . "\n", "UTF8 CREATE SQL");
$backup_table = $table . "_backup";
//create table backup
$sql = "CREATE TABLE `" . $backup_table . "` SELECT * FROM `" . $table . "`";
$this->log($sql, "MAKING BACKUP");
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$this->log($backup_table, "BACKUP COMPLETE");
//drop original table
$sql = "DROP TABLE `" . $table . "`";
$this->log($sql, "DROPPING ORIGINAL");
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$this->log($table, "DROPPED ORIGINAL");
//create the UTF8 version of the table
$this->log($table, "CREATING UTF TABLE");
$result = false;
try{
$stmt = $db->prepare($utf_create);
$result = $stmt->execute();
}catch(\PDOException $e){
$this->log($table.': '.print_r($e->getMessage()), "ERROR!!!!!");
}
if ($result) {
$this->log($table, "UTF TABLE CREATED");
//restore the data from the backup table
$sql = "INSERT INTO `" . $table . "` SELECT * FROM `" . $backup_table . "`";
$this->log($backup_table . ' -> ' . $table, "RESTORING");
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$this->log($backup_table . ' -> ' . $table, "RESTORED");
//dropping the backup table
$this->log($backup_table, "DROPPING");
$sql = "DROP TABLE " . $backup_table;
$stmt = $db->prepare($sql);
$result = $stmt->execute();
if ($result) {
$this->log($backup_table, "BACKUP DROPPED");
}
}
}
}
}
}
}
} | [
"public",
"function",
"convert",
"(",
"\\",
"PDO",
"$",
"db",
")",
"{",
"$",
"this",
"->",
"setMaxExecutionTime",
"(",
"86400",
")",
";",
"$",
"this",
"->",
"setMemoryLimit",
"(",
"2000",
")",
";",
"//find all the tables in the db",
"$",
"tables",
"=",
"[",
"]",
";",
"$",
"sql",
"=",
"\"SHOW TABLES\"",
";",
"$",
"stmt",
"=",
"$",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"tables",
"=",
"$",
"stmt",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
",",
"0",
")",
";",
"}",
"//loop through the tables and grab the create statements",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"table",
",",
"\"CONVERTING TABLE\"",
")",
";",
"$",
"sql",
"=",
"\"SHOW CREATE TABLE \"",
".",
"$",
"table",
";",
"$",
"stmt",
"=",
"$",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"create",
"=",
"$",
"stmt",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
",",
"1",
")",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"log",
"(",
"$",
"create",
".",
"\"\\n\"",
",",
"\"ORIGINAL CREATE SQL\"",
")",
";",
"//convert the create statements into utf8 charset",
"$",
"utf_create",
"=",
"preg_replace",
"(",
"\"~CHARSET=(.*)~\"",
",",
"\"CHARSET=utf8\"",
",",
"$",
"create",
")",
";",
"$",
"this",
"->",
"log",
"(",
"$",
"utf_create",
".",
"\"\\n\"",
",",
"\"UTF8 CREATE SQL\"",
")",
";",
"$",
"backup_table",
"=",
"$",
"table",
".",
"\"_backup\"",
";",
"//create table backup",
"$",
"sql",
"=",
"\"CREATE TABLE `\"",
".",
"$",
"backup_table",
".",
"\"` SELECT * FROM `\"",
".",
"$",
"table",
".",
"\"`\"",
";",
"$",
"this",
"->",
"log",
"(",
"$",
"sql",
",",
"\"MAKING BACKUP\"",
")",
";",
"$",
"stmt",
"=",
"$",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"backup_table",
",",
"\"BACKUP COMPLETE\"",
")",
";",
"//drop original table",
"$",
"sql",
"=",
"\"DROP TABLE `\"",
".",
"$",
"table",
".",
"\"`\"",
";",
"$",
"this",
"->",
"log",
"(",
"$",
"sql",
",",
"\"DROPPING ORIGINAL\"",
")",
";",
"$",
"stmt",
"=",
"$",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"table",
",",
"\"DROPPED ORIGINAL\"",
")",
";",
"//create the UTF8 version of the table",
"$",
"this",
"->",
"log",
"(",
"$",
"table",
",",
"\"CREATING UTF TABLE\"",
")",
";",
"$",
"result",
"=",
"false",
";",
"try",
"{",
"$",
"stmt",
"=",
"$",
"db",
"->",
"prepare",
"(",
"$",
"utf_create",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"table",
".",
"': '",
".",
"print_r",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"\"ERROR!!!!!\"",
")",
";",
"}",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"table",
",",
"\"UTF TABLE CREATED\"",
")",
";",
"//restore the data from the backup table",
"$",
"sql",
"=",
"\"INSERT INTO `\"",
".",
"$",
"table",
".",
"\"` SELECT * FROM `\"",
".",
"$",
"backup_table",
".",
"\"`\"",
";",
"$",
"this",
"->",
"log",
"(",
"$",
"backup_table",
".",
"' -> '",
".",
"$",
"table",
",",
"\"RESTORING\"",
")",
";",
"$",
"stmt",
"=",
"$",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"backup_table",
".",
"' -> '",
".",
"$",
"table",
",",
"\"RESTORED\"",
")",
";",
"//dropping the backup table",
"$",
"this",
"->",
"log",
"(",
"$",
"backup_table",
",",
"\"DROPPING\"",
")",
";",
"$",
"sql",
"=",
"\"DROP TABLE \"",
".",
"$",
"backup_table",
";",
"$",
"stmt",
"=",
"$",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"backup_table",
",",
"\"BACKUP DROPPED\"",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}"
] | Converts entire db to UTF8, only run once then delete
@servable true | [
"Converts",
"entire",
"db",
"to",
"UTF8",
"only",
"run",
"once",
"then",
"delete"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/PDO/Mysql/Utf8.php#L14-L100 |
ezsystems/ezcomments-ls-extension | datatypes/ezcomcomments/ezcomcommentstype.php | ezcomCommentsType.objectAttributeContent | function objectAttributeContent( $objectAttribute )
{
$ini = eZINI::instance( 'ezcomments.ini' );
$defaultShown = $ini->variable( 'GlobalSettings', 'DefaultShown' );
$defaultEnabled = $ini->variable( 'GlobalSettings', 'DefaultEnabled' );
$showComments = false;
switch ( $objectAttribute->attribute( 'data_float' ) )
{
case 1:
$showComments = true;
break;
case -1:
$showComments = false;
break;
default:
$showComments = $defaultShown === 'true';
break;
}
$enableComment = false;
switch ( $objectAttribute->attribute( 'data_int' ) )
{
case 1:
$enableComment = true;
break;
case -1:
$enableComment = false;
break;
default:
$enableComment = $defaultEnabled === 'true';
break;
}
$result = array(
'show_comments' => $showComments,
'enable_comment' => $enableComment
);
return $result;
} | php | function objectAttributeContent( $objectAttribute )
{
$ini = eZINI::instance( 'ezcomments.ini' );
$defaultShown = $ini->variable( 'GlobalSettings', 'DefaultShown' );
$defaultEnabled = $ini->variable( 'GlobalSettings', 'DefaultEnabled' );
$showComments = false;
switch ( $objectAttribute->attribute( 'data_float' ) )
{
case 1:
$showComments = true;
break;
case -1:
$showComments = false;
break;
default:
$showComments = $defaultShown === 'true';
break;
}
$enableComment = false;
switch ( $objectAttribute->attribute( 'data_int' ) )
{
case 1:
$enableComment = true;
break;
case -1:
$enableComment = false;
break;
default:
$enableComment = $defaultEnabled === 'true';
break;
}
$result = array(
'show_comments' => $showComments,
'enable_comment' => $enableComment
);
return $result;
} | [
"function",
"objectAttributeContent",
"(",
"$",
"objectAttribute",
")",
"{",
"$",
"ini",
"=",
"eZINI",
"::",
"instance",
"(",
"'ezcomments.ini'",
")",
";",
"$",
"defaultShown",
"=",
"$",
"ini",
"->",
"variable",
"(",
"'GlobalSettings'",
",",
"'DefaultShown'",
")",
";",
"$",
"defaultEnabled",
"=",
"$",
"ini",
"->",
"variable",
"(",
"'GlobalSettings'",
",",
"'DefaultEnabled'",
")",
";",
"$",
"showComments",
"=",
"false",
";",
"switch",
"(",
"$",
"objectAttribute",
"->",
"attribute",
"(",
"'data_float'",
")",
")",
"{",
"case",
"1",
":",
"$",
"showComments",
"=",
"true",
";",
"break",
";",
"case",
"-",
"1",
":",
"$",
"showComments",
"=",
"false",
";",
"break",
";",
"default",
":",
"$",
"showComments",
"=",
"$",
"defaultShown",
"===",
"'true'",
";",
"break",
";",
"}",
"$",
"enableComment",
"=",
"false",
";",
"switch",
"(",
"$",
"objectAttribute",
"->",
"attribute",
"(",
"'data_int'",
")",
")",
"{",
"case",
"1",
":",
"$",
"enableComment",
"=",
"true",
";",
"break",
";",
"case",
"-",
"1",
":",
"$",
"enableComment",
"=",
"false",
";",
"break",
";",
"default",
":",
"$",
"enableComment",
"=",
"$",
"defaultEnabled",
"===",
"'true'",
";",
"break",
";",
"}",
"$",
"result",
"=",
"array",
"(",
"'show_comments'",
"=>",
"$",
"showComments",
",",
"'enable_comment'",
"=>",
"$",
"enableComment",
")",
";",
"return",
"$",
"result",
";",
"}"
] | data_float->show comment: 1 to show comment, -1 not to show comment, other value to get default setting
data_int->enable commenting: 1 to show comment, -1 not to show comment, other value to get default setting
@see kernel/classes/eZDataType#objectAttributeContent($objectAttribute) | [
"data_float",
"-",
">",
"show",
"comment",
":",
"1",
"to",
"show",
"comment",
"-",
"1",
"not",
"to",
"show",
"comment",
"other",
"value",
"to",
"get",
"default",
"setting",
"data_int",
"-",
">",
"enable",
"commenting",
":",
"1",
"to",
"show",
"comment",
"-",
"1",
"not",
"to",
"show",
"comment",
"other",
"value",
"to",
"get",
"default",
"setting"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/datatypes/ezcomcomments/ezcomcommentstype.php#L74-L110 |
ezsystems/ezcomments-ls-extension | datatypes/ezcomcomments/ezcomcommentstype.php | ezcomCommentsType.fetchObjectAttributeHTTPInput | function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
$enabledName = $base . '_ezcomcomments_enabled_' . $contentObjectAttribute->attribute( 'id' );
$shownName = $base . '_ezcomcomments_shown_' . $contentObjectAttribute->attribute( 'id' );
$enabledValue = -1;
$shownValue = -1;
if ( $http->hasPostVariable( $enabledName ) )
{
$enabledValue = 1;
}
if ( $http->hasPostVariable( $shownName ) )
{
$shownValue = 1;
}
$contentObjectAttribute->setAttribute( 'data_float', $shownValue );
$contentObjectAttribute->setAttribute( 'data_int', $enabledValue );
return true;
} | php | function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
$enabledName = $base . '_ezcomcomments_enabled_' . $contentObjectAttribute->attribute( 'id' );
$shownName = $base . '_ezcomcomments_shown_' . $contentObjectAttribute->attribute( 'id' );
$enabledValue = -1;
$shownValue = -1;
if ( $http->hasPostVariable( $enabledName ) )
{
$enabledValue = 1;
}
if ( $http->hasPostVariable( $shownName ) )
{
$shownValue = 1;
}
$contentObjectAttribute->setAttribute( 'data_float', $shownValue );
$contentObjectAttribute->setAttribute( 'data_int', $enabledValue );
return true;
} | [
"function",
"fetchObjectAttributeHTTPInput",
"(",
"$",
"http",
",",
"$",
"base",
",",
"$",
"contentObjectAttribute",
")",
"{",
"$",
"enabledName",
"=",
"$",
"base",
".",
"'_ezcomcomments_enabled_'",
".",
"$",
"contentObjectAttribute",
"->",
"attribute",
"(",
"'id'",
")",
";",
"$",
"shownName",
"=",
"$",
"base",
".",
"'_ezcomcomments_shown_'",
".",
"$",
"contentObjectAttribute",
"->",
"attribute",
"(",
"'id'",
")",
";",
"$",
"enabledValue",
"=",
"-",
"1",
";",
"$",
"shownValue",
"=",
"-",
"1",
";",
"if",
"(",
"$",
"http",
"->",
"hasPostVariable",
"(",
"$",
"enabledName",
")",
")",
"{",
"$",
"enabledValue",
"=",
"1",
";",
"}",
"if",
"(",
"$",
"http",
"->",
"hasPostVariable",
"(",
"$",
"shownName",
")",
")",
"{",
"$",
"shownValue",
"=",
"1",
";",
"}",
"$",
"contentObjectAttribute",
"->",
"setAttribute",
"(",
"'data_float'",
",",
"$",
"shownValue",
")",
";",
"$",
"contentObjectAttribute",
"->",
"setAttribute",
"(",
"'data_int'",
",",
"$",
"enabledValue",
")",
";",
"return",
"true",
";",
"}"
] | put the option enabled of ezcomcomment into data_int of contentobjectattribute
@see kernel/classes/eZDataType#fetchObjectAttributeHTTPInput($http, $base, $objectAttribute) | [
"put",
"the",
"option",
"enabled",
"of",
"ezcomcomment",
"into",
"data_int",
"of",
"contentobjectattribute"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/datatypes/ezcomcomments/ezcomcommentstype.php#L117-L134 |
ezsystems/ezcomments-ls-extension | datatypes/ezcomcomments/ezcomcommentstype.php | ezcomCommentsType.deleteStoredObjectAttribute | function deleteStoredObjectAttribute( $contentObjectAttribute, $version = null )
{
$version = $contentObjectAttribute->objectVersion();
if ( !is_null( $version ) &&
$version->attribute( 'status' ) == eZContentObjectVersion::STATUS_PUBLISHED )
{
$contentObjectID = $contentObjectAttribute->attribute( 'contentobject_id' );
$languageID = $contentObjectAttribute->attribute( 'language_id' );
eZPersistentObject::removeObject( ezcomComment::definition(),
array( 'contentobject_id' => $contentObjectID,
'language_id' => $languageID ) );
}
} | php | function deleteStoredObjectAttribute( $contentObjectAttribute, $version = null )
{
$version = $contentObjectAttribute->objectVersion();
if ( !is_null( $version ) &&
$version->attribute( 'status' ) == eZContentObjectVersion::STATUS_PUBLISHED )
{
$contentObjectID = $contentObjectAttribute->attribute( 'contentobject_id' );
$languageID = $contentObjectAttribute->attribute( 'language_id' );
eZPersistentObject::removeObject( ezcomComment::definition(),
array( 'contentobject_id' => $contentObjectID,
'language_id' => $languageID ) );
}
} | [
"function",
"deleteStoredObjectAttribute",
"(",
"$",
"contentObjectAttribute",
",",
"$",
"version",
"=",
"null",
")",
"{",
"$",
"version",
"=",
"$",
"contentObjectAttribute",
"->",
"objectVersion",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"version",
")",
"&&",
"$",
"version",
"->",
"attribute",
"(",
"'status'",
")",
"==",
"eZContentObjectVersion",
"::",
"STATUS_PUBLISHED",
")",
"{",
"$",
"contentObjectID",
"=",
"$",
"contentObjectAttribute",
"->",
"attribute",
"(",
"'contentobject_id'",
")",
";",
"$",
"languageID",
"=",
"$",
"contentObjectAttribute",
"->",
"attribute",
"(",
"'language_id'",
")",
";",
"eZPersistentObject",
"::",
"removeObject",
"(",
"ezcomComment",
"::",
"definition",
"(",
")",
",",
"array",
"(",
"'contentobject_id'",
"=>",
"$",
"contentObjectID",
",",
"'language_id'",
"=>",
"$",
"languageID",
")",
")",
";",
"}",
"}"
] | When deleting the content object, deleting all the comments.
@see kernel/classes/eZDataType#deleteStoredObjectAttribute($objectAttribute, $version) | [
"When",
"deleting",
"the",
"content",
"object",
"deleting",
"all",
"the",
"comments",
"."
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/datatypes/ezcomcomments/ezcomcommentstype.php#L152-L164 |
zhouyl/mellivora | Mellivora/Helper/ProtobufHelper.php | ProtobufHelper.repeatWrapper | public function repeatWrapper($message, array $multiples)
{
$repeated = [];
foreach ($multiples as $array) {
$repeated[] = $this->wrapper($message, $array)->raw();
}
return $repeated;
} | php | public function repeatWrapper($message, array $multiples)
{
$repeated = [];
foreach ($multiples as $array) {
$repeated[] = $this->wrapper($message, $array)->raw();
}
return $repeated;
} | [
"public",
"function",
"repeatWrapper",
"(",
"$",
"message",
",",
"array",
"$",
"multiples",
")",
"{",
"$",
"repeated",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"multiples",
"as",
"$",
"array",
")",
"{",
"$",
"repeated",
"[",
"]",
"=",
"$",
"this",
"->",
"wrapper",
"(",
"$",
"message",
",",
"$",
"array",
")",
"->",
"raw",
"(",
")",
";",
"}",
"return",
"$",
"repeated",
";",
"}"
] | 对 Protobuf repeated 数据进行包裹,并返回数组
@param object|string $message
@param array $multiples
@return array | [
"对",
"Protobuf",
"repeated",
"数据进行包裹,并返回数组"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/ProtobufHelper.php#L46-L54 |
snapwp/snap-blade | src/Blade_Service_Provider.php | Blade_Service_Provider.register | public function register()
{
$this->add_config_location(\realpath(__DIR__ . '/../config'));
$this->add_blade();
Container::add(
Blade_Strategy::class,
function (\Snap\Core\Container $container) {
return $container->resolve(Blade_Strategy::class);
}
);
Container::remove(Standard_Strategy::class);
Container::remove(Partial::class);
// Bind blade strategy as the current Templating engine.
Container::bind(Blade_Strategy::class, Templating_Interface::class);
$this->publishes_config(\realpath(__DIR__ . '/../config'));
$this->publishes_directory(
\realpath(__DIR__ . '/../templates'),
Config::get('theme.templates_directory')
);
} | php | public function register()
{
$this->add_config_location(\realpath(__DIR__ . '/../config'));
$this->add_blade();
Container::add(
Blade_Strategy::class,
function (\Snap\Core\Container $container) {
return $container->resolve(Blade_Strategy::class);
}
);
Container::remove(Standard_Strategy::class);
Container::remove(Partial::class);
// Bind blade strategy as the current Templating engine.
Container::bind(Blade_Strategy::class, Templating_Interface::class);
$this->publishes_config(\realpath(__DIR__ . '/../config'));
$this->publishes_directory(
\realpath(__DIR__ . '/../templates'),
Config::get('theme.templates_directory')
);
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"add_config_location",
"(",
"\\",
"realpath",
"(",
"__DIR__",
".",
"'/../config'",
")",
")",
";",
"$",
"this",
"->",
"add_blade",
"(",
")",
";",
"Container",
"::",
"add",
"(",
"Blade_Strategy",
"::",
"class",
",",
"function",
"(",
"\\",
"Snap",
"\\",
"Core",
"\\",
"Container",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"->",
"resolve",
"(",
"Blade_Strategy",
"::",
"class",
")",
";",
"}",
")",
";",
"Container",
"::",
"remove",
"(",
"Standard_Strategy",
"::",
"class",
")",
";",
"Container",
"::",
"remove",
"(",
"Partial",
"::",
"class",
")",
";",
"// Bind blade strategy as the current Templating engine.",
"Container",
"::",
"bind",
"(",
"Blade_Strategy",
"::",
"class",
",",
"Templating_Interface",
"::",
"class",
")",
";",
"$",
"this",
"->",
"publishes_config",
"(",
"\\",
"realpath",
"(",
"__DIR__",
".",
"'/../config'",
")",
")",
";",
"$",
"this",
"->",
"publishes_directory",
"(",
"\\",
"realpath",
"(",
"__DIR__",
".",
"'/../templates'",
")",
",",
"Config",
"::",
"get",
"(",
"'theme.templates_directory'",
")",
")",
";",
"}"
] | Register the Service.
@since 1.0.0 | [
"Register",
"the",
"Service",
"."
] | train | https://github.com/snapwp/snap-blade/blob/41e004e93440f6b58638b64dc8d20cca4a0546fa/src/Blade_Service_Provider.php#L26-L51 |
snapwp/snap-blade | src/Blade_Service_Provider.php | Blade_Service_Provider.add_blade | public function add_blade()
{
$blade = new Snap_Blade(
Theme_Utils::get_active_theme_path(Config::get('theme.templates_directory')),
Theme_Utils::get_active_theme_path(\trailingslashit(Config::get('theme.cache_directory')) . 'templates'),
Config::get('blade.development_mode') ? BladeOne::MODE_SLOW : BladeOne::MODE_FAST
);
if (Config::get('blade.file_extension') !== $blade->getFileExtension()) {
$blade->setFileExtension(Config::get('blade.file_extension'));
}
// Set the @inject directive to resolve from the service container.
$blade->setInjectResolver(
function ($namespace) {
return Container::get($namespace);
}
);
$this->set_auth_callbacks($blade);
$this->add_directives($blade);
$this->add_wp_directives($blade);
Container::add_instance($blade);
Container::alias(Snap_Blade::class, 'blade');
} | php | public function add_blade()
{
$blade = new Snap_Blade(
Theme_Utils::get_active_theme_path(Config::get('theme.templates_directory')),
Theme_Utils::get_active_theme_path(\trailingslashit(Config::get('theme.cache_directory')) . 'templates'),
Config::get('blade.development_mode') ? BladeOne::MODE_SLOW : BladeOne::MODE_FAST
);
if (Config::get('blade.file_extension') !== $blade->getFileExtension()) {
$blade->setFileExtension(Config::get('blade.file_extension'));
}
// Set the @inject directive to resolve from the service container.
$blade->setInjectResolver(
function ($namespace) {
return Container::get($namespace);
}
);
$this->set_auth_callbacks($blade);
$this->add_directives($blade);
$this->add_wp_directives($blade);
Container::add_instance($blade);
Container::alias(Snap_Blade::class, 'blade');
} | [
"public",
"function",
"add_blade",
"(",
")",
"{",
"$",
"blade",
"=",
"new",
"Snap_Blade",
"(",
"Theme_Utils",
"::",
"get_active_theme_path",
"(",
"Config",
"::",
"get",
"(",
"'theme.templates_directory'",
")",
")",
",",
"Theme_Utils",
"::",
"get_active_theme_path",
"(",
"\\",
"trailingslashit",
"(",
"Config",
"::",
"get",
"(",
"'theme.cache_directory'",
")",
")",
".",
"'templates'",
")",
",",
"Config",
"::",
"get",
"(",
"'blade.development_mode'",
")",
"?",
"BladeOne",
"::",
"MODE_SLOW",
":",
"BladeOne",
"::",
"MODE_FAST",
")",
";",
"if",
"(",
"Config",
"::",
"get",
"(",
"'blade.file_extension'",
")",
"!==",
"$",
"blade",
"->",
"getFileExtension",
"(",
")",
")",
"{",
"$",
"blade",
"->",
"setFileExtension",
"(",
"Config",
"::",
"get",
"(",
"'blade.file_extension'",
")",
")",
";",
"}",
"// Set the @inject directive to resolve from the service container.",
"$",
"blade",
"->",
"setInjectResolver",
"(",
"function",
"(",
"$",
"namespace",
")",
"{",
"return",
"Container",
"::",
"get",
"(",
"$",
"namespace",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"set_auth_callbacks",
"(",
"$",
"blade",
")",
";",
"$",
"this",
"->",
"add_directives",
"(",
"$",
"blade",
")",
";",
"$",
"this",
"->",
"add_wp_directives",
"(",
"$",
"blade",
")",
";",
"Container",
"::",
"add_instance",
"(",
"$",
"blade",
")",
";",
"Container",
"::",
"alias",
"(",
"Snap_Blade",
"::",
"class",
",",
"'blade'",
")",
";",
"}"
] | Creates the Snap_blade instance, and adds to service container.
@since 1.0.0 | [
"Creates",
"the",
"Snap_blade",
"instance",
"and",
"adds",
"to",
"service",
"container",
"."
] | train | https://github.com/snapwp/snap-blade/blob/41e004e93440f6b58638b64dc8d20cca4a0546fa/src/Blade_Service_Provider.php#L58-L85 |
snapwp/snap-blade | src/Blade_Service_Provider.php | Blade_Service_Provider.set_auth_callbacks | private function set_auth_callbacks($blade)
{
// Set the current user.
if (\is_user_logged_in()) {
$current_user = \wp_get_current_user();
$blade->setAuth($current_user->data->display_name, User_Utils::get_user_role()->name);
}
// Set the @can directive.
$blade->setCanFunction(
function ($action = null, $subject = null) {
if ($subject === null) {
return \current_user_can($action);
}
return \user_can($subject, $action);
}
);
// Set the @canany directive.
$blade->setAnyFunction(
function ($array = []) {
foreach ($array as $permission) {
if (\current_user_can($permission)) {
return true;
}
}
return false;
}
);
} | php | private function set_auth_callbacks($blade)
{
// Set the current user.
if (\is_user_logged_in()) {
$current_user = \wp_get_current_user();
$blade->setAuth($current_user->data->display_name, User_Utils::get_user_role()->name);
}
// Set the @can directive.
$blade->setCanFunction(
function ($action = null, $subject = null) {
if ($subject === null) {
return \current_user_can($action);
}
return \user_can($subject, $action);
}
);
// Set the @canany directive.
$blade->setAnyFunction(
function ($array = []) {
foreach ($array as $permission) {
if (\current_user_can($permission)) {
return true;
}
}
return false;
}
);
} | [
"private",
"function",
"set_auth_callbacks",
"(",
"$",
"blade",
")",
"{",
"// Set the current user.",
"if",
"(",
"\\",
"is_user_logged_in",
"(",
")",
")",
"{",
"$",
"current_user",
"=",
"\\",
"wp_get_current_user",
"(",
")",
";",
"$",
"blade",
"->",
"setAuth",
"(",
"$",
"current_user",
"->",
"data",
"->",
"display_name",
",",
"User_Utils",
"::",
"get_user_role",
"(",
")",
"->",
"name",
")",
";",
"}",
"// Set the @can directive.",
"$",
"blade",
"->",
"setCanFunction",
"(",
"function",
"(",
"$",
"action",
"=",
"null",
",",
"$",
"subject",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"subject",
"===",
"null",
")",
"{",
"return",
"\\",
"current_user_can",
"(",
"$",
"action",
")",
";",
"}",
"return",
"\\",
"user_can",
"(",
"$",
"subject",
",",
"$",
"action",
")",
";",
"}",
")",
";",
"// Set the @canany directive.",
"$",
"blade",
"->",
"setAnyFunction",
"(",
"function",
"(",
"$",
"array",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"permission",
")",
"{",
"if",
"(",
"\\",
"current_user_can",
"(",
"$",
"permission",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
")",
";",
"}"
] | Sets the authentication and can/cannot functionality.
@since 1.0.0
@param BladeOne $blade The BladeOne service. | [
"Sets",
"the",
"authentication",
"and",
"can",
"/",
"cannot",
"functionality",
"."
] | train | https://github.com/snapwp/snap-blade/blob/41e004e93440f6b58638b64dc8d20cca4a0546fa/src/Blade_Service_Provider.php#L94-L125 |
snapwp/snap-blade | src/Blade_Service_Provider.php | Blade_Service_Provider.add_directives | private function add_directives($blade)
{
$blade->directive(
'simplemenu',
function ($expression) {
\preg_match('/\( *(.*) * as *([^\)]*)/', $expression, $matches);
$iteratee = \trim($matches[1]);
$iteration = \trim($matches[2]);
$init_loop = "\$__currentLoopData = \Snap\Utils\Menu_Utils::get_nav_menu($iteratee);
\$this->addLoop(\$__currentLoopData);";
$iterate_loop = '$this->incrementLoopIndices();
$loop = $this->getFirstLoop();';
return "<?php {$init_loop} foreach(\$__currentLoopData as {$iteration}): {$iterate_loop} ?>";
}
);
$blade->directive(
'endsimplemenu',
function () {
return '<?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>';
}
);
$blade->directive(
'partial',
function ($input) {
$input = $this->trim_input($input);
$input = \str_replace('partials.\'', 'partials.', '\'partials.' . $input);
return '<?php echo $this->runChild('.$input.'); ?>';
}
);
$blade->directive(
'posttypepartial',
function () {
return '<?php global $post; echo $this->runChild(\'partials.post-type.\' . \get_post_type(), [\'post\' => $post]); ?>';
}
);
$blade->directive(
'paginate',
function ($input = []) {
$input = $input ?? '[]';
return '
<?php
$pagination = \Snap\Services\Container::resolve(
\Snap\Templating\Pagination::class,
[
\'args\' => ' . $this->trim_input($input) .',
]
);
echo $pagination->get();
?>';
}
);
$blade->directive(
'loop',
function ($input) {
$input = $this->trim_input($input);
$init_loop = '$__loop_query = $wp_query;';
if (! empty($input)) {
$init_loop = '$__loop_query = ' . $input . ';';
}
$init_loop .= '$__currentLoopData = $__loop_query->posts;
$this->addLoop($__currentLoopData);
global $post;';
$iterate_loop = '$this->incrementLoopIndices(); $loop = $this->getFirstLoop();';
return "<?php {$init_loop} while (\$__loop_query->have_posts()):
\$__loop_query->the_post(); {$iterate_loop} ?>";
}
);
$blade->directive(
'endloop',
function () {
return '<?php endwhile; ?>';
}
);
} | php | private function add_directives($blade)
{
$blade->directive(
'simplemenu',
function ($expression) {
\preg_match('/\( *(.*) * as *([^\)]*)/', $expression, $matches);
$iteratee = \trim($matches[1]);
$iteration = \trim($matches[2]);
$init_loop = "\$__currentLoopData = \Snap\Utils\Menu_Utils::get_nav_menu($iteratee);
\$this->addLoop(\$__currentLoopData);";
$iterate_loop = '$this->incrementLoopIndices();
$loop = $this->getFirstLoop();';
return "<?php {$init_loop} foreach(\$__currentLoopData as {$iteration}): {$iterate_loop} ?>";
}
);
$blade->directive(
'endsimplemenu',
function () {
return '<?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>';
}
);
$blade->directive(
'partial',
function ($input) {
$input = $this->trim_input($input);
$input = \str_replace('partials.\'', 'partials.', '\'partials.' . $input);
return '<?php echo $this->runChild('.$input.'); ?>';
}
);
$blade->directive(
'posttypepartial',
function () {
return '<?php global $post; echo $this->runChild(\'partials.post-type.\' . \get_post_type(), [\'post\' => $post]); ?>';
}
);
$blade->directive(
'paginate',
function ($input = []) {
$input = $input ?? '[]';
return '
<?php
$pagination = \Snap\Services\Container::resolve(
\Snap\Templating\Pagination::class,
[
\'args\' => ' . $this->trim_input($input) .',
]
);
echo $pagination->get();
?>';
}
);
$blade->directive(
'loop',
function ($input) {
$input = $this->trim_input($input);
$init_loop = '$__loop_query = $wp_query;';
if (! empty($input)) {
$init_loop = '$__loop_query = ' . $input . ';';
}
$init_loop .= '$__currentLoopData = $__loop_query->posts;
$this->addLoop($__currentLoopData);
global $post;';
$iterate_loop = '$this->incrementLoopIndices(); $loop = $this->getFirstLoop();';
return "<?php {$init_loop} while (\$__loop_query->have_posts()):
\$__loop_query->the_post(); {$iterate_loop} ?>";
}
);
$blade->directive(
'endloop',
function () {
return '<?php endwhile; ?>';
}
);
} | [
"private",
"function",
"add_directives",
"(",
"$",
"blade",
")",
"{",
"$",
"blade",
"->",
"directive",
"(",
"'simplemenu'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"\\",
"preg_match",
"(",
"'/\\( *(.*) * as *([^\\)]*)/'",
",",
"$",
"expression",
",",
"$",
"matches",
")",
";",
"$",
"iteratee",
"=",
"\\",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"$",
"iteration",
"=",
"\\",
"trim",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"$",
"init_loop",
"=",
"\"\\$__currentLoopData = \\Snap\\Utils\\Menu_Utils::get_nav_menu($iteratee); \n \\$this->addLoop(\\$__currentLoopData);\"",
";",
"$",
"iterate_loop",
"=",
"'$this->incrementLoopIndices(); \n $loop = $this->getFirstLoop();'",
";",
"return",
"\"<?php {$init_loop} foreach(\\$__currentLoopData as {$iteration}): {$iterate_loop} ?>\"",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'endsimplemenu'",
",",
"function",
"(",
")",
"{",
"return",
"'<?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>'",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'partial'",
",",
"function",
"(",
"$",
"input",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"trim_input",
"(",
"$",
"input",
")",
";",
"$",
"input",
"=",
"\\",
"str_replace",
"(",
"'partials.\\''",
",",
"'partials.'",
",",
"'\\'partials.'",
".",
"$",
"input",
")",
";",
"return",
"'<?php echo $this->runChild('",
".",
"$",
"input",
".",
"'); ?>'",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'posttypepartial'",
",",
"function",
"(",
")",
"{",
"return",
"'<?php global $post; echo $this->runChild(\\'partials.post-type.\\' . \\get_post_type(), [\\'post\\' => $post]); ?>'",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'paginate'",
",",
"function",
"(",
"$",
"input",
"=",
"[",
"]",
")",
"{",
"$",
"input",
"=",
"$",
"input",
"??",
"'[]'",
";",
"return",
"'\n\t\t\t<?php\n\t\t\t$pagination = \\Snap\\Services\\Container::resolve(\n\t \\Snap\\Templating\\Pagination::class,\n\t [\n\t \\'args\\' => '",
".",
"$",
"this",
"->",
"trim_input",
"(",
"$",
"input",
")",
".",
"',\n\t ]\n\t );\n\n\t echo $pagination->get();\n\t ?>'",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'loop'",
",",
"function",
"(",
"$",
"input",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"trim_input",
"(",
"$",
"input",
")",
";",
"$",
"init_loop",
"=",
"'$__loop_query = $wp_query;'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"input",
")",
")",
"{",
"$",
"init_loop",
"=",
"'$__loop_query = '",
".",
"$",
"input",
".",
"';'",
";",
"}",
"$",
"init_loop",
".=",
"'$__currentLoopData = $__loop_query->posts; \n $this->addLoop($__currentLoopData); \n global $post;'",
";",
"$",
"iterate_loop",
"=",
"'$this->incrementLoopIndices(); $loop = $this->getFirstLoop();'",
";",
"return",
"\"<?php {$init_loop} while (\\$__loop_query->have_posts()): \n \\$__loop_query->the_post(); {$iterate_loop} ?>\"",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'endloop'",
",",
"function",
"(",
")",
"{",
"return",
"'<?php endwhile; ?>'",
";",
"}",
")",
";",
"}"
] | Add custom directives to blade.
@since 1.0.0
@param BladeOne $blade The BladeOne service. | [
"Add",
"custom",
"directives",
"to",
"blade",
"."
] | train | https://github.com/snapwp/snap-blade/blob/41e004e93440f6b58638b64dc8d20cca4a0546fa/src/Blade_Service_Provider.php#L134-L225 |
snapwp/snap-blade | src/Blade_Service_Provider.php | Blade_Service_Provider.add_wp_directives | private function add_wp_directives($blade)
{
$blade->directive(
'wphead',
function () {
return '<?php wp_head(); ?>';
}
);
$blade->directive(
'wpfooter',
function () {
return '<?php wp_footer(); ?>';
}
);
$blade->directive(
'sidebar',
function ($input) {
return "<?php dynamic_sidebar({$this->trim_input($input)}); ?>";
}
);
$blade->directive(
'action',
function ($input) {
return "<?php do_action({$this->trim_input($input)}); ?>";
}
);
$blade->directive(
'thecontent',
function () {
return "<?php the_content(); ?>";
}
);
$blade->directive(
'theexcerpt',
function () {
return "<?php the_excerpt(); ?>";
}
);
$blade->directive(
'navmenu',
function ($input) {
return "<?php wp_nav_menu({$this->trim_input($input)}); ?>";
}
);
$blade->directive(
'searchform',
function () {
return "<?php get_search_form(); ?>";
}
);
$blade->directive(
'setpostdata',
function ($input) {
return '<?php setup_postdata($GLOBALS[\'post\'] =& '. $this->trim_input($input) .'); ?>';
}
);
$blade->directive(
'resetpostdata',
function () {
return '<?php wp_reset_postdata(); ?>';
}
);
} | php | private function add_wp_directives($blade)
{
$blade->directive(
'wphead',
function () {
return '<?php wp_head(); ?>';
}
);
$blade->directive(
'wpfooter',
function () {
return '<?php wp_footer(); ?>';
}
);
$blade->directive(
'sidebar',
function ($input) {
return "<?php dynamic_sidebar({$this->trim_input($input)}); ?>";
}
);
$blade->directive(
'action',
function ($input) {
return "<?php do_action({$this->trim_input($input)}); ?>";
}
);
$blade->directive(
'thecontent',
function () {
return "<?php the_content(); ?>";
}
);
$blade->directive(
'theexcerpt',
function () {
return "<?php the_excerpt(); ?>";
}
);
$blade->directive(
'navmenu',
function ($input) {
return "<?php wp_nav_menu({$this->trim_input($input)}); ?>";
}
);
$blade->directive(
'searchform',
function () {
return "<?php get_search_form(); ?>";
}
);
$blade->directive(
'setpostdata',
function ($input) {
return '<?php setup_postdata($GLOBALS[\'post\'] =& '. $this->trim_input($input) .'); ?>';
}
);
$blade->directive(
'resetpostdata',
function () {
return '<?php wp_reset_postdata(); ?>';
}
);
} | [
"private",
"function",
"add_wp_directives",
"(",
"$",
"blade",
")",
"{",
"$",
"blade",
"->",
"directive",
"(",
"'wphead'",
",",
"function",
"(",
")",
"{",
"return",
"'<?php wp_head(); ?>'",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'wpfooter'",
",",
"function",
"(",
")",
"{",
"return",
"'<?php wp_footer(); ?>'",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'sidebar'",
",",
"function",
"(",
"$",
"input",
")",
"{",
"return",
"\"<?php dynamic_sidebar({$this->trim_input($input)}); ?>\"",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'action'",
",",
"function",
"(",
"$",
"input",
")",
"{",
"return",
"\"<?php do_action({$this->trim_input($input)}); ?>\"",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'thecontent'",
",",
"function",
"(",
")",
"{",
"return",
"\"<?php the_content(); ?>\"",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'theexcerpt'",
",",
"function",
"(",
")",
"{",
"return",
"\"<?php the_excerpt(); ?>\"",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'navmenu'",
",",
"function",
"(",
"$",
"input",
")",
"{",
"return",
"\"<?php wp_nav_menu({$this->trim_input($input)}); ?>\"",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'searchform'",
",",
"function",
"(",
")",
"{",
"return",
"\"<?php get_search_form(); ?>\"",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'setpostdata'",
",",
"function",
"(",
"$",
"input",
")",
"{",
"return",
"'<?php setup_postdata($GLOBALS[\\'post\\'] =& '",
".",
"$",
"this",
"->",
"trim_input",
"(",
"$",
"input",
")",
".",
"'); ?>'",
";",
"}",
")",
";",
"$",
"blade",
"->",
"directive",
"(",
"'resetpostdata'",
",",
"function",
"(",
")",
"{",
"return",
"'<?php wp_reset_postdata(); ?>'",
";",
"}",
")",
";",
"}"
] | Add custom directives for WordPress functions to blade.
@since 1.0.0
@param BladeOne $blade The BladeOne service. | [
"Add",
"custom",
"directives",
"for",
"WordPress",
"functions",
"to",
"blade",
"."
] | train | https://github.com/snapwp/snap-blade/blob/41e004e93440f6b58638b64dc8d20cca4a0546fa/src/Blade_Service_Provider.php#L234-L305 |
NuclearCMS/Hierarchy | src/Repositories/NodeFieldRepository.php | NodeFieldRepository.create | public function create($id, array $attributes)
{
$typeModelName = $this->getTypeModelName();
$nodeType = $typeModelName::findOrFail($id);
$nodeField = $nodeType->addField($attributes);
$this->builderService->buildField(
$nodeField->getName(),
$nodeField->getType(),
$nodeField->isIndexed(),
$nodeType->getName(),
$nodeType
);
return $nodeField;
} | php | public function create($id, array $attributes)
{
$typeModelName = $this->getTypeModelName();
$nodeType = $typeModelName::findOrFail($id);
$nodeField = $nodeType->addField($attributes);
$this->builderService->buildField(
$nodeField->getName(),
$nodeField->getType(),
$nodeField->isIndexed(),
$nodeType->getName(),
$nodeType
);
return $nodeField;
} | [
"public",
"function",
"create",
"(",
"$",
"id",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"typeModelName",
"=",
"$",
"this",
"->",
"getTypeModelName",
"(",
")",
";",
"$",
"nodeType",
"=",
"$",
"typeModelName",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"nodeField",
"=",
"$",
"nodeType",
"->",
"addField",
"(",
"$",
"attributes",
")",
";",
"$",
"this",
"->",
"builderService",
"->",
"buildField",
"(",
"$",
"nodeField",
"->",
"getName",
"(",
")",
",",
"$",
"nodeField",
"->",
"getType",
"(",
")",
",",
"$",
"nodeField",
"->",
"isIndexed",
"(",
")",
",",
"$",
"nodeType",
"->",
"getName",
"(",
")",
",",
"$",
"nodeType",
")",
";",
"return",
"$",
"nodeField",
";",
"}"
] | Creates a node field
@param int $id
@param array $attributes
@return NodeFieldContract | [
"Creates",
"a",
"node",
"field"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Repositories/NodeFieldRepository.php#L15-L32 |
NuclearCMS/Hierarchy | src/Repositories/NodeFieldRepository.php | NodeFieldRepository.destroy | public function destroy($id)
{
$modelName = $this->getModelName();
$nodeField = $modelName::findOrFail($id);
$nodeField->delete();
$this->builderService->destroyField(
$nodeField->getName(),
$nodeField->nodeType->getName(),
$nodeField->nodeType
);
return $nodeField;
} | php | public function destroy($id)
{
$modelName = $this->getModelName();
$nodeField = $modelName::findOrFail($id);
$nodeField->delete();
$this->builderService->destroyField(
$nodeField->getName(),
$nodeField->nodeType->getName(),
$nodeField->nodeType
);
return $nodeField;
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"$",
"modelName",
"=",
"$",
"this",
"->",
"getModelName",
"(",
")",
";",
"$",
"nodeField",
"=",
"$",
"modelName",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"nodeField",
"->",
"delete",
"(",
")",
";",
"$",
"this",
"->",
"builderService",
"->",
"destroyField",
"(",
"$",
"nodeField",
"->",
"getName",
"(",
")",
",",
"$",
"nodeField",
"->",
"nodeType",
"->",
"getName",
"(",
")",
",",
"$",
"nodeField",
"->",
"nodeType",
")",
";",
"return",
"$",
"nodeField",
";",
"}"
] | Destroys a node field
@param int $id
@return NodeFieldContract | [
"Destroys",
"a",
"node",
"field"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Repositories/NodeFieldRepository.php#L40-L54 |
zicht/z | src/Zicht/Tool/Command/Descriptor/TextDescriptor.php | TextDescriptor.describeCommand | protected function describeCommand(Command $command, array $options = array())
{
list($public, $internal) = $this->splitDefinition($command->getNativeDefinition());
$synopsis = new Command($command->getName());
$synopsis->setDefinition($public);
$this->writeText('<comment>Usage:</comment>', $options);
$this->writeText("\n");
$this->writeText(' ' . $synopsis->getSynopsis(), $options);
$this->writeText("\n");
if (count($command->getAliases()) > 0) {
$this->writeText("\n");
$this->writeText('<comment>Aliases:</comment> <info>' . implode(', ', $command->getAliases()) . '</info>', $options);
}
$this->writeText("\n");
$this->describeInputDefinition($public, $options);
if (count($internal->getOptions())) {
$this->writeText("\n\n" . '<comment>Global options:</comment>' . "\n");
$this->writeText(' Following global options are available for all task commands:');
$this->writeText(' ' . join(', ', array_map(function ($o) { return $o->getName(); }, $internal->getOptions())));
$this->writeText(' Read the application help for more info' . "\n");
}
$this->writeText("\n");
if ($help = $command->getProcessedHelp()) {
$this->writeText('<comment>Help:</comment>', $options);
$this->writeText("\n");
$this->writeText(' ' . str_replace("\n", "\n ", $help), $options);
$this->writeText("\n");
}
$this->writeText("\n");
} | php | protected function describeCommand(Command $command, array $options = array())
{
list($public, $internal) = $this->splitDefinition($command->getNativeDefinition());
$synopsis = new Command($command->getName());
$synopsis->setDefinition($public);
$this->writeText('<comment>Usage:</comment>', $options);
$this->writeText("\n");
$this->writeText(' ' . $synopsis->getSynopsis(), $options);
$this->writeText("\n");
if (count($command->getAliases()) > 0) {
$this->writeText("\n");
$this->writeText('<comment>Aliases:</comment> <info>' . implode(', ', $command->getAliases()) . '</info>', $options);
}
$this->writeText("\n");
$this->describeInputDefinition($public, $options);
if (count($internal->getOptions())) {
$this->writeText("\n\n" . '<comment>Global options:</comment>' . "\n");
$this->writeText(' Following global options are available for all task commands:');
$this->writeText(' ' . join(', ', array_map(function ($o) { return $o->getName(); }, $internal->getOptions())));
$this->writeText(' Read the application help for more info' . "\n");
}
$this->writeText("\n");
if ($help = $command->getProcessedHelp()) {
$this->writeText('<comment>Help:</comment>', $options);
$this->writeText("\n");
$this->writeText(' ' . str_replace("\n", "\n ", $help), $options);
$this->writeText("\n");
}
$this->writeText("\n");
} | [
"protected",
"function",
"describeCommand",
"(",
"Command",
"$",
"command",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"public",
",",
"$",
"internal",
")",
"=",
"$",
"this",
"->",
"splitDefinition",
"(",
"$",
"command",
"->",
"getNativeDefinition",
"(",
")",
")",
";",
"$",
"synopsis",
"=",
"new",
"Command",
"(",
"$",
"command",
"->",
"getName",
"(",
")",
")",
";",
"$",
"synopsis",
"->",
"setDefinition",
"(",
"$",
"public",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"'<comment>Usage:</comment>'",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\"",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"' '",
".",
"$",
"synopsis",
"->",
"getSynopsis",
"(",
")",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\"",
")",
";",
"if",
"(",
"count",
"(",
"$",
"command",
"->",
"getAliases",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\"",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"'<comment>Aliases:</comment> <info>'",
".",
"implode",
"(",
"', '",
",",
"$",
"command",
"->",
"getAliases",
"(",
")",
")",
".",
"'</info>'",
",",
"$",
"options",
")",
";",
"}",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\"",
")",
";",
"$",
"this",
"->",
"describeInputDefinition",
"(",
"$",
"public",
",",
"$",
"options",
")",
";",
"if",
"(",
"count",
"(",
"$",
"internal",
"->",
"getOptions",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\\n\"",
".",
"'<comment>Global options:</comment>'",
".",
"\"\\n\"",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"' Following global options are available for all task commands:'",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"' '",
".",
"join",
"(",
"', '",
",",
"array_map",
"(",
"function",
"(",
"$",
"o",
")",
"{",
"return",
"$",
"o",
"->",
"getName",
"(",
")",
";",
"}",
",",
"$",
"internal",
"->",
"getOptions",
"(",
")",
")",
")",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"' Read the application help for more info'",
".",
"\"\\n\"",
")",
";",
"}",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\"",
")",
";",
"if",
"(",
"$",
"help",
"=",
"$",
"command",
"->",
"getProcessedHelp",
"(",
")",
")",
"{",
"$",
"this",
"->",
"writeText",
"(",
"'<comment>Help:</comment>'",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\"",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"' '",
".",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\\n \"",
",",
"$",
"help",
")",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\"",
")",
";",
"}",
"$",
"this",
"->",
"writeText",
"(",
"\"\\n\"",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Command/Descriptor/TextDescriptor.php#L30-L65 |
zicht/z | src/Zicht/Tool/Command/Descriptor/TextDescriptor.php | TextDescriptor.splitDefinition | public function splitDefinition(InputDefinition $definition)
{
/** @var InputDefinition[] $ret */
$ret = array(
new InputDefinition(),
new InputDefinition()
);
foreach ($definition->getArguments() as $arg) {
$ret[0]->addArgument($arg);
$ret[1]->addArgument($arg);
}
foreach ($definition->getOptions() as $opt) {
$ret[$this->isHiddenOption($opt) ? 1 : 0]->addOption($opt);
}
return $ret;
} | php | public function splitDefinition(InputDefinition $definition)
{
/** @var InputDefinition[] $ret */
$ret = array(
new InputDefinition(),
new InputDefinition()
);
foreach ($definition->getArguments() as $arg) {
$ret[0]->addArgument($arg);
$ret[1]->addArgument($arg);
}
foreach ($definition->getOptions() as $opt) {
$ret[$this->isHiddenOption($opt) ? 1 : 0]->addOption($opt);
}
return $ret;
} | [
"public",
"function",
"splitDefinition",
"(",
"InputDefinition",
"$",
"definition",
")",
"{",
"/** @var InputDefinition[] $ret */",
"$",
"ret",
"=",
"array",
"(",
"new",
"InputDefinition",
"(",
")",
",",
"new",
"InputDefinition",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"definition",
"->",
"getArguments",
"(",
")",
"as",
"$",
"arg",
")",
"{",
"$",
"ret",
"[",
"0",
"]",
"->",
"addArgument",
"(",
"$",
"arg",
")",
";",
"$",
"ret",
"[",
"1",
"]",
"->",
"addArgument",
"(",
"$",
"arg",
")",
";",
"}",
"foreach",
"(",
"$",
"definition",
"->",
"getOptions",
"(",
")",
"as",
"$",
"opt",
")",
"{",
"$",
"ret",
"[",
"$",
"this",
"->",
"isHiddenOption",
"(",
"$",
"opt",
")",
"?",
"1",
":",
"0",
"]",
"->",
"addOption",
"(",
"$",
"opt",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Splits the definition in an internal and public one, the latter representing whatever is shown to the user,
the former representing the options that are hidden.
@param \Symfony\Component\Console\Input\InputDefinition $definition
@return InputDefinition[] | [
"Splits",
"the",
"definition",
"in",
"an",
"internal",
"and",
"public",
"one",
"the",
"latter",
"representing",
"whatever",
"is",
"shown",
"to",
"the",
"user",
"the",
"former",
"representing",
"the",
"options",
"that",
"are",
"hidden",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Command/Descriptor/TextDescriptor.php#L74-L90 |
Isset/pushnotification | src/PushNotification/Core/Message/MessageEnvelopeQueueImpl.php | MessageEnvelopeQueueImpl.split | public function split($identifier): MessageEnvelopeQueue
{
$return = new self();
$items = $this->queue;
$this->clear();
$currentQueue = $return;
foreach ($items as $item) {
$currentQueue->add($item);
if ($item->getMessage()->getIdentifier() === $identifier) {
$currentQueue = $this;
}
}
return $return;
} | php | public function split($identifier): MessageEnvelopeQueue
{
$return = new self();
$items = $this->queue;
$this->clear();
$currentQueue = $return;
foreach ($items as $item) {
$currentQueue->add($item);
if ($item->getMessage()->getIdentifier() === $identifier) {
$currentQueue = $this;
}
}
return $return;
} | [
"public",
"function",
"split",
"(",
"$",
"identifier",
")",
":",
"MessageEnvelopeQueue",
"{",
"$",
"return",
"=",
"new",
"self",
"(",
")",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"queue",
";",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"currentQueue",
"=",
"$",
"return",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"currentQueue",
"->",
"add",
"(",
"$",
"item",
")",
";",
"if",
"(",
"$",
"item",
"->",
"getMessage",
"(",
")",
"->",
"getIdentifier",
"(",
")",
"===",
"$",
"identifier",
")",
"{",
"$",
"currentQueue",
"=",
"$",
"this",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | @param string $identifier
@throws LogicException
@return MessageEnvelopeQueue | [
"@param",
"string",
"$identifier"
] | train | https://github.com/Isset/pushnotification/blob/5e7634dc6b1cf4f7c371d1890243a25252db0d85/src/PushNotification/Core/Message/MessageEnvelopeQueueImpl.php#L45-L59 |
Isset/pushnotification | src/PushNotification/Core/Message/MessageEnvelopeQueueImpl.php | MessageEnvelopeQueueImpl.remove | public function remove($identifier): Option
{
foreach ($this->queue as $key => $item) {
if ($item->getMessage()->getIdentifier() === $identifier) {
unset($this->queue[$key]);
return Option::fromValue($item);
}
}
return None::create();
} | php | public function remove($identifier): Option
{
foreach ($this->queue as $key => $item) {
if ($item->getMessage()->getIdentifier() === $identifier) {
unset($this->queue[$key]);
return Option::fromValue($item);
}
}
return None::create();
} | [
"public",
"function",
"remove",
"(",
"$",
"identifier",
")",
":",
"Option",
"{",
"foreach",
"(",
"$",
"this",
"->",
"queue",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getMessage",
"(",
")",
"->",
"getIdentifier",
"(",
")",
"===",
"$",
"identifier",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"key",
"]",
")",
";",
"return",
"Option",
"::",
"fromValue",
"(",
"$",
"item",
")",
";",
"}",
"}",
"return",
"None",
"::",
"create",
"(",
")",
";",
"}"
] | @param $identifier
@return Option<MessageEnvelope> | [
"@param",
"$identifier"
] | train | https://github.com/Isset/pushnotification/blob/5e7634dc6b1cf4f7c371d1890243a25252db0d85/src/PushNotification/Core/Message/MessageEnvelopeQueueImpl.php#L92-L103 |
Isset/pushnotification | src/PushNotification/Core/Message/MessageEnvelopeQueueImpl.php | MessageEnvelopeQueueImpl.has | public function has($identifier): bool
{
foreach ($this->queue as $item) {
if ($item->getMessage()->getIdentifier() === $identifier) {
return true;
}
}
return false;
} | php | public function has($identifier): bool
{
foreach ($this->queue as $item) {
if ($item->getMessage()->getIdentifier() === $identifier) {
return true;
}
}
return false;
} | [
"public",
"function",
"has",
"(",
"$",
"identifier",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"queue",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getMessage",
"(",
")",
"->",
"getIdentifier",
"(",
")",
"===",
"$",
"identifier",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param $identifier
@return bool | [
"@param",
"$identifier"
] | train | https://github.com/Isset/pushnotification/blob/5e7634dc6b1cf4f7c371d1890243a25252db0d85/src/PushNotification/Core/Message/MessageEnvelopeQueueImpl.php#L110-L119 |
trunda/SmfMenu | src/Smf/Menu/Renderer/Manager.php | Manager.addRenderer | public function addRenderer($name, $renderer, $overwrite = false)
{
if (isset($this->renderers[$name]) && !$overwrite) {
throw new InvalidArgumentException("Renderer with name '$name' is already registered.");
}
unset($this->renderers[$name]);
// Is class? Exists?
if (is_string($renderer) && !class_exists($renderer)) {
throw new InvalidArgumentException("Renderer class '$renderer' doesn't exist.");
}
$this->renderers[$name] = $renderer;
return $this;
} | php | public function addRenderer($name, $renderer, $overwrite = false)
{
if (isset($this->renderers[$name]) && !$overwrite) {
throw new InvalidArgumentException("Renderer with name '$name' is already registered.");
}
unset($this->renderers[$name]);
// Is class? Exists?
if (is_string($renderer) && !class_exists($renderer)) {
throw new InvalidArgumentException("Renderer class '$renderer' doesn't exist.");
}
$this->renderers[$name] = $renderer;
return $this;
} | [
"public",
"function",
"addRenderer",
"(",
"$",
"name",
",",
"$",
"renderer",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"renderers",
"[",
"$",
"name",
"]",
")",
"&&",
"!",
"$",
"overwrite",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Renderer with name '$name' is already registered.\"",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"renderers",
"[",
"$",
"name",
"]",
")",
";",
"// Is class? Exists?",
"if",
"(",
"is_string",
"(",
"$",
"renderer",
")",
"&&",
"!",
"class_exists",
"(",
"$",
"renderer",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Renderer class '$renderer' doesn't exist.\"",
")",
";",
"}",
"$",
"this",
"->",
"renderers",
"[",
"$",
"name",
"]",
"=",
"$",
"renderer",
";",
"return",
"$",
"this",
";",
"}"
] | Ads renderer with given name
@param string $name Name of the renderer
@param string|IRenderer $renderer Renderer class name or instance
@param bool $overwrite Should be overwritten renderer with this name if exists?
@return IManager Fluent interface
@throws InvalidArgumentException If the renderer with given name already exists and $overwrite is false | [
"Ads",
"renderer",
"with",
"given",
"name"
] | train | https://github.com/trunda/SmfMenu/blob/739e74fb664c1f018b4a74142bd28d20c004bac6/src/Smf/Menu/Renderer/Manager.php#L25-L37 |
trunda/SmfMenu | src/Smf/Menu/Renderer/Manager.php | Manager.getRenderer | public function getRenderer($name)
{
// default
if ($name === null) {
if ($this->defaultRenderer !== null) {
$name = $this->defaultRenderer;
} else if (count($this->renderers) > 0) {
$name = key($this->renderers);
}
}
if (!isset($this->renderers[$name])) {
throw new InvalidArgumentException("Renderer with name '$name' doesn't exist.");
}
if (is_string($this->renderers[$name])) {
$renderer = new $this->renderers[$name]();
$reflection = ClassType::from($renderer);
if (!$reflection->isSubclassOf('Smf\Menu\Renderer\IRenderer')) {
throw new InvalidArgumentException("Renderer class '{$this->renderers[$name]}' is not subclass of Smf\\Menu\\Renderer\\IRenderer");
}
$this->renderers[$name] = $renderer;
}
return $this->renderers[$name];
} | php | public function getRenderer($name)
{
// default
if ($name === null) {
if ($this->defaultRenderer !== null) {
$name = $this->defaultRenderer;
} else if (count($this->renderers) > 0) {
$name = key($this->renderers);
}
}
if (!isset($this->renderers[$name])) {
throw new InvalidArgumentException("Renderer with name '$name' doesn't exist.");
}
if (is_string($this->renderers[$name])) {
$renderer = new $this->renderers[$name]();
$reflection = ClassType::from($renderer);
if (!$reflection->isSubclassOf('Smf\Menu\Renderer\IRenderer')) {
throw new InvalidArgumentException("Renderer class '{$this->renderers[$name]}' is not subclass of Smf\\Menu\\Renderer\\IRenderer");
}
$this->renderers[$name] = $renderer;
}
return $this->renderers[$name];
} | [
"public",
"function",
"getRenderer",
"(",
"$",
"name",
")",
"{",
"// default",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"defaultRenderer",
"!==",
"null",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"defaultRenderer",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"renderers",
")",
">",
"0",
")",
"{",
"$",
"name",
"=",
"key",
"(",
"$",
"this",
"->",
"renderers",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"renderers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Renderer with name '$name' doesn't exist.\"",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"renderers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"renderer",
"=",
"new",
"$",
"this",
"->",
"renderers",
"[",
"$",
"name",
"]",
"(",
")",
";",
"$",
"reflection",
"=",
"ClassType",
"::",
"from",
"(",
"$",
"renderer",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isSubclassOf",
"(",
"'Smf\\Menu\\Renderer\\IRenderer'",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Renderer class '{$this->renderers[$name]}' is not subclass of Smf\\\\Menu\\\\Renderer\\\\IRenderer\"",
")",
";",
"}",
"$",
"this",
"->",
"renderers",
"[",
"$",
"name",
"]",
"=",
"$",
"renderer",
";",
"}",
"return",
"$",
"this",
"->",
"renderers",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns instance of the renderer
@param string $name Name of the renderer
@return IRenderer Renderer instance
@throws InvalidArgumentException If the renderer with given name does not exist | [
"Returns",
"instance",
"of",
"the",
"renderer"
] | train | https://github.com/trunda/SmfMenu/blob/739e74fb664c1f018b4a74142bd28d20c004bac6/src/Smf/Menu/Renderer/Manager.php#L59-L84 |
zicht/z | src/Zicht/Tool/Command/DumpCommand.php | DumpCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(Yaml::dump($this->getContainer()->getValues(), 5, 4));
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(Yaml::dump($this->getContainer()->getValues(), 5, 4));
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"Yaml",
"::",
"dump",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"getValues",
"(",
")",
",",
"5",
",",
"4",
")",
")",
";",
"}"
] | Executes the command
@param InputInterface $input
@param OutputInterface $output
@return void | [
"Executes",
"the",
"command"
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Command/DumpCommand.php#L40-L43 |
digipolisgent/robo-digipolis-package | src/PackageProject.php | PackageProject.getFiles | protected function getFiles()
{
$this->mirrorDir();
$this->prepareMirrorDir();
$this->printTaskInfo('Retrieving files to package.');
$mirrorFinder = new Finder();
$mirrorFinder->ignoreDotFiles(false);
$add = [];
$mirrorFinder
->in($this->tmpDir)
->depth(0);
foreach ($mirrorFinder as $file) {
$add[substr($file->getRealPath(), strlen(realpath($this->tmpDir)) + 1)] = $file->getRealPath();
}
return $add;
} | php | protected function getFiles()
{
$this->mirrorDir();
$this->prepareMirrorDir();
$this->printTaskInfo('Retrieving files to package.');
$mirrorFinder = new Finder();
$mirrorFinder->ignoreDotFiles(false);
$add = [];
$mirrorFinder
->in($this->tmpDir)
->depth(0);
foreach ($mirrorFinder as $file) {
$add[substr($file->getRealPath(), strlen(realpath($this->tmpDir)) + 1)] = $file->getRealPath();
}
return $add;
} | [
"protected",
"function",
"getFiles",
"(",
")",
"{",
"$",
"this",
"->",
"mirrorDir",
"(",
")",
";",
"$",
"this",
"->",
"prepareMirrorDir",
"(",
")",
";",
"$",
"this",
"->",
"printTaskInfo",
"(",
"'Retrieving files to package.'",
")",
";",
"$",
"mirrorFinder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"mirrorFinder",
"->",
"ignoreDotFiles",
"(",
"false",
")",
";",
"$",
"add",
"=",
"[",
"]",
";",
"$",
"mirrorFinder",
"->",
"in",
"(",
"$",
"this",
"->",
"tmpDir",
")",
"->",
"depth",
"(",
"0",
")",
";",
"foreach",
"(",
"$",
"mirrorFinder",
"as",
"$",
"file",
")",
"{",
"$",
"add",
"[",
"substr",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
",",
"strlen",
"(",
"realpath",
"(",
"$",
"this",
"->",
"tmpDir",
")",
")",
"+",
"1",
")",
"]",
"=",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"}",
"return",
"$",
"add",
";",
"}"
] | Get the files and directories to package.
@return array
The list of files and directories to package. | [
"Get",
"the",
"files",
"and",
"directories",
"to",
"package",
"."
] | train | https://github.com/digipolisgent/robo-digipolis-package/blob/6f206f32d910992d27b2a1b4dda1c5e7d8259b75/src/PackageProject.php#L117-L132 |
digipolisgent/robo-digipolis-package | src/PackageProject.php | PackageProject.mirrorDir | protected function mirrorDir()
{
if (!$this->useTmpDir) {
$this->tmpDir = $this->dir;
return;
}
$this->tmpDir = md5(time());
if (file_exists($this->tmpDir)) {
$this->fs->remove($this->tmpDir);
}
$this->printTaskInfo(sprintf(
'Creating temporary directory %s.',
$this->tmpDir
));
$this->fs->mkdir($this->tmpDir);
$tmpRealPath = realpath($this->tmpDir);
$directoryIterator = new \RecursiveDirectoryIterator($this->dir, \RecursiveDirectoryIterator::SKIP_DOTS);
$recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
$filterIterator = new \CallbackFilterIterator(
$recursiveIterator,
function ($current) use ($tmpRealPath) {
return strpos($current->getRealPath(), $tmpRealPath) !== 0;
}
);
$this->printTaskInfo(sprintf(
'Mirroring directory %s to temporary directory %s.',
$this->dir,
$tmpRealPath
));
foreach ($filterIterator as $item) {
if (strpos($item->getRealPath(), $tmpRealPath) === 0) {
continue;
}
if (is_link($item)) {
if ($item->getRealPath() !== false) {
$this->fs->symlink(
$item->getLinkTarget(),
$this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName()
);
}
continue;
}
if ($item->isDir()) {
$this->fs->mkdir($this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName());
continue;
}
$this->fs->copy($item, $this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName());
}
} | php | protected function mirrorDir()
{
if (!$this->useTmpDir) {
$this->tmpDir = $this->dir;
return;
}
$this->tmpDir = md5(time());
if (file_exists($this->tmpDir)) {
$this->fs->remove($this->tmpDir);
}
$this->printTaskInfo(sprintf(
'Creating temporary directory %s.',
$this->tmpDir
));
$this->fs->mkdir($this->tmpDir);
$tmpRealPath = realpath($this->tmpDir);
$directoryIterator = new \RecursiveDirectoryIterator($this->dir, \RecursiveDirectoryIterator::SKIP_DOTS);
$recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
$filterIterator = new \CallbackFilterIterator(
$recursiveIterator,
function ($current) use ($tmpRealPath) {
return strpos($current->getRealPath(), $tmpRealPath) !== 0;
}
);
$this->printTaskInfo(sprintf(
'Mirroring directory %s to temporary directory %s.',
$this->dir,
$tmpRealPath
));
foreach ($filterIterator as $item) {
if (strpos($item->getRealPath(), $tmpRealPath) === 0) {
continue;
}
if (is_link($item)) {
if ($item->getRealPath() !== false) {
$this->fs->symlink(
$item->getLinkTarget(),
$this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName()
);
}
continue;
}
if ($item->isDir()) {
$this->fs->mkdir($this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName());
continue;
}
$this->fs->copy($item, $this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName());
}
} | [
"protected",
"function",
"mirrorDir",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"useTmpDir",
")",
"{",
"$",
"this",
"->",
"tmpDir",
"=",
"$",
"this",
"->",
"dir",
";",
"return",
";",
"}",
"$",
"this",
"->",
"tmpDir",
"=",
"md5",
"(",
"time",
"(",
")",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"tmpDir",
")",
")",
"{",
"$",
"this",
"->",
"fs",
"->",
"remove",
"(",
"$",
"this",
"->",
"tmpDir",
")",
";",
"}",
"$",
"this",
"->",
"printTaskInfo",
"(",
"sprintf",
"(",
"'Creating temporary directory %s.'",
",",
"$",
"this",
"->",
"tmpDir",
")",
")",
";",
"$",
"this",
"->",
"fs",
"->",
"mkdir",
"(",
"$",
"this",
"->",
"tmpDir",
")",
";",
"$",
"tmpRealPath",
"=",
"realpath",
"(",
"$",
"this",
"->",
"tmpDir",
")",
";",
"$",
"directoryIterator",
"=",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"this",
"->",
"dir",
",",
"\\",
"RecursiveDirectoryIterator",
"::",
"SKIP_DOTS",
")",
";",
"$",
"recursiveIterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"$",
"directoryIterator",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"$",
"filterIterator",
"=",
"new",
"\\",
"CallbackFilterIterator",
"(",
"$",
"recursiveIterator",
",",
"function",
"(",
"$",
"current",
")",
"use",
"(",
"$",
"tmpRealPath",
")",
"{",
"return",
"strpos",
"(",
"$",
"current",
"->",
"getRealPath",
"(",
")",
",",
"$",
"tmpRealPath",
")",
"!==",
"0",
";",
"}",
")",
";",
"$",
"this",
"->",
"printTaskInfo",
"(",
"sprintf",
"(",
"'Mirroring directory %s to temporary directory %s.'",
",",
"$",
"this",
"->",
"dir",
",",
"$",
"tmpRealPath",
")",
")",
";",
"foreach",
"(",
"$",
"filterIterator",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"item",
"->",
"getRealPath",
"(",
")",
",",
"$",
"tmpRealPath",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_link",
"(",
"$",
"item",
")",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getRealPath",
"(",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"fs",
"->",
"symlink",
"(",
"$",
"item",
"->",
"getLinkTarget",
"(",
")",
",",
"$",
"this",
"->",
"tmpDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filterIterator",
"->",
"getSubPathName",
"(",
")",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"this",
"->",
"fs",
"->",
"mkdir",
"(",
"$",
"this",
"->",
"tmpDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filterIterator",
"->",
"getSubPathName",
"(",
")",
")",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"fs",
"->",
"copy",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"tmpDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filterIterator",
"->",
"getSubPathName",
"(",
")",
")",
";",
"}",
"}"
] | Mirror the directory to a temp directory. | [
"Mirror",
"the",
"directory",
"to",
"a",
"temp",
"directory",
"."
] | train | https://github.com/digipolisgent/robo-digipolis-package/blob/6f206f32d910992d27b2a1b4dda1c5e7d8259b75/src/PackageProject.php#L137-L186 |
digipolisgent/robo-digipolis-package | src/PackageProject.php | PackageProject.prepareMirrorDir | protected function prepareMirrorDir()
{
$this->printTaskInfo(sprintf('Preparing directory %s.', $this->tmpDir));
if (empty($this->ignoreFileNames)) {
return;
}
$files = new Finder();
$files->in($this->tmpDir);
$files->ignoreDotFiles(false);
$files->files();
// Ignore files defined by the dev.
foreach ($this->ignoreFileNames as $fileName) {
$files->name($fileName);
}
$this->fs->remove($files);
} | php | protected function prepareMirrorDir()
{
$this->printTaskInfo(sprintf('Preparing directory %s.', $this->tmpDir));
if (empty($this->ignoreFileNames)) {
return;
}
$files = new Finder();
$files->in($this->tmpDir);
$files->ignoreDotFiles(false);
$files->files();
// Ignore files defined by the dev.
foreach ($this->ignoreFileNames as $fileName) {
$files->name($fileName);
}
$this->fs->remove($files);
} | [
"protected",
"function",
"prepareMirrorDir",
"(",
")",
"{",
"$",
"this",
"->",
"printTaskInfo",
"(",
"sprintf",
"(",
"'Preparing directory %s.'",
",",
"$",
"this",
"->",
"tmpDir",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"ignoreFileNames",
")",
")",
"{",
"return",
";",
"}",
"$",
"files",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"files",
"->",
"in",
"(",
"$",
"this",
"->",
"tmpDir",
")",
";",
"$",
"files",
"->",
"ignoreDotFiles",
"(",
"false",
")",
";",
"$",
"files",
"->",
"files",
"(",
")",
";",
"// Ignore files defined by the dev.",
"foreach",
"(",
"$",
"this",
"->",
"ignoreFileNames",
"as",
"$",
"fileName",
")",
"{",
"$",
"files",
"->",
"name",
"(",
"$",
"fileName",
")",
";",
"}",
"$",
"this",
"->",
"fs",
"->",
"remove",
"(",
"$",
"files",
")",
";",
"}"
] | Removes files that should not be packaged from the mirrored directory. | [
"Removes",
"files",
"that",
"should",
"not",
"be",
"packaged",
"from",
"the",
"mirrored",
"directory",
"."
] | train | https://github.com/digipolisgent/robo-digipolis-package/blob/6f206f32d910992d27b2a1b4dda1c5e7d8259b75/src/PackageProject.php#L191-L207 |
digipolisgent/robo-digipolis-package | src/PackageProject.php | PackageProject.run | public function run()
{
if (is_null($this->dir)) {
$projectRoot = $this->getConfig()->get('digipolis.root.project', null);
$this->dir = is_null($projectRoot)
? getcwd()
: $projectRoot;
}
$this->add($this->getFiles());
$result = parent::run();
if ($this->useTmpDir) {
$this->printTaskInfo(
sprintf('Removing temporary directory %s.', $this->tmpDir)
);
$this->fs->remove($this->tmpDir);
}
return $result;
} | php | public function run()
{
if (is_null($this->dir)) {
$projectRoot = $this->getConfig()->get('digipolis.root.project', null);
$this->dir = is_null($projectRoot)
? getcwd()
: $projectRoot;
}
$this->add($this->getFiles());
$result = parent::run();
if ($this->useTmpDir) {
$this->printTaskInfo(
sprintf('Removing temporary directory %s.', $this->tmpDir)
);
$this->fs->remove($this->tmpDir);
}
return $result;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"dir",
")",
")",
"{",
"$",
"projectRoot",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'digipolis.root.project'",
",",
"null",
")",
";",
"$",
"this",
"->",
"dir",
"=",
"is_null",
"(",
"$",
"projectRoot",
")",
"?",
"getcwd",
"(",
")",
":",
"$",
"projectRoot",
";",
"}",
"$",
"this",
"->",
"add",
"(",
"$",
"this",
"->",
"getFiles",
"(",
")",
")",
";",
"$",
"result",
"=",
"parent",
"::",
"run",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"useTmpDir",
")",
"{",
"$",
"this",
"->",
"printTaskInfo",
"(",
"sprintf",
"(",
"'Removing temporary directory %s.'",
",",
"$",
"this",
"->",
"tmpDir",
")",
")",
";",
"$",
"this",
"->",
"fs",
"->",
"remove",
"(",
"$",
"this",
"->",
"tmpDir",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/digipolisgent/robo-digipolis-package/blob/6f206f32d910992d27b2a1b4dda1c5e7d8259b75/src/PackageProject.php#L212-L229 |
inhere/php-librarys | src/Helpers/UtilHelper.php | UtilHelper.fd | public static function fd($object, $type = 'log')
{
$types = array('log', 'debug', 'info', 'warn', 'error', 'assert');
if (!\in_array($type, $types, true)) {
$type = 'log';
}
$data = json_encode($object);
echo '<script type="text/javascript">console.' . $type . '(' . $data . ');</script>';
} | php | public static function fd($object, $type = 'log')
{
$types = array('log', 'debug', 'info', 'warn', 'error', 'assert');
if (!\in_array($type, $types, true)) {
$type = 'log';
}
$data = json_encode($object);
echo '<script type="text/javascript">console.' . $type . '(' . $data . ');</script>';
} | [
"public",
"static",
"function",
"fd",
"(",
"$",
"object",
",",
"$",
"type",
"=",
"'log'",
")",
"{",
"$",
"types",
"=",
"array",
"(",
"'log'",
",",
"'debug'",
",",
"'info'",
",",
"'warn'",
",",
"'error'",
",",
"'assert'",
")",
";",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"type",
",",
"$",
"types",
",",
"true",
")",
")",
"{",
"$",
"type",
"=",
"'log'",
";",
"}",
"$",
"data",
"=",
"json_encode",
"(",
"$",
"object",
")",
";",
"echo",
"'<script type=\"text/javascript\">console.'",
".",
"$",
"type",
".",
"'('",
".",
"$",
"data",
".",
"');</script>'",
";",
"}"
] | Display a var dump in firebug console
@param mixed $object Object to display
@param string $type | [
"Display",
"a",
"var",
"dump",
"in",
"firebug",
"console"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/UtilHelper.php#L16-L27 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.parse | public function parse() {
$p = 0;
do {
$p = $this->scanner->position();
$this->consumeData();
// FIXME: Add infinite loop protection.
} while ($this->carryOn);
} | php | public function parse() {
$p = 0;
do {
$p = $this->scanner->position();
$this->consumeData();
// FIXME: Add infinite loop protection.
} while ($this->carryOn);
} | [
"public",
"function",
"parse",
"(",
")",
"{",
"$",
"p",
"=",
"0",
";",
"do",
"{",
"$",
"p",
"=",
"$",
"this",
"->",
"scanner",
"->",
"position",
"(",
")",
";",
"$",
"this",
"->",
"consumeData",
"(",
")",
";",
"// FIXME: Add infinite loop protection.",
"}",
"while",
"(",
"$",
"this",
"->",
"carryOn",
")",
";",
"}"
] | Begin parsing.
This will begin scanning the document, tokenizing as it goes.
Tokens are emitted into the event handler.
Tokenizing will continue until the document is completely
read. Errors are emitted into the event handler, but
the parser will attempt to continue parsing until the
entire input stream is read. | [
"Begin",
"parsing",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L154-L162 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.setTextMode | public function setTextMode($textmode, $untilTag = null) {
$this->textMode = $textmode & (HTML5_Elements::TEXT_RAW | HTML5_Elements::TEXT_RCDATA);
$this->untilTag = $untilTag;
} | php | public function setTextMode($textmode, $untilTag = null) {
$this->textMode = $textmode & (HTML5_Elements::TEXT_RAW | HTML5_Elements::TEXT_RCDATA);
$this->untilTag = $untilTag;
} | [
"public",
"function",
"setTextMode",
"(",
"$",
"textmode",
",",
"$",
"untilTag",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"textMode",
"=",
"$",
"textmode",
"&",
"(",
"HTML5_Elements",
"::",
"TEXT_RAW",
"|",
"HTML5_Elements",
"::",
"TEXT_RCDATA",
")",
";",
"$",
"this",
"->",
"untilTag",
"=",
"$",
"untilTag",
";",
"}"
] | Set the text mode for the character data reader.
HTML5 defines three different modes for reading text:
- Normal: Read until a tag is encountered.
- RCDATA: Read until a tag is encountered, but skip a few otherwise-
special characters.
- Raw: Read until a special closing tag is encountered (viz. pre, script)
This allows those modes to be set.
Normally, setting is done by the event handler via a special return code on
startTag(), but it can also be set manually using this function.
@param integer $textmode
One of HTML5_Elements::TEXT_*
@param string $untilTag
The tag that should stop RAW or RCDATA mode. Normal mode does not
use this indicator. | [
"Set",
"the",
"text",
"mode",
"for",
"the",
"character",
"data",
"reader",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L184-L187 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.consumeData | protected function consumeData() {
// Character Ref
/*
* $this->characterReference() || $this->tagOpen() || $this->eof() || $this->characterData();
*/
$this->characterReference();
$this->tagOpen();
$this->eof();
$this->characterData();
return $this->carryOn;
} | php | protected function consumeData() {
// Character Ref
/*
* $this->characterReference() || $this->tagOpen() || $this->eof() || $this->characterData();
*/
$this->characterReference();
$this->tagOpen();
$this->eof();
$this->characterData();
return $this->carryOn;
} | [
"protected",
"function",
"consumeData",
"(",
")",
"{",
"// Character Ref",
"/*\n * $this->characterReference() || $this->tagOpen() || $this->eof() || $this->characterData();\n */",
"$",
"this",
"->",
"characterReference",
"(",
")",
";",
"$",
"this",
"->",
"tagOpen",
"(",
")",
";",
"$",
"this",
"->",
"eof",
"(",
")",
";",
"$",
"this",
"->",
"characterData",
"(",
")",
";",
"return",
"$",
"this",
"->",
"carryOn",
";",
"}"
] | Consume a character and make a move.
HTML5 8.2.4.1 | [
"Consume",
"a",
"character",
"and",
"make",
"a",
"move",
".",
"HTML5",
"8",
".",
"2",
".",
"4",
".",
"1"
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L193-L204 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.characterData | protected function characterData() {
if ($this->scanner->current() === false) {
return false;
}
switch ($this->textMode) {
case HTML5_Elements::TEXT_RAW:
return $this->rawText();
case HTML5_Elements::TEXT_RCDATA:
return $this->rcdata();
default:
$tok = $this->scanner->current();
if (strspn($tok, "<&")) {
return false;
}
return $this->text();
}
} | php | protected function characterData() {
if ($this->scanner->current() === false) {
return false;
}
switch ($this->textMode) {
case HTML5_Elements::TEXT_RAW:
return $this->rawText();
case HTML5_Elements::TEXT_RCDATA:
return $this->rcdata();
default:
$tok = $this->scanner->current();
if (strspn($tok, "<&")) {
return false;
}
return $this->text();
}
} | [
"protected",
"function",
"characterData",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"textMode",
")",
"{",
"case",
"HTML5_Elements",
"::",
"TEXT_RAW",
":",
"return",
"$",
"this",
"->",
"rawText",
"(",
")",
";",
"case",
"HTML5_Elements",
"::",
"TEXT_RCDATA",
":",
"return",
"$",
"this",
"->",
"rcdata",
"(",
")",
";",
"default",
":",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"if",
"(",
"strspn",
"(",
"$",
"tok",
",",
"\"<&\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"text",
"(",
")",
";",
"}",
"}"
] | Parse anything that looks like character data.
Different rules apply based on the current text mode.
@see HTML5_Elements::TEXT_RAW HTML5_Elements::TEXT_RCDATA. | [
"Parse",
"anything",
"that",
"looks",
"like",
"character",
"data",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L213-L229 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.text | protected function text() {
$tok = $this->scanner->current();
// This should never happen...
if ($tok === false) {
return false;
}
// Null
if ($tok === "\00") {
$this->parseError("Received null character.");
}
// fprintf(STDOUT, "Writing '%s'", $tok);
$this->buffer($tok);
$this->scanner->next();
return true;
} | php | protected function text() {
$tok = $this->scanner->current();
// This should never happen...
if ($tok === false) {
return false;
}
// Null
if ($tok === "\00") {
$this->parseError("Received null character.");
}
// fprintf(STDOUT, "Writing '%s'", $tok);
$this->buffer($tok);
$this->scanner->next();
return true;
} | [
"protected",
"function",
"text",
"(",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"// This should never happen...",
"if",
"(",
"$",
"tok",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"// Null",
"if",
"(",
"$",
"tok",
"===",
"\"\\00\"",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Received null character.\"",
")",
";",
"}",
"// fprintf(STDOUT, \"Writing '%s'\", $tok);",
"$",
"this",
"->",
"buffer",
"(",
"$",
"tok",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | This buffers the current token as character data. | [
"This",
"buffers",
"the",
"current",
"token",
"as",
"character",
"data",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L234-L249 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.rawText | protected function rawText() {
if (is_null($this->untilTag)) {
return $this->text();
}
$sequence = '</' . $this->untilTag . '>';
$txt = $this->readUntilSequence($sequence);
$this->events->text($txt);
$this->setTextMode(0);
return $this->endTag();
} | php | protected function rawText() {
if (is_null($this->untilTag)) {
return $this->text();
}
$sequence = '</' . $this->untilTag . '>';
$txt = $this->readUntilSequence($sequence);
$this->events->text($txt);
$this->setTextMode(0);
return $this->endTag();
} | [
"protected",
"function",
"rawText",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"untilTag",
")",
")",
"{",
"return",
"$",
"this",
"->",
"text",
"(",
")",
";",
"}",
"$",
"sequence",
"=",
"'</'",
".",
"$",
"this",
"->",
"untilTag",
".",
"'>'",
";",
"$",
"txt",
"=",
"$",
"this",
"->",
"readUntilSequence",
"(",
"$",
"sequence",
")",
";",
"$",
"this",
"->",
"events",
"->",
"text",
"(",
"$",
"txt",
")",
";",
"$",
"this",
"->",
"setTextMode",
"(",
"0",
")",
";",
"return",
"$",
"this",
"->",
"endTag",
"(",
")",
";",
"}"
] | Read text in RAW mode. | [
"Read",
"text",
"in",
"RAW",
"mode",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L254-L263 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.rcdata | protected function rcdata() {
if (is_null($this->untilTag)) {
return $this->text();
}
$sequence = '</' . $this->untilTag . '>';
$txt = '';
$tok = $this->scanner->current();
while ($tok !== false && !($tok == '<' && ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))))) {
if ($tok == '&') {
$txt .= $this->decodeCharacterReference();
$tok = $this->scanner->current();
} else {
$txt .= $tok;
$tok = $this->scanner->next();
}
}
$this->events->text($txt);
$this->setTextMode(0);
return $this->endTag();
} | php | protected function rcdata() {
if (is_null($this->untilTag)) {
return $this->text();
}
$sequence = '</' . $this->untilTag . '>';
$txt = '';
$tok = $this->scanner->current();
while ($tok !== false && !($tok == '<' && ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))))) {
if ($tok == '&') {
$txt .= $this->decodeCharacterReference();
$tok = $this->scanner->current();
} else {
$txt .= $tok;
$tok = $this->scanner->next();
}
}
$this->events->text($txt);
$this->setTextMode(0);
return $this->endTag();
} | [
"protected",
"function",
"rcdata",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"untilTag",
")",
")",
"{",
"return",
"$",
"this",
"->",
"text",
"(",
")",
";",
"}",
"$",
"sequence",
"=",
"'</'",
".",
"$",
"this",
"->",
"untilTag",
".",
"'>'",
";",
"$",
"txt",
"=",
"''",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"while",
"(",
"$",
"tok",
"!==",
"false",
"&&",
"!",
"(",
"$",
"tok",
"==",
"'<'",
"&&",
"(",
"$",
"this",
"->",
"sequenceMatches",
"(",
"$",
"sequence",
")",
"||",
"$",
"this",
"->",
"sequenceMatches",
"(",
"strtoupper",
"(",
"$",
"sequence",
")",
")",
")",
")",
")",
"{",
"if",
"(",
"$",
"tok",
"==",
"'&'",
")",
"{",
"$",
"txt",
".=",
"$",
"this",
"->",
"decodeCharacterReference",
"(",
")",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"}",
"else",
"{",
"$",
"txt",
".=",
"$",
"tok",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"events",
"->",
"text",
"(",
"$",
"txt",
")",
";",
"$",
"this",
"->",
"setTextMode",
"(",
"0",
")",
";",
"return",
"$",
"this",
"->",
"endTag",
"(",
")",
";",
"}"
] | Read text in RCDATA mode. | [
"Read",
"text",
"in",
"RCDATA",
"mode",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L268-L287 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.eof | protected function eof() {
if ($this->scanner->current() === false) {
// fprintf(STDOUT, "EOF");
$this->flushBuffer();
$this->events->eof();
$this->carryOn = false;
return true;
}
return false;
} | php | protected function eof() {
if ($this->scanner->current() === false) {
// fprintf(STDOUT, "EOF");
$this->flushBuffer();
$this->events->eof();
$this->carryOn = false;
return true;
}
return false;
} | [
"protected",
"function",
"eof",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"===",
"false",
")",
"{",
"// fprintf(STDOUT, \"EOF\");",
"$",
"this",
"->",
"flushBuffer",
"(",
")",
";",
"$",
"this",
"->",
"events",
"->",
"eof",
"(",
")",
";",
"$",
"this",
"->",
"carryOn",
"=",
"false",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | If the document is read, emit an EOF event. | [
"If",
"the",
"document",
"is",
"read",
"emit",
"an",
"EOF",
"event",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L292-L301 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.characterReference | protected function characterReference() {
$ref = $this->decodeCharacterReference();
if ($ref !== false) {
$this->buffer($ref);
return true;
}
return false;
} | php | protected function characterReference() {
$ref = $this->decodeCharacterReference();
if ($ref !== false) {
$this->buffer($ref);
return true;
}
return false;
} | [
"protected",
"function",
"characterReference",
"(",
")",
"{",
"$",
"ref",
"=",
"$",
"this",
"->",
"decodeCharacterReference",
"(",
")",
";",
"if",
"(",
"$",
"ref",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"buffer",
"(",
"$",
"ref",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Handle character references (aka entities).
This version is specific to PCDATA, as it buffers data into the
text buffer. For a generic version, see decodeCharacterReference().
HTML5 8.2.4.2 | [
"Handle",
"character",
"references",
"(",
"aka",
"entities",
")",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L311-L318 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.tagOpen | protected function tagOpen() {
if ($this->scanner->current() != '<') {
return false;
}
// Any buffered text data can go out now.
$this->flushBuffer();
$this->scanner->next();
return $this->markupDeclaration() || $this->endTag() || $this->processingInstruction() || $this->tagName() ||
/* This always returns false. */
$this->parseError("Illegal tag opening") || $this->characterData();
} | php | protected function tagOpen() {
if ($this->scanner->current() != '<') {
return false;
}
// Any buffered text data can go out now.
$this->flushBuffer();
$this->scanner->next();
return $this->markupDeclaration() || $this->endTag() || $this->processingInstruction() || $this->tagName() ||
/* This always returns false. */
$this->parseError("Illegal tag opening") || $this->characterData();
} | [
"protected",
"function",
"tagOpen",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'<'",
")",
"{",
"return",
"false",
";",
"}",
"// Any buffered text data can go out now.",
"$",
"this",
"->",
"flushBuffer",
"(",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"$",
"this",
"->",
"markupDeclaration",
"(",
")",
"||",
"$",
"this",
"->",
"endTag",
"(",
")",
"||",
"$",
"this",
"->",
"processingInstruction",
"(",
")",
"||",
"$",
"this",
"->",
"tagName",
"(",
")",
"||",
"/* This always returns false. */",
"$",
"this",
"->",
"parseError",
"(",
"\"Illegal tag opening\"",
")",
"||",
"$",
"this",
"->",
"characterData",
"(",
")",
";",
"}"
] | Emit a tagStart event on encountering a tag.
8.2.4.8 | [
"Emit",
"a",
"tagStart",
"event",
"on",
"encountering",
"a",
"tag",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L325-L338 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.markupDeclaration | protected function markupDeclaration() {
if ($this->scanner->current() != '!') {
return false;
}
$tok = $this->scanner->next();
// Comment:
if ($tok == '-' && $this->scanner->peek() == '-') {
$this->scanner->next(); // Consume the other '-'
$this->scanner->next(); // Next char.
return $this->comment();
} elseif ($tok == 'D' || $tok == 'd') { // Doctype
return $this->doctype('');
} elseif ($tok == '[') { // CDATA section
return $this->cdataSection();
}
// FINISH
$this->parseError("Expected <!--, <![CDATA[, or <!DOCTYPE. Got <!%s", $tok);
$this->bogusComment('<!');
return true;
} | php | protected function markupDeclaration() {
if ($this->scanner->current() != '!') {
return false;
}
$tok = $this->scanner->next();
// Comment:
if ($tok == '-' && $this->scanner->peek() == '-') {
$this->scanner->next(); // Consume the other '-'
$this->scanner->next(); // Next char.
return $this->comment();
} elseif ($tok == 'D' || $tok == 'd') { // Doctype
return $this->doctype('');
} elseif ($tok == '[') { // CDATA section
return $this->cdataSection();
}
// FINISH
$this->parseError("Expected <!--, <![CDATA[, or <!DOCTYPE. Got <!%s", $tok);
$this->bogusComment('<!');
return true;
} | [
"protected",
"function",
"markupDeclaration",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'!'",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// Comment:",
"if",
"(",
"$",
"tok",
"==",
"'-'",
"&&",
"$",
"this",
"->",
"scanner",
"->",
"peek",
"(",
")",
"==",
"'-'",
")",
"{",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// Consume the other '-'",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// Next char.",
"return",
"$",
"this",
"->",
"comment",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"tok",
"==",
"'D'",
"||",
"$",
"tok",
"==",
"'d'",
")",
"{",
"// Doctype",
"return",
"$",
"this",
"->",
"doctype",
"(",
"''",
")",
";",
"}",
"elseif",
"(",
"$",
"tok",
"==",
"'['",
")",
"{",
"// CDATA section",
"return",
"$",
"this",
"->",
"cdataSection",
"(",
")",
";",
"}",
"// FINISH",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected <!--, <![CDATA[, or <!DOCTYPE. Got <!%s\"",
",",
"$",
"tok",
")",
";",
"$",
"this",
"->",
"bogusComment",
"(",
"'<!'",
")",
";",
"return",
"true",
";",
"}"
] | Look for markup. | [
"Look",
"for",
"markup",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L343-L365 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.endTag | protected function endTag() {
if ($this->scanner->current() != '/') {
return false;
}
$tok = $this->scanner->next();
// a-zA-Z -> tagname
// > -> parse error
// EOF -> parse error
// -> parse error
if (!ctype_alpha($tok)) {
$this->parseError("Expected tag name, got '%s'", $tok);
if ($tok == "\0" || $tok === false) {
return false;
}
return $this->bogusComment('</');
}
$name = strtolower($this->scanner->charsUntil("\n\f \t>"));
// Trash whitespace.
$this->scanner->whitespace();
if ($this->scanner->current() != '>') {
$this->parseError("Expected >, got '%s'", $this->scanner->current());
// We just trash stuff until we get to the next tag close.
$this->scanner->charsUntil('>');
}
$this->events->endTag($name);
$this->scanner->next();
return true;
} | php | protected function endTag() {
if ($this->scanner->current() != '/') {
return false;
}
$tok = $this->scanner->next();
// a-zA-Z -> tagname
// > -> parse error
// EOF -> parse error
// -> parse error
if (!ctype_alpha($tok)) {
$this->parseError("Expected tag name, got '%s'", $tok);
if ($tok == "\0" || $tok === false) {
return false;
}
return $this->bogusComment('</');
}
$name = strtolower($this->scanner->charsUntil("\n\f \t>"));
// Trash whitespace.
$this->scanner->whitespace();
if ($this->scanner->current() != '>') {
$this->parseError("Expected >, got '%s'", $this->scanner->current());
// We just trash stuff until we get to the next tag close.
$this->scanner->charsUntil('>');
}
$this->events->endTag($name);
$this->scanner->next();
return true;
} | [
"protected",
"function",
"endTag",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'/'",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// a-zA-Z -> tagname",
"// > -> parse error",
"// EOF -> parse error",
"// -> parse error",
"if",
"(",
"!",
"ctype_alpha",
"(",
"$",
"tok",
")",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected tag name, got '%s'\"",
",",
"$",
"tok",
")",
";",
"if",
"(",
"$",
"tok",
"==",
"\"\\0\"",
"||",
"$",
"tok",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"bogusComment",
"(",
"'</'",
")",
";",
"}",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"scanner",
"->",
"charsUntil",
"(",
"\"\\n\\f \\t>\"",
")",
")",
";",
"// Trash whitespace.",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'>'",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected >, got '%s'\"",
",",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
")",
";",
"// We just trash stuff until we get to the next tag close.",
"$",
"this",
"->",
"scanner",
"->",
"charsUntil",
"(",
"'>'",
")",
";",
"}",
"$",
"this",
"->",
"events",
"->",
"endTag",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Consume an end tag.
8.2.4.9 | [
"Consume",
"an",
"end",
"tag",
".",
"8",
".",
"2",
".",
"4",
".",
"9"
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L371-L402 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.tagName | protected function tagName() {
$tok = $this->scanner->current();
if (!ctype_alpha($tok)) {
return false;
}
// We know this is at least one char.
$name = strtolower($this->scanner->charsWhile(":_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
$attributes = array();
$selfClose = false;
// Handle attribute parse exceptions here so that we can
// react by trying to build a sensible parse tree.
try {
do {
$this->scanner->whitespace();
$this->attribute($attributes);
} while (!$this->isTagEnd($selfClose));
} catch (HTML5_Parser_Exception $e) {
$selfClose = false;
}
$mode = $this->events->startTag($name, $attributes, $selfClose);
// Should we do this? What does this buy that selfClose doesn't?
if ($selfClose) {
$this->events->endTag($name);
} elseif (is_int($mode)) {
// fprintf(STDOUT, "Event response says move into mode %d for tag %s", $mode, $name);
$this->setTextMode($mode, $name);
}
$this->scanner->next();
return true;
} | php | protected function tagName() {
$tok = $this->scanner->current();
if (!ctype_alpha($tok)) {
return false;
}
// We know this is at least one char.
$name = strtolower($this->scanner->charsWhile(":_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
$attributes = array();
$selfClose = false;
// Handle attribute parse exceptions here so that we can
// react by trying to build a sensible parse tree.
try {
do {
$this->scanner->whitespace();
$this->attribute($attributes);
} while (!$this->isTagEnd($selfClose));
} catch (HTML5_Parser_Exception $e) {
$selfClose = false;
}
$mode = $this->events->startTag($name, $attributes, $selfClose);
// Should we do this? What does this buy that selfClose doesn't?
if ($selfClose) {
$this->events->endTag($name);
} elseif (is_int($mode)) {
// fprintf(STDOUT, "Event response says move into mode %d for tag %s", $mode, $name);
$this->setTextMode($mode, $name);
}
$this->scanner->next();
return true;
} | [
"protected",
"function",
"tagName",
"(",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"ctype_alpha",
"(",
"$",
"tok",
")",
")",
"{",
"return",
"false",
";",
"}",
"// We know this is at least one char.",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"scanner",
"->",
"charsWhile",
"(",
"\":_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"",
")",
")",
";",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"$",
"selfClose",
"=",
"false",
";",
"// Handle attribute parse exceptions here so that we can",
"// react by trying to build a sensible parse tree.",
"try",
"{",
"do",
"{",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
";",
"$",
"this",
"->",
"attribute",
"(",
"$",
"attributes",
")",
";",
"}",
"while",
"(",
"!",
"$",
"this",
"->",
"isTagEnd",
"(",
"$",
"selfClose",
")",
")",
";",
"}",
"catch",
"(",
"HTML5_Parser_Exception",
"$",
"e",
")",
"{",
"$",
"selfClose",
"=",
"false",
";",
"}",
"$",
"mode",
"=",
"$",
"this",
"->",
"events",
"->",
"startTag",
"(",
"$",
"name",
",",
"$",
"attributes",
",",
"$",
"selfClose",
")",
";",
"// Should we do this? What does this buy that selfClose doesn't?",
"if",
"(",
"$",
"selfClose",
")",
"{",
"$",
"this",
"->",
"events",
"->",
"endTag",
"(",
"$",
"name",
")",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"mode",
")",
")",
"{",
"// fprintf(STDOUT, \"Event response says move into mode %d for tag %s\", $mode, $name);",
"$",
"this",
"->",
"setTextMode",
"(",
"$",
"mode",
",",
"$",
"name",
")",
";",
"}",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Consume a tag name and body.
8.2.4.10 | [
"Consume",
"a",
"tag",
"name",
"and",
"body",
".",
"8",
".",
"2",
".",
"4",
".",
"10"
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L408-L442 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.isTagEnd | protected function isTagEnd(&$selfClose) {
$tok = $this->scanner->current();
if ($tok == '/') {
$this->scanner->next();
$this->scanner->whitespace();
if ($this->scanner->current() == '>') {
$selfClose = true;
return true;
}
if ($this->scanner->current() === false) {
$this->parseError("Unexpected EOF inside of tag.");
return true;
}
// Basically, we skip the / token and go on.
// See 8.2.4.43.
$this->parseError("Unexpected '%s' inside of a tag.", $this->scanner->current());
return false;
}
if ($this->scanner->current() == '>') {
return true;
}
if ($this->scanner->current() === false) {
$this->parseError("Unexpected EOF inside of tag.");
return true;
}
return false;
} | php | protected function isTagEnd(&$selfClose) {
$tok = $this->scanner->current();
if ($tok == '/') {
$this->scanner->next();
$this->scanner->whitespace();
if ($this->scanner->current() == '>') {
$selfClose = true;
return true;
}
if ($this->scanner->current() === false) {
$this->parseError("Unexpected EOF inside of tag.");
return true;
}
// Basically, we skip the / token and go on.
// See 8.2.4.43.
$this->parseError("Unexpected '%s' inside of a tag.", $this->scanner->current());
return false;
}
if ($this->scanner->current() == '>') {
return true;
}
if ($this->scanner->current() === false) {
$this->parseError("Unexpected EOF inside of tag.");
return true;
}
return false;
} | [
"protected",
"function",
"isTagEnd",
"(",
"&",
"$",
"selfClose",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"if",
"(",
"$",
"tok",
"==",
"'/'",
")",
"{",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"==",
"'>'",
")",
"{",
"$",
"selfClose",
"=",
"true",
";",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected EOF inside of tag.\"",
")",
";",
"return",
"true",
";",
"}",
"// Basically, we skip the / token and go on.",
"// See 8.2.4.43.",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected '%s' inside of a tag.\"",
",",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"==",
"'>'",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected EOF inside of tag.\"",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if the scanner has reached the end of a tag. | [
"Check",
"if",
"the",
"scanner",
"has",
"reached",
"the",
"end",
"of",
"a",
"tag",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L447-L475 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.attribute | protected function attribute(&$attributes) {
$tok = $this->scanner->current();
if ($tok == '/' || $tok == '>' || $tok === false) {
return false;
}
if ($tok == '<') {
$this->parseError("Unexepcted '<' inside of attributes list.");
// Push the < back onto the stack.
$this->scanner->unconsume();
// Let the caller figure out how to handle this.
throw new HTML5_Parser_Exception("Start tag inside of attribute.");
}
$name = strtolower($this->scanner->charsUntil("/>=\n\f\t "));
if (strlen($name) == 0) {
$this->parseError("Expected an attribute name, got %s.", $this->scanner->current());
// Really, only '=' can be the char here. Everything else gets absorbed
// under one rule or another.
$name = $this->scanner->current();
$this->scanner->next();
}
$isValidAttribute = true;
// Attribute names can contain most Unicode characters for HTML5.
// But method "DOMElement::setAttribute" is throwing exception
// because of it's own internal restriction so these have to be filtered.
// see issue #23: https://github.com/Masterminds/html5-php/issues/23
// and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name
if (preg_match("/[\x1-\x2C\\/\x3B-\x40\x5B-\x5E\x60\x7B-\x7F]/u", $name)) {
$this->parseError("Unexpected characters in attribute name: %s", $name);
$isValidAttribute = false;
} // There is no limitation for 1st character in HTML5.
// But method "DOMElement::setAttribute" is throwing exception for the
// characters below so they have to be filtered.
// see issue #23: https://github.com/Masterminds/html5-php/issues/23
// and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name
else
if (preg_match("/^[0-9.-]/u", $name)) {
$this->parseError("Unexpected character at the begining of attribute name: %s", $name);
$isValidAttribute = false;
}
// 8.1.2.3
$this->scanner->whitespace();
$val = $this->attributeValue();
if ($isValidAttribute) {
$attributes[$name] = $val;
}
return true;
} | php | protected function attribute(&$attributes) {
$tok = $this->scanner->current();
if ($tok == '/' || $tok == '>' || $tok === false) {
return false;
}
if ($tok == '<') {
$this->parseError("Unexepcted '<' inside of attributes list.");
// Push the < back onto the stack.
$this->scanner->unconsume();
// Let the caller figure out how to handle this.
throw new HTML5_Parser_Exception("Start tag inside of attribute.");
}
$name = strtolower($this->scanner->charsUntil("/>=\n\f\t "));
if (strlen($name) == 0) {
$this->parseError("Expected an attribute name, got %s.", $this->scanner->current());
// Really, only '=' can be the char here. Everything else gets absorbed
// under one rule or another.
$name = $this->scanner->current();
$this->scanner->next();
}
$isValidAttribute = true;
// Attribute names can contain most Unicode characters for HTML5.
// But method "DOMElement::setAttribute" is throwing exception
// because of it's own internal restriction so these have to be filtered.
// see issue #23: https://github.com/Masterminds/html5-php/issues/23
// and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name
if (preg_match("/[\x1-\x2C\\/\x3B-\x40\x5B-\x5E\x60\x7B-\x7F]/u", $name)) {
$this->parseError("Unexpected characters in attribute name: %s", $name);
$isValidAttribute = false;
} // There is no limitation for 1st character in HTML5.
// But method "DOMElement::setAttribute" is throwing exception for the
// characters below so they have to be filtered.
// see issue #23: https://github.com/Masterminds/html5-php/issues/23
// and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name
else
if (preg_match("/^[0-9.-]/u", $name)) {
$this->parseError("Unexpected character at the begining of attribute name: %s", $name);
$isValidAttribute = false;
}
// 8.1.2.3
$this->scanner->whitespace();
$val = $this->attributeValue();
if ($isValidAttribute) {
$attributes[$name] = $val;
}
return true;
} | [
"protected",
"function",
"attribute",
"(",
"&",
"$",
"attributes",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"if",
"(",
"$",
"tok",
"==",
"'/'",
"||",
"$",
"tok",
"==",
"'>'",
"||",
"$",
"tok",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"tok",
"==",
"'<'",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexepcted '<' inside of attributes list.\"",
")",
";",
"// Push the < back onto the stack.",
"$",
"this",
"->",
"scanner",
"->",
"unconsume",
"(",
")",
";",
"// Let the caller figure out how to handle this.",
"throw",
"new",
"HTML5_Parser_Exception",
"(",
"\"Start tag inside of attribute.\"",
")",
";",
"}",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"scanner",
"->",
"charsUntil",
"(",
"\"/>=\\n\\f\\t \"",
")",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"name",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected an attribute name, got %s.\"",
",",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
")",
";",
"// Really, only '=' can be the char here. Everything else gets absorbed",
"// under one rule or another.",
"$",
"name",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"$",
"isValidAttribute",
"=",
"true",
";",
"// Attribute names can contain most Unicode characters for HTML5.",
"// But method \"DOMElement::setAttribute\" is throwing exception",
"// because of it's own internal restriction so these have to be filtered.",
"// see issue #23: https://github.com/Masterminds/html5-php/issues/23",
"// and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name",
"if",
"(",
"preg_match",
"(",
"\"/[\\x1-\\x2C\\\\/\\x3B-\\x40\\x5B-\\x5E\\x60\\x7B-\\x7F]/u\"",
",",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected characters in attribute name: %s\"",
",",
"$",
"name",
")",
";",
"$",
"isValidAttribute",
"=",
"false",
";",
"}",
"// There is no limitation for 1st character in HTML5.",
"// But method \"DOMElement::setAttribute\" is throwing exception for the",
"// characters below so they have to be filtered.",
"// see issue #23: https://github.com/Masterminds/html5-php/issues/23",
"// and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name",
"else",
"if",
"(",
"preg_match",
"(",
"\"/^[0-9.-]/u\"",
",",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected character at the begining of attribute name: %s\"",
",",
"$",
"name",
")",
";",
"$",
"isValidAttribute",
"=",
"false",
";",
"}",
"// 8.1.2.3",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
";",
"$",
"val",
"=",
"$",
"this",
"->",
"attributeValue",
"(",
")",
";",
"if",
"(",
"$",
"isValidAttribute",
")",
"{",
"$",
"attributes",
"[",
"$",
"name",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"true",
";",
"}"
] | Parse attributes from inside of a tag. | [
"Parse",
"attributes",
"from",
"inside",
"of",
"a",
"tag",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L480-L531 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.attributeValue | protected function attributeValue() {
if ($this->scanner->current() != '=') {
return null;
}
$this->scanner->next();
// 8.1.2.3
$this->scanner->whitespace();
$tok = $this->scanner->current();
switch ($tok) {
case "\n":
case "\f":
case " ":
case "\t":
// Whitespace here indicates an empty value.
return null;
case '"':
case "'":
$this->scanner->next();
return $this->quotedAttributeValue($tok);
case '>':
// case '/': // 8.2.4.37 seems to allow foo=/ as a valid attr.
$this->parseError("Expected attribute value, got tag end.");
return null;
case '=':
case '`':
$this->parseError("Expecting quotes, got %s.", $tok);
return $this->unquotedAttributeValue();
default:
return $this->unquotedAttributeValue();
}
} | php | protected function attributeValue() {
if ($this->scanner->current() != '=') {
return null;
}
$this->scanner->next();
// 8.1.2.3
$this->scanner->whitespace();
$tok = $this->scanner->current();
switch ($tok) {
case "\n":
case "\f":
case " ":
case "\t":
// Whitespace here indicates an empty value.
return null;
case '"':
case "'":
$this->scanner->next();
return $this->quotedAttributeValue($tok);
case '>':
// case '/': // 8.2.4.37 seems to allow foo=/ as a valid attr.
$this->parseError("Expected attribute value, got tag end.");
return null;
case '=':
case '`':
$this->parseError("Expecting quotes, got %s.", $tok);
return $this->unquotedAttributeValue();
default:
return $this->unquotedAttributeValue();
}
} | [
"protected",
"function",
"attributeValue",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'='",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// 8.1.2.3",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"switch",
"(",
"$",
"tok",
")",
"{",
"case",
"\"\\n\"",
":",
"case",
"\"\\f\"",
":",
"case",
"\" \"",
":",
"case",
"\"\\t\"",
":",
"// Whitespace here indicates an empty value.",
"return",
"null",
";",
"case",
"'\"'",
":",
"case",
"\"'\"",
":",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"$",
"this",
"->",
"quotedAttributeValue",
"(",
"$",
"tok",
")",
";",
"case",
"'>'",
":",
"// case '/': // 8.2.4.37 seems to allow foo=/ as a valid attr.",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected attribute value, got tag end.\"",
")",
";",
"return",
"null",
";",
"case",
"'='",
":",
"case",
"'`'",
":",
"$",
"this",
"->",
"parseError",
"(",
"\"Expecting quotes, got %s.\"",
",",
"$",
"tok",
")",
";",
"return",
"$",
"this",
"->",
"unquotedAttributeValue",
"(",
")",
";",
"default",
":",
"return",
"$",
"this",
"->",
"unquotedAttributeValue",
"(",
")",
";",
"}",
"}"
] | Consume an attribute value.
8.2.4.37 and after. | [
"Consume",
"an",
"attribute",
"value",
".",
"8",
".",
"2",
".",
"4",
".",
"37",
"and",
"after",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L537-L568 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.quotedAttributeValue | protected function quotedAttributeValue($quote) {
$stoplist = "\f" . $quote;
$val = '';
$tok = $this->scanner->current();
while (strspn($tok, $stoplist) == 0 && $tok !== false) {
if ($tok == '&') {
$val .= $this->decodeCharacterReference(true);
$tok = $this->scanner->current();
} else {
$val .= $tok;
$tok = $this->scanner->next();
}
}
$this->scanner->next();
return $val;
} | php | protected function quotedAttributeValue($quote) {
$stoplist = "\f" . $quote;
$val = '';
$tok = $this->scanner->current();
while (strspn($tok, $stoplist) == 0 && $tok !== false) {
if ($tok == '&') {
$val .= $this->decodeCharacterReference(true);
$tok = $this->scanner->current();
} else {
$val .= $tok;
$tok = $this->scanner->next();
}
}
$this->scanner->next();
return $val;
} | [
"protected",
"function",
"quotedAttributeValue",
"(",
"$",
"quote",
")",
"{",
"$",
"stoplist",
"=",
"\"\\f\"",
".",
"$",
"quote",
";",
"$",
"val",
"=",
"''",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"while",
"(",
"strspn",
"(",
"$",
"tok",
",",
"$",
"stoplist",
")",
"==",
"0",
"&&",
"$",
"tok",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"tok",
"==",
"'&'",
")",
"{",
"$",
"val",
".=",
"$",
"this",
"->",
"decodeCharacterReference",
"(",
"true",
")",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"}",
"else",
"{",
"$",
"val",
".=",
"$",
"tok",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"$",
"val",
";",
"}"
] | Get an attribute value string.
@param string $quote
IMPORTANT: This is a series of chars! Any one of which will be considered
termination of an attribute's value. E.g. "\"'" will stop at either
' or ".
@return string The attribute value. | [
"Get",
"an",
"attribute",
"value",
"string",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L579-L594 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.bogusComment | protected function bogusComment($leading = '') {
// TODO: This can be done more efficiently when the
// scanner exposes a readUntil() method.
$comment = $leading;
$tok = $this->scanner->current();
do {
$comment .= $tok;
$tok = $this->scanner->next();
} while ($tok !== false && $tok != '>');
$this->flushBuffer();
$this->events->comment($comment . $tok);
$this->scanner->next();
return true;
} | php | protected function bogusComment($leading = '') {
// TODO: This can be done more efficiently when the
// scanner exposes a readUntil() method.
$comment = $leading;
$tok = $this->scanner->current();
do {
$comment .= $tok;
$tok = $this->scanner->next();
} while ($tok !== false && $tok != '>');
$this->flushBuffer();
$this->events->comment($comment . $tok);
$this->scanner->next();
return true;
} | [
"protected",
"function",
"bogusComment",
"(",
"$",
"leading",
"=",
"''",
")",
"{",
"// TODO: This can be done more efficiently when the",
"// scanner exposes a readUntil() method.",
"$",
"comment",
"=",
"$",
"leading",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"do",
"{",
"$",
"comment",
".=",
"$",
"tok",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"while",
"(",
"$",
"tok",
"!==",
"false",
"&&",
"$",
"tok",
"!=",
"'>'",
")",
";",
"$",
"this",
"->",
"flushBuffer",
"(",
")",
";",
"$",
"this",
"->",
"events",
"->",
"comment",
"(",
"$",
"comment",
".",
"$",
"tok",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Consume malformed markup as if it were a comment.
8.2.4.44
The spec requires that the ENTIRE tag-like thing be enclosed inside of
the comment. So this will generate comments like:
<!--</+foo>-->
@param string $leading
Prepend any leading characters. This essentially
negates the need to backtrack, but it's sort of
a hack. | [
"Consume",
"malformed",
"markup",
"as",
"if",
"it",
"were",
"a",
"comment",
".",
"8",
".",
"2",
".",
"4",
".",
"44"
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L629-L645 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.comment | protected function comment() {
$tok = $this->scanner->current();
$comment = '';
// <!-->. Emit an empty comment because 8.2.4.46 says to.
if ($tok == '>') {
// Parse error. Emit the comment token.
$this->parseError("Expected comment data, got '>'");
$this->events->comment('');
$this->scanner->next();
return true;
}
// Replace NULL with the replacement char.
if ($tok == "\0") {
$tok = HTML5_Parser_UTF8Utils::FFFD;
}
while (!$this->isCommentEnd()) {
$comment .= $tok;
$tok = $this->scanner->next();
}
$this->events->comment($comment);
$this->scanner->next();
return true;
} | php | protected function comment() {
$tok = $this->scanner->current();
$comment = '';
// <!-->. Emit an empty comment because 8.2.4.46 says to.
if ($tok == '>') {
// Parse error. Emit the comment token.
$this->parseError("Expected comment data, got '>'");
$this->events->comment('');
$this->scanner->next();
return true;
}
// Replace NULL with the replacement char.
if ($tok == "\0") {
$tok = HTML5_Parser_UTF8Utils::FFFD;
}
while (!$this->isCommentEnd()) {
$comment .= $tok;
$tok = $this->scanner->next();
}
$this->events->comment($comment);
$this->scanner->next();
return true;
} | [
"protected",
"function",
"comment",
"(",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"$",
"comment",
"=",
"''",
";",
"// <!-->. Emit an empty comment because 8.2.4.46 says to.",
"if",
"(",
"$",
"tok",
"==",
"'>'",
")",
"{",
"// Parse error. Emit the comment token.",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected comment data, got '>'\"",
")",
";",
"$",
"this",
"->",
"events",
"->",
"comment",
"(",
"''",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}",
"// Replace NULL with the replacement char.",
"if",
"(",
"$",
"tok",
"==",
"\"\\0\"",
")",
"{",
"$",
"tok",
"=",
"HTML5_Parser_UTF8Utils",
"::",
"FFFD",
";",
"}",
"while",
"(",
"!",
"$",
"this",
"->",
"isCommentEnd",
"(",
")",
")",
"{",
"$",
"comment",
".=",
"$",
"tok",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"$",
"this",
"->",
"events",
"->",
"comment",
"(",
"$",
"comment",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Read a comment.
Expects the first tok to be inside of the comment. | [
"Read",
"a",
"comment",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L652-L677 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.isCommentEnd | protected function isCommentEnd() {
// EOF
if ($this->scanner->current() === false) {
// Hit the end.
$this->parseError("Unexpected EOF in a comment.");
return true;
}
// If it doesn't start with -, not the end.
if ($this->scanner->current() != '-') {
return false;
}
// Advance one, and test for '->'
if ($this->scanner->next() == '-' && $this->scanner->peek() == '>') {
$this->scanner->next(); // Consume the last '>'
return true;
}
// Unread '-';
$this->scanner->unconsume(1);
return false;
} | php | protected function isCommentEnd() {
// EOF
if ($this->scanner->current() === false) {
// Hit the end.
$this->parseError("Unexpected EOF in a comment.");
return true;
}
// If it doesn't start with -, not the end.
if ($this->scanner->current() != '-') {
return false;
}
// Advance one, and test for '->'
if ($this->scanner->next() == '-' && $this->scanner->peek() == '>') {
$this->scanner->next(); // Consume the last '>'
return true;
}
// Unread '-';
$this->scanner->unconsume(1);
return false;
} | [
"protected",
"function",
"isCommentEnd",
"(",
")",
"{",
"// EOF",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"===",
"false",
")",
"{",
"// Hit the end.",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected EOF in a comment.\"",
")",
";",
"return",
"true",
";",
"}",
"// If it doesn't start with -, not the end.",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'-'",
")",
"{",
"return",
"false",
";",
"}",
"// Advance one, and test for '->'",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
"==",
"'-'",
"&&",
"$",
"this",
"->",
"scanner",
"->",
"peek",
"(",
")",
"==",
"'>'",
")",
"{",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// Consume the last '>'",
"return",
"true",
";",
"}",
"// Unread '-';",
"$",
"this",
"->",
"scanner",
"->",
"unconsume",
"(",
"1",
")",
";",
"return",
"false",
";",
"}"
] | Check if the scanner has reached the end of a comment. | [
"Check",
"if",
"the",
"scanner",
"has",
"reached",
"the",
"end",
"of",
"a",
"comment",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L682-L703 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.doctype | protected function doctype() {
if (strcasecmp($this->scanner->current(), 'D')) {
return false;
}
// Check that string is DOCTYPE.
$chars = $this->scanner->charsWhile("DOCTYPEdoctype");
if (strcasecmp($chars, 'DOCTYPE')) {
$this->parseError('Expected DOCTYPE, got %s', $chars);
return $this->bogusComment('<!' . $chars);
}
$this->scanner->whitespace();
$tok = $this->scanner->current();
// EOF: die.
if ($tok === false) {
$this->events->doctype('html5', HTML5_Parser_EventHandler::DOCTYPE_NONE, '', true);
return $this->eof();
}
$doctypeName = '';
// NULL char: convert.
if ($tok === "\0") {
$this->parseError("Unexpected null character in DOCTYPE.");
$doctypeName .= UTF8::FFFD;
$tok = $this->scanner->next();
}
$stop = " \n\f>";
$doctypeName = $this->scanner->charsUntil($stop);
// Lowercase ASCII, replace \0 with FFFD
$doctypeName = strtolower(strtr($doctypeName, "\0", HTML5_Parser_UTF8Utils::FFFD));
$tok = $this->scanner->current();
// If false, emit a parse error, DOCTYPE, and return.
if ($tok === false) {
$this->parseError('Unexpected EOF in DOCTYPE declaration.');
$this->events->doctype($doctypeName, HTML5_Parser_EventHandler::DOCTYPE_NONE, null, true);
return true;
}
// Short DOCTYPE, like <!DOCTYPE html>
if ($tok == '>') {
// DOCTYPE without a name.
if (strlen($doctypeName) == 0) {
$this->parseError("Expected a DOCTYPE name. Got nothing.");
$this->events->doctype($doctypeName, 0, null, true);
$this->scanner->next();
return true;
}
$this->events->doctype($doctypeName);
$this->scanner->next();
return true;
}
$this->scanner->whitespace();
$pub = strtoupper($this->scanner->getAsciiAlpha());
$white = strlen($this->scanner->whitespace());
$tok = $this->scanner->current();
// Get ID, and flag it as pub or system.
if (($pub == 'PUBLIC' || $pub == 'SYSTEM') && $white > 0) {
// Get the sys ID.
$type = $pub == 'PUBLIC' ? HTML5_Parser_EventHandler::DOCTYPE_PUBLIC : HTML5_Parser_EventHandler::DOCTYPE_SYSTEM;
$id = $this->quotedString("\0>");
if ($id === false) {
$this->events->doctype($doctypeName, $type, $pub, false);
return false;
}
// Premature EOF.
if ($this->scanner->current() === false) {
$this->parseError("Unexpected EOF in DOCTYPE");
$this->events->doctype($doctypeName, $type, $id, true);
return true;
}
// Well-formed complete DOCTYPE.
$this->scanner->whitespace();
if ($this->scanner->current() == '>') {
$this->events->doctype($doctypeName, $type, $id, false);
$this->scanner->next();
return true;
}
// If we get here, we have <!DOCTYPE foo PUBLIC "bar" SOME_JUNK
// Throw away the junk, parse error, quirks mode, return true.
$this->scanner->charsUntil(">");
$this->parseError("Malformed DOCTYPE.");
$this->events->doctype($doctypeName, $type, $id, true);
$this->scanner->next();
return true;
}
// Else it's a bogus DOCTYPE.
// Consume to > and trash.
$this->scanner->charsUntil('>');
$this->parseError("Expected PUBLIC or SYSTEM. Got %s.", $pub);
$this->events->doctype($doctypeName, 0, null, true);
$this->scanner->next();
return true;
} | php | protected function doctype() {
if (strcasecmp($this->scanner->current(), 'D')) {
return false;
}
// Check that string is DOCTYPE.
$chars = $this->scanner->charsWhile("DOCTYPEdoctype");
if (strcasecmp($chars, 'DOCTYPE')) {
$this->parseError('Expected DOCTYPE, got %s', $chars);
return $this->bogusComment('<!' . $chars);
}
$this->scanner->whitespace();
$tok = $this->scanner->current();
// EOF: die.
if ($tok === false) {
$this->events->doctype('html5', HTML5_Parser_EventHandler::DOCTYPE_NONE, '', true);
return $this->eof();
}
$doctypeName = '';
// NULL char: convert.
if ($tok === "\0") {
$this->parseError("Unexpected null character in DOCTYPE.");
$doctypeName .= UTF8::FFFD;
$tok = $this->scanner->next();
}
$stop = " \n\f>";
$doctypeName = $this->scanner->charsUntil($stop);
// Lowercase ASCII, replace \0 with FFFD
$doctypeName = strtolower(strtr($doctypeName, "\0", HTML5_Parser_UTF8Utils::FFFD));
$tok = $this->scanner->current();
// If false, emit a parse error, DOCTYPE, and return.
if ($tok === false) {
$this->parseError('Unexpected EOF in DOCTYPE declaration.');
$this->events->doctype($doctypeName, HTML5_Parser_EventHandler::DOCTYPE_NONE, null, true);
return true;
}
// Short DOCTYPE, like <!DOCTYPE html>
if ($tok == '>') {
// DOCTYPE without a name.
if (strlen($doctypeName) == 0) {
$this->parseError("Expected a DOCTYPE name. Got nothing.");
$this->events->doctype($doctypeName, 0, null, true);
$this->scanner->next();
return true;
}
$this->events->doctype($doctypeName);
$this->scanner->next();
return true;
}
$this->scanner->whitespace();
$pub = strtoupper($this->scanner->getAsciiAlpha());
$white = strlen($this->scanner->whitespace());
$tok = $this->scanner->current();
// Get ID, and flag it as pub or system.
if (($pub == 'PUBLIC' || $pub == 'SYSTEM') && $white > 0) {
// Get the sys ID.
$type = $pub == 'PUBLIC' ? HTML5_Parser_EventHandler::DOCTYPE_PUBLIC : HTML5_Parser_EventHandler::DOCTYPE_SYSTEM;
$id = $this->quotedString("\0>");
if ($id === false) {
$this->events->doctype($doctypeName, $type, $pub, false);
return false;
}
// Premature EOF.
if ($this->scanner->current() === false) {
$this->parseError("Unexpected EOF in DOCTYPE");
$this->events->doctype($doctypeName, $type, $id, true);
return true;
}
// Well-formed complete DOCTYPE.
$this->scanner->whitespace();
if ($this->scanner->current() == '>') {
$this->events->doctype($doctypeName, $type, $id, false);
$this->scanner->next();
return true;
}
// If we get here, we have <!DOCTYPE foo PUBLIC "bar" SOME_JUNK
// Throw away the junk, parse error, quirks mode, return true.
$this->scanner->charsUntil(">");
$this->parseError("Malformed DOCTYPE.");
$this->events->doctype($doctypeName, $type, $id, true);
$this->scanner->next();
return true;
}
// Else it's a bogus DOCTYPE.
// Consume to > and trash.
$this->scanner->charsUntil('>');
$this->parseError("Expected PUBLIC or SYSTEM. Got %s.", $pub);
$this->events->doctype($doctypeName, 0, null, true);
$this->scanner->next();
return true;
} | [
"protected",
"function",
"doctype",
"(",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
",",
"'D'",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Check that string is DOCTYPE.",
"$",
"chars",
"=",
"$",
"this",
"->",
"scanner",
"->",
"charsWhile",
"(",
"\"DOCTYPEdoctype\"",
")",
";",
"if",
"(",
"strcasecmp",
"(",
"$",
"chars",
",",
"'DOCTYPE'",
")",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"'Expected DOCTYPE, got %s'",
",",
"$",
"chars",
")",
";",
"return",
"$",
"this",
"->",
"bogusComment",
"(",
"'<!'",
".",
"$",
"chars",
")",
";",
"}",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"// EOF: die.",
"if",
"(",
"$",
"tok",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"'html5'",
",",
"HTML5_Parser_EventHandler",
"::",
"DOCTYPE_NONE",
",",
"''",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"eof",
"(",
")",
";",
"}",
"$",
"doctypeName",
"=",
"''",
";",
"// NULL char: convert.",
"if",
"(",
"$",
"tok",
"===",
"\"\\0\"",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected null character in DOCTYPE.\"",
")",
";",
"$",
"doctypeName",
".=",
"UTF8",
"::",
"FFFD",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"$",
"stop",
"=",
"\" \\n\\f>\"",
";",
"$",
"doctypeName",
"=",
"$",
"this",
"->",
"scanner",
"->",
"charsUntil",
"(",
"$",
"stop",
")",
";",
"// Lowercase ASCII, replace \\0 with FFFD",
"$",
"doctypeName",
"=",
"strtolower",
"(",
"strtr",
"(",
"$",
"doctypeName",
",",
"\"\\0\"",
",",
"HTML5_Parser_UTF8Utils",
"::",
"FFFD",
")",
")",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"// If false, emit a parse error, DOCTYPE, and return.",
"if",
"(",
"$",
"tok",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"'Unexpected EOF in DOCTYPE declaration.'",
")",
";",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"$",
"doctypeName",
",",
"HTML5_Parser_EventHandler",
"::",
"DOCTYPE_NONE",
",",
"null",
",",
"true",
")",
";",
"return",
"true",
";",
"}",
"// Short DOCTYPE, like <!DOCTYPE html>",
"if",
"(",
"$",
"tok",
"==",
"'>'",
")",
"{",
"// DOCTYPE without a name.",
"if",
"(",
"strlen",
"(",
"$",
"doctypeName",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected a DOCTYPE name. Got nothing.\"",
")",
";",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"$",
"doctypeName",
",",
"0",
",",
"null",
",",
"true",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"$",
"doctypeName",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
";",
"$",
"pub",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"scanner",
"->",
"getAsciiAlpha",
"(",
")",
")",
";",
"$",
"white",
"=",
"strlen",
"(",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
")",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"// Get ID, and flag it as pub or system.",
"if",
"(",
"(",
"$",
"pub",
"==",
"'PUBLIC'",
"||",
"$",
"pub",
"==",
"'SYSTEM'",
")",
"&&",
"$",
"white",
">",
"0",
")",
"{",
"// Get the sys ID.",
"$",
"type",
"=",
"$",
"pub",
"==",
"'PUBLIC'",
"?",
"HTML5_Parser_EventHandler",
"::",
"DOCTYPE_PUBLIC",
":",
"HTML5_Parser_EventHandler",
"::",
"DOCTYPE_SYSTEM",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"quotedString",
"(",
"\"\\0>\"",
")",
";",
"if",
"(",
"$",
"id",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"$",
"doctypeName",
",",
"$",
"type",
",",
"$",
"pub",
",",
"false",
")",
";",
"return",
"false",
";",
"}",
"// Premature EOF.",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected EOF in DOCTYPE\"",
")",
";",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"$",
"doctypeName",
",",
"$",
"type",
",",
"$",
"id",
",",
"true",
")",
";",
"return",
"true",
";",
"}",
"// Well-formed complete DOCTYPE.",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"==",
"'>'",
")",
"{",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"$",
"doctypeName",
",",
"$",
"type",
",",
"$",
"id",
",",
"false",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}",
"// If we get here, we have <!DOCTYPE foo PUBLIC \"bar\" SOME_JUNK",
"// Throw away the junk, parse error, quirks mode, return true.",
"$",
"this",
"->",
"scanner",
"->",
"charsUntil",
"(",
"\">\"",
")",
";",
"$",
"this",
"->",
"parseError",
"(",
"\"Malformed DOCTYPE.\"",
")",
";",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"$",
"doctypeName",
",",
"$",
"type",
",",
"$",
"id",
",",
"true",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}",
"// Else it's a bogus DOCTYPE.",
"// Consume to > and trash.",
"$",
"this",
"->",
"scanner",
"->",
"charsUntil",
"(",
"'>'",
")",
";",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected PUBLIC or SYSTEM. Got %s.\"",
",",
"$",
"pub",
")",
";",
"$",
"this",
"->",
"events",
"->",
"doctype",
"(",
"$",
"doctypeName",
",",
"0",
",",
"null",
",",
"true",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Parse a DOCTYPE.
Parse a DOCTYPE declaration. This method has strong bearing on whether or
not Quirksmode is enabled on the event handler.
@todo This method is a little long. Should probably refactor. | [
"Parse",
"a",
"DOCTYPE",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L713-L817 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.quotedString | protected function quotedString($stopchars) {
$tok = $this->scanner->current();
if ($tok == '"' || $tok == "'") {
$this->scanner->next();
$ret = $this->scanner->charsUntil($tok . $stopchars);
if ($this->scanner->current() == $tok) {
$this->scanner->next();
} else {
// Parse error because no close quote.
$this->parseError("Expected %s, got %s", $tok, $this->scanner->current());
}
return $ret;
}
return false;
} | php | protected function quotedString($stopchars) {
$tok = $this->scanner->current();
if ($tok == '"' || $tok == "'") {
$this->scanner->next();
$ret = $this->scanner->charsUntil($tok . $stopchars);
if ($this->scanner->current() == $tok) {
$this->scanner->next();
} else {
// Parse error because no close quote.
$this->parseError("Expected %s, got %s", $tok, $this->scanner->current());
}
return $ret;
}
return false;
} | [
"protected",
"function",
"quotedString",
"(",
"$",
"stopchars",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"if",
"(",
"$",
"tok",
"==",
"'\"'",
"||",
"$",
"tok",
"==",
"\"'\"",
")",
"{",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"$",
"ret",
"=",
"$",
"this",
"->",
"scanner",
"->",
"charsUntil",
"(",
"$",
"tok",
".",
"$",
"stopchars",
")",
";",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"==",
"$",
"tok",
")",
"{",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"else",
"{",
"// Parse error because no close quote.",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected %s, got %s\"",
",",
"$",
"tok",
",",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}",
"return",
"false",
";",
"}"
] | Utility for reading a quoted string.
@param string $stopchars
Characters (in addition to a close-quote) that should stop the string.
E.g. sometimes '>' is higher precedence than '"' or "'".
@return mixed String if one is found (quotations omitted) | [
"Utility",
"for",
"reading",
"a",
"quoted",
"string",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L827-L841 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.cdataSection | protected function cdataSection() {
if ($this->scanner->current() != '[') {
return false;
}
$cdata = '';
$this->scanner->next();
$chars = $this->scanner->charsWhile('CDAT');
if ($chars != 'CDATA' || $this->scanner->current() != '[') {
$this->parseError('Expected [CDATA[, got %s', $chars);
return $this->bogusComment('<![' . $chars);
}
$tok = $this->scanner->next();
do {
if ($tok === false) {
$this->parseError('Unexpected EOF inside CDATA.');
$this->bogusComment('<![CDATA[' . $cdata);
return true;
}
$cdata .= $tok;
$tok = $this->scanner->next();
} while (!$this->sequenceMatches(']]>'));
// Consume ]]>
$this->scanner->consume(3);
$this->events->cdata($cdata);
return true;
} | php | protected function cdataSection() {
if ($this->scanner->current() != '[') {
return false;
}
$cdata = '';
$this->scanner->next();
$chars = $this->scanner->charsWhile('CDAT');
if ($chars != 'CDATA' || $this->scanner->current() != '[') {
$this->parseError('Expected [CDATA[, got %s', $chars);
return $this->bogusComment('<![' . $chars);
}
$tok = $this->scanner->next();
do {
if ($tok === false) {
$this->parseError('Unexpected EOF inside CDATA.');
$this->bogusComment('<![CDATA[' . $cdata);
return true;
}
$cdata .= $tok;
$tok = $this->scanner->next();
} while (!$this->sequenceMatches(']]>'));
// Consume ]]>
$this->scanner->consume(3);
$this->events->cdata($cdata);
return true;
} | [
"protected",
"function",
"cdataSection",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'['",
")",
"{",
"return",
"false",
";",
"}",
"$",
"cdata",
"=",
"''",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"$",
"chars",
"=",
"$",
"this",
"->",
"scanner",
"->",
"charsWhile",
"(",
"'CDAT'",
")",
";",
"if",
"(",
"$",
"chars",
"!=",
"'CDATA'",
"||",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'['",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"'Expected [CDATA[, got %s'",
",",
"$",
"chars",
")",
";",
"return",
"$",
"this",
"->",
"bogusComment",
"(",
"'<!['",
".",
"$",
"chars",
")",
";",
"}",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"do",
"{",
"if",
"(",
"$",
"tok",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"'Unexpected EOF inside CDATA.'",
")",
";",
"$",
"this",
"->",
"bogusComment",
"(",
"'<![CDATA['",
".",
"$",
"cdata",
")",
";",
"return",
"true",
";",
"}",
"$",
"cdata",
".=",
"$",
"tok",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"while",
"(",
"!",
"$",
"this",
"->",
"sequenceMatches",
"(",
"']]>'",
")",
")",
";",
"// Consume ]]>",
"$",
"this",
"->",
"scanner",
"->",
"consume",
"(",
"3",
")",
";",
"$",
"this",
"->",
"events",
"->",
"cdata",
"(",
"$",
"cdata",
")",
";",
"return",
"true",
";",
"}"
] | Handle a CDATA section. | [
"Handle",
"a",
"CDATA",
"section",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L846-L875 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.processingInstruction | protected function processingInstruction() {
if ($this->scanner->current() != '?') {
return false;
}
$tok = $this->scanner->next();
$procName = $this->scanner->getAsciiAlpha();
$white = strlen($this->scanner->whitespace());
// If not a PI, send to bogusComment.
if (strlen($procName) == 0 || $white == 0 || $this->scanner->current() == false) {
$this->parseError("Expected processing instruction name, got $tok");
$this->bogusComment('<?' . $tok . $procName);
return true;
}
$data = '';
// As long as it's not the case that the next two chars are ? and >.
while (!($this->scanner->current() == '?' && $this->scanner->peek() == '>')) {
$data .= $this->scanner->current();
$tok = $this->scanner->next();
if ($tok === false) {
$this->parseError("Unexpected EOF in processing instruction.");
$this->events->processingInstruction($procName, $data);
return true;
}
}
$this->scanner->next(); // >
$this->scanner->next(); // Next token.
$this->events->processingInstruction($procName, $data);
return true;
} | php | protected function processingInstruction() {
if ($this->scanner->current() != '?') {
return false;
}
$tok = $this->scanner->next();
$procName = $this->scanner->getAsciiAlpha();
$white = strlen($this->scanner->whitespace());
// If not a PI, send to bogusComment.
if (strlen($procName) == 0 || $white == 0 || $this->scanner->current() == false) {
$this->parseError("Expected processing instruction name, got $tok");
$this->bogusComment('<?' . $tok . $procName);
return true;
}
$data = '';
// As long as it's not the case that the next two chars are ? and >.
while (!($this->scanner->current() == '?' && $this->scanner->peek() == '>')) {
$data .= $this->scanner->current();
$tok = $this->scanner->next();
if ($tok === false) {
$this->parseError("Unexpected EOF in processing instruction.");
$this->events->processingInstruction($procName, $data);
return true;
}
}
$this->scanner->next(); // >
$this->scanner->next(); // Next token.
$this->events->processingInstruction($procName, $data);
return true;
} | [
"protected",
"function",
"processingInstruction",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!=",
"'?'",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"$",
"procName",
"=",
"$",
"this",
"->",
"scanner",
"->",
"getAsciiAlpha",
"(",
")",
";",
"$",
"white",
"=",
"strlen",
"(",
"$",
"this",
"->",
"scanner",
"->",
"whitespace",
"(",
")",
")",
";",
"// If not a PI, send to bogusComment.",
"if",
"(",
"strlen",
"(",
"$",
"procName",
")",
"==",
"0",
"||",
"$",
"white",
"==",
"0",
"||",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"==",
"false",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Expected processing instruction name, got $tok\"",
")",
";",
"$",
"this",
"->",
"bogusComment",
"(",
"'<?'",
".",
"$",
"tok",
".",
"$",
"procName",
")",
";",
"return",
"true",
";",
"}",
"$",
"data",
"=",
"''",
";",
"// As long as it's not the case that the next two chars are ? and >.",
"while",
"(",
"!",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"==",
"'?'",
"&&",
"$",
"this",
"->",
"scanner",
"->",
"peek",
"(",
")",
"==",
"'>'",
")",
")",
"{",
"$",
"data",
".=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"$",
"tok",
"=",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"if",
"(",
"$",
"tok",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected EOF in processing instruction.\"",
")",
";",
"$",
"this",
"->",
"events",
"->",
"processingInstruction",
"(",
"$",
"procName",
",",
"$",
"data",
")",
";",
"return",
"true",
";",
"}",
"}",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// >",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"// Next token.",
"$",
"this",
"->",
"events",
"->",
"processingInstruction",
"(",
"$",
"procName",
",",
"$",
"data",
")",
";",
"return",
"true",
";",
"}"
] | Handle a processing instruction.
XML processing instructions are supposed to be ignored in HTML5,
treated as "bogus comments". However, since we're not a user
agent, we allow them. We consume until ?> and then issue a
EventListener::processingInstruction() event. | [
"Handle",
"a",
"processing",
"instruction",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L888-L921 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/Tokenizer.php | HTML5_Parser_Tokenizer.readUntilSequence | protected function readUntilSequence($sequence) {
$buffer = '';
// Optimization for reading larger blocks faster.
$first = substr($sequence, 0, 1);
while ($this->scanner->current() !== false) {
$buffer .= $this->scanner->charsUntil($first);
// Stop as soon as we hit the stopping condition.
if ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))) {
return $buffer;
}
$buffer .= $this->scanner->current();
$this->scanner->next();
}
// If we get here, we hit the EOF.
$this->parseError("Unexpected EOF during text read.");
return $buffer;
} | php | protected function readUntilSequence($sequence) {
$buffer = '';
// Optimization for reading larger blocks faster.
$first = substr($sequence, 0, 1);
while ($this->scanner->current() !== false) {
$buffer .= $this->scanner->charsUntil($first);
// Stop as soon as we hit the stopping condition.
if ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))) {
return $buffer;
}
$buffer .= $this->scanner->current();
$this->scanner->next();
}
// If we get here, we hit the EOF.
$this->parseError("Unexpected EOF during text read.");
return $buffer;
} | [
"protected",
"function",
"readUntilSequence",
"(",
"$",
"sequence",
")",
"{",
"$",
"buffer",
"=",
"''",
";",
"// Optimization for reading larger blocks faster.",
"$",
"first",
"=",
"substr",
"(",
"$",
"sequence",
",",
"0",
",",
"1",
")",
";",
"while",
"(",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
"!==",
"false",
")",
"{",
"$",
"buffer",
".=",
"$",
"this",
"->",
"scanner",
"->",
"charsUntil",
"(",
"$",
"first",
")",
";",
"// Stop as soon as we hit the stopping condition.",
"if",
"(",
"$",
"this",
"->",
"sequenceMatches",
"(",
"$",
"sequence",
")",
"||",
"$",
"this",
"->",
"sequenceMatches",
"(",
"strtoupper",
"(",
"$",
"sequence",
")",
")",
")",
"{",
"return",
"$",
"buffer",
";",
"}",
"$",
"buffer",
".=",
"$",
"this",
"->",
"scanner",
"->",
"current",
"(",
")",
";",
"$",
"this",
"->",
"scanner",
"->",
"next",
"(",
")",
";",
"}",
"// If we get here, we hit the EOF.",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected EOF during text read.\"",
")",
";",
"return",
"$",
"buffer",
";",
"}"
] | Read from the input stream until we get to the desired sequene
or hit the end of the input stream. | [
"Read",
"from",
"the",
"input",
"stream",
"until",
"we",
"get",
"to",
"the",
"desired",
"sequene",
"or",
"hit",
"the",
"end",
"of",
"the",
"input",
"stream",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L931-L950 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.