repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 39
1.84M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Compiler/Linker/Linker.php | Linker.getTypeWithClassAsContext | protected function getTypeWithClassAsContext(string $fqsen, DescriptorAbstract $container): string
{
if (!$container instanceof ClassDescriptor
&& !$container instanceof InterfaceDescriptor
&& !$container instanceof TraitDescriptor
) {
return $fqsen;
}
$containerFqsen = $container->getFullyQualifiedStructuralElementName();
return str_replace(self::CONTEXT_MARKER . '::', $containerFqsen . '::', $fqsen);
} | php | protected function getTypeWithClassAsContext(string $fqsen, DescriptorAbstract $container): string
{
if (!$container instanceof ClassDescriptor
&& !$container instanceof InterfaceDescriptor
&& !$container instanceof TraitDescriptor
) {
return $fqsen;
}
$containerFqsen = $container->getFullyQualifiedStructuralElementName();
return str_replace(self::CONTEXT_MARKER . '::', $containerFqsen . '::', $fqsen);
} | [
"protected",
"function",
"getTypeWithClassAsContext",
"(",
"string",
"$",
"fqsen",
",",
"DescriptorAbstract",
"$",
"container",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"container",
"instanceof",
"ClassDescriptor",
"&&",
"!",
"$",
"container",
"instanceof",
"InterfaceDescriptor",
"&&",
"!",
"$",
"container",
"instanceof",
"TraitDescriptor",
")",
"{",
"return",
"$",
"fqsen",
";",
"}",
"$",
"containerFqsen",
"=",
"$",
"container",
"->",
"getFullyQualifiedStructuralElementName",
"(",
")",
";",
"return",
"str_replace",
"(",
"self",
"::",
"CONTEXT_MARKER",
".",
"'::'",
",",
"$",
"containerFqsen",
".",
"'::'",
",",
"$",
"fqsen",
")",
";",
"}"
] | Normalizes the given FQSEN as if the context marker represents a class/interface/trait as parent. | [
"Normalizes",
"the",
"given",
"FQSEN",
"as",
"if",
"the",
"context",
"marker",
"represents",
"a",
"class",
"/",
"interface",
"/",
"trait",
"as",
"parent",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Compiler/Linker/Linker.php#L297-L309 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Compiler/Linker/Linker.php | Linker.getTypeWithNamespaceAsContext | protected function getTypeWithNamespaceAsContext(string $fqsen, DescriptorAbstract $container): string
{
$namespace = $container instanceof NamespaceDescriptor ? $container : $container->getNamespace();
$fqnn = $namespace instanceof NamespaceDescriptor
? $namespace->getFullyQualifiedStructuralElementName()
: $namespace;
return str_replace(self::CONTEXT_MARKER . '::', $fqnn . '\\', $fqsen);
} | php | protected function getTypeWithNamespaceAsContext(string $fqsen, DescriptorAbstract $container): string
{
$namespace = $container instanceof NamespaceDescriptor ? $container : $container->getNamespace();
$fqnn = $namespace instanceof NamespaceDescriptor
? $namespace->getFullyQualifiedStructuralElementName()
: $namespace;
return str_replace(self::CONTEXT_MARKER . '::', $fqnn . '\\', $fqsen);
} | [
"protected",
"function",
"getTypeWithNamespaceAsContext",
"(",
"string",
"$",
"fqsen",
",",
"DescriptorAbstract",
"$",
"container",
")",
":",
"string",
"{",
"$",
"namespace",
"=",
"$",
"container",
"instanceof",
"NamespaceDescriptor",
"?",
"$",
"container",
":",
"$",
"container",
"->",
"getNamespace",
"(",
")",
";",
"$",
"fqnn",
"=",
"$",
"namespace",
"instanceof",
"NamespaceDescriptor",
"?",
"$",
"namespace",
"->",
"getFullyQualifiedStructuralElementName",
"(",
")",
":",
"$",
"namespace",
";",
"return",
"str_replace",
"(",
"self",
"::",
"CONTEXT_MARKER",
".",
"'::'",
",",
"$",
"fqnn",
".",
"'\\\\'",
",",
"$",
"fqsen",
")",
";",
"}"
] | Normalizes the given FQSEN as if the context marker represents a class/interface/trait as parent. | [
"Normalizes",
"the",
"given",
"FQSEN",
"as",
"if",
"the",
"context",
"marker",
"represents",
"a",
"class",
"/",
"interface",
"/",
"trait",
"as",
"parent",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Compiler/Linker/Linker.php#L314-L322 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Builder/Reflector/Tags/AuthorAssembler.php | AuthorAssembler.create | public function create($data)
{
$descriptor = new AuthorDescriptor($data->getName());
$descriptor->setDescription((string) $data);
return $descriptor;
} | php | public function create($data)
{
$descriptor = new AuthorDescriptor($data->getName());
$descriptor->setDescription((string) $data);
return $descriptor;
} | [
"public",
"function",
"create",
"(",
"$",
"data",
")",
"{",
"$",
"descriptor",
"=",
"new",
"AuthorDescriptor",
"(",
"$",
"data",
"->",
"getName",
"(",
")",
")",
";",
"$",
"descriptor",
"->",
"setDescription",
"(",
"(",
"string",
")",
"$",
"data",
")",
";",
"return",
"$",
"descriptor",
";",
"}"
] | Creates a new Descriptor from the given Reflector.
@param Author $data
@return AuthorDescriptor | [
"Creates",
"a",
"new",
"Descriptor",
"from",
"the",
"given",
"Reflector",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/AuthorAssembler.php#L37-L43 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Builder/Reflector/PropertyAssembler.php | PropertyAssembler.create | public function create($data)
{
$propertyDescriptor = new PropertyDescriptor();
$propertyDescriptor->setNamespace(substr((string) $data->getFqsen(), 0, -strlen($data->getName()) - 3));
$propertyDescriptor->setFullyQualifiedStructuralElementName($data->getFqsen());
$propertyDescriptor->setName($data->getName());
$propertyDescriptor->setVisibility((string) $data->getVisibility() ?: 'public');
$propertyDescriptor->setStatic($data->isStatic());
$propertyDescriptor->setDefault($data->getDefault());
$this->assembleDocBlock($data->getDocBlock(), $propertyDescriptor);
$propertyDescriptor->setLine($data->getLocation()->getLineNumber());
return $propertyDescriptor;
} | php | public function create($data)
{
$propertyDescriptor = new PropertyDescriptor();
$propertyDescriptor->setNamespace(substr((string) $data->getFqsen(), 0, -strlen($data->getName()) - 3));
$propertyDescriptor->setFullyQualifiedStructuralElementName($data->getFqsen());
$propertyDescriptor->setName($data->getName());
$propertyDescriptor->setVisibility((string) $data->getVisibility() ?: 'public');
$propertyDescriptor->setStatic($data->isStatic());
$propertyDescriptor->setDefault($data->getDefault());
$this->assembleDocBlock($data->getDocBlock(), $propertyDescriptor);
$propertyDescriptor->setLine($data->getLocation()->getLineNumber());
return $propertyDescriptor;
} | [
"public",
"function",
"create",
"(",
"$",
"data",
")",
"{",
"$",
"propertyDescriptor",
"=",
"new",
"PropertyDescriptor",
"(",
")",
";",
"$",
"propertyDescriptor",
"->",
"setNamespace",
"(",
"substr",
"(",
"(",
"string",
")",
"$",
"data",
"->",
"getFqsen",
"(",
")",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"data",
"->",
"getName",
"(",
")",
")",
"-",
"3",
")",
")",
";",
"$",
"propertyDescriptor",
"->",
"setFullyQualifiedStructuralElementName",
"(",
"$",
"data",
"->",
"getFqsen",
"(",
")",
")",
";",
"$",
"propertyDescriptor",
"->",
"setName",
"(",
"$",
"data",
"->",
"getName",
"(",
")",
")",
";",
"$",
"propertyDescriptor",
"->",
"setVisibility",
"(",
"(",
"string",
")",
"$",
"data",
"->",
"getVisibility",
"(",
")",
"?",
":",
"'public'",
")",
";",
"$",
"propertyDescriptor",
"->",
"setStatic",
"(",
"$",
"data",
"->",
"isStatic",
"(",
")",
")",
";",
"$",
"propertyDescriptor",
"->",
"setDefault",
"(",
"$",
"data",
"->",
"getDefault",
"(",
")",
")",
";",
"$",
"this",
"->",
"assembleDocBlock",
"(",
"$",
"data",
"->",
"getDocBlock",
"(",
")",
",",
"$",
"propertyDescriptor",
")",
";",
"$",
"propertyDescriptor",
"->",
"setLine",
"(",
"$",
"data",
"->",
"getLocation",
"(",
")",
"->",
"getLineNumber",
"(",
")",
")",
";",
"return",
"$",
"propertyDescriptor",
";",
"}"
] | Creates a Descriptor from the provided data.
@param Property $data
@return PropertyDescriptor | [
"Creates",
"a",
"Descriptor",
"from",
"the",
"provided",
"data",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Builder/Reflector/PropertyAssembler.php#L33-L47 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Filter/StripInternal.php | StripInternal.filter | public function filter($value)
{
$isInternalAllowed = $this->builder->isVisibilityAllowed(Settings::VISIBILITY_INTERNAL);
if ($isInternalAllowed) {
$value->setDescription(preg_replace('/\{@internal\s(.+?)\}\}/', '$1', $value->getDescription()));
return $value;
}
// remove inline @internal tags
$value->setDescription(preg_replace('/\{@internal\s(.+?)\}\}/', '', $value->getDescription()));
// if internal elements are not allowed; filter this element
if ($value->getTags()->get('internal')) {
return null;
}
return $value;
} | php | public function filter($value)
{
$isInternalAllowed = $this->builder->isVisibilityAllowed(Settings::VISIBILITY_INTERNAL);
if ($isInternalAllowed) {
$value->setDescription(preg_replace('/\{@internal\s(.+?)\}\}/', '$1', $value->getDescription()));
return $value;
}
$value->setDescription(preg_replace('/\{@internal\s(.+?)\}\}/', '', $value->getDescription()));
if ($value->getTags()->get('internal')) {
return null;
}
return $value;
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"$",
"isInternalAllowed",
"=",
"$",
"this",
"->",
"builder",
"->",
"isVisibilityAllowed",
"(",
"Settings",
"::",
"VISIBILITY_INTERNAL",
")",
";",
"if",
"(",
"$",
"isInternalAllowed",
")",
"{",
"$",
"value",
"->",
"setDescription",
"(",
"preg_replace",
"(",
"'/\\{@internal\\s(.+?)\\}\\}/'",
",",
"'$1'",
",",
"$",
"value",
"->",
"getDescription",
"(",
")",
")",
")",
";",
"return",
"$",
"value",
";",
"}",
"// remove inline @internal tags",
"$",
"value",
"->",
"setDescription",
"(",
"preg_replace",
"(",
"'/\\{@internal\\s(.+?)\\}\\}/'",
",",
"''",
",",
"$",
"value",
"->",
"getDescription",
"(",
")",
")",
")",
";",
"// if internal elements are not allowed; filter this element",
"if",
"(",
"$",
"value",
"->",
"getTags",
"(",
")",
"->",
"get",
"(",
"'internal'",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | If the ProjectDescriptor's settings allow internal tags then return the Descriptor, otherwise null to filter it.
@param DescriptorAbstract $value
@return DescriptorAbstract|null | [
"If",
"the",
"ProjectDescriptor",
"s",
"settings",
"allow",
"internal",
"tags",
"then",
"return",
"the",
"Descriptor",
"otherwise",
"null",
"to",
"filter",
"it",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Filter/StripInternal.php#L54-L72 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/Visitors/Creator.php | Creator.getFilename | public function getFilename()
{
/** @var BaseConverter $converter */
$converter = $this->getDocument()->getConverter();
return $converter->getDestinationFilenameRelativeToProjectRoot($this->getDocument()->getFile());
} | php | public function getFilename()
{
$converter = $this->getDocument()->getConverter();
return $converter->getDestinationFilenameRelativeToProjectRoot($this->getDocument()->getFile());
} | [
"public",
"function",
"getFilename",
"(",
")",
"{",
"/** @var BaseConverter $converter */",
"$",
"converter",
"=",
"$",
"this",
"->",
"getDocument",
"(",
")",
"->",
"getConverter",
"(",
")",
";",
"return",
"$",
"converter",
"->",
"getDestinationFilenameRelativeToProjectRoot",
"(",
"$",
"this",
"->",
"getDocument",
"(",
")",
"->",
"getFile",
"(",
")",
")",
";",
"}"
] | Returns the filename for this visitor.
@return string | [
"Returns",
"the",
"filename",
"for",
"this",
"visitor",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/Visitors/Creator.php#L45-L50 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/Visitors/Creator.php | Creator.getFilenameWithoutExtension | public function getFilenameWithoutExtension()
{
$filename = $this->getDocument()->getFile()->getFilename();
return substr($filename, 0, strrpos($filename, '.'));
} | php | public function getFilenameWithoutExtension()
{
$filename = $this->getDocument()->getFile()->getFilename();
return substr($filename, 0, strrpos($filename, '.'));
} | [
"public",
"function",
"getFilenameWithoutExtension",
"(",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"getDocument",
"(",
")",
"->",
"getFile",
"(",
")",
"->",
"getFilename",
"(",
")",
";",
"return",
"substr",
"(",
"$",
"filename",
",",
"0",
",",
"strrpos",
"(",
"$",
"filename",
",",
"'.'",
")",
")",
";",
"}"
] | Returns the filename for this visitor without an extension.
@return string | [
"Returns",
"the",
"filename",
"for",
"this",
"visitor",
"without",
"an",
"extension",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/Visitors/Creator.php#L57-L62 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Transformer/Router/Renderer.php | Renderer.render | public function render($value, $presentation)
{
if (is_array($value) && current($value) instanceof Type) {
return $this->renderType($value, $presentation);
}
if (is_array($value) || $value instanceof \Traversable || $value instanceof Collection) {
return $this->renderASeriesOfLinks($value, $presentation);
}
if ($value instanceof CollectionDescriptor) {
return $this->renderTypeCollection($value, $presentation);
}
return $this->renderLink($value, $presentation);
} | php | public function render($value, $presentation)
{
if (is_array($value) && current($value) instanceof Type) {
return $this->renderType($value, $presentation);
}
if (is_array($value) || $value instanceof \Traversable || $value instanceof Collection) {
return $this->renderASeriesOfLinks($value, $presentation);
}
if ($value instanceof CollectionDescriptor) {
return $this->renderTypeCollection($value, $presentation);
}
return $this->renderLink($value, $presentation);
} | [
"public",
"function",
"render",
"(",
"$",
"value",
",",
"$",
"presentation",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"current",
"(",
"$",
"value",
")",
"instanceof",
"Type",
")",
"{",
"return",
"$",
"this",
"->",
"renderType",
"(",
"$",
"value",
",",
"$",
"presentation",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"instanceof",
"\\",
"Traversable",
"||",
"$",
"value",
"instanceof",
"Collection",
")",
"{",
"return",
"$",
"this",
"->",
"renderASeriesOfLinks",
"(",
"$",
"value",
",",
"$",
"presentation",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"CollectionDescriptor",
")",
"{",
"return",
"$",
"this",
"->",
"renderTypeCollection",
"(",
"$",
"value",
",",
"$",
"presentation",
")",
";",
"}",
"return",
"$",
"this",
"->",
"renderLink",
"(",
"$",
"value",
",",
"$",
"presentation",
")",
";",
"}"
] | @param string|DescriptorAbstract $value
@param string $presentation
@return bool|mixed|string|\string[] | [
"@param",
"string|DescriptorAbstract",
"$value",
"@param",
"string",
"$presentation"
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Transformer/Router/Renderer.php#L100-L115 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Transformer/Router/Renderer.php | Renderer.convertToRootPath | public function convertToRootPath($relative_path): ?string
{
// get the path to the root directory
$path_parts = explode(DIRECTORY_SEPARATOR, $this->getDestination());
$path_to_root = (count($path_parts) > 1)
? implode('/', array_fill(0, count($path_parts) - 1, '..')) . '/'
: '';
// append the relative path to the root
if (is_string($relative_path) && ($relative_path[0] !== '@')) {
return $path_to_root . ltrim($relative_path, '/');
}
$rule = $this->routers->match($relative_path);
if (!$rule) {
return null;
}
$generatedPath = $rule->generate($relative_path);
return $generatedPath ? $path_to_root . ltrim($generatedPath, '/') : null;
} | php | public function convertToRootPath($relative_path): ?string
{
$path_parts = explode(DIRECTORY_SEPARATOR, $this->getDestination());
$path_to_root = (count($path_parts) > 1)
? implode('/', array_fill(0, count($path_parts) - 1, '..')) . '/'
: '';
if (is_string($relative_path) && ($relative_path[0] !== '@')) {
return $path_to_root . ltrim($relative_path, '/');
}
$rule = $this->routers->match($relative_path);
if (!$rule) {
return null;
}
$generatedPath = $rule->generate($relative_path);
return $generatedPath ? $path_to_root . ltrim($generatedPath, '/') : null;
} | [
"public",
"function",
"convertToRootPath",
"(",
"$",
"relative_path",
")",
":",
"?",
"string",
"{",
"// get the path to the root directory",
"$",
"path_parts",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"this",
"->",
"getDestination",
"(",
")",
")",
";",
"$",
"path_to_root",
"=",
"(",
"count",
"(",
"$",
"path_parts",
")",
">",
"1",
")",
"?",
"implode",
"(",
"'/'",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"path_parts",
")",
"-",
"1",
",",
"'..'",
")",
")",
".",
"'/'",
":",
"''",
";",
"// append the relative path to the root",
"if",
"(",
"is_string",
"(",
"$",
"relative_path",
")",
"&&",
"(",
"$",
"relative_path",
"[",
"0",
"]",
"!==",
"'@'",
")",
")",
"{",
"return",
"$",
"path_to_root",
".",
"ltrim",
"(",
"$",
"relative_path",
",",
"'/'",
")",
";",
"}",
"$",
"rule",
"=",
"$",
"this",
"->",
"routers",
"->",
"match",
"(",
"$",
"relative_path",
")",
";",
"if",
"(",
"!",
"$",
"rule",
")",
"{",
"return",
"null",
";",
"}",
"$",
"generatedPath",
"=",
"$",
"rule",
"->",
"generate",
"(",
"$",
"relative_path",
")",
";",
"return",
"$",
"generatedPath",
"?",
"$",
"path_to_root",
".",
"ltrim",
"(",
"$",
"generatedPath",
",",
"'/'",
")",
":",
"null",
";",
"}"
] | Converts the given path to be relative to the root of the documentation
target directory.
It is not possible to use absolute paths in documentation templates since
they may be used locally, or in a subfolder. As such we need to calculate
the number of levels to go up from the current document's directory and
then append the given path.
For example:
Suppose you are in <root>/classes/my/class.html and you want open
<root>/my/index.html then you provide 'my/index.html' to this method
and it will convert it into ../../my/index.html (<root>/classes/my is
two nesting levels until the root).
This method does not try to normalize or optimize the paths in order to
save on development time and performance, and because it adds no real
value.
@param string $relative_path
@return string|null | [
"Converts",
"the",
"given",
"path",
"to",
"be",
"relative",
"to",
"the",
"root",
"of",
"the",
"documentation",
"target",
"directory",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Transformer/Router/Renderer.php#L141-L162 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Transformer/Router/Renderer.php | Renderer.renderASeriesOfLinks | protected function renderASeriesOfLinks($value, $presentation): array
{
if ($value instanceof Collection) {
$value = $value->getAll();
}
$result = [];
foreach ($value as $path) {
$result[] = $this->render($path, $presentation);
}
return $result;
} | php | protected function renderASeriesOfLinks($value, $presentation): array
{
if ($value instanceof Collection) {
$value = $value->getAll();
}
$result = [];
foreach ($value as $path) {
$result[] = $this->render($path, $presentation);
}
return $result;
} | [
"protected",
"function",
"renderASeriesOfLinks",
"(",
"$",
"value",
",",
"$",
"presentation",
")",
":",
"array",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Collection",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"getAll",
"(",
")",
";",
"}",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"path",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"render",
"(",
"$",
"path",
",",
"$",
"presentation",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns a series of anchors and strings for the given collection of routable items.
@param array|\Traversable|Collection $value
@param string $presentation
@return string[] | [
"Returns",
"a",
"series",
"of",
"anchors",
"and",
"strings",
"for",
"the",
"given",
"collection",
"of",
"routable",
"items",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Transformer/Router/Renderer.php#L172-L184 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Transformer/Router/Renderer.php | Renderer.renderTypeCollection | protected function renderTypeCollection($value, $presentation)
{
$baseType = $this->render($value->getBaseType(), $presentation);
$keyTypes = $this->render($value->getKeyTypes(), $presentation);
$types = $this->render($value->getTypes(), $presentation);
$arguments = [];
if ($keyTypes) {
$arguments[] = implode('|', $keyTypes);
}
$arguments[] = implode('|', $types);
if ($value->getName() === 'array' && count($value->getKeyTypes()) === 0) {
$typeString = (count($types) > 1) ? '(' . reset($arguments) . ')' : reset($arguments);
$collection = $typeString . '[]';
} else {
$collection = ($baseType ?: $value->getName()) . '<' . implode(',', $arguments) . '>';
}
return $collection;
} | php | protected function renderTypeCollection($value, $presentation)
{
$baseType = $this->render($value->getBaseType(), $presentation);
$keyTypes = $this->render($value->getKeyTypes(), $presentation);
$types = $this->render($value->getTypes(), $presentation);
$arguments = [];
if ($keyTypes) {
$arguments[] = implode('|', $keyTypes);
}
$arguments[] = implode('|', $types);
if ($value->getName() === 'array' && count($value->getKeyTypes()) === 0) {
$typeString = (count($types) > 1) ? '(' . reset($arguments) . ')' : reset($arguments);
$collection = $typeString . '[]';
} else {
$collection = ($baseType ?: $value->getName()) . '<' . implode(',', $arguments) . '>';
}
return $collection;
} | [
"protected",
"function",
"renderTypeCollection",
"(",
"$",
"value",
",",
"$",
"presentation",
")",
"{",
"$",
"baseType",
"=",
"$",
"this",
"->",
"render",
"(",
"$",
"value",
"->",
"getBaseType",
"(",
")",
",",
"$",
"presentation",
")",
";",
"$",
"keyTypes",
"=",
"$",
"this",
"->",
"render",
"(",
"$",
"value",
"->",
"getKeyTypes",
"(",
")",
",",
"$",
"presentation",
")",
";",
"$",
"types",
"=",
"$",
"this",
"->",
"render",
"(",
"$",
"value",
"->",
"getTypes",
"(",
")",
",",
"$",
"presentation",
")",
";",
"$",
"arguments",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"keyTypes",
")",
"{",
"$",
"arguments",
"[",
"]",
"=",
"implode",
"(",
"'|'",
",",
"$",
"keyTypes",
")",
";",
"}",
"$",
"arguments",
"[",
"]",
"=",
"implode",
"(",
"'|'",
",",
"$",
"types",
")",
";",
"if",
"(",
"$",
"value",
"->",
"getName",
"(",
")",
"===",
"'array'",
"&&",
"count",
"(",
"$",
"value",
"->",
"getKeyTypes",
"(",
")",
")",
"===",
"0",
")",
"{",
"$",
"typeString",
"=",
"(",
"count",
"(",
"$",
"types",
")",
">",
"1",
")",
"?",
"'('",
".",
"reset",
"(",
"$",
"arguments",
")",
".",
"')'",
":",
"reset",
"(",
"$",
"arguments",
")",
";",
"$",
"collection",
"=",
"$",
"typeString",
".",
"'[]'",
";",
"}",
"else",
"{",
"$",
"collection",
"=",
"(",
"$",
"baseType",
"?",
":",
"$",
"value",
"->",
"getName",
"(",
")",
")",
".",
"'<'",
".",
"implode",
"(",
"','",
",",
"$",
"arguments",
")",
".",
"'>'",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | Renders the view representation for an array or collection.
@param CollectionDescriptor $value
@param string $presentation
@return string | [
"Renders",
"the",
"view",
"representation",
"for",
"an",
"array",
"or",
"collection",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Transformer/Router/Renderer.php#L194-L215 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Builder/Reflector/ArgumentAssembler.php | ArgumentAssembler.create | public function create($data, $params = [])
{
$argumentDescriptor = new ArgumentDescriptor();
$argumentDescriptor->setName($data->getName());
$argumentDescriptor->setType($data->getType());
foreach ($params as $paramDescriptor) {
$this->overwriteTypeAndDescriptionFromParamTag($data, $paramDescriptor, $argumentDescriptor);
}
$argumentDescriptor->setDefault($data->getDefault());
$argumentDescriptor->setByReference($data->isByReference());
return $argumentDescriptor;
} | php | public function create($data, $params = [])
{
$argumentDescriptor = new ArgumentDescriptor();
$argumentDescriptor->setName($data->getName());
$argumentDescriptor->setType($data->getType());
foreach ($params as $paramDescriptor) {
$this->overwriteTypeAndDescriptionFromParamTag($data, $paramDescriptor, $argumentDescriptor);
}
$argumentDescriptor->setDefault($data->getDefault());
$argumentDescriptor->setByReference($data->isByReference());
return $argumentDescriptor;
} | [
"public",
"function",
"create",
"(",
"$",
"data",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"argumentDescriptor",
"=",
"new",
"ArgumentDescriptor",
"(",
")",
";",
"$",
"argumentDescriptor",
"->",
"setName",
"(",
"$",
"data",
"->",
"getName",
"(",
")",
")",
";",
"$",
"argumentDescriptor",
"->",
"setType",
"(",
"$",
"data",
"->",
"getType",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"paramDescriptor",
")",
"{",
"$",
"this",
"->",
"overwriteTypeAndDescriptionFromParamTag",
"(",
"$",
"data",
",",
"$",
"paramDescriptor",
",",
"$",
"argumentDescriptor",
")",
";",
"}",
"$",
"argumentDescriptor",
"->",
"setDefault",
"(",
"$",
"data",
"->",
"getDefault",
"(",
")",
")",
";",
"$",
"argumentDescriptor",
"->",
"setByReference",
"(",
"$",
"data",
"->",
"isByReference",
"(",
")",
")",
";",
"return",
"$",
"argumentDescriptor",
";",
"}"
] | Creates a Descriptor from the provided data.
@param Argument $data
@param ParamDescriptor[] $params
@return ArgumentDescriptor | [
"Creates",
"a",
"Descriptor",
"from",
"the",
"provided",
"data",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Builder/Reflector/ArgumentAssembler.php#L35-L49 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Builder/Reflector/ArgumentAssembler.php | ArgumentAssembler.overwriteTypeAndDescriptionFromParamTag | protected function overwriteTypeAndDescriptionFromParamTag(
Argument $argument,
ParamDescriptor $paramDescriptor,
ArgumentDescriptor $argumentDescriptor
): void {
if ($paramDescriptor->getVariableName() !== $argument->getName()) {
return;
}
$argumentDescriptor->setDescription($paramDescriptor->getDescription());
$argumentDescriptor->setType($paramDescriptor->getType());
} | php | protected function overwriteTypeAndDescriptionFromParamTag(
Argument $argument,
ParamDescriptor $paramDescriptor,
ArgumentDescriptor $argumentDescriptor
): void {
if ($paramDescriptor->getVariableName() !== $argument->getName()) {
return;
}
$argumentDescriptor->setDescription($paramDescriptor->getDescription());
$argumentDescriptor->setType($paramDescriptor->getType());
} | [
"protected",
"function",
"overwriteTypeAndDescriptionFromParamTag",
"(",
"Argument",
"$",
"argument",
",",
"ParamDescriptor",
"$",
"paramDescriptor",
",",
"ArgumentDescriptor",
"$",
"argumentDescriptor",
")",
":",
"void",
"{",
"if",
"(",
"$",
"paramDescriptor",
"->",
"getVariableName",
"(",
")",
"!==",
"$",
"argument",
"->",
"getName",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"argumentDescriptor",
"->",
"setDescription",
"(",
"$",
"paramDescriptor",
"->",
"getDescription",
"(",
")",
")",
";",
"$",
"argumentDescriptor",
"->",
"setType",
"(",
"$",
"paramDescriptor",
"->",
"getType",
"(",
")",
")",
";",
"}"
] | Overwrites the type and description in the Argument Descriptor with that from the tag if the names match. | [
"Overwrites",
"the",
"type",
"and",
"description",
"in",
"the",
"Argument",
"Descriptor",
"with",
"that",
"from",
"the",
"tag",
"if",
"the",
"names",
"match",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Builder/Reflector/ArgumentAssembler.php#L54-L65 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Infrastructure/FlySystemFactory.php | FlySystemFactory.create | public function create(Dsn $dsn)
{
$dsnId = hash('md5', (string) $dsn);
try {
$filesystem = $this->mountManager->getFilesystem($dsnId);
} catch (LogicException $e) {
if ($dsn->getScheme() === 'file') {
$path = $dsn->getPath();
$filesystem = new Filesystem(new Local($path, LOCK_EX, Local::SKIP_LINKS));
} else {
//This will be implemented as soon as the CloneRemoteGitToLocal adapter is finished
throw new \InvalidArgumentException('http and https are not supported yet');
}
$this->mountManager->mountFilesystem($dsnId, $filesystem);
}
$filesystem->addPlugin(new Finder());
return $filesystem;
} | php | public function create(Dsn $dsn)
{
$dsnId = hash('md5', (string) $dsn);
try {
$filesystem = $this->mountManager->getFilesystem($dsnId);
} catch (LogicException $e) {
if ($dsn->getScheme() === 'file') {
$path = $dsn->getPath();
$filesystem = new Filesystem(new Local($path, LOCK_EX, Local::SKIP_LINKS));
} else {
throw new \InvalidArgumentException('http and https are not supported yet');
}
$this->mountManager->mountFilesystem($dsnId, $filesystem);
}
$filesystem->addPlugin(new Finder());
return $filesystem;
} | [
"public",
"function",
"create",
"(",
"Dsn",
"$",
"dsn",
")",
"{",
"$",
"dsnId",
"=",
"hash",
"(",
"'md5'",
",",
"(",
"string",
")",
"$",
"dsn",
")",
";",
"try",
"{",
"$",
"filesystem",
"=",
"$",
"this",
"->",
"mountManager",
"->",
"getFilesystem",
"(",
"$",
"dsnId",
")",
";",
"}",
"catch",
"(",
"LogicException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"dsn",
"->",
"getScheme",
"(",
")",
"===",
"'file'",
")",
"{",
"$",
"path",
"=",
"$",
"dsn",
"->",
"getPath",
"(",
")",
";",
"$",
"filesystem",
"=",
"new",
"Filesystem",
"(",
"new",
"Local",
"(",
"$",
"path",
",",
"LOCK_EX",
",",
"Local",
"::",
"SKIP_LINKS",
")",
")",
";",
"}",
"else",
"{",
"//This will be implemented as soon as the CloneRemoteGitToLocal adapter is finished",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'http and https are not supported yet'",
")",
";",
"}",
"$",
"this",
"->",
"mountManager",
"->",
"mountFilesystem",
"(",
"$",
"dsnId",
",",
"$",
"filesystem",
")",
";",
"}",
"$",
"filesystem",
"->",
"addPlugin",
"(",
"new",
"Finder",
"(",
")",
")",
";",
"return",
"$",
"filesystem",
";",
"}"
] | Returns a Filesystem instance based on the scheme of the provided Dsn
@return FilesystemInterface | [
"Returns",
"a",
"Filesystem",
"instance",
"based",
"on",
"the",
"scheme",
"of",
"the",
"provided",
"Dsn"
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Infrastructure/FlySystemFactory.php#L44-L64 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php | ElementsIndexBuilder.getSubElements | protected function getSubElements(DescriptorAbstract $element): array
{
$subElements = [];
if ($element instanceof ClassInterface) {
$subElements = array_merge(
$element->getMethods()->getAll(),
$element->getConstants()->getAll(),
$element->getProperties()->getAll()
);
}
if ($element instanceof InterfaceInterface) {
$subElements = array_merge(
$element->getMethods()->getAll(),
$element->getConstants()->getAll()
);
}
if ($element instanceof TraitInterface) {
$subElements = array_merge(
$element->getMethods()->getAll(),
$element->getProperties()->getAll()
);
}
return $subElements;
} | php | protected function getSubElements(DescriptorAbstract $element): array
{
$subElements = [];
if ($element instanceof ClassInterface) {
$subElements = array_merge(
$element->getMethods()->getAll(),
$element->getConstants()->getAll(),
$element->getProperties()->getAll()
);
}
if ($element instanceof InterfaceInterface) {
$subElements = array_merge(
$element->getMethods()->getAll(),
$element->getConstants()->getAll()
);
}
if ($element instanceof TraitInterface) {
$subElements = array_merge(
$element->getMethods()->getAll(),
$element->getProperties()->getAll()
);
}
return $subElements;
} | [
"protected",
"function",
"getSubElements",
"(",
"DescriptorAbstract",
"$",
"element",
")",
":",
"array",
"{",
"$",
"subElements",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"element",
"instanceof",
"ClassInterface",
")",
"{",
"$",
"subElements",
"=",
"array_merge",
"(",
"$",
"element",
"->",
"getMethods",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"$",
"element",
"->",
"getConstants",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"$",
"element",
"->",
"getProperties",
"(",
")",
"->",
"getAll",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"element",
"instanceof",
"InterfaceInterface",
")",
"{",
"$",
"subElements",
"=",
"array_merge",
"(",
"$",
"element",
"->",
"getMethods",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"$",
"element",
"->",
"getConstants",
"(",
")",
"->",
"getAll",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"element",
"instanceof",
"TraitInterface",
")",
"{",
"$",
"subElements",
"=",
"array_merge",
"(",
"$",
"element",
"->",
"getMethods",
"(",
")",
"->",
"getAll",
"(",
")",
",",
"$",
"element",
"->",
"getProperties",
"(",
")",
"->",
"getAll",
"(",
")",
")",
";",
"}",
"return",
"$",
"subElements",
";",
"}"
] | Returns any sub-elements for the given element.
This method checks whether the given element is a class, interface or trait and returns
their methods, properties and constants accordingly, or an empty array if no sub-elements
are applicable.
@return DescriptorAbstract[] | [
"Returns",
"any",
"sub",
"-",
"elements",
"for",
"the",
"given",
"element",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php#L82-L109 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php | ElementsIndexBuilder.addElementsToIndexes | protected function addElementsToIndexes($elements, array $indexes): void
{
if (!is_array($elements)) {
$elements = [$elements];
}
/** @var DescriptorAbstract $element */
foreach ($elements as $element) {
/** @var Collection $collection */
foreach ($indexes as $collection) {
$collection->set($this->getIndexKey($element), $element);
}
}
} | php | protected function addElementsToIndexes($elements, array $indexes): void
{
if (!is_array($elements)) {
$elements = [$elements];
}
foreach ($elements as $element) {
foreach ($indexes as $collection) {
$collection->set($this->getIndexKey($element), $element);
}
}
} | [
"protected",
"function",
"addElementsToIndexes",
"(",
"$",
"elements",
",",
"array",
"$",
"indexes",
")",
":",
"void",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"elements",
")",
")",
"{",
"$",
"elements",
"=",
"[",
"$",
"elements",
"]",
";",
"}",
"/** @var DescriptorAbstract $element */",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"/** @var Collection $collection */",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"collection",
")",
"{",
"$",
"collection",
"->",
"set",
"(",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"element",
")",
",",
"$",
"element",
")",
";",
"}",
"}",
"}"
] | Adds a series of descriptors to the given list of collections.
@param DescriptorAbstract|DescriptorAbstract[] $elements
@param Collection[] $indexes | [
"Adds",
"a",
"series",
"of",
"descriptors",
"to",
"the",
"given",
"list",
"of",
"collections",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php#L117-L130 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Compiler/Pass/NamespaceTreeBuilder.php | NamespaceTreeBuilder.addElementsOfTypeToNamespace | protected function addElementsOfTypeToNamespace(ProjectDescriptor $project, array $elements, string $type): void
{
/** @var DescriptorAbstract $element */
foreach ($elements as $element) {
$namespaceName = (string) $element->getNamespace();
//TODO: find out why this can happen. Some bug in the assembler?
if ($namespaceName === '') {
$namespaceName = '\\';
}
$namespace = $project->getIndexes()->get('namespaces', new Collection())->get($namespaceName);
if ($namespace === null) {
$namespace = new NamespaceDescriptor();
$fqsen = new Fqsen($namespaceName);
$namespace->setName($fqsen->getName());
$namespace->setFullyQualifiedStructuralElementName($fqsen);
$namespaceName = substr((string) $fqsen, 0, -strlen($fqsen->getName()) - 1);
$namespace->setNamespace($namespaceName);
$project->getIndexes()
->get('namespaces')
->set((string) $namespace->getFullyQualifiedStructuralElementName(), $namespace);
$this->addToParentNamespace($project, $namespace);
}
// replace textual representation with an object representation
$element->setNamespace($namespace);
// add element to namespace
$getter = 'get' . ucfirst($type);
/** @var Collection $collection */
$collection = $namespace->{$getter}();
$collection->add($element);
}
} | php | protected function addElementsOfTypeToNamespace(ProjectDescriptor $project, array $elements, string $type): void
{
foreach ($elements as $element) {
$namespaceName = (string) $element->getNamespace();
if ($namespaceName === '') {
$namespaceName = '\\';
}
$namespace = $project->getIndexes()->get('namespaces', new Collection())->get($namespaceName);
if ($namespace === null) {
$namespace = new NamespaceDescriptor();
$fqsen = new Fqsen($namespaceName);
$namespace->setName($fqsen->getName());
$namespace->setFullyQualifiedStructuralElementName($fqsen);
$namespaceName = substr((string) $fqsen, 0, -strlen($fqsen->getName()) - 1);
$namespace->setNamespace($namespaceName);
$project->getIndexes()
->get('namespaces')
->set((string) $namespace->getFullyQualifiedStructuralElementName(), $namespace);
$this->addToParentNamespace($project, $namespace);
}
$element->setNamespace($namespace);
$getter = 'get' . ucfirst($type);
$collection = $namespace->{$getter}();
$collection->add($element);
}
} | [
"protected",
"function",
"addElementsOfTypeToNamespace",
"(",
"ProjectDescriptor",
"$",
"project",
",",
"array",
"$",
"elements",
",",
"string",
"$",
"type",
")",
":",
"void",
"{",
"/** @var DescriptorAbstract $element */",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"namespaceName",
"=",
"(",
"string",
")",
"$",
"element",
"->",
"getNamespace",
"(",
")",
";",
"//TODO: find out why this can happen. Some bug in the assembler?",
"if",
"(",
"$",
"namespaceName",
"===",
"''",
")",
"{",
"$",
"namespaceName",
"=",
"'\\\\'",
";",
"}",
"$",
"namespace",
"=",
"$",
"project",
"->",
"getIndexes",
"(",
")",
"->",
"get",
"(",
"'namespaces'",
",",
"new",
"Collection",
"(",
")",
")",
"->",
"get",
"(",
"$",
"namespaceName",
")",
";",
"if",
"(",
"$",
"namespace",
"===",
"null",
")",
"{",
"$",
"namespace",
"=",
"new",
"NamespaceDescriptor",
"(",
")",
";",
"$",
"fqsen",
"=",
"new",
"Fqsen",
"(",
"$",
"namespaceName",
")",
";",
"$",
"namespace",
"->",
"setName",
"(",
"$",
"fqsen",
"->",
"getName",
"(",
")",
")",
";",
"$",
"namespace",
"->",
"setFullyQualifiedStructuralElementName",
"(",
"$",
"fqsen",
")",
";",
"$",
"namespaceName",
"=",
"substr",
"(",
"(",
"string",
")",
"$",
"fqsen",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"fqsen",
"->",
"getName",
"(",
")",
")",
"-",
"1",
")",
";",
"$",
"namespace",
"->",
"setNamespace",
"(",
"$",
"namespaceName",
")",
";",
"$",
"project",
"->",
"getIndexes",
"(",
")",
"->",
"get",
"(",
"'namespaces'",
")",
"->",
"set",
"(",
"(",
"string",
")",
"$",
"namespace",
"->",
"getFullyQualifiedStructuralElementName",
"(",
")",
",",
"$",
"namespace",
")",
";",
"$",
"this",
"->",
"addToParentNamespace",
"(",
"$",
"project",
",",
"$",
"namespace",
")",
";",
"}",
"// replace textual representation with an object representation",
"$",
"element",
"->",
"setNamespace",
"(",
"$",
"namespace",
")",
";",
"// add element to namespace",
"$",
"getter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"type",
")",
";",
"/** @var Collection $collection */",
"$",
"collection",
"=",
"$",
"namespace",
"->",
"{",
"$",
"getter",
"}",
"(",
")",
";",
"$",
"collection",
"->",
"add",
"(",
"$",
"element",
")",
";",
"}",
"}"
] | Adds the given elements of a specific type to their respective Namespace Descriptors.
This method will assign the given elements to the namespace as registered in the namespace field of that
element. If a namespace does not exist yet it will automatically be created.
@param DescriptorAbstract[] $elements Series of elements to add to their respective namespace.
@param string $type Declares which field of the namespace will be populated with the given series of elements.
This name will be transformed to a getter which must exist. Out of performance
considerations will no effort be done to verify whether the provided type is valid. | [
"Adds",
"the",
"given",
"elements",
"of",
"a",
"specific",
"type",
"to",
"their",
"respective",
"Namespace",
"Descriptors",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Compiler/Pass/NamespaceTreeBuilder.php#L77-L112 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractor.php | MarkerFromTagsExtractor.addTodoMarkerToFile | protected function addTodoMarkerToFile(FileDescriptor $fileDescriptor, TagDescriptor $todo, int $lineNumber): void
{
$fileDescriptor->getMarkers()->add(
[
'type' => 'TODO',
'message' => $todo->getDescription(),
'line' => $lineNumber,
]
);
} | php | protected function addTodoMarkerToFile(FileDescriptor $fileDescriptor, TagDescriptor $todo, int $lineNumber): void
{
$fileDescriptor->getMarkers()->add(
[
'type' => 'TODO',
'message' => $todo->getDescription(),
'line' => $lineNumber,
]
);
} | [
"protected",
"function",
"addTodoMarkerToFile",
"(",
"FileDescriptor",
"$",
"fileDescriptor",
",",
"TagDescriptor",
"$",
"todo",
",",
"int",
"$",
"lineNumber",
")",
":",
"void",
"{",
"$",
"fileDescriptor",
"->",
"getMarkers",
"(",
")",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'TODO'",
",",
"'message'",
"=>",
"$",
"todo",
"->",
"getDescription",
"(",
")",
",",
"'line'",
"=>",
"$",
"lineNumber",
",",
"]",
")",
";",
"}"
] | Adds a marker with the TO DO information to the file on a given line number. | [
"Adds",
"a",
"marker",
"with",
"the",
"TO",
"DO",
"information",
"to",
"the",
"file",
"on",
"a",
"given",
"line",
"number",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractor.php#L77-L86 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Parser/Middleware/StopwatchMiddleware.php | StopwatchMiddleware.execute | public function execute(Command $command, callable $next)
{
$result = $next($command);
if ($this->stopwatch) {
$lap = $this->stopwatch->lap('parser.parse');
$oldMemory = $this->memory;
$periods = $lap->getPeriods();
$memory = end($periods)->getMemory();
$this->log(
'>> Memory after processing of file: ' . number_format($memory / 1024 / 1024, 2)
. ' megabytes (' . (($memory - $oldMemory >= 0)
? '+'
: '-') . number_format(($memory - $oldMemory) / 1024)
. ' kilobytes)',
LogLevel::DEBUG
);
$this->memory = $memory;
}
return $result;
} | php | public function execute(Command $command, callable $next)
{
$result = $next($command);
if ($this->stopwatch) {
$lap = $this->stopwatch->lap('parser.parse');
$oldMemory = $this->memory;
$periods = $lap->getPeriods();
$memory = end($periods)->getMemory();
$this->log(
'>> Memory after processing of file: ' . number_format($memory / 1024 / 1024, 2)
. ' megabytes (' . (($memory - $oldMemory >= 0)
? '+'
: '-') . number_format(($memory - $oldMemory) / 1024)
. ' kilobytes)',
LogLevel::DEBUG
);
$this->memory = $memory;
}
return $result;
} | [
"public",
"function",
"execute",
"(",
"Command",
"$",
"command",
",",
"callable",
"$",
"next",
")",
"{",
"$",
"result",
"=",
"$",
"next",
"(",
"$",
"command",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stopwatch",
")",
"{",
"$",
"lap",
"=",
"$",
"this",
"->",
"stopwatch",
"->",
"lap",
"(",
"'parser.parse'",
")",
";",
"$",
"oldMemory",
"=",
"$",
"this",
"->",
"memory",
";",
"$",
"periods",
"=",
"$",
"lap",
"->",
"getPeriods",
"(",
")",
";",
"$",
"memory",
"=",
"end",
"(",
"$",
"periods",
")",
"->",
"getMemory",
"(",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'>> Memory after processing of file: '",
".",
"number_format",
"(",
"$",
"memory",
"/",
"1024",
"/",
"1024",
",",
"2",
")",
".",
"' megabytes ('",
".",
"(",
"(",
"$",
"memory",
"-",
"$",
"oldMemory",
">=",
"0",
")",
"?",
"'+'",
":",
"'-'",
")",
".",
"number_format",
"(",
"(",
"$",
"memory",
"-",
"$",
"oldMemory",
")",
"/",
"1024",
")",
".",
"' kilobytes)'",
",",
"LogLevel",
"::",
"DEBUG",
")",
";",
"$",
"this",
"->",
"memory",
"=",
"$",
"memory",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Executes this middle ware class.
@param callable $next
@return object | [
"Executes",
"this",
"middle",
"ware",
"class",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Parser/Middleware/StopwatchMiddleware.php#L50-L73 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Application.php | Application.defineIniSettings | protected function defineIniSettings(): void
{
$this->setTimezone();
ini_set('memory_limit', '-1');
if (extension_loaded('Zend OPcache') && ini_get('opcache.enable') && ini_get('opcache.enable_cli')) {
if (ini_get('opcache.save_comments')) {
ini_set('opcache.load_comments', '1');
} else {
ini_set('opcache.enable', '0');
}
}
if (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.save_comments') === 0) {
throw new RuntimeException('Please enable zend_optimizerplus.save_comments in php.ini.');
}
} | php | protected function defineIniSettings(): void
{
$this->setTimezone();
ini_set('memory_limit', '-1');
if (extension_loaded('Zend OPcache') && ini_get('opcache.enable') && ini_get('opcache.enable_cli')) {
if (ini_get('opcache.save_comments')) {
ini_set('opcache.load_comments', '1');
} else {
ini_set('opcache.enable', '0');
}
}
if (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.save_comments') === 0) {
throw new RuntimeException('Please enable zend_optimizerplus.save_comments in php.ini.');
}
} | [
"protected",
"function",
"defineIniSettings",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"setTimezone",
"(",
")",
";",
"ini_set",
"(",
"'memory_limit'",
",",
"'-1'",
")",
";",
"if",
"(",
"extension_loaded",
"(",
"'Zend OPcache'",
")",
"&&",
"ini_get",
"(",
"'opcache.enable'",
")",
"&&",
"ini_get",
"(",
"'opcache.enable_cli'",
")",
")",
"{",
"if",
"(",
"ini_get",
"(",
"'opcache.save_comments'",
")",
")",
"{",
"ini_set",
"(",
"'opcache.load_comments'",
",",
"'1'",
")",
";",
"}",
"else",
"{",
"ini_set",
"(",
"'opcache.enable'",
",",
"'0'",
")",
";",
"}",
"}",
"if",
"(",
"extension_loaded",
"(",
"'Zend Optimizer+'",
")",
"&&",
"ini_get",
"(",
"'zend_optimizerplus.save_comments'",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Please enable zend_optimizerplus.save_comments in php.ini.'",
")",
";",
"}",
"}"
] | Adjust php.ini settings.
@throws RuntimeException | [
"Adjust",
"php",
".",
"ini",
"settings",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Application.php#L78-L94 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Builder/Reflector/FunctionAssembler.php | FunctionAssembler.create | public function create($data)
{
$functionDescriptor = new FunctionDescriptor();
$this->mapReflectorPropertiesOntoDescriptor($data, $functionDescriptor);
$this->assembleDocBlock($data->getDocBlock(), $functionDescriptor);
$this->addArgumentsToFunctionDescriptor($data->getArguments(), $functionDescriptor);
return $functionDescriptor;
} | php | public function create($data)
{
$functionDescriptor = new FunctionDescriptor();
$this->mapReflectorPropertiesOntoDescriptor($data, $functionDescriptor);
$this->assembleDocBlock($data->getDocBlock(), $functionDescriptor);
$this->addArgumentsToFunctionDescriptor($data->getArguments(), $functionDescriptor);
return $functionDescriptor;
} | [
"public",
"function",
"create",
"(",
"$",
"data",
")",
"{",
"$",
"functionDescriptor",
"=",
"new",
"FunctionDescriptor",
"(",
")",
";",
"$",
"this",
"->",
"mapReflectorPropertiesOntoDescriptor",
"(",
"$",
"data",
",",
"$",
"functionDescriptor",
")",
";",
"$",
"this",
"->",
"assembleDocBlock",
"(",
"$",
"data",
"->",
"getDocBlock",
"(",
")",
",",
"$",
"functionDescriptor",
")",
";",
"$",
"this",
"->",
"addArgumentsToFunctionDescriptor",
"(",
"$",
"data",
"->",
"getArguments",
"(",
")",
",",
"$",
"functionDescriptor",
")",
";",
"return",
"$",
"functionDescriptor",
";",
"}"
] | Creates a Descriptor from the provided data.
@param Function_ $data
@return FunctionDescriptor | [
"Creates",
"a",
"Descriptor",
"from",
"the",
"provided",
"data",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Builder/Reflector/FunctionAssembler.php#L48-L57 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Builder/Reflector/FunctionAssembler.php | FunctionAssembler.mapReflectorPropertiesOntoDescriptor | protected function mapReflectorPropertiesOntoDescriptor(Function_ $reflector, FunctionDescriptor $descriptor): void
{
$packages = new Collection();
$package = $this->extractPackageFromDocBlock($reflector->getDocBlock());
//TODO: this looks like a potential bug. Have to investigate this!
if ($package) {
$tag = new TagDescriptor('package');
$tag->setDescription($package);
$packages->add($tag);
}
$descriptor->getTags()->set('package', $packages);
$descriptor->setFullyQualifiedStructuralElementName($reflector->getFqsen());
$descriptor->setName($reflector->getName());
$descriptor->setLine($reflector->getLocation()->getLineNumber());
$descriptor->setNamespace('\\' . trim(substr(
(string) $reflector->getFqsen(),
0,
-strlen($reflector->getName()) - 2
), '\\'));
$descriptor->setReturnType($reflector->getReturnType());
} | php | protected function mapReflectorPropertiesOntoDescriptor(Function_ $reflector, FunctionDescriptor $descriptor): void
{
$packages = new Collection();
$package = $this->extractPackageFromDocBlock($reflector->getDocBlock());
if ($package) {
$tag = new TagDescriptor('package');
$tag->setDescription($package);
$packages->add($tag);
}
$descriptor->getTags()->set('package', $packages);
$descriptor->setFullyQualifiedStructuralElementName($reflector->getFqsen());
$descriptor->setName($reflector->getName());
$descriptor->setLine($reflector->getLocation()->getLineNumber());
$descriptor->setNamespace('\\' . trim(substr(
(string) $reflector->getFqsen(),
0,
-strlen($reflector->getName()) - 2
), '\\'));
$descriptor->setReturnType($reflector->getReturnType());
} | [
"protected",
"function",
"mapReflectorPropertiesOntoDescriptor",
"(",
"Function_",
"$",
"reflector",
",",
"FunctionDescriptor",
"$",
"descriptor",
")",
":",
"void",
"{",
"$",
"packages",
"=",
"new",
"Collection",
"(",
")",
";",
"$",
"package",
"=",
"$",
"this",
"->",
"extractPackageFromDocBlock",
"(",
"$",
"reflector",
"->",
"getDocBlock",
"(",
")",
")",
";",
"//TODO: this looks like a potential bug. Have to investigate this!",
"if",
"(",
"$",
"package",
")",
"{",
"$",
"tag",
"=",
"new",
"TagDescriptor",
"(",
"'package'",
")",
";",
"$",
"tag",
"->",
"setDescription",
"(",
"$",
"package",
")",
";",
"$",
"packages",
"->",
"add",
"(",
"$",
"tag",
")",
";",
"}",
"$",
"descriptor",
"->",
"getTags",
"(",
")",
"->",
"set",
"(",
"'package'",
",",
"$",
"packages",
")",
";",
"$",
"descriptor",
"->",
"setFullyQualifiedStructuralElementName",
"(",
"$",
"reflector",
"->",
"getFqsen",
"(",
")",
")",
";",
"$",
"descriptor",
"->",
"setName",
"(",
"$",
"reflector",
"->",
"getName",
"(",
")",
")",
";",
"$",
"descriptor",
"->",
"setLine",
"(",
"$",
"reflector",
"->",
"getLocation",
"(",
")",
"->",
"getLineNumber",
"(",
")",
")",
";",
"$",
"descriptor",
"->",
"setNamespace",
"(",
"'\\\\'",
".",
"trim",
"(",
"substr",
"(",
"(",
"string",
")",
"$",
"reflector",
"->",
"getFqsen",
"(",
")",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"reflector",
"->",
"getName",
"(",
")",
")",
"-",
"2",
")",
",",
"'\\\\'",
")",
")",
";",
"$",
"descriptor",
"->",
"setReturnType",
"(",
"$",
"reflector",
"->",
"getReturnType",
"(",
")",
")",
";",
"}"
] | Maps the properties of the Function reflector onto the Descriptor. | [
"Maps",
"the",
"properties",
"of",
"the",
"Function",
"reflector",
"onto",
"the",
"Descriptor",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Builder/Reflector/FunctionAssembler.php#L62-L84 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Builder/Reflector/FunctionAssembler.php | FunctionAssembler.addArgumentsToFunctionDescriptor | protected function addArgumentsToFunctionDescriptor(array $arguments, FunctionDescriptor $functionDescriptor): void
{
foreach ($arguments as $argument) {
$this->addArgumentDescriptorToFunction(
$functionDescriptor,
$this->createArgumentDescriptor($functionDescriptor, $argument)
);
}
} | php | protected function addArgumentsToFunctionDescriptor(array $arguments, FunctionDescriptor $functionDescriptor): void
{
foreach ($arguments as $argument) {
$this->addArgumentDescriptorToFunction(
$functionDescriptor,
$this->createArgumentDescriptor($functionDescriptor, $argument)
);
}
} | [
"protected",
"function",
"addArgumentsToFunctionDescriptor",
"(",
"array",
"$",
"arguments",
",",
"FunctionDescriptor",
"$",
"functionDescriptor",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"argument",
")",
"{",
"$",
"this",
"->",
"addArgumentDescriptorToFunction",
"(",
"$",
"functionDescriptor",
",",
"$",
"this",
"->",
"createArgumentDescriptor",
"(",
"$",
"functionDescriptor",
",",
"$",
"argument",
")",
")",
";",
"}",
"}"
] | Converts each argument reflector to an argument descriptor and adds it to the function descriptor.
@param Argument[] $arguments | [
"Converts",
"each",
"argument",
"reflector",
"to",
"an",
"argument",
"descriptor",
"and",
"adds",
"it",
"to",
"the",
"function",
"descriptor",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Builder/Reflector/FunctionAssembler.php#L91-L99 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Builder/Reflector/FunctionAssembler.php | FunctionAssembler.addArgumentDescriptorToFunction | protected function addArgumentDescriptorToFunction(
FunctionDescriptor $functionDescriptor,
ArgumentDescriptor $argumentDescriptor
): void {
$functionDescriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor);
} | php | protected function addArgumentDescriptorToFunction(
FunctionDescriptor $functionDescriptor,
ArgumentDescriptor $argumentDescriptor
): void {
$functionDescriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor);
} | [
"protected",
"function",
"addArgumentDescriptorToFunction",
"(",
"FunctionDescriptor",
"$",
"functionDescriptor",
",",
"ArgumentDescriptor",
"$",
"argumentDescriptor",
")",
":",
"void",
"{",
"$",
"functionDescriptor",
"->",
"getArguments",
"(",
")",
"->",
"set",
"(",
"$",
"argumentDescriptor",
"->",
"getName",
"(",
")",
",",
"$",
"argumentDescriptor",
")",
";",
"}"
] | Adds the given argument to the function. | [
"Adds",
"the",
"given",
"argument",
"to",
"the",
"function",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Builder/Reflector/FunctionAssembler.php#L104-L109 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Transformer/Router/UrlGenerator/Standard/QualifiedNameToUrlConverter.php | QualifiedNameToUrlConverter.fromNamespace | public function fromNamespace($fqnn)
{
$name = str_replace('\\', '.', ltrim((string) $fqnn, '\\'));
// convert root namespace to default; default is a keyword and no namespace CAN be named as such
if ($name === '') {
$name = 'default';
}
return $name;
} | php | public function fromNamespace($fqnn)
{
$name = str_replace('\\', '.', ltrim((string) $fqnn, '\\'));
if ($name === '') {
$name = 'default';
}
return $name;
} | [
"public",
"function",
"fromNamespace",
"(",
"$",
"fqnn",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'.'",
",",
"ltrim",
"(",
"(",
"string",
")",
"$",
"fqnn",
",",
"'\\\\'",
")",
")",
";",
"// convert root namespace to default; default is a keyword and no namespace CAN be named as such",
"if",
"(",
"$",
"name",
"===",
"''",
")",
"{",
"$",
"name",
"=",
"'default'",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Converts the provided FQCN into a file name by replacing all slashes with dots.
@param string $fqnn
@return string | [
"Converts",
"the",
"provided",
"FQCN",
"into",
"a",
"file",
"name",
"by",
"replacing",
"all",
"slashes",
"with",
"dots",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Transformer/Router/UrlGenerator/Standard/QualifiedNameToUrlConverter.php#L49-L59 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Transformer/Router/UrlGenerator/Standard/QualifiedNameToUrlConverter.php#L94-L101 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/CommandlineOptionsMiddleware.php#L69-L76 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/CommandlineOptionsMiddleware.php#L99-L111 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/Filter/Filter.php | Filter.attach | public function attach(string $fqcn, FilterInterface $filter, int $priority = self::DEFAULT_PRIORITY): void
{
$chain = $this->factory->getChainFor($fqcn);
$chain->attach($filter, $priority);
} | php | public function attach(string $fqcn, FilterInterface $filter, int $priority = self::DEFAULT_PRIORITY): void
{
$chain = $this->factory->getChainFor($fqcn);
$chain->attach($filter, $priority);
} | [
"public",
"function",
"attach",
"(",
"string",
"$",
"fqcn",
",",
"FilterInterface",
"$",
"filter",
",",
"int",
"$",
"priority",
"=",
"self",
"::",
"DEFAULT_PRIORITY",
")",
":",
"void",
"{",
"$",
"chain",
"=",
"$",
"this",
"->",
"factory",
"->",
"getChainFor",
"(",
"$",
"fqcn",
")",
";",
"$",
"chain",
"->",
"attach",
"(",
"$",
"filter",
",",
"$",
"priority",
")",
";",
"}"
] | Attaches a filter to a specific FQCN. | [
"Attaches",
"a",
"filter",
"to",
"a",
"specific",
"FQCN",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Filter/Filter.php#L67-L71 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/Filter/Filter.php#L76-L81 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Scrybe/Converter/Format/Collection.php#L54-L61 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Partials/ServiceProvider.php | ServiceProvider.register | public function register(Container $app): void
{
$app['markdown'] = function () {
return Parsedown::instance();
};
$partialsCollection = new Collection();
$app['partials'] = $partialsCollection;
/** @var Partial[] $partials */
$partials = []; //$config->getPartials();
if ($partials) {
foreach ($partials as $partial) {
if (! $partial->getName()) {
throw new MissingNameForPartialException('The name of the partial to load is missing');
}
$partial->setParser($app['markdown']);
if (!$partial->getContent() && $partial->getLink()) {
if (! is_readable($partial->getLink())) {
$app['monolog']->error(
sprintf('Partial "%s" not readable or found.', $partial->getLink())
);
continue;
}
}
$partialsCollection->set($partial->getName(), $partial);
}
}
} | php | public function register(Container $app): void
{
$app['markdown'] = function () {
return Parsedown::instance();
};
$partialsCollection = new Collection();
$app['partials'] = $partialsCollection;
$partials = [];
if ($partials) {
foreach ($partials as $partial) {
if (! $partial->getName()) {
throw new MissingNameForPartialException('The name of the partial to load is missing');
}
$partial->setParser($app['markdown']);
if (!$partial->getContent() && $partial->getLink()) {
if (! is_readable($partial->getLink())) {
$app['monolog']->error(
sprintf('Partial "%s" not readable or found.', $partial->getLink())
);
continue;
}
}
$partialsCollection->set($partial->getName(), $partial);
}
}
} | [
"public",
"function",
"register",
"(",
"Container",
"$",
"app",
")",
":",
"void",
"{",
"$",
"app",
"[",
"'markdown'",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"Parsedown",
"::",
"instance",
"(",
")",
";",
"}",
";",
"$",
"partialsCollection",
"=",
"new",
"Collection",
"(",
")",
";",
"$",
"app",
"[",
"'partials'",
"]",
"=",
"$",
"partialsCollection",
";",
"/** @var Partial[] $partials */",
"$",
"partials",
"=",
"[",
"]",
";",
"//$config->getPartials();",
"if",
"(",
"$",
"partials",
")",
"{",
"foreach",
"(",
"$",
"partials",
"as",
"$",
"partial",
")",
"{",
"if",
"(",
"!",
"$",
"partial",
"->",
"getName",
"(",
")",
")",
"{",
"throw",
"new",
"MissingNameForPartialException",
"(",
"'The name of the partial to load is missing'",
")",
";",
"}",
"$",
"partial",
"->",
"setParser",
"(",
"$",
"app",
"[",
"'markdown'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"partial",
"->",
"getContent",
"(",
")",
"&&",
"$",
"partial",
"->",
"getLink",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"partial",
"->",
"getLink",
"(",
")",
")",
")",
"{",
"$",
"app",
"[",
"'monolog'",
"]",
"->",
"error",
"(",
"sprintf",
"(",
"'Partial \"%s\" not readable or found.'",
",",
"$",
"partial",
"->",
"getLink",
"(",
")",
")",
")",
";",
"continue",
";",
"}",
"}",
"$",
"partialsCollection",
"->",
"set",
"(",
"$",
"partial",
"->",
"getName",
"(",
")",
",",
"$",
"partial",
")",
";",
"}",
"}",
"}"
] | Registers services on the given app.
@throws MissingNameForPartialException if a partial has no name provided. | [
"Registers",
"services",
"on",
"the",
"given",
"app",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Partials/ServiceProvider.php#L34-L64 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Plugin/Scrybe/Converter/Metadata/TableOfContents/BaseEntry.php | BaseEntry.setParent | public function setParent($parent)
{
if ($parent !== null && !$parent instanceof self) {
throw new \InvalidArgumentException('An entry may only have another entry as parent');
}
$this->parent = $parent;
} | php | public function setParent($parent)
{
if ($parent !== null && !$parent instanceof self) {
throw new \InvalidArgumentException('An entry may only have another entry as parent');
}
$this->parent = $parent;
} | [
"public",
"function",
"setParent",
"(",
"$",
"parent",
")",
"{",
"if",
"(",
"$",
"parent",
"!==",
"null",
"&&",
"!",
"$",
"parent",
"instanceof",
"self",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'An entry may only have another entry as parent'",
")",
";",
"}",
"$",
"this",
"->",
"parent",
"=",
"$",
"parent",
";",
"}"
] | Sets the parent entry for this entry.
@param BaseEntry|null $parent
@throws \InvalidArgumentException if the given parameter is of an incorrect type. | [
"Sets",
"the",
"parent",
"entry",
"for",
"this",
"entry",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Scrybe/Converter/Metadata/TableOfContents/BaseEntry.php#L81-L88 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/DomainModel/Uri.php | Uri.validateString | private function validateString(string $uri): void
{
if (!\is_string($uri)) {
throw new InvalidArgumentException(sprintf('String required, %s given', \gettype($uri)));
}
} | php | private function validateString(string $uri): void
{
if (!\is_string($uri)) {
throw new InvalidArgumentException(sprintf('String required, %s given', \gettype($uri)));
}
} | [
"private",
"function",
"validateString",
"(",
"string",
"$",
"uri",
")",
":",
"void",
"{",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"uri",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'String required, %s given'",
",",
"\\",
"gettype",
"(",
"$",
"uri",
")",
")",
")",
";",
"}",
"}"
] | Checks if $uri is of type string.
@throws InvalidArgumentException if $uri is not a string. | [
"Checks",
"if",
"$uri",
"is",
"of",
"type",
"string",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/DomainModel/Uri.php#L70-L75 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/DomainModel/Uri.php | Uri.validateUri | private function validateUri(string $uri): void
{
if (filter_var($uri, FILTER_VALIDATE_URL) === false) {
throw new InvalidArgumentException(sprintf('%s is not a valid uri', $uri));
}
} | php | private function validateUri(string $uri): void
{
if (filter_var($uri, FILTER_VALIDATE_URL) === false) {
throw new InvalidArgumentException(sprintf('%s is not a valid uri', $uri));
}
} | [
"private",
"function",
"validateUri",
"(",
"string",
"$",
"uri",
")",
":",
"void",
"{",
"if",
"(",
"filter_var",
"(",
"$",
"uri",
",",
"FILTER_VALIDATE_URL",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s is not a valid uri'",
",",
"$",
"uri",
")",
")",
";",
"}",
"}"
] | Checks if $uri is valid.
@throws InvalidArgumentException if $uri is not a valid uri. | [
"Checks",
"if",
"$uri",
"is",
"valid",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/DomainModel/Uri.php#L82-L87 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/DomainModel/Uri.php | Uri.addFileSchemeWhenSchemeIsAbsent | private function addFileSchemeWhenSchemeIsAbsent(string $uri): string
{
$scheme = parse_url($uri, PHP_URL_SCHEME);
if (empty($scheme)) {
$uri = 'file://' . $uri;
} elseif (preg_match('/^[a-z]$/i', (string) $scheme)) { // windows driver letter
$uri = 'file:///' . $uri;
}
return $uri;
} | php | private function addFileSchemeWhenSchemeIsAbsent(string $uri): string
{
$scheme = parse_url($uri, PHP_URL_SCHEME);
if (empty($scheme)) {
$uri = 'file:
} elseif (preg_match('/^[a-z]$/i', (string) $scheme)) {
$uri = 'file:
}
return $uri;
} | [
"private",
"function",
"addFileSchemeWhenSchemeIsAbsent",
"(",
"string",
"$",
"uri",
")",
":",
"string",
"{",
"$",
"scheme",
"=",
"parse_url",
"(",
"$",
"uri",
",",
"PHP_URL_SCHEME",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"scheme",
")",
")",
"{",
"$",
"uri",
"=",
"'file://'",
".",
"$",
"uri",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^[a-z]$/i'",
",",
"(",
"string",
")",
"$",
"scheme",
")",
")",
"{",
"// windows driver letter",
"$",
"uri",
"=",
"'file:///'",
".",
"$",
"uri",
";",
"}",
"return",
"$",
"uri",
";",
"}"
] | Checks if a scheme is present.
If no scheme is found, it is assumed that a local path is used, and file:// is prepended. | [
"Checks",
"if",
"a",
"scheme",
"is",
"present",
".",
"If",
"no",
"scheme",
"is",
"found",
"it",
"is",
"assumed",
"that",
"a",
"local",
"path",
"is",
"used",
"and",
"file",
":",
"//",
"is",
"prepended",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/DomainModel/Uri.php#L93-L104 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L116-L126 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L133-L144 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L151-L162 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L169-L180 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L185-L196 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Configuration/Factory/Version2.php | Version2.buildTemplate | private function buildTemplate(SimpleXMLElement $phpDocumentor): string
{
if ((array) $phpDocumentor->transformations === []) {
return $this->template;
}
if ((string) $phpDocumentor->transformations->template === '') {
return $this->template;
}
return (string) $phpDocumentor->transformations->template->attributes()->name;
} | php | private function buildTemplate(SimpleXMLElement $phpDocumentor): string
{
if ((array) $phpDocumentor->transformations === []) {
return $this->template;
}
if ((string) $phpDocumentor->transformations->template === '') {
return $this->template;
}
return (string) $phpDocumentor->transformations->template->attributes()->name;
} | [
"private",
"function",
"buildTemplate",
"(",
"SimpleXMLElement",
"$",
"phpDocumentor",
")",
":",
"string",
"{",
"if",
"(",
"(",
"array",
")",
"$",
"phpDocumentor",
"->",
"transformations",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"template",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"transformations",
"->",
"template",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"template",
";",
"}",
"return",
"(",
"string",
")",
"$",
"phpDocumentor",
"->",
"transformations",
"->",
"template",
"->",
"attributes",
"(",
")",
"->",
"name",
";",
"}"
] | Builds the template part of the array from the configuration xml. | [
"Builds",
"the",
"template",
"part",
"of",
"the",
"array",
"from",
"the",
"configuration",
"xml",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L201-L212 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L217-L228 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L233-L244 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L251-L268 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L273-L284 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L291-L302 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L309-L319 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Configuration/Factory/Version2.php#L326-L333 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Descriptor/FunctionDescriptor.php | FunctionDescriptor.getResponse | public function getResponse(): ReturnDescriptor
{
$definedReturn = new ReturnDescriptor('return');
$definedReturn->setType($this->returnType);
/** @var Collection|null $returnTags */
$returnTags = $this->getTags()->get('return');
if ($returnTags instanceof Collection && $returnTags->count() > 0) {
/** @var ReturnDescriptor $returnTag */
return current($returnTags->getAll());
}
return $definedReturn;
} | php | public function getResponse(): ReturnDescriptor
{
$definedReturn = new ReturnDescriptor('return');
$definedReturn->setType($this->returnType);
$returnTags = $this->getTags()->get('return');
if ($returnTags instanceof Collection && $returnTags->count() > 0) {
return current($returnTags->getAll());
}
return $definedReturn;
} | [
"public",
"function",
"getResponse",
"(",
")",
":",
"ReturnDescriptor",
"{",
"$",
"definedReturn",
"=",
"new",
"ReturnDescriptor",
"(",
"'return'",
")",
";",
"$",
"definedReturn",
"->",
"setType",
"(",
"$",
"this",
"->",
"returnType",
")",
";",
"/** @var Collection|null $returnTags */",
"$",
"returnTags",
"=",
"$",
"this",
"->",
"getTags",
"(",
")",
"->",
"get",
"(",
"'return'",
")",
";",
"if",
"(",
"$",
"returnTags",
"instanceof",
"Collection",
"&&",
"$",
"returnTags",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"/** @var ReturnDescriptor $returnTag */",
"return",
"current",
"(",
"$",
"returnTags",
"->",
"getAll",
"(",
")",
")",
";",
"}",
"return",
"$",
"definedReturn",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Descriptor/FunctionDescriptor.php#L61-L75 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Core/Xslt/Extension.php#L53-L62 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Plugin/Core/Xslt/Extension.php | Extension.path | public static function path($fqsen)
{
$node = self::getDocumentedElement($fqsen) ?: $fqsen;
$rule = self::$routers->match($node);
if (! $rule) {
return '';
}
$generatedUrl = $rule->generate($node);
return $generatedUrl ? ltrim($generatedUrl, '/') : false;
} | php | public static function path($fqsen)
{
$node = self::getDocumentedElement($fqsen) ?: $fqsen;
$rule = self::$routers->match($node);
if (! $rule) {
return '';
}
$generatedUrl = $rule->generate($node);
return $generatedUrl ? ltrim($generatedUrl, '/') : false;
} | [
"public",
"static",
"function",
"path",
"(",
"$",
"fqsen",
")",
"{",
"$",
"node",
"=",
"self",
"::",
"getDocumentedElement",
"(",
"$",
"fqsen",
")",
"?",
":",
"$",
"fqsen",
";",
"$",
"rule",
"=",
"self",
"::",
"$",
"routers",
"->",
"match",
"(",
"$",
"node",
")",
";",
"if",
"(",
"!",
"$",
"rule",
")",
"{",
"return",
"''",
";",
"}",
"$",
"generatedUrl",
"=",
"$",
"rule",
"->",
"generate",
"(",
"$",
"node",
")",
";",
"return",
"$",
"generatedUrl",
"?",
"ltrim",
"(",
"$",
"generatedUrl",
",",
"'/'",
")",
":",
"false",
";",
"}"
] | Returns a relative URL from the webroot if the given FQSEN exists in the project.
Example usage inside template would be (where @link is an attribute called link):
```
<xsl:value-of select="php:function('phpDocumentor\Plugin\Core\Xslt\Extension::path', string(@link))" />
```
@param string $fqsen
@return bool|string | [
"Returns",
"a",
"relative",
"URL",
"from",
"the",
"webroot",
"if",
"the",
"given",
"FQSEN",
"exists",
"in",
"the",
"project",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Core/Xslt/Extension.php#L77-L89 |
phpDocumentor/phpDocumentor2 | src/phpDocumentor/Plugin/Core/Xslt/Extension.php | Extension.typeOfElement | public static function typeOfElement($link)
{
if (self::getDocumentedElement($link)) {
return 'documented';
}
if (!self::getDocumentedElement($link) && filter_var($link, FILTER_VALIDATE_URL)) {
return 'url';
}
return 'undocumented';
} | php | public static function typeOfElement($link)
{
if (self::getDocumentedElement($link)) {
return 'documented';
}
if (!self::getDocumentedElement($link) && filter_var($link, FILTER_VALIDATE_URL)) {
return 'url';
}
return 'undocumented';
} | [
"public",
"static",
"function",
"typeOfElement",
"(",
"$",
"link",
")",
"{",
"if",
"(",
"self",
"::",
"getDocumentedElement",
"(",
"$",
"link",
")",
")",
"{",
"return",
"'documented'",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"getDocumentedElement",
"(",
"$",
"link",
")",
"&&",
"filter_var",
"(",
"$",
"link",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"return",
"'url'",
";",
"}",
"return",
"'undocumented'",
";",
"}"
] | Example usage inside template would be (where @link is an attribute called link):
```
<xsl:value-of select="php:function('phpDocumentor\Plugin\Core\Xslt\Extension::typeOfElement', string(@link))" />
```
@param string $link
@return string | [
"Example",
"usage",
"inside",
"template",
"would",
"be",
"(",
"where",
"@link",
"is",
"an",
"attribute",
"called",
"link",
")",
":"
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Core/Xslt/Extension.php#L101-L112 |
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",
"."
] | train | https://github.com/phpDocumentor/phpDocumentor2/blob/7a835fd03ff40244ff557c3e0ce32239e478def0/src/phpDocumentor/Plugin/Core/Xslt/Extension.php#L121-L134 |
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();
if ($redirects < $this->maxRedirects && in_array($code, [301, 302, 307, 308])) {
$oldLocation = $request->getUrl();
$request = clone $request;
$request->setUrl(Uri\resolve(
$oldLocation,
$response->getHeader('Location')
));
$doRedirect = true;
++$redirects;
}
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) {
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L102-L167 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L178-L183 |
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
{
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L192-L269 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L313-L331 |
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)) {
$settings[CURLOPT_PUT] = true;
$settings[CURLOPT_INFILE] = $request->getBody();
} else {
$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();
if (defined('CURLOPT_PROTOCOLS')) {
$settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L364-L412 |
sabre-io/http | lib/Client.php | Client.parseCurlResponse | protected function parseCurlResponse(array $headerLines, string $body, $curlHandle): array
{
list(
$curlInfo,
$curlErrNo,
$curlErrMsg
) = $this->curlStuff($curlHandle);
if ($curlErrNo) {
return [
'status' => self::STATUS_CURLERROR,
'curl_errno' => $curlErrNo,
'curl_errmsg' => $curlErrMsg,
];
}
$response = new Response();
$response->setStatus($curlInfo['http_code']);
$response->setBody($body);
foreach ($headerLines as $header) {
$parts = explode(':', $header, 2);
if (2 === count($parts)) {
$response->addHeader(trim($parts[0]), trim($parts[1]));
}
}
$httpCode = $response->getStatus();
return [
'status' => $httpCode >= 400 ? self::STATUS_HTTPERROR : self::STATUS_SUCCESS,
'response' => $response,
'http_code' => $httpCode,
];
} | php | protected function parseCurlResponse(array $headerLines, string $body, $curlHandle): array
{
list(
$curlInfo,
$curlErrNo,
$curlErrMsg
) = $this->curlStuff($curlHandle);
if ($curlErrNo) {
return [
'status' => self::STATUS_CURLERROR,
'curl_errno' => $curlErrNo,
'curl_errmsg' => $curlErrMsg,
];
}
$response = new Response();
$response->setStatus($curlInfo['http_code']);
$response->setBody($body);
foreach ($headerLines as $header) {
$parts = explode(':', $header, 2);
if (2 === count($parts)) {
$response->addHeader(trim($parts[0]), trim($parts[1]));
}
}
$httpCode = $response->getStatus();
return [
'status' => $httpCode >= 400 ? self::STATUS_HTTPERROR : self::STATUS_SUCCESS,
'response' => $response,
'http_code' => $httpCode,
];
} | [
"protected",
"function",
"parseCurlResponse",
"(",
"array",
"$",
"headerLines",
",",
"string",
"$",
"body",
",",
"$",
"curlHandle",
")",
":",
"array",
"{",
"list",
"(",
"$",
"curlInfo",
",",
"$",
"curlErrNo",
",",
"$",
"curlErrMsg",
")",
"=",
"$",
"this",
"->",
"curlStuff",
"(",
"$",
"curlHandle",
")",
";",
"if",
"(",
"$",
"curlErrNo",
")",
"{",
"return",
"[",
"'status'",
"=>",
"self",
"::",
"STATUS_CURLERROR",
",",
"'curl_errno'",
"=>",
"$",
"curlErrNo",
",",
"'curl_errmsg'",
"=>",
"$",
"curlErrMsg",
",",
"]",
";",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"$",
"curlInfo",
"[",
"'http_code'",
"]",
")",
";",
"$",
"response",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"foreach",
"(",
"$",
"headerLines",
"as",
"$",
"header",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"header",
",",
"2",
")",
";",
"if",
"(",
"2",
"===",
"count",
"(",
"$",
"parts",
")",
")",
"{",
"$",
"response",
"->",
"addHeader",
"(",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
",",
"trim",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
")",
";",
"}",
"}",
"$",
"httpCode",
"=",
"$",
"response",
"->",
"getStatus",
"(",
")",
";",
"return",
"[",
"'status'",
"=>",
"$",
"httpCode",
">=",
"400",
"?",
"self",
"::",
"STATUS_HTTPERROR",
":",
"self",
"::",
"STATUS_SUCCESS",
",",
"'response'",
"=>",
"$",
"response",
",",
"'http_code'",
"=>",
"$",
"httpCode",
",",
"]",
";",
"}"
] | Parses the result of a curl call in a format that's a bit more
convenient to work with.
The method returns an array with the following elements:
* status - one of the 3 STATUS constants.
* curl_errno - A curl error number. Only set if status is
STATUS_CURLERROR.
* curl_errmsg - A current error message. Only set if status is
STATUS_CURLERROR.
* response - Response object. Only set if status is STATUS_SUCCESS, or
STATUS_HTTPERROR.
* http_code - HTTP status code, as an int. Only set if Only set if
status is STATUS_SUCCESS, or STATUS_HTTPERROR
@param array $headerLines
@param string $body
@param resource $curlHandle | [
"Parses",
"the",
"result",
"of",
"a",
"curl",
"call",
"in",
"a",
"format",
"that",
"s",
"a",
"bit",
"more",
"convenient",
"to",
"work",
"with",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L457-L491 |
sabre-io/http | lib/Client.php | Client.parseCurlResult | protected function parseCurlResult(string $response, $curlHandle): array
{
list(
$curlInfo,
$curlErrNo,
$curlErrMsg
) = $this->curlStuff($curlHandle);
if ($curlErrNo) {
return [
'status' => self::STATUS_CURLERROR,
'curl_errno' => $curlErrNo,
'curl_errmsg' => $curlErrMsg,
];
}
$headerBlob = substr($response, 0, $curlInfo['header_size']);
// In the case of 204 No Content, strlen($response) == $curlInfo['header_size].
// This will cause substr($response, $curlInfo['header_size']) return FALSE instead of NULL
// An exception will be thrown when calling getBodyAsString then
$responseBody = substr($response, $curlInfo['header_size']) ?: null;
unset($response);
// In the case of 100 Continue, or redirects we'll have multiple lists
// of headers for each separate HTTP response. We can easily split this
// because they are separated by \r\n\r\n
$headerBlob = explode("\r\n\r\n", trim($headerBlob, "\r\n"));
// We only care about the last set of headers
$headerBlob = $headerBlob[count($headerBlob) - 1];
// Splitting headers
$headerBlob = explode("\r\n", $headerBlob);
return $this->parseCurlResponse($headerBlob, $responseBody, $curlHandle);
} | php | protected function parseCurlResult(string $response, $curlHandle): array
{
list(
$curlInfo,
$curlErrNo,
$curlErrMsg
) = $this->curlStuff($curlHandle);
if ($curlErrNo) {
return [
'status' => self::STATUS_CURLERROR,
'curl_errno' => $curlErrNo,
'curl_errmsg' => $curlErrMsg,
];
}
$headerBlob = substr($response, 0, $curlInfo['header_size']);
$responseBody = substr($response, $curlInfo['header_size']) ?: null;
unset($response);
$headerBlob = explode("\r\n\r\n", trim($headerBlob, "\r\n"));
$headerBlob = $headerBlob[count($headerBlob) - 1];
$headerBlob = explode("\r\n", $headerBlob);
return $this->parseCurlResponse($headerBlob, $responseBody, $curlHandle);
} | [
"protected",
"function",
"parseCurlResult",
"(",
"string",
"$",
"response",
",",
"$",
"curlHandle",
")",
":",
"array",
"{",
"list",
"(",
"$",
"curlInfo",
",",
"$",
"curlErrNo",
",",
"$",
"curlErrMsg",
")",
"=",
"$",
"this",
"->",
"curlStuff",
"(",
"$",
"curlHandle",
")",
";",
"if",
"(",
"$",
"curlErrNo",
")",
"{",
"return",
"[",
"'status'",
"=>",
"self",
"::",
"STATUS_CURLERROR",
",",
"'curl_errno'",
"=>",
"$",
"curlErrNo",
",",
"'curl_errmsg'",
"=>",
"$",
"curlErrMsg",
",",
"]",
";",
"}",
"$",
"headerBlob",
"=",
"substr",
"(",
"$",
"response",
",",
"0",
",",
"$",
"curlInfo",
"[",
"'header_size'",
"]",
")",
";",
"// In the case of 204 No Content, strlen($response) == $curlInfo['header_size].",
"// This will cause substr($response, $curlInfo['header_size']) return FALSE instead of NULL",
"// An exception will be thrown when calling getBodyAsString then",
"$",
"responseBody",
"=",
"substr",
"(",
"$",
"response",
",",
"$",
"curlInfo",
"[",
"'header_size'",
"]",
")",
"?",
":",
"null",
";",
"unset",
"(",
"$",
"response",
")",
";",
"// In the case of 100 Continue, or redirects we'll have multiple lists",
"// of headers for each separate HTTP response. We can easily split this",
"// because they are separated by \\r\\n\\r\\n",
"$",
"headerBlob",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"trim",
"(",
"$",
"headerBlob",
",",
"\"\\r\\n\"",
")",
")",
";",
"// We only care about the last set of headers",
"$",
"headerBlob",
"=",
"$",
"headerBlob",
"[",
"count",
"(",
"$",
"headerBlob",
")",
"-",
"1",
"]",
";",
"// Splitting headers",
"$",
"headerBlob",
"=",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"headerBlob",
")",
";",
"return",
"$",
"this",
"->",
"parseCurlResponse",
"(",
"$",
"headerBlob",
",",
"$",
"responseBody",
",",
"$",
"curlHandle",
")",
";",
"}"
] | Parses the result of a curl call in a format that's a bit more
convenient to work with.
The method returns an array with the following elements:
* status - one of the 3 STATUS constants.
* curl_errno - A curl error number. Only set if status is
STATUS_CURLERROR.
* curl_errmsg - A current error message. Only set if status is
STATUS_CURLERROR.
* response - Response object. Only set if status is STATUS_SUCCESS, or
STATUS_HTTPERROR.
* http_code - HTTP status code, as an int. Only set if Only set if
status is STATUS_SUCCESS, or STATUS_HTTPERROR
@deprecated Use parseCurlResponse instead
@param resource $curlHandle | [
"Parses",
"the",
"result",
"of",
"a",
"curl",
"call",
"in",
"a",
"format",
"that",
"s",
"a",
"bit",
"more",
"convenient",
"to",
"work",
"with",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L512-L548 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L556-L576 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Client.php#L587-L597 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Bearer.php#L29-L42 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Basic.php#L30-L49 |
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) {
$serverArr['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ?? '/';
$serverArr['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'] ?? 'CLI';
}
$r = self::createFromServerArray($serverArr);
$r->setBody(fopen('php:
$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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Sapi.php#L41-L57 |
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:
if (is_resource($body) && 'stream' == get_resource_type($body)) {
if (PHP_INT_SIZE !== 4) {
stream_copy_to_stream($body, $output, (int) $contentLength);
} else {
while (!feof($body)) {
fwrite($output, fread($body, 8192));
}
}
} else {
fwrite($output, $body, (int) $contentLength);
}
} else {
file_put_contents('php:
}
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Sapi.php#L64-L111 |
sabre-io/http | lib/Sapi.php | Sapi.createFromServerArray | public static function createFromServerArray(array $serverArray): Request
{
$headers = [];
$method = null;
$url = null;
$httpVersion = '1.1';
$protocol = 'http';
$hostName = 'localhost';
foreach ($serverArray as $key => $value) {
switch ($key) {
case 'SERVER_PROTOCOL':
if ('HTTP/1.0' === $value) {
$httpVersion = '1.0';
} elseif ('HTTP/2.0' === $value) {
$httpVersion = '2.0';
}
break;
case 'REQUEST_METHOD':
$method = $value;
break;
case 'REQUEST_URI':
$url = $value;
break;
// These sometimes show up without a HTTP_ prefix
case 'CONTENT_TYPE':
$headers['Content-Type'] = $value;
break;
case 'CONTENT_LENGTH':
$headers['Content-Length'] = $value;
break;
// mod_php on apache will put credentials in these variables.
// (fast)cgi does not usually do this, however.
case 'PHP_AUTH_USER':
if (isset($serverArray['PHP_AUTH_PW'])) {
$headers['Authorization'] = 'Basic '.base64_encode($value.':'.$serverArray['PHP_AUTH_PW']);
}
break;
// Similarly, mod_php may also screw around with digest auth.
case 'PHP_AUTH_DIGEST':
$headers['Authorization'] = 'Digest '.$value;
break;
// Apache may prefix the HTTP_AUTHORIZATION header with
// REDIRECT_, if mod_rewrite was used.
case 'REDIRECT_HTTP_AUTHORIZATION':
$headers['Authorization'] = $value;
break;
case 'HTTP_HOST':
$hostName = $value;
$headers['Host'] = $value;
break;
case 'HTTPS':
if (!empty($value) && 'off' !== $value) {
$protocol = 'https';
}
break;
default:
if ('HTTP_' === substr($key, 0, 5)) {
// It's a HTTP header
// Normalizing it to be prettier
$header = strtolower(substr($key, 5));
// Transforming dashes into spaces, and uppercasing
// every first letter.
$header = ucwords(str_replace('_', ' ', $header));
// Turning spaces into dashes.
$header = str_replace(' ', '-', $header);
$headers[$header] = $value;
}
break;
}
}
if (null === $url) {
throw new InvalidArgumentException('The _SERVER array must have a REQUEST_URI key');
}
if (null === $method) {
throw new InvalidArgumentException('The _SERVER array must have a REQUEST_METHOD key');
}
$r = new Request($method, $url, $headers);
$r->setHttpVersion($httpVersion);
$r->setRawServerData($serverArray);
$r->setAbsoluteUrl($protocol.'://'.$hostName.$url);
return $r;
} | php | public static function createFromServerArray(array $serverArray): Request
{
$headers = [];
$method = null;
$url = null;
$httpVersion = '1.1';
$protocol = 'http';
$hostName = 'localhost';
foreach ($serverArray as $key => $value) {
switch ($key) {
case 'SERVER_PROTOCOL':
if ('HTTP/1.0' === $value) {
$httpVersion = '1.0';
} elseif ('HTTP/2.0' === $value) {
$httpVersion = '2.0';
}
break;
case 'REQUEST_METHOD':
$method = $value;
break;
case 'REQUEST_URI':
$url = $value;
break;
case 'CONTENT_TYPE':
$headers['Content-Type'] = $value;
break;
case 'CONTENT_LENGTH':
$headers['Content-Length'] = $value;
break;
case 'PHP_AUTH_USER':
if (isset($serverArray['PHP_AUTH_PW'])) {
$headers['Authorization'] = 'Basic '.base64_encode($value.':'.$serverArray['PHP_AUTH_PW']);
}
break;
case 'PHP_AUTH_DIGEST':
$headers['Authorization'] = 'Digest '.$value;
break;
case 'REDIRECT_HTTP_AUTHORIZATION':
$headers['Authorization'] = $value;
break;
case 'HTTP_HOST':
$hostName = $value;
$headers['Host'] = $value;
break;
case 'HTTPS':
if (!empty($value) && 'off' !== $value) {
$protocol = 'https';
}
break;
default:
if ('HTTP_' === substr($key, 0, 5)) {
$header = strtolower(substr($key, 5));
$header = ucwords(str_replace('_', ' ', $header));
$header = str_replace(' ', '-', $header);
$headers[$header] = $value;
}
break;
}
}
if (null === $url) {
throw new InvalidArgumentException('The _SERVER array must have a REQUEST_URI key');
}
if (null === $method) {
throw new InvalidArgumentException('The _SERVER array must have a REQUEST_METHOD key');
}
$r = new Request($method, $url, $headers);
$r->setHttpVersion($httpVersion);
$r->setRawServerData($serverArray);
$r->setAbsoluteUrl($protocol.':
return $r;
} | [
"public",
"static",
"function",
"createFromServerArray",
"(",
"array",
"$",
"serverArray",
")",
":",
"Request",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"method",
"=",
"null",
";",
"$",
"url",
"=",
"null",
";",
"$",
"httpVersion",
"=",
"'1.1'",
";",
"$",
"protocol",
"=",
"'http'",
";",
"$",
"hostName",
"=",
"'localhost'",
";",
"foreach",
"(",
"$",
"serverArray",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'SERVER_PROTOCOL'",
":",
"if",
"(",
"'HTTP/1.0'",
"===",
"$",
"value",
")",
"{",
"$",
"httpVersion",
"=",
"'1.0'",
";",
"}",
"elseif",
"(",
"'HTTP/2.0'",
"===",
"$",
"value",
")",
"{",
"$",
"httpVersion",
"=",
"'2.0'",
";",
"}",
"break",
";",
"case",
"'REQUEST_METHOD'",
":",
"$",
"method",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'REQUEST_URI'",
":",
"$",
"url",
"=",
"$",
"value",
";",
"break",
";",
"// These sometimes show up without a HTTP_ prefix",
"case",
"'CONTENT_TYPE'",
":",
"$",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'CONTENT_LENGTH'",
":",
"$",
"headers",
"[",
"'Content-Length'",
"]",
"=",
"$",
"value",
";",
"break",
";",
"// mod_php on apache will put credentials in these variables.",
"// (fast)cgi does not usually do this, however.",
"case",
"'PHP_AUTH_USER'",
":",
"if",
"(",
"isset",
"(",
"$",
"serverArray",
"[",
"'PHP_AUTH_PW'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"'Authorization'",
"]",
"=",
"'Basic '",
".",
"base64_encode",
"(",
"$",
"value",
".",
"':'",
".",
"$",
"serverArray",
"[",
"'PHP_AUTH_PW'",
"]",
")",
";",
"}",
"break",
";",
"// Similarly, mod_php may also screw around with digest auth.",
"case",
"'PHP_AUTH_DIGEST'",
":",
"$",
"headers",
"[",
"'Authorization'",
"]",
"=",
"'Digest '",
".",
"$",
"value",
";",
"break",
";",
"// Apache may prefix the HTTP_AUTHORIZATION header with",
"// REDIRECT_, if mod_rewrite was used.",
"case",
"'REDIRECT_HTTP_AUTHORIZATION'",
":",
"$",
"headers",
"[",
"'Authorization'",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'HTTP_HOST'",
":",
"$",
"hostName",
"=",
"$",
"value",
";",
"$",
"headers",
"[",
"'Host'",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'HTTPS'",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"'off'",
"!==",
"$",
"value",
")",
"{",
"$",
"protocol",
"=",
"'https'",
";",
"}",
"break",
";",
"default",
":",
"if",
"(",
"'HTTP_'",
"===",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"5",
")",
")",
"{",
"// It's a HTTP header",
"// Normalizing it to be prettier",
"$",
"header",
"=",
"strtolower",
"(",
"substr",
"(",
"$",
"key",
",",
"5",
")",
")",
";",
"// Transforming dashes into spaces, and uppercasing",
"// every first letter.",
"$",
"header",
"=",
"ucwords",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"header",
")",
")",
";",
"// Turning spaces into dashes.",
"$",
"header",
"=",
"str_replace",
"(",
"' '",
",",
"'-'",
",",
"$",
"header",
")",
";",
"$",
"headers",
"[",
"$",
"header",
"]",
"=",
"$",
"value",
";",
"}",
"break",
";",
"}",
"}",
"if",
"(",
"null",
"===",
"$",
"url",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The _SERVER array must have a REQUEST_URI key'",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"method",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The _SERVER array must have a REQUEST_METHOD key'",
")",
";",
"}",
"$",
"r",
"=",
"new",
"Request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"headers",
")",
";",
"$",
"r",
"->",
"setHttpVersion",
"(",
"$",
"httpVersion",
")",
";",
"$",
"r",
"->",
"setRawServerData",
"(",
"$",
"serverArray",
")",
";",
"$",
"r",
"->",
"setAbsoluteUrl",
"(",
"$",
"protocol",
".",
"'://'",
".",
"$",
"hostName",
".",
"$",
"url",
")",
";",
"return",
"$",
"r",
";",
"}"
] | This static method will create a new Request object, based on a PHP
$_SERVER array.
REQUEST_URI and REQUEST_METHOD are required. | [
"This",
"static",
"method",
"will",
"create",
"a",
"new",
"Request",
"object",
"based",
"on",
"a",
"PHP",
"$_SERVER",
"array",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Sapi.php#L119-L215 |
sabre-io/http | lib/Auth/Digest.php | Digest.init | public function init()
{
$digest = $this->getDigest();
$this->digestParts = $this->parseDigest((string) $digest);
} | php | public function init()
{
$digest = $this->getDigest();
$this->digestParts = $this->parseDigest((string) $digest);
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"digest",
"=",
"$",
"this",
"->",
"getDigest",
"(",
")",
";",
"$",
"this",
"->",
"digestParts",
"=",
"$",
"this",
"->",
"parseDigest",
"(",
"(",
"string",
")",
"$",
"digest",
")",
";",
"}"
] | Gathers all information from the headers.
This method needs to be called prior to anything else. | [
"Gathers",
"all",
"information",
"from",
"the",
"headers",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L61-L65 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L101-L106 |
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']) {
if (!($this->qop & self::QOP_AUTHINT)) {
return false;
}
$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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L122-L144 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L151-L168 |
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)
{
$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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/Digest.php#L191-L205 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Request.php#L86-L96 |
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) {
$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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Request.php#L111-L121 |
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
{
$uri = str_replace('
$uri = Uri\normalize($uri);
$baseUri = Uri\normalize($this->getBaseUrl());
if (0 === strpos($uri, $baseUri)) {
list($uri) = explode('?', $uri);
return trim(decodePath(substr($uri, strlen($baseUri))), '/');
}
if ($uri.'/' === $baseUri) {
return '';
}
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Request.php#L163-L185 |
sabre-io/http | lib/Response.php | Response.setStatus | public function setStatus($status)
{
if (ctype_digit($status) || is_int($status)) {
$statusCode = $status;
$statusText = self::$statusCodes[$status] ?? 'Unknown';
} else {
list(
$statusCode,
$statusText
) = explode(' ', $status, 2);
$statusCode = (int) $statusCode;
}
if ($statusCode < 100 || $statusCode > 999) {
throw new \InvalidArgumentException('The HTTP status code must be exactly 3 digits');
}
$this->status = $statusCode;
$this->statusText = $statusText;
} | php | public function setStatus($status)
{
if (ctype_digit($status) || is_int($status)) {
$statusCode = $status;
$statusText = self::$statusCodes[$status] ?? 'Unknown';
} else {
list(
$statusCode,
$statusText
) = explode(' ', $status, 2);
$statusCode = (int) $statusCode;
}
if ($statusCode < 100 || $statusCode > 999) {
throw new \InvalidArgumentException('The HTTP status code must be exactly 3 digits');
}
$this->status = $statusCode;
$this->statusText = $statusText;
} | [
"public",
"function",
"setStatus",
"(",
"$",
"status",
")",
"{",
"if",
"(",
"ctype_digit",
"(",
"$",
"status",
")",
"||",
"is_int",
"(",
"$",
"status",
")",
")",
"{",
"$",
"statusCode",
"=",
"$",
"status",
";",
"$",
"statusText",
"=",
"self",
"::",
"$",
"statusCodes",
"[",
"$",
"status",
"]",
"??",
"'Unknown'",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"statusCode",
",",
"$",
"statusText",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"status",
",",
"2",
")",
";",
"$",
"statusCode",
"=",
"(",
"int",
")",
"$",
"statusCode",
";",
"}",
"if",
"(",
"$",
"statusCode",
"<",
"100",
"||",
"$",
"statusCode",
">",
"999",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The HTTP status code must be exactly 3 digits'",
")",
";",
"}",
"$",
"this",
"->",
"status",
"=",
"$",
"statusCode",
";",
"$",
"this",
"->",
"statusText",
"=",
"$",
"statusText",
";",
"}"
] | Sets the HTTP status code.
This can be either the full HTTP status code with human readable string,
for example: "403 I can't let you do that, Dave".
Or just the code, in which case the appropriate default message will be
added.
@param string|int $status
@throws \InvalidArgumentException | [
"Sets",
"the",
"HTTP",
"status",
"code",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Response.php#L150-L168 |
sabre-io/http | lib/Auth/AWS.php | AWS.init | public function init(): bool
{
$authHeader = $this->request->getHeader('Authorization');
if (null === $authHeader) {
$this->errorCode = self::ERR_NOAWSHEADER;
return false;
}
$authHeader = explode(' ', $authHeader);
if ('AWS' !== $authHeader[0] || !isset($authHeader[1])) {
$this->errorCode = self::ERR_NOAWSHEADER;
return false;
}
list($this->accessKey, $this->signature) = explode(':', $authHeader[1]);
return true;
} | php | public function init(): bool
{
$authHeader = $this->request->getHeader('Authorization');
if (null === $authHeader) {
$this->errorCode = self::ERR_NOAWSHEADER;
return false;
}
$authHeader = explode(' ', $authHeader);
if ('AWS' !== $authHeader[0] || !isset($authHeader[1])) {
$this->errorCode = self::ERR_NOAWSHEADER;
return false;
}
list($this->accessKey, $this->signature) = explode(':', $authHeader[1]);
return true;
} | [
"public",
"function",
"init",
"(",
")",
":",
"bool",
"{",
"$",
"authHeader",
"=",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'Authorization'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"authHeader",
")",
"{",
"$",
"this",
"->",
"errorCode",
"=",
"self",
"::",
"ERR_NOAWSHEADER",
";",
"return",
"false",
";",
"}",
"$",
"authHeader",
"=",
"explode",
"(",
"' '",
",",
"$",
"authHeader",
")",
";",
"if",
"(",
"'AWS'",
"!==",
"$",
"authHeader",
"[",
"0",
"]",
"||",
"!",
"isset",
"(",
"$",
"authHeader",
"[",
"1",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorCode",
"=",
"self",
"::",
"ERR_NOAWSHEADER",
";",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"this",
"->",
"accessKey",
",",
"$",
"this",
"->",
"signature",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"authHeader",
"[",
"1",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Gathers all information from the headers.
This method needs to be called prior to anything else. | [
"Gathers",
"all",
"information",
"from",
"the",
"headers",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L54-L74 |
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) {
$body = $this->request->getBody();
$this->request->setBody($body);
if ($contentMD5 !== base64_encode(md5((string) $body, true))) {
$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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L87-L132 |
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);
if (!$date) {
$this->errorCode = self::ERR_INVALIDDATEFORMAT;
return false;
}
$min = new \DateTime('-15 minutes');
$max = new \DateTime('+15 minutes');
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L154-L176 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L181-L198 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Auth/AWS.php#L203-L219 |
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:
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L49-L64 |
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();
}
$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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L72-L96 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L125-L133 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L228-L242 |
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",
"."
] | train | https://github.com/sabre-io/http/blob/404788805fa07338599ebc25b6aa834be02abe2f/lib/Message.php#L263-L272 |
mongodb/mongo-php-library | src/Operation/Watch.php | Watch.execute | public function execute(Server $server)
{
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
if ($inTransaction && isset($this->options['readConcern'])) {
throw UnsupportedException::readConcernNotSupportedInTransaction();
}
return new ChangeStream($this->executeAggregate($server), $this->resumeCallable);
} | php | public function execute(Server $server)
{
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
if ($inTransaction && isset($this->options['readConcern'])) {
throw UnsupportedException::readConcernNotSupportedInTransaction();
}
return new ChangeStream($this->executeAggregate($server), $this->resumeCallable);
} | [
"public",
"function",
"execute",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"inTransaction",
"=",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'session'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'session'",
"]",
"->",
"isInTransaction",
"(",
")",
";",
"if",
"(",
"$",
"inTransaction",
"&&",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'readConcern'",
"]",
")",
")",
"{",
"throw",
"UnsupportedException",
"::",
"readConcernNotSupportedInTransaction",
"(",
")",
";",
"}",
"return",
"new",
"ChangeStream",
"(",
"$",
"this",
"->",
"executeAggregate",
"(",
"$",
"server",
")",
",",
"$",
"this",
"->",
"resumeCallable",
")",
";",
"}"
] | Execute the operation.
@see Executable::execute()
@param Server $server
@return ChangeStream
@throws UnsupportedException if collation or read concern is used and unsupported
@throws RuntimeException for other driver errors (e.g. connection errors) | [
"Execute",
"the",
"operation",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Operation/Watch.php#L214-L222 |
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']);
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",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L190-L230 |
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",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L269-L284 |
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",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L438-L453 |
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",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L866-L876 |
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",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L889-L899 |
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;
}
if ($hasOutputCollection) {
$options['readPreference'] = new ReadPreference(ReadPreference::RP_PRIMARY);
}
$server = $this->manager->selectServer($options['readPreference']);
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",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L933-L968 |
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']);
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",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L1054-L1080 |
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"
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Collection.php#L1108-L1114 |
mongodb/mongo-php-library | src/Operation/FindAndModify.php | FindAndModify.execute | public function execute(Server $server)
{
if (isset($this->options['arrayFilters']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForArrayFilters)) {
throw UnsupportedException::arrayFiltersNotSupported();
}
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported();
}
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported();
}
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
if ($inTransaction && isset($this->options['writeConcern'])) {
throw UnsupportedException::writeConcernNotSupportedInTransaction();
}
$cursor = $server->executeWriteCommand($this->databaseName, new Command($this->createCommandDocument($server)), $this->createOptions());
$result = current($cursor->toArray());
if ( ! isset($result->value)) {
return null;
}
if ( ! is_object($result->value)) {
throw new UnexpectedValueException('findAndModify command did not return a "value" document');
}
if (isset($this->options['typeMap'])) {
return \MongoDB\apply_type_map_to_document($result->value, $this->options['typeMap']);
}
return $result->value;
} | php | public function execute(Server $server)
{
if (isset($this->options['arrayFilters']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForArrayFilters)) {
throw UnsupportedException::arrayFiltersNotSupported();
}
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported();
}
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported();
}
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
if ($inTransaction && isset($this->options['writeConcern'])) {
throw UnsupportedException::writeConcernNotSupportedInTransaction();
}
$cursor = $server->executeWriteCommand($this->databaseName, new Command($this->createCommandDocument($server)), $this->createOptions());
$result = current($cursor->toArray());
if ( ! isset($result->value)) {
return null;
}
if ( ! is_object($result->value)) {
throw new UnexpectedValueException('findAndModify command did not return a "value" document');
}
if (isset($this->options['typeMap'])) {
return \MongoDB\apply_type_map_to_document($result->value, $this->options['typeMap']);
}
return $result->value;
} | [
"public",
"function",
"execute",
"(",
"Server",
"$",
"server",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'arrayFilters'",
"]",
")",
"&&",
"!",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForArrayFilters",
")",
")",
"{",
"throw",
"UnsupportedException",
"::",
"arrayFiltersNotSupported",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'collation'",
"]",
")",
"&&",
"!",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForCollation",
")",
")",
"{",
"throw",
"UnsupportedException",
"::",
"collationNotSupported",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'writeConcern'",
"]",
")",
"&&",
"!",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForWriteConcern",
")",
")",
"{",
"throw",
"UnsupportedException",
"::",
"writeConcernNotSupported",
"(",
")",
";",
"}",
"$",
"inTransaction",
"=",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'session'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'session'",
"]",
"->",
"isInTransaction",
"(",
")",
";",
"if",
"(",
"$",
"inTransaction",
"&&",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'writeConcern'",
"]",
")",
")",
"{",
"throw",
"UnsupportedException",
"::",
"writeConcernNotSupportedInTransaction",
"(",
")",
";",
"}",
"$",
"cursor",
"=",
"$",
"server",
"->",
"executeWriteCommand",
"(",
"$",
"this",
"->",
"databaseName",
",",
"new",
"Command",
"(",
"$",
"this",
"->",
"createCommandDocument",
"(",
"$",
"server",
")",
")",
",",
"$",
"this",
"->",
"createOptions",
"(",
")",
")",
";",
"$",
"result",
"=",
"current",
"(",
"$",
"cursor",
"->",
"toArray",
"(",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"->",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"result",
"->",
"value",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'findAndModify command did not return a \"value\" document'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'typeMap'",
"]",
")",
")",
"{",
"return",
"\\",
"MongoDB",
"\\",
"apply_type_map_to_document",
"(",
"$",
"result",
"->",
"value",
",",
"$",
"this",
"->",
"options",
"[",
"'typeMap'",
"]",
")",
";",
"}",
"return",
"$",
"result",
"->",
"value",
";",
"}"
] | Execute the operation.
@see Executable::execute()
@param Server $server
@return array|object|null
@throws UnexpectedValueException if the command response was malformed
@throws UnsupportedException if array filters, collation, or write concern is used and unsupported
@throws DriverRuntimeException for other driver errors (e.g. connection errors) | [
"Execute",
"the",
"operation",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Operation/FindAndModify.php#L199-L234 |
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",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Operation/FindAndModify.php#L247-L280 |
mongodb/mongo-php-library | src/Operation/InsertMany.php | InsertMany.execute | public function execute(Server $server)
{
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
if ($inTransaction && isset($this->options['writeConcern'])) {
throw UnsupportedException::writeConcernNotSupportedInTransaction();
}
$options = ['ordered' => $this->options['ordered']];
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
$bulk = new Bulk($options);
$insertedIds = [];
foreach ($this->documents as $i => $document) {
$insertedIds[$i] = $bulk->insert($document);
}
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $this->createOptions());
return new InsertManyResult($writeResult, $insertedIds);
} | php | public function execute(Server $server)
{
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
if ($inTransaction && isset($this->options['writeConcern'])) {
throw UnsupportedException::writeConcernNotSupportedInTransaction();
}
$options = ['ordered' => $this->options['ordered']];
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
$bulk = new Bulk($options);
$insertedIds = [];
foreach ($this->documents as $i => $document) {
$insertedIds[$i] = $bulk->insert($document);
}
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $this->createOptions());
return new InsertManyResult($writeResult, $insertedIds);
} | [
"public",
"function",
"execute",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"inTransaction",
"=",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'session'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'session'",
"]",
"->",
"isInTransaction",
"(",
")",
";",
"if",
"(",
"$",
"inTransaction",
"&&",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'writeConcern'",
"]",
")",
")",
"{",
"throw",
"UnsupportedException",
"::",
"writeConcernNotSupportedInTransaction",
"(",
")",
";",
"}",
"$",
"options",
"=",
"[",
"'ordered'",
"=>",
"$",
"this",
"->",
"options",
"[",
"'ordered'",
"]",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"options",
"[",
"'bypassDocumentValidation'",
"]",
")",
"&&",
"\\",
"MongoDB",
"\\",
"server_supports_feature",
"(",
"$",
"server",
",",
"self",
"::",
"$",
"wireVersionForDocumentLevelValidation",
")",
")",
"{",
"$",
"options",
"[",
"'bypassDocumentValidation'",
"]",
"=",
"$",
"this",
"->",
"options",
"[",
"'bypassDocumentValidation'",
"]",
";",
"}",
"$",
"bulk",
"=",
"new",
"Bulk",
"(",
"$",
"options",
")",
";",
"$",
"insertedIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"documents",
"as",
"$",
"i",
"=>",
"$",
"document",
")",
"{",
"$",
"insertedIds",
"[",
"$",
"i",
"]",
"=",
"$",
"bulk",
"->",
"insert",
"(",
"$",
"document",
")",
";",
"}",
"$",
"writeResult",
"=",
"$",
"server",
"->",
"executeBulkWrite",
"(",
"$",
"this",
"->",
"databaseName",
".",
"'.'",
".",
"$",
"this",
"->",
"collectionName",
",",
"$",
"bulk",
",",
"$",
"this",
"->",
"createOptions",
"(",
")",
")",
";",
"return",
"new",
"InsertManyResult",
"(",
"$",
"writeResult",
",",
"$",
"insertedIds",
")",
";",
"}"
] | Execute the operation.
@see Executable::execute()
@param Server $server
@return InsertManyResult
@throws DriverRuntimeException for other driver errors (e.g. connection errors) | [
"Execute",
"the",
"operation",
"."
] | train | https://github.com/mongodb/mongo-php-library/blob/d444ddead4cf8a3d93f4c9206e7eac1ac14ff216/src/Operation/InsertMany.php#L128-L154 |
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) {
throw new Exception('PREG error ' . preg_last_error());
}
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"
] | train | https://github.com/slevomat/coding-standard/blob/1ff7cfb8e8df3af138cd04793ca1fbfea254cd50/SlevomatCodingStandard/Helpers/TypeHelper.php#L19-L31 |