repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Transformer/Router/UrlGenerator/Standard/QualifiedNameToUrlConverter.php | QualifiedNameToUrlConverter.removeFileExtensionFromPath | private function removeFileExtensionFromPath($path)
{
if (strrpos($path, '.') !== false) {
$path = substr($path, 0, strrpos($path, '.'));
}
return $path;
} | php | private function removeFileExtensionFromPath($path)
{
if (strrpos($path, '.') !== false) {
$path = substr($path, 0, strrpos($path, '.'));
}
return $path;
} | [
"private",
"function",
"removeFileExtensionFromPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"strrpos",
"(",
"$",
"path",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"strrpos",
"(",
"$",
"path",
",",
"'.'",
")",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Removes the file extension from the provided path.
@param string $path
@return string | [
"Removes",
"the",
"file",
"extension",
"from",
"the",
"provided",
"path",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Transformer/Router/UrlGenerator/Standard/QualifiedNameToUrlConverter.php#L94-L101 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/CommandlineOptionsMiddleware.php | CommandlineOptionsMiddleware.disableCache | private function disableCache(array $configuration): array
{
if (isset($this->options['force']) && $this->options['force']) {
$configuration['phpdocumentor']['use-cache'] = false;
}
return $configuration;
} | php | private function disableCache(array $configuration): array
{
if (isset($this->options['force']) && $this->options['force']) {
$configuration['phpdocumentor']['use-cache'] = false;
}
return $configuration;
} | [
"private",
"function",
"disableCache",
"(",
"array",
"$",
"configuration",
")",
":",
"array",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'force'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'force'",
"]",
")",
"{",
"$",
"configuration",
"[",
"'phpdocumentor'",
"]",
"[",
"'use-cache'",
"]",
"=",
"false",
";",
"}",
"return",
"$",
"configuration",
";",
"}"
] | Changes the given configuration array so that the cache handling is disabled. | [
"Changes",
"the",
"given",
"configuration",
"array",
"so",
"that",
"the",
"cache",
"handling",
"is",
"disabled",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/CommandlineOptionsMiddleware.php#L69-L76 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/CommandlineOptionsMiddleware.php | CommandlineOptionsMiddleware.overwriteTemplates | private function overwriteTemplates(array $configuration): array
{
if (isset($this->options['template']) && $this->options['template']) {
$configuration['phpdocumentor']['templates'] = array_map(
function ($templateName) {
return ['name' => $templateName];
},
(array)$this->options['template']
);
}
return $configuration;
} | php | private function overwriteTemplates(array $configuration): array
{
if (isset($this->options['template']) && $this->options['template']) {
$configuration['phpdocumentor']['templates'] = array_map(
function ($templateName) {
return ['name' => $templateName];
},
(array)$this->options['template']
);
}
return $configuration;
} | [
"private",
"function",
"overwriteTemplates",
"(",
"array",
"$",
"configuration",
")",
":",
"array",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'template'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'template'",
"]",
")",
"{",
"$",
"configuration",
"[",
"'phpdocumentor'",
"]",
"[",
"'templates'",
"]",
"=",
"array_map",
"(",
"function",
"(",
"$",
"templateName",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"templateName",
"]",
";",
"}",
",",
"(",
"array",
")",
"$",
"this",
"->",
"options",
"[",
"'template'",
"]",
")",
";",
"}",
"return",
"$",
"configuration",
";",
"}"
] | Changes the given configuration array to feature the templates from the options. | [
"Changes",
"the",
"given",
"configuration",
"array",
"to",
"feature",
"the",
"templates",
"from",
"the",
"options",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/CommandlineOptionsMiddleware.php#L99-L111 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Filter/Filter.php | Filter.filter | public function filter(Filterable $descriptor): ?Filterable
{
$chain = $this->factory->getChainFor(get_class($descriptor));
return $chain->filter($descriptor);
} | php | public function filter(Filterable $descriptor): ?Filterable
{
$chain = $this->factory->getChainFor(get_class($descriptor));
return $chain->filter($descriptor);
} | [
"public",
"function",
"filter",
"(",
"Filterable",
"$",
"descriptor",
")",
":",
"?",
"Filterable",
"{",
"$",
"chain",
"=",
"$",
"this",
"->",
"factory",
"->",
"getChainFor",
"(",
"get_class",
"(",
"$",
"descriptor",
")",
")",
";",
"return",
"$",
"chain",
"->",
"filter",
"(",
"$",
"descriptor",
")",
";",
"}"
] | Filters the given Descriptor and returns the altered object. | [
"Filters",
"the",
"given",
"Descriptor",
"and",
"returns",
"the",
"altered",
"object",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Filter/Filter.php#L76-L81 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Plugin/Scrybe/Converter/Format/Collection.php | Collection.offsetGet | public function offsetGet($index)
{
if (!$this->offsetExists($index)) {
throw new Exception\FormatNotFoundException('Format ' . $index . ' is not known');
}
return parent::offsetGet($index);
} | php | public function offsetGet($index)
{
if (!$this->offsetExists($index)) {
throw new Exception\FormatNotFoundException('Format ' . $index . ' is not known');
}
return parent::offsetGet($index);
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"index",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FormatNotFoundException",
"(",
"'Format '",
".",
"$",
"index",
".",
"' is not known'",
")",
";",
"}",
"return",
"parent",
"::",
"offsetGet",
"(",
"$",
"index",
")",
";",
"}"
] | Finds a format by the given name or throws an exception if that index is not found.
@param string $index
@throws Exception\FormatNotFoundException if the given format index was not found.
@return Format | [
"Finds",
"a",
"format",
"by",
"the",
"given",
"name",
"or",
"throws",
"an",
"exception",
"if",
"that",
"index",
"is",
"not",
"found",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Scrybe/Converter/Format/Collection.php#L54-L61 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildArrayFromNode | private function buildArrayFromNode(SimpleXMLElement $node): array
{
$array = [];
foreach ($node->children() as $child) {
if ((string) $child !== '') {
$array[] = (string) $child;
}
}
return $array;
} | php | private function buildArrayFromNode(SimpleXMLElement $node): array
{
$array = [];
foreach ($node->children() as $child) {
if ((string) $child !== '') {
$array[] = (string) $child;
}
}
return $array;
} | [
"private",
"function",
"buildArrayFromNode",
"(",
"SimpleXMLElement",
"$",
"node",
")",
":",
"array",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"node",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"child",
"!==",
"''",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"(",
"string",
")",
"$",
"child",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Loops over a node and fills an array with the found children. | [
"Loops",
"over",
"a",
"node",
"and",
"fills",
"an",
"array",
"with",
"the",
"found",
"children",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L116-L126 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildExtensions | private function buildExtensions(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->parser === []) {
return $this->extensions;
}
if ((array) $phpDocumentor->parser->extensions === []) {
return $this->extensions;
}
return $this->buildArrayFromNode($phpDocumentor->parser->extensions);
} | php | private function buildExtensions(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->parser === []) {
return $this->extensions;
}
if ((array) $phpDocumentor->parser->extensions === []) {
return $this->extensions;
}
return $this->buildArrayFromNode($phpDocumentor->parser->extensions);
} | [
"private",
"function",
"buildExtensions",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"array",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"parser",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"extensions",
";",
"}",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"parser",
"->",
"extensions",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"extensions",
";",
"}",
"return",
"$",
"this",
"->",
"buildArrayFromNode",
"(",
"$",
"phpDocumentor",
"->",
"parser",
"->",
"extensions",
")",
";",
"}"
] | Builds the extensions part of the array from the configuration xml.
@return string[] | [
"Builds",
"the",
"extensions",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L133-L144 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildMarkers | private function buildMarkers(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->parser === []) {
return $this->markers;
}
if ((array) $phpDocumentor->parser->markers === []) {
return $this->markers;
}
return $this->buildArrayFromNode($phpDocumentor->parser->markers);
} | php | private function buildMarkers(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->parser === []) {
return $this->markers;
}
if ((array) $phpDocumentor->parser->markers === []) {
return $this->markers;
}
return $this->buildArrayFromNode($phpDocumentor->parser->markers);
} | [
"private",
"function",
"buildMarkers",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"array",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"parser",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"markers",
";",
"}",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"parser",
"->",
"markers",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"markers",
";",
"}",
"return",
"$",
"this",
"->",
"buildArrayFromNode",
"(",
"$",
"phpDocumentor",
"->",
"parser",
"->",
"markers",
")",
";",
"}"
] | Builds the markers part of the array from the configuration xml.
@return string[] | [
"Builds",
"the",
"markers",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L151-L162 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildVisibility | private function buildVisibility(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->parser === []) {
return $this->visibility;
}
if ((string) $phpDocumentor->parser->visibility === '') {
return $this->visibility;
}
return explode(',', (string) $phpDocumentor->parser->visibility);
} | php | private function buildVisibility(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->parser === []) {
return $this->visibility;
}
if ((string) $phpDocumentor->parser->visibility === '') {
return $this->visibility;
}
return explode(',', (string) $phpDocumentor->parser->visibility);
} | [
"private",
"function",
"buildVisibility",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"array",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"parser",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"visibility",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"parser",
"->",
"visibility",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"visibility",
";",
"}",
"return",
"explode",
"(",
"','",
",",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"parser",
"->",
"visibility",
")",
";",
"}"
] | Builds the visibility part of the array from the configuration xml.
@return string[] | [
"Builds",
"the",
"visibility",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L169-L180 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildDefaultPackageName | private function buildDefaultPackageName(SimpleXMLElement $phpDocumentor): string
{
if ((array) $phpDocumentor->parser === []) {
return $this->defaultPackageName;
}
if ((string) $phpDocumentor->parser->{'default-package-name'} === '') {
return $this->defaultPackageName;
}
return (string) $phpDocumentor->parser->{'default-package-name'};
} | php | private function buildDefaultPackageName(SimpleXMLElement $phpDocumentor): string
{
if ((array) $phpDocumentor->parser === []) {
return $this->defaultPackageName;
}
if ((string) $phpDocumentor->parser->{'default-package-name'} === '') {
return $this->defaultPackageName;
}
return (string) $phpDocumentor->parser->{'default-package-name'};
} | [
"private",
"function",
"buildDefaultPackageName",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"string",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"parser",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"defaultPackageName",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"parser",
"->",
"{",
"'default-package-name'",
"}",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"defaultPackageName",
";",
"}",
"return",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"parser",
"->",
"{",
"'default-package-name'",
"}",
";",
"}"
] | Builds the defaultPackageName part of the array from the configuration xml. | [
"Builds",
"the",
"defaultPackageName",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L185-L196 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildIgnoreHidden | private function buildIgnoreHidden(SimpleXMLElement $phpDocumentor): bool
{
if ((array) $phpDocumentor->files === []) {
return $this->ignoreHidden;
}
if ((string) $phpDocumentor->files->{'ignore-hidden'} === '') {
return $this->ignoreHidden;
}
return filter_var($phpDocumentor->files->{'ignore-hidden'}, FILTER_VALIDATE_BOOLEAN);
} | php | private function buildIgnoreHidden(SimpleXMLElement $phpDocumentor): bool
{
if ((array) $phpDocumentor->files === []) {
return $this->ignoreHidden;
}
if ((string) $phpDocumentor->files->{'ignore-hidden'} === '') {
return $this->ignoreHidden;
}
return filter_var($phpDocumentor->files->{'ignore-hidden'}, FILTER_VALIDATE_BOOLEAN);
} | [
"private",
"function",
"buildIgnoreHidden",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"bool",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"files",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"ignoreHidden",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"files",
"->",
"{",
"'ignore-hidden'",
"}",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"ignoreHidden",
";",
"}",
"return",
"filter_var",
"(",
"$",
"phpDocumentor",
"->",
"files",
"->",
"{",
"'ignore-hidden'",
"}",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
";",
"}"
] | Builds the ignore-hidden part of the array from the configuration xml. | [
"Builds",
"the",
"ignore",
"-",
"hidden",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L217-L228 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildIgnoreSymlinks | private function buildIgnoreSymlinks(SimpleXMLElement $phpDocumentor): bool
{
if ((array) $phpDocumentor->files === []) {
return $this->ignoreSymlinks;
}
if ((string) $phpDocumentor->files->{'ignore-symlinks'} === '') {
return $this->ignoreSymlinks;
}
return filter_var($phpDocumentor->files->{'ignore-symlinks'}, FILTER_VALIDATE_BOOLEAN);
} | php | private function buildIgnoreSymlinks(SimpleXMLElement $phpDocumentor): bool
{
if ((array) $phpDocumentor->files === []) {
return $this->ignoreSymlinks;
}
if ((string) $phpDocumentor->files->{'ignore-symlinks'} === '') {
return $this->ignoreSymlinks;
}
return filter_var($phpDocumentor->files->{'ignore-symlinks'}, FILTER_VALIDATE_BOOLEAN);
} | [
"private",
"function",
"buildIgnoreSymlinks",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"bool",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"files",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"ignoreSymlinks",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"files",
"->",
"{",
"'ignore-symlinks'",
"}",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"ignoreSymlinks",
";",
"}",
"return",
"filter_var",
"(",
"$",
"phpDocumentor",
"->",
"files",
"->",
"{",
"'ignore-symlinks'",
"}",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
";",
"}"
] | Builds the ignore-symlinks part of the array from the configuration xml. | [
"Builds",
"the",
"ignore",
"-",
"symlinks",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L233-L244 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildIgnorePaths | private function buildIgnorePaths(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->files === []) {
return $this->ignorePaths;
}
$ignorePaths = [];
foreach ($phpDocumentor->files->children() as $child) {
if ($child->getName() === 'ignore') {
$ignorePaths[] = (string) $child;
}
}
if (count($ignorePaths) === 0) {
return $this->ignorePaths;
}
return $ignorePaths;
} | php | private function buildIgnorePaths(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->files === []) {
return $this->ignorePaths;
}
$ignorePaths = [];
foreach ($phpDocumentor->files->children() as $child) {
if ($child->getName() === 'ignore') {
$ignorePaths[] = (string) $child;
}
}
if (count($ignorePaths) === 0) {
return $this->ignorePaths;
}
return $ignorePaths;
} | [
"private",
"function",
"buildIgnorePaths",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"array",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"files",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"ignorePaths",
";",
"}",
"$",
"ignorePaths",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"phpDocumentor",
"->",
"files",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"getName",
"(",
")",
"===",
"'ignore'",
")",
"{",
"$",
"ignorePaths",
"[",
"]",
"=",
"(",
"string",
")",
"$",
"child",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"ignorePaths",
")",
"===",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"ignorePaths",
";",
"}",
"return",
"$",
"ignorePaths",
";",
"}"
] | Builds the ignorePaths part of the array from the configuration xml.
@return string[] | [
"Builds",
"the",
"ignorePaths",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L251-L268 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildOutputDirectory | private function buildOutputDirectory(SimpleXMLElement $phpDocumentor): string
{
if ((array) $phpDocumentor->transformer === []) {
return $this->outputDirectory;
}
if ((string) $phpDocumentor->transformer->target === '') {
return $this->outputDirectory;
}
return (string) $phpDocumentor->transformer->target;
} | php | private function buildOutputDirectory(SimpleXMLElement $phpDocumentor): string
{
if ((array) $phpDocumentor->transformer === []) {
return $this->outputDirectory;
}
if ((string) $phpDocumentor->transformer->target === '') {
return $this->outputDirectory;
}
return (string) $phpDocumentor->transformer->target;
} | [
"private",
"function",
"buildOutputDirectory",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"string",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"transformer",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"outputDirectory",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"transformer",
"->",
"target",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"outputDirectory",
";",
"}",
"return",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"transformer",
"->",
"target",
";",
"}"
] | Builds the outputDirectory part of the array from the configuration xml. | [
"Builds",
"the",
"outputDirectory",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L273-L284 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildDirectories | private function buildDirectories(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->files === []) {
return $this->directories;
}
if ((string) $phpDocumentor->files->directory === '') {
return $this->directories;
}
return (array) $phpDocumentor->files->directory;
} | php | private function buildDirectories(SimpleXMLElement $phpDocumentor): array
{
if ((array) $phpDocumentor->files === []) {
return $this->directories;
}
if ((string) $phpDocumentor->files->directory === '') {
return $this->directories;
}
return (array) $phpDocumentor->files->directory;
} | [
"private",
"function",
"buildDirectories",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"array",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"files",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"directories",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"files",
"->",
"directory",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"directories",
";",
"}",
"return",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"files",
"->",
"directory",
";",
"}"
] | Builds the directories that are used in the sourcePaths.
@return string[] | [
"Builds",
"the",
"directories",
"that",
"are",
"used",
"in",
"the",
"sourcePaths",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L291-L302 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildSourcePaths | private function buildSourcePaths(SimpleXMLElement $phpDocumentor): array
{
$sourcePaths = [];
$directories = $this->buildDirectories($phpDocumentor);
foreach ($directories as $directory) {
$sourcePaths[] = (new Dsn($directory))->getPath();
}
return $sourcePaths;
} | php | private function buildSourcePaths(SimpleXMLElement $phpDocumentor): array
{
$sourcePaths = [];
$directories = $this->buildDirectories($phpDocumentor);
foreach ($directories as $directory) {
$sourcePaths[] = (new Dsn($directory))->getPath();
}
return $sourcePaths;
} | [
"private",
"function",
"buildSourcePaths",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"array",
"{",
"$",
"sourcePaths",
"=",
"[",
"]",
";",
"$",
"directories",
"=",
"$",
"this",
"->",
"buildDirectories",
"(",
"$",
"phpDocumentor",
")",
";",
"foreach",
"(",
"$",
"directories",
"as",
"$",
"directory",
")",
"{",
"$",
"sourcePaths",
"[",
"]",
"=",
"(",
"new",
"Dsn",
"(",
"$",
"directory",
")",
")",
"->",
"getPath",
"(",
")",
";",
"}",
"return",
"$",
"sourcePaths",
";",
"}"
] | Builds the sourcePaths part of the array from the configuration xml.
@return Path[] | [
"Builds",
"the",
"sourcePaths",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L309-L319 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.validate | private function validate(SimpleXMLElement $xml): void
{
if ($xml->getName() !== 'phpdocumentor') {
throw new InvalidArgumentException(
sprintf('Root element name should be phpdocumentor, %s found', $xml->getName())
);
}
} | php | private function validate(SimpleXMLElement $xml): void
{
if ($xml->getName() !== 'phpdocumentor') {
throw new InvalidArgumentException(
sprintf('Root element name should be phpdocumentor, %s found', $xml->getName())
);
}
} | [
"private",
"function",
"validate",
"(",
"SimpleXMLElement",
"$",
"xml",
")",
":",
"void",
"{",
"if",
"(",
"$",
"xml",
"->",
"getName",
"(",
")",
"!==",
"'phpdocumentor'",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Root element name should be phpdocumentor, %s found'",
",",
"$",
"xml",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}"
] | Validates if the xml has a root element which name is phpdocumentor.
@throws InvalidArgumentException if the root element of the xml is not phpdocumentor. | [
"Validates",
"if",
"the",
"xml",
"has",
"a",
"root",
"element",
"which",
"name",
"is",
"phpdocumentor",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L326-L333 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Plugin/Core/Xslt/Extension.php | Extension.markdown | public static function markdown($text)
{
if (!is_string($text)) {
return $text;
}
$markdown = \Parsedown::instance();
return $markdown->parse($text);
} | php | public static function markdown($text)
{
if (!is_string($text)) {
return $text;
}
$markdown = \Parsedown::instance();
return $markdown->parse($text);
} | [
"public",
"static",
"function",
"markdown",
"(",
"$",
"text",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"text",
")",
")",
"{",
"return",
"$",
"text",
";",
"}",
"$",
"markdown",
"=",
"\\",
"Parsedown",
"::",
"instance",
"(",
")",
";",
"return",
"$",
"markdown",
"->",
"parse",
"(",
"$",
"text",
")",
";",
"}"
] | Markdown filter.
Example usage inside template would be:
```
<div class="long_description">
<xsl:value-of
select="php:function('phpDocumentor\Plugin\Core\Xslt\Extension::markdown',
string(docblock/long-description))"
disable-output-escaping="yes" />
</div>
```
@param string $text
@return string | [
"Markdown",
"filter",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Core/Xslt/Extension.php#L53-L62 | train |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Plugin/Core/Xslt/Extension.php | Extension.getDocumentedElement | private static function getDocumentedElement($fqsen)
{
$projectDescriptor = self::$descriptorBuilder->getProjectDescriptor();
$elementList = $projectDescriptor->getIndexes()->get('elements');
$prefixedLink = '~\\' . $fqsen;
if (isset($elementList[$fqsen])) {
return $elementList[$fqsen];
} elseif (isset($elementList[$prefixedLink])) {
return $elementList[$prefixedLink];
}
return false;
} | php | private static function getDocumentedElement($fqsen)
{
$projectDescriptor = self::$descriptorBuilder->getProjectDescriptor();
$elementList = $projectDescriptor->getIndexes()->get('elements');
$prefixedLink = '~\\' . $fqsen;
if (isset($elementList[$fqsen])) {
return $elementList[$fqsen];
} elseif (isset($elementList[$prefixedLink])) {
return $elementList[$prefixedLink];
}
return false;
} | [
"private",
"static",
"function",
"getDocumentedElement",
"(",
"$",
"fqsen",
")",
"{",
"$",
"projectDescriptor",
"=",
"self",
"::",
"$",
"descriptorBuilder",
"->",
"getProjectDescriptor",
"(",
")",
";",
"$",
"elementList",
"=",
"$",
"projectDescriptor",
"->",
"getIndexes",
"(",
")",
"->",
"get",
"(",
"'elements'",
")",
";",
"$",
"prefixedLink",
"=",
"'~\\\\'",
".",
"$",
"fqsen",
";",
"if",
"(",
"isset",
"(",
"$",
"elementList",
"[",
"$",
"fqsen",
"]",
")",
")",
"{",
"return",
"$",
"elementList",
"[",
"$",
"fqsen",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"elementList",
"[",
"$",
"prefixedLink",
"]",
")",
")",
"{",
"return",
"$",
"elementList",
"[",
"$",
"prefixedLink",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Returns a Descriptor Object if the given FQSEN exists in the project.
@param string $fqsen
@return bool|DescriptorAbstract | [
"Returns",
"a",
"Descriptor",
"Object",
"if",
"the",
"given",
"FQSEN",
"exists",
"in",
"the",
"project",
"."
] | 7a835fd03ff40244ff557c3e0ce32239e478def0 | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Core/Xslt/Extension.php#L121-L134 | train |
sabre-io/http | lib/Client.php | Client.send | public function send(RequestInterface $request): ResponseInterface
{
$this->emit('beforeRequest', [$request]);
$retryCount = 0;
$redirects = 0;
do {
$doRedirect = false;
$retry = false;
try {
$response = $this->doRequest($request);
$code = $response->getStatus();
// We are doing in-PHP redirects, because curl's
// FOLLOW_LOCATION throws errors when PHP is configured with
// open_basedir.
//
// https://github.com/fruux/sabre-http/issues/12
if ($redirects < $this->maxRedirects && in_array($code, [301, 302, 307, 308])) {
$oldLocation = $request->getUrl();
// Creating a new instance of the request object.
$request = clone $request;
// Setting the new location
$request->setUrl(Uri\resolve(
$oldLocation,
$response->getHeader('Location')
));
$doRedirect = true;
++$redirects;
}
// This was a HTTP error
if ($code >= 400) {
$this->emit('error', [$request, $response, &$retry, $retryCount]);
$this->emit('error:'.$code, [$request, $response, &$retry, $retryCount]);
}
} catch (ClientException $e) {
$this->emit('exception', [$request, $e, &$retry, $retryCount]);
// If retry was still set to false, it means no event handler
// dealt with the problem. In this case we just re-throw the
// exception.
if (!$retry) {
throw $e;
}
}
if ($retry) {
++$retryCount;
}
} while ($retry || $doRedirect);
$this->emit('afterRequest', [$request, $response]);
if ($this->throwExceptions && $code >= 400) {
throw new ClientHttpException($response);
}
return $response;
} | php | public function send(RequestInterface $request): ResponseInterface
{
$this->emit('beforeRequest', [$request]);
$retryCount = 0;
$redirects = 0;
do {
$doRedirect = false;
$retry = false;
try {
$response = $this->doRequest($request);
$code = $response->getStatus();
// We are doing in-PHP redirects, because curl's
// FOLLOW_LOCATION throws errors when PHP is configured with
// open_basedir.
//
// https://github.com/fruux/sabre-http/issues/12
if ($redirects < $this->maxRedirects && in_array($code, [301, 302, 307, 308])) {
$oldLocation = $request->getUrl();
// Creating a new instance of the request object.
$request = clone $request;
// Setting the new location
$request->setUrl(Uri\resolve(
$oldLocation,
$response->getHeader('Location')
));
$doRedirect = true;
++$redirects;
}
// This was a HTTP error
if ($code >= 400) {
$this->emit('error', [$request, $response, &$retry, $retryCount]);
$this->emit('error:'.$code, [$request, $response, &$retry, $retryCount]);
}
} catch (ClientException $e) {
$this->emit('exception', [$request, $e, &$retry, $retryCount]);
// If retry was still set to false, it means no event handler
// dealt with the problem. In this case we just re-throw the
// exception.
if (!$retry) {
throw $e;
}
}
if ($retry) {
++$retryCount;
}
} while ($retry || $doRedirect);
$this->emit('afterRequest', [$request, $response]);
if ($this->throwExceptions && $code >= 400) {
throw new ClientHttpException($response);
}
return $response;
} | [
"public",
"function",
"send",
"(",
"RequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"this",
"->",
"emit",
"(",
"'beforeRequest'",
",",
"[",
"$",
"request",
"]",
")",
";",
"$",
"retryCount",
"=",
"0",
";",
"$",
"redirects",
"=",
"0",
";",
"do",
"{",
"$",
"doRedirect",
"=",
"false",
";",
"$",
"retry",
"=",
"false",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"doRequest",
"(",
"$",
"request",
")",
";",
"$",
"code",
"=",
"$",
"response",
"->",
"getStatus",
"(",
")",
";",
"// We are doing in-PHP redirects, because curl's",
"// FOLLOW_LOCATION throws errors when PHP is configured with",
"// open_basedir.",
"//",
"// https://github.com/fruux/sabre-http/issues/12",
"if",
"(",
"$",
"redirects",
"<",
"$",
"this",
"->",
"maxRedirects",
"&&",
"in_array",
"(",
"$",
"code",
",",
"[",
"301",
",",
"302",
",",
"307",
",",
"308",
"]",
")",
")",
"{",
"$",
"oldLocation",
"=",
"$",
"request",
"->",
"getUrl",
"(",
")",
";",
"// Creating a new instance of the request object.",
"$",
"request",
"=",
"clone",
"$",
"request",
";",
"// Setting the new location",
"$",
"request",
"->",
"setUrl",
"(",
"Uri",
"\\",
"resolve",
"(",
"$",
"oldLocation",
",",
"$",
"response",
"->",
"getHeader",
"(",
"'Location'",
")",
")",
")",
";",
"$",
"doRedirect",
"=",
"true",
";",
"++",
"$",
"redirects",
";",
"}",
"// This was a HTTP error",
"if",
"(",
"$",
"code",
">=",
"400",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'error'",
",",
"[",
"$",
"request",
",",
"$",
"response",
",",
"&",
"$",
"retry",
",",
"$",
"retryCount",
"]",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'error:'",
".",
"$",
"code",
",",
"[",
"$",
"request",
",",
"$",
"response",
",",
"&",
"$",
"retry",
",",
"$",
"retryCount",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"ClientException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'exception'",
",",
"[",
"$",
"request",
",",
"$",
"e",
",",
"&",
"$",
"retry",
",",
"$",
"retryCount",
"]",
")",
";",
"// If retry was still set to false, it means no event handler",
"// dealt with the problem. In this case we just re-throw the",
"// exception.",
"if",
"(",
"!",
"$",
"retry",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"if",
"(",
"$",
"retry",
")",
"{",
"++",
"$",
"retryCount",
";",
"}",
"}",
"while",
"(",
"$",
"retry",
"||",
"$",
"doRedirect",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'afterRequest'",
",",
"[",
"$",
"request",
",",
"$",
"response",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"throwExceptions",
"&&",
"$",
"code",
">=",
"400",
")",
"{",
"throw",
"new",
"ClientHttpException",
"(",
"$",
"response",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Sends a request to a HTTP server, and returns a response. | [
"Sends",
"a",
"request",
"to",
"a",
"HTTP",
"server",
"and",
"returns",
"a",
"response",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L102-L167 | train |
sabre-io/http | lib/Client.php | Client.sendAsync | public function sendAsync(RequestInterface $request, callable $success = null, callable $error = null)
{
$this->emit('beforeRequest', [$request]);
$this->sendAsyncInternal($request, $success, $error);
$this->poll();
} | php | public function sendAsync(RequestInterface $request, callable $success = null, callable $error = null)
{
$this->emit('beforeRequest', [$request]);
$this->sendAsyncInternal($request, $success, $error);
$this->poll();
} | [
"public",
"function",
"sendAsync",
"(",
"RequestInterface",
"$",
"request",
",",
"callable",
"$",
"success",
"=",
"null",
",",
"callable",
"$",
"error",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'beforeRequest'",
",",
"[",
"$",
"request",
"]",
")",
";",
"$",
"this",
"->",
"sendAsyncInternal",
"(",
"$",
"request",
",",
"$",
"success",
",",
"$",
"error",
")",
";",
"$",
"this",
"->",
"poll",
"(",
")",
";",
"}"
] | Sends a HTTP request asynchronously.
Due to the nature of PHP, you must from time to time poll to see if any
new responses came in.
After calling sendAsync, you must therefore occasionally call the poll()
method, or wait(). | [
"Sends",
"a",
"HTTP",
"request",
"asynchronously",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L178-L183 | train |
sabre-io/http | lib/Client.php | Client.poll | public function poll(): bool
{
// nothing to do?
if (!$this->curlMultiMap) {
return false;
}
do {
$r = curl_multi_exec(
$this->curlMultiHandle,
$stillRunning
);
} while (CURLM_CALL_MULTI_PERFORM === $r);
$messagesInQueue = 0;
do {
messageQueue:
$status = curl_multi_info_read(
$this->curlMultiHandle,
$messagesInQueue
);
if ($status && CURLMSG_DONE === $status['msg']) {
$resourceId = (int) $status['handle'];
list(
$request,
$successCallback,
$errorCallback,
$retryCount) = $this->curlMultiMap[$resourceId];
unset($this->curlMultiMap[$resourceId]);
$curlHandle = $status['handle'];
$curlResult = $this->parseResponse(curl_multi_getcontent($curlHandle), $curlHandle);
$retry = false;
if (self::STATUS_CURLERROR === $curlResult['status']) {
$e = new ClientException($curlResult['curl_errmsg'], $curlResult['curl_errno']);
$this->emit('exception', [$request, $e, &$retry, $retryCount]);
if ($retry) {
++$retryCount;
$this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount);
goto messageQueue;
}
$curlResult['request'] = $request;
if ($errorCallback) {
$errorCallback($curlResult);
}
} elseif (self::STATUS_HTTPERROR === $curlResult['status']) {
$this->emit('error', [$request, $curlResult['response'], &$retry, $retryCount]);
$this->emit('error:'.$curlResult['http_code'], [$request, $curlResult['response'], &$retry, $retryCount]);
if ($retry) {
++$retryCount;
$this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount);
goto messageQueue;
}
$curlResult['request'] = $request;
if ($errorCallback) {
$errorCallback($curlResult);
}
} else {
$this->emit('afterRequest', [$request, $curlResult['response']]);
if ($successCallback) {
$successCallback($curlResult['response']);
}
}
}
} while ($messagesInQueue > 0);
return count($this->curlMultiMap) > 0;
} | php | public function poll(): bool
{
// nothing to do?
if (!$this->curlMultiMap) {
return false;
}
do {
$r = curl_multi_exec(
$this->curlMultiHandle,
$stillRunning
);
} while (CURLM_CALL_MULTI_PERFORM === $r);
$messagesInQueue = 0;
do {
messageQueue:
$status = curl_multi_info_read(
$this->curlMultiHandle,
$messagesInQueue
);
if ($status && CURLMSG_DONE === $status['msg']) {
$resourceId = (int) $status['handle'];
list(
$request,
$successCallback,
$errorCallback,
$retryCount) = $this->curlMultiMap[$resourceId];
unset($this->curlMultiMap[$resourceId]);
$curlHandle = $status['handle'];
$curlResult = $this->parseResponse(curl_multi_getcontent($curlHandle), $curlHandle);
$retry = false;
if (self::STATUS_CURLERROR === $curlResult['status']) {
$e = new ClientException($curlResult['curl_errmsg'], $curlResult['curl_errno']);
$this->emit('exception', [$request, $e, &$retry, $retryCount]);
if ($retry) {
++$retryCount;
$this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount);
goto messageQueue;
}
$curlResult['request'] = $request;
if ($errorCallback) {
$errorCallback($curlResult);
}
} elseif (self::STATUS_HTTPERROR === $curlResult['status']) {
$this->emit('error', [$request, $curlResult['response'], &$retry, $retryCount]);
$this->emit('error:'.$curlResult['http_code'], [$request, $curlResult['response'], &$retry, $retryCount]);
if ($retry) {
++$retryCount;
$this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount);
goto messageQueue;
}
$curlResult['request'] = $request;
if ($errorCallback) {
$errorCallback($curlResult);
}
} else {
$this->emit('afterRequest', [$request, $curlResult['response']]);
if ($successCallback) {
$successCallback($curlResult['response']);
}
}
}
} while ($messagesInQueue > 0);
return count($this->curlMultiMap) > 0;
} | [
"public",
"function",
"poll",
"(",
")",
":",
"bool",
"{",
"// nothing to do?",
"if",
"(",
"!",
"$",
"this",
"->",
"curlMultiMap",
")",
"{",
"return",
"false",
";",
"}",
"do",
"{",
"$",
"r",
"=",
"curl_multi_exec",
"(",
"$",
"this",
"->",
"curlMultiHandle",
",",
"$",
"stillRunning",
")",
";",
"}",
"while",
"(",
"CURLM_CALL_MULTI_PERFORM",
"===",
"$",
"r",
")",
";",
"$",
"messagesInQueue",
"=",
"0",
";",
"do",
"{",
"messageQueue",
":",
"$",
"status",
"=",
"curl_multi_info_read",
"(",
"$",
"this",
"->",
"curlMultiHandle",
",",
"$",
"messagesInQueue",
")",
";",
"if",
"(",
"$",
"status",
"&&",
"CURLMSG_DONE",
"===",
"$",
"status",
"[",
"'msg'",
"]",
")",
"{",
"$",
"resourceId",
"=",
"(",
"int",
")",
"$",
"status",
"[",
"'handle'",
"]",
";",
"list",
"(",
"$",
"request",
",",
"$",
"successCallback",
",",
"$",
"errorCallback",
",",
"$",
"retryCount",
")",
"=",
"$",
"this",
"->",
"curlMultiMap",
"[",
"$",
"resourceId",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"curlMultiMap",
"[",
"$",
"resourceId",
"]",
")",
";",
"$",
"curlHandle",
"=",
"$",
"status",
"[",
"'handle'",
"]",
";",
"$",
"curlResult",
"=",
"$",
"this",
"->",
"parseResponse",
"(",
"curl_multi_getcontent",
"(",
"$",
"curlHandle",
")",
",",
"$",
"curlHandle",
")",
";",
"$",
"retry",
"=",
"false",
";",
"if",
"(",
"self",
"::",
"STATUS_CURLERROR",
"===",
"$",
"curlResult",
"[",
"'status'",
"]",
")",
"{",
"$",
"e",
"=",
"new",
"ClientException",
"(",
"$",
"curlResult",
"[",
"'curl_errmsg'",
"]",
",",
"$",
"curlResult",
"[",
"'curl_errno'",
"]",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'exception'",
",",
"[",
"$",
"request",
",",
"$",
"e",
",",
"&",
"$",
"retry",
",",
"$",
"retryCount",
"]",
")",
";",
"if",
"(",
"$",
"retry",
")",
"{",
"++",
"$",
"retryCount",
";",
"$",
"this",
"->",
"sendAsyncInternal",
"(",
"$",
"request",
",",
"$",
"successCallback",
",",
"$",
"errorCallback",
",",
"$",
"retryCount",
")",
";",
"goto",
"messageQueue",
";",
"}",
"$",
"curlResult",
"[",
"'request'",
"]",
"=",
"$",
"request",
";",
"if",
"(",
"$",
"errorCallback",
")",
"{",
"$",
"errorCallback",
"(",
"$",
"curlResult",
")",
";",
"}",
"}",
"elseif",
"(",
"self",
"::",
"STATUS_HTTPERROR",
"===",
"$",
"curlResult",
"[",
"'status'",
"]",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'error'",
",",
"[",
"$",
"request",
",",
"$",
"curlResult",
"[",
"'response'",
"]",
",",
"&",
"$",
"retry",
",",
"$",
"retryCount",
"]",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'error:'",
".",
"$",
"curlResult",
"[",
"'http_code'",
"]",
",",
"[",
"$",
"request",
",",
"$",
"curlResult",
"[",
"'response'",
"]",
",",
"&",
"$",
"retry",
",",
"$",
"retryCount",
"]",
")",
";",
"if",
"(",
"$",
"retry",
")",
"{",
"++",
"$",
"retryCount",
";",
"$",
"this",
"->",
"sendAsyncInternal",
"(",
"$",
"request",
",",
"$",
"successCallback",
",",
"$",
"errorCallback",
",",
"$",
"retryCount",
")",
";",
"goto",
"messageQueue",
";",
"}",
"$",
"curlResult",
"[",
"'request'",
"]",
"=",
"$",
"request",
";",
"if",
"(",
"$",
"errorCallback",
")",
"{",
"$",
"errorCallback",
"(",
"$",
"curlResult",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"emit",
"(",
"'afterRequest'",
",",
"[",
"$",
"request",
",",
"$",
"curlResult",
"[",
"'response'",
"]",
"]",
")",
";",
"if",
"(",
"$",
"successCallback",
")",
"{",
"$",
"successCallback",
"(",
"$",
"curlResult",
"[",
"'response'",
"]",
")",
";",
"}",
"}",
"}",
"}",
"while",
"(",
"$",
"messagesInQueue",
">",
"0",
")",
";",
"return",
"count",
"(",
"$",
"this",
"->",
"curlMultiMap",
")",
">",
"0",
";",
"}"
] | This method checks if any http requests have gotten results, and if so,
call the appropriate success or error handlers.
This method will return true if there are still requests waiting to
return, and false if all the work is done. | [
"This",
"method",
"checks",
"if",
"any",
"http",
"requests",
"have",
"gotten",
"results",
"and",
"if",
"so",
"call",
"the",
"appropriate",
"success",
"or",
"error",
"handlers",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L192-L269 | train |
sabre-io/http | lib/Client.php | Client.doRequest | protected function doRequest(RequestInterface $request): ResponseInterface
{
$settings = $this->createCurlSettingsArray($request);
if (!$this->curlHandle) {
$this->curlHandle = curl_init();
} else {
curl_reset($this->curlHandle);
}
curl_setopt_array($this->curlHandle, $settings);
$response = $this->curlExec($this->curlHandle);
$response = $this->parseResponse($response, $this->curlHandle);
if (self::STATUS_CURLERROR === $response['status']) {
throw new ClientException($response['curl_errmsg'], $response['curl_errno']);
}
return $response['response'];
} | php | protected function doRequest(RequestInterface $request): ResponseInterface
{
$settings = $this->createCurlSettingsArray($request);
if (!$this->curlHandle) {
$this->curlHandle = curl_init();
} else {
curl_reset($this->curlHandle);
}
curl_setopt_array($this->curlHandle, $settings);
$response = $this->curlExec($this->curlHandle);
$response = $this->parseResponse($response, $this->curlHandle);
if (self::STATUS_CURLERROR === $response['status']) {
throw new ClientException($response['curl_errmsg'], $response['curl_errno']);
}
return $response['response'];
} | [
"protected",
"function",
"doRequest",
"(",
"RequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"createCurlSettingsArray",
"(",
"$",
"request",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"curlHandle",
")",
"{",
"$",
"this",
"->",
"curlHandle",
"=",
"curl_init",
"(",
")",
";",
"}",
"else",
"{",
"curl_reset",
"(",
"$",
"this",
"->",
"curlHandle",
")",
";",
"}",
"curl_setopt_array",
"(",
"$",
"this",
"->",
"curlHandle",
",",
"$",
"settings",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"curlExec",
"(",
"$",
"this",
"->",
"curlHandle",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"parseResponse",
"(",
"$",
"response",
",",
"$",
"this",
"->",
"curlHandle",
")",
";",
"if",
"(",
"self",
"::",
"STATUS_CURLERROR",
"===",
"$",
"response",
"[",
"'status'",
"]",
")",
"{",
"throw",
"new",
"ClientException",
"(",
"$",
"response",
"[",
"'curl_errmsg'",
"]",
",",
"$",
"response",
"[",
"'curl_errno'",
"]",
")",
";",
"}",
"return",
"$",
"response",
"[",
"'response'",
"]",
";",
"}"
] | This method is responsible for performing a single request. | [
"This",
"method",
"is",
"responsible",
"for",
"performing",
"a",
"single",
"request",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L313-L331 | train |
sabre-io/http | lib/Client.php | Client.createCurlSettingsArray | protected function createCurlSettingsArray(RequestInterface $request): array
{
$settings = $this->curlSettings;
switch ($request->getMethod()) {
case 'HEAD':
$settings[CURLOPT_NOBODY] = true;
$settings[CURLOPT_CUSTOMREQUEST] = 'HEAD';
break;
case 'GET':
$settings[CURLOPT_CUSTOMREQUEST] = 'GET';
break;
default:
$body = $request->getBody();
if (is_resource($body)) {
// This needs to be set to PUT, regardless of the actual
// method used. Without it, INFILE will be ignored for some
// reason.
$settings[CURLOPT_PUT] = true;
$settings[CURLOPT_INFILE] = $request->getBody();
} else {
// For security we cast this to a string. If somehow an array could
// be passed here, it would be possible for an attacker to use @ to
// post local files.
$settings[CURLOPT_POSTFIELDS] = (string) $body;
}
$settings[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
break;
}
$nHeaders = [];
foreach ($request->getHeaders() as $key => $values) {
foreach ($values as $value) {
$nHeaders[] = $key.': '.$value;
}
}
$settings[CURLOPT_HTTPHEADER] = $nHeaders;
$settings[CURLOPT_URL] = $request->getUrl();
// FIXME: CURLOPT_PROTOCOLS is currently unsupported by HHVM
if (defined('CURLOPT_PROTOCOLS')) {
$settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
// FIXME: CURLOPT_REDIR_PROTOCOLS is currently unsupported by HHVM
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
$settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
return $settings;
} | php | protected function createCurlSettingsArray(RequestInterface $request): array
{
$settings = $this->curlSettings;
switch ($request->getMethod()) {
case 'HEAD':
$settings[CURLOPT_NOBODY] = true;
$settings[CURLOPT_CUSTOMREQUEST] = 'HEAD';
break;
case 'GET':
$settings[CURLOPT_CUSTOMREQUEST] = 'GET';
break;
default:
$body = $request->getBody();
if (is_resource($body)) {
// This needs to be set to PUT, regardless of the actual
// method used. Without it, INFILE will be ignored for some
// reason.
$settings[CURLOPT_PUT] = true;
$settings[CURLOPT_INFILE] = $request->getBody();
} else {
// For security we cast this to a string. If somehow an array could
// be passed here, it would be possible for an attacker to use @ to
// post local files.
$settings[CURLOPT_POSTFIELDS] = (string) $body;
}
$settings[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
break;
}
$nHeaders = [];
foreach ($request->getHeaders() as $key => $values) {
foreach ($values as $value) {
$nHeaders[] = $key.': '.$value;
}
}
$settings[CURLOPT_HTTPHEADER] = $nHeaders;
$settings[CURLOPT_URL] = $request->getUrl();
// FIXME: CURLOPT_PROTOCOLS is currently unsupported by HHVM
if (defined('CURLOPT_PROTOCOLS')) {
$settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
// FIXME: CURLOPT_REDIR_PROTOCOLS is currently unsupported by HHVM
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
$settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
return $settings;
} | [
"protected",
"function",
"createCurlSettingsArray",
"(",
"RequestInterface",
"$",
"request",
")",
":",
"array",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"curlSettings",
";",
"switch",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"case",
"'HEAD'",
":",
"$",
"settings",
"[",
"CURLOPT_NOBODY",
"]",
"=",
"true",
";",
"$",
"settings",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"'HEAD'",
";",
"break",
";",
"case",
"'GET'",
":",
"$",
"settings",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"'GET'",
";",
"break",
";",
"default",
":",
"$",
"body",
"=",
"$",
"request",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"body",
")",
")",
"{",
"// This needs to be set to PUT, regardless of the actual",
"// method used. Without it, INFILE will be ignored for some",
"// reason.",
"$",
"settings",
"[",
"CURLOPT_PUT",
"]",
"=",
"true",
";",
"$",
"settings",
"[",
"CURLOPT_INFILE",
"]",
"=",
"$",
"request",
"->",
"getBody",
"(",
")",
";",
"}",
"else",
"{",
"// For security we cast this to a string. If somehow an array could",
"// be passed here, it would be possible for an attacker to use @ to",
"// post local files.",
"$",
"settings",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"(",
"string",
")",
"$",
"body",
";",
"}",
"$",
"settings",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"break",
";",
"}",
"$",
"nHeaders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"request",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"nHeaders",
"[",
"]",
"=",
"$",
"key",
".",
"': '",
".",
"$",
"value",
";",
"}",
"}",
"$",
"settings",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"$",
"nHeaders",
";",
"$",
"settings",
"[",
"CURLOPT_URL",
"]",
"=",
"$",
"request",
"->",
"getUrl",
"(",
")",
";",
"// FIXME: CURLOPT_PROTOCOLS is currently unsupported by HHVM",
"if",
"(",
"defined",
"(",
"'CURLOPT_PROTOCOLS'",
")",
")",
"{",
"$",
"settings",
"[",
"CURLOPT_PROTOCOLS",
"]",
"=",
"CURLPROTO_HTTP",
"|",
"CURLPROTO_HTTPS",
";",
"}",
"// FIXME: CURLOPT_REDIR_PROTOCOLS is currently unsupported by HHVM",
"if",
"(",
"defined",
"(",
"'CURLOPT_REDIR_PROTOCOLS'",
")",
")",
"{",
"$",
"settings",
"[",
"CURLOPT_REDIR_PROTOCOLS",
"]",
"=",
"CURLPROTO_HTTP",
"|",
"CURLPROTO_HTTPS",
";",
"}",
"return",
"$",
"settings",
";",
"}"
] | Turns a RequestInterface object into an array with settings that can be
fed to curl_setopt. | [
"Turns",
"a",
"RequestInterface",
"object",
"into",
"an",
"array",
"with",
"settings",
"that",
"can",
"be",
"fed",
"to",
"curl_setopt",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L364-L412 | train |
sabre-io/http | lib/Client.php | Client.sendAsyncInternal | protected function sendAsyncInternal(RequestInterface $request, callable $success, callable $error, int $retryCount = 0)
{
if (!$this->curlMultiHandle) {
$this->curlMultiHandle = curl_multi_init();
}
$curl = curl_init();
curl_setopt_array(
$curl,
$this->createCurlSettingsArray($request)
);
curl_multi_add_handle($this->curlMultiHandle, $curl);
$resourceId = (int) $curl;
$this->headerLinesMap[$resourceId] = [];
$this->curlMultiMap[$resourceId] = [
$request,
$success,
$error,
$retryCount,
];
} | php | protected function sendAsyncInternal(RequestInterface $request, callable $success, callable $error, int $retryCount = 0)
{
if (!$this->curlMultiHandle) {
$this->curlMultiHandle = curl_multi_init();
}
$curl = curl_init();
curl_setopt_array(
$curl,
$this->createCurlSettingsArray($request)
);
curl_multi_add_handle($this->curlMultiHandle, $curl);
$resourceId = (int) $curl;
$this->headerLinesMap[$resourceId] = [];
$this->curlMultiMap[$resourceId] = [
$request,
$success,
$error,
$retryCount,
];
} | [
"protected",
"function",
"sendAsyncInternal",
"(",
"RequestInterface",
"$",
"request",
",",
"callable",
"$",
"success",
",",
"callable",
"$",
"error",
",",
"int",
"$",
"retryCount",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"curlMultiHandle",
")",
"{",
"$",
"this",
"->",
"curlMultiHandle",
"=",
"curl_multi_init",
"(",
")",
";",
"}",
"$",
"curl",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt_array",
"(",
"$",
"curl",
",",
"$",
"this",
"->",
"createCurlSettingsArray",
"(",
"$",
"request",
")",
")",
";",
"curl_multi_add_handle",
"(",
"$",
"this",
"->",
"curlMultiHandle",
",",
"$",
"curl",
")",
";",
"$",
"resourceId",
"=",
"(",
"int",
")",
"$",
"curl",
";",
"$",
"this",
"->",
"headerLinesMap",
"[",
"$",
"resourceId",
"]",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"curlMultiMap",
"[",
"$",
"resourceId",
"]",
"=",
"[",
"$",
"request",
",",
"$",
"success",
",",
"$",
"error",
",",
"$",
"retryCount",
",",
"]",
";",
"}"
] | Sends an asynchronous HTTP request.
We keep this in a separate method, so we can call it without triggering
the beforeRequest event and don't do the poll(). | [
"Sends",
"an",
"asynchronous",
"HTTP",
"request",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L556-L576 | train |
sabre-io/http | lib/Client.php | Client.curlExec | protected function curlExec($curlHandle): string
{
$this->headerLinesMap[(int) $curlHandle] = [];
$result = curl_exec($curlHandle);
if (false === $result) {
$result = '';
}
return $result;
} | php | protected function curlExec($curlHandle): string
{
$this->headerLinesMap[(int) $curlHandle] = [];
$result = curl_exec($curlHandle);
if (false === $result) {
$result = '';
}
return $result;
} | [
"protected",
"function",
"curlExec",
"(",
"$",
"curlHandle",
")",
":",
"string",
"{",
"$",
"this",
"->",
"headerLinesMap",
"[",
"(",
"int",
")",
"$",
"curlHandle",
"]",
"=",
"[",
"]",
";",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"curlHandle",
")",
";",
"if",
"(",
"false",
"===",
"$",
"result",
")",
"{",
"$",
"result",
"=",
"''",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Calls curl_exec.
This method exists so it can easily be overridden and mocked.
@param resource $curlHandle | [
"Calls",
"curl_exec",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L587-L597 | train |
sabre-io/http | lib/Auth/Bearer.php | Bearer.getToken | public function getToken()
{
$auth = $this->request->getHeader('Authorization');
if (!$auth) {
return null;
}
if ('bearer ' !== strtolower(substr($auth, 0, 7))) {
return null;
}
return substr($auth, 7);
} | php | public function getToken()
{
$auth = $this->request->getHeader('Authorization');
if (!$auth) {
return null;
}
if ('bearer ' !== strtolower(substr($auth, 0, 7))) {
return null;
}
return substr($auth, 7);
} | [
"public",
"function",
"getToken",
"(",
")",
"{",
"$",
"auth",
"=",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'Authorization'",
")",
";",
"if",
"(",
"!",
"$",
"auth",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"'bearer '",
"!==",
"strtolower",
"(",
"substr",
"(",
"$",
"auth",
",",
"0",
",",
"7",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"substr",
"(",
"$",
"auth",
",",
"7",
")",
";",
"}"
] | This method returns a string with an access token.
If no token was found, this method returns null.
@return null|string | [
"This",
"method",
"returns",
"a",
"string",
"with",
"an",
"access",
"token",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Bearer.php#L29-L42 | train |
sabre-io/http | lib/Auth/Basic.php | Basic.getCredentials | public function getCredentials()
{
$auth = $this->request->getHeader('Authorization');
if (!$auth) {
return null;
}
if ('basic ' !== strtolower(substr($auth, 0, 6))) {
return null;
}
$credentials = explode(':', base64_decode(substr($auth, 6)), 2);
if (2 !== count($credentials)) {
return null;
}
return $credentials;
} | php | public function getCredentials()
{
$auth = $this->request->getHeader('Authorization');
if (!$auth) {
return null;
}
if ('basic ' !== strtolower(substr($auth, 0, 6))) {
return null;
}
$credentials = explode(':', base64_decode(substr($auth, 6)), 2);
if (2 !== count($credentials)) {
return null;
}
return $credentials;
} | [
"public",
"function",
"getCredentials",
"(",
")",
"{",
"$",
"auth",
"=",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'Authorization'",
")",
";",
"if",
"(",
"!",
"$",
"auth",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"'basic '",
"!==",
"strtolower",
"(",
"substr",
"(",
"$",
"auth",
",",
"0",
",",
"6",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"credentials",
"=",
"explode",
"(",
"':'",
",",
"base64_decode",
"(",
"substr",
"(",
"$",
"auth",
",",
"6",
")",
")",
",",
"2",
")",
";",
"if",
"(",
"2",
"!==",
"count",
"(",
"$",
"credentials",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"credentials",
";",
"}"
] | This method returns a numeric array with a username and password as the
only elements.
If no credentials were found, this method returns null.
@return null|array | [
"This",
"method",
"returns",
"a",
"numeric",
"array",
"with",
"a",
"username",
"and",
"password",
"as",
"the",
"only",
"elements",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Basic.php#L30-L49 | train |
sabre-io/http | lib/Sapi.php | Sapi.getRequest | public static function getRequest(): Request
{
$serverArr = $_SERVER;
if ('cli' === PHP_SAPI) {
// If we're running off the CLI, we're going to set some default
// settings.
$serverArr['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ?? '/';
$serverArr['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'] ?? 'CLI';
}
$r = self::createFromServerArray($serverArr);
$r->setBody(fopen('php://input', 'r'));
$r->setPostData($_POST);
return $r;
} | php | public static function getRequest(): Request
{
$serverArr = $_SERVER;
if ('cli' === PHP_SAPI) {
// If we're running off the CLI, we're going to set some default
// settings.
$serverArr['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ?? '/';
$serverArr['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'] ?? 'CLI';
}
$r = self::createFromServerArray($serverArr);
$r->setBody(fopen('php://input', 'r'));
$r->setPostData($_POST);
return $r;
} | [
"public",
"static",
"function",
"getRequest",
"(",
")",
":",
"Request",
"{",
"$",
"serverArr",
"=",
"$",
"_SERVER",
";",
"if",
"(",
"'cli'",
"===",
"PHP_SAPI",
")",
"{",
"// If we're running off the CLI, we're going to set some default",
"// settings.",
"$",
"serverArr",
"[",
"'REQUEST_URI'",
"]",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
"??",
"'/'",
";",
"$",
"serverArr",
"[",
"'REQUEST_METHOD'",
"]",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"??",
"'CLI'",
";",
"}",
"$",
"r",
"=",
"self",
"::",
"createFromServerArray",
"(",
"$",
"serverArr",
")",
";",
"$",
"r",
"->",
"setBody",
"(",
"fopen",
"(",
"'php://input'",
",",
"'r'",
")",
")",
";",
"$",
"r",
"->",
"setPostData",
"(",
"$",
"_POST",
")",
";",
"return",
"$",
"r",
";",
"}"
] | This static method will create a new Request object, based on the
current PHP request. | [
"This",
"static",
"method",
"will",
"create",
"a",
"new",
"Request",
"object",
"based",
"on",
"the",
"current",
"PHP",
"request",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Sapi.php#L41-L57 | train |
sabre-io/http | lib/Sapi.php | Sapi.sendResponse | public static function sendResponse(ResponseInterface $response)
{
header('HTTP/'.$response->getHttpVersion().' '.$response->getStatus().' '.$response->getStatusText());
foreach ($response->getHeaders() as $key => $value) {
foreach ($value as $k => $v) {
if (0 === $k) {
header($key.': '.$v);
} else {
header($key.': '.$v, false);
}
}
}
$body = $response->getBody();
if (null === $body) {
return;
}
if (is_callable($body)) {
$body();
return;
}
$contentLength = $response->getHeader('Content-Length');
if (null !== $contentLength) {
$output = fopen('php://output', 'wb');
if (is_resource($body) && 'stream' == get_resource_type($body)) {
if (PHP_INT_SIZE !== 4) {
// use the dedicated function on 64 Bit systems
stream_copy_to_stream($body, $output, (int) $contentLength);
} else {
// workaround for 32 Bit systems to avoid stream_copy_to_stream
while (!feof($body)) {
fwrite($output, fread($body, 8192));
}
}
} else {
fwrite($output, $body, (int) $contentLength);
}
} else {
file_put_contents('php://output', $body);
}
if (is_resource($body)) {
fclose($body);
}
} | php | public static function sendResponse(ResponseInterface $response)
{
header('HTTP/'.$response->getHttpVersion().' '.$response->getStatus().' '.$response->getStatusText());
foreach ($response->getHeaders() as $key => $value) {
foreach ($value as $k => $v) {
if (0 === $k) {
header($key.': '.$v);
} else {
header($key.': '.$v, false);
}
}
}
$body = $response->getBody();
if (null === $body) {
return;
}
if (is_callable($body)) {
$body();
return;
}
$contentLength = $response->getHeader('Content-Length');
if (null !== $contentLength) {
$output = fopen('php://output', 'wb');
if (is_resource($body) && 'stream' == get_resource_type($body)) {
if (PHP_INT_SIZE !== 4) {
// use the dedicated function on 64 Bit systems
stream_copy_to_stream($body, $output, (int) $contentLength);
} else {
// workaround for 32 Bit systems to avoid stream_copy_to_stream
while (!feof($body)) {
fwrite($output, fread($body, 8192));
}
}
} else {
fwrite($output, $body, (int) $contentLength);
}
} else {
file_put_contents('php://output', $body);
}
if (is_resource($body)) {
fclose($body);
}
} | [
"public",
"static",
"function",
"sendResponse",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"header",
"(",
"'HTTP/'",
".",
"$",
"response",
"->",
"getHttpVersion",
"(",
")",
".",
"' '",
".",
"$",
"response",
"->",
"getStatus",
"(",
")",
".",
"' '",
".",
"$",
"response",
"->",
"getStatusText",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"response",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"0",
"===",
"$",
"k",
")",
"{",
"header",
"(",
"$",
"key",
".",
"': '",
".",
"$",
"v",
")",
";",
"}",
"else",
"{",
"header",
"(",
"$",
"key",
".",
"': '",
".",
"$",
"v",
",",
"false",
")",
";",
"}",
"}",
"}",
"$",
"body",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"body",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"body",
")",
")",
"{",
"$",
"body",
"(",
")",
";",
"return",
";",
"}",
"$",
"contentLength",
"=",
"$",
"response",
"->",
"getHeader",
"(",
"'Content-Length'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"contentLength",
")",
"{",
"$",
"output",
"=",
"fopen",
"(",
"'php://output'",
",",
"'wb'",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"body",
")",
"&&",
"'stream'",
"==",
"get_resource_type",
"(",
"$",
"body",
")",
")",
"{",
"if",
"(",
"PHP_INT_SIZE",
"!==",
"4",
")",
"{",
"// use the dedicated function on 64 Bit systems",
"stream_copy_to_stream",
"(",
"$",
"body",
",",
"$",
"output",
",",
"(",
"int",
")",
"$",
"contentLength",
")",
";",
"}",
"else",
"{",
"// workaround for 32 Bit systems to avoid stream_copy_to_stream",
"while",
"(",
"!",
"feof",
"(",
"$",
"body",
")",
")",
"{",
"fwrite",
"(",
"$",
"output",
",",
"fread",
"(",
"$",
"body",
",",
"8192",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"fwrite",
"(",
"$",
"output",
",",
"$",
"body",
",",
"(",
"int",
")",
"$",
"contentLength",
")",
";",
"}",
"}",
"else",
"{",
"file_put_contents",
"(",
"'php://output'",
",",
"$",
"body",
")",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"body",
")",
")",
"{",
"fclose",
"(",
"$",
"body",
")",
";",
"}",
"}"
] | Sends the HTTP response back to a HTTP client.
This calls php's header() function and streams the body to php://output. | [
"Sends",
"the",
"HTTP",
"response",
"back",
"to",
"a",
"HTTP",
"client",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Sapi.php#L64-L111 | train |
sabre-io/http | lib/Auth/Digest.php | Digest.validatePassword | public function validatePassword(string $password): bool
{
$this->A1 = md5($this->digestParts['username'].':'.$this->realm.':'.$password);
return $this->validate();
} | php | public function validatePassword(string $password): bool
{
$this->A1 = md5($this->digestParts['username'].':'.$this->realm.':'.$password);
return $this->validate();
} | [
"public",
"function",
"validatePassword",
"(",
"string",
"$",
"password",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"A1",
"=",
"md5",
"(",
"$",
"this",
"->",
"digestParts",
"[",
"'username'",
"]",
".",
"':'",
".",
"$",
"this",
"->",
"realm",
".",
"':'",
".",
"$",
"password",
")",
";",
"return",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"}"
] | Validates authentication through a password. The actual password must be provided here.
It is strongly recommended not store the password in plain-text and use validateA1 instead. | [
"Validates",
"authentication",
"through",
"a",
"password",
".",
"The",
"actual",
"password",
"must",
"be",
"provided",
"here",
".",
"It",
"is",
"strongly",
"recommended",
"not",
"store",
"the",
"password",
"in",
"plain",
"-",
"text",
"and",
"use",
"validateA1",
"instead",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L101-L106 | train |
sabre-io/http | lib/Auth/Digest.php | Digest.validate | protected function validate(): bool
{
$A2 = $this->request->getMethod().':'.$this->digestParts['uri'];
if ('auth-int' === $this->digestParts['qop']) {
// Making sure we support this qop value
if (!($this->qop & self::QOP_AUTHINT)) {
return false;
}
// We need to add an md5 of the entire request body to the A2 part of the hash
$body = $this->request->getBody($asString = true);
$this->request->setBody($body);
$A2 .= ':'.md5($body);
} elseif (!($this->qop & self::QOP_AUTH)) {
return false;
}
$A2 = md5($A2);
$validResponse = md5("{$this->A1}:{$this->digestParts['nonce']}:{$this->digestParts['nc']}:{$this->digestParts['cnonce']}:{$this->digestParts['qop']}:{$A2}");
return $this->digestParts['response'] === $validResponse;
} | php | protected function validate(): bool
{
$A2 = $this->request->getMethod().':'.$this->digestParts['uri'];
if ('auth-int' === $this->digestParts['qop']) {
// Making sure we support this qop value
if (!($this->qop & self::QOP_AUTHINT)) {
return false;
}
// We need to add an md5 of the entire request body to the A2 part of the hash
$body = $this->request->getBody($asString = true);
$this->request->setBody($body);
$A2 .= ':'.md5($body);
} elseif (!($this->qop & self::QOP_AUTH)) {
return false;
}
$A2 = md5($A2);
$validResponse = md5("{$this->A1}:{$this->digestParts['nonce']}:{$this->digestParts['nc']}:{$this->digestParts['cnonce']}:{$this->digestParts['qop']}:{$A2}");
return $this->digestParts['response'] === $validResponse;
} | [
"protected",
"function",
"validate",
"(",
")",
":",
"bool",
"{",
"$",
"A2",
"=",
"$",
"this",
"->",
"request",
"->",
"getMethod",
"(",
")",
".",
"':'",
".",
"$",
"this",
"->",
"digestParts",
"[",
"'uri'",
"]",
";",
"if",
"(",
"'auth-int'",
"===",
"$",
"this",
"->",
"digestParts",
"[",
"'qop'",
"]",
")",
"{",
"// Making sure we support this qop value",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"qop",
"&",
"self",
"::",
"QOP_AUTHINT",
")",
")",
"{",
"return",
"false",
";",
"}",
"// We need to add an md5 of the entire request body to the A2 part of the hash",
"$",
"body",
"=",
"$",
"this",
"->",
"request",
"->",
"getBody",
"(",
"$",
"asString",
"=",
"true",
")",
";",
"$",
"this",
"->",
"request",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"$",
"A2",
".=",
"':'",
".",
"md5",
"(",
"$",
"body",
")",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"this",
"->",
"qop",
"&",
"self",
"::",
"QOP_AUTH",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"A2",
"=",
"md5",
"(",
"$",
"A2",
")",
";",
"$",
"validResponse",
"=",
"md5",
"(",
"\"{$this->A1}:{$this->digestParts['nonce']}:{$this->digestParts['nc']}:{$this->digestParts['cnonce']}:{$this->digestParts['qop']}:{$A2}\"",
")",
";",
"return",
"$",
"this",
"->",
"digestParts",
"[",
"'response'",
"]",
"===",
"$",
"validResponse",
";",
"}"
] | Validates the digest challenge. | [
"Validates",
"the",
"digest",
"challenge",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L122-L144 | train |
sabre-io/http | lib/Auth/Digest.php | Digest.requireLogin | public function requireLogin()
{
$qop = '';
switch ($this->qop) {
case self::QOP_AUTH:
$qop = 'auth';
break;
case self::QOP_AUTHINT:
$qop = 'auth-int';
break;
case self::QOP_AUTH | self::QOP_AUTHINT:
$qop = 'auth,auth-int';
break;
}
$this->response->addHeader('WWW-Authenticate', 'Digest realm="'.$this->realm.'",qop="'.$qop.'",nonce="'.$this->nonce.'",opaque="'.$this->opaque.'"');
$this->response->setStatus(401);
} | php | public function requireLogin()
{
$qop = '';
switch ($this->qop) {
case self::QOP_AUTH:
$qop = 'auth';
break;
case self::QOP_AUTHINT:
$qop = 'auth-int';
break;
case self::QOP_AUTH | self::QOP_AUTHINT:
$qop = 'auth,auth-int';
break;
}
$this->response->addHeader('WWW-Authenticate', 'Digest realm="'.$this->realm.'",qop="'.$qop.'",nonce="'.$this->nonce.'",opaque="'.$this->opaque.'"');
$this->response->setStatus(401);
} | [
"public",
"function",
"requireLogin",
"(",
")",
"{",
"$",
"qop",
"=",
"''",
";",
"switch",
"(",
"$",
"this",
"->",
"qop",
")",
"{",
"case",
"self",
"::",
"QOP_AUTH",
":",
"$",
"qop",
"=",
"'auth'",
";",
"break",
";",
"case",
"self",
"::",
"QOP_AUTHINT",
":",
"$",
"qop",
"=",
"'auth-int'",
";",
"break",
";",
"case",
"self",
"::",
"QOP_AUTH",
"|",
"self",
"::",
"QOP_AUTHINT",
":",
"$",
"qop",
"=",
"'auth,auth-int'",
";",
"break",
";",
"}",
"$",
"this",
"->",
"response",
"->",
"addHeader",
"(",
"'WWW-Authenticate'",
",",
"'Digest realm=\"'",
".",
"$",
"this",
"->",
"realm",
".",
"'\",qop=\"'",
".",
"$",
"qop",
".",
"'\",nonce=\"'",
".",
"$",
"this",
"->",
"nonce",
".",
"'\",opaque=\"'",
".",
"$",
"this",
"->",
"opaque",
".",
"'\"'",
")",
";",
"$",
"this",
"->",
"response",
"->",
"setStatus",
"(",
"401",
")",
";",
"}"
] | Returns an HTTP 401 header, forcing login.
This should be called when username and password are incorrect, or not supplied at all | [
"Returns",
"an",
"HTTP",
"401",
"header",
"forcing",
"login",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L151-L168 | train |
sabre-io/http | lib/Auth/Digest.php | Digest.parseDigest | protected function parseDigest(string $digest)
{
// protect against missing data
$needed_parts = ['nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1];
$data = [];
preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $digest, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
$data[$m[1]] = $m[2] ?: $m[3];
unset($needed_parts[$m[1]]);
}
return $needed_parts ? false : $data;
} | php | protected function parseDigest(string $digest)
{
// protect against missing data
$needed_parts = ['nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1];
$data = [];
preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $digest, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
$data[$m[1]] = $m[2] ?: $m[3];
unset($needed_parts[$m[1]]);
}
return $needed_parts ? false : $data;
} | [
"protected",
"function",
"parseDigest",
"(",
"string",
"$",
"digest",
")",
"{",
"// protect against missing data",
"$",
"needed_parts",
"=",
"[",
"'nonce'",
"=>",
"1",
",",
"'nc'",
"=>",
"1",
",",
"'cnonce'",
"=>",
"1",
",",
"'qop'",
"=>",
"1",
",",
"'username'",
"=>",
"1",
",",
"'uri'",
"=>",
"1",
",",
"'response'",
"=>",
"1",
"]",
";",
"$",
"data",
"=",
"[",
"]",
";",
"preg_match_all",
"(",
"'@(\\w+)=(?:(?:\")([^\"]+)\"|([^\\s,$]+))@'",
",",
"$",
"digest",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"m",
")",
"{",
"$",
"data",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
"=",
"$",
"m",
"[",
"2",
"]",
"?",
":",
"$",
"m",
"[",
"3",
"]",
";",
"unset",
"(",
"$",
"needed_parts",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
")",
";",
"}",
"return",
"$",
"needed_parts",
"?",
"false",
":",
"$",
"data",
";",
"}"
] | Parses the different pieces of the digest string into an array.
This method returns false if an incomplete digest was supplied
@return bool|array | [
"Parses",
"the",
"different",
"pieces",
"of",
"the",
"digest",
"string",
"into",
"an",
"array",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L191-L205 | train |
sabre-io/http | lib/Request.php | Request.getQueryParameters | public function getQueryParameters(): array
{
$url = $this->getUrl();
if (false === ($index = strpos($url, '?'))) {
return [];
}
parse_str(substr($url, $index + 1), $queryParams);
return $queryParams;
} | php | public function getQueryParameters(): array
{
$url = $this->getUrl();
if (false === ($index = strpos($url, '?'))) {
return [];
}
parse_str(substr($url, $index + 1), $queryParams);
return $queryParams;
} | [
"public",
"function",
"getQueryParameters",
"(",
")",
":",
"array",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getUrl",
"(",
")",
";",
"if",
"(",
"false",
"===",
"(",
"$",
"index",
"=",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"parse_str",
"(",
"substr",
"(",
"$",
"url",
",",
"$",
"index",
"+",
"1",
")",
",",
"$",
"queryParams",
")",
";",
"return",
"$",
"queryParams",
";",
"}"
] | Returns the list of query parameters.
This is equivalent to PHP's $_GET superglobal. | [
"Returns",
"the",
"list",
"of",
"query",
"parameters",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Request.php#L86-L96 | train |
sabre-io/http | lib/Request.php | Request.getAbsoluteUrl | public function getAbsoluteUrl(): string
{
if (!$this->absoluteUrl) {
// Guessing we're a http endpoint.
$this->absoluteUrl = 'http://'.
($this->getHeader('Host') ?? 'localhost').
$this->getUrl();
}
return $this->absoluteUrl;
} | php | public function getAbsoluteUrl(): string
{
if (!$this->absoluteUrl) {
// Guessing we're a http endpoint.
$this->absoluteUrl = 'http://'.
($this->getHeader('Host') ?? 'localhost').
$this->getUrl();
}
return $this->absoluteUrl;
} | [
"public",
"function",
"getAbsoluteUrl",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"absoluteUrl",
")",
"{",
"// Guessing we're a http endpoint.",
"$",
"this",
"->",
"absoluteUrl",
"=",
"'http://'",
".",
"(",
"$",
"this",
"->",
"getHeader",
"(",
"'Host'",
")",
"??",
"'localhost'",
")",
".",
"$",
"this",
"->",
"getUrl",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"absoluteUrl",
";",
"}"
] | Returns the absolute url. | [
"Returns",
"the",
"absolute",
"url",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Request.php#L111-L121 | train |
sabre-io/http | lib/Request.php | Request.getPath | public function getPath(): string
{
// Removing duplicated slashes.
$uri = str_replace('//', '/', $this->getUrl());
$uri = Uri\normalize($uri);
$baseUri = Uri\normalize($this->getBaseUrl());
if (0 === strpos($uri, $baseUri)) {
// We're not interested in the query part (everything after the ?).
list($uri) = explode('?', $uri);
return trim(decodePath(substr($uri, strlen($baseUri))), '/');
}
if ($uri.'/' === $baseUri) {
return '';
}
// A special case, if the baseUri was accessed without a trailing
// slash, we'll accept it as well.
throw new \LogicException('Requested uri ('.$this->getUrl().') is out of base uri ('.$this->getBaseUrl().')');
} | php | public function getPath(): string
{
// Removing duplicated slashes.
$uri = str_replace('//', '/', $this->getUrl());
$uri = Uri\normalize($uri);
$baseUri = Uri\normalize($this->getBaseUrl());
if (0 === strpos($uri, $baseUri)) {
// We're not interested in the query part (everything after the ?).
list($uri) = explode('?', $uri);
return trim(decodePath(substr($uri, strlen($baseUri))), '/');
}
if ($uri.'/' === $baseUri) {
return '';
}
// A special case, if the baseUri was accessed without a trailing
// slash, we'll accept it as well.
throw new \LogicException('Requested uri ('.$this->getUrl().') is out of base uri ('.$this->getBaseUrl().')');
} | [
"public",
"function",
"getPath",
"(",
")",
":",
"string",
"{",
"// Removing duplicated slashes.",
"$",
"uri",
"=",
"str_replace",
"(",
"'//'",
",",
"'/'",
",",
"$",
"this",
"->",
"getUrl",
"(",
")",
")",
";",
"$",
"uri",
"=",
"Uri",
"\\",
"normalize",
"(",
"$",
"uri",
")",
";",
"$",
"baseUri",
"=",
"Uri",
"\\",
"normalize",
"(",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
")",
";",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"uri",
",",
"$",
"baseUri",
")",
")",
"{",
"// We're not interested in the query part (everything after the ?).",
"list",
"(",
"$",
"uri",
")",
"=",
"explode",
"(",
"'?'",
",",
"$",
"uri",
")",
";",
"return",
"trim",
"(",
"decodePath",
"(",
"substr",
"(",
"$",
"uri",
",",
"strlen",
"(",
"$",
"baseUri",
")",
")",
")",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"$",
"uri",
".",
"'/'",
"===",
"$",
"baseUri",
")",
"{",
"return",
"''",
";",
"}",
"// A special case, if the baseUri was accessed without a trailing",
"// slash, we'll accept it as well.",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Requested uri ('",
".",
"$",
"this",
"->",
"getUrl",
"(",
")",
".",
"') is out of base uri ('",
".",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
".",
"')'",
")",
";",
"}"
] | Returns the relative path.
This is being calculated using the base url. This path will not start
with a slash, so it will always return something like
'example/path.html'.
If the full path is equal to the base url, this method will return an
empty string.
This method will also urldecode the path, and if the url was incoded as
ISO-8859-1, it will convert it to UTF-8.
If the path is outside of the base url, a LogicException will be thrown. | [
"Returns",
"the",
"relative",
"path",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Request.php#L163-L185 | train |
sabre-io/http | lib/Auth/AWS.php | AWS.validate | public function validate(string $secretKey): bool
{
$contentMD5 = $this->request->getHeader('Content-MD5');
if ($contentMD5) {
// We need to validate the integrity of the request
$body = $this->request->getBody();
$this->request->setBody($body);
if ($contentMD5 !== base64_encode(md5((string) $body, true))) {
// content-md5 header did not match md5 signature of body
$this->errorCode = self::ERR_MD5CHECKSUMWRONG;
return false;
}
}
if (!$requestDate = $this->request->getHeader('x-amz-date')) {
$requestDate = $this->request->getHeader('Date');
}
if (!$this->validateRFC2616Date((string) $requestDate)) {
return false;
}
$amzHeaders = $this->getAmzHeaders();
$signature = base64_encode(
$this->hmacsha1($secretKey,
$this->request->getMethod()."\n".
$contentMD5."\n".
$this->request->getHeader('Content-type')."\n".
$requestDate."\n".
$amzHeaders.
$this->request->getUrl()
)
);
if ($this->signature !== $signature) {
$this->errorCode = self::ERR_INVALIDSIGNATURE;
return false;
}
return true;
} | php | public function validate(string $secretKey): bool
{
$contentMD5 = $this->request->getHeader('Content-MD5');
if ($contentMD5) {
// We need to validate the integrity of the request
$body = $this->request->getBody();
$this->request->setBody($body);
if ($contentMD5 !== base64_encode(md5((string) $body, true))) {
// content-md5 header did not match md5 signature of body
$this->errorCode = self::ERR_MD5CHECKSUMWRONG;
return false;
}
}
if (!$requestDate = $this->request->getHeader('x-amz-date')) {
$requestDate = $this->request->getHeader('Date');
}
if (!$this->validateRFC2616Date((string) $requestDate)) {
return false;
}
$amzHeaders = $this->getAmzHeaders();
$signature = base64_encode(
$this->hmacsha1($secretKey,
$this->request->getMethod()."\n".
$contentMD5."\n".
$this->request->getHeader('Content-type')."\n".
$requestDate."\n".
$amzHeaders.
$this->request->getUrl()
)
);
if ($this->signature !== $signature) {
$this->errorCode = self::ERR_INVALIDSIGNATURE;
return false;
}
return true;
} | [
"public",
"function",
"validate",
"(",
"string",
"$",
"secretKey",
")",
":",
"bool",
"{",
"$",
"contentMD5",
"=",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'Content-MD5'",
")",
";",
"if",
"(",
"$",
"contentMD5",
")",
"{",
"// We need to validate the integrity of the request",
"$",
"body",
"=",
"$",
"this",
"->",
"request",
"->",
"getBody",
"(",
")",
";",
"$",
"this",
"->",
"request",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"if",
"(",
"$",
"contentMD5",
"!==",
"base64_encode",
"(",
"md5",
"(",
"(",
"string",
")",
"$",
"body",
",",
"true",
")",
")",
")",
"{",
"// content-md5 header did not match md5 signature of body",
"$",
"this",
"->",
"errorCode",
"=",
"self",
"::",
"ERR_MD5CHECKSUMWRONG",
";",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"requestDate",
"=",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'x-amz-date'",
")",
")",
"{",
"$",
"requestDate",
"=",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'Date'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"validateRFC2616Date",
"(",
"(",
"string",
")",
"$",
"requestDate",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"amzHeaders",
"=",
"$",
"this",
"->",
"getAmzHeaders",
"(",
")",
";",
"$",
"signature",
"=",
"base64_encode",
"(",
"$",
"this",
"->",
"hmacsha1",
"(",
"$",
"secretKey",
",",
"$",
"this",
"->",
"request",
"->",
"getMethod",
"(",
")",
".",
"\"\\n\"",
".",
"$",
"contentMD5",
".",
"\"\\n\"",
".",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'Content-type'",
")",
".",
"\"\\n\"",
".",
"$",
"requestDate",
".",
"\"\\n\"",
".",
"$",
"amzHeaders",
".",
"$",
"this",
"->",
"request",
"->",
"getUrl",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"signature",
"!==",
"$",
"signature",
")",
"{",
"$",
"this",
"->",
"errorCode",
"=",
"self",
"::",
"ERR_INVALIDSIGNATURE",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Validates the signature based on the secretKey. | [
"Validates",
"the",
"signature",
"based",
"on",
"the",
"secretKey",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L87-L132 | train |
sabre-io/http | lib/Auth/AWS.php | AWS.validateRFC2616Date | protected function validateRFC2616Date(string $dateHeader): bool
{
$date = HTTP\parseDate($dateHeader);
// Unknown format
if (!$date) {
$this->errorCode = self::ERR_INVALIDDATEFORMAT;
return false;
}
$min = new \DateTime('-15 minutes');
$max = new \DateTime('+15 minutes');
// We allow 15 minutes around the current date/time
if ($date > $max || $date < $min) {
$this->errorCode = self::ERR_REQUESTTIMESKEWED;
return false;
}
return true;
} | php | protected function validateRFC2616Date(string $dateHeader): bool
{
$date = HTTP\parseDate($dateHeader);
// Unknown format
if (!$date) {
$this->errorCode = self::ERR_INVALIDDATEFORMAT;
return false;
}
$min = new \DateTime('-15 minutes');
$max = new \DateTime('+15 minutes');
// We allow 15 minutes around the current date/time
if ($date > $max || $date < $min) {
$this->errorCode = self::ERR_REQUESTTIMESKEWED;
return false;
}
return true;
} | [
"protected",
"function",
"validateRFC2616Date",
"(",
"string",
"$",
"dateHeader",
")",
":",
"bool",
"{",
"$",
"date",
"=",
"HTTP",
"\\",
"parseDate",
"(",
"$",
"dateHeader",
")",
";",
"// Unknown format",
"if",
"(",
"!",
"$",
"date",
")",
"{",
"$",
"this",
"->",
"errorCode",
"=",
"self",
"::",
"ERR_INVALIDDATEFORMAT",
";",
"return",
"false",
";",
"}",
"$",
"min",
"=",
"new",
"\\",
"DateTime",
"(",
"'-15 minutes'",
")",
";",
"$",
"max",
"=",
"new",
"\\",
"DateTime",
"(",
"'+15 minutes'",
")",
";",
"// We allow 15 minutes around the current date/time",
"if",
"(",
"$",
"date",
">",
"$",
"max",
"||",
"$",
"date",
"<",
"$",
"min",
")",
"{",
"$",
"this",
"->",
"errorCode",
"=",
"self",
"::",
"ERR_REQUESTTIMESKEWED",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Makes sure the supplied value is a valid RFC2616 date.
If we would just use strtotime to get a valid timestamp, we have no way of checking if a
user just supplied the word 'now' for the date header.
This function also makes sure the Date header is within 15 minutes of the operating
system date, to prevent replay attacks. | [
"Makes",
"sure",
"the",
"supplied",
"value",
"is",
"a",
"valid",
"RFC2616",
"date",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L154-L176 | train |
sabre-io/http | lib/Auth/AWS.php | AWS.getAmzHeaders | protected function getAmzHeaders(): string
{
$amzHeaders = [];
$headers = $this->request->getHeaders();
foreach ($headers as $headerName => $headerValue) {
if (0 === strpos(strtolower($headerName), 'x-amz-')) {
$amzHeaders[strtolower($headerName)] = str_replace(["\r\n"], [' '], $headerValue[0])."\n";
}
}
ksort($amzHeaders);
$headerStr = '';
foreach ($amzHeaders as $h => $v) {
$headerStr .= $h.':'.$v;
}
return $headerStr;
} | php | protected function getAmzHeaders(): string
{
$amzHeaders = [];
$headers = $this->request->getHeaders();
foreach ($headers as $headerName => $headerValue) {
if (0 === strpos(strtolower($headerName), 'x-amz-')) {
$amzHeaders[strtolower($headerName)] = str_replace(["\r\n"], [' '], $headerValue[0])."\n";
}
}
ksort($amzHeaders);
$headerStr = '';
foreach ($amzHeaders as $h => $v) {
$headerStr .= $h.':'.$v;
}
return $headerStr;
} | [
"protected",
"function",
"getAmzHeaders",
"(",
")",
":",
"string",
"{",
"$",
"amzHeaders",
"=",
"[",
"]",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"request",
"->",
"getHeaders",
"(",
")",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"headerName",
"=>",
"$",
"headerValue",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"strtolower",
"(",
"$",
"headerName",
")",
",",
"'x-amz-'",
")",
")",
"{",
"$",
"amzHeaders",
"[",
"strtolower",
"(",
"$",
"headerName",
")",
"]",
"=",
"str_replace",
"(",
"[",
"\"\\r\\n\"",
"]",
",",
"[",
"' '",
"]",
",",
"$",
"headerValue",
"[",
"0",
"]",
")",
".",
"\"\\n\"",
";",
"}",
"}",
"ksort",
"(",
"$",
"amzHeaders",
")",
";",
"$",
"headerStr",
"=",
"''",
";",
"foreach",
"(",
"$",
"amzHeaders",
"as",
"$",
"h",
"=>",
"$",
"v",
")",
"{",
"$",
"headerStr",
".=",
"$",
"h",
".",
"':'",
".",
"$",
"v",
";",
"}",
"return",
"$",
"headerStr",
";",
"}"
] | Returns a list of AMZ headers. | [
"Returns",
"a",
"list",
"of",
"AMZ",
"headers",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L181-L198 | train |
sabre-io/http | lib/Auth/AWS.php | AWS.hmacsha1 | private function hmacsha1(string $key, string $message): string
{
if (function_exists('hash_hmac')) {
return hash_hmac('sha1', $message, $key, true);
}
$blocksize = 64;
if (strlen($key) > $blocksize) {
$key = pack('H*', sha1($key));
}
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$hmac = pack('H*', sha1(($key ^ $opad).pack('H*', sha1(($key ^ $ipad).$message))));
return $hmac;
} | php | private function hmacsha1(string $key, string $message): string
{
if (function_exists('hash_hmac')) {
return hash_hmac('sha1', $message, $key, true);
}
$blocksize = 64;
if (strlen($key) > $blocksize) {
$key = pack('H*', sha1($key));
}
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$hmac = pack('H*', sha1(($key ^ $opad).pack('H*', sha1(($key ^ $ipad).$message))));
return $hmac;
} | [
"private",
"function",
"hmacsha1",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"message",
")",
":",
"string",
"{",
"if",
"(",
"function_exists",
"(",
"'hash_hmac'",
")",
")",
"{",
"return",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"message",
",",
"$",
"key",
",",
"true",
")",
";",
"}",
"$",
"blocksize",
"=",
"64",
";",
"if",
"(",
"strlen",
"(",
"$",
"key",
")",
">",
"$",
"blocksize",
")",
"{",
"$",
"key",
"=",
"pack",
"(",
"'H*'",
",",
"sha1",
"(",
"$",
"key",
")",
")",
";",
"}",
"$",
"key",
"=",
"str_pad",
"(",
"$",
"key",
",",
"$",
"blocksize",
",",
"chr",
"(",
"0x00",
")",
")",
";",
"$",
"ipad",
"=",
"str_repeat",
"(",
"chr",
"(",
"0x36",
")",
",",
"$",
"blocksize",
")",
";",
"$",
"opad",
"=",
"str_repeat",
"(",
"chr",
"(",
"0x5c",
")",
",",
"$",
"blocksize",
")",
";",
"$",
"hmac",
"=",
"pack",
"(",
"'H*'",
",",
"sha1",
"(",
"(",
"$",
"key",
"^",
"$",
"opad",
")",
".",
"pack",
"(",
"'H*'",
",",
"sha1",
"(",
"(",
"$",
"key",
"^",
"$",
"ipad",
")",
".",
"$",
"message",
")",
")",
")",
")",
";",
"return",
"$",
"hmac",
";",
"}"
] | Generates an HMAC-SHA1 signature. | [
"Generates",
"an",
"HMAC",
"-",
"SHA1",
"signature",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L203-L219 | train |
sabre-io/http | lib/Message.php | Message.getBodyAsStream | public function getBodyAsStream()
{
$body = $this->getBody();
if (is_callable($this->body)) {
$body = $this->getBodyAsString();
}
if (is_string($body) || null === $body) {
$stream = fopen('php://temp', 'r+');
fwrite($stream, (string) $body);
rewind($stream);
return $stream;
}
return $body;
} | php | public function getBodyAsStream()
{
$body = $this->getBody();
if (is_callable($this->body)) {
$body = $this->getBodyAsString();
}
if (is_string($body) || null === $body) {
$stream = fopen('php://temp', 'r+');
fwrite($stream, (string) $body);
rewind($stream);
return $stream;
}
return $body;
} | [
"public",
"function",
"getBodyAsStream",
"(",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"body",
")",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"getBodyAsString",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"body",
")",
"||",
"null",
"===",
"$",
"body",
")",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'r+'",
")",
";",
"fwrite",
"(",
"$",
"stream",
",",
"(",
"string",
")",
"$",
"body",
")",
";",
"rewind",
"(",
"$",
"stream",
")",
";",
"return",
"$",
"stream",
";",
"}",
"return",
"$",
"body",
";",
"}"
] | Returns the body as a readable stream resource.
Note that the stream may not be rewindable, and therefore may only be
read once.
@return resource | [
"Returns",
"the",
"body",
"as",
"a",
"readable",
"stream",
"resource",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L49-L64 | train |
sabre-io/http | lib/Message.php | Message.getBodyAsString | public function getBodyAsString(): string
{
$body = $this->getBody();
if (is_string($body)) {
return $body;
}
if (null === $body) {
return '';
}
if (is_callable($body)) {
ob_start();
$body();
return ob_get_clean();
}
/**
* @var string|int|null
*/
$contentLength = $this->getHeader('Content-Length');
if (is_int($contentLength) || ctype_digit($contentLength)) {
return stream_get_contents($body, (int) $contentLength);
}
return stream_get_contents($body);
} | php | public function getBodyAsString(): string
{
$body = $this->getBody();
if (is_string($body)) {
return $body;
}
if (null === $body) {
return '';
}
if (is_callable($body)) {
ob_start();
$body();
return ob_get_clean();
}
/**
* @var string|int|null
*/
$contentLength = $this->getHeader('Content-Length');
if (is_int($contentLength) || ctype_digit($contentLength)) {
return stream_get_contents($body, (int) $contentLength);
}
return stream_get_contents($body);
} | [
"public",
"function",
"getBodyAsString",
"(",
")",
":",
"string",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"body",
")",
")",
"{",
"return",
"$",
"body",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"body",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"body",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"body",
"(",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}",
"/**\n * @var string|int|null\n */",
"$",
"contentLength",
"=",
"$",
"this",
"->",
"getHeader",
"(",
"'Content-Length'",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"contentLength",
")",
"||",
"ctype_digit",
"(",
"$",
"contentLength",
")",
")",
"{",
"return",
"stream_get_contents",
"(",
"$",
"body",
",",
"(",
"int",
")",
"$",
"contentLength",
")",
";",
"}",
"return",
"stream_get_contents",
"(",
"$",
"body",
")",
";",
"}"
] | Returns the body as a string.
Note that because the underlying data may be based on a stream, this
method could only work correctly the first time. | [
"Returns",
"the",
"body",
"as",
"a",
"string",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L72-L96 | train |
sabre-io/http | lib/Message.php | Message.getHeaders | public function getHeaders(): array
{
$result = [];
foreach ($this->headers as $headerInfo) {
$result[$headerInfo[0]] = $headerInfo[1];
}
return $result;
} | php | public function getHeaders(): array
{
$result = [];
foreach ($this->headers as $headerInfo) {
$result[$headerInfo[0]] = $headerInfo[1];
}
return $result;
} | [
"public",
"function",
"getHeaders",
"(",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"headerInfo",
")",
"{",
"$",
"result",
"[",
"$",
"headerInfo",
"[",
"0",
"]",
"]",
"=",
"$",
"headerInfo",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns all the HTTP headers as an array.
Every header is returned as an array, with one or more values. | [
"Returns",
"all",
"the",
"HTTP",
"headers",
"as",
"an",
"array",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L125-L133 | train |
sabre-io/http | lib/Message.php | Message.addHeader | public function addHeader(string $name, $value)
{
$lName = strtolower($name);
if (isset($this->headers[$lName])) {
$this->headers[$lName][1] = array_merge(
$this->headers[$lName][1],
(array) $value
);
} else {
$this->headers[$lName] = [
$name,
(array) $value,
];
}
} | php | public function addHeader(string $name, $value)
{
$lName = strtolower($name);
if (isset($this->headers[$lName])) {
$this->headers[$lName][1] = array_merge(
$this->headers[$lName][1],
(array) $value
);
} else {
$this->headers[$lName] = [
$name,
(array) $value,
];
}
} | [
"public",
"function",
"addHeader",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"lName",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"lName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"lName",
"]",
"[",
"1",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"lName",
"]",
"[",
"1",
"]",
",",
"(",
"array",
")",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"lName",
"]",
"=",
"[",
"$",
"name",
",",
"(",
"array",
")",
"$",
"value",
",",
"]",
";",
"}",
"}"
] | Adds a HTTP header.
This method will not overwrite any existing HTTP header, but instead add
another value. Individual values can be retrieved with
getHeadersAsArray.
@param string|string[] $value | [
"Adds",
"a",
"HTTP",
"header",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L228-L242 | train |
sabre-io/http | lib/Message.php | Message.removeHeader | public function removeHeader(string $name): bool
{
$name = strtolower($name);
if (!isset($this->headers[$name])) {
return false;
}
unset($this->headers[$name]);
return true;
} | php | public function removeHeader(string $name): bool
{
$name = strtolower($name);
if (!isset($this->headers[$name])) {
return false;
}
unset($this->headers[$name]);
return true;
} | [
"public",
"function",
"removeHeader",
"(",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Removes a HTTP header.
The specified header name must be treated as case-insensitive.
This method should return true if the header was successfully deleted,
and false if the header did not exist. | [
"Removes",
"a",
"HTTP",
"header",
"."
] | 404788805fa07338599ebc25b6aa834be02abe2f | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L263-L272 | train |
mongodb/mongo-php-library | src/Collection.php | Collection.aggregate | public function aggregate(array $pipeline, array $options = [])
{
$hasOutStage = \MongoDB\is_last_pipeline_operator_out($pipeline);
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
if ($hasOutStage) {
$options['readPreference'] = new ReadPreference(ReadPreference::RP_PRIMARY);
}
$server = $this->manager->selectServer($options['readPreference']);
/* A "majority" read concern is not compatible with the $out stage, so
* avoid providing the Collection's read concern if it would conflict.
*
* A read concern is also not compatible with transactions.
*/
if ( ! isset($options['readConcern']) &&
! ($hasOutStage && $this->readConcern->getLevel() === ReadConcern::MAJORITY) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) &&
! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
}
if ($hasOutStage &&
! isset($options['writeConcern']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) &&
! $this->isInTransaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new Aggregate($this->databaseName, $this->collectionName, $pipeline, $options);
return $operation->execute($server);
} | php | public function aggregate(array $pipeline, array $options = [])
{
$hasOutStage = \MongoDB\is_last_pipeline_operator_out($pipeline);
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
if ($hasOutStage) {
$options['readPreference'] = new ReadPreference(ReadPreference::RP_PRIMARY);
}
$server = $this->manager->selectServer($options['readPreference']);
/* A "majority" read concern is not compatible with the $out stage, so
* avoid providing the Collection's read concern if it would conflict.
*
* A read concern is also not compatible with transactions.
*/
if ( ! isset($options['readConcern']) &&
! ($hasOutStage && $this->readConcern->getLevel() === ReadConcern::MAJORITY) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) &&
! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
}
if ($hasOutStage &&
! isset($options['writeConcern']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) &&
! $this->isInTransaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new Aggregate($this->databaseName, $this->collectionName, $pipeline, $options);
return $operation->execute($server);
} | [
"public",
"function",
"aggregate",
"(",
"array",
"$",
"pipeline",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"hasOutStage",
"=",
"\\",
"MongoDB",
"\\",
"is_last_pipeline_operator_out",
"(",
"$",
"pipeline",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"$",
"this",
"->",
"readPreference",
";",
"}",
"if",
"(",
"$",
"hasOutStage",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"new",
"ReadPreference",
"(",
"ReadPreference",
"::",
"RP_PRIMARY",
")",
";",
"}",
"$",
"server",
"=",
"$",
"this",
"->",
"manager",
"->",
"selectServer",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
";",
"/* A \"majority\" read concern is not compatible with the $out stage, so\n * avoid providing the Collection's read concern if it would conflict.\n *\n * A read concern is also not compatible with transactions.\n */",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readConcern'",
"]",
")",
"&&",
"!",
"(",
"$",
"hasOutStage",
"&&",
"$",
"this",
"->",
"readConcern",
"->",
"getLevel",
"(",
")",
"===",
"ReadConcern",
"::",
"MAJORITY",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForReadConcern",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'readConcern'",
"]",
"=",
"$",
"this",
"->",
"readConcern",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'typeMap'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'typeMap'",
"]",
"=",
"$",
"this",
"->",
"typeMap",
";",
"}",
"if",
"(",
"$",
"hasOutStage",
"&&",
"!",
"isset",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForWritableCommandWriteConcern",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'writeConcern'",
"]",
"=",
"$",
"this",
"->",
"writeConcern",
";",
"}",
"$",
"operation",
"=",
"new",
"Aggregate",
"(",
"$",
"this",
"->",
"databaseName",
",",
"$",
"this",
"->",
"collectionName",
",",
"$",
"pipeline",
",",
"$",
"options",
")",
";",
"return",
"$",
"operation",
"->",
"execute",
"(",
"$",
"server",
")",
";",
"}"
] | Executes an aggregation framework pipeline on the collection.
Note: this method's return value depends on the MongoDB server version
and the "useCursor" option. If "useCursor" is true, a Cursor will be
returned; otherwise, an ArrayIterator is returned, which wraps the
"result" array from the command response document.
@see Aggregate::__construct() for supported options
@param array $pipeline List of pipeline operations
@param array $options Command options
@return Traversable
@throws UnexpectedValueException if the command response was malformed
@throws UnsupportedException if options are not supported by the selected server
@throws InvalidArgumentException for parameter/option parsing errors
@throws DriverRuntimeException for other driver errors (e.g. connection errors) | [
"Executes",
"an",
"aggregation",
"framework",
"pipeline",
"on",
"the",
"collection",
"."
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L190-L230 | train |
mongodb/mongo-php-library | src/Collection.php | Collection.count | public function count($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
$server = $this->manager->selectServer($options['readPreference']);
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
$operation = new Count($this->databaseName, $this->collectionName, $filter, $options);
return $operation->execute($server);
} | php | public function count($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
$server = $this->manager->selectServer($options['readPreference']);
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
$operation = new Count($this->databaseName, $this->collectionName, $filter, $options);
return $operation->execute($server);
} | [
"public",
"function",
"count",
"(",
"$",
"filter",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"$",
"this",
"->",
"readPreference",
";",
"}",
"$",
"server",
"=",
"$",
"this",
"->",
"manager",
"->",
"selectServer",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readConcern'",
"]",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForReadConcern",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'readConcern'",
"]",
"=",
"$",
"this",
"->",
"readConcern",
";",
"}",
"$",
"operation",
"=",
"new",
"Count",
"(",
"$",
"this",
"->",
"databaseName",
",",
"$",
"this",
"->",
"collectionName",
",",
"$",
"filter",
",",
"$",
"options",
")",
";",
"return",
"$",
"operation",
"->",
"execute",
"(",
"$",
"server",
")",
";",
"}"
] | Gets the number of documents matching the filter.
@see Count::__construct() for supported options
@param array|object $filter Query by which to filter documents
@param array $options Command options
@return integer
@throws UnexpectedValueException if the command response was malformed
@throws UnsupportedException if options are not supported by the selected server
@throws InvalidArgumentException for parameter/option parsing errors
@throws DriverRuntimeException for other driver errors (e.g. connection errors)
@deprecated 1.4 | [
"Gets",
"the",
"number",
"of",
"documents",
"matching",
"the",
"filter",
"."
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L269-L284 | train |
mongodb/mongo-php-library | src/Collection.php | Collection.distinct | public function distinct($fieldName, $filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
$server = $this->manager->selectServer($options['readPreference']);
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
$operation = new Distinct($this->databaseName, $this->collectionName, $fieldName, $filter, $options);
return $operation->execute($server);
} | php | public function distinct($fieldName, $filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
$server = $this->manager->selectServer($options['readPreference']);
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
$operation = new Distinct($this->databaseName, $this->collectionName, $fieldName, $filter, $options);
return $operation->execute($server);
} | [
"public",
"function",
"distinct",
"(",
"$",
"fieldName",
",",
"$",
"filter",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"$",
"this",
"->",
"readPreference",
";",
"}",
"$",
"server",
"=",
"$",
"this",
"->",
"manager",
"->",
"selectServer",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readConcern'",
"]",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForReadConcern",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'readConcern'",
"]",
"=",
"$",
"this",
"->",
"readConcern",
";",
"}",
"$",
"operation",
"=",
"new",
"Distinct",
"(",
"$",
"this",
"->",
"databaseName",
",",
"$",
"this",
"->",
"collectionName",
",",
"$",
"fieldName",
",",
"$",
"filter",
",",
"$",
"options",
")",
";",
"return",
"$",
"operation",
"->",
"execute",
"(",
"$",
"server",
")",
";",
"}"
] | Finds the distinct values for a specified field across the collection.
@see Distinct::__construct() for supported options
@param string $fieldName Field for which to return distinct values
@param array|object $filter Query by which to filter documents
@param array $options Command options
@return mixed[]
@throws UnexpectedValueException if the command response was malformed
@throws UnsupportedException if options are not supported by the selected server
@throws InvalidArgumentException for parameter/option parsing errors
@throws DriverRuntimeException for other driver errors (e.g. connection errors) | [
"Finds",
"the",
"distinct",
"values",
"for",
"a",
"specified",
"field",
"across",
"the",
"collection",
"."
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L438-L453 | train |
mongodb/mongo-php-library | src/Collection.php | Collection.insertMany | public function insertMany(array $documents, array $options = [])
{
if ( ! isset($options['writeConcern']) && ! $this->isInTransaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new InsertMany($this->databaseName, $this->collectionName, $documents, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
return $operation->execute($server);
} | php | public function insertMany(array $documents, array $options = [])
{
if ( ! isset($options['writeConcern']) && ! $this->isInTransaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new InsertMany($this->databaseName, $this->collectionName, $documents, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
return $operation->execute($server);
} | [
"public",
"function",
"insertMany",
"(",
"array",
"$",
"documents",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'writeConcern'",
"]",
"=",
"$",
"this",
"->",
"writeConcern",
";",
"}",
"$",
"operation",
"=",
"new",
"InsertMany",
"(",
"$",
"this",
"->",
"databaseName",
",",
"$",
"this",
"->",
"collectionName",
",",
"$",
"documents",
",",
"$",
"options",
")",
";",
"$",
"server",
"=",
"$",
"this",
"->",
"manager",
"->",
"selectServer",
"(",
"new",
"ReadPreference",
"(",
"ReadPreference",
"::",
"RP_PRIMARY",
")",
")",
";",
"return",
"$",
"operation",
"->",
"execute",
"(",
"$",
"server",
")",
";",
"}"
] | Inserts multiple documents.
@see InsertMany::__construct() for supported options
@see http://docs.mongodb.org/manual/reference/command/insert/
@param array[]|object[] $documents The documents to insert
@param array $options Command options
@return InsertManyResult
@throws InvalidArgumentException for parameter/option parsing errors
@throws DriverRuntimeException for other driver errors (e.g. connection errors) | [
"Inserts",
"multiple",
"documents",
"."
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L866-L876 | train |
mongodb/mongo-php-library | src/Collection.php | Collection.insertOne | public function insertOne($document, array $options = [])
{
if ( ! isset($options['writeConcern']) && ! $this->isInTransaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new InsertOne($this->databaseName, $this->collectionName, $document, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
return $operation->execute($server);
} | php | public function insertOne($document, array $options = [])
{
if ( ! isset($options['writeConcern']) && ! $this->isInTransaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new InsertOne($this->databaseName, $this->collectionName, $document, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
return $operation->execute($server);
} | [
"public",
"function",
"insertOne",
"(",
"$",
"document",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'writeConcern'",
"]",
"=",
"$",
"this",
"->",
"writeConcern",
";",
"}",
"$",
"operation",
"=",
"new",
"InsertOne",
"(",
"$",
"this",
"->",
"databaseName",
",",
"$",
"this",
"->",
"collectionName",
",",
"$",
"document",
",",
"$",
"options",
")",
";",
"$",
"server",
"=",
"$",
"this",
"->",
"manager",
"->",
"selectServer",
"(",
"new",
"ReadPreference",
"(",
"ReadPreference",
"::",
"RP_PRIMARY",
")",
")",
";",
"return",
"$",
"operation",
"->",
"execute",
"(",
"$",
"server",
")",
";",
"}"
] | Inserts one document.
@see InsertOne::__construct() for supported options
@see http://docs.mongodb.org/manual/reference/command/insert/
@param array|object $document The document to insert
@param array $options Command options
@return InsertOneResult
@throws InvalidArgumentException for parameter/option parsing errors
@throws DriverRuntimeException for other driver errors (e.g. connection errors) | [
"Inserts",
"one",
"document",
"."
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L889-L899 | train |
mongodb/mongo-php-library | src/Collection.php | Collection.mapReduce | public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])
{
$hasOutputCollection = ! \MongoDB\is_mapreduce_output_inline($out);
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
// Check if the out option is inline because we will want to coerce a primary read preference if not
if ($hasOutputCollection) {
$options['readPreference'] = new ReadPreference(ReadPreference::RP_PRIMARY);
}
$server = $this->manager->selectServer($options['readPreference']);
/* A "majority" read concern is not compatible with inline output, so
* avoid providing the Collection's read concern if it would conflict.
*
* A read concern is also not compatible with transactions.
*/
if ( ! isset($options['readConcern']) && ! ($hasOutputCollection && $this->readConcern->getLevel() === ReadConcern::MAJORITY) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
}
if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! $this->isInTransaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new MapReduce($this->databaseName, $this->collectionName, $map, $reduce, $out, $options);
return $operation->execute($server);
} | php | public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])
{
$hasOutputCollection = ! \MongoDB\is_mapreduce_output_inline($out);
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
// Check if the out option is inline because we will want to coerce a primary read preference if not
if ($hasOutputCollection) {
$options['readPreference'] = new ReadPreference(ReadPreference::RP_PRIMARY);
}
$server = $this->manager->selectServer($options['readPreference']);
/* A "majority" read concern is not compatible with inline output, so
* avoid providing the Collection's read concern if it would conflict.
*
* A read concern is also not compatible with transactions.
*/
if ( ! isset($options['readConcern']) && ! ($hasOutputCollection && $this->readConcern->getLevel() === ReadConcern::MAJORITY) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
}
if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! $this->isInTransaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new MapReduce($this->databaseName, $this->collectionName, $map, $reduce, $out, $options);
return $operation->execute($server);
} | [
"public",
"function",
"mapReduce",
"(",
"JavascriptInterface",
"$",
"map",
",",
"JavascriptInterface",
"$",
"reduce",
",",
"$",
"out",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"hasOutputCollection",
"=",
"!",
"\\",
"MongoDB",
"\\",
"is_mapreduce_output_inline",
"(",
"$",
"out",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"$",
"this",
"->",
"readPreference",
";",
"}",
"// Check if the out option is inline because we will want to coerce a primary read preference if not",
"if",
"(",
"$",
"hasOutputCollection",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"new",
"ReadPreference",
"(",
"ReadPreference",
"::",
"RP_PRIMARY",
")",
";",
"}",
"$",
"server",
"=",
"$",
"this",
"->",
"manager",
"->",
"selectServer",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
";",
"/* A \"majority\" read concern is not compatible with inline output, so\n * avoid providing the Collection's read concern if it would conflict.\n *\n * A read concern is also not compatible with transactions.\n */",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readConcern'",
"]",
")",
"&&",
"!",
"(",
"$",
"hasOutputCollection",
"&&",
"$",
"this",
"->",
"readConcern",
"->",
"getLevel",
"(",
")",
"===",
"ReadConcern",
"::",
"MAJORITY",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForReadConcern",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'readConcern'",
"]",
"=",
"$",
"this",
"->",
"readConcern",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'typeMap'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'typeMap'",
"]",
"=",
"$",
"this",
"->",
"typeMap",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'writeConcern'",
"]",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForWritableCommandWriteConcern",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'writeConcern'",
"]",
"=",
"$",
"this",
"->",
"writeConcern",
";",
"}",
"$",
"operation",
"=",
"new",
"MapReduce",
"(",
"$",
"this",
"->",
"databaseName",
",",
"$",
"this",
"->",
"collectionName",
",",
"$",
"map",
",",
"$",
"reduce",
",",
"$",
"out",
",",
"$",
"options",
")",
";",
"return",
"$",
"operation",
"->",
"execute",
"(",
"$",
"server",
")",
";",
"}"
] | Executes a map-reduce aggregation on the collection.
@see MapReduce::__construct() for supported options
@see http://docs.mongodb.org/manual/reference/command/mapReduce/
@param JavascriptInterface $map Map function
@param JavascriptInterface $reduce Reduce function
@param string|array|object $out Output specification
@param array $options Command options
@return MapReduceResult
@throws UnsupportedException if options are not supported by the selected server
@throws InvalidArgumentException for parameter/option parsing errors
@throws DriverRuntimeException for other driver errors (e.g. connection errors)
@throws UnexpectedValueException if the command response was malformed | [
"Executes",
"a",
"map",
"-",
"reduce",
"aggregation",
"on",
"the",
"collection",
"."
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L933-L968 | train |
mongodb/mongo-php-library | src/Collection.php | Collection.watch | public function watch(array $pipeline = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
$server = $this->manager->selectServer($options['readPreference']);
/* Although change streams require a newer version of the server than
* read concerns, perform the usual wire version check before inheriting
* the collection's read concern. In the event that the server is too
* old, this makes it more likely that users will encounter an error
* related to change streams being unsupported instead of an
* UnsupportedException regarding use of the "readConcern" option from
* the Aggregate operation class. */
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
}
$operation = new Watch($this->manager, $this->databaseName, $this->collectionName, $pipeline, $options);
return $operation->execute($server);
} | php | public function watch(array $pipeline = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
$server = $this->manager->selectServer($options['readPreference']);
/* Although change streams require a newer version of the server than
* read concerns, perform the usual wire version check before inheriting
* the collection's read concern. In the event that the server is too
* old, this makes it more likely that users will encounter an error
* related to change streams being unsupported instead of an
* UnsupportedException regarding use of the "readConcern" option from
* the Aggregate operation class. */
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
$options['readConcern'] = $this->readConcern;
}
if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
}
$operation = new Watch($this->manager, $this->databaseName, $this->collectionName, $pipeline, $options);
return $operation->execute($server);
} | [
"public",
"function",
"watch",
"(",
"array",
"$",
"pipeline",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"$",
"this",
"->",
"readPreference",
";",
"}",
"$",
"server",
"=",
"$",
"this",
"->",
"manager",
"->",
"selectServer",
"(",
"$",
"options",
"[",
"'readPreference'",
"]",
")",
";",
"/* Although change streams require a newer version of the server than\n * read concerns, perform the usual wire version check before inheriting\n * the collection's read concern. In the event that the server is too\n * old, this makes it more likely that users will encounter an error\n * related to change streams being unsupported instead of an\n * UnsupportedException regarding use of the \"readConcern\" option from\n * the Aggregate operation class. */",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'readConcern'",
"]",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForReadConcern",
")",
"&&",
"!",
"$",
"this",
"->",
"isInTransaction",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"[",
"'readConcern'",
"]",
"=",
"$",
"this",
"->",
"readConcern",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'typeMap'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'typeMap'",
"]",
"=",
"$",
"this",
"->",
"typeMap",
";",
"}",
"$",
"operation",
"=",
"new",
"Watch",
"(",
"$",
"this",
"->",
"manager",
",",
"$",
"this",
"->",
"databaseName",
",",
"$",
"this",
"->",
"collectionName",
",",
"$",
"pipeline",
",",
"$",
"options",
")",
";",
"return",
"$",
"operation",
"->",
"execute",
"(",
"$",
"server",
")",
";",
"}"
] | Create a change stream for watching changes to the collection.
@see Watch::__construct() for supported options
@param array $pipeline List of pipeline operations
@param array $options Command options
@return ChangeStream
@throws InvalidArgumentException for parameter/option parsing errors | [
"Create",
"a",
"change",
"stream",
"for",
"watching",
"changes",
"to",
"the",
"collection",
"."
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L1054-L1080 | train |
mongodb/mongo-php-library | src/Collection.php | Collection.isInTransaction | private function isInTransaction(array $options)
{
if (isset($options['session']) && $options['session'] instanceof \MongoDB\Driver\Session && $options['session']->isInTransaction()) {
return true;
}
return false;
} | php | private function isInTransaction(array $options)
{
if (isset($options['session']) && $options['session'] instanceof \MongoDB\Driver\Session && $options['session']->isInTransaction()) {
return true;
}
return false;
} | [
"private",
"function",
"isInTransaction",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'session'",
"]",
")",
"&&",
"$",
"options",
"[",
"'session'",
"]",
"instanceof",
"\\",
"MongoDB",
"\\",
"Driver",
"\\",
"Session",
"&&",
"$",
"options",
"[",
"'session'",
"]",
"->",
"isInTransaction",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns whether we are currently in a transaction
@param array $options Command options
@return bool | [
"Returns",
"whether",
"we",
"are",
"currently",
"in",
"a",
"transaction"
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L1108-L1114 | train |
mongodb/mongo-php-library | src/Operation/FindAndModify.php | FindAndModify.createCommandDocument | private function createCommandDocument(Server $server)
{
$cmd = ['findAndModify' => $this->collectionName];
if ($this->options['remove']) {
$cmd['remove'] = true;
} else {
$cmd['new'] = $this->options['new'];
$cmd['upsert'] = $this->options['upsert'];
}
foreach (['collation', 'fields', 'query', 'sort', 'update'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = (object) $this->options[$option];
}
}
if (isset($this->options['arrayFilters'])) {
$cmd['arrayFilters'] = $this->options['arrayFilters'];
}
if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
}
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
return $cmd;
} | php | private function createCommandDocument(Server $server)
{
$cmd = ['findAndModify' => $this->collectionName];
if ($this->options['remove']) {
$cmd['remove'] = true;
} else {
$cmd['new'] = $this->options['new'];
$cmd['upsert'] = $this->options['upsert'];
}
foreach (['collation', 'fields', 'query', 'sort', 'update'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = (object) $this->options[$option];
}
}
if (isset($this->options['arrayFilters'])) {
$cmd['arrayFilters'] = $this->options['arrayFilters'];
}
if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
}
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
return $cmd;
} | [
"private",
"function",
"createCommandDocument",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"cmd",
"=",
"[",
"'findAndModify'",
"=>",
"$",
"this",
"->",
"collectionName",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'remove'",
"]",
")",
"{",
"$",
"cmd",
"[",
"'remove'",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"cmd",
"[",
"'new'",
"]",
"=",
"$",
"this",
"->",
"options",
"[",
"'new'",
"]",
";",
"$",
"cmd",
"[",
"'upsert'",
"]",
"=",
"$",
"this",
"->",
"options",
"[",
"'upsert'",
"]",
";",
"}",
"foreach",
"(",
"[",
"'collation'",
",",
"'fields'",
",",
"'query'",
",",
"'sort'",
",",
"'update'",
"]",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
")",
")",
"{",
"$",
"cmd",
"[",
"$",
"option",
"]",
"=",
"(",
"object",
")",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'arrayFilters'",
"]",
")",
")",
"{",
"$",
"cmd",
"[",
"'arrayFilters'",
"]",
"=",
"$",
"this",
"->",
"options",
"[",
"'arrayFilters'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'maxTimeMS'",
"]",
")",
")",
"{",
"$",
"cmd",
"[",
"'maxTimeMS'",
"]",
"=",
"$",
"this",
"->",
"options",
"[",
"'maxTimeMS'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"options",
"[",
"'bypassDocumentValidation'",
"]",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForDocumentLevelValidation",
")",
")",
"{",
"$",
"cmd",
"[",
"'bypassDocumentValidation'",
"]",
"=",
"$",
"this",
"->",
"options",
"[",
"'bypassDocumentValidation'",
"]",
";",
"}",
"return",
"$",
"cmd",
";",
"}"
] | Create the findAndModify command document.
@param Server $server
@return array | [
"Create",
"the",
"findAndModify",
"command",
"document",
"."
] | d444ddead4cf8a3d93f4c9206e7eac1ac14ff216 | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Operation/FindAndModify.php#L247-L280 | train |
slevomat/coding-standard | SlevomatCodingStandard/Helpers/TypeHelper.php | TypeHelper.isTypeName | public static function isTypeName(string $typeName): bool
{
$matches = [];
$result = preg_match('~^\\\\?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)(\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*$~', $typeName, $matches);
if ($result === false) {
// @codeCoverageIgnoreStart
throw new Exception('PREG error ' . preg_last_error());
// @codeCoverageIgnoreEnd
}
return $result !== 0 && $matches !== null;
} | php | public static function isTypeName(string $typeName): bool
{
$matches = [];
$result = preg_match('~^\\\\?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)(\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*$~', $typeName, $matches);
if ($result === false) {
// @codeCoverageIgnoreStart
throw new Exception('PREG error ' . preg_last_error());
// @codeCoverageIgnoreEnd
}
return $result !== 0 && $matches !== null;
} | [
"public",
"static",
"function",
"isTypeName",
"(",
"string",
"$",
"typeName",
")",
":",
"bool",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"result",
"=",
"preg_match",
"(",
"'~^\\\\\\\\?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)(\\\\\\\\[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*$~'",
",",
"$",
"typeName",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"new",
"Exception",
"(",
"'PREG error '",
".",
"preg_last_error",
"(",
")",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"return",
"$",
"result",
"!==",
"0",
"&&",
"$",
"matches",
"!==",
"null",
";",
"}"
] | Validates type name according to the allowed characters in type names + namespaces
@link http://php.net/manual/en/language.oop5.basic.php
@param string $typeName
@return bool | [
"Validates",
"type",
"name",
"according",
"to",
"the",
"allowed",
"characters",
"in",
"type",
"names",
"+",
"namespaces"
] | 1ff7cfb8e8df3af138cd04793ca1fbfea254cd50 | https://github.com/slevomat/coding-standard/blob/1ff7cfb8e8df3af138cd04793ca1fbfea254cd50/SlevomatCodingStandard/Helpers/TypeHelper.php#L19-L31 | train |
slevomat/coding-standard | SlevomatCodingStandard/Helpers/UseStatementHelper.php | UseStatementHelper.getUseStatementPointers | private static function getUseStatementPointers(File $phpcsFile, int $openTagPointer): array
{
$tokens = $phpcsFile->getTokens();
$pointer = $openTagPointer + 1;
$pointers = [];
while (true) {
$typesToFind = array_merge([T_USE], TokenHelper::$typeKeywordTokenCodes);
$pointer = TokenHelper::findNext($phpcsFile, $typesToFind, $pointer);
if ($pointer === null) {
break;
}
$token = $tokens[$pointer];
if (in_array($token['code'], TokenHelper::$typeKeywordTokenCodes, true)) {
$pointer = $token['scope_closer'] + 1;
continue;
}
if (self::isAnonymousFunctionUse($phpcsFile, $pointer)) {
$pointer++;
continue;
}
$pointers[] = $pointer;
$pointer++;
}
return $pointers;
} | php | private static function getUseStatementPointers(File $phpcsFile, int $openTagPointer): array
{
$tokens = $phpcsFile->getTokens();
$pointer = $openTagPointer + 1;
$pointers = [];
while (true) {
$typesToFind = array_merge([T_USE], TokenHelper::$typeKeywordTokenCodes);
$pointer = TokenHelper::findNext($phpcsFile, $typesToFind, $pointer);
if ($pointer === null) {
break;
}
$token = $tokens[$pointer];
if (in_array($token['code'], TokenHelper::$typeKeywordTokenCodes, true)) {
$pointer = $token['scope_closer'] + 1;
continue;
}
if (self::isAnonymousFunctionUse($phpcsFile, $pointer)) {
$pointer++;
continue;
}
$pointers[] = $pointer;
$pointer++;
}
return $pointers;
} | [
"private",
"static",
"function",
"getUseStatementPointers",
"(",
"File",
"$",
"phpcsFile",
",",
"int",
"$",
"openTagPointer",
")",
":",
"array",
"{",
"$",
"tokens",
"=",
"$",
"phpcsFile",
"->",
"getTokens",
"(",
")",
";",
"$",
"pointer",
"=",
"$",
"openTagPointer",
"+",
"1",
";",
"$",
"pointers",
"=",
"[",
"]",
";",
"while",
"(",
"true",
")",
"{",
"$",
"typesToFind",
"=",
"array_merge",
"(",
"[",
"T_USE",
"]",
",",
"TokenHelper",
"::",
"$",
"typeKeywordTokenCodes",
")",
";",
"$",
"pointer",
"=",
"TokenHelper",
"::",
"findNext",
"(",
"$",
"phpcsFile",
",",
"$",
"typesToFind",
",",
"$",
"pointer",
")",
";",
"if",
"(",
"$",
"pointer",
"===",
"null",
")",
"{",
"break",
";",
"}",
"$",
"token",
"=",
"$",
"tokens",
"[",
"$",
"pointer",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"token",
"[",
"'code'",
"]",
",",
"TokenHelper",
"::",
"$",
"typeKeywordTokenCodes",
",",
"true",
")",
")",
"{",
"$",
"pointer",
"=",
"$",
"token",
"[",
"'scope_closer'",
"]",
"+",
"1",
";",
"continue",
";",
"}",
"if",
"(",
"self",
"::",
"isAnonymousFunctionUse",
"(",
"$",
"phpcsFile",
",",
"$",
"pointer",
")",
")",
"{",
"$",
"pointer",
"++",
";",
"continue",
";",
"}",
"$",
"pointers",
"[",
"]",
"=",
"$",
"pointer",
";",
"$",
"pointer",
"++",
";",
"}",
"return",
"$",
"pointers",
";",
"}"
] | Searches for all use statements in a file, skips bodies of classes and traits.
@param \PHP_CodeSniffer\Files\File $phpcsFile
@param int $openTagPointer
@return int[] | [
"Searches",
"for",
"all",
"use",
"statements",
"in",
"a",
"file",
"skips",
"bodies",
"of",
"classes",
"and",
"traits",
"."
] | 1ff7cfb8e8df3af138cd04793ca1fbfea254cd50 | https://github.com/slevomat/coding-standard/blob/1ff7cfb8e8df3af138cd04793ca1fbfea254cd50/SlevomatCodingStandard/Helpers/UseStatementHelper.php#L193-L218 | train |
anhskohbo/no-captcha | src/NoCaptcha.php | NoCaptcha.displaySubmit | public function displaySubmit($formIdentifier, $text = 'submit', $attributes = [])
{
$javascript = '';
if (!isset($attributes['data-callback'])) {
$functionName = 'onSubmit' . str_replace(['-', '=', '\'', '"', '<', '>', '`'], '', $formIdentifier);
$attributes['data-callback'] = $functionName;
$javascript = sprintf(
'<script>function %s(){document.getElementById("%s").submit();}</script>',
$functionName,
$formIdentifier
);
}
$attributes = $this->prepareAttributes($attributes);
$button = sprintf('<button%s><span>%s</span></button>', $this->buildAttributes($attributes), $text);
return $button . $javascript;
} | php | public function displaySubmit($formIdentifier, $text = 'submit', $attributes = [])
{
$javascript = '';
if (!isset($attributes['data-callback'])) {
$functionName = 'onSubmit' . str_replace(['-', '=', '\'', '"', '<', '>', '`'], '', $formIdentifier);
$attributes['data-callback'] = $functionName;
$javascript = sprintf(
'<script>function %s(){document.getElementById("%s").submit();}</script>',
$functionName,
$formIdentifier
);
}
$attributes = $this->prepareAttributes($attributes);
$button = sprintf('<button%s><span>%s</span></button>', $this->buildAttributes($attributes), $text);
return $button . $javascript;
} | [
"public",
"function",
"displaySubmit",
"(",
"$",
"formIdentifier",
",",
"$",
"text",
"=",
"'submit'",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"javascript",
"=",
"''",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"'data-callback'",
"]",
")",
")",
"{",
"$",
"functionName",
"=",
"'onSubmit'",
".",
"str_replace",
"(",
"[",
"'-'",
",",
"'='",
",",
"'\\''",
",",
"'\"'",
",",
"'<'",
",",
"'>'",
",",
"'`'",
"]",
",",
"''",
",",
"$",
"formIdentifier",
")",
";",
"$",
"attributes",
"[",
"'data-callback'",
"]",
"=",
"$",
"functionName",
";",
"$",
"javascript",
"=",
"sprintf",
"(",
"'<script>function %s(){document.getElementById(\"%s\").submit();}</script>'",
",",
"$",
"functionName",
",",
"$",
"formIdentifier",
")",
";",
"}",
"$",
"attributes",
"=",
"$",
"this",
"->",
"prepareAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"button",
"=",
"sprintf",
"(",
"'<button%s><span>%s</span></button>'",
",",
"$",
"this",
"->",
"buildAttributes",
"(",
"$",
"attributes",
")",
",",
"$",
"text",
")",
";",
"return",
"$",
"button",
".",
"$",
"javascript",
";",
"}"
] | Display a Invisible reCAPTCHA by embedding a callback into a form submit button.
@param string $formIdentifier the html ID of the form that should be submitted.
@param string $text the text inside the form button
@param array $attributes array of additional html elements
@return string | [
"Display",
"a",
"Invisible",
"reCAPTCHA",
"by",
"embedding",
"a",
"callback",
"into",
"a",
"form",
"submit",
"button",
"."
] | fd08c84bd0e05f4a048a9bba800ab64ada9fadfc | https://github.com/anhskohbo/no-captcha/blob/fd08c84bd0e05f4a048a9bba800ab64ada9fadfc/src/NoCaptcha.php#L83-L101 | train |
anhskohbo/no-captcha | src/NoCaptcha.php | NoCaptcha.renderJs | public function renderJs($lang = null, $callback = false, $onLoadClass = 'onloadCallBack')
{
return '<script src="'.$this->getJsLink($lang, $callback, $onLoadClass).'" async defer></script>'."\n";
} | php | public function renderJs($lang = null, $callback = false, $onLoadClass = 'onloadCallBack')
{
return '<script src="'.$this->getJsLink($lang, $callback, $onLoadClass).'" async defer></script>'."\n";
} | [
"public",
"function",
"renderJs",
"(",
"$",
"lang",
"=",
"null",
",",
"$",
"callback",
"=",
"false",
",",
"$",
"onLoadClass",
"=",
"'onloadCallBack'",
")",
"{",
"return",
"'<script src=\"'",
".",
"$",
"this",
"->",
"getJsLink",
"(",
"$",
"lang",
",",
"$",
"callback",
",",
"$",
"onLoadClass",
")",
".",
"'\" async defer></script>'",
".",
"\"\\n\"",
";",
"}"
] | Render js source
@param null $lang
@param bool $callback
@param string $onLoadClass
@return string | [
"Render",
"js",
"source"
] | fd08c84bd0e05f4a048a9bba800ab64ada9fadfc | https://github.com/anhskohbo/no-captcha/blob/fd08c84bd0e05f4a048a9bba800ab64ada9fadfc/src/NoCaptcha.php#L111-L114 | train |
anhskohbo/no-captcha | src/NoCaptcha.php | NoCaptcha.verifyResponse | public function verifyResponse($response, $clientIp = null)
{
if (empty($response)) {
return false;
}
// Return true if response already verfied before.
if (in_array($response, $this->verifiedResponses)) {
return true;
}
$verifyResponse = $this->sendRequestVerify([
'secret' => $this->secret,
'response' => $response,
'remoteip' => $clientIp,
]);
if (isset($verifyResponse['success']) && $verifyResponse['success'] === true) {
// A response can only be verified once from google, so we need to
// cache it to make it work in case we want to verify it multiple times.
$this->verifiedResponses[] = $response;
return true;
} else {
return false;
}
} | php | public function verifyResponse($response, $clientIp = null)
{
if (empty($response)) {
return false;
}
// Return true if response already verfied before.
if (in_array($response, $this->verifiedResponses)) {
return true;
}
$verifyResponse = $this->sendRequestVerify([
'secret' => $this->secret,
'response' => $response,
'remoteip' => $clientIp,
]);
if (isset($verifyResponse['success']) && $verifyResponse['success'] === true) {
// A response can only be verified once from google, so we need to
// cache it to make it work in case we want to verify it multiple times.
$this->verifiedResponses[] = $response;
return true;
} else {
return false;
}
} | [
"public",
"function",
"verifyResponse",
"(",
"$",
"response",
",",
"$",
"clientIp",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Return true if response already verfied before.",
"if",
"(",
"in_array",
"(",
"$",
"response",
",",
"$",
"this",
"->",
"verifiedResponses",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"verifyResponse",
"=",
"$",
"this",
"->",
"sendRequestVerify",
"(",
"[",
"'secret'",
"=>",
"$",
"this",
"->",
"secret",
",",
"'response'",
"=>",
"$",
"response",
",",
"'remoteip'",
"=>",
"$",
"clientIp",
",",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"verifyResponse",
"[",
"'success'",
"]",
")",
"&&",
"$",
"verifyResponse",
"[",
"'success'",
"]",
"===",
"true",
")",
"{",
"// A response can only be verified once from google, so we need to",
"// cache it to make it work in case we want to verify it multiple times.",
"$",
"this",
"->",
"verifiedResponses",
"[",
"]",
"=",
"$",
"response",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Verify no-captcha response.
@param string $response
@param string $clientIp
@return bool | [
"Verify",
"no",
"-",
"captcha",
"response",
"."
] | fd08c84bd0e05f4a048a9bba800ab64ada9fadfc | https://github.com/anhskohbo/no-captcha/blob/fd08c84bd0e05f4a048a9bba800ab64ada9fadfc/src/NoCaptcha.php#L124-L149 | train |
anhskohbo/no-captcha | src/NoCaptcha.php | NoCaptcha.getJsLink | public function getJsLink($lang = null, $callback = false, $onLoadClass = 'onloadCallBack')
{
$client_api = static::CLIENT_API;
$params = [];
$callback ? $this->setCallBackParams($params, $onLoadClass) : false;
$lang ? $params['hl'] = $lang : null;
return $client_api . '?'. http_build_query($params);
} | php | public function getJsLink($lang = null, $callback = false, $onLoadClass = 'onloadCallBack')
{
$client_api = static::CLIENT_API;
$params = [];
$callback ? $this->setCallBackParams($params, $onLoadClass) : false;
$lang ? $params['hl'] = $lang : null;
return $client_api . '?'. http_build_query($params);
} | [
"public",
"function",
"getJsLink",
"(",
"$",
"lang",
"=",
"null",
",",
"$",
"callback",
"=",
"false",
",",
"$",
"onLoadClass",
"=",
"'onloadCallBack'",
")",
"{",
"$",
"client_api",
"=",
"static",
"::",
"CLIENT_API",
";",
"$",
"params",
"=",
"[",
"]",
";",
"$",
"callback",
"?",
"$",
"this",
"->",
"setCallBackParams",
"(",
"$",
"params",
",",
"$",
"onLoadClass",
")",
":",
"false",
";",
"$",
"lang",
"?",
"$",
"params",
"[",
"'hl'",
"]",
"=",
"$",
"lang",
":",
"null",
";",
"return",
"$",
"client_api",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"params",
")",
";",
"}"
] | Get recaptcha js link.
@param string $lang
@param boolean $callback
@param string $onLoadClass
@return string | [
"Get",
"recaptcha",
"js",
"link",
"."
] | fd08c84bd0e05f4a048a9bba800ab64ada9fadfc | https://github.com/anhskohbo/no-captcha/blob/fd08c84bd0e05f4a048a9bba800ab64ada9fadfc/src/NoCaptcha.php#L174-L183 | train |
anhskohbo/no-captcha | src/NoCaptcha.php | NoCaptcha.prepareAttributes | protected function prepareAttributes(array $attributes)
{
$attributes['data-sitekey'] = $this->sitekey;
if (!isset($attributes['class'])) {
$attributes['class'] = '';
}
$attributes['class'] = trim('g-recaptcha ' . $attributes['class']);
return $attributes;
} | php | protected function prepareAttributes(array $attributes)
{
$attributes['data-sitekey'] = $this->sitekey;
if (!isset($attributes['class'])) {
$attributes['class'] = '';
}
$attributes['class'] = trim('g-recaptcha ' . $attributes['class']);
return $attributes;
} | [
"protected",
"function",
"prepareAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"attributes",
"[",
"'data-sitekey'",
"]",
"=",
"$",
"this",
"->",
"sitekey",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"attributes",
"[",
"'class'",
"]",
"=",
"''",
";",
"}",
"$",
"attributes",
"[",
"'class'",
"]",
"=",
"trim",
"(",
"'g-recaptcha '",
".",
"$",
"attributes",
"[",
"'class'",
"]",
")",
";",
"return",
"$",
"attributes",
";",
"}"
] | Prepare HTML attributes and assure that the correct classes and attributes for captcha are inserted.
@param array $attributes
@return array | [
"Prepare",
"HTML",
"attributes",
"and",
"assure",
"that",
"the",
"correct",
"classes",
"and",
"attributes",
"for",
"captcha",
"are",
"inserted",
"."
] | fd08c84bd0e05f4a048a9bba800ab64ada9fadfc | https://github.com/anhskohbo/no-captcha/blob/fd08c84bd0e05f4a048a9bba800ab64ada9fadfc/src/NoCaptcha.php#L218-L227 | train |
anhskohbo/no-captcha | src/NoCaptcha.php | NoCaptcha.buildAttributes | protected function buildAttributes(array $attributes)
{
$html = [];
foreach ($attributes as $key => $value) {
$html[] = $key.'="'.$value.'"';
}
return count($html) ? ' '.implode(' ', $html) : '';
} | php | protected function buildAttributes(array $attributes)
{
$html = [];
foreach ($attributes as $key => $value) {
$html[] = $key.'="'.$value.'"';
}
return count($html) ? ' '.implode(' ', $html) : '';
} | [
"protected",
"function",
"buildAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"html",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"$",
"key",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"}",
"return",
"count",
"(",
"$",
"html",
")",
"?",
"' '",
".",
"implode",
"(",
"' '",
",",
"$",
"html",
")",
":",
"''",
";",
"}"
] | Build HTML attributes.
@param array $attributes
@return string | [
"Build",
"HTML",
"attributes",
"."
] | fd08c84bd0e05f4a048a9bba800ab64ada9fadfc | https://github.com/anhskohbo/no-captcha/blob/fd08c84bd0e05f4a048a9bba800ab64ada9fadfc/src/NoCaptcha.php#L236-L245 | train |
top-think/think-queue | src/queue/Job.php | Job.resolve | protected function resolve($name)
{
if (strpos($name, '\\') === false) {
if (strpos($name, '/') === false) {
$app = '';
} else {
list($app, $name) = explode('/', $name, 2);
}
$name = ($this->app->config->get('app.app_namespace') ?: 'app\\') . ($app ? strtolower($app) . '\\' : '') . 'job\\' . $name;
}
return $this->app->make($name);
} | php | protected function resolve($name)
{
if (strpos($name, '\\') === false) {
if (strpos($name, '/') === false) {
$app = '';
} else {
list($app, $name) = explode('/', $name, 2);
}
$name = ($this->app->config->get('app.app_namespace') ?: 'app\\') . ($app ? strtolower($app) . '\\' : '') . 'job\\' . $name;
}
return $this->app->make($name);
} | [
"protected",
"function",
"resolve",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'\\\\'",
")",
"===",
"false",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'/'",
")",
"===",
"false",
")",
"{",
"$",
"app",
"=",
"''",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"app",
",",
"$",
"name",
")",
"=",
"explode",
"(",
"'/'",
",",
"$",
"name",
",",
"2",
")",
";",
"}",
"$",
"name",
"=",
"(",
"$",
"this",
"->",
"app",
"->",
"config",
"->",
"get",
"(",
"'app.app_namespace'",
")",
"?",
":",
"'app\\\\'",
")",
".",
"(",
"$",
"app",
"?",
"strtolower",
"(",
"$",
"app",
")",
".",
"'\\\\'",
":",
"''",
")",
".",
"'job\\\\'",
".",
"$",
"name",
";",
"}",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"$",
"name",
")",
";",
"}"
] | Resolve the given job handler.
@param string $name
@return mixed | [
"Resolve",
"the",
"given",
"job",
"handler",
"."
] | 7e07fd55af7e3daf6adb8d78c134cefb42e48a63 | https://github.com/top-think/think-queue/blob/7e07fd55af7e3daf6adb8d78c134cefb42e48a63/src/queue/Job.php#L169-L183 | train |
top-think/think-queue | src/queue/Worker.php | Worker.registerTimeoutHandler | protected function registerTimeoutHandler($job, $timeout)
{
pcntl_signal(SIGALRM, function () {
$this->kill(1);
});
pcntl_alarm(
max($this->timeoutForJob($job, $timeout), 0)
);
} | php | protected function registerTimeoutHandler($job, $timeout)
{
pcntl_signal(SIGALRM, function () {
$this->kill(1);
});
pcntl_alarm(
max($this->timeoutForJob($job, $timeout), 0)
);
} | [
"protected",
"function",
"registerTimeoutHandler",
"(",
"$",
"job",
",",
"$",
"timeout",
")",
"{",
"pcntl_signal",
"(",
"SIGALRM",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"kill",
"(",
"1",
")",
";",
"}",
")",
";",
"pcntl_alarm",
"(",
"max",
"(",
"$",
"this",
"->",
"timeoutForJob",
"(",
"$",
"job",
",",
"$",
"timeout",
")",
",",
"0",
")",
")",
";",
"}"
] | Register the worker timeout handler.
@param Job|null $job
@param int $timeout
@return void | [
"Register",
"the",
"worker",
"timeout",
"handler",
"."
] | 7e07fd55af7e3daf6adb8d78c134cefb42e48a63 | https://github.com/top-think/think-queue/blob/7e07fd55af7e3daf6adb8d78c134cefb42e48a63/src/queue/Worker.php#L142-L151 | train |
top-think/think-queue | src/queue/command/ListFailed.php | ListFailed.displayFailedJobs | protected function displayFailedJobs(array $jobs)
{
$table = new Table();
$table->setHeader($this->headers);
$table->setRows($jobs);
$this->table($table);
} | php | protected function displayFailedJobs(array $jobs)
{
$table = new Table();
$table->setHeader($this->headers);
$table->setRows($jobs);
$this->table($table);
} | [
"protected",
"function",
"displayFailedJobs",
"(",
"array",
"$",
"jobs",
")",
"{",
"$",
"table",
"=",
"new",
"Table",
"(",
")",
";",
"$",
"table",
"->",
"setHeader",
"(",
"$",
"this",
"->",
"headers",
")",
";",
"$",
"table",
"->",
"setRows",
"(",
"$",
"jobs",
")",
";",
"$",
"this",
"->",
"table",
"(",
"$",
"table",
")",
";",
"}"
] | Display the failed jobs in the console.
@param array $jobs
@return void | [
"Display",
"the",
"failed",
"jobs",
"in",
"the",
"console",
"."
] | 7e07fd55af7e3daf6adb8d78c134cefb42e48a63 | https://github.com/top-think/think-queue/blob/7e07fd55af7e3daf6adb8d78c134cefb42e48a63/src/queue/command/ListFailed.php#L39-L46 | train |
top-think/think-queue | src/queue/command/ListFailed.php | ListFailed.matchJobName | protected function matchJobName($payload)
{
preg_match('/"([^"]+)"/', $payload['data']['command'], $matches);
if (isset($matches[1])) {
return $matches[1];
}
return $payload['job'] ?? null;
} | php | protected function matchJobName($payload)
{
preg_match('/"([^"]+)"/', $payload['data']['command'], $matches);
if (isset($matches[1])) {
return $matches[1];
}
return $payload['job'] ?? null;
} | [
"protected",
"function",
"matchJobName",
"(",
"$",
"payload",
")",
"{",
"preg_match",
"(",
"'/\"([^\"]+)\"/'",
",",
"$",
"payload",
"[",
"'data'",
"]",
"[",
"'command'",
"]",
",",
"$",
"matches",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"payload",
"[",
"'job'",
"]",
"??",
"null",
";",
"}"
] | Match the job name from the payload.
@param array $payload
@return string | [
"Match",
"the",
"job",
"name",
"from",
"the",
"payload",
"."
] | 7e07fd55af7e3daf6adb8d78c134cefb42e48a63 | https://github.com/top-think/think-queue/blob/7e07fd55af7e3daf6adb8d78c134cefb42e48a63/src/queue/command/ListFailed.php#L100-L109 | train |
kint-php/kint | src/Utils.php | Utils.getHumanReadableBytes | public static function getHumanReadableBytes($value)
{
static $unit = array('B', 'KB', 'MB', 'GB', 'TB');
$i = \floor(\log($value, 1024));
$i = \min($i, 4); // Only go up to TB
return array(
'value' => (float) ($value / \pow(1024, $i)),
'unit' => $unit[$i],
);
} | php | public static function getHumanReadableBytes($value)
{
static $unit = array('B', 'KB', 'MB', 'GB', 'TB');
$i = \floor(\log($value, 1024));
$i = \min($i, 4); // Only go up to TB
return array(
'value' => (float) ($value / \pow(1024, $i)),
'unit' => $unit[$i],
);
} | [
"public",
"static",
"function",
"getHumanReadableBytes",
"(",
"$",
"value",
")",
"{",
"static",
"$",
"unit",
"=",
"array",
"(",
"'B'",
",",
"'KB'",
",",
"'MB'",
",",
"'GB'",
",",
"'TB'",
")",
";",
"$",
"i",
"=",
"\\",
"floor",
"(",
"\\",
"log",
"(",
"$",
"value",
",",
"1024",
")",
")",
";",
"$",
"i",
"=",
"\\",
"min",
"(",
"$",
"i",
",",
"4",
")",
";",
"// Only go up to TB",
"return",
"array",
"(",
"'value'",
"=>",
"(",
"float",
")",
"(",
"$",
"value",
"/",
"\\",
"pow",
"(",
"1024",
",",
"$",
"i",
")",
")",
",",
"'unit'",
"=>",
"$",
"unit",
"[",
"$",
"i",
"]",
",",
")",
";",
"}"
] | Turns a byte value into a human-readable representation.
@param int $value Amount of bytes
@return array Human readable value and unit | [
"Turns",
"a",
"byte",
"value",
"into",
"a",
"human",
"-",
"readable",
"representation",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Utils.php#L50-L61 | train |
kint-php/kint | src/Kint.php | Kint.dumpAll | public function dumpAll(array $vars, array $base)
{
if (\array_keys($vars) !== \array_keys($base)) {
throw new InvalidArgumentException('Kint::dumpAll requires arrays of identical size and keys as arguments');
}
$output = $this->renderer->preRender();
if ($vars === array()) {
$output .= $this->renderer->renderNothing();
}
foreach ($vars as $key => $arg) {
if (!$base[$key] instanceof BasicObject) {
throw new InvalidArgumentException('Kint::dumpAll requires all elements of the second argument to be BasicObject instances');
}
$output .= $this->dumpVar($arg, $base[$key]);
}
$output .= $this->renderer->postRender();
return $output;
} | php | public function dumpAll(array $vars, array $base)
{
if (\array_keys($vars) !== \array_keys($base)) {
throw new InvalidArgumentException('Kint::dumpAll requires arrays of identical size and keys as arguments');
}
$output = $this->renderer->preRender();
if ($vars === array()) {
$output .= $this->renderer->renderNothing();
}
foreach ($vars as $key => $arg) {
if (!$base[$key] instanceof BasicObject) {
throw new InvalidArgumentException('Kint::dumpAll requires all elements of the second argument to be BasicObject instances');
}
$output .= $this->dumpVar($arg, $base[$key]);
}
$output .= $this->renderer->postRender();
return $output;
} | [
"public",
"function",
"dumpAll",
"(",
"array",
"$",
"vars",
",",
"array",
"$",
"base",
")",
"{",
"if",
"(",
"\\",
"array_keys",
"(",
"$",
"vars",
")",
"!==",
"\\",
"array_keys",
"(",
"$",
"base",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Kint::dumpAll requires arrays of identical size and keys as arguments'",
")",
";",
"}",
"$",
"output",
"=",
"$",
"this",
"->",
"renderer",
"->",
"preRender",
"(",
")",
";",
"if",
"(",
"$",
"vars",
"===",
"array",
"(",
")",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"renderer",
"->",
"renderNothing",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"$",
"base",
"[",
"$",
"key",
"]",
"instanceof",
"BasicObject",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Kint::dumpAll requires all elements of the second argument to be BasicObject instances'",
")",
";",
"}",
"$",
"output",
".=",
"$",
"this",
"->",
"dumpVar",
"(",
"$",
"arg",
",",
"$",
"base",
"[",
"$",
"key",
"]",
")",
";",
"}",
"$",
"output",
".=",
"$",
"this",
"->",
"renderer",
"->",
"postRender",
"(",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Renders a list of vars including the pre and post renders.
@param array $vars Data to dump
@param BasicObject[] $base Base objects
@return string | [
"Renders",
"a",
"list",
"of",
"vars",
"including",
"the",
"pre",
"and",
"post",
"renders",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L249-L271 | train |
kint-php/kint | src/Kint.php | Kint.dumpVar | public function dumpVar(&$var, BasicObject $base)
{
return $this->renderer->render(
$this->parser->parse($var, $base)
);
} | php | public function dumpVar(&$var, BasicObject $base)
{
return $this->renderer->render(
$this->parser->parse($var, $base)
);
} | [
"public",
"function",
"dumpVar",
"(",
"&",
"$",
"var",
",",
"BasicObject",
"$",
"base",
")",
"{",
"return",
"$",
"this",
"->",
"renderer",
"->",
"render",
"(",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"$",
"var",
",",
"$",
"base",
")",
")",
";",
"}"
] | Dumps and renders a var.
@param mixed $var Data to dump
@param BasicObject $base Base object
@return string | [
"Dumps",
"and",
"renders",
"a",
"var",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L281-L286 | train |
kint-php/kint | src/Kint.php | Kint.getStatics | public static function getStatics()
{
return array(
'aliases' => self::$aliases,
'app_root_dirs' => self::$app_root_dirs,
'cli_detection' => self::$cli_detection,
'display_called_from' => self::$display_called_from,
'enabled_mode' => self::$enabled_mode,
'expanded' => self::$expanded,
'file_link_format' => self::$file_link_format,
'max_depth' => self::$max_depth,
'mode_default' => self::$mode_default,
'mode_default_cli' => self::$mode_default_cli,
'plugins' => self::$plugins,
'renderers' => self::$renderers,
'return' => self::$return,
);
} | php | public static function getStatics()
{
return array(
'aliases' => self::$aliases,
'app_root_dirs' => self::$app_root_dirs,
'cli_detection' => self::$cli_detection,
'display_called_from' => self::$display_called_from,
'enabled_mode' => self::$enabled_mode,
'expanded' => self::$expanded,
'file_link_format' => self::$file_link_format,
'max_depth' => self::$max_depth,
'mode_default' => self::$mode_default,
'mode_default_cli' => self::$mode_default_cli,
'plugins' => self::$plugins,
'renderers' => self::$renderers,
'return' => self::$return,
);
} | [
"public",
"static",
"function",
"getStatics",
"(",
")",
"{",
"return",
"array",
"(",
"'aliases'",
"=>",
"self",
"::",
"$",
"aliases",
",",
"'app_root_dirs'",
"=>",
"self",
"::",
"$",
"app_root_dirs",
",",
"'cli_detection'",
"=>",
"self",
"::",
"$",
"cli_detection",
",",
"'display_called_from'",
"=>",
"self",
"::",
"$",
"display_called_from",
",",
"'enabled_mode'",
"=>",
"self",
"::",
"$",
"enabled_mode",
",",
"'expanded'",
"=>",
"self",
"::",
"$",
"expanded",
",",
"'file_link_format'",
"=>",
"self",
"::",
"$",
"file_link_format",
",",
"'max_depth'",
"=>",
"self",
"::",
"$",
"max_depth",
",",
"'mode_default'",
"=>",
"self",
"::",
"$",
"mode_default",
",",
"'mode_default_cli'",
"=>",
"self",
"::",
"$",
"mode_default_cli",
",",
"'plugins'",
"=>",
"self",
"::",
"$",
"plugins",
",",
"'renderers'",
"=>",
"self",
"::",
"$",
"renderers",
",",
"'return'",
"=>",
"self",
"::",
"$",
"return",
",",
")",
";",
"}"
] | Gets all static settings at once.
@return array Current static settings | [
"Gets",
"all",
"static",
"settings",
"at",
"once",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L293-L310 | train |
kint-php/kint | src/Kint.php | Kint.createFromStatics | public static function createFromStatics(array $statics)
{
$mode = false;
if (isset($statics['enabled_mode'])) {
$mode = $statics['enabled_mode'];
if (true === $statics['enabled_mode'] && isset($statics['mode_default'])) {
$mode = $statics['mode_default'];
if (PHP_SAPI === 'cli' && !empty($statics['cli_detection']) && isset($statics['mode_default_cli'])) {
$mode = $statics['mode_default_cli'];
}
}
}
if (!$mode) {
return null;
}
if (!isset($statics['renderers'][$mode])) {
$renderer = new TextRenderer();
} else {
/** @var Renderer */
$renderer = new $statics['renderers'][$mode]();
}
return new self(new Parser(), $renderer);
} | php | public static function createFromStatics(array $statics)
{
$mode = false;
if (isset($statics['enabled_mode'])) {
$mode = $statics['enabled_mode'];
if (true === $statics['enabled_mode'] && isset($statics['mode_default'])) {
$mode = $statics['mode_default'];
if (PHP_SAPI === 'cli' && !empty($statics['cli_detection']) && isset($statics['mode_default_cli'])) {
$mode = $statics['mode_default_cli'];
}
}
}
if (!$mode) {
return null;
}
if (!isset($statics['renderers'][$mode])) {
$renderer = new TextRenderer();
} else {
/** @var Renderer */
$renderer = new $statics['renderers'][$mode]();
}
return new self(new Parser(), $renderer);
} | [
"public",
"static",
"function",
"createFromStatics",
"(",
"array",
"$",
"statics",
")",
"{",
"$",
"mode",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"statics",
"[",
"'enabled_mode'",
"]",
")",
")",
"{",
"$",
"mode",
"=",
"$",
"statics",
"[",
"'enabled_mode'",
"]",
";",
"if",
"(",
"true",
"===",
"$",
"statics",
"[",
"'enabled_mode'",
"]",
"&&",
"isset",
"(",
"$",
"statics",
"[",
"'mode_default'",
"]",
")",
")",
"{",
"$",
"mode",
"=",
"$",
"statics",
"[",
"'mode_default'",
"]",
";",
"if",
"(",
"PHP_SAPI",
"===",
"'cli'",
"&&",
"!",
"empty",
"(",
"$",
"statics",
"[",
"'cli_detection'",
"]",
")",
"&&",
"isset",
"(",
"$",
"statics",
"[",
"'mode_default_cli'",
"]",
")",
")",
"{",
"$",
"mode",
"=",
"$",
"statics",
"[",
"'mode_default_cli'",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"mode",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"statics",
"[",
"'renderers'",
"]",
"[",
"$",
"mode",
"]",
")",
")",
"{",
"$",
"renderer",
"=",
"new",
"TextRenderer",
"(",
")",
";",
"}",
"else",
"{",
"/** @var Renderer */",
"$",
"renderer",
"=",
"new",
"$",
"statics",
"[",
"'renderers'",
"]",
"[",
"$",
"mode",
"]",
"(",
")",
";",
"}",
"return",
"new",
"self",
"(",
"new",
"Parser",
"(",
")",
",",
"$",
"renderer",
")",
";",
"}"
] | Creates a Kint instances based on static settings.
Also calls setStatesFromStatics for you
@param array $statics array of statics as returned by getStatics
@return null|\Kint\Kint | [
"Creates",
"a",
"Kint",
"instances",
"based",
"on",
"static",
"settings",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L321-L349 | train |
kint-php/kint | src/Kint.php | Kint.getBasesFromParamInfo | public static function getBasesFromParamInfo(array $params, $argc)
{
static $blacklist = array(
'null',
'true',
'false',
'array(...)',
'array()',
'[...]',
'[]',
'(...)',
'()',
'"..."',
'b"..."',
"'...'",
"b'...'",
);
$params = \array_values($params);
$bases = array();
for ($i = 0; $i < $argc; ++$i) {
if (isset($params[$i])) {
$param = $params[$i];
} else {
$param = null;
}
if (!isset($param['name']) || \is_numeric($param['name'])) {
$name = null;
} elseif (\in_array(\strtolower($param['name']), $blacklist, true)) {
$name = null;
} else {
$name = $param['name'];
}
if (isset($param['path'])) {
$access_path = $param['path'];
if (!empty($param['expression'])) {
$access_path = '('.$access_path.')';
}
} else {
$access_path = '$'.$i;
}
$bases[] = BasicObject::blank($name, $access_path);
}
return $bases;
} | php | public static function getBasesFromParamInfo(array $params, $argc)
{
static $blacklist = array(
'null',
'true',
'false',
'array(...)',
'array()',
'[...]',
'[]',
'(...)',
'()',
'"..."',
'b"..."',
"'...'",
"b'...'",
);
$params = \array_values($params);
$bases = array();
for ($i = 0; $i < $argc; ++$i) {
if (isset($params[$i])) {
$param = $params[$i];
} else {
$param = null;
}
if (!isset($param['name']) || \is_numeric($param['name'])) {
$name = null;
} elseif (\in_array(\strtolower($param['name']), $blacklist, true)) {
$name = null;
} else {
$name = $param['name'];
}
if (isset($param['path'])) {
$access_path = $param['path'];
if (!empty($param['expression'])) {
$access_path = '('.$access_path.')';
}
} else {
$access_path = '$'.$i;
}
$bases[] = BasicObject::blank($name, $access_path);
}
return $bases;
} | [
"public",
"static",
"function",
"getBasesFromParamInfo",
"(",
"array",
"$",
"params",
",",
"$",
"argc",
")",
"{",
"static",
"$",
"blacklist",
"=",
"array",
"(",
"'null'",
",",
"'true'",
",",
"'false'",
",",
"'array(...)'",
",",
"'array()'",
",",
"'[...]'",
",",
"'[]'",
",",
"'(...)'",
",",
"'()'",
",",
"'\"...\"'",
",",
"'b\"...\"'",
",",
"\"'...'\"",
",",
"\"b'...'\"",
",",
")",
";",
"$",
"params",
"=",
"\\",
"array_values",
"(",
"$",
"params",
")",
";",
"$",
"bases",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"argc",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"param",
"=",
"$",
"params",
"[",
"$",
"i",
"]",
";",
"}",
"else",
"{",
"$",
"param",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"param",
"[",
"'name'",
"]",
")",
"||",
"\\",
"is_numeric",
"(",
"$",
"param",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"null",
";",
"}",
"elseif",
"(",
"\\",
"in_array",
"(",
"\\",
"strtolower",
"(",
"$",
"param",
"[",
"'name'",
"]",
")",
",",
"$",
"blacklist",
",",
"true",
")",
")",
"{",
"$",
"name",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"param",
"[",
"'name'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"param",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"access_path",
"=",
"$",
"param",
"[",
"'path'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"param",
"[",
"'expression'",
"]",
")",
")",
"{",
"$",
"access_path",
"=",
"'('",
".",
"$",
"access_path",
".",
"')'",
";",
"}",
"}",
"else",
"{",
"$",
"access_path",
"=",
"'$'",
".",
"$",
"i",
";",
"}",
"$",
"bases",
"[",
"]",
"=",
"BasicObject",
"::",
"blank",
"(",
"$",
"name",
",",
"$",
"access_path",
")",
";",
"}",
"return",
"$",
"bases",
";",
"}"
] | Creates base objects given parameter info.
@param array $params Parameters as returned from getCallInfo
@param int $argc Number of arguments the helper was called with
@return BasicObject[] Base objects for the arguments | [
"Creates",
"base",
"objects",
"given",
"parameter",
"info",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L359-L409 | train |
kint-php/kint | src/Kint.php | Kint.getCallInfo | public static function getCallInfo(array $aliases, array $trace, $argc)
{
$found = false;
$callee = null;
$caller = null;
$miniTrace = array();
foreach ($trace as $index => $frame) {
if (Utils::traceFrameIsListed($frame, $aliases)) {
$found = true;
$miniTrace = array();
}
if (!Utils::traceFrameIsListed($frame, array('spl_autoload_call'))) {
$miniTrace[] = $frame;
}
}
if ($found) {
$callee = \reset($miniTrace) ?: null;
/** @var null|array Psalm bug workaround */
$caller = \next($miniTrace) ?: null;
}
foreach ($miniTrace as $index => $frame) {
if ((0 === $index && $callee === $frame) || isset($frame['file'], $frame['line'])) {
unset($frame['object'], $frame['args']);
$miniTrace[$index] = $frame;
} else {
unset($miniTrace[$index]);
}
}
$miniTrace = \array_values($miniTrace);
$call = self::getSingleCall($callee ?: array(), $argc);
$ret = array(
'params' => null,
'modifiers' => array(),
'callee' => $callee,
'caller' => $caller,
'trace' => $miniTrace,
);
if ($call) {
$ret['params'] = $call['parameters'];
$ret['modifiers'] = $call['modifiers'];
}
return $ret;
} | php | public static function getCallInfo(array $aliases, array $trace, $argc)
{
$found = false;
$callee = null;
$caller = null;
$miniTrace = array();
foreach ($trace as $index => $frame) {
if (Utils::traceFrameIsListed($frame, $aliases)) {
$found = true;
$miniTrace = array();
}
if (!Utils::traceFrameIsListed($frame, array('spl_autoload_call'))) {
$miniTrace[] = $frame;
}
}
if ($found) {
$callee = \reset($miniTrace) ?: null;
/** @var null|array Psalm bug workaround */
$caller = \next($miniTrace) ?: null;
}
foreach ($miniTrace as $index => $frame) {
if ((0 === $index && $callee === $frame) || isset($frame['file'], $frame['line'])) {
unset($frame['object'], $frame['args']);
$miniTrace[$index] = $frame;
} else {
unset($miniTrace[$index]);
}
}
$miniTrace = \array_values($miniTrace);
$call = self::getSingleCall($callee ?: array(), $argc);
$ret = array(
'params' => null,
'modifiers' => array(),
'callee' => $callee,
'caller' => $caller,
'trace' => $miniTrace,
);
if ($call) {
$ret['params'] = $call['parameters'];
$ret['modifiers'] = $call['modifiers'];
}
return $ret;
} | [
"public",
"static",
"function",
"getCallInfo",
"(",
"array",
"$",
"aliases",
",",
"array",
"$",
"trace",
",",
"$",
"argc",
")",
"{",
"$",
"found",
"=",
"false",
";",
"$",
"callee",
"=",
"null",
";",
"$",
"caller",
"=",
"null",
";",
"$",
"miniTrace",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"trace",
"as",
"$",
"index",
"=>",
"$",
"frame",
")",
"{",
"if",
"(",
"Utils",
"::",
"traceFrameIsListed",
"(",
"$",
"frame",
",",
"$",
"aliases",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"$",
"miniTrace",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"Utils",
"::",
"traceFrameIsListed",
"(",
"$",
"frame",
",",
"array",
"(",
"'spl_autoload_call'",
")",
")",
")",
"{",
"$",
"miniTrace",
"[",
"]",
"=",
"$",
"frame",
";",
"}",
"}",
"if",
"(",
"$",
"found",
")",
"{",
"$",
"callee",
"=",
"\\",
"reset",
"(",
"$",
"miniTrace",
")",
"?",
":",
"null",
";",
"/** @var null|array Psalm bug workaround */",
"$",
"caller",
"=",
"\\",
"next",
"(",
"$",
"miniTrace",
")",
"?",
":",
"null",
";",
"}",
"foreach",
"(",
"$",
"miniTrace",
"as",
"$",
"index",
"=>",
"$",
"frame",
")",
"{",
"if",
"(",
"(",
"0",
"===",
"$",
"index",
"&&",
"$",
"callee",
"===",
"$",
"frame",
")",
"||",
"isset",
"(",
"$",
"frame",
"[",
"'file'",
"]",
",",
"$",
"frame",
"[",
"'line'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"frame",
"[",
"'object'",
"]",
",",
"$",
"frame",
"[",
"'args'",
"]",
")",
";",
"$",
"miniTrace",
"[",
"$",
"index",
"]",
"=",
"$",
"frame",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"miniTrace",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"$",
"miniTrace",
"=",
"\\",
"array_values",
"(",
"$",
"miniTrace",
")",
";",
"$",
"call",
"=",
"self",
"::",
"getSingleCall",
"(",
"$",
"callee",
"?",
":",
"array",
"(",
")",
",",
"$",
"argc",
")",
";",
"$",
"ret",
"=",
"array",
"(",
"'params'",
"=>",
"null",
",",
"'modifiers'",
"=>",
"array",
"(",
")",
",",
"'callee'",
"=>",
"$",
"callee",
",",
"'caller'",
"=>",
"$",
"caller",
",",
"'trace'",
"=>",
"$",
"miniTrace",
",",
")",
";",
"if",
"(",
"$",
"call",
")",
"{",
"$",
"ret",
"[",
"'params'",
"]",
"=",
"$",
"call",
"[",
"'parameters'",
"]",
";",
"$",
"ret",
"[",
"'modifiers'",
"]",
"=",
"$",
"call",
"[",
"'modifiers'",
"]",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Gets call info from the backtrace, alias, and argument count.
Aliases must be normalized beforehand (Utils::normalizeAliases)
@param array $aliases Call aliases as found in Kint::$aliases
@param array[] $trace Backtrace
@param int $argc Number of arguments
@return array{params:null|array, modifiers:array, callee:null|array, caller:null|array, trace:array[]} Call info | [
"Gets",
"call",
"info",
"from",
"the",
"backtrace",
"alias",
"and",
"argument",
"count",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L422-L474 | train |
kint-php/kint | src/Kint.php | Kint.trace | public static function trace()
{
if (!self::$enabled_mode) {
return 0;
}
Utils::normalizeAliases(self::$aliases);
$args = \func_get_args();
$call_info = self::getCallInfo(self::$aliases, \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), \count($args));
$statics = self::getStatics();
if (\in_array('~', $call_info['modifiers'], true)) {
$statics['enabled_mode'] = self::MODE_TEXT;
}
$kintstance = self::createFromStatics($statics);
if (!$kintstance) {
// Should never happen
return 0; // @codeCoverageIgnore
}
if (\in_array('-', $call_info['modifiers'], true)) {
while (\ob_get_level()) {
\ob_end_clean();
}
}
$kintstance->setStatesFromStatics($statics);
$kintstance->setStatesFromCallInfo($call_info);
$trimmed_trace = array();
$trace = \debug_backtrace(true);
foreach ($trace as $frame) {
if (Utils::traceFrameIsListed($frame, self::$aliases)) {
$trimmed_trace = array();
}
$trimmed_trace[] = $frame;
}
$output = $kintstance->dumpAll(
array($trimmed_trace),
array(BasicObject::blank('Kint\\Kint::trace()', 'debug_backtrace(true)'))
);
if (self::$return || \in_array('@', $call_info['modifiers'], true)) {
return $output;
}
echo $output;
if (\in_array('-', $call_info['modifiers'], true)) {
\flush(); // @codeCoverageIgnore
}
return 0;
} | php | public static function trace()
{
if (!self::$enabled_mode) {
return 0;
}
Utils::normalizeAliases(self::$aliases);
$args = \func_get_args();
$call_info = self::getCallInfo(self::$aliases, \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), \count($args));
$statics = self::getStatics();
if (\in_array('~', $call_info['modifiers'], true)) {
$statics['enabled_mode'] = self::MODE_TEXT;
}
$kintstance = self::createFromStatics($statics);
if (!$kintstance) {
// Should never happen
return 0; // @codeCoverageIgnore
}
if (\in_array('-', $call_info['modifiers'], true)) {
while (\ob_get_level()) {
\ob_end_clean();
}
}
$kintstance->setStatesFromStatics($statics);
$kintstance->setStatesFromCallInfo($call_info);
$trimmed_trace = array();
$trace = \debug_backtrace(true);
foreach ($trace as $frame) {
if (Utils::traceFrameIsListed($frame, self::$aliases)) {
$trimmed_trace = array();
}
$trimmed_trace[] = $frame;
}
$output = $kintstance->dumpAll(
array($trimmed_trace),
array(BasicObject::blank('Kint\\Kint::trace()', 'debug_backtrace(true)'))
);
if (self::$return || \in_array('@', $call_info['modifiers'], true)) {
return $output;
}
echo $output;
if (\in_array('-', $call_info['modifiers'], true)) {
\flush(); // @codeCoverageIgnore
}
return 0;
} | [
"public",
"static",
"function",
"trace",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"enabled_mode",
")",
"{",
"return",
"0",
";",
"}",
"Utils",
"::",
"normalizeAliases",
"(",
"self",
"::",
"$",
"aliases",
")",
";",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"$",
"call_info",
"=",
"self",
"::",
"getCallInfo",
"(",
"self",
"::",
"$",
"aliases",
",",
"\\",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
")",
",",
"\\",
"count",
"(",
"$",
"args",
")",
")",
";",
"$",
"statics",
"=",
"self",
"::",
"getStatics",
"(",
")",
";",
"if",
"(",
"\\",
"in_array",
"(",
"'~'",
",",
"$",
"call_info",
"[",
"'modifiers'",
"]",
",",
"true",
")",
")",
"{",
"$",
"statics",
"[",
"'enabled_mode'",
"]",
"=",
"self",
"::",
"MODE_TEXT",
";",
"}",
"$",
"kintstance",
"=",
"self",
"::",
"createFromStatics",
"(",
"$",
"statics",
")",
";",
"if",
"(",
"!",
"$",
"kintstance",
")",
"{",
"// Should never happen",
"return",
"0",
";",
"// @codeCoverageIgnore",
"}",
"if",
"(",
"\\",
"in_array",
"(",
"'-'",
",",
"$",
"call_info",
"[",
"'modifiers'",
"]",
",",
"true",
")",
")",
"{",
"while",
"(",
"\\",
"ob_get_level",
"(",
")",
")",
"{",
"\\",
"ob_end_clean",
"(",
")",
";",
"}",
"}",
"$",
"kintstance",
"->",
"setStatesFromStatics",
"(",
"$",
"statics",
")",
";",
"$",
"kintstance",
"->",
"setStatesFromCallInfo",
"(",
"$",
"call_info",
")",
";",
"$",
"trimmed_trace",
"=",
"array",
"(",
")",
";",
"$",
"trace",
"=",
"\\",
"debug_backtrace",
"(",
"true",
")",
";",
"foreach",
"(",
"$",
"trace",
"as",
"$",
"frame",
")",
"{",
"if",
"(",
"Utils",
"::",
"traceFrameIsListed",
"(",
"$",
"frame",
",",
"self",
"::",
"$",
"aliases",
")",
")",
"{",
"$",
"trimmed_trace",
"=",
"array",
"(",
")",
";",
"}",
"$",
"trimmed_trace",
"[",
"]",
"=",
"$",
"frame",
";",
"}",
"$",
"output",
"=",
"$",
"kintstance",
"->",
"dumpAll",
"(",
"array",
"(",
"$",
"trimmed_trace",
")",
",",
"array",
"(",
"BasicObject",
"::",
"blank",
"(",
"'Kint\\\\Kint::trace()'",
",",
"'debug_backtrace(true)'",
")",
")",
")",
";",
"if",
"(",
"self",
"::",
"$",
"return",
"||",
"\\",
"in_array",
"(",
"'@'",
",",
"$",
"call_info",
"[",
"'modifiers'",
"]",
",",
"true",
")",
")",
"{",
"return",
"$",
"output",
";",
"}",
"echo",
"$",
"output",
";",
"if",
"(",
"\\",
"in_array",
"(",
"'-'",
",",
"$",
"call_info",
"[",
"'modifiers'",
"]",
",",
"true",
")",
")",
"{",
"\\",
"flush",
"(",
")",
";",
"// @codeCoverageIgnore",
"}",
"return",
"0",
";",
"}"
] | Dumps a backtrace.
Functionally equivalent to Kint::dump(1) or Kint::dump(debug_backtrace(true))
@return int|string | [
"Dumps",
"a",
"backtrace",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L483-L543 | train |
kint-php/kint | src/Kint.php | Kint.dump | public static function dump()
{
if (!self::$enabled_mode) {
return 0;
}
Utils::normalizeAliases(self::$aliases);
$args = \func_get_args();
$call_info = self::getCallInfo(self::$aliases, \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), \count($args));
$statics = self::getStatics();
if (\in_array('~', $call_info['modifiers'], true)) {
$statics['enabled_mode'] = self::MODE_TEXT;
}
$kintstance = self::createFromStatics($statics);
if (!$kintstance) {
// Should never happen
return 0; // @codeCoverageIgnore
}
if (\in_array('-', $call_info['modifiers'], true)) {
while (\ob_get_level()) {
\ob_end_clean();
}
}
$kintstance->setStatesFromStatics($statics);
$kintstance->setStatesFromCallInfo($call_info);
// If the call is Kint::dump(1) then dump a backtrace instead
if ($args === array(1) && (!isset($call_info['params'][0]['name']) || '1' === $call_info['params'][0]['name'])) {
$args = \debug_backtrace(true);
$trace = array();
foreach ($args as $index => $frame) {
if (Utils::traceFrameIsListed($frame, self::$aliases)) {
$trace = array();
}
$trace[] = $frame;
}
if (isset($call_info['callee']['function'])) {
$tracename = $call_info['callee']['function'].'(1)';
if (isset($call_info['callee']['class'], $call_info['callee']['type'])) {
$tracename = $call_info['callee']['class'].$call_info['callee']['type'].$tracename;
}
} else {
$tracename = 'Kint\\Kint::dump(1)';
}
$tracebase = BasicObject::blank($tracename, 'debug_backtrace(true)');
$output = $kintstance->dumpAll(array($trace), array($tracebase));
} else {
$bases = self::getBasesFromParamInfo(
isset($call_info['params']) ? $call_info['params'] : array(),
\count($args)
);
$output = $kintstance->dumpAll($args, $bases);
}
if (self::$return || \in_array('@', $call_info['modifiers'], true)) {
return $output;
}
echo $output;
if (\in_array('-', $call_info['modifiers'], true)) {
\flush(); // @codeCoverageIgnore
}
return 0;
} | php | public static function dump()
{
if (!self::$enabled_mode) {
return 0;
}
Utils::normalizeAliases(self::$aliases);
$args = \func_get_args();
$call_info = self::getCallInfo(self::$aliases, \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), \count($args));
$statics = self::getStatics();
if (\in_array('~', $call_info['modifiers'], true)) {
$statics['enabled_mode'] = self::MODE_TEXT;
}
$kintstance = self::createFromStatics($statics);
if (!$kintstance) {
// Should never happen
return 0; // @codeCoverageIgnore
}
if (\in_array('-', $call_info['modifiers'], true)) {
while (\ob_get_level()) {
\ob_end_clean();
}
}
$kintstance->setStatesFromStatics($statics);
$kintstance->setStatesFromCallInfo($call_info);
// If the call is Kint::dump(1) then dump a backtrace instead
if ($args === array(1) && (!isset($call_info['params'][0]['name']) || '1' === $call_info['params'][0]['name'])) {
$args = \debug_backtrace(true);
$trace = array();
foreach ($args as $index => $frame) {
if (Utils::traceFrameIsListed($frame, self::$aliases)) {
$trace = array();
}
$trace[] = $frame;
}
if (isset($call_info['callee']['function'])) {
$tracename = $call_info['callee']['function'].'(1)';
if (isset($call_info['callee']['class'], $call_info['callee']['type'])) {
$tracename = $call_info['callee']['class'].$call_info['callee']['type'].$tracename;
}
} else {
$tracename = 'Kint\\Kint::dump(1)';
}
$tracebase = BasicObject::blank($tracename, 'debug_backtrace(true)');
$output = $kintstance->dumpAll(array($trace), array($tracebase));
} else {
$bases = self::getBasesFromParamInfo(
isset($call_info['params']) ? $call_info['params'] : array(),
\count($args)
);
$output = $kintstance->dumpAll($args, $bases);
}
if (self::$return || \in_array('@', $call_info['modifiers'], true)) {
return $output;
}
echo $output;
if (\in_array('-', $call_info['modifiers'], true)) {
\flush(); // @codeCoverageIgnore
}
return 0;
} | [
"public",
"static",
"function",
"dump",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"enabled_mode",
")",
"{",
"return",
"0",
";",
"}",
"Utils",
"::",
"normalizeAliases",
"(",
"self",
"::",
"$",
"aliases",
")",
";",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"$",
"call_info",
"=",
"self",
"::",
"getCallInfo",
"(",
"self",
"::",
"$",
"aliases",
",",
"\\",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
")",
",",
"\\",
"count",
"(",
"$",
"args",
")",
")",
";",
"$",
"statics",
"=",
"self",
"::",
"getStatics",
"(",
")",
";",
"if",
"(",
"\\",
"in_array",
"(",
"'~'",
",",
"$",
"call_info",
"[",
"'modifiers'",
"]",
",",
"true",
")",
")",
"{",
"$",
"statics",
"[",
"'enabled_mode'",
"]",
"=",
"self",
"::",
"MODE_TEXT",
";",
"}",
"$",
"kintstance",
"=",
"self",
"::",
"createFromStatics",
"(",
"$",
"statics",
")",
";",
"if",
"(",
"!",
"$",
"kintstance",
")",
"{",
"// Should never happen",
"return",
"0",
";",
"// @codeCoverageIgnore",
"}",
"if",
"(",
"\\",
"in_array",
"(",
"'-'",
",",
"$",
"call_info",
"[",
"'modifiers'",
"]",
",",
"true",
")",
")",
"{",
"while",
"(",
"\\",
"ob_get_level",
"(",
")",
")",
"{",
"\\",
"ob_end_clean",
"(",
")",
";",
"}",
"}",
"$",
"kintstance",
"->",
"setStatesFromStatics",
"(",
"$",
"statics",
")",
";",
"$",
"kintstance",
"->",
"setStatesFromCallInfo",
"(",
"$",
"call_info",
")",
";",
"// If the call is Kint::dump(1) then dump a backtrace instead",
"if",
"(",
"$",
"args",
"===",
"array",
"(",
"1",
")",
"&&",
"(",
"!",
"isset",
"(",
"$",
"call_info",
"[",
"'params'",
"]",
"[",
"0",
"]",
"[",
"'name'",
"]",
")",
"||",
"'1'",
"===",
"$",
"call_info",
"[",
"'params'",
"]",
"[",
"0",
"]",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"args",
"=",
"\\",
"debug_backtrace",
"(",
"true",
")",
";",
"$",
"trace",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"index",
"=>",
"$",
"frame",
")",
"{",
"if",
"(",
"Utils",
"::",
"traceFrameIsListed",
"(",
"$",
"frame",
",",
"self",
"::",
"$",
"aliases",
")",
")",
"{",
"$",
"trace",
"=",
"array",
"(",
")",
";",
"}",
"$",
"trace",
"[",
"]",
"=",
"$",
"frame",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"call_info",
"[",
"'callee'",
"]",
"[",
"'function'",
"]",
")",
")",
"{",
"$",
"tracename",
"=",
"$",
"call_info",
"[",
"'callee'",
"]",
"[",
"'function'",
"]",
".",
"'(1)'",
";",
"if",
"(",
"isset",
"(",
"$",
"call_info",
"[",
"'callee'",
"]",
"[",
"'class'",
"]",
",",
"$",
"call_info",
"[",
"'callee'",
"]",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"tracename",
"=",
"$",
"call_info",
"[",
"'callee'",
"]",
"[",
"'class'",
"]",
".",
"$",
"call_info",
"[",
"'callee'",
"]",
"[",
"'type'",
"]",
".",
"$",
"tracename",
";",
"}",
"}",
"else",
"{",
"$",
"tracename",
"=",
"'Kint\\\\Kint::dump(1)'",
";",
"}",
"$",
"tracebase",
"=",
"BasicObject",
"::",
"blank",
"(",
"$",
"tracename",
",",
"'debug_backtrace(true)'",
")",
";",
"$",
"output",
"=",
"$",
"kintstance",
"->",
"dumpAll",
"(",
"array",
"(",
"$",
"trace",
")",
",",
"array",
"(",
"$",
"tracebase",
")",
")",
";",
"}",
"else",
"{",
"$",
"bases",
"=",
"self",
"::",
"getBasesFromParamInfo",
"(",
"isset",
"(",
"$",
"call_info",
"[",
"'params'",
"]",
")",
"?",
"$",
"call_info",
"[",
"'params'",
"]",
":",
"array",
"(",
")",
",",
"\\",
"count",
"(",
"$",
"args",
")",
")",
";",
"$",
"output",
"=",
"$",
"kintstance",
"->",
"dumpAll",
"(",
"$",
"args",
",",
"$",
"bases",
")",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"return",
"||",
"\\",
"in_array",
"(",
"'@'",
",",
"$",
"call_info",
"[",
"'modifiers'",
"]",
",",
"true",
")",
")",
"{",
"return",
"$",
"output",
";",
"}",
"echo",
"$",
"output",
";",
"if",
"(",
"\\",
"in_array",
"(",
"'-'",
",",
"$",
"call_info",
"[",
"'modifiers'",
"]",
",",
"true",
")",
")",
"{",
"\\",
"flush",
"(",
")",
";",
"// @codeCoverageIgnore",
"}",
"return",
"0",
";",
"}"
] | Dumps some data.
Functionally equivalent to Kint::dump(1) or Kint::dump(debug_backtrace(true))
@return int|string | [
"Dumps",
"some",
"data",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L552-L629 | train |
kint-php/kint | src/Kint.php | Kint.shortenPath | public static function shortenPath($file)
{
$file = \array_values(\array_filter(\explode('/', \str_replace('\\', '/', $file)), 'strlen'));
$longest_match = 0;
$match = '/';
foreach (self::$app_root_dirs as $path => $alias) {
if (empty($path)) {
continue;
}
$path = \array_values(\array_filter(\explode('/', \str_replace('\\', '/', $path)), 'strlen'));
if (\array_slice($file, 0, \count($path)) === $path && \count($path) > $longest_match) {
$longest_match = \count($path);
$match = $alias;
}
}
if ($longest_match) {
$file = \array_merge(array($match), \array_slice($file, $longest_match));
return \implode('/', $file);
}
// fallback to find common path with Kint dir
$kint = \array_values(\array_filter(\explode('/', \str_replace('\\', '/', KINT_DIR)), 'strlen'));
foreach ($file as $i => $part) {
if (!isset($kint[$i]) || $kint[$i] !== $part) {
return ($i ? '.../' : '/').\implode('/', \array_slice($file, $i));
}
}
return '/'.\implode('/', $file);
} | php | public static function shortenPath($file)
{
$file = \array_values(\array_filter(\explode('/', \str_replace('\\', '/', $file)), 'strlen'));
$longest_match = 0;
$match = '/';
foreach (self::$app_root_dirs as $path => $alias) {
if (empty($path)) {
continue;
}
$path = \array_values(\array_filter(\explode('/', \str_replace('\\', '/', $path)), 'strlen'));
if (\array_slice($file, 0, \count($path)) === $path && \count($path) > $longest_match) {
$longest_match = \count($path);
$match = $alias;
}
}
if ($longest_match) {
$file = \array_merge(array($match), \array_slice($file, $longest_match));
return \implode('/', $file);
}
// fallback to find common path with Kint dir
$kint = \array_values(\array_filter(\explode('/', \str_replace('\\', '/', KINT_DIR)), 'strlen'));
foreach ($file as $i => $part) {
if (!isset($kint[$i]) || $kint[$i] !== $part) {
return ($i ? '.../' : '/').\implode('/', \array_slice($file, $i));
}
}
return '/'.\implode('/', $file);
} | [
"public",
"static",
"function",
"shortenPath",
"(",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"\\",
"array_values",
"(",
"\\",
"array_filter",
"(",
"\\",
"explode",
"(",
"'/'",
",",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"file",
")",
")",
",",
"'strlen'",
")",
")",
";",
"$",
"longest_match",
"=",
"0",
";",
"$",
"match",
"=",
"'/'",
";",
"foreach",
"(",
"self",
"::",
"$",
"app_root_dirs",
"as",
"$",
"path",
"=>",
"$",
"alias",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"continue",
";",
"}",
"$",
"path",
"=",
"\\",
"array_values",
"(",
"\\",
"array_filter",
"(",
"\\",
"explode",
"(",
"'/'",
",",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
")",
",",
"'strlen'",
")",
")",
";",
"if",
"(",
"\\",
"array_slice",
"(",
"$",
"file",
",",
"0",
",",
"\\",
"count",
"(",
"$",
"path",
")",
")",
"===",
"$",
"path",
"&&",
"\\",
"count",
"(",
"$",
"path",
")",
">",
"$",
"longest_match",
")",
"{",
"$",
"longest_match",
"=",
"\\",
"count",
"(",
"$",
"path",
")",
";",
"$",
"match",
"=",
"$",
"alias",
";",
"}",
"}",
"if",
"(",
"$",
"longest_match",
")",
"{",
"$",
"file",
"=",
"\\",
"array_merge",
"(",
"array",
"(",
"$",
"match",
")",
",",
"\\",
"array_slice",
"(",
"$",
"file",
",",
"$",
"longest_match",
")",
")",
";",
"return",
"\\",
"implode",
"(",
"'/'",
",",
"$",
"file",
")",
";",
"}",
"// fallback to find common path with Kint dir",
"$",
"kint",
"=",
"\\",
"array_values",
"(",
"\\",
"array_filter",
"(",
"\\",
"explode",
"(",
"'/'",
",",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"KINT_DIR",
")",
")",
",",
"'strlen'",
")",
")",
";",
"foreach",
"(",
"$",
"file",
"as",
"$",
"i",
"=>",
"$",
"part",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"kint",
"[",
"$",
"i",
"]",
")",
"||",
"$",
"kint",
"[",
"$",
"i",
"]",
"!==",
"$",
"part",
")",
"{",
"return",
"(",
"$",
"i",
"?",
"'.../'",
":",
"'/'",
")",
".",
"\\",
"implode",
"(",
"'/'",
",",
"\\",
"array_slice",
"(",
"$",
"file",
",",
"$",
"i",
")",
")",
";",
"}",
"}",
"return",
"'/'",
".",
"\\",
"implode",
"(",
"'/'",
",",
"$",
"file",
")",
";",
"}"
] | generic path display callback, can be configured in app_root_dirs; purpose is
to show relevant path info and hide as much of the path as possible.
@param string $file
@return string | [
"generic",
"path",
"display",
"callback",
"can",
"be",
"configured",
"in",
"app_root_dirs",
";",
"purpose",
"is",
"to",
"show",
"relevant",
"path",
"info",
"and",
"hide",
"as",
"much",
"of",
"the",
"path",
"as",
"possible",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L639-L675 | train |
kint-php/kint | src/Kint.php | Kint.getSingleCall | protected static function getSingleCall(array $frame, $argc)
{
if (!isset($frame['file'], $frame['line'], $frame['function']) || !\is_readable($frame['file'])) {
return null;
}
if (empty($frame['class'])) {
$callfunc = $frame['function'];
} else {
$callfunc = array($frame['class'], $frame['function']);
}
$calls = CallFinder::getFunctionCalls(
\file_get_contents($frame['file']),
$frame['line'],
$callfunc
);
$return = null;
foreach ($calls as $call) {
$is_unpack = false;
// Handle argument unpacking as a last resort
if (KINT_PHP56) {
foreach ($call['parameters'] as $i => &$param) {
if (0 === \strpos($param['name'], '...')) {
if ($i < $argc && $i === \count($call['parameters']) - 1) {
for ($j = 1; $j + $i < $argc; ++$j) {
$call['parameters'][] = array(
'name' => 'array_values('.\substr($param['name'], 3).')['.$j.']',
'path' => 'array_values('.\substr($param['path'], 3).')['.$j.']',
'expression' => false,
);
}
$param['name'] = 'reset('.\substr($param['name'], 3).')';
$param['path'] = 'reset('.\substr($param['path'], 3).')';
$param['expression'] = false;
} else {
$call['parameters'] = \array_slice($call['parameters'], 0, $i);
}
$is_unpack = true;
break;
}
if ($i >= $argc) {
continue 2;
}
}
}
if ($is_unpack || \count($call['parameters']) === $argc) {
if (null === $return) {
$return = $call;
} else {
// If we have multiple calls on the same line with the same amount of arguments,
// we can't be sure which it is so just return null and let them figure it out
return null;
}
}
}
return $return;
} | php | protected static function getSingleCall(array $frame, $argc)
{
if (!isset($frame['file'], $frame['line'], $frame['function']) || !\is_readable($frame['file'])) {
return null;
}
if (empty($frame['class'])) {
$callfunc = $frame['function'];
} else {
$callfunc = array($frame['class'], $frame['function']);
}
$calls = CallFinder::getFunctionCalls(
\file_get_contents($frame['file']),
$frame['line'],
$callfunc
);
$return = null;
foreach ($calls as $call) {
$is_unpack = false;
// Handle argument unpacking as a last resort
if (KINT_PHP56) {
foreach ($call['parameters'] as $i => &$param) {
if (0 === \strpos($param['name'], '...')) {
if ($i < $argc && $i === \count($call['parameters']) - 1) {
for ($j = 1; $j + $i < $argc; ++$j) {
$call['parameters'][] = array(
'name' => 'array_values('.\substr($param['name'], 3).')['.$j.']',
'path' => 'array_values('.\substr($param['path'], 3).')['.$j.']',
'expression' => false,
);
}
$param['name'] = 'reset('.\substr($param['name'], 3).')';
$param['path'] = 'reset('.\substr($param['path'], 3).')';
$param['expression'] = false;
} else {
$call['parameters'] = \array_slice($call['parameters'], 0, $i);
}
$is_unpack = true;
break;
}
if ($i >= $argc) {
continue 2;
}
}
}
if ($is_unpack || \count($call['parameters']) === $argc) {
if (null === $return) {
$return = $call;
} else {
// If we have multiple calls on the same line with the same amount of arguments,
// we can't be sure which it is so just return null and let them figure it out
return null;
}
}
}
return $return;
} | [
"protected",
"static",
"function",
"getSingleCall",
"(",
"array",
"$",
"frame",
",",
"$",
"argc",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"frame",
"[",
"'file'",
"]",
",",
"$",
"frame",
"[",
"'line'",
"]",
",",
"$",
"frame",
"[",
"'function'",
"]",
")",
"||",
"!",
"\\",
"is_readable",
"(",
"$",
"frame",
"[",
"'file'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"frame",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"callfunc",
"=",
"$",
"frame",
"[",
"'function'",
"]",
";",
"}",
"else",
"{",
"$",
"callfunc",
"=",
"array",
"(",
"$",
"frame",
"[",
"'class'",
"]",
",",
"$",
"frame",
"[",
"'function'",
"]",
")",
";",
"}",
"$",
"calls",
"=",
"CallFinder",
"::",
"getFunctionCalls",
"(",
"\\",
"file_get_contents",
"(",
"$",
"frame",
"[",
"'file'",
"]",
")",
",",
"$",
"frame",
"[",
"'line'",
"]",
",",
"$",
"callfunc",
")",
";",
"$",
"return",
"=",
"null",
";",
"foreach",
"(",
"$",
"calls",
"as",
"$",
"call",
")",
"{",
"$",
"is_unpack",
"=",
"false",
";",
"// Handle argument unpacking as a last resort",
"if",
"(",
"KINT_PHP56",
")",
"{",
"foreach",
"(",
"$",
"call",
"[",
"'parameters'",
"]",
"as",
"$",
"i",
"=>",
"&",
"$",
"param",
")",
"{",
"if",
"(",
"0",
"===",
"\\",
"strpos",
"(",
"$",
"param",
"[",
"'name'",
"]",
",",
"'...'",
")",
")",
"{",
"if",
"(",
"$",
"i",
"<",
"$",
"argc",
"&&",
"$",
"i",
"===",
"\\",
"count",
"(",
"$",
"call",
"[",
"'parameters'",
"]",
")",
"-",
"1",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"1",
";",
"$",
"j",
"+",
"$",
"i",
"<",
"$",
"argc",
";",
"++",
"$",
"j",
")",
"{",
"$",
"call",
"[",
"'parameters'",
"]",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"'array_values('",
".",
"\\",
"substr",
"(",
"$",
"param",
"[",
"'name'",
"]",
",",
"3",
")",
".",
"')['",
".",
"$",
"j",
".",
"']'",
",",
"'path'",
"=>",
"'array_values('",
".",
"\\",
"substr",
"(",
"$",
"param",
"[",
"'path'",
"]",
",",
"3",
")",
".",
"')['",
".",
"$",
"j",
".",
"']'",
",",
"'expression'",
"=>",
"false",
",",
")",
";",
"}",
"$",
"param",
"[",
"'name'",
"]",
"=",
"'reset('",
".",
"\\",
"substr",
"(",
"$",
"param",
"[",
"'name'",
"]",
",",
"3",
")",
".",
"')'",
";",
"$",
"param",
"[",
"'path'",
"]",
"=",
"'reset('",
".",
"\\",
"substr",
"(",
"$",
"param",
"[",
"'path'",
"]",
",",
"3",
")",
".",
"')'",
";",
"$",
"param",
"[",
"'expression'",
"]",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"call",
"[",
"'parameters'",
"]",
"=",
"\\",
"array_slice",
"(",
"$",
"call",
"[",
"'parameters'",
"]",
",",
"0",
",",
"$",
"i",
")",
";",
"}",
"$",
"is_unpack",
"=",
"true",
";",
"break",
";",
"}",
"if",
"(",
"$",
"i",
">=",
"$",
"argc",
")",
"{",
"continue",
"2",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"is_unpack",
"||",
"\\",
"count",
"(",
"$",
"call",
"[",
"'parameters'",
"]",
")",
"===",
"$",
"argc",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"return",
")",
"{",
"$",
"return",
"=",
"$",
"call",
";",
"}",
"else",
"{",
"// If we have multiple calls on the same line with the same amount of arguments,",
"// we can't be sure which it is so just return null and let them figure it out",
"return",
"null",
";",
"}",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Returns specific function call info from a stack trace frame, or null if no match could be found.
@param array $frame The stack trace frame in question
@param int $argc The amount of arguments received
@return null|array{parameters:array, modifiers:array} params and modifiers, or null if a specific call could not be determined | [
"Returns",
"specific",
"function",
"call",
"info",
"from",
"a",
"stack",
"trace",
"frame",
"or",
"null",
"if",
"no",
"match",
"could",
"be",
"found",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Kint.php#L690-L755 | train |
kint-php/kint | src/Object/Representation/SourceRepresentation.php | SourceRepresentation.getSource | public static function getSource($filename, $start_line = 1, $length = null)
{
if (!$filename || !\file_exists($filename) || !\is_readable($filename)) {
return null;
}
$source = \preg_split("/\r\n|\n|\r/", \file_get_contents($filename));
$source = \array_combine(\range(1, \count($source)), $source);
$source = \array_slice($source, $start_line - 1, $length, true);
return $source;
} | php | public static function getSource($filename, $start_line = 1, $length = null)
{
if (!$filename || !\file_exists($filename) || !\is_readable($filename)) {
return null;
}
$source = \preg_split("/\r\n|\n|\r/", \file_get_contents($filename));
$source = \array_combine(\range(1, \count($source)), $source);
$source = \array_slice($source, $start_line - 1, $length, true);
return $source;
} | [
"public",
"static",
"function",
"getSource",
"(",
"$",
"filename",
",",
"$",
"start_line",
"=",
"1",
",",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"filename",
"||",
"!",
"\\",
"file_exists",
"(",
"$",
"filename",
")",
"||",
"!",
"\\",
"is_readable",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"source",
"=",
"\\",
"preg_split",
"(",
"\"/\\r\\n|\\n|\\r/\"",
",",
"\\",
"file_get_contents",
"(",
"$",
"filename",
")",
")",
";",
"$",
"source",
"=",
"\\",
"array_combine",
"(",
"\\",
"range",
"(",
"1",
",",
"\\",
"count",
"(",
"$",
"source",
")",
")",
",",
"$",
"source",
")",
";",
"$",
"source",
"=",
"\\",
"array_slice",
"(",
"$",
"source",
",",
"$",
"start_line",
"-",
"1",
",",
"$",
"length",
",",
"true",
")",
";",
"return",
"$",
"source",
";",
"}"
] | Gets section of source code.
@param string $filename Full path to file
@param int $start_line The first line to display (1 based)
@param null|int $length Amount of lines to show
@return null|array | [
"Gets",
"section",
"of",
"source",
"code",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Object/Representation/SourceRepresentation.php#L60-L71 | train |
kint-php/kint | src/Renderer/Renderer.php | Renderer.matchPlugins | public function matchPlugins(array $plugins, array $hints)
{
$out = array();
foreach ($hints as $key) {
if (isset($plugins[$key])) {
$out[$key] = $plugins[$key];
}
}
return $out;
} | php | public function matchPlugins(array $plugins, array $hints)
{
$out = array();
foreach ($hints as $key) {
if (isset($plugins[$key])) {
$out[$key] = $plugins[$key];
}
}
return $out;
} | [
"public",
"function",
"matchPlugins",
"(",
"array",
"$",
"plugins",
",",
"array",
"$",
"hints",
")",
"{",
"$",
"out",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"hints",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"plugins",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"$",
"plugins",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] | Returns the first compatible plugin available.
@param array $plugins Array of hints to class strings
@param array $hints Array of object hints
@return array Array of hints to class strings filtered and sorted by object hints | [
"Returns",
"the",
"first",
"compatible",
"plugin",
"available",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Renderer/Renderer.php#L110-L121 | train |
kint-php/kint | src/Renderer/Renderer.php | Renderer.sortProperties | public static function sortProperties(array $contents, $sort)
{
switch ($sort) {
case self::SORT_VISIBILITY:
/** @var array<array-key, BasicObject[]> Containers to quickly stable sort by type */
$containers = array(
BasicObject::ACCESS_PUBLIC => array(),
BasicObject::ACCESS_PROTECTED => array(),
BasicObject::ACCESS_PRIVATE => array(),
BasicObject::ACCESS_NONE => array(),
);
foreach ($contents as $item) {
$containers[$item->access][] = $item;
}
return \call_user_func_array('array_merge', $containers);
case self::SORT_FULL:
\usort($contents, array('Kint\\Renderer\\Renderer', 'sortPropertiesFull'));
// no break
default:
return $contents;
}
} | php | public static function sortProperties(array $contents, $sort)
{
switch ($sort) {
case self::SORT_VISIBILITY:
/** @var array<array-key, BasicObject[]> Containers to quickly stable sort by type */
$containers = array(
BasicObject::ACCESS_PUBLIC => array(),
BasicObject::ACCESS_PROTECTED => array(),
BasicObject::ACCESS_PRIVATE => array(),
BasicObject::ACCESS_NONE => array(),
);
foreach ($contents as $item) {
$containers[$item->access][] = $item;
}
return \call_user_func_array('array_merge', $containers);
case self::SORT_FULL:
\usort($contents, array('Kint\\Renderer\\Renderer', 'sortPropertiesFull'));
// no break
default:
return $contents;
}
} | [
"public",
"static",
"function",
"sortProperties",
"(",
"array",
"$",
"contents",
",",
"$",
"sort",
")",
"{",
"switch",
"(",
"$",
"sort",
")",
"{",
"case",
"self",
"::",
"SORT_VISIBILITY",
":",
"/** @var array<array-key, BasicObject[]> Containers to quickly stable sort by type */",
"$",
"containers",
"=",
"array",
"(",
"BasicObject",
"::",
"ACCESS_PUBLIC",
"=>",
"array",
"(",
")",
",",
"BasicObject",
"::",
"ACCESS_PROTECTED",
"=>",
"array",
"(",
")",
",",
"BasicObject",
"::",
"ACCESS_PRIVATE",
"=>",
"array",
"(",
")",
",",
"BasicObject",
"::",
"ACCESS_NONE",
"=>",
"array",
"(",
")",
",",
")",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"item",
")",
"{",
"$",
"containers",
"[",
"$",
"item",
"->",
"access",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"\\",
"call_user_func_array",
"(",
"'array_merge'",
",",
"$",
"containers",
")",
";",
"case",
"self",
"::",
"SORT_FULL",
":",
"\\",
"usort",
"(",
"$",
"contents",
",",
"array",
"(",
"'Kint\\\\Renderer\\\\Renderer'",
",",
"'sortPropertiesFull'",
")",
")",
";",
"// no break",
"default",
":",
"return",
"$",
"contents",
";",
"}",
"}"
] | Sorts an array of BasicObject.
@param BasicObject[] $contents Object properties to sort
@param int $sort
@return BasicObject[] | [
"Sorts",
"an",
"array",
"of",
"BasicObject",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Renderer/Renderer.php#L161-L184 | train |
kint-php/kint | src/Parser/Parser.php | Parser.parseDeep | public function parseDeep(&$var, BasicObject $o)
{
$depth_limit = $this->depth_limit;
$this->depth_limit = false;
$out = $this->parse($var, $o);
$this->depth_limit = $depth_limit;
return $out;
} | php | public function parseDeep(&$var, BasicObject $o)
{
$depth_limit = $this->depth_limit;
$this->depth_limit = false;
$out = $this->parse($var, $o);
$this->depth_limit = $depth_limit;
return $out;
} | [
"public",
"function",
"parseDeep",
"(",
"&",
"$",
"var",
",",
"BasicObject",
"$",
"o",
")",
"{",
"$",
"depth_limit",
"=",
"$",
"this",
"->",
"depth_limit",
";",
"$",
"this",
"->",
"depth_limit",
"=",
"false",
";",
"$",
"out",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"var",
",",
"$",
"o",
")",
";",
"$",
"this",
"->",
"depth_limit",
"=",
"$",
"depth_limit",
";",
"return",
"$",
"out",
";",
"}"
] | Disables the depth limit and parses a variable.
This should not be used unless you know what you're doing!
@param mixed $var The input variable
@param BasicObject $o The base object
@return BasicObject | [
"Disables",
"the",
"depth",
"limit",
"and",
"parses",
"a",
"variable",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Parser/Parser.php#L126-L136 | train |
kint-php/kint | src/Parser/Parser.php | Parser.parse | public function parse(&$var, BasicObject $o)
{
$o->type = \strtolower(\gettype($var));
if (!$this->applyPlugins($var, $o, self::TRIGGER_BEGIN)) {
return $o;
}
switch ($o->type) {
case 'array':
return $this->parseArray($var, $o);
case 'boolean':
case 'double':
case 'integer':
case 'null':
return $this->parseGeneric($var, $o);
case 'object':
return $this->parseObject($var, $o);
case 'resource':
return $this->parseResource($var, $o);
case 'string':
return $this->parseString($var, $o);
default:
return $this->parseUnknown($var, $o);
}
} | php | public function parse(&$var, BasicObject $o)
{
$o->type = \strtolower(\gettype($var));
if (!$this->applyPlugins($var, $o, self::TRIGGER_BEGIN)) {
return $o;
}
switch ($o->type) {
case 'array':
return $this->parseArray($var, $o);
case 'boolean':
case 'double':
case 'integer':
case 'null':
return $this->parseGeneric($var, $o);
case 'object':
return $this->parseObject($var, $o);
case 'resource':
return $this->parseResource($var, $o);
case 'string':
return $this->parseString($var, $o);
default:
return $this->parseUnknown($var, $o);
}
} | [
"public",
"function",
"parse",
"(",
"&",
"$",
"var",
",",
"BasicObject",
"$",
"o",
")",
"{",
"$",
"o",
"->",
"type",
"=",
"\\",
"strtolower",
"(",
"\\",
"gettype",
"(",
"$",
"var",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"applyPlugins",
"(",
"$",
"var",
",",
"$",
"o",
",",
"self",
"::",
"TRIGGER_BEGIN",
")",
")",
"{",
"return",
"$",
"o",
";",
"}",
"switch",
"(",
"$",
"o",
"->",
"type",
")",
"{",
"case",
"'array'",
":",
"return",
"$",
"this",
"->",
"parseArray",
"(",
"$",
"var",
",",
"$",
"o",
")",
";",
"case",
"'boolean'",
":",
"case",
"'double'",
":",
"case",
"'integer'",
":",
"case",
"'null'",
":",
"return",
"$",
"this",
"->",
"parseGeneric",
"(",
"$",
"var",
",",
"$",
"o",
")",
";",
"case",
"'object'",
":",
"return",
"$",
"this",
"->",
"parseObject",
"(",
"$",
"var",
",",
"$",
"o",
")",
";",
"case",
"'resource'",
":",
"return",
"$",
"this",
"->",
"parseResource",
"(",
"$",
"var",
",",
"$",
"o",
")",
";",
"case",
"'string'",
":",
"return",
"$",
"this",
"->",
"parseString",
"(",
"$",
"var",
",",
"$",
"o",
")",
";",
"default",
":",
"return",
"$",
"this",
"->",
"parseUnknown",
"(",
"$",
"var",
",",
"$",
"o",
")",
";",
"}",
"}"
] | Parses a variable into a Kint object structure.
@param mixed $var The input variable
@param BasicObject $o The base object
@return BasicObject | [
"Parses",
"a",
"variable",
"into",
"a",
"Kint",
"object",
"structure",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Parser/Parser.php#L146-L171 | train |
kint-php/kint | src/Parser/Parser.php | Parser.parseString | private function parseString(&$var, BasicObject $o)
{
$string = new BlobObject();
$string->transplant($o);
$string->encoding = BlobObject::detectEncoding($var);
$string->size = BlobObject::strlen($var, $string->encoding);
$rep = new Representation('Contents');
$rep->contents = $var;
$rep->implicit_label = true;
$string->addRepresentation($rep);
$string->value = $rep;
$this->applyPlugins($var, $string, self::TRIGGER_SUCCESS);
return $string;
} | php | private function parseString(&$var, BasicObject $o)
{
$string = new BlobObject();
$string->transplant($o);
$string->encoding = BlobObject::detectEncoding($var);
$string->size = BlobObject::strlen($var, $string->encoding);
$rep = new Representation('Contents');
$rep->contents = $var;
$rep->implicit_label = true;
$string->addRepresentation($rep);
$string->value = $rep;
$this->applyPlugins($var, $string, self::TRIGGER_SUCCESS);
return $string;
} | [
"private",
"function",
"parseString",
"(",
"&",
"$",
"var",
",",
"BasicObject",
"$",
"o",
")",
"{",
"$",
"string",
"=",
"new",
"BlobObject",
"(",
")",
";",
"$",
"string",
"->",
"transplant",
"(",
"$",
"o",
")",
";",
"$",
"string",
"->",
"encoding",
"=",
"BlobObject",
"::",
"detectEncoding",
"(",
"$",
"var",
")",
";",
"$",
"string",
"->",
"size",
"=",
"BlobObject",
"::",
"strlen",
"(",
"$",
"var",
",",
"$",
"string",
"->",
"encoding",
")",
";",
"$",
"rep",
"=",
"new",
"Representation",
"(",
"'Contents'",
")",
";",
"$",
"rep",
"->",
"contents",
"=",
"$",
"var",
";",
"$",
"rep",
"->",
"implicit_label",
"=",
"true",
";",
"$",
"string",
"->",
"addRepresentation",
"(",
"$",
"rep",
")",
";",
"$",
"string",
"->",
"value",
"=",
"$",
"rep",
";",
"$",
"this",
"->",
"applyPlugins",
"(",
"$",
"var",
",",
"$",
"string",
",",
"self",
"::",
"TRIGGER_SUCCESS",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Parses a string into a Kint BlobObject structure.
@param string $var The input variable
@param BasicObject $o The base object
@return BasicObject | [
"Parses",
"a",
"string",
"into",
"a",
"Kint",
"BlobObject",
"structure",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Parser/Parser.php#L301-L318 | train |
kint-php/kint | src/Parser/Parser.php | Parser.parseArray | private function parseArray(array &$var, BasicObject $o)
{
$array = new BasicObject();
$array->transplant($o);
$array->size = \count($var);
if (isset($var[$this->marker])) {
--$array->size;
$array->hints[] = 'recursion';
$this->applyPlugins($var, $array, self::TRIGGER_RECURSION);
return $array;
}
$rep = new Representation('Contents');
$rep->implicit_label = true;
$array->addRepresentation($rep);
$array->value = $rep;
if (!$array->size) {
$this->applyPlugins($var, $array, self::TRIGGER_SUCCESS);
return $array;
}
if ($this->depth_limit && $o->depth >= $this->depth_limit) {
$array->hints[] = 'depth_limit';
$this->applyPlugins($var, $array, self::TRIGGER_DEPTH_LIMIT);
return $array;
}
$copy = \array_values($var);
// It's really really hard to access numeric string keys in arrays,
// and it's really really hard to access integer properties in
// objects, so we just use array_values and index by counter to get
// at it reliably for reference testing. This also affects access
// paths since it's pretty much impossible to access these things
// without complicated stuff you should never need to do.
$i = 0;
// Set the marker for recursion
$var[$this->marker] = $array->depth;
$refmarker = new stdClass();
foreach ($var as $key => &$val) {
if ($key === $this->marker) {
continue;
}
$child = new BasicObject();
$child->name = $key;
$child->depth = $array->depth + 1;
$child->access = BasicObject::ACCESS_NONE;
$child->operator = BasicObject::OPERATOR_ARRAY;
if (null !== $array->access_path) {
if (\is_string($key) && (string) (int) $key === $key) {
$child->access_path = 'array_values('.$array->access_path.')['.$i.']'; // @codeCoverageIgnore
} else {
$child->access_path = $array->access_path.'['.\var_export($key, true).']';
}
}
$stash = $val;
$copy[$i] = $refmarker;
if ($val === $refmarker) {
$child->reference = true;
$val = $stash;
}
$rep->contents[] = $this->parse($val, $child);
++$i;
}
$this->applyPlugins($var, $array, self::TRIGGER_SUCCESS);
unset($var[$this->marker]);
return $array;
} | php | private function parseArray(array &$var, BasicObject $o)
{
$array = new BasicObject();
$array->transplant($o);
$array->size = \count($var);
if (isset($var[$this->marker])) {
--$array->size;
$array->hints[] = 'recursion';
$this->applyPlugins($var, $array, self::TRIGGER_RECURSION);
return $array;
}
$rep = new Representation('Contents');
$rep->implicit_label = true;
$array->addRepresentation($rep);
$array->value = $rep;
if (!$array->size) {
$this->applyPlugins($var, $array, self::TRIGGER_SUCCESS);
return $array;
}
if ($this->depth_limit && $o->depth >= $this->depth_limit) {
$array->hints[] = 'depth_limit';
$this->applyPlugins($var, $array, self::TRIGGER_DEPTH_LIMIT);
return $array;
}
$copy = \array_values($var);
// It's really really hard to access numeric string keys in arrays,
// and it's really really hard to access integer properties in
// objects, so we just use array_values and index by counter to get
// at it reliably for reference testing. This also affects access
// paths since it's pretty much impossible to access these things
// without complicated stuff you should never need to do.
$i = 0;
// Set the marker for recursion
$var[$this->marker] = $array->depth;
$refmarker = new stdClass();
foreach ($var as $key => &$val) {
if ($key === $this->marker) {
continue;
}
$child = new BasicObject();
$child->name = $key;
$child->depth = $array->depth + 1;
$child->access = BasicObject::ACCESS_NONE;
$child->operator = BasicObject::OPERATOR_ARRAY;
if (null !== $array->access_path) {
if (\is_string($key) && (string) (int) $key === $key) {
$child->access_path = 'array_values('.$array->access_path.')['.$i.']'; // @codeCoverageIgnore
} else {
$child->access_path = $array->access_path.'['.\var_export($key, true).']';
}
}
$stash = $val;
$copy[$i] = $refmarker;
if ($val === $refmarker) {
$child->reference = true;
$val = $stash;
}
$rep->contents[] = $this->parse($val, $child);
++$i;
}
$this->applyPlugins($var, $array, self::TRIGGER_SUCCESS);
unset($var[$this->marker]);
return $array;
} | [
"private",
"function",
"parseArray",
"(",
"array",
"&",
"$",
"var",
",",
"BasicObject",
"$",
"o",
")",
"{",
"$",
"array",
"=",
"new",
"BasicObject",
"(",
")",
";",
"$",
"array",
"->",
"transplant",
"(",
"$",
"o",
")",
";",
"$",
"array",
"->",
"size",
"=",
"\\",
"count",
"(",
"$",
"var",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"var",
"[",
"$",
"this",
"->",
"marker",
"]",
")",
")",
"{",
"--",
"$",
"array",
"->",
"size",
";",
"$",
"array",
"->",
"hints",
"[",
"]",
"=",
"'recursion'",
";",
"$",
"this",
"->",
"applyPlugins",
"(",
"$",
"var",
",",
"$",
"array",
",",
"self",
"::",
"TRIGGER_RECURSION",
")",
";",
"return",
"$",
"array",
";",
"}",
"$",
"rep",
"=",
"new",
"Representation",
"(",
"'Contents'",
")",
";",
"$",
"rep",
"->",
"implicit_label",
"=",
"true",
";",
"$",
"array",
"->",
"addRepresentation",
"(",
"$",
"rep",
")",
";",
"$",
"array",
"->",
"value",
"=",
"$",
"rep",
";",
"if",
"(",
"!",
"$",
"array",
"->",
"size",
")",
"{",
"$",
"this",
"->",
"applyPlugins",
"(",
"$",
"var",
",",
"$",
"array",
",",
"self",
"::",
"TRIGGER_SUCCESS",
")",
";",
"return",
"$",
"array",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"depth_limit",
"&&",
"$",
"o",
"->",
"depth",
">=",
"$",
"this",
"->",
"depth_limit",
")",
"{",
"$",
"array",
"->",
"hints",
"[",
"]",
"=",
"'depth_limit'",
";",
"$",
"this",
"->",
"applyPlugins",
"(",
"$",
"var",
",",
"$",
"array",
",",
"self",
"::",
"TRIGGER_DEPTH_LIMIT",
")",
";",
"return",
"$",
"array",
";",
"}",
"$",
"copy",
"=",
"\\",
"array_values",
"(",
"$",
"var",
")",
";",
"// It's really really hard to access numeric string keys in arrays,",
"// and it's really really hard to access integer properties in",
"// objects, so we just use array_values and index by counter to get",
"// at it reliably for reference testing. This also affects access",
"// paths since it's pretty much impossible to access these things",
"// without complicated stuff you should never need to do.",
"$",
"i",
"=",
"0",
";",
"// Set the marker for recursion",
"$",
"var",
"[",
"$",
"this",
"->",
"marker",
"]",
"=",
"$",
"array",
"->",
"depth",
";",
"$",
"refmarker",
"=",
"new",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"var",
"as",
"$",
"key",
"=>",
"&",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"$",
"this",
"->",
"marker",
")",
"{",
"continue",
";",
"}",
"$",
"child",
"=",
"new",
"BasicObject",
"(",
")",
";",
"$",
"child",
"->",
"name",
"=",
"$",
"key",
";",
"$",
"child",
"->",
"depth",
"=",
"$",
"array",
"->",
"depth",
"+",
"1",
";",
"$",
"child",
"->",
"access",
"=",
"BasicObject",
"::",
"ACCESS_NONE",
";",
"$",
"child",
"->",
"operator",
"=",
"BasicObject",
"::",
"OPERATOR_ARRAY",
";",
"if",
"(",
"null",
"!==",
"$",
"array",
"->",
"access_path",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"key",
")",
"&&",
"(",
"string",
")",
"(",
"int",
")",
"$",
"key",
"===",
"$",
"key",
")",
"{",
"$",
"child",
"->",
"access_path",
"=",
"'array_values('",
".",
"$",
"array",
"->",
"access_path",
".",
"')['",
".",
"$",
"i",
".",
"']'",
";",
"// @codeCoverageIgnore",
"}",
"else",
"{",
"$",
"child",
"->",
"access_path",
"=",
"$",
"array",
"->",
"access_path",
".",
"'['",
".",
"\\",
"var_export",
"(",
"$",
"key",
",",
"true",
")",
".",
"']'",
";",
"}",
"}",
"$",
"stash",
"=",
"$",
"val",
";",
"$",
"copy",
"[",
"$",
"i",
"]",
"=",
"$",
"refmarker",
";",
"if",
"(",
"$",
"val",
"===",
"$",
"refmarker",
")",
"{",
"$",
"child",
"->",
"reference",
"=",
"true",
";",
"$",
"val",
"=",
"$",
"stash",
";",
"}",
"$",
"rep",
"->",
"contents",
"[",
"]",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"val",
",",
"$",
"child",
")",
";",
"++",
"$",
"i",
";",
"}",
"$",
"this",
"->",
"applyPlugins",
"(",
"$",
"var",
",",
"$",
"array",
",",
"self",
"::",
"TRIGGER_SUCCESS",
")",
";",
"unset",
"(",
"$",
"var",
"[",
"$",
"this",
"->",
"marker",
"]",
")",
";",
"return",
"$",
"array",
";",
"}"
] | Parses an array into a Kint object structure.
@param array $var The input variable
@param BasicObject $o The base object
@return BasicObject | [
"Parses",
"an",
"array",
"into",
"a",
"Kint",
"object",
"structure",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Parser/Parser.php#L328-L411 | train |
kint-php/kint | src/Parser/Parser.php | Parser.parseResource | private function parseResource(&$var, BasicObject $o)
{
$resource = new ResourceObject();
$resource->transplant($o);
$resource->resource_type = \get_resource_type($var);
$this->applyPlugins($var, $resource, self::TRIGGER_SUCCESS);
return $resource;
} | php | private function parseResource(&$var, BasicObject $o)
{
$resource = new ResourceObject();
$resource->transplant($o);
$resource->resource_type = \get_resource_type($var);
$this->applyPlugins($var, $resource, self::TRIGGER_SUCCESS);
return $resource;
} | [
"private",
"function",
"parseResource",
"(",
"&",
"$",
"var",
",",
"BasicObject",
"$",
"o",
")",
"{",
"$",
"resource",
"=",
"new",
"ResourceObject",
"(",
")",
";",
"$",
"resource",
"->",
"transplant",
"(",
"$",
"o",
")",
";",
"$",
"resource",
"->",
"resource_type",
"=",
"\\",
"get_resource_type",
"(",
"$",
"var",
")",
";",
"$",
"this",
"->",
"applyPlugins",
"(",
"$",
"var",
",",
"$",
"resource",
",",
"self",
"::",
"TRIGGER_SUCCESS",
")",
";",
"return",
"$",
"resource",
";",
"}"
] | Parses a resource into a Kint ResourceObject structure.
@param resource $var The input variable
@param BasicObject $o The base object
@return BasicObject | [
"Parses",
"a",
"resource",
"into",
"a",
"Kint",
"ResourceObject",
"structure",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Parser/Parser.php#L534-L543 | train |
kint-php/kint | src/Parser/Parser.php | Parser.parseUnknown | private function parseUnknown(&$var, BasicObject $o)
{
$o->type = 'unknown';
$this->applyPlugins($var, $o, self::TRIGGER_SUCCESS);
return $o;
} | php | private function parseUnknown(&$var, BasicObject $o)
{
$o->type = 'unknown';
$this->applyPlugins($var, $o, self::TRIGGER_SUCCESS);
return $o;
} | [
"private",
"function",
"parseUnknown",
"(",
"&",
"$",
"var",
",",
"BasicObject",
"$",
"o",
")",
"{",
"$",
"o",
"->",
"type",
"=",
"'unknown'",
";",
"$",
"this",
"->",
"applyPlugins",
"(",
"$",
"var",
",",
"$",
"o",
",",
"self",
"::",
"TRIGGER_SUCCESS",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Parses an unknown into a Kint object structure.
@param mixed $var The input variable
@param BasicObject $o The base object
@return BasicObject | [
"Parses",
"an",
"unknown",
"into",
"a",
"Kint",
"object",
"structure",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Parser/Parser.php#L553-L559 | train |
kint-php/kint | src/Parser/Parser.php | Parser.applyPlugins | private function applyPlugins(&$var, BasicObject &$o, $trigger)
{
$break_stash = $this->parse_break;
/** @var bool Psalm bug workaround */
$this->parse_break = false;
$plugins = array();
if (isset($this->plugins[$o->type][$trigger])) {
$plugins = $this->plugins[$o->type][$trigger];
}
foreach ($plugins as $plugin) {
try {
$plugin->parse($var, $o, $trigger);
} catch (Exception $e) {
\trigger_error(
'An exception ('.\get_class($e).') was thrown in '.$e->getFile().' on line '.$e->getLine().' while executing Kint Parser Plugin "'.\get_class($plugin).'". Error message: '.$e->getMessage(),
E_USER_WARNING
);
}
if ($this->parse_break) {
$this->parse_break = $break_stash;
return false;
}
}
$this->parse_break = $break_stash;
return true;
} | php | private function applyPlugins(&$var, BasicObject &$o, $trigger)
{
$break_stash = $this->parse_break;
/** @var bool Psalm bug workaround */
$this->parse_break = false;
$plugins = array();
if (isset($this->plugins[$o->type][$trigger])) {
$plugins = $this->plugins[$o->type][$trigger];
}
foreach ($plugins as $plugin) {
try {
$plugin->parse($var, $o, $trigger);
} catch (Exception $e) {
\trigger_error(
'An exception ('.\get_class($e).') was thrown in '.$e->getFile().' on line '.$e->getLine().' while executing Kint Parser Plugin "'.\get_class($plugin).'". Error message: '.$e->getMessage(),
E_USER_WARNING
);
}
if ($this->parse_break) {
$this->parse_break = $break_stash;
return false;
}
}
$this->parse_break = $break_stash;
return true;
} | [
"private",
"function",
"applyPlugins",
"(",
"&",
"$",
"var",
",",
"BasicObject",
"&",
"$",
"o",
",",
"$",
"trigger",
")",
"{",
"$",
"break_stash",
"=",
"$",
"this",
"->",
"parse_break",
";",
"/** @var bool Psalm bug workaround */",
"$",
"this",
"->",
"parse_break",
"=",
"false",
";",
"$",
"plugins",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"plugins",
"[",
"$",
"o",
"->",
"type",
"]",
"[",
"$",
"trigger",
"]",
")",
")",
"{",
"$",
"plugins",
"=",
"$",
"this",
"->",
"plugins",
"[",
"$",
"o",
"->",
"type",
"]",
"[",
"$",
"trigger",
"]",
";",
"}",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
")",
"{",
"try",
"{",
"$",
"plugin",
"->",
"parse",
"(",
"$",
"var",
",",
"$",
"o",
",",
"$",
"trigger",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"\\",
"trigger_error",
"(",
"'An exception ('",
".",
"\\",
"get_class",
"(",
"$",
"e",
")",
".",
"') was thrown in '",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"' on line '",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"' while executing Kint Parser Plugin \"'",
".",
"\\",
"get_class",
"(",
"$",
"plugin",
")",
".",
"'\". Error message: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"E_USER_WARNING",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"parse_break",
")",
"{",
"$",
"this",
"->",
"parse_break",
"=",
"$",
"break_stash",
";",
"return",
"false",
";",
"}",
"}",
"$",
"this",
"->",
"parse_break",
"=",
"$",
"break_stash",
";",
"return",
"true",
";",
"}"
] | Applies plugins for an object type.
@param mixed $var variable
@param BasicObject $o Kint object parsed so far
@param int $trigger The trigger to check for the plugins
@return bool Continue parsing | [
"Applies",
"plugins",
"for",
"an",
"object",
"type",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Parser/Parser.php#L570-L603 | train |
kint-php/kint | src/Renderer/Rich/Plugin.php | Plugin.renderLockedHeader | public function renderLockedHeader(BasicObject $o, $content)
{
$header = '<dt class="kint-parent kint-locked">';
if (RichRenderer::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) {
$header .= '<span class="kint-access-path-trigger" title="Show access path">⇄</span>';
}
$header .= '<span class="kint-popup-trigger" title="Open in new window">⧉</span><nav></nav>';
if (null !== ($s = $o->getModifiers())) {
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getName())) {
$header .= '<dfn>'.$this->renderer->escape($s).'</dfn> ';
if ($s = $o->getOperator()) {
$header .= $this->renderer->escape($s, 'ASCII').' ';
}
}
if (null !== ($s = $o->getType())) {
$s = $this->renderer->escape($s);
if ($o->reference) {
$s = '&'.$s;
}
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getSize())) {
$header .= '('.$this->renderer->escape($s).') ';
}
$header .= $content;
if (!empty($ap)) {
$header .= '<div class="access-path">'.$this->renderer->escape($ap).'</div>';
}
return $header.'</dt>';
} | php | public function renderLockedHeader(BasicObject $o, $content)
{
$header = '<dt class="kint-parent kint-locked">';
if (RichRenderer::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) {
$header .= '<span class="kint-access-path-trigger" title="Show access path">⇄</span>';
}
$header .= '<span class="kint-popup-trigger" title="Open in new window">⧉</span><nav></nav>';
if (null !== ($s = $o->getModifiers())) {
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getName())) {
$header .= '<dfn>'.$this->renderer->escape($s).'</dfn> ';
if ($s = $o->getOperator()) {
$header .= $this->renderer->escape($s, 'ASCII').' ';
}
}
if (null !== ($s = $o->getType())) {
$s = $this->renderer->escape($s);
if ($o->reference) {
$s = '&'.$s;
}
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getSize())) {
$header .= '('.$this->renderer->escape($s).') ';
}
$header .= $content;
if (!empty($ap)) {
$header .= '<div class="access-path">'.$this->renderer->escape($ap).'</div>';
}
return $header.'</dt>';
} | [
"public",
"function",
"renderLockedHeader",
"(",
"BasicObject",
"$",
"o",
",",
"$",
"content",
")",
"{",
"$",
"header",
"=",
"'<dt class=\"kint-parent kint-locked\">'",
";",
"if",
"(",
"RichRenderer",
"::",
"$",
"access_paths",
"&&",
"$",
"o",
"->",
"depth",
">",
"0",
"&&",
"$",
"ap",
"=",
"$",
"o",
"->",
"getAccessPath",
"(",
")",
")",
"{",
"$",
"header",
".=",
"'<span class=\"kint-access-path-trigger\" title=\"Show access path\">⇄</span>'",
";",
"}",
"$",
"header",
".=",
"'<span class=\"kint-popup-trigger\" title=\"Open in new window\">⧉</span><nav></nav>'",
";",
"if",
"(",
"null",
"!==",
"(",
"$",
"s",
"=",
"$",
"o",
"->",
"getModifiers",
"(",
")",
")",
")",
"{",
"$",
"header",
".=",
"'<var>'",
".",
"$",
"s",
".",
"'</var> '",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"s",
"=",
"$",
"o",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"header",
".=",
"'<dfn>'",
".",
"$",
"this",
"->",
"renderer",
"->",
"escape",
"(",
"$",
"s",
")",
".",
"'</dfn> '",
";",
"if",
"(",
"$",
"s",
"=",
"$",
"o",
"->",
"getOperator",
"(",
")",
")",
"{",
"$",
"header",
".=",
"$",
"this",
"->",
"renderer",
"->",
"escape",
"(",
"$",
"s",
",",
"'ASCII'",
")",
".",
"' '",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"s",
"=",
"$",
"o",
"->",
"getType",
"(",
")",
")",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"renderer",
"->",
"escape",
"(",
"$",
"s",
")",
";",
"if",
"(",
"$",
"o",
"->",
"reference",
")",
"{",
"$",
"s",
"=",
"'&'",
".",
"$",
"s",
";",
"}",
"$",
"header",
".=",
"'<var>'",
".",
"$",
"s",
".",
"'</var> '",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"s",
"=",
"$",
"o",
"->",
"getSize",
"(",
")",
")",
")",
"{",
"$",
"header",
".=",
"'('",
".",
"$",
"this",
"->",
"renderer",
"->",
"escape",
"(",
"$",
"s",
")",
".",
"') '",
";",
"}",
"$",
"header",
".=",
"$",
"content",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"ap",
")",
")",
"{",
"$",
"header",
".=",
"'<div class=\"access-path\">'",
".",
"$",
"this",
"->",
"renderer",
"->",
"escape",
"(",
"$",
"ap",
")",
".",
"'</div>'",
";",
"}",
"return",
"$",
"header",
".",
"'</dt>'",
";",
"}"
] | Renders a locked header.
@param BasicObject $o
@param string $content | [
"Renders",
"a",
"locked",
"header",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Renderer/Rich/Plugin.php#L46-L89 | train |
kint-php/kint | src/Object/Representation/ColorRepresentation.php | ColorRepresentation.hslToRgb | public static function hslToRgb($h, $s, $l)
{
if (\min($h, $s, $l) < 0) {
throw new InvalidArgumentException('The parameters for hslToRgb should be no less than 0');
}
if ($h > 360 || \max($s, $l) > 100) {
throw new InvalidArgumentException('The parameters for hslToRgb should be no more than 360, 100, and 100 respectively');
}
$h /= 360;
$s /= 100;
$l /= 100;
$m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s;
$m1 = $l * 2 - $m2;
return array(
(int) \round(self::hueToRgb($m1, $m2, $h + 1 / 3) * 0xFF),
(int) \round(self::hueToRgb($m1, $m2, $h) * 0xFF),
(int) \round(self::hueToRgb($m1, $m2, $h - 1 / 3) * 0xFF),
);
} | php | public static function hslToRgb($h, $s, $l)
{
if (\min($h, $s, $l) < 0) {
throw new InvalidArgumentException('The parameters for hslToRgb should be no less than 0');
}
if ($h > 360 || \max($s, $l) > 100) {
throw new InvalidArgumentException('The parameters for hslToRgb should be no more than 360, 100, and 100 respectively');
}
$h /= 360;
$s /= 100;
$l /= 100;
$m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s;
$m1 = $l * 2 - $m2;
return array(
(int) \round(self::hueToRgb($m1, $m2, $h + 1 / 3) * 0xFF),
(int) \round(self::hueToRgb($m1, $m2, $h) * 0xFF),
(int) \round(self::hueToRgb($m1, $m2, $h - 1 / 3) * 0xFF),
);
} | [
"public",
"static",
"function",
"hslToRgb",
"(",
"$",
"h",
",",
"$",
"s",
",",
"$",
"l",
")",
"{",
"if",
"(",
"\\",
"min",
"(",
"$",
"h",
",",
"$",
"s",
",",
"$",
"l",
")",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The parameters for hslToRgb should be no less than 0'",
")",
";",
"}",
"if",
"(",
"$",
"h",
">",
"360",
"||",
"\\",
"max",
"(",
"$",
"s",
",",
"$",
"l",
")",
">",
"100",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The parameters for hslToRgb should be no more than 360, 100, and 100 respectively'",
")",
";",
"}",
"$",
"h",
"/=",
"360",
";",
"$",
"s",
"/=",
"100",
";",
"$",
"l",
"/=",
"100",
";",
"$",
"m2",
"=",
"(",
"$",
"l",
"<=",
"0.5",
")",
"?",
"$",
"l",
"*",
"(",
"$",
"s",
"+",
"1",
")",
":",
"$",
"l",
"+",
"$",
"s",
"-",
"$",
"l",
"*",
"$",
"s",
";",
"$",
"m1",
"=",
"$",
"l",
"*",
"2",
"-",
"$",
"m2",
";",
"return",
"array",
"(",
"(",
"int",
")",
"\\",
"round",
"(",
"self",
"::",
"hueToRgb",
"(",
"$",
"m1",
",",
"$",
"m2",
",",
"$",
"h",
"+",
"1",
"/",
"3",
")",
"*",
"0xFF",
")",
",",
"(",
"int",
")",
"\\",
"round",
"(",
"self",
"::",
"hueToRgb",
"(",
"$",
"m1",
",",
"$",
"m2",
",",
"$",
"h",
")",
"*",
"0xFF",
")",
",",
"(",
"int",
")",
"\\",
"round",
"(",
"self",
"::",
"hueToRgb",
"(",
"$",
"m1",
",",
"$",
"m2",
",",
"$",
"h",
"-",
"1",
"/",
"3",
")",
"*",
"0xFF",
")",
",",
")",
";",
"}"
] | Turns HSL color to RGB. Black magic.
@param float $h Hue
@param float $s Saturation
@param float $l Lightness
@return int[] RGB array | [
"Turns",
"HSL",
"color",
"to",
"RGB",
".",
"Black",
"magic",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Object/Representation/ColorRepresentation.php#L472-L494 | train |
kint-php/kint | src/Object/Representation/ColorRepresentation.php | ColorRepresentation.rgbToHsl | public static function rgbToHsl($red, $green, $blue)
{
if (\min($red, $green, $blue) < 0) {
throw new InvalidArgumentException('The parameters for rgbToHsl should be no less than 0');
}
if (\max($red, $green, $blue) > 0xFF) {
throw new InvalidArgumentException('The parameters for rgbToHsl should be no more than 255');
}
$clrMin = \min($red, $green, $blue);
$clrMax = \max($red, $green, $blue);
$deltaMax = $clrMax - $clrMin;
$L = ($clrMax + $clrMin) / 510;
if (0 == $deltaMax) {
$H = 0;
$S = 0;
} else {
if (0.5 > $L) {
$S = $deltaMax / ($clrMax + $clrMin);
} else {
$S = $deltaMax / (510 - $clrMax - $clrMin);
}
if ($clrMax === $red) {
$H = ($green - $blue) / (6.0 * $deltaMax);
if (0 > $H) {
$H += 1.0;
}
} elseif ($clrMax === $green) {
$H = 1 / 3 + ($blue - $red) / (6.0 * $deltaMax);
} else {
$H = 2 / 3 + ($red - $green) / (6.0 * $deltaMax);
}
}
return array(
(float) ($H * 360 % 360),
(float) ($S * 100),
(float) ($L * 100),
);
} | php | public static function rgbToHsl($red, $green, $blue)
{
if (\min($red, $green, $blue) < 0) {
throw new InvalidArgumentException('The parameters for rgbToHsl should be no less than 0');
}
if (\max($red, $green, $blue) > 0xFF) {
throw new InvalidArgumentException('The parameters for rgbToHsl should be no more than 255');
}
$clrMin = \min($red, $green, $blue);
$clrMax = \max($red, $green, $blue);
$deltaMax = $clrMax - $clrMin;
$L = ($clrMax + $clrMin) / 510;
if (0 == $deltaMax) {
$H = 0;
$S = 0;
} else {
if (0.5 > $L) {
$S = $deltaMax / ($clrMax + $clrMin);
} else {
$S = $deltaMax / (510 - $clrMax - $clrMin);
}
if ($clrMax === $red) {
$H = ($green - $blue) / (6.0 * $deltaMax);
if (0 > $H) {
$H += 1.0;
}
} elseif ($clrMax === $green) {
$H = 1 / 3 + ($blue - $red) / (6.0 * $deltaMax);
} else {
$H = 2 / 3 + ($red - $green) / (6.0 * $deltaMax);
}
}
return array(
(float) ($H * 360 % 360),
(float) ($S * 100),
(float) ($L * 100),
);
} | [
"public",
"static",
"function",
"rgbToHsl",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"if",
"(",
"\\",
"min",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The parameters for rgbToHsl should be no less than 0'",
")",
";",
"}",
"if",
"(",
"\\",
"max",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
">",
"0xFF",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The parameters for rgbToHsl should be no more than 255'",
")",
";",
"}",
"$",
"clrMin",
"=",
"\\",
"min",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
";",
"$",
"clrMax",
"=",
"\\",
"max",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
";",
"$",
"deltaMax",
"=",
"$",
"clrMax",
"-",
"$",
"clrMin",
";",
"$",
"L",
"=",
"(",
"$",
"clrMax",
"+",
"$",
"clrMin",
")",
"/",
"510",
";",
"if",
"(",
"0",
"==",
"$",
"deltaMax",
")",
"{",
"$",
"H",
"=",
"0",
";",
"$",
"S",
"=",
"0",
";",
"}",
"else",
"{",
"if",
"(",
"0.5",
">",
"$",
"L",
")",
"{",
"$",
"S",
"=",
"$",
"deltaMax",
"/",
"(",
"$",
"clrMax",
"+",
"$",
"clrMin",
")",
";",
"}",
"else",
"{",
"$",
"S",
"=",
"$",
"deltaMax",
"/",
"(",
"510",
"-",
"$",
"clrMax",
"-",
"$",
"clrMin",
")",
";",
"}",
"if",
"(",
"$",
"clrMax",
"===",
"$",
"red",
")",
"{",
"$",
"H",
"=",
"(",
"$",
"green",
"-",
"$",
"blue",
")",
"/",
"(",
"6.0",
"*",
"$",
"deltaMax",
")",
";",
"if",
"(",
"0",
">",
"$",
"H",
")",
"{",
"$",
"H",
"+=",
"1.0",
";",
"}",
"}",
"elseif",
"(",
"$",
"clrMax",
"===",
"$",
"green",
")",
"{",
"$",
"H",
"=",
"1",
"/",
"3",
"+",
"(",
"$",
"blue",
"-",
"$",
"red",
")",
"/",
"(",
"6.0",
"*",
"$",
"deltaMax",
")",
";",
"}",
"else",
"{",
"$",
"H",
"=",
"2",
"/",
"3",
"+",
"(",
"$",
"red",
"-",
"$",
"green",
")",
"/",
"(",
"6.0",
"*",
"$",
"deltaMax",
")",
";",
"}",
"}",
"return",
"array",
"(",
"(",
"float",
")",
"(",
"$",
"H",
"*",
"360",
"%",
"360",
")",
",",
"(",
"float",
")",
"(",
"$",
"S",
"*",
"100",
")",
",",
"(",
"float",
")",
"(",
"$",
"L",
"*",
"100",
")",
",",
")",
";",
"}"
] | Converts RGB to HSL. Color inversion of previous black magic is white magic?
@param float|int $red Red
@param float|int $green Green
@param float|int $blue Blue
@return float[] HSL array | [
"Converts",
"RGB",
"to",
"HSL",
".",
"Color",
"inversion",
"of",
"previous",
"black",
"magic",
"is",
"white",
"magic?"
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Object/Representation/ColorRepresentation.php#L505-L549 | train |
kint-php/kint | src/Object/Representation/ColorRepresentation.php | ColorRepresentation.hueToRgb | private static function hueToRgb($m1, $m2, $hue)
{
$hue = ($hue < 0) ? $hue + 1 : (($hue > 1) ? $hue - 1 : $hue);
if ($hue * 6 < 1) {
return $m1 + ($m2 - $m1) * $hue * 6;
}
if ($hue * 2 < 1) {
return $m2;
}
if ($hue * 3 < 2) {
return $m1 + ($m2 - $m1) * (2 / 3 - $hue) * 6;
}
return $m1;
} | php | private static function hueToRgb($m1, $m2, $hue)
{
$hue = ($hue < 0) ? $hue + 1 : (($hue > 1) ? $hue - 1 : $hue);
if ($hue * 6 < 1) {
return $m1 + ($m2 - $m1) * $hue * 6;
}
if ($hue * 2 < 1) {
return $m2;
}
if ($hue * 3 < 2) {
return $m1 + ($m2 - $m1) * (2 / 3 - $hue) * 6;
}
return $m1;
} | [
"private",
"static",
"function",
"hueToRgb",
"(",
"$",
"m1",
",",
"$",
"m2",
",",
"$",
"hue",
")",
"{",
"$",
"hue",
"=",
"(",
"$",
"hue",
"<",
"0",
")",
"?",
"$",
"hue",
"+",
"1",
":",
"(",
"(",
"$",
"hue",
">",
"1",
")",
"?",
"$",
"hue",
"-",
"1",
":",
"$",
"hue",
")",
";",
"if",
"(",
"$",
"hue",
"*",
"6",
"<",
"1",
")",
"{",
"return",
"$",
"m1",
"+",
"(",
"$",
"m2",
"-",
"$",
"m1",
")",
"*",
"$",
"hue",
"*",
"6",
";",
"}",
"if",
"(",
"$",
"hue",
"*",
"2",
"<",
"1",
")",
"{",
"return",
"$",
"m2",
";",
"}",
"if",
"(",
"$",
"hue",
"*",
"3",
"<",
"2",
")",
"{",
"return",
"$",
"m1",
"+",
"(",
"$",
"m2",
"-",
"$",
"m1",
")",
"*",
"(",
"2",
"/",
"3",
"-",
"$",
"hue",
")",
"*",
"6",
";",
"}",
"return",
"$",
"m1",
";",
"}"
] | Helper function for hslToRgb. Even blacker magic.
@param float $m1
@param float $m2
@param float $hue
@return float Color value | [
"Helper",
"function",
"for",
"hslToRgb",
".",
"Even",
"blacker",
"magic",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Object/Representation/ColorRepresentation.php#L561-L575 | train |
kint-php/kint | src/Object/BasicObject.php | BasicObject.blank | public static function blank($name = null, $access_path = null)
{
$o = new self();
$o->name = $name;
$o->access_path = $access_path;
return $o;
} | php | public static function blank($name = null, $access_path = null)
{
$o = new self();
$o->name = $name;
$o->access_path = $access_path;
return $o;
} | [
"public",
"static",
"function",
"blank",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"access_path",
"=",
"null",
")",
"{",
"$",
"o",
"=",
"new",
"self",
"(",
")",
";",
"$",
"o",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"o",
"->",
"access_path",
"=",
"$",
"access_path",
";",
"return",
"$",
"o",
";",
"}"
] | Creates a new basic object with a name and access path.
@param null|string $name
@param null|string $access_path
@return \Kint\Object\BasicObject | [
"Creates",
"a",
"new",
"basic",
"object",
"with",
"a",
"name",
"and",
"access",
"path",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Object/BasicObject.php#L217-L224 | train |
kint-php/kint | src/Object/Representation/DocstringRepresentation.php | DocstringRepresentation.getDocstringWithoutComments | public function getDocstringWithoutComments()
{
if (!$this->contents) {
return null;
}
$string = \substr($this->contents, 3, -2);
$string = \preg_replace('/^\\s*\\*\\s*?(\\S|$)/m', '\\1', $string);
return \trim($string);
} | php | public function getDocstringWithoutComments()
{
if (!$this->contents) {
return null;
}
$string = \substr($this->contents, 3, -2);
$string = \preg_replace('/^\\s*\\*\\s*?(\\S|$)/m', '\\1', $string);
return \trim($string);
} | [
"public",
"function",
"getDocstringWithoutComments",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"contents",
")",
"{",
"return",
"null",
";",
"}",
"$",
"string",
"=",
"\\",
"substr",
"(",
"$",
"this",
"->",
"contents",
",",
"3",
",",
"-",
"2",
")",
";",
"$",
"string",
"=",
"\\",
"preg_replace",
"(",
"'/^\\\\s*\\\\*\\\\s*?(\\\\S|$)/m'",
",",
"'\\\\1'",
",",
"$",
"string",
")",
";",
"return",
"\\",
"trim",
"(",
"$",
"string",
")",
";",
"}"
] | Returns the representation's docstring without surrounding comments.
Note that this will not work flawlessly.
On comments with whitespace after the stars the lines will begin with
whitespace, since we can't accurately guess how much of an indentation
is required.
And on lines without stars on the left this may eat bullet points.
Long story short: If you want the docstring read the contents. If you
absolutely must have it without comments (ie renderValueShort) this will
probably do.
@return null|string Docstring with comments stripped | [
"Returns",
"the",
"representation",
"s",
"docstring",
"without",
"surrounding",
"comments",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Object/Representation/DocstringRepresentation.php#L62-L72 | train |
kint-php/kint | src/Parser/XmlPlugin.php | XmlPlugin.xmlToDOMDocument | protected static function xmlToDOMDocument($var, $parent_path)
{
// There's no way to check validity in DOMDocument without making errors. For shame!
if (!self::xmlToSimpleXML($var, $parent_path)) {
return null;
}
$xml = new DOMDocument();
$xml->loadXML($var);
$xml = $xml->firstChild;
if (null === $parent_path) {
$access_path = null;
} else {
$access_path = '@\\DOMDocument::loadXML('.$parent_path.')->firstChild';
}
$name = $xml->nodeName;
return array($xml, $access_path, $name);
} | php | protected static function xmlToDOMDocument($var, $parent_path)
{
// There's no way to check validity in DOMDocument without making errors. For shame!
if (!self::xmlToSimpleXML($var, $parent_path)) {
return null;
}
$xml = new DOMDocument();
$xml->loadXML($var);
$xml = $xml->firstChild;
if (null === $parent_path) {
$access_path = null;
} else {
$access_path = '@\\DOMDocument::loadXML('.$parent_path.')->firstChild';
}
$name = $xml->nodeName;
return array($xml, $access_path, $name);
} | [
"protected",
"static",
"function",
"xmlToDOMDocument",
"(",
"$",
"var",
",",
"$",
"parent_path",
")",
"{",
"// There's no way to check validity in DOMDocument without making errors. For shame!",
"if",
"(",
"!",
"self",
"::",
"xmlToSimpleXML",
"(",
"$",
"var",
",",
"$",
"parent_path",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"xml",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"xml",
"->",
"loadXML",
"(",
"$",
"var",
")",
";",
"$",
"xml",
"=",
"$",
"xml",
"->",
"firstChild",
";",
"if",
"(",
"null",
"===",
"$",
"parent_path",
")",
"{",
"$",
"access_path",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"access_path",
"=",
"'@\\\\DOMDocument::loadXML('",
".",
"$",
"parent_path",
".",
"')->firstChild'",
";",
"}",
"$",
"name",
"=",
"$",
"xml",
"->",
"nodeName",
";",
"return",
"array",
"(",
"$",
"xml",
",",
"$",
"access_path",
",",
"$",
"name",
")",
";",
"}"
] | Get the DOMDocument info.
The documentation of DOMDocument::loadXML() states that while you can
call it statically, it will give an E_STRICT warning. On my system it
actually gives an E_DEPRECATED warning, but it works so we'll just add
an error-silencing '@' to the access path.
If it errors loading then we wouldn't have gotten this far in the first place.
@param string $var The XML string
@param null|string $parent_path The path to the parent, in this case the XML string
@return null|array The root element DOMNode, the access path, and the root element name | [
"Get",
"the",
"DOMDocument",
"info",
"."
] | c332db9529fdce74ae6a347f97a1e7395e76ced8 | https://github.com/kint-php/kint/blob/c332db9529fdce74ae6a347f97a1e7395e76ced8/src/Parser/XmlPlugin.php#L129-L149 | train |
eyecatchup/SEOstats | SEOstats/Services/Mozscape.php | Mozscape.getPageAuthority | public static function getPageAuthority($url = false)
{
$data = static::getCols('34359738368', $url);
return (parent::noDataDefaultValue() == $data) ? $data :
$data['upa'];
} | php | public static function getPageAuthority($url = false)
{
$data = static::getCols('34359738368', $url);
return (parent::noDataDefaultValue() == $data) ? $data :
$data['upa'];
} | [
"public",
"static",
"function",
"getPageAuthority",
"(",
"$",
"url",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"static",
"::",
"getCols",
"(",
"'34359738368'",
",",
"$",
"url",
")",
";",
"return",
"(",
"parent",
"::",
"noDataDefaultValue",
"(",
")",
"==",
"$",
"data",
")",
"?",
"$",
"data",
":",
"$",
"data",
"[",
"'upa'",
"]",
";",
"}"
] | of the URL to rank well in search engine results. | [
"of",
"the",
"URL",
"to",
"rank",
"well",
"in",
"search",
"engine",
"results",
"."
] | bd3117f3ee10d6bf3c3cadd0461c15b91b15428b | https://github.com/eyecatchup/SEOstats/blob/bd3117f3ee10d6bf3c3cadd0461c15b91b15428b/SEOstats/Services/Mozscape.php#L23-L28 | train |
eyecatchup/SEOstats | SEOstats/Services/Mozscape.php | Mozscape.getDomainAuthority | public static function getDomainAuthority($url = false)
{
$data = static::getCols('68719476736', Helper\Url::parseHost($url));
return (parent::noDataDefaultValue() == $data) ? $data :
$data['pda'];
} | php | public static function getDomainAuthority($url = false)
{
$data = static::getCols('68719476736', Helper\Url::parseHost($url));
return (parent::noDataDefaultValue() == $data) ? $data :
$data['pda'];
} | [
"public",
"static",
"function",
"getDomainAuthority",
"(",
"$",
"url",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"static",
"::",
"getCols",
"(",
"'68719476736'",
",",
"Helper",
"\\",
"Url",
"::",
"parseHost",
"(",
"$",
"url",
")",
")",
";",
"return",
"(",
"parent",
"::",
"noDataDefaultValue",
"(",
")",
"==",
"$",
"data",
")",
"?",
"$",
"data",
":",
"$",
"data",
"[",
"'pda'",
"]",
";",
"}"
] | of the domain of the URL to rank well in search engine results. | [
"of",
"the",
"domain",
"of",
"the",
"URL",
"to",
"rank",
"well",
"in",
"search",
"engine",
"results",
"."
] | bd3117f3ee10d6bf3c3cadd0461c15b91b15428b | https://github.com/eyecatchup/SEOstats/blob/bd3117f3ee10d6bf3c3cadd0461c15b91b15428b/SEOstats/Services/Mozscape.php#L32-L37 | train |
eyecatchup/SEOstats | SEOstats/Services/Mozscape.php | Mozscape.getMozRank | public static function getMozRank($url = false)
{
$data = static::getCols('16384', $url);
return (parent::noDataDefaultValue() == $data) ? $data :
$data['umrp'];
} | php | public static function getMozRank($url = false)
{
$data = static::getCols('16384', $url);
return (parent::noDataDefaultValue() == $data) ? $data :
$data['umrp'];
} | [
"public",
"static",
"function",
"getMozRank",
"(",
"$",
"url",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"static",
"::",
"getCols",
"(",
"'16384'",
",",
"$",
"url",
")",
";",
"return",
"(",
"parent",
"::",
"noDataDefaultValue",
"(",
")",
"==",
"$",
"data",
")",
"?",
"$",
"data",
":",
"$",
"data",
"[",
"'umrp'",
"]",
";",
"}"
] | The normalized 10-point MozRank score of the URL. | [
"The",
"normalized",
"10",
"-",
"point",
"MozRank",
"score",
"of",
"the",
"URL",
"."
] | bd3117f3ee10d6bf3c3cadd0461c15b91b15428b | https://github.com/eyecatchup/SEOstats/blob/bd3117f3ee10d6bf3c3cadd0461c15b91b15428b/SEOstats/Services/Mozscape.php#L57-L62 | train |
eyecatchup/SEOstats | SEOstats/Services/Mozscape.php | Mozscape.getMozRankRaw | public static function getMozRankRaw($url = false)
{
$data = static::getCols('16384', $url);
return (parent::noDataDefaultValue() == $data) ? $data :
number_format($data['umrr'], 16);
} | php | public static function getMozRankRaw($url = false)
{
$data = static::getCols('16384', $url);
return (parent::noDataDefaultValue() == $data) ? $data :
number_format($data['umrr'], 16);
} | [
"public",
"static",
"function",
"getMozRankRaw",
"(",
"$",
"url",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"static",
"::",
"getCols",
"(",
"'16384'",
",",
"$",
"url",
")",
";",
"return",
"(",
"parent",
"::",
"noDataDefaultValue",
"(",
")",
"==",
"$",
"data",
")",
"?",
"$",
"data",
":",
"number_format",
"(",
"$",
"data",
"[",
"'umrr'",
"]",
",",
"16",
")",
";",
"}"
] | The raw MozRank score of the URL. | [
"The",
"raw",
"MozRank",
"score",
"of",
"the",
"URL",
"."
] | bd3117f3ee10d6bf3c3cadd0461c15b91b15428b | https://github.com/eyecatchup/SEOstats/blob/bd3117f3ee10d6bf3c3cadd0461c15b91b15428b/SEOstats/Services/Mozscape.php#L65-L70 | train |
eyecatchup/SEOstats | SEOstats/SEOstats.php | SEOstats.getUrl | public static function getUrl($url = false)
{
$url = false !== $url ? $url : self::$_url;
return $url;
} | php | public static function getUrl($url = false)
{
$url = false !== $url ? $url : self::$_url;
return $url;
} | [
"public",
"static",
"function",
"getUrl",
"(",
"$",
"url",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"false",
"!==",
"$",
"url",
"?",
"$",
"url",
":",
"self",
"::",
"$",
"_url",
";",
"return",
"$",
"url",
";",
"}"
] | Ensure the URL is set, return default otherwise
@return string | [
"Ensure",
"the",
"URL",
"is",
"set",
"return",
"default",
"otherwise"
] | bd3117f3ee10d6bf3c3cadd0461c15b91b15428b | https://github.com/eyecatchup/SEOstats/blob/bd3117f3ee10d6bf3c3cadd0461c15b91b15428b/SEOstats/SEOstats.php#L149-L153 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.